[cig-commits] commit: Rename .c -> .cxx and make configure automatically use c++

Mercurial hg at geodynamics.org
Thu May 12 11:22:14 PDT 2011


changeset:   608:5f446b6d9117
tag:         tip
user:        Walter Landry <wlandry at caltech.edu>
date:        Thu May 12 11:18:48 2011 -0700
files:       Geometry/src/ComplexMath.c Geometry/src/ComplexMath.cxx Geometry/src/ComplexVectorMath.c Geometry/src/ComplexVectorMath.cxx Geometry/src/Delaunay.c Geometry/src/Delaunay.cxx Geometry/src/Dimension.c Geometry/src/Dimension.cxx Geometry/src/Edge.c Geometry/src/Edge.cxx Geometry/src/Finalise.c Geometry/src/Finalise.cxx Geometry/src/Hex.c Geometry/src/Hex.cxx Geometry/src/Init.c Geometry/src/Init.cxx Geometry/src/Line.c Geometry/src/Line.cxx Geometry/src/ParallelDelaunay.c Geometry/src/ParallelDelaunay.cxx Geometry/src/Plane.c Geometry/src/Plane.cxx Geometry/src/QuadEdge.c Geometry/src/QuadEdge.cxx Geometry/src/RMatrix.c Geometry/src/RMatrix.cxx Geometry/src/Simplex.c Geometry/src/Simplex.cxx Geometry/src/TensorMath.c Geometry/src/TensorMath.cxx Geometry/src/TensorMultMath.c Geometry/src/TensorMultMath.cxx Geometry/src/TrigMath.c Geometry/src/TrigMath.cxx Geometry/src/VectorMath.c Geometry/src/VectorMath.cxx Geometry/tests/ComplexMathSuite.c Geometry/tests/ComplexMathSuite.cxx Geometry/tests/ComplexVectorMathSuite.c Geometry/tests/ComplexVectorMathSuite.cxx Geometry/tests/DelaunaySuite.c Geometry/tests/DelaunaySuite.cxx Geometry/tests/DimensionMacrosSuite.c Geometry/tests/DimensionMacrosSuite.cxx Geometry/tests/EdgeSuite.c Geometry/tests/EdgeSuite.cxx Geometry/tests/LineSuite.c Geometry/tests/LineSuite.cxx Geometry/tests/ParallelDelaunaySuite.c Geometry/tests/ParallelDelaunaySuite.cxx Geometry/tests/PlaneSuite.c Geometry/tests/PlaneSuite.cxx Geometry/tests/TensorMathSuite.c Geometry/tests/TensorMathSuite.cxx Geometry/tests/TensorMultMathSuite.c Geometry/tests/TensorMultMathSuite.cxx Geometry/tests/TrigMathSuite.c Geometry/tests/TrigMathSuite.cxx Geometry/tests/VectorMathSuite.c Geometry/tests/VectorMathSuite.cxx Mesh/src/CartesianGenerator.c Mesh/src/CartesianGenerator.cxx Mesh/src/CompressionAdaptor.c Mesh/src/CompressionAdaptor.cxx Mesh/src/Decomp.c Mesh/src/Decomp.cxx Mesh/src/Finalise.c Mesh/src/Finalise.cxx Mesh/src/Grid.c Mesh/src/Grid.cxx Mesh/src/IGraph.c Mesh/src/IGraph.cxx Mesh/src/Init.c Mesh/src/Init.cxx Mesh/src/MeshAdaptor.c Mesh/src/MeshAdaptor.cxx Mesh/src/MeshClass.c Mesh/src/MeshClass.cxx Mesh/src/MeshGenerator.c Mesh/src/MeshGenerator.cxx Mesh/src/MeshTopology.c Mesh/src/MeshTopology.cxx Mesh/src/MeshVariable.c Mesh/src/MeshVariable.cxx Mesh/src/Mesh_Algorithms.c Mesh/src/Mesh_Algorithms.cxx Mesh/src/Mesh_CentroidAlgorithms.c Mesh/src/Mesh_CentroidAlgorithms.cxx Mesh/src/Mesh_CentroidType.c Mesh/src/Mesh_CentroidType.cxx Mesh/src/Mesh_ElementType.c Mesh/src/Mesh_ElementType.cxx Mesh/src/Mesh_HexAlgorithms.c Mesh/src/Mesh_HexAlgorithms.cxx Mesh/src/Mesh_HexType.c Mesh/src/Mesh_HexType.cxx Mesh/src/Mesh_RegularAlgorithms.c Mesh/src/Mesh_RegularAlgorithms.cxx Mesh/src/Remesher.c Mesh/src/Remesher.cxx Mesh/src/SpatialTree.c Mesh/src/SpatialTree.cxx Mesh/src/SurfaceAdaptor.c Mesh/src/SurfaceAdaptor.cxx Mesh/src/Sync.c Mesh/src/Sync.cxx Mesh/src/linearSpaceAdaptor.c Mesh/src/linearSpaceAdaptor.cxx Mesh/tests/CartesianGeneratorSuite.c Mesh/tests/CartesianGeneratorSuite.cxx Mesh/tests/DecompSuite.c Mesh/tests/DecompSuite.cxx Mesh/tests/MeshSuite.c Mesh/tests/MeshSuite.cxx Python/Bindings/Mesh/bindings.c Python/Bindings/Mesh/bindings.cxx Python/Bindings/Mesh/init.c Python/Bindings/Mesh/init.cxx Python/Bindings/Mesh/misc.c Python/Bindings/Mesh/misc.cxx SConscript Shape/src/BelowCosinePlane.c Shape/src/BelowCosinePlane.cxx Shape/src/BelowPlane.c Shape/src/BelowPlane.cxx Shape/src/Box.c Shape/src/Box.cxx Shape/src/ConvexHull.c Shape/src/ConvexHull.cxx Shape/src/Cylinder.c Shape/src/Cylinder.cxx Shape/src/Everywhere.c Shape/src/Everywhere.cxx Shape/src/Finalise.c Shape/src/Finalise.cxx Shape/src/Init.c Shape/src/Init.cxx Shape/src/Intersection.c Shape/src/Intersection.cxx Shape/src/PolygonShape.c Shape/src/PolygonShape.cxx Shape/src/PythonShape.c Shape/src/PythonShape.cxx Shape/src/ShapeClass.c Shape/src/ShapeClass.cxx Shape/src/Sphere.c Shape/src/Sphere.cxx Shape/src/Superellipsoid.c Shape/src/Superellipsoid.cxx Shape/src/Union.c Shape/src/Union.cxx Shape/tests/ShapeSuite.c Shape/tests/ShapeSuite.cxx Swarm/src/CellLayout.c Swarm/src/CellLayout.cxx Swarm/src/ElementCellLayout.c Swarm/src/ElementCellLayout.cxx Swarm/src/FileParticleLayout.c Swarm/src/FileParticleLayout.cxx Swarm/src/Finalise.c Swarm/src/Finalise.cxx Swarm/src/GaussBorderParticleLayout.c Swarm/src/GaussBorderParticleLayout.cxx Swarm/src/GaussParticleLayout.c Swarm/src/GaussParticleLayout.cxx Swarm/src/GlobalParticleLayout.c Swarm/src/GlobalParticleLayout.cxx Swarm/src/Init.c Swarm/src/Init.cxx Swarm/src/IntegrationPoint.c Swarm/src/IntegrationPoint.cxx Swarm/src/LineParticleLayout.c Swarm/src/LineParticleLayout.cxx Swarm/src/ManualParticleLayout.c Swarm/src/ManualParticleLayout.cxx Swarm/src/MeshParticleLayout.c Swarm/src/MeshParticleLayout.cxx Swarm/src/OperatorSwarmVariable.c Swarm/src/OperatorSwarmVariable.cxx Swarm/src/ParticleCommHandler.c Swarm/src/ParticleCommHandler.cxx Swarm/src/ParticleLayout.c Swarm/src/ParticleLayout.cxx Swarm/src/ParticleMovementHandler.c Swarm/src/ParticleMovementHandler.cxx Swarm/src/ParticleShadowSync.c Swarm/src/ParticleShadowSync.cxx Swarm/src/PerCellParticleLayout.c Swarm/src/PerCellParticleLayout.cxx Swarm/src/PlaneParticleLayout.c Swarm/src/PlaneParticleLayout.cxx Swarm/src/Random.c Swarm/src/Random.cxx Swarm/src/RandomParticleLayout.c Swarm/src/RandomParticleLayout.cxx Swarm/src/SingleCellLayout.c Swarm/src/SingleCellLayout.cxx Swarm/src/SpaceFillerParticleLayout.c Swarm/src/SpaceFillerParticleLayout.cxx Swarm/src/StandardParticle.c Swarm/src/StandardParticle.cxx Swarm/src/SwarmClass.c Swarm/src/SwarmClass.cxx Swarm/src/SwarmDump.c Swarm/src/SwarmDump.cxx Swarm/src/SwarmOutput.c Swarm/src/SwarmOutput.cxx Swarm/src/SwarmShapeVC.c Swarm/src/SwarmShapeVC.cxx Swarm/src/SwarmVariable.c Swarm/src/SwarmVariable.cxx Swarm/src/SwarmVariable_Register.c Swarm/src/SwarmVariable_Register.cxx Swarm/src/Swarm_Register.c Swarm/src/Swarm_Register.cxx Swarm/src/TriGaussParticleLayout.c Swarm/src/TriGaussParticleLayout.cxx Swarm/src/TriSingleCellLayout.c Swarm/src/TriSingleCellLayout.cxx Swarm/src/UnionParticleLayout.c Swarm/src/UnionParticleLayout.cxx Swarm/src/WithinShapeParticleLayout.c Swarm/src/WithinShapeParticleLayout.cxx Swarm/tests/Bouncer/Bouncer.c Swarm/tests/Bouncer/Bouncer.cxx Swarm/tests/ElementCellLayoutSuite.c Swarm/tests/ElementCellLayoutSuite.cxx Swarm/tests/GaussLayoutSingleCellSuite.c Swarm/tests/GaussLayoutSingleCellSuite.cxx Swarm/tests/GaussLayoutSuite.c Swarm/tests/GaussLayoutSuite.cxx Swarm/tests/ManualParticleLayoutSuite.c Swarm/tests/ManualParticleLayoutSuite.cxx Swarm/tests/ParticleCoordsSuite.c Swarm/tests/ParticleCoordsSuite.cxx Swarm/tests/ShadowSyncSuite.c Swarm/tests/ShadowSyncSuite.cxx Swarm/tests/SingleAttractor/SingleAttractor.c Swarm/tests/SingleAttractor/SingleAttractor.cxx Swarm/tests/SingleAttractorSuite.c Swarm/tests/SingleAttractorSuite.cxx Swarm/tests/SingleCellLayoutSuite.c Swarm/tests/SingleCellLayoutSuite.cxx Swarm/tests/SpaceFillerParticleLayoutSuite.c Swarm/tests/SpaceFillerParticleLayoutSuite.cxx Swarm/tests/Spinner/Spinner.c Swarm/tests/Spinner/Spinner.cxx Swarm/tests/SwarmDumpAndLoadSuite.c Swarm/tests/SwarmDumpAndLoadSuite.cxx Swarm/tests/SwarmOutputSuite.c Swarm/tests/SwarmOutputSuite.cxx Swarm/tests/SwarmSuite.c Swarm/tests/SwarmSuite.cxx Swarm/tests/VaryingCornerAttractors/VaryingCornerAttractors.c Swarm/tests/VaryingCornerAttractors/VaryingCornerAttractors.cxx Swarm/tests/WithinShapeParticleLayoutSuite.c Swarm/tests/WithinShapeParticleLayoutSuite.cxx Utils/src/AllElementsVC.c Utils/src/AllElementsVC.cxx Utils/src/AllNodesVC.c Utils/src/AllNodesVC.cxx Utils/src/ContactVC.c Utils/src/ContactVC.cxx Utils/src/CornerVC.c Utils/src/CornerVC.cxx Utils/src/DofLayout.c Utils/src/DofLayout.cxx Utils/src/DomainContext.c Utils/src/DomainContext.cxx Utils/src/FieldVariable.c Utils/src/FieldVariable.cxx Utils/src/FieldVariable_Register.c Utils/src/FieldVariable_Register.cxx Utils/src/Finalise.c Utils/src/Finalise.cxx Utils/src/Init.c Utils/src/Init.cxx Utils/src/InnerWallVC.c Utils/src/InnerWallVC.cxx Utils/src/LinearRegression.c Utils/src/LinearRegression.cxx Utils/src/MeshBoundaryShape.c Utils/src/MeshBoundaryShape.cxx Utils/src/MeshShapeVC.c Utils/src/MeshShapeVC.cxx Utils/src/NewRemesher.c Utils/src/NewRemesher.cxx Utils/src/Operator.c Utils/src/Operator.cxx Utils/src/OperatorFieldVariable.c Utils/src/OperatorFieldVariable.cxx Utils/src/RegularMeshUtils.c Utils/src/RegularMeshUtils.cxx Utils/src/RegularRemesher.c Utils/src/RegularRemesher.cxx Utils/src/RegularRemesherCmpt.c Utils/src/RegularRemesherCmpt.cxx Utils/src/ShapeAdvector.c Utils/src/ShapeAdvector.cxx Utils/src/SobolGenerator.c Utils/src/SobolGenerator.cxx Utils/src/TimeIntegrand.c Utils/src/TimeIntegrand.cxx Utils/src/TimeIntegrator.c Utils/src/TimeIntegrator.cxx Utils/src/WallVC.c Utils/src/WallVC.cxx Utils/tests/AllNodesVCSuite.c Utils/tests/AllNodesVCSuite.cxx Utils/tests/CompositeVCSuite.c Utils/tests/CompositeVCSuite.cxx Utils/tests/CornerVCSuite.c Utils/tests/CornerVCSuite.cxx Utils/tests/DofLayoutSuite.c Utils/tests/DofLayoutSuite.cxx Utils/tests/FieldVariableRegisterSuite.c Utils/tests/FieldVariableRegisterSuite.cxx Utils/tests/OperatorFieldVariableSuite.c Utils/tests/OperatorFieldVariableSuite.cxx Utils/tests/RegularMeshUtilsSuite.c Utils/tests/RegularMeshUtilsSuite.cxx Utils/tests/SobolGeneratorSuite.c Utils/tests/SobolGeneratorSuite.cxx Utils/tests/TimeIntegrationSuite.c Utils/tests/TimeIntegrationSuite.cxx Utils/tests/WallVCSuite.c Utils/tests/WallVCSuite.cxx libStgDomain/Toolbox/Toolbox.c libStgDomain/Toolbox/Toolbox.cxx libStgDomain/src/Finalise.c libStgDomain/src/Finalise.cxx libStgDomain/src/Init.c libStgDomain/src/Init.cxx libStgDomain/tests/LibDiscretisationSuite.c libStgDomain/tests/LibDiscretisationSuite.cxx
description:
Rename .c -> .cxx and make configure automatically use c++


diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/ComplexMath.c
--- a/Geometry/src/ComplexMath.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,208 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ComplexMath.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-#include "TrigMath.h"
-#include "ComplexMath.h"
-#include <math.h>
-#include <string.h>
-
-#define a 	self[ REAL_PART ]
-#define b 	self[ IMAG_PART ]
-#define c 	Y[ REAL_PART ]		
-#define d 	Y[ IMAG_PART ]		
-
-/**  
- * X = a + b . i, Y = c + d . i
- * X + Y = (a + b.i) + (c + d.i) = (a + c) + i(b + d) 
-destination may be stored in either X or Y */
-void Cmplx_Add( Cmplx self, Cmplx Y, Cmplx destination ) {
-	destination[ REAL_PART ] = a + c;
-	destination[ IMAG_PART ] = b + d;
-}
-
-/** 
-X = a + b i, Y = c + d i
-X - Y = (a + b.i) - (c + d.i) = (a - c) + i(b - d) 
-destination may be stored in either X or Y */
-void Cmplx_Subtract( Cmplx self, Cmplx Y, Cmplx destination ) {
-	destination[ REAL_PART ] = a - c;
-	destination[ IMAG_PART ] = b - d;
-}
-
-/** 
-X = a + b . i, Y = c + d . i
-X . Y = (a + b.i)(c + d.i) = (ac - bd) + i(ad + bc) 
-destination may be stored in either X or Y */
-void Cmplx_Multiply( Cmplx self, Cmplx Y, Cmplx destination ) {
-	double real = a * c - b * d;
-	double imag = a * d + b * c;
-	destination[ REAL_PART ] = real;
-	destination[ IMAG_PART ] = imag;
-}
-
-/** 
-X = a + b i, Y = c + d i
-X / Y = \frac{a + b i}{c + d i} = \frac{(ac + bd) + i(bc - ad)}{c^2 + d^2} 
-destination may be stored in either X or Y */
-void Cmplx_Division( Cmplx self, Cmplx Y, Cmplx destination ) {
-	double denominator = c * c + d * d;
-	double real = (a * c + b * d)/denominator;
-	double imag = (b * c - a * d)/denominator;
-	
-	destination[ REAL_PART ] = real;
-	destination[ IMAG_PART ] = imag;
-}
-/** Add real to complex number */
-void Cmplx_AddReal( Cmplx self, double real, Cmplx destination ) {
-	destination[ REAL_PART ] = real + a;
-	destination[ IMAG_PART ] = b;
-}
-/** Subtract a complex number from a real number */
-void Cmplx_RealMinusCmplx( Cmplx self, double real, Cmplx destination ) {
-	destination[ REAL_PART ] = real - a;
-	destination[ IMAG_PART ] = -b;
-}
-
-/**  
-x(a + bi) = xa + xb i */
-void Cmplx_RealMultiply( Cmplx self, double real, Cmplx destination ) {
-	destination[ REAL_PART ] = real * a;
-	destination[ IMAG_PART ] = real * b;
-}
-
-/** 
-x/(a + bi) = x/(a^2 + b^2) * (a - bi) */
-void Cmplx_RealDivideByCmplx( Cmplx self, double real, Cmplx destination ) {
-	double factor = real/(a*a + b*b);
-	destination[ REAL_PART ] = a * factor;
-	destination[ IMAG_PART ] = -b * factor;
-}
-
-/** exp( a + bi ) = exp( a ) [ cos(b) + i sin(b) ] */
-void Cmplx_Exp( Cmplx self, Cmplx destination ) {
-	double realPart = self[ REAL_PART ];
-	double imagPart = self[ IMAG_PART ];
-
-	destination[ REAL_PART ] = exp( realPart ) * cos( imagPart );
-	destination[ IMAG_PART ] = exp( realPart ) * sin( imagPart );
-}
-/** Copy complex value from one variable to another. 
-This nicely replaces = sign for assignments */
-void Cmplx_Copy( Cmplx X, Cmplx destination ) {
-	memcpy( destination, X, sizeof(Cmplx) );
-}
-
-/** Sets a complex variable to zero */
-void Cmplx_Zero( Cmplx X ) {
-	memset( X, 0, sizeof(Cmplx) );
-}
-
-/**
-X = a + b i
-\bar X = a - b i
-conjugate may be stored in X */
-void Cmplx_Conjugate( Cmplx self, Cmplx conjugate ) {
-	conjugate[ REAL_PART ] = a;
-	conjugate[ IMAG_PART ] = -b;
-}
-
-/** 
-Defined as per: Eric W. Weisstein. "Complex Argument." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ComplexArgument.html */
-double Cmplx_Argument( Cmplx self ) {
-	double argument = atan( b / a );
-	
-	if ( a > 0.0 ) 		/* If number is in first or fourth quadrant */
-		return argument;
-	else if ( a < 0.0 ) {
-		if ( b > 0.0 ) /* Number is in Second Quadrant */
-			return argument + M_PI;  
-		else           /* Number is in Third Quadrant */
-			return argument - M_PI;  
-	}
-	/* If a == 0 then: arg(x) = 
-		\pi/2     if b > 0.0 
-		undefined if b == 0.0 
-		-\pi/2    if b < 0.0 */
-	else {
-		if      ( b > 0.0 ) return  M_PI/2;
-		else if ( b < 0.0 ) return -M_PI/2;
-		else                return  0.0;
-	}
-}
-
-/** 
-X = a + b i
-|X| = \sqrt{a^2 + b^2}
- */
-double Cmplx_Modulus( Cmplx self ) {
-	return sqrt( a * a + b * b );
-}
-
-/** 
-X = a + b i = |X|(\cos(\theta) + i \sin( \theta )) = |X| e^{i\theta}
-X^n = (|X| e^{i\theta})^n = |X|^n e^{i n \theta} = |X|^n (cos(\theta) + i sin(\theta) )
-destination may be stored in 'self' */
-void Cmplx_RealPower( Cmplx self, double y, Cmplx destination ) {
-	double mod   = pow( Cmplx_Modulus(self), y );
-	double theta = Cmplx_Argument( self ) * y;
-
-	destination[ REAL_PART ] = mod * cos(theta);
-	destination[ IMAG_PART ] = mod * sin(theta);
-}
-
-/** 
-see Eric W. Weisstein. "Complex Exponentiation." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ComplexExponentiation.html
-destination may be stored in either 'self' or 'power' */
-void Cmplx_CmplxPower( Cmplx self, Cmplx Y, Cmplx destination ) {
-	double argX = Cmplx_Argument( self );
-	double modXSquared = a*a + b*b;
-	double mod   = pow( modXSquared, c * 0.5 ) * exp( -argX * d );
-	double theta = argX * c + 0.5 * d * log(modXSquared);
-
-	destination[ REAL_PART ] = mod * cos(theta);
-	destination[ IMAG_PART ] = mod * sin(theta);
-}
-
-/** Rotate complex value through an angle in radians. 
-This rotates the complex number on the complex plane. */
-void Cmplx_Rotate( Cmplx self, double angle, Cmplx dest ) {
-	Cmplx rotationFactor;
-
-	rotationFactor[ REAL_PART ] = cos( angle );
-	rotationFactor[ IMAG_PART ] = sin( angle );
-
-	Cmplx_Multiply( self, rotationFactor, dest );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/ComplexMath.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/ComplexMath.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,208 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ComplexMath.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+#include "TrigMath.h"
+#include "ComplexMath.h"
+#include <math.h>
+#include <string.h>
+
+#define a 	self[ REAL_PART ]
+#define b 	self[ IMAG_PART ]
+#define c 	Y[ REAL_PART ]		
+#define d 	Y[ IMAG_PART ]		
+
+/**  
+ * X = a + b . i, Y = c + d . i
+ * X + Y = (a + b.i) + (c + d.i) = (a + c) + i(b + d) 
+destination may be stored in either X or Y */
+void Cmplx_Add( Cmplx self, Cmplx Y, Cmplx destination ) {
+	destination[ REAL_PART ] = a + c;
+	destination[ IMAG_PART ] = b + d;
+}
+
+/** 
+X = a + b i, Y = c + d i
+X - Y = (a + b.i) - (c + d.i) = (a - c) + i(b - d) 
+destination may be stored in either X or Y */
+void Cmplx_Subtract( Cmplx self, Cmplx Y, Cmplx destination ) {
+	destination[ REAL_PART ] = a - c;
+	destination[ IMAG_PART ] = b - d;
+}
+
+/** 
+X = a + b . i, Y = c + d . i
+X . Y = (a + b.i)(c + d.i) = (ac - bd) + i(ad + bc) 
+destination may be stored in either X or Y */
+void Cmplx_Multiply( Cmplx self, Cmplx Y, Cmplx destination ) {
+	double real = a * c - b * d;
+	double imag = a * d + b * c;
+	destination[ REAL_PART ] = real;
+	destination[ IMAG_PART ] = imag;
+}
+
+/** 
+X = a + b i, Y = c + d i
+X / Y = \frac{a + b i}{c + d i} = \frac{(ac + bd) + i(bc - ad)}{c^2 + d^2} 
+destination may be stored in either X or Y */
+void Cmplx_Division( Cmplx self, Cmplx Y, Cmplx destination ) {
+	double denominator = c * c + d * d;
+	double real = (a * c + b * d)/denominator;
+	double imag = (b * c - a * d)/denominator;
+	
+	destination[ REAL_PART ] = real;
+	destination[ IMAG_PART ] = imag;
+}
+/** Add real to complex number */
+void Cmplx_AddReal( Cmplx self, double real, Cmplx destination ) {
+	destination[ REAL_PART ] = real + a;
+	destination[ IMAG_PART ] = b;
+}
+/** Subtract a complex number from a real number */
+void Cmplx_RealMinusCmplx( Cmplx self, double real, Cmplx destination ) {
+	destination[ REAL_PART ] = real - a;
+	destination[ IMAG_PART ] = -b;
+}
+
+/**  
+x(a + bi) = xa + xb i */
+void Cmplx_RealMultiply( Cmplx self, double real, Cmplx destination ) {
+	destination[ REAL_PART ] = real * a;
+	destination[ IMAG_PART ] = real * b;
+}
+
+/** 
+x/(a + bi) = x/(a^2 + b^2) * (a - bi) */
+void Cmplx_RealDivideByCmplx( Cmplx self, double real, Cmplx destination ) {
+	double factor = real/(a*a + b*b);
+	destination[ REAL_PART ] = a * factor;
+	destination[ IMAG_PART ] = -b * factor;
+}
+
+/** exp( a + bi ) = exp( a ) [ cos(b) + i sin(b) ] */
+void Cmplx_Exp( Cmplx self, Cmplx destination ) {
+	double realPart = self[ REAL_PART ];
+	double imagPart = self[ IMAG_PART ];
+
+	destination[ REAL_PART ] = exp( realPart ) * cos( imagPart );
+	destination[ IMAG_PART ] = exp( realPart ) * sin( imagPart );
+}
+/** Copy complex value from one variable to another. 
+This nicely replaces = sign for assignments */
+void Cmplx_Copy( Cmplx X, Cmplx destination ) {
+	memcpy( destination, X, sizeof(Cmplx) );
+}
+
+/** Sets a complex variable to zero */
+void Cmplx_Zero( Cmplx X ) {
+	memset( X, 0, sizeof(Cmplx) );
+}
+
+/**
+X = a + b i
+\bar X = a - b i
+conjugate may be stored in X */
+void Cmplx_Conjugate( Cmplx self, Cmplx conjugate ) {
+	conjugate[ REAL_PART ] = a;
+	conjugate[ IMAG_PART ] = -b;
+}
+
+/** 
+Defined as per: Eric W. Weisstein. "Complex Argument." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ComplexArgument.html */
+double Cmplx_Argument( Cmplx self ) {
+	double argument = atan( b / a );
+	
+	if ( a > 0.0 ) 		/* If number is in first or fourth quadrant */
+		return argument;
+	else if ( a < 0.0 ) {
+		if ( b > 0.0 ) /* Number is in Second Quadrant */
+			return argument + M_PI;  
+		else           /* Number is in Third Quadrant */
+			return argument - M_PI;  
+	}
+	/* If a == 0 then: arg(x) = 
+		\pi/2     if b > 0.0 
+		undefined if b == 0.0 
+		-\pi/2    if b < 0.0 */
+	else {
+		if      ( b > 0.0 ) return  M_PI/2;
+		else if ( b < 0.0 ) return -M_PI/2;
+		else                return  0.0;
+	}
+}
+
+/** 
+X = a + b i
+|X| = \sqrt{a^2 + b^2}
+ */
+double Cmplx_Modulus( Cmplx self ) {
+	return sqrt( a * a + b * b );
+}
+
+/** 
+X = a + b i = |X|(\cos(\theta) + i \sin( \theta )) = |X| e^{i\theta}
+X^n = (|X| e^{i\theta})^n = |X|^n e^{i n \theta} = |X|^n (cos(\theta) + i sin(\theta) )
+destination may be stored in 'self' */
+void Cmplx_RealPower( Cmplx self, double y, Cmplx destination ) {
+	double mod   = pow( Cmplx_Modulus(self), y );
+	double theta = Cmplx_Argument( self ) * y;
+
+	destination[ REAL_PART ] = mod * cos(theta);
+	destination[ IMAG_PART ] = mod * sin(theta);
+}
+
+/** 
+see Eric W. Weisstein. "Complex Exponentiation." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ComplexExponentiation.html
+destination may be stored in either 'self' or 'power' */
+void Cmplx_CmplxPower( Cmplx self, Cmplx Y, Cmplx destination ) {
+	double argX = Cmplx_Argument( self );
+	double modXSquared = a*a + b*b;
+	double mod   = pow( modXSquared, c * 0.5 ) * exp( -argX * d );
+	double theta = argX * c + 0.5 * d * log(modXSquared);
+
+	destination[ REAL_PART ] = mod * cos(theta);
+	destination[ IMAG_PART ] = mod * sin(theta);
+}
+
+/** Rotate complex value through an angle in radians. 
+This rotates the complex number on the complex plane. */
+void Cmplx_Rotate( Cmplx self, double angle, Cmplx dest ) {
+	Cmplx rotationFactor;
+
+	rotationFactor[ REAL_PART ] = cos( angle );
+	rotationFactor[ IMAG_PART ] = sin( angle );
+
+	Cmplx_Multiply( self, rotationFactor, dest );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/ComplexVectorMath.c
--- a/Geometry/src/ComplexVectorMath.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,552 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
-**	Kathleen M. Humble, Computational Scientist, VPAC. (khumble at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ComplexVectorMath.c 3677 2006-07-14 11:03:24Z KathleenHumble $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "ComplexMath.h"
-#include "VectorMath.h"
-#include "ComplexVectorMath.h"
-#include "TrigMath.h"
-
-#include <math.h>
-#include <assert.h>
-
-/**(Assumes <=3D),  Set one ComplexVector to another */
-void ComplexVector_Set(CoordC set, CoordC dest) {
-	dest[0][REAL_PART] = set[0][REAL_PART];
-	dest[0][IMAG_PART] = set[0][IMAG_PART];
-	dest[1][REAL_PART] = set[1][REAL_PART];
-	dest[1][IMAG_PART] = set[1][IMAG_PART];
-	dest[2][REAL_PART] = set[2][REAL_PART];
-	dest[2][IMAG_PART] = set[2][IMAG_PART];
-}
-
-/**(Assumes 3D),  Set complex numbers to entries of function.
-One drawback, scalars must already be defined as complex numbers */
-void ComplexVector_SetScalar( Cmplx a, Cmplx b, Cmplx c, CoordC dest ) {
-	dest[0][REAL_PART] = a[REAL_PART];
-	dest[0][IMAG_PART] = a[IMAG_PART];
-	dest[1][REAL_PART] = b[REAL_PART];
-	dest[1][IMAG_PART] = b[IMAG_PART];
-	dest[2][REAL_PART] = c[REAL_PART];
-	dest[2][IMAG_PART] = c[IMAG_PART];
-
-}
-
-
-/** (Assumes 3D), Add two complex vectors:  dest = a + b */
-void ComplexVector_Add( CoordC a, CoordC b, CoordC dest ) {
-	Cmplx_Add( a[0], b[0], dest[0] );
-	Cmplx_Add( a[1], b[1], dest[1] );
-	Cmplx_Add( a[2], b[2], dest[2] );
-}	
-		
-/** (Assumes 3D), Subtract two complex vectors: dest = a - b */
-void ComplexVector_Sub( CoordC a, CoordC b, CoordC dest ) {
-	Cmplx_Subtract( a[0], b[0], dest[0] );
-	Cmplx_Subtract( a[1], b[1], dest[1] );
-	Cmplx_Subtract( a[2], b[2], dest[2] );
-}
-			
-/** (Assumes 3D), Returns the dot product of two complex vectors, a and b */
-void ComplexVector_Dot(CoordC a, CoordC b, Cmplx destSum ) {
-	CoordC dest;
-
-	Cmplx_Multiply(a[0], b[0], dest[0]);
-	Cmplx_Multiply(a[1], b[1], dest[1]);
-	Cmplx_Multiply(a[2], b[2], dest[2]);
-	Cmplx_Add(dest[0], dest[1], destSum);
-	Cmplx_Add(destSum, dest[2], destSum);
-	
-}	
-	
-/** (Assumes 3D), Multiply two complex vectors: dest = a * s */
-void ComplexVector_Mult(CoordC a, Cmplx s, CoordC dest ) {
-	Cmplx_Multiply(a[0], s, dest[0]);
-	Cmplx_Multiply(a[1], s, dest[1]);
-	Cmplx_Multiply(a[2], s, dest[2]);
-}
-
-/** (Assumes 3D), Multiply complex vector by real number */ 
-void ComplexVector_MultReal(CoordC a, double valueReal, CoordC dest ) {
-	Cmplx value;
-	value[REAL_PART] = valueReal;
-	value[IMAG_PART] = 0.0;
-	Cmplx_Multiply(a[0], value, dest[0]);
-	Cmplx_Multiply(a[1], value, dest[1]);
-	Cmplx_Multiply(a[2], value, dest[2]);
-}
-
-/** (Assumes 3D), Returns the magnitude of complex vector a */
-double ComplexVector_Mag(CoordC a ) {
-	double a_0, a_1, a_2;
-	a_0 = Cmplx_Modulus(a[0]);
-	a_1 = Cmplx_Modulus(a[1]);
-	a_2 = Cmplx_Modulus(a[2]);
-	return sqrt(a_0*a_0 + a_1*a_1 + a_2*a_2); 	
-}
-
-/** (Assumes 3D), complexVector projection of a onto b, store result in dest */
-void ComplexVector_Proj(CoordC a, CoordC b, CoordC dest ) {
-		/* Calculate norm of b */
-		Cmplx tmp;
-		ComplexVector_Norm( b, dest);
-		/* Calculate proj of a onto b */
-		ComplexVector_Dot( a, b, tmp );
-		ComplexVector_Mult( dest, tmp, dest );
-}
-	
-/** (Assumes 3D), Calculates cross product of two complex vectors */	
-void ComplexVector_Cross( CoordC a, CoordC b, CoordC dest ) {
-
-	Cmplx 	ans1, ans2;
-	 
-	Cmplx_Multiply(a[1], b[2], ans1);
-	Cmplx_Multiply(a[2], b[1], ans2);
-	Cmplx_Subtract(ans1, ans2, dest[0]);
-	
-	Cmplx_Multiply(a[2], b[0], ans1);
-	Cmplx_Multiply(a[0], b[2], ans2);
-	Cmplx_Subtract(ans1, ans2, dest[1]);
-	
-	Cmplx_Multiply(a[0], b[1], ans1);
-	Cmplx_Multiply(a[1], b[0], ans2);
-	Cmplx_Subtract(ans1, ans2, dest[2]);
-
-}
-
-/** (Assumes 3D), Divide complex vector by complex number */
-void ComplexVector_Div( CoordC a, Cmplx s, CoordC dest )
-{
-	Cmplx	inv, one;
-	one[REAL_PART] = 1.0;
-	one[IMAG_PART] = 0.0;
-	
-	Cmplx_Division( one, s, inv );
-
-	
-	Cmplx_Multiply(a[0], inv, dest[0]);
-	Cmplx_Multiply(a[1], inv, dest[1]);
-	Cmplx_Multiply(a[2], inv, dest[2]);
-}
-
-/** (Assumes 3D), Normalises complex vector */
-void ComplexVector_Norm(CoordC a, CoordC dest) {
-	double invMag;
-	
-	 
-	invMag = 1.0 / ComplexVector_Mag( a );
-	ComplexVector_MultReal(a, invMag, dest);
-
-}
-
-/** (Assumes 3D), Swaps coords based on i,j,k input */
-void ComplexVector_Swizzle( CoordC src, unsigned char iInd, 
-		unsigned char jInd, unsigned char kInd, CoordC dst ) {
-	CoordC dummy;
-	assert( iInd < 3 && jInd < 3 && kInd < 3 );
-	dummy[0][REAL_PART] = src[iInd][REAL_PART];
-	dummy[0][IMAG_PART] = src[iInd][IMAG_PART];
-	dummy[1][REAL_PART] = src[jInd][REAL_PART];
-	dummy[1][IMAG_PART] = src[jInd][IMAG_PART];
-	dummy[2][REAL_PART] = src[kInd][REAL_PART];
-	dummy[2][IMAG_PART] = src[kInd][IMAG_PART];
-		
-	dst[0][REAL_PART] = dummy[0][REAL_PART];
-	dst[0][IMAG_PART] = dummy[0][IMAG_PART];	
-	dst[1][REAL_PART] = dummy[1][REAL_PART];
-	dst[1][IMAG_PART] = dummy[1][IMAG_PART];
-	dst[2][REAL_PART] = dummy[2][REAL_PART];
-	dst[2][IMAG_PART] = dummy[2][IMAG_PART];
-}
-
-
-/** StGermain_ComplexRotateVector takes an argument 'vectorToRotate', and rotates it through 
-three angles for the x, y and z coordinates.(\alpha, \beta, \gama) respectively I believe.
-The angles should be reals, and in radians.
-This function cannot use Rodrigues' Rotation Formula because that is only defined for reals.
-See: 
-http://mathworld.wolfram.com/EulerAngles.html
-http://mathworld.wolfram.com/EulerParameters.html */
-void StGermain_RotateComplexVector(Cmplx* vector, double alpha, double beta, 
-			double gama, Cmplx* rotatedVector) {
-	double rotationMatrix[3][3]; 	/* Indicies [Column][Row][Real or Imag] */
-	/*double e0, e1, e2, e3; */
-				
-	Cmplx r_0, r_1, r_2, tmp ;
-
-	rotationMatrix[0][0] =   cos(beta) * cos(gama);
-	rotationMatrix[0][1] =   cos(beta) * sin(gama); 
-	rotationMatrix[0][2] =  -sin(beta);
-				
-	rotationMatrix[1][0] = -cos(alpha) * sin(gama) + sin(alpha) * sin(beta) * cos(gama);
-	rotationMatrix[1][1] =  cos(alpha) * cos(gama) + sin(alpha) * sin(beta) * sin(gama);
-	rotationMatrix[1][2] =  sin(alpha) * cos(beta);
-	
-	rotationMatrix[2][0] =  sin(alpha) * sin(gama) + cos(alpha) * sin(beta) * cos(gama);
-	rotationMatrix[2][1] = -sin(alpha) * cos(gama) + cos(alpha) * sin(beta) * sin(gama);
-	rotationMatrix[2][2] = 	cos(alpha) * cos(beta);		
-				
-
-	/* x direction */
-	Cmplx_RealMultiply(vector[0], rotationMatrix[0][0], r_0);
-	Cmplx_RealMultiply(vector[1], rotationMatrix[0][1], r_1);
-	Cmplx_RealMultiply(vector[2], rotationMatrix[0][2], r_2);
-
-	Cmplx_Add(r_0, r_1, tmp);
-	Cmplx_Add(tmp, r_2, rotatedVector[0]);
-
-	
-	/* y direction */
-	Cmplx_RealMultiply(vector[0], rotationMatrix[1][0], r_0);
-	Cmplx_RealMultiply(vector[1], rotationMatrix[1][1], r_1);
-	Cmplx_RealMultiply(vector[2], rotationMatrix[1][2], r_2);
-
-	Cmplx_Add(r_0, r_1, tmp);
-	Cmplx_Add(tmp, r_2, rotatedVector[1]);
-	
-	/* z direction */
-	Cmplx_RealMultiply(vector[0], rotationMatrix[2][0], r_0);
-	Cmplx_RealMultiply(vector[1], rotationMatrix[2][1], r_1);
-	Cmplx_RealMultiply(vector[2], rotationMatrix[2][2], r_2);
-
-	Cmplx_Add(r_0, r_1, tmp);
-	Cmplx_Add(tmp, r_2, rotatedVector[2]);
-}		
-
-/** StGermain_RotateCoordinateAxisComplex multiplies a vector with a Rotation Matrix to rotate it around a co-ordinate axis -
-Is a simpler function than StGermain_RotateComplexVector for more specific cases where the vector is to be rotated around one of the axes of the co-ordinate system. The arguments are the same except the the 'axis' argument is of type 'Index' which could be either I_AXIS, J_AXIS or K_AXIS. Vectors have to be the size of 3 doubles.
-See, Eric W. Weisstein. "Rotation Matrix." 
-From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/RotationMatrix.htm */
-void StGermain_RotateCoordinateAxisComplex( Cmplx* vector, 
-			Index axis, double theta, Cmplx* rotatedVector ) {
-	
-	Cmplx r_1, r_2;
-	/* Rotation around one axis will always leave the component on that axis alone */
-	rotatedVector[axis][REAL_PART] = vector[axis][REAL_PART];
-	rotatedVector[axis][IMAG_PART] = vector[axis][IMAG_PART];
-	/*printf("axis %d, %2.3f", axis, vector[axis][REAL_PART]); 				 */
-	switch (axis) {
-		case K_AXIS: /* Rotate around Z axis */
-			Cmplx_RealMultiply(vector[0], cos(theta), r_1);
-			Cmplx_RealMultiply(vector[1], sin(theta), r_2);
-			Cmplx_Add(r_1, r_2, rotatedVector[0]);
-		
-			Cmplx_RealMultiply(vector[0], sin(theta), r_1);
-			Cmplx_RealMultiply(vector[1], cos(theta), r_2);
-			Cmplx_Subtract(r_2, r_1, rotatedVector[1]);
-			return;
-		case I_AXIS:  /* Rotate around X axis */
-			Cmplx_RealMultiply(vector[1], cos(theta), r_1);
-			Cmplx_RealMultiply(vector[2], sin(theta), r_2);
-			Cmplx_Add(r_1, r_2, rotatedVector[1]);
-		
-			Cmplx_RealMultiply(vector[1], sin(theta), r_1);
-			Cmplx_RealMultiply(vector[2], cos(theta), r_2);
-			Cmplx_Subtract(r_2, r_1, rotatedVector[2] );
-			return;
-		case J_AXIS: /* Rotate around Y axis */
-			Cmplx_RealMultiply(vector[0], cos(theta), r_1);
-			Cmplx_RealMultiply(vector[2], sin(theta), r_2);
-			Cmplx_Subtract(r_1, r_2, rotatedVector[0] );
-		
-			Cmplx_RealMultiply(vector[0], sin(theta), r_1);
-			Cmplx_RealMultiply(vector[2], cos(theta), r_2);
-			Cmplx_Add(r_1, r_2, rotatedVector[2]) ;
-			return;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"ComplexVectorMath"  );
-			Journal_Printf( error, "Impossible axis to rotate around in %s.", __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"ComplexVectorMath"  ),
-				"Error in '%s':Impossible axis to rotate around. \n", __func__);
-		}
-	}
-}
-
-/** Subtracts one complex vector from another - 
-destination = vector1 - vector2
-Destination vector may be the same as either of the other two input vectors 
-Function is optimised for 1-3 dimensions but will work for any dimension */
-void StGermain_ComplexVectorSubtraction(Cmplx* destination, Cmplx* vector1, Cmplx* vector2, Index dim) {
-
-	switch (dim) {
-		case 3:
-			Cmplx_Subtract(vector1[2], vector2[2], destination[2]);			
-			
-		case 2:
-			Cmplx_Subtract(vector1[1], vector2[1], destination[1]);
-		case 1: 
-			Cmplx_Subtract(vector1[0], vector2[0], destination[0]);
-			return;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				Cmplx_Subtract(vector1[d], vector2[d], destination[d]);
-			return;
-		}
-	}	
-}
-
-/** Adds two vectors - 
-destination = vector1 + vector2
-Destination vector may be the same as either of the other two input vectors 
-Function is optimised for 1-3 dimensions but will work for any dimension */
-void StGermain_ComplexVectorAddition(Cmplx* destination, Cmplx* vector1, Cmplx* vector2, Index dim) {
-	switch (dim) {
-		case 3: 
-			Cmplx_Add(vector1[2], vector2[2], destination[2]);	
-		case 2:
-			Cmplx_Add(vector1[1], vector2[1], destination[1]);	
-		case 1: 
-			Cmplx_Add(vector1[0], vector2[0], destination[0]);	
-			return;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				Cmplx_Add(vector1[d], vector2[d], destination[d]);	
-                        /*printf("%f, %f", destination[d][REAL_PART], destination[d][IMAG_PART]); */
-			return;
-		}
-	}	
-}
-
-/** StGermain_ComplexVectorMagnitude calculates the magnitude of a vector
-|v| = \sqrt{ v . v } 
-This function uses function StGermain_ComplexVectorDotProduct to calculate v . v. 
-Vector has to be of size dim doubles */
-double StGermain_ComplexVectorMagnitude(Cmplx* vector, Index dim) {
-	Cmplx dotProduct;
-
-	StGermain_ComplexVectorDotProduct(vector, vector, dim, dotProduct);
-	return sqrt(Cmplx_Modulus(dotProduct));
-}
-
-/** StGermain_ComplexVectorDotProduct calculates the complex valued dot product of two
-complex vectors
-*/
-void StGermain_ComplexVectorDotProduct(Cmplx* vector1, Cmplx* vector2, Dimension_Index dim, Cmplx dotProduct) {
-	Cmplx tmp;
-	dotProduct[REAL_PART] = 0.0;
-	dotProduct[IMAG_PART] = 0.0;
-
-	switch (dim) {
-		case 3: {
-			Cmplx_Multiply(vector1[2], vector2[2], tmp);
-			Cmplx_Add(dotProduct, tmp, dotProduct);
-		}
-		case 2: {
-			Cmplx_Multiply(vector1[1], vector2[1], tmp);
-			Cmplx_Add(dotProduct, tmp, dotProduct);
-		}
-		case 1: {
-			Cmplx_Multiply(vector1[0], vector2[0], tmp);
-			Cmplx_Add(dotProduct, tmp, dotProduct);
-			break;
-		}
-		default: {
-			Dimension_Index d;
-			for ( d = 0 ; d < dim ; d++ ) {
-				Cmplx_Multiply(vector1[d], vector2[d], tmp);
-				Cmplx_Add(dotProduct, tmp, dotProduct);
-			}
-			break;
-		}
-	}
-	
-	
-}
-
-/** See Eric W. Weisstein. "Cross Product." 
-From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
-Tested against http://www.engplanet.com/redirect.html?3859 */
-void StGermain_ComplexVectorCrossProduct(Cmplx* destination, Cmplx* vector1, Cmplx* vector2) {
-	Cmplx c_1, c_2;
-	/*x direction */
-	Cmplx_Multiply(vector1[1], vector2[2], c_1);
-	Cmplx_Multiply(vector1[2], vector2[1], c_2);
-	Cmplx_Subtract(c_1, c_2, destination[0]);
-
-	/*y direction */
-	Cmplx_Multiply(vector1[2], vector2[0], c_1);
-	Cmplx_Multiply(vector1[0], vector2[2], c_2);
-	Cmplx_Subtract(c_1, c_2, destination[1]);
-	/*z direction */
-	Cmplx_Multiply(vector1[0], vector2[1], c_1);
-	Cmplx_Multiply(vector1[1], vector2[0], c_2);
-	Cmplx_Subtract(c_1, c_2, destination[2]);
-}
-
-/** StGermain_VectorCrossProductMagnitude - See Eric W. Weisstein. "Cross Product." 
-From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
-|a \times b| = |a||b|\sqrt{ 1 - (\hat a . \hat b)^2}
-*/
-void StGermain_ComplexVectorCrossProductMagnitude( Cmplx* vector1, Cmplx* vector2, Dimension_Index dim, Cmplx tmp ) {
-	double mag1       = StGermain_ComplexVectorMagnitude( vector1, dim );
-	double mag2       = StGermain_ComplexVectorMagnitude( vector2, dim );
-	Cmplx dotProduct, dotSquared;
-	StGermain_ComplexVectorDotProduct( vector1, vector2, dim, dotProduct );
-	
-	Cmplx_Multiply(dotProduct, dotProduct, dotSquared);
-	Cmplx_RealMultiply(dotSquared, 1.0/(mag1 * mag1 * mag2 * mag2), tmp);
-	Cmplx_RealMinusCmplx(tmp, 1.0, tmp); 
-	Cmplx_RealPower(tmp, 0.5, tmp);
-	Cmplx_RealMultiply(tmp, (mag1 * mag2), tmp);
-	
-}
-
-
-/** StGermain_ComplexScalarTripleProduct - Calculates the scalar vector product of three vectors -
- * see Eric W. Weisstein. "Scalar Triple Product." From MathWorld--A Wolfram Web Resource. 
-	http://mathworld.wolfram.com/ScalarTripleProduct.html
- * Assumes 3 Dimensions */
-void StGermain_ComplexScalarTripleProduct( Cmplx* vectorA, Cmplx* vectorB, Cmplx* vectorC, Cmplx tripleProduct ) {
-	XYZC crossProduct;
-	
-	StGermain_ComplexVectorCrossProduct( crossProduct, vectorB, vectorC );
-	StGermain_ComplexVectorDotProduct( vectorA, crossProduct, 3, tripleProduct );
-	 
-}
-
-
-/** StGermain_ComplexVectorNormalise calculates the magnitude of a vector
-\hat v = frac{v} / {|v|}
-This function uses function StGermain_VectorDotProduct to calculate v . v. 
-Vector has to be of size dim Cmplx */
-void StGermain_ComplexVectorNormalise(Cmplx* vector, Index dim) {
-	double mag;
-
-	mag = StGermain_ComplexVectorMagnitude( vector , dim );
-	switch (dim) {
-		case 3: 
-			Cmplx_RealMultiply(vector[2], 1.0/mag, vector[2]);
-		
-		case 2:
-			Cmplx_RealMultiply(vector[1], 1.0/mag, vector[1]);
-
-		case 1: 
-			Cmplx_RealMultiply(vector[0], 1.0/mag, vector[0]);			
-
-			break;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ )
-				Cmplx_RealMultiply(vector[d], 1.0/mag, vector[d]);
-			break;
-		}
-	}	
-}
-
-
-
-#define STGERMAIN_COMPLEXVECTOR_ONE_THIRD 0.3333333333333333333
-
-/** StGermain_ComplexTriangleCentroid Calculates the position vector to the centroid of a triangle whose vertices are given by position vectors 
-Position vectors have to be of size dim Cmplx */
-void StGermain_ComplexTriangleCentroid( Cmplx* centroid, Cmplx* pos0, Cmplx* pos1, Cmplx* pos2, Index dim) {
-	Cmplx tmp;
-	switch (dim) {
-		case 3:
-			Cmplx_Add(pos0[2], pos1[2], tmp);
-			Cmplx_Add(pos2[2], tmp, tmp);
-			Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[2]);
-			
-		case 2: 
-			Cmplx_Add(pos0[1], pos1[1], tmp);
-			Cmplx_Add(pos2[1], tmp, tmp);
-			Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[1]);
-		case 1:
-			Cmplx_Add(pos0[0], pos1[0], tmp);
-			Cmplx_Add(pos2[0], tmp, tmp);
-			Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[0]);
-			return;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) {
-				Cmplx_Add(pos0[d], pos1[d], tmp);
-				Cmplx_Add(pos2[d], tmp, tmp);
-				Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[d]);
-			}
-			return;
-		}
-	}
-}
-
-/** Prints complex Vector using %g on all entries.
-TODO: would like this to be specified from function call
-with automatic default value
-*/
-void StGermain_PrintComplexVector( Stream* stream, Cmplx* vector, Index dim ) {
-	Index d;
-
-	if ( dim <= 0 ) {
-		Journal_Printf( stream, "{<NON_POSITIVE DIMENSION %d>}\n", dim );
-		return;
-	}
-
-	Journal_Printf( stream, "{");
-	for ( d = 0 ; d < dim - 1 ; d++ ) 
-		Journal_Printf( stream, "%g + i %g, ", vector[d][REAL_PART], vector[d][IMAG_PART] );
-	
-	Journal_Printf( stream, "%g + i %g}\n", vector[d][REAL_PART], vector[d][IMAG_PART] );
-}
-
-/** Converts ComplexVector into a vector,
-but only if there are no non-zero imaginary values. */
-void ComplexVector_ToVector(CoordC complexVector, Dimension_Index dim, Coord vector) {
-	Dimension_Index index;
-	for (index = 0; index < dim; index++) {
-		if (complexVector[index][IMAG_PART] != 0.0) {
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"ComplexVectorMath"  ),
-				"Error in '%s': Complex value in complex vector at index '%s' \n", __func__, index );
-		}
-		else {
-			vector[index] = complexVector[index][REAL_PART];
-		}
-	}
-}
-
-/** Converts vector into Complex vector, seting all imaginary 
-parts to zero */
-void Vector_ToComplexVector(Coord vector, Dimension_Index dim, CoordC complexVector) {
-	Dimension_Index index;
-	for (index = 0; index < dim; index++) {
-		complexVector[index][REAL_PART] = vector[index];
-		complexVector[index][IMAG_PART] = 0.0;
-	}		
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/ComplexVectorMath.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/ComplexVectorMath.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,552 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
+**	Kathleen M. Humble, Computational Scientist, VPAC. (khumble at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ComplexVectorMath.c 3677 2006-07-14 11:03:24Z KathleenHumble $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "ComplexMath.h"
+#include "VectorMath.h"
+#include "ComplexVectorMath.h"
+#include "TrigMath.h"
+
+#include <math.h>
+#include <assert.h>
+
+/**(Assumes <=3D),  Set one ComplexVector to another */
+void ComplexVector_Set(CoordC set, CoordC dest) {
+	dest[0][REAL_PART] = set[0][REAL_PART];
+	dest[0][IMAG_PART] = set[0][IMAG_PART];
+	dest[1][REAL_PART] = set[1][REAL_PART];
+	dest[1][IMAG_PART] = set[1][IMAG_PART];
+	dest[2][REAL_PART] = set[2][REAL_PART];
+	dest[2][IMAG_PART] = set[2][IMAG_PART];
+}
+
+/**(Assumes 3D),  Set complex numbers to entries of function.
+One drawback, scalars must already be defined as complex numbers */
+void ComplexVector_SetScalar( Cmplx a, Cmplx b, Cmplx c, CoordC dest ) {
+	dest[0][REAL_PART] = a[REAL_PART];
+	dest[0][IMAG_PART] = a[IMAG_PART];
+	dest[1][REAL_PART] = b[REAL_PART];
+	dest[1][IMAG_PART] = b[IMAG_PART];
+	dest[2][REAL_PART] = c[REAL_PART];
+	dest[2][IMAG_PART] = c[IMAG_PART];
+
+}
+
+
+/** (Assumes 3D), Add two complex vectors:  dest = a + b */
+void ComplexVector_Add( CoordC a, CoordC b, CoordC dest ) {
+	Cmplx_Add( a[0], b[0], dest[0] );
+	Cmplx_Add( a[1], b[1], dest[1] );
+	Cmplx_Add( a[2], b[2], dest[2] );
+}	
+		
+/** (Assumes 3D), Subtract two complex vectors: dest = a - b */
+void ComplexVector_Sub( CoordC a, CoordC b, CoordC dest ) {
+	Cmplx_Subtract( a[0], b[0], dest[0] );
+	Cmplx_Subtract( a[1], b[1], dest[1] );
+	Cmplx_Subtract( a[2], b[2], dest[2] );
+}
+			
+/** (Assumes 3D), Returns the dot product of two complex vectors, a and b */
+void ComplexVector_Dot(CoordC a, CoordC b, Cmplx destSum ) {
+	CoordC dest;
+
+	Cmplx_Multiply(a[0], b[0], dest[0]);
+	Cmplx_Multiply(a[1], b[1], dest[1]);
+	Cmplx_Multiply(a[2], b[2], dest[2]);
+	Cmplx_Add(dest[0], dest[1], destSum);
+	Cmplx_Add(destSum, dest[2], destSum);
+	
+}	
+	
+/** (Assumes 3D), Multiply two complex vectors: dest = a * s */
+void ComplexVector_Mult(CoordC a, Cmplx s, CoordC dest ) {
+	Cmplx_Multiply(a[0], s, dest[0]);
+	Cmplx_Multiply(a[1], s, dest[1]);
+	Cmplx_Multiply(a[2], s, dest[2]);
+}
+
+/** (Assumes 3D), Multiply complex vector by real number */ 
+void ComplexVector_MultReal(CoordC a, double valueReal, CoordC dest ) {
+	Cmplx value;
+	value[REAL_PART] = valueReal;
+	value[IMAG_PART] = 0.0;
+	Cmplx_Multiply(a[0], value, dest[0]);
+	Cmplx_Multiply(a[1], value, dest[1]);
+	Cmplx_Multiply(a[2], value, dest[2]);
+}
+
+/** (Assumes 3D), Returns the magnitude of complex vector a */
+double ComplexVector_Mag(CoordC a ) {
+	double a_0, a_1, a_2;
+	a_0 = Cmplx_Modulus(a[0]);
+	a_1 = Cmplx_Modulus(a[1]);
+	a_2 = Cmplx_Modulus(a[2]);
+	return sqrt(a_0*a_0 + a_1*a_1 + a_2*a_2); 	
+}
+
+/** (Assumes 3D), complexVector projection of a onto b, store result in dest */
+void ComplexVector_Proj(CoordC a, CoordC b, CoordC dest ) {
+		/* Calculate norm of b */
+		Cmplx tmp;
+		ComplexVector_Norm( b, dest);
+		/* Calculate proj of a onto b */
+		ComplexVector_Dot( a, b, tmp );
+		ComplexVector_Mult( dest, tmp, dest );
+}
+	
+/** (Assumes 3D), Calculates cross product of two complex vectors */	
+void ComplexVector_Cross( CoordC a, CoordC b, CoordC dest ) {
+
+	Cmplx 	ans1, ans2;
+	 
+	Cmplx_Multiply(a[1], b[2], ans1);
+	Cmplx_Multiply(a[2], b[1], ans2);
+	Cmplx_Subtract(ans1, ans2, dest[0]);
+	
+	Cmplx_Multiply(a[2], b[0], ans1);
+	Cmplx_Multiply(a[0], b[2], ans2);
+	Cmplx_Subtract(ans1, ans2, dest[1]);
+	
+	Cmplx_Multiply(a[0], b[1], ans1);
+	Cmplx_Multiply(a[1], b[0], ans2);
+	Cmplx_Subtract(ans1, ans2, dest[2]);
+
+}
+
+/** (Assumes 3D), Divide complex vector by complex number */
+void ComplexVector_Div( CoordC a, Cmplx s, CoordC dest )
+{
+	Cmplx	inv, one;
+	one[REAL_PART] = 1.0;
+	one[IMAG_PART] = 0.0;
+	
+	Cmplx_Division( one, s, inv );
+
+	
+	Cmplx_Multiply(a[0], inv, dest[0]);
+	Cmplx_Multiply(a[1], inv, dest[1]);
+	Cmplx_Multiply(a[2], inv, dest[2]);
+}
+
+/** (Assumes 3D), Normalises complex vector */
+void ComplexVector_Norm(CoordC a, CoordC dest) {
+	double invMag;
+	
+	 
+	invMag = 1.0 / ComplexVector_Mag( a );
+	ComplexVector_MultReal(a, invMag, dest);
+
+}
+
+/** (Assumes 3D), Swaps coords based on i,j,k input */
+void ComplexVector_Swizzle( CoordC src, unsigned char iInd, 
+		unsigned char jInd, unsigned char kInd, CoordC dst ) {
+	CoordC dummy;
+	assert( iInd < 3 && jInd < 3 && kInd < 3 );
+	dummy[0][REAL_PART] = src[iInd][REAL_PART];
+	dummy[0][IMAG_PART] = src[iInd][IMAG_PART];
+	dummy[1][REAL_PART] = src[jInd][REAL_PART];
+	dummy[1][IMAG_PART] = src[jInd][IMAG_PART];
+	dummy[2][REAL_PART] = src[kInd][REAL_PART];
+	dummy[2][IMAG_PART] = src[kInd][IMAG_PART];
+		
+	dst[0][REAL_PART] = dummy[0][REAL_PART];
+	dst[0][IMAG_PART] = dummy[0][IMAG_PART];	
+	dst[1][REAL_PART] = dummy[1][REAL_PART];
+	dst[1][IMAG_PART] = dummy[1][IMAG_PART];
+	dst[2][REAL_PART] = dummy[2][REAL_PART];
+	dst[2][IMAG_PART] = dummy[2][IMAG_PART];
+}
+
+
+/** StGermain_ComplexRotateVector takes an argument 'vectorToRotate', and rotates it through 
+three angles for the x, y and z coordinates.(\alpha, \beta, \gama) respectively I believe.
+The angles should be reals, and in radians.
+This function cannot use Rodrigues' Rotation Formula because that is only defined for reals.
+See: 
+http://mathworld.wolfram.com/EulerAngles.html
+http://mathworld.wolfram.com/EulerParameters.html */
+void StGermain_RotateComplexVector(Cmplx* vector, double alpha, double beta, 
+			double gama, Cmplx* rotatedVector) {
+	double rotationMatrix[3][3]; 	/* Indicies [Column][Row][Real or Imag] */
+	/*double e0, e1, e2, e3; */
+				
+	Cmplx r_0, r_1, r_2, tmp ;
+
+	rotationMatrix[0][0] =   cos(beta) * cos(gama);
+	rotationMatrix[0][1] =   cos(beta) * sin(gama); 
+	rotationMatrix[0][2] =  -sin(beta);
+				
+	rotationMatrix[1][0] = -cos(alpha) * sin(gama) + sin(alpha) * sin(beta) * cos(gama);
+	rotationMatrix[1][1] =  cos(alpha) * cos(gama) + sin(alpha) * sin(beta) * sin(gama);
+	rotationMatrix[1][2] =  sin(alpha) * cos(beta);
+	
+	rotationMatrix[2][0] =  sin(alpha) * sin(gama) + cos(alpha) * sin(beta) * cos(gama);
+	rotationMatrix[2][1] = -sin(alpha) * cos(gama) + cos(alpha) * sin(beta) * sin(gama);
+	rotationMatrix[2][2] = 	cos(alpha) * cos(beta);		
+				
+
+	/* x direction */
+	Cmplx_RealMultiply(vector[0], rotationMatrix[0][0], r_0);
+	Cmplx_RealMultiply(vector[1], rotationMatrix[0][1], r_1);
+	Cmplx_RealMultiply(vector[2], rotationMatrix[0][2], r_2);
+
+	Cmplx_Add(r_0, r_1, tmp);
+	Cmplx_Add(tmp, r_2, rotatedVector[0]);
+
+	
+	/* y direction */
+	Cmplx_RealMultiply(vector[0], rotationMatrix[1][0], r_0);
+	Cmplx_RealMultiply(vector[1], rotationMatrix[1][1], r_1);
+	Cmplx_RealMultiply(vector[2], rotationMatrix[1][2], r_2);
+
+	Cmplx_Add(r_0, r_1, tmp);
+	Cmplx_Add(tmp, r_2, rotatedVector[1]);
+	
+	/* z direction */
+	Cmplx_RealMultiply(vector[0], rotationMatrix[2][0], r_0);
+	Cmplx_RealMultiply(vector[1], rotationMatrix[2][1], r_1);
+	Cmplx_RealMultiply(vector[2], rotationMatrix[2][2], r_2);
+
+	Cmplx_Add(r_0, r_1, tmp);
+	Cmplx_Add(tmp, r_2, rotatedVector[2]);
+}		
+
+/** StGermain_RotateCoordinateAxisComplex multiplies a vector with a Rotation Matrix to rotate it around a co-ordinate axis -
+Is a simpler function than StGermain_RotateComplexVector for more specific cases where the vector is to be rotated around one of the axes of the co-ordinate system. The arguments are the same except the the 'axis' argument is of type 'Index' which could be either I_AXIS, J_AXIS or K_AXIS. Vectors have to be the size of 3 doubles.
+See, Eric W. Weisstein. "Rotation Matrix." 
+From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/RotationMatrix.htm */
+void StGermain_RotateCoordinateAxisComplex( Cmplx* vector, 
+			Index axis, double theta, Cmplx* rotatedVector ) {
+	
+	Cmplx r_1, r_2;
+	/* Rotation around one axis will always leave the component on that axis alone */
+	rotatedVector[axis][REAL_PART] = vector[axis][REAL_PART];
+	rotatedVector[axis][IMAG_PART] = vector[axis][IMAG_PART];
+	/*printf("axis %d, %2.3f", axis, vector[axis][REAL_PART]); 				 */
+	switch (axis) {
+		case K_AXIS: /* Rotate around Z axis */
+			Cmplx_RealMultiply(vector[0], cos(theta), r_1);
+			Cmplx_RealMultiply(vector[1], sin(theta), r_2);
+			Cmplx_Add(r_1, r_2, rotatedVector[0]);
+		
+			Cmplx_RealMultiply(vector[0], sin(theta), r_1);
+			Cmplx_RealMultiply(vector[1], cos(theta), r_2);
+			Cmplx_Subtract(r_2, r_1, rotatedVector[1]);
+			return;
+		case I_AXIS:  /* Rotate around X axis */
+			Cmplx_RealMultiply(vector[1], cos(theta), r_1);
+			Cmplx_RealMultiply(vector[2], sin(theta), r_2);
+			Cmplx_Add(r_1, r_2, rotatedVector[1]);
+		
+			Cmplx_RealMultiply(vector[1], sin(theta), r_1);
+			Cmplx_RealMultiply(vector[2], cos(theta), r_2);
+			Cmplx_Subtract(r_2, r_1, rotatedVector[2] );
+			return;
+		case J_AXIS: /* Rotate around Y axis */
+			Cmplx_RealMultiply(vector[0], cos(theta), r_1);
+			Cmplx_RealMultiply(vector[2], sin(theta), r_2);
+			Cmplx_Subtract(r_1, r_2, rotatedVector[0] );
+		
+			Cmplx_RealMultiply(vector[0], sin(theta), r_1);
+			Cmplx_RealMultiply(vector[2], cos(theta), r_2);
+			Cmplx_Add(r_1, r_2, rotatedVector[2]) ;
+			return;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"ComplexVectorMath"  );
+			Journal_Printf( error, "Impossible axis to rotate around in %s.", __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"ComplexVectorMath"  ),
+				"Error in '%s':Impossible axis to rotate around. \n", __func__);
+		}
+	}
+}
+
+/** Subtracts one complex vector from another - 
+destination = vector1 - vector2
+Destination vector may be the same as either of the other two input vectors 
+Function is optimised for 1-3 dimensions but will work for any dimension */
+void StGermain_ComplexVectorSubtraction(Cmplx* destination, Cmplx* vector1, Cmplx* vector2, Index dim) {
+
+	switch (dim) {
+		case 3:
+			Cmplx_Subtract(vector1[2], vector2[2], destination[2]);			
+			
+		case 2:
+			Cmplx_Subtract(vector1[1], vector2[1], destination[1]);
+		case 1: 
+			Cmplx_Subtract(vector1[0], vector2[0], destination[0]);
+			return;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				Cmplx_Subtract(vector1[d], vector2[d], destination[d]);
+			return;
+		}
+	}	
+}
+
+/** Adds two vectors - 
+destination = vector1 + vector2
+Destination vector may be the same as either of the other two input vectors 
+Function is optimised for 1-3 dimensions but will work for any dimension */
+void StGermain_ComplexVectorAddition(Cmplx* destination, Cmplx* vector1, Cmplx* vector2, Index dim) {
+	switch (dim) {
+		case 3: 
+			Cmplx_Add(vector1[2], vector2[2], destination[2]);	
+		case 2:
+			Cmplx_Add(vector1[1], vector2[1], destination[1]);	
+		case 1: 
+			Cmplx_Add(vector1[0], vector2[0], destination[0]);	
+			return;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				Cmplx_Add(vector1[d], vector2[d], destination[d]);	
+                        /*printf("%f, %f", destination[d][REAL_PART], destination[d][IMAG_PART]); */
+			return;
+		}
+	}	
+}
+
+/** StGermain_ComplexVectorMagnitude calculates the magnitude of a vector
+|v| = \sqrt{ v . v } 
+This function uses function StGermain_ComplexVectorDotProduct to calculate v . v. 
+Vector has to be of size dim doubles */
+double StGermain_ComplexVectorMagnitude(Cmplx* vector, Index dim) {
+	Cmplx dotProduct;
+
+	StGermain_ComplexVectorDotProduct(vector, vector, dim, dotProduct);
+	return sqrt(Cmplx_Modulus(dotProduct));
+}
+
+/** StGermain_ComplexVectorDotProduct calculates the complex valued dot product of two
+complex vectors
+*/
+void StGermain_ComplexVectorDotProduct(Cmplx* vector1, Cmplx* vector2, Dimension_Index dim, Cmplx dotProduct) {
+	Cmplx tmp;
+	dotProduct[REAL_PART] = 0.0;
+	dotProduct[IMAG_PART] = 0.0;
+
+	switch (dim) {
+		case 3: {
+			Cmplx_Multiply(vector1[2], vector2[2], tmp);
+			Cmplx_Add(dotProduct, tmp, dotProduct);
+		}
+		case 2: {
+			Cmplx_Multiply(vector1[1], vector2[1], tmp);
+			Cmplx_Add(dotProduct, tmp, dotProduct);
+		}
+		case 1: {
+			Cmplx_Multiply(vector1[0], vector2[0], tmp);
+			Cmplx_Add(dotProduct, tmp, dotProduct);
+			break;
+		}
+		default: {
+			Dimension_Index d;
+			for ( d = 0 ; d < dim ; d++ ) {
+				Cmplx_Multiply(vector1[d], vector2[d], tmp);
+				Cmplx_Add(dotProduct, tmp, dotProduct);
+			}
+			break;
+		}
+	}
+	
+	
+}
+
+/** See Eric W. Weisstein. "Cross Product." 
+From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
+Tested against http://www.engplanet.com/redirect.html?3859 */
+void StGermain_ComplexVectorCrossProduct(Cmplx* destination, Cmplx* vector1, Cmplx* vector2) {
+	Cmplx c_1, c_2;
+	/*x direction */
+	Cmplx_Multiply(vector1[1], vector2[2], c_1);
+	Cmplx_Multiply(vector1[2], vector2[1], c_2);
+	Cmplx_Subtract(c_1, c_2, destination[0]);
+
+	/*y direction */
+	Cmplx_Multiply(vector1[2], vector2[0], c_1);
+	Cmplx_Multiply(vector1[0], vector2[2], c_2);
+	Cmplx_Subtract(c_1, c_2, destination[1]);
+	/*z direction */
+	Cmplx_Multiply(vector1[0], vector2[1], c_1);
+	Cmplx_Multiply(vector1[1], vector2[0], c_2);
+	Cmplx_Subtract(c_1, c_2, destination[2]);
+}
+
+/** StGermain_VectorCrossProductMagnitude - See Eric W. Weisstein. "Cross Product." 
+From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
+|a \times b| = |a||b|\sqrt{ 1 - (\hat a . \hat b)^2}
+*/
+void StGermain_ComplexVectorCrossProductMagnitude( Cmplx* vector1, Cmplx* vector2, Dimension_Index dim, Cmplx tmp ) {
+	double mag1       = StGermain_ComplexVectorMagnitude( vector1, dim );
+	double mag2       = StGermain_ComplexVectorMagnitude( vector2, dim );
+	Cmplx dotProduct, dotSquared;
+	StGermain_ComplexVectorDotProduct( vector1, vector2, dim, dotProduct );
+	
+	Cmplx_Multiply(dotProduct, dotProduct, dotSquared);
+	Cmplx_RealMultiply(dotSquared, 1.0/(mag1 * mag1 * mag2 * mag2), tmp);
+	Cmplx_RealMinusCmplx(tmp, 1.0, tmp); 
+	Cmplx_RealPower(tmp, 0.5, tmp);
+	Cmplx_RealMultiply(tmp, (mag1 * mag2), tmp);
+	
+}
+
+
+/** StGermain_ComplexScalarTripleProduct - Calculates the scalar vector product of three vectors -
+ * see Eric W. Weisstein. "Scalar Triple Product." From MathWorld--A Wolfram Web Resource. 
+	http://mathworld.wolfram.com/ScalarTripleProduct.html
+ * Assumes 3 Dimensions */
+void StGermain_ComplexScalarTripleProduct( Cmplx* vectorA, Cmplx* vectorB, Cmplx* vectorC, Cmplx tripleProduct ) {
+	XYZC crossProduct;
+	
+	StGermain_ComplexVectorCrossProduct( crossProduct, vectorB, vectorC );
+	StGermain_ComplexVectorDotProduct( vectorA, crossProduct, 3, tripleProduct );
+	 
+}
+
+
+/** StGermain_ComplexVectorNormalise calculates the magnitude of a vector
+\hat v = frac{v} / {|v|}
+This function uses function StGermain_VectorDotProduct to calculate v . v. 
+Vector has to be of size dim Cmplx */
+void StGermain_ComplexVectorNormalise(Cmplx* vector, Index dim) {
+	double mag;
+
+	mag = StGermain_ComplexVectorMagnitude( vector , dim );
+	switch (dim) {
+		case 3: 
+			Cmplx_RealMultiply(vector[2], 1.0/mag, vector[2]);
+		
+		case 2:
+			Cmplx_RealMultiply(vector[1], 1.0/mag, vector[1]);
+
+		case 1: 
+			Cmplx_RealMultiply(vector[0], 1.0/mag, vector[0]);			
+
+			break;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ )
+				Cmplx_RealMultiply(vector[d], 1.0/mag, vector[d]);
+			break;
+		}
+	}	
+}
+
+
+
+#define STGERMAIN_COMPLEXVECTOR_ONE_THIRD 0.3333333333333333333
+
+/** StGermain_ComplexTriangleCentroid Calculates the position vector to the centroid of a triangle whose vertices are given by position vectors 
+Position vectors have to be of size dim Cmplx */
+void StGermain_ComplexTriangleCentroid( Cmplx* centroid, Cmplx* pos0, Cmplx* pos1, Cmplx* pos2, Index dim) {
+	Cmplx tmp;
+	switch (dim) {
+		case 3:
+			Cmplx_Add(pos0[2], pos1[2], tmp);
+			Cmplx_Add(pos2[2], tmp, tmp);
+			Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[2]);
+			
+		case 2: 
+			Cmplx_Add(pos0[1], pos1[1], tmp);
+			Cmplx_Add(pos2[1], tmp, tmp);
+			Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[1]);
+		case 1:
+			Cmplx_Add(pos0[0], pos1[0], tmp);
+			Cmplx_Add(pos2[0], tmp, tmp);
+			Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[0]);
+			return;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) {
+				Cmplx_Add(pos0[d], pos1[d], tmp);
+				Cmplx_Add(pos2[d], tmp, tmp);
+				Cmplx_RealMultiply(tmp, STGERMAIN_COMPLEXVECTOR_ONE_THIRD, centroid[d]);
+			}
+			return;
+		}
+	}
+}
+
+/** Prints complex Vector using %g on all entries.
+TODO: would like this to be specified from function call
+with automatic default value
+*/
+void StGermain_PrintComplexVector( Stream* stream, Cmplx* vector, Index dim ) {
+	Index d;
+
+	if ( dim <= 0 ) {
+		Journal_Printf( stream, "{<NON_POSITIVE DIMENSION %d>}\n", dim );
+		return;
+	}
+
+	Journal_Printf( stream, "{");
+	for ( d = 0 ; d < dim - 1 ; d++ ) 
+		Journal_Printf( stream, "%g + i %g, ", vector[d][REAL_PART], vector[d][IMAG_PART] );
+	
+	Journal_Printf( stream, "%g + i %g}\n", vector[d][REAL_PART], vector[d][IMAG_PART] );
+}
+
+/** Converts ComplexVector into a vector,
+but only if there are no non-zero imaginary values. */
+void ComplexVector_ToVector(CoordC complexVector, Dimension_Index dim, Coord vector) {
+	Dimension_Index index;
+	for (index = 0; index < dim; index++) {
+		if (complexVector[index][IMAG_PART] != 0.0) {
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"ComplexVectorMath"  ),
+				"Error in '%s': Complex value in complex vector at index '%s' \n", __func__, index );
+		}
+		else {
+			vector[index] = complexVector[index][REAL_PART];
+		}
+	}
+}
+
+/** Converts vector into Complex vector, seting all imaginary 
+parts to zero */
+void Vector_ToComplexVector(Coord vector, Dimension_Index dim, CoordC complexVector) {
+	Dimension_Index index;
+	for (index = 0; index < dim; index++) {
+		complexVector[index][REAL_PART] = vector[index];
+		complexVector[index][IMAG_PART] = 0.0;
+	}		
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Delaunay.c
--- a/Geometry/src/Delaunay.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1009 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-*/
-/** \file
-**  Role:
-** The Delaunay class computes the constrained delaunay triangulation of a set of points
-** in 2 Dimensions along with the voronoi diagram of the point-set.
-** Assumptions:
-**
-** Comments:
-**
-** The recursive divide and conquer algorithm has been implemented from the pseudo-code
-** given in "Primitives for the manipulation of general subdivisions and the computation
-** of voronoi diagrams" by Leonidas Guibas and Jorge Stolfi.
-** ACM transtactions on graphics, Vol. 4, No. 2, April 1985, Pages 74-123
-**
-**
-** $Id: Delaunay.c 3462 2006-02-19 06:53:24Z RaquibulHassan $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "QuadEdge.h"
-#include "Delaunay.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-#include <limits.h>
-
-const Type Delaunay_Type="Delaunay";
-
-#if !defined INFINITY
-	#define INFINITY LONG_MAX
-#endif
-
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Constructors
-	*/
-	
-/** Create a Delaunay */
-Delaunay* Delaunay_DefaultNew( Name name )
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( Delaunay );
-	Type                                                      type = Delaunay_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Delaunay_Delete;
-	Stg_Class_PrintFunction*                                _print = _Delaunay_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Delaunay_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Delaunay_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Delaunay_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Delaunay_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Delaunay_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Delaunay_Destroy;
-	Bool                                                  initFlag = False;
-	Dictionary*                                         dictionary = NULL;
-	CoordF*                                                  sites = NULL;
-	int                                                   numSites = 0;
-	int                                                   idOffset = 0;
-	DelaunayAttributes*                                       attr = NULL;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	Delaunay *d = _Delaunay_New(  DELAUNAY_PASSARGS  );
-
-	return d;
-}
-	
-Delaunay* Delaunay_New(
-	Name						name,
-	Dictionary*					dictionary,
-	CoordF						*sites,
-	int							numSites,
-	int							idOffset,
-	DelaunayAttributes			*attr )
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( Delaunay );
-	Type                                                      type = Delaunay_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Delaunay_Delete;
-	Stg_Class_PrintFunction*                                _print = _Delaunay_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Delaunay_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Delaunay_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Delaunay_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Delaunay_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Delaunay_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Delaunay_Destroy;
-	Bool                                                  initFlag = True;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	Delaunay *d = _Delaunay_New(  DELAUNAY_PASSARGS  );
-	
-	return d;
-}
-
-	/** Initialise a Delaunay */
-void Delaunay_Init(
-	Delaunay*				self,
-	Name						name,
-	Dictionary*				dictionary,
-	CoordF					*sites,
-	int						numSites,
-	int						idOffset,
-	DelaunayAttributes	*attr )
-{
-	self->type = Delaunay_Type;
-	self->_sizeOfSelf = sizeof( Delaunay );
-	self->_deleteSelf = False;
-	self->dictionary = dictionary;
-
-	self->_delete = _Delaunay_Delete;
-	self->_print = _Delaunay_Print;
-	self->_copy = _Delaunay_Copy;
-	self->_defaultConstructor = (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew;
-	self->_construct = _Delaunay_AssignFromXML;
-	self->_build = _Delaunay_Build;
-	self->_initialise = _Delaunay_Initialise;
-	self->_execute = _Delaunay_Execute;
-	self->_destroy = _Delaunay_Destroy;
-
-	_Stg_Class_Init( (Stg_Class*)self );
-	_Stg_Object_Init( (Stg_Object*)self, name, NON_GLOBAL );
-	_Stg_Component_Init( (Stg_Component*)self );
-	_Delaunay_Init( self, sites, attr, numSites, idOffset, dictionary, True );
-}
-
-/** Creation implementation */
-Delaunay* _Delaunay_New(  DELAUNAY_DEFARGS  ) {
-	Delaunay *self = NULL;
-	
-	assert( _sizeOfSelf >= sizeof(Delaunay) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (Delaunay*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	_Delaunay_Init( self, sites, attr, numSites, idOffset, dictionary, initFlag );
-
-	return self;
-}
-
-#define PI 3.1415926535897932384626
-void Delaunay_FindMinMax( Site *sites, int count, float *minX, float *minY, float *maxX, float *maxY )
-{
-	int i = 0;
-	
-	*maxX = -INFINITY;
-	*maxY = -INFINITY;
-	
-	*minX = INFINITY;
-	*minY = INFINITY;
-
-	if (sites == NULL ) return;
-	
-	for( i=0; i<count; i++ ){
-		if( *maxX < (*(sites[i].coord))[0] ){
-			*maxX = (*(sites[i].coord))[0];
-		}
-		if( *maxY < (*(sites[i].coord))[1] ){
-			*maxY = (*(sites[i].coord))[1];
-		}
-		if( *minX > (*(sites[i].coord))[0] ){
-			*minX = (*(sites[i].coord))[0];
-		}
-		if( *minY > (*(sites[i].coord))[1] ){
-			*minY = (*(sites[i].coord))[1];
-		}
-	}
-}
-
-void _Delaunay_Init( Delaunay* self, CoordF* points, DelaunayAttributes* attr, int numSites, int idOffset, Dictionary* dictionary, Bool initFlag  )
-{
-	float maxX, minX, maxY, minY;
-	float centreX, centreY;
-	float radius;
-	int i = 0;
-	CoordF *sites = NULL;
-	
-	assert( self );
-	
-	self->dictionary = dictionary;
-	self->points = points;
-	self->attributes = attr;
-	self->idOffset = idOffset;
-
-	if( self->attributes->BuildBoundingTriangle ){
-		self->numSites = numSites + 3;
-	}
-	else{
-		self->numSites = numSites;
-	}
-	
-	self->numInputSites = numSites;
-
-
-	sites = self->points;
-	
-    if (initFlag) {
-
-	    if( sites != NULL ){
-		    self->sites = Memory_Alloc_Array_Unnamed( Site, self->numSites );
-		    memset( self->boundingTriangle, 0, sizeof( self->boundingTriangle ) );
-
-		    for( i=0; i<self->numSites; i++ ){
-			    if( i < self->numInputSites ){
-				    self->sites[i].coord = &(sites[i]);
-			    }
-			    else{
-				    self->sites[i].coord = &(self->boundingTriangle[i%3]);
-			    }
-			    self->sites[i].id = i + self->idOffset;
-		    }
-	    }
-	
-	    centreX = 0; centreY = 0; 
-	
-	    Delaunay_FindMinMax( self->sites, self->numSites, &minX, &minY, &maxX, &maxY );
-
-	    radius = (sqrt((maxX - minX) * (maxX - minX) + (maxY - minY) * (maxY - minY)));
-			
-	    centreX = minX + (maxX - minX) / 2.0f;
-	    centreY = minY + (maxY - minY) / 2.0f;
-
-	    self->boundingTriangle[0][0] = centreX - tan(PI/3.0f)*radius;
-	    self->boundingTriangle[0][1] = centreY - radius;
-
-	    self->boundingTriangle[1][0] = centreX + tan(PI/3.0f)*radius;
-	    self->boundingTriangle[1][1] = centreY - radius;
-			
-	    self->boundingTriangle[2][0] = centreX;
-	    self->boundingTriangle[2][1] = centreY + radius/cos(PI/3.0f);
-    }
-}
-
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Virtual functions
-	*/
-
-/** Stg_Class_Delete() implementation */
-void _Delaunay_Delete( void* delaunay )
-{
-	Delaunay *self = (Delaunay*)delaunay;
-	
-	assert( self );
-
-	_Stg_Component_Delete( self );
-}
-
-/** Stg_Class_Print() implementation */
-void _Delaunay_Print( void* delaunay, Stream* stream )
-{
-	Delaunay *self = ( Delaunay* )delaunay;
-	
-	assert( self );
-	assert( stream );
-
-	_Stg_Component_Print( self, stream );
-	Journal_Printf( stream, "Delaunay (ptr): (%p)\n", self );
-	
-	Journal_Printf( stream, "\tNum Sites %d\n", self->numSites );
-	Journal_Printf( stream, "\tNum Edges %d\n", self->numEdges );
-	Journal_Printf( stream, "\tNum Triangles %d\n", self->numTriangles );
-	Journal_Printf( stream, "\tNum Voronoi Vertices %d\n", self->numVoronoiVertices );
-}
-
-void *_Delaunay_Copy( const void* delaunay, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap )
-{
-	return NULL;
-}
-
-void _Delaunay_AssignFromXML( void* delaunay, Stg_ComponentFactory* cf, void* data )
-{
-	Delaunay *self = NULL;
-	Stg_ObjectList* pointerRegister;
-	int idOffset = 0;
-	CoordF *points = NULL;
-	DelaunayAttributes *attr = NULL;
-	int numSites = 0;
-
-	self = (Delaunay*) delaunay;
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !self->context  )
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
-	
-	pointerRegister = self->context->pointer_Register; 
-	
-	assert( pointerRegister  );
-
-	points = (float (*)[3])Stg_ObjectList_Get( pointerRegister, (Name)"dataPoints"  );
-	attr = (DelaunayAttributes*)Stg_ObjectList_Get( pointerRegister, (Name)"delaunayAttributes"  );
-
-	numSites = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"numSites", 0  );
-
-	_Delaunay_Init( self, points, attr, numSites, idOffset, cf->rootDict, True );
-
-	_Delaunay_Build( self, NULL );
-}
-
-void _Delaunay_Build( void* delaunay, void* data )
-{
-	Delaunay *self = ( Delaunay* )delaunay;
-	DelaunayAttributes *attr = NULL;
-    
-	assert( self );
-	
-	self->qp = MemoryPool_New( QuadEdge, self->numSites * 3, 10 );
-	
-	Delaunay_SortSites(self->sites, self->numSites);
-
-    Delaunay_Recurse(self, 0, self->numSites, &self->leftMost, &self->rightMost);
-
-	self->numEdges = self->qp->numElements - self->qp->numElementsFree;
-	self->numFaces = self->numEdges - self->numSites + 2;
-	self->numTriangles = 0;
-
-	attr = self->attributes;
-
-	if( attr->CreateVoronoiVertices ){
-		self->vp = MemoryPool_New( VoronoiVertex, self->numSites * 2, 10 );
-	}
-	
-	Delaunay_FindHull( self );
-	
-	if( attr->BuildTriangleIndices ){
-		Delaunay_BuildTriangleIndices( self );
-	}
-	
-	if( attr->CreateVoronoiVertices ){
-		Delaunay_BuildVoronoiVertices( self );
-		self->numVoronoiVertices = self->vp->numElements - self->vp->numElementsFree;
-	}
-	
-	Delaunay_FindNeighbours( self );
-}
-
-void _Delaunay_Initialise( void* delaunay, void* data ) {
-}
-
-void _Delaunay_Execute( void* delaunay, void* data ) {
-}
-
-void _Delaunay_Destroy( void* delaunay, void* data ) {
-   Delaunay *self = (Delaunay*)delaunay;
-	
-	assert( self );
-
-	if( self->sites ){
-		Memory_Free( self->sites );
-	}
-	
-	if( self->qp ){
-		Stg_Class_Delete( self->qp );
-	}
-
-	if( self->vp ){
-		Stg_Class_Delete( self->vp );
-	}
-
-	if( self->triangleIndices ){
-		Memory_Free( self->triangleIndices[0] );
-		Memory_Free( self->triangleIndices );
-	}
-
-	if( self->triangleNeighbours ){
-		Memory_Free( self->triangleNeighbours[0] );
-		Memory_Free( self->triangleNeighbours );
-	}
-
-	if( self->numNeighbours ){
-		Memory_Free( self->numNeighbours );
-	}
-	
-	if( self->neighbours ){
-		Memory_Free( self->neighbours[0] );
-		Memory_Free( self->neighbours );
-	}
-
-	if( self->voronoiSides ){
-		Memory_Free( self->voronoiSides[0] );
-		Memory_Free( self->voronoiSides );
-	}
-
-	if( self->voronoiArea ){
-		Memory_Free( self->voronoiArea );
-	}
-
-	if( self->hull ){
-		Memory_Free( self->hull );
-	}
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-/* Function for heap sorting the input points in ascending x-coordinate */
-void Delaunay_SortSites(Site *sites, int numSites )
-{
-   int gap, i, j;
-   Site temp;
-
-	for (gap = numSites/2; gap > 0; gap /= 2){
-		for (i = gap; i < numSites; i++){
-			for ( j = i-gap;
-				j >= 0 && ( (*(sites[j].coord))[0] != (*(sites[j+gap].coord))[0] ?
-					((*(sites[j].coord))[0] > (*(sites[j+gap].coord))[0]) : ((*(sites[j].coord))[1] > (*(sites[j+gap].coord))[1]));
-				j -= gap) 
-			{
-				memcpy( &temp, sites+j, sizeof( Site ) );
-				memcpy( sites+j, sites+j+gap, sizeof( Site ) );
-				memcpy( sites+j+gap, &temp, sizeof( Site ) );
-			}
-		}
-	}
-}
-
-/* Function to check if a point is to the right of an edge */
-int RightOf(Site *s, QuadEdgeRef e)
-{
-	double result=0;
-
-	CCW(s->coord, ((Site*)DEST(e))->coord, ((Site*)ORG(e))->coord, &result);
-
-	return result > 0.0;
-}
-
-/* Function to check if a point is to the left of an edge */
-int LeftOf(Site *s, QuadEdgeRef e)
-{
-	double result=0;
-	CCW(s->coord, ((Site*)ORG(e))->coord, ((Site*)DEST(e))->coord, &result);
-
-	return result > 0.0;
-}
-
-/* Function to check if a point is inside the circumcircle of three other points */
-int InCircle(Site *a, Site *b, Site *c, Site *d)
-{
-	double x1 = (*(a->coord))[0], y1 = (*(a->coord))[1];
-	double x2 = (*(b->coord))[0], y2 = (*(b->coord))[1];
-	double x3 = (*(c->coord))[0], y3 = (*(c->coord))[1];
-	double x4 = (*(d->coord))[0], y4 = (*(d->coord))[1];
-
-	return ((y4-y1)*(x2-x3)+(x4-x1)*(y2-y3))*((x4-x3)*(x2-x1)-(y4-y3)*(y2-y1)) >
-			((y4-y3)*(x2-x1)+(x4-x3)*(y2-y1))*((x4-x1)*(x2-x3)-(y4-y1)*(y2-y3));
-}
-
-/* This is the famous divide and conquer algorithm implemented from Guibas and Stolfi's 1985
- * paper. Refer to ACM Transcations on graphics, Vol. 4, No. 2, April 1985, Pages 74-123 */
-void Delaunay_Recurse( Delaunay *delaunay, int sl, int sh, QuadEdgeRef *le, QuadEdgeRef *re )
-{
-	Site *sites = delaunay->sites;
-	
-	if (sh == sl+2) 
-	{
-		QuadEdgeRef a = MakeQuadEdge( delaunay->qp );
-		ORG(a) = &sites[sl]; DEST(a) = &sites[sl+1];
-		*le = a; *re = SYM(a);
-	}
-	else if (sh == sl+3) 
-	{
-		QuadEdgeRef a = MakeQuadEdge( delaunay->qp );
-		QuadEdgeRef b = MakeQuadEdge( delaunay->qp );
-		float ct;
-		CCW(sites[sl].coord, sites[sl+1].coord, sites[sl+2].coord, &ct);
-		SpliceQuadEdges(SYM(a), b);
-		ORG(a) = &sites[sl]; DEST(a) = &sites[sl+1];
-		ORG(b) = &sites[sl+1];  DEST(b) = &sites[sl+2];
-		if (ct == 0.0) 
-		{ *le = a; *re = SYM(b); }
-		else
-		{ QuadEdgeRef c = ConnectQuadEdges(delaunay->qp, b, a);
-			if (ct > 0.0) 
-			{ *le = a; *re = SYM(b); }
-			else 
-			{ *le = SYM(c); *re = c; }
-		}
-	}
-	else
-	{
-		QuadEdgeRef ldo = 0, ldi = 0, rdi = 0, rdo = 0;
-		QuadEdgeRef basel = 0, lcand = 0, rcand = 0;
-
-		int sm = (sl+sh)/2;
-
-		Delaunay_Recurse( delaunay, sl, sm, &ldo, &ldi );
-		Delaunay_Recurse( delaunay, sm, sh, &rdi, &rdo);
-
-		while (1) 
-		{
-                  if (LeftOf((Site*)ORG(rdi), ldi)) ldi = LNEXT(ldi);
-                  else if (RightOf((Site*)ORG(ldi), rdi)) rdi = ONEXT(SYM(rdi));
-                  else break;
-		}
-
-		basel = ConnectQuadEdges(delaunay->qp, SYM(rdi), ldi);
-		if (ORG(ldi) == ORG(ldo)) ldo = SYM(basel);
-		if (ORG(rdi) == ORG(rdo)) rdo = basel;
-
-		while (1) 
-		{
-
-			lcand = ONEXT(SYM(basel));
-			if (RightOf((Site*)DEST(lcand), basel))
-				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(lcand), (Site*)DEST(ONEXT(lcand)))) 
-				{
-					QuadEdgeRef t = ONEXT(lcand);
-					
-					DeleteQuadEdge(delaunay->qp, lcand);
-					lcand = t;
-				}
-
-			rcand = OPREV(basel);
-			if (RightOf((Site*)DEST(rcand), basel))
-				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(rcand), (Site*)DEST(OPREV(rcand)))) 
-				{
-					QuadEdgeRef t = OPREV(rcand);
-
-					DeleteQuadEdge(delaunay->qp, rcand);
-					rcand = t;
-				}
-
-			if (!RightOf((Site*)DEST(lcand), basel) && !RightOf((Site*)DEST(rcand), basel)) break;
-
-			if ( !RightOf((Site*)DEST(lcand), basel) ||
-				( RightOf((Site*)DEST(rcand), basel) && 
-				InCircle((Site*)DEST(lcand), (Site*)ORG(lcand), (Site*)ORG(rcand), (Site*)DEST(rcand))))
-				basel = ConnectQuadEdges(delaunay->qp, rcand, SYM(basel));
-			else
-				basel = ConnectQuadEdges(delaunay->qp, SYM(basel), SYM(lcand));
-		}
-		*le = ldo; *re = rdo;
-	}
-}
-
-/* Function to find the convex hull of a triangulated set of points */
-void Delaunay_FindHull( Delaunay *delaunay )
-{
-	QuadEdgeRef start = 0, le = 0;
-	
-	assert( delaunay );
-	
-	start = le = delaunay->leftMost;
-	
-	delaunay->hull = Memory_Alloc_Array_Unnamed( int, delaunay->numSites );
-	memset( delaunay->hull, 0, sizeof( int ) * delaunay->numSites );
-	
-	do{
-		delaunay->hull[((Site*)ORG(le))->id - delaunay->idOffset] = 1;
-		delaunay->hull[((Site*)DEST(le))->id - delaunay->idOffset] = 1;
-		le = RPREV(le);
-	}while(le != start);
-}
-
-/* Function for generating triangle indices from a triangulation */
-void Delaunay_BuildTriangleIndices( Delaunay *delaunay )
-{
-	int i = 0, triCount;
-	QuadEdgeRef e = 0, eStart = 0, eOnext = 0, eLnext = 0;
-	QuadEdge *edges = NULL;
-	Site *sites = NULL;
-	int maxEdges = 0;
-	unsigned int **triIndices = NULL;
-	int **edgeToTriangle = NULL;
-	int index = 0;
-
-	assert( delaunay );
-	
-	delaunay->triangleIndices = Memory_Alloc_Array_Unnamed( unsigned int*, delaunay->numFaces );
-	delaunay->triangleIndices[0] = Memory_Alloc_Array_Unnamed( unsigned int, delaunay->numFaces * 3 );
-	memset( delaunay->triangleIndices[0] , 0, sizeof(unsigned int) * delaunay->numFaces * 3 );
-	
-	if( delaunay->attributes->BuildTriangleNeighbours ){
-		delaunay->triangleNeighbours = Memory_Alloc_Array_Unnamed( unsigned int*, delaunay->numFaces );
-		delaunay->triangleNeighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, delaunay->numFaces * 3 );
-
-		edgeToTriangle = Memory_Alloc_Array_Unnamed( int*, delaunay->qp->numElements );
-		edgeToTriangle[0] = Memory_Alloc_Array_Unnamed( int, delaunay->qp->numElements * 2 );
-	}
-	
-	for( i=0; i<delaunay->numFaces; i++ ){
-		delaunay->triangleIndices[i] = delaunay->triangleIndices[0]+i*3;
-
-		if( delaunay->attributes->BuildTriangleNeighbours ){
-			delaunay->triangleNeighbours[i] = delaunay->triangleNeighbours[0]+i*3;
-			
-			delaunay->triangleNeighbours[i][0] = delaunay->numFaces-1;
-			delaunay->triangleNeighbours[i][1] = delaunay->numFaces-1;
-			delaunay->triangleNeighbours[i][2] = delaunay->numFaces-1;
-		}
-	}
-	
-	if( delaunay->attributes->BuildTriangleNeighbours ){
-		for( i=0; i<delaunay->qp->numElements; i++ ){
-			edgeToTriangle[i] = edgeToTriangle[0]+i*2;
-			
-			edgeToTriangle[i][0] = delaunay->numFaces-1;
-			edgeToTriangle[i][1] = delaunay->numFaces-1;
-		}
-	}
-		
-	triIndices = delaunay->triangleIndices;
-	
-	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
-	sites = delaunay->sites;
-	maxEdges = delaunay->qp->numElements;
-		
-	for (i = 0; i < maxEdges; i++) {
-		edges[i].count = 0;
-	}
-
-	triCount = 0;
-	for (i = 0; i < maxEdges; i++) {
-		
-		e = eStart = (QuadEdgeRef)((void*)&(edges[i]));
-		
-		if( IS_FREE(e) )continue;
-		
-		do{
-			eOnext = ONEXT(e);
-			eLnext = LNEXT(e);
-			
-			if( (COUNT(e)<2) && (COUNT(LNEXT(e))<2) && (COUNT(eOnext)<2) ){
-					if( ((((Site*)ORG(eLnext)) == ((Site*)DEST(e)))) &&
-					 ((((Site*)DEST(eLnext)) == ((Site*)DEST(eOnext)))) ){
-		
-						if( delaunay->attributes->BuildBoundingTriangle ){
-							if( (!( delaunay->hull[(((Site*)ORG(e))->id) - delaunay->idOffset] )) &&
-								(!( delaunay->hull[(((Site*)DEST(e))->id) - delaunay->idOffset] )) && 
-								(!( delaunay->hull[(((Site*)DEST(eOnext))->id) - delaunay->idOffset] )) )
-							{
-								triIndices[triCount][0] = (((Site*)ORG(e))->id);
-								triIndices[triCount][1] = (((Site*)DEST(e))->id);
-								triIndices[triCount][2] = (((Site*)DEST(eOnext))->id);
-
-								if( delaunay->attributes->BuildTriangleNeighbours ){
-									index = (int)(((QuadEdge*)((void*)e)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
-									edgeToTriangle[index][COUNT(e)] = triCount;
-								
-									index = (int)(((QuadEdge*)((void*)eOnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
-									edgeToTriangle[index][COUNT(eOnext)] = triCount;
-								
-									index = (int)(((QuadEdge*)((void*)eLnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
-									edgeToTriangle[index][COUNT(eLnext)] = triCount;
-								}
-								
-								triCount++;
-							}
-						}
-						else{
-							triIndices[triCount][0] = (((Site*)ORG(e))->id);
-							triIndices[triCount][1] = (((Site*)DEST(e))->id);
-							triIndices[triCount][2] = (((Site*)DEST(eOnext))->id);
-							
-							if( delaunay->attributes->BuildTriangleNeighbours ){
-								index = (int)(((QuadEdge*)((void*)e)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
-								edgeToTriangle[index][COUNT(e)] = triCount;
-								
-								index = (int)(((QuadEdge*)((void*)eOnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
-								edgeToTriangle[index][COUNT(eOnext)] = triCount;
-								
-								index = (int)(((QuadEdge*)((void*)eLnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
-								edgeToTriangle[index][COUNT(eLnext)] = triCount;
-							}
-
-							triCount++;
-						}
-
-						COUNT(e)++;
-						COUNT(LNEXT(e))++;
-						COUNT(eOnext)++;
-					}
-				}
-			e = eOnext;
-		}while( e != eStart );
-	}
-	
-	delaunay->numTriangles = triCount;
-
-	if( delaunay->attributes->BuildTriangleNeighbours ){
-		int *triangleNeighbourCount = NULL;
-
-		triangleNeighbourCount = Memory_Alloc_Array_Unnamed( int, delaunay->numFaces );
-		memset( triangleNeighbourCount, 0, sizeof( int ) * delaunay->numFaces );
-		
-		for( i=0; i<delaunay->qp->numElements; i++ ){
-			if( IS_FREE( (QuadEdgeRef)(&(delaunay->qp->chunks[0].memory[i*sizeof(QuadEdge)])) ) ) continue;
-
-		
-			if( edgeToTriangle[i][0] != (delaunay->numFaces-1) )
-				delaunay->triangleNeighbours[edgeToTriangle[i][0]][triangleNeighbourCount[edgeToTriangle[i][0]]++] = edgeToTriangle[i][1];
-		
-			if( edgeToTriangle[i][1] != (delaunay->numFaces-1) )
-				delaunay->triangleNeighbours[edgeToTriangle[i][1]][triangleNeighbourCount[edgeToTriangle[i][1]]++] = edgeToTriangle[i][0];
-		}
-		
-		Memory_Free( edgeToTriangle[0] );
-		Memory_Free( edgeToTriangle );
-		Memory_Free( triangleNeighbourCount );
-	}
-}
-
-/* Function for calculating voronoi vertices */
-void Delaunay_BuildVoronoiVertices( Delaunay *delaunay )
-{
-	int i = 0;
-	QuadEdgeRef e = 0, eStart = 0, eOnext = 0, eLnext = 0;
-	VoronoiVertex *new_voronoi_site = NULL;
-	QuadEdge *edges = NULL;
-	Site *sites = NULL;
-	int maxEdges = 0;
-
-	assert( delaunay );
-	
-	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
-	sites = delaunay->sites;
-	maxEdges = delaunay->qp->numElements;
-		
-	for (i = 0; i < maxEdges; i++) {
-		edges[i].count = 0;
-	}
-
-	for (i = 0; i < maxEdges; i++) {
-		
-		e = eStart = (QuadEdgeRef)((void*)&(edges[i]));
-		
-		if( IS_FREE(e) )continue;
-		
-		new_voronoi_site = NULL;
-		do{
-			eOnext = ONEXT(e);
-			eLnext = LNEXT(e);
-
-			if( (COUNT(e)<2) && (COUNT(LNEXT(e))<2) && (COUNT(eOnext)<2) ){
-					if( ((((Site*)ORG(eLnext)) == ((Site*)DEST(e)))) &&
-					 ((((Site*)DEST(eLnext)) == ((Site*)DEST(eOnext)))) ){
-						
-						/* voronoi */
-							
-						new_voronoi_site = MemoryPool_NewObject( VoronoiVertex, delaunay->vp );
-					
-						/* Fiding the center of the circumcircle defined by org(e), dest(eonext) and dest(e)
-						 * and retrieving the result via new_voronoi_site */
-						CIRCUM_CIRCLE( ((Site*)ORG(e))->coord, ((Site*)DEST(eOnext))->coord, ((Site*)DEST(e))->coord, &(new_voronoi_site) );
-						
-						/* Assigning the new voronoi vertex to the associated edges */
-						VDEST( e ) = new_voronoi_site;
-						VORG( eOnext ) = new_voronoi_site;
-						VDEST( eLnext ) = new_voronoi_site;
-						
-						/*         */
-						
-						/* Marking the edges so that we dont visit any edge more than twice */
-						COUNT(e)++;
-						COUNT(LNEXT(e))++;
-						COUNT(eOnext)++;
-					}
-				}
-			e = eOnext;
-		}while( e != eStart );
-	}
-}
-
-/* Function for finding the neighbours of each point, along with the sides
- * of the voronoi cells and the surface area of the voronoi cells */
-void Delaunay_FindNeighbours( Delaunay *delaunay )
-{
-	int current_pos = 0, i = 0, count = 0, count1 = 0, numNeighboursSum;
-	int *tempNumNeighbours = NULL;
-	int maxEdges = 0, numSites = 0;
-	Site *src, *dst;
-	VoronoiVertex *vsrc, *vdst;
-	float dist = 0.0f, diffx = 0.0f, diffy = 0.0f, voronoiAreaResult = 0.0;
-	Site *sites = NULL;
-	QuadEdge *edges = NULL;
-	unsigned int *numNeighbours;
-	int *hull;
-	unsigned int **neighbours;
-	float *voronoiArea, **sides;
-	DelaunayAttributes *attr = NULL;
-
-	assert( delaunay );
-
-	attr = delaunay->attributes;
-	sites = delaunay->sites;
-	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
-	maxEdges = delaunay->qp->numElements;
-	numSites = delaunay->numSites;
-	
-	for (i = 0; i < maxEdges; i++) {
-		edges[i].count = 0;
-	}
-
-	delaunay->numNeighbours = Memory_Alloc_Array_Unnamed( unsigned int, numSites );
-	memset( delaunay->numNeighbours, 0, sizeof( unsigned int ) * numSites );
-	numNeighbours = delaunay->numNeighbours;
-	
-	hull = delaunay->hull;
-
-	numNeighboursSum = 0;
-	for( i=0; i<maxEdges; i++ ){
-		if( IS_FREE( (QuadEdgeRef)&(edges[i]) ) ) continue;
-		
-		if( edges[i].count == 0 ){
-			src = (Site*)ORG((QuadEdgeRef)((void*)(&(edges[i]))));
-			dst = (Site*)DEST((QuadEdgeRef)((void*)(&(edges[i]))));
-
-			if( (src->id < (delaunay->numInputSites+delaunay->idOffset)) 
-					&& (dst->id < (delaunay->numInputSites+delaunay->idOffset)) ){
-				
-				/* Finding the number of neighbours that each point has */
-				numNeighbours[src->id - delaunay->idOffset]++;
-				numNeighbours[dst->id - delaunay->idOffset]++;
-			
-				/* NumNeighboursSum is required for allocating just enough memory for storing the
-				 * actual neighbours and the sides of the voronoi celss */
-				numNeighboursSum += 2;
-
-			}
-
-			edges[i].count++;
-		}
-	}
-
-	/* allocating memory */
-	if( attr->CalculateVoronoiSurfaceArea ){
-		delaunay->voronoiArea = Memory_Alloc_Array_Unnamed( float, numSites );
-		memset( delaunay->voronoiArea, 0, sizeof( float ) * numSites );
-	}
-	
-	if( attr->FindNeighbours ){
-		delaunay->neighbours = Memory_Alloc_Array_Unnamed( unsigned int*, numSites );
-		delaunay->neighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, numNeighboursSum );
-		memset( delaunay->neighbours[0], 0, sizeof( unsigned int ) * numNeighboursSum );
-	}
-	
-	if( attr->CalculateVoronoiSides ){
-		delaunay->voronoiSides = Memory_Alloc_Array_Unnamed( float*, numSites );
-		delaunay->voronoiSides[0] = Memory_Alloc_Array_Unnamed( float, numNeighboursSum );
-		memset( delaunay->voronoiSides[0], 0, sizeof( float ) * numNeighboursSum );
-	}
-
-	tempNumNeighbours = Memory_Alloc_Array_Unnamed( int, numSites );
-	memcpy( tempNumNeighbours, numNeighbours, sizeof( int ) * numSites );
-
-	
-	voronoiArea = delaunay->voronoiArea;
-	neighbours = delaunay->neighbours;
-	sides = delaunay->voronoiSides;
-	
-	current_pos = 0;
-	for( i=0; i<numSites; i++ ){
-		
-		if( neighbours ) neighbours[i] = neighbours[0] + current_pos;
-		if( sides ) sides[i] = sides[0] + current_pos;
-		
-		current_pos += numNeighbours[i];
-	}
-	
-	for( i=0; i<maxEdges; i++ ){
-		if( IS_FREE( (QuadEdgeRef)&(edges[i]) ) ) continue;
-
-		src = (Site*)ORG((QuadEdgeRef)((void*)(&(edges[i]))));
-		dst = (Site*)DEST((QuadEdgeRef)((void*)(&(edges[i]))));
-
-		count = tempNumNeighbours[src->id - delaunay->idOffset];
-		count1 = tempNumNeighbours[dst->id - delaunay->idOffset];
-		
-		if( edges[i].count == 1 ){
-
-			if( (src->id < (delaunay->numInputSites+delaunay->idOffset)) 
-					&& (dst->id < (delaunay->numInputSites+delaunay->idOffset)) ){
-
-				vsrc = (VoronoiVertex*)VORG((QuadEdgeRef)((void*)(&(edges[i]))));
-				vdst = (VoronoiVertex*)VDEST((QuadEdgeRef)((void*)(&(edges[i]))));
-			
-				if( vsrc && vdst ){
-				
-					/* calculating the length of the voronoi sides */
-					if( attr->CalculateVoronoiSides ){
-					
-						diffx = ( vsrc->point[0] - vdst->point[0] );
-						diffy = ( vsrc->point[1] - vdst->point[1] );
-				
-						dist = sqrt( diffx*diffx + diffy*diffy );
-
-						sides[src->id - delaunay->idOffset][--count] = dist;
-						sides[dst->id - delaunay->idOffset][--count1] = dist;
-					}
-				
-					if( attr->CalculateVoronoiSurfaceArea ){
-					
-						/* calculating the voronoi surface area for each point, with the hull
-						 * nodes having an infinite unbounded area */
-
-						if( !(hull[src->id - delaunay->idOffset]) ){
-							CCW( src->coord, &(vsrc->point), &(vdst->point), &voronoiAreaResult );
-							voronoiArea[src->id - delaunay->idOffset] += FABS( voronoiAreaResult ) * 0.5;
-						}
-						else{
-							voronoiArea[src->id - delaunay->idOffset] = INFINITY;
-						}
-					
-						if( !(hull[dst->id - delaunay->idOffset]) ){
-							CCW( dst->coord, &(vsrc->point), &(vdst->point), &voronoiAreaResult );
-							voronoiArea[dst->id - delaunay->idOffset] += FABS( voronoiAreaResult ) * 0.5;
-						}
-						else{
-							voronoiArea[dst->id - delaunay->idOffset] = INFINITY;
-						}
-					}
-				}
-
-				/* Storing the actual neighbours of each node */
-				if( attr->FindNeighbours ){
-					neighbours[src->id - delaunay->idOffset][--tempNumNeighbours[src->id - delaunay->idOffset]] = dst->id;
-					neighbours[dst->id - delaunay->idOffset][--tempNumNeighbours[dst->id - delaunay->idOffset]] = src->id;
-				}
-			}
-			edges[i].count++;
-		}
-	}
-	Memory_Free(tempNumNeighbours);
-}
-
-/* Accessor functions below for accessing arrays inside the class */
-
-unsigned int **Delaunay_GetTriangleIndices( Delaunay *delaunay )
-{
-	assert( delaunay );
-
-	return delaunay->triangleIndices;
-}
-
-float **Delaunay_GetVoronoiSides( Delaunay *delaunay )
-{
-	assert( delaunay );
-
-	return delaunay->voronoiSides;
-}
-
-float *Delaunay_GetSurfaceArea( Delaunay *delaunay )
-{
-	assert( delaunay );
-
-	return delaunay->voronoiArea;
-}
-
-unsigned int *Delaunay_GetNumNeighbours( Delaunay *delaunay )
-{
-	assert( delaunay );
-
-	return delaunay->numNeighbours;
-}
-
-unsigned int **Delaunay_GetNeighbours( Delaunay *delaunay )
-{
-	assert( delaunay );
-
-	return delaunay->neighbours;
-}
-
-int *Delaunay_GetHull( Delaunay *delaunay )
-{
-	assert( delaunay );
-
-	return delaunay->hull;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Delaunay.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Delaunay.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1009 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+*/
+/** \file
+**  Role:
+** The Delaunay class computes the constrained delaunay triangulation of a set of points
+** in 2 Dimensions along with the voronoi diagram of the point-set.
+** Assumptions:
+**
+** Comments:
+**
+** The recursive divide and conquer algorithm has been implemented from the pseudo-code
+** given in "Primitives for the manipulation of general subdivisions and the computation
+** of voronoi diagrams" by Leonidas Guibas and Jorge Stolfi.
+** ACM transtactions on graphics, Vol. 4, No. 2, April 1985, Pages 74-123
+**
+**
+** $Id: Delaunay.c 3462 2006-02-19 06:53:24Z RaquibulHassan $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "QuadEdge.h"
+#include "Delaunay.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+#include <limits.h>
+
+const Type Delaunay_Type="Delaunay";
+
+#if !defined INFINITY
+	#define INFINITY LONG_MAX
+#endif
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Constructors
+	*/
+	
+/** Create a Delaunay */
+Delaunay* Delaunay_DefaultNew( Name name )
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( Delaunay );
+	Type                                                      type = Delaunay_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Delaunay_Delete;
+	Stg_Class_PrintFunction*                                _print = _Delaunay_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Delaunay_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Delaunay_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Delaunay_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Delaunay_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Delaunay_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Delaunay_Destroy;
+	Bool                                                  initFlag = False;
+	Dictionary*                                         dictionary = NULL;
+	CoordF*                                                  sites = NULL;
+	int                                                   numSites = 0;
+	int                                                   idOffset = 0;
+	DelaunayAttributes*                                       attr = NULL;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	Delaunay *d = _Delaunay_New(  DELAUNAY_PASSARGS  );
+
+	return d;
+}
+	
+Delaunay* Delaunay_New(
+	Name						name,
+	Dictionary*					dictionary,
+	CoordF						*sites,
+	int							numSites,
+	int							idOffset,
+	DelaunayAttributes			*attr )
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( Delaunay );
+	Type                                                      type = Delaunay_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Delaunay_Delete;
+	Stg_Class_PrintFunction*                                _print = _Delaunay_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Delaunay_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Delaunay_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Delaunay_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Delaunay_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Delaunay_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Delaunay_Destroy;
+	Bool                                                  initFlag = True;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	Delaunay *d = _Delaunay_New(  DELAUNAY_PASSARGS  );
+	
+	return d;
+}
+
+	/** Initialise a Delaunay */
+void Delaunay_Init(
+	Delaunay*				self,
+	Name						name,
+	Dictionary*				dictionary,
+	CoordF					*sites,
+	int						numSites,
+	int						idOffset,
+	DelaunayAttributes	*attr )
+{
+	self->type = Delaunay_Type;
+	self->_sizeOfSelf = sizeof( Delaunay );
+	self->_deleteSelf = False;
+	self->dictionary = dictionary;
+
+	self->_delete = _Delaunay_Delete;
+	self->_print = _Delaunay_Print;
+	self->_copy = _Delaunay_Copy;
+	self->_defaultConstructor = (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew;
+	self->_construct = _Delaunay_AssignFromXML;
+	self->_build = _Delaunay_Build;
+	self->_initialise = _Delaunay_Initialise;
+	self->_execute = _Delaunay_Execute;
+	self->_destroy = _Delaunay_Destroy;
+
+	_Stg_Class_Init( (Stg_Class*)self );
+	_Stg_Object_Init( (Stg_Object*)self, name, NON_GLOBAL );
+	_Stg_Component_Init( (Stg_Component*)self );
+	_Delaunay_Init( self, sites, attr, numSites, idOffset, dictionary, True );
+}
+
+/** Creation implementation */
+Delaunay* _Delaunay_New(  DELAUNAY_DEFARGS  ) {
+	Delaunay *self = NULL;
+	
+	assert( _sizeOfSelf >= sizeof(Delaunay) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (Delaunay*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	_Delaunay_Init( self, sites, attr, numSites, idOffset, dictionary, initFlag );
+
+	return self;
+}
+
+#define PI 3.1415926535897932384626
+void Delaunay_FindMinMax( Site *sites, int count, float *minX, float *minY, float *maxX, float *maxY )
+{
+	int i = 0;
+	
+	*maxX = -INFINITY;
+	*maxY = -INFINITY;
+	
+	*minX = INFINITY;
+	*minY = INFINITY;
+
+	if (sites == NULL ) return;
+	
+	for( i=0; i<count; i++ ){
+		if( *maxX < (*(sites[i].coord))[0] ){
+			*maxX = (*(sites[i].coord))[0];
+		}
+		if( *maxY < (*(sites[i].coord))[1] ){
+			*maxY = (*(sites[i].coord))[1];
+		}
+		if( *minX > (*(sites[i].coord))[0] ){
+			*minX = (*(sites[i].coord))[0];
+		}
+		if( *minY > (*(sites[i].coord))[1] ){
+			*minY = (*(sites[i].coord))[1];
+		}
+	}
+}
+
+void _Delaunay_Init( Delaunay* self, CoordF* points, DelaunayAttributes* attr, int numSites, int idOffset, Dictionary* dictionary, Bool initFlag  )
+{
+	float maxX, minX, maxY, minY;
+	float centreX, centreY;
+	float radius;
+	int i = 0;
+	CoordF *sites = NULL;
+	
+	assert( self );
+	
+	self->dictionary = dictionary;
+	self->points = points;
+	self->attributes = attr;
+	self->idOffset = idOffset;
+
+	if( self->attributes->BuildBoundingTriangle ){
+		self->numSites = numSites + 3;
+	}
+	else{
+		self->numSites = numSites;
+	}
+	
+	self->numInputSites = numSites;
+
+
+	sites = self->points;
+	
+    if (initFlag) {
+
+	    if( sites != NULL ){
+		    self->sites = Memory_Alloc_Array_Unnamed( Site, self->numSites );
+		    memset( self->boundingTriangle, 0, sizeof( self->boundingTriangle ) );
+
+		    for( i=0; i<self->numSites; i++ ){
+			    if( i < self->numInputSites ){
+				    self->sites[i].coord = &(sites[i]);
+			    }
+			    else{
+				    self->sites[i].coord = &(self->boundingTriangle[i%3]);
+			    }
+			    self->sites[i].id = i + self->idOffset;
+		    }
+	    }
+	
+	    centreX = 0; centreY = 0; 
+	
+	    Delaunay_FindMinMax( self->sites, self->numSites, &minX, &minY, &maxX, &maxY );
+
+	    radius = (sqrt((maxX - minX) * (maxX - minX) + (maxY - minY) * (maxY - minY)));
+			
+	    centreX = minX + (maxX - minX) / 2.0f;
+	    centreY = minY + (maxY - minY) / 2.0f;
+
+	    self->boundingTriangle[0][0] = centreX - tan(PI/3.0f)*radius;
+	    self->boundingTriangle[0][1] = centreY - radius;
+
+	    self->boundingTriangle[1][0] = centreX + tan(PI/3.0f)*radius;
+	    self->boundingTriangle[1][1] = centreY - radius;
+			
+	    self->boundingTriangle[2][0] = centreX;
+	    self->boundingTriangle[2][1] = centreY + radius/cos(PI/3.0f);
+    }
+}
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Virtual functions
+	*/
+
+/** Stg_Class_Delete() implementation */
+void _Delaunay_Delete( void* delaunay )
+{
+	Delaunay *self = (Delaunay*)delaunay;
+	
+	assert( self );
+
+	_Stg_Component_Delete( self );
+}
+
+/** Stg_Class_Print() implementation */
+void _Delaunay_Print( void* delaunay, Stream* stream )
+{
+	Delaunay *self = ( Delaunay* )delaunay;
+	
+	assert( self );
+	assert( stream );
+
+	_Stg_Component_Print( self, stream );
+	Journal_Printf( stream, "Delaunay (ptr): (%p)\n", self );
+	
+	Journal_Printf( stream, "\tNum Sites %d\n", self->numSites );
+	Journal_Printf( stream, "\tNum Edges %d\n", self->numEdges );
+	Journal_Printf( stream, "\tNum Triangles %d\n", self->numTriangles );
+	Journal_Printf( stream, "\tNum Voronoi Vertices %d\n", self->numVoronoiVertices );
+}
+
+void *_Delaunay_Copy( const void* delaunay, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap )
+{
+	return NULL;
+}
+
+void _Delaunay_AssignFromXML( void* delaunay, Stg_ComponentFactory* cf, void* data )
+{
+	Delaunay *self = NULL;
+	Stg_ObjectList* pointerRegister;
+	int idOffset = 0;
+	CoordF *points = NULL;
+	DelaunayAttributes *attr = NULL;
+	int numSites = 0;
+
+	self = (Delaunay*) delaunay;
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !self->context  )
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
+	
+	pointerRegister = self->context->pointer_Register; 
+	
+	assert( pointerRegister  );
+
+	points = (float (*)[3])Stg_ObjectList_Get( pointerRegister, (Name)"dataPoints"  );
+	attr = (DelaunayAttributes*)Stg_ObjectList_Get( pointerRegister, (Name)"delaunayAttributes"  );
+
+	numSites = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"numSites", 0  );
+
+	_Delaunay_Init( self, points, attr, numSites, idOffset, cf->rootDict, True );
+
+	_Delaunay_Build( self, NULL );
+}
+
+void _Delaunay_Build( void* delaunay, void* data )
+{
+	Delaunay *self = ( Delaunay* )delaunay;
+	DelaunayAttributes *attr = NULL;
+    
+	assert( self );
+	
+	self->qp = MemoryPool_New( QuadEdge, self->numSites * 3, 10 );
+	
+	Delaunay_SortSites(self->sites, self->numSites);
+
+    Delaunay_Recurse(self, 0, self->numSites, &self->leftMost, &self->rightMost);
+
+	self->numEdges = self->qp->numElements - self->qp->numElementsFree;
+	self->numFaces = self->numEdges - self->numSites + 2;
+	self->numTriangles = 0;
+
+	attr = self->attributes;
+
+	if( attr->CreateVoronoiVertices ){
+		self->vp = MemoryPool_New( VoronoiVertex, self->numSites * 2, 10 );
+	}
+	
+	Delaunay_FindHull( self );
+	
+	if( attr->BuildTriangleIndices ){
+		Delaunay_BuildTriangleIndices( self );
+	}
+	
+	if( attr->CreateVoronoiVertices ){
+		Delaunay_BuildVoronoiVertices( self );
+		self->numVoronoiVertices = self->vp->numElements - self->vp->numElementsFree;
+	}
+	
+	Delaunay_FindNeighbours( self );
+}
+
+void _Delaunay_Initialise( void* delaunay, void* data ) {
+}
+
+void _Delaunay_Execute( void* delaunay, void* data ) {
+}
+
+void _Delaunay_Destroy( void* delaunay, void* data ) {
+   Delaunay *self = (Delaunay*)delaunay;
+	
+	assert( self );
+
+	if( self->sites ){
+		Memory_Free( self->sites );
+	}
+	
+	if( self->qp ){
+		Stg_Class_Delete( self->qp );
+	}
+
+	if( self->vp ){
+		Stg_Class_Delete( self->vp );
+	}
+
+	if( self->triangleIndices ){
+		Memory_Free( self->triangleIndices[0] );
+		Memory_Free( self->triangleIndices );
+	}
+
+	if( self->triangleNeighbours ){
+		Memory_Free( self->triangleNeighbours[0] );
+		Memory_Free( self->triangleNeighbours );
+	}
+
+	if( self->numNeighbours ){
+		Memory_Free( self->numNeighbours );
+	}
+	
+	if( self->neighbours ){
+		Memory_Free( self->neighbours[0] );
+		Memory_Free( self->neighbours );
+	}
+
+	if( self->voronoiSides ){
+		Memory_Free( self->voronoiSides[0] );
+		Memory_Free( self->voronoiSides );
+	}
+
+	if( self->voronoiArea ){
+		Memory_Free( self->voronoiArea );
+	}
+
+	if( self->hull ){
+		Memory_Free( self->hull );
+	}
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+/* Function for heap sorting the input points in ascending x-coordinate */
+void Delaunay_SortSites(Site *sites, int numSites )
+{
+   int gap, i, j;
+   Site temp;
+
+	for (gap = numSites/2; gap > 0; gap /= 2){
+		for (i = gap; i < numSites; i++){
+			for ( j = i-gap;
+				j >= 0 && ( (*(sites[j].coord))[0] != (*(sites[j+gap].coord))[0] ?
+					((*(sites[j].coord))[0] > (*(sites[j+gap].coord))[0]) : ((*(sites[j].coord))[1] > (*(sites[j+gap].coord))[1]));
+				j -= gap) 
+			{
+				memcpy( &temp, sites+j, sizeof( Site ) );
+				memcpy( sites+j, sites+j+gap, sizeof( Site ) );
+				memcpy( sites+j+gap, &temp, sizeof( Site ) );
+			}
+		}
+	}
+}
+
+/* Function to check if a point is to the right of an edge */
+int RightOf(Site *s, QuadEdgeRef e)
+{
+	double result=0;
+
+	CCW(s->coord, ((Site*)DEST(e))->coord, ((Site*)ORG(e))->coord, &result);
+
+	return result > 0.0;
+}
+
+/* Function to check if a point is to the left of an edge */
+int LeftOf(Site *s, QuadEdgeRef e)
+{
+	double result=0;
+	CCW(s->coord, ((Site*)ORG(e))->coord, ((Site*)DEST(e))->coord, &result);
+
+	return result > 0.0;
+}
+
+/* Function to check if a point is inside the circumcircle of three other points */
+int InCircle(Site *a, Site *b, Site *c, Site *d)
+{
+	double x1 = (*(a->coord))[0], y1 = (*(a->coord))[1];
+	double x2 = (*(b->coord))[0], y2 = (*(b->coord))[1];
+	double x3 = (*(c->coord))[0], y3 = (*(c->coord))[1];
+	double x4 = (*(d->coord))[0], y4 = (*(d->coord))[1];
+
+	return ((y4-y1)*(x2-x3)+(x4-x1)*(y2-y3))*((x4-x3)*(x2-x1)-(y4-y3)*(y2-y1)) >
+			((y4-y3)*(x2-x1)+(x4-x3)*(y2-y1))*((x4-x1)*(x2-x3)-(y4-y1)*(y2-y3));
+}
+
+/* This is the famous divide and conquer algorithm implemented from Guibas and Stolfi's 1985
+ * paper. Refer to ACM Transcations on graphics, Vol. 4, No. 2, April 1985, Pages 74-123 */
+void Delaunay_Recurse( Delaunay *delaunay, int sl, int sh, QuadEdgeRef *le, QuadEdgeRef *re )
+{
+	Site *sites = delaunay->sites;
+	
+	if (sh == sl+2) 
+	{
+		QuadEdgeRef a = MakeQuadEdge( delaunay->qp );
+		ORG(a) = &sites[sl]; DEST(a) = &sites[sl+1];
+		*le = a; *re = SYM(a);
+	}
+	else if (sh == sl+3) 
+	{
+		QuadEdgeRef a = MakeQuadEdge( delaunay->qp );
+		QuadEdgeRef b = MakeQuadEdge( delaunay->qp );
+		float ct;
+		CCW(sites[sl].coord, sites[sl+1].coord, sites[sl+2].coord, &ct);
+		SpliceQuadEdges(SYM(a), b);
+		ORG(a) = &sites[sl]; DEST(a) = &sites[sl+1];
+		ORG(b) = &sites[sl+1];  DEST(b) = &sites[sl+2];
+		if (ct == 0.0) 
+		{ *le = a; *re = SYM(b); }
+		else
+		{ QuadEdgeRef c = ConnectQuadEdges(delaunay->qp, b, a);
+			if (ct > 0.0) 
+			{ *le = a; *re = SYM(b); }
+			else 
+			{ *le = SYM(c); *re = c; }
+		}
+	}
+	else
+	{
+		QuadEdgeRef ldo = 0, ldi = 0, rdi = 0, rdo = 0;
+		QuadEdgeRef basel = 0, lcand = 0, rcand = 0;
+
+		int sm = (sl+sh)/2;
+
+		Delaunay_Recurse( delaunay, sl, sm, &ldo, &ldi );
+		Delaunay_Recurse( delaunay, sm, sh, &rdi, &rdo);
+
+		while (1) 
+		{
+                  if (LeftOf((Site*)ORG(rdi), ldi)) ldi = LNEXT(ldi);
+                  else if (RightOf((Site*)ORG(ldi), rdi)) rdi = ONEXT(SYM(rdi));
+                  else break;
+		}
+
+		basel = ConnectQuadEdges(delaunay->qp, SYM(rdi), ldi);
+		if (ORG(ldi) == ORG(ldo)) ldo = SYM(basel);
+		if (ORG(rdi) == ORG(rdo)) rdo = basel;
+
+		while (1) 
+		{
+
+			lcand = ONEXT(SYM(basel));
+			if (RightOf((Site*)DEST(lcand), basel))
+				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(lcand), (Site*)DEST(ONEXT(lcand)))) 
+				{
+					QuadEdgeRef t = ONEXT(lcand);
+					
+					DeleteQuadEdge(delaunay->qp, lcand);
+					lcand = t;
+				}
+
+			rcand = OPREV(basel);
+			if (RightOf((Site*)DEST(rcand), basel))
+				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(rcand), (Site*)DEST(OPREV(rcand)))) 
+				{
+					QuadEdgeRef t = OPREV(rcand);
+
+					DeleteQuadEdge(delaunay->qp, rcand);
+					rcand = t;
+				}
+
+			if (!RightOf((Site*)DEST(lcand), basel) && !RightOf((Site*)DEST(rcand), basel)) break;
+
+			if ( !RightOf((Site*)DEST(lcand), basel) ||
+				( RightOf((Site*)DEST(rcand), basel) && 
+				InCircle((Site*)DEST(lcand), (Site*)ORG(lcand), (Site*)ORG(rcand), (Site*)DEST(rcand))))
+				basel = ConnectQuadEdges(delaunay->qp, rcand, SYM(basel));
+			else
+				basel = ConnectQuadEdges(delaunay->qp, SYM(basel), SYM(lcand));
+		}
+		*le = ldo; *re = rdo;
+	}
+}
+
+/* Function to find the convex hull of a triangulated set of points */
+void Delaunay_FindHull( Delaunay *delaunay )
+{
+	QuadEdgeRef start = 0, le = 0;
+	
+	assert( delaunay );
+	
+	start = le = delaunay->leftMost;
+	
+	delaunay->hull = Memory_Alloc_Array_Unnamed( int, delaunay->numSites );
+	memset( delaunay->hull, 0, sizeof( int ) * delaunay->numSites );
+	
+	do{
+		delaunay->hull[((Site*)ORG(le))->id - delaunay->idOffset] = 1;
+		delaunay->hull[((Site*)DEST(le))->id - delaunay->idOffset] = 1;
+		le = RPREV(le);
+	}while(le != start);
+}
+
+/* Function for generating triangle indices from a triangulation */
+void Delaunay_BuildTriangleIndices( Delaunay *delaunay )
+{
+	int i = 0, triCount;
+	QuadEdgeRef e = 0, eStart = 0, eOnext = 0, eLnext = 0;
+	QuadEdge *edges = NULL;
+	Site *sites = NULL;
+	int maxEdges = 0;
+	unsigned int **triIndices = NULL;
+	int **edgeToTriangle = NULL;
+	int index = 0;
+
+	assert( delaunay );
+	
+	delaunay->triangleIndices = Memory_Alloc_Array_Unnamed( unsigned int*, delaunay->numFaces );
+	delaunay->triangleIndices[0] = Memory_Alloc_Array_Unnamed( unsigned int, delaunay->numFaces * 3 );
+	memset( delaunay->triangleIndices[0] , 0, sizeof(unsigned int) * delaunay->numFaces * 3 );
+	
+	if( delaunay->attributes->BuildTriangleNeighbours ){
+		delaunay->triangleNeighbours = Memory_Alloc_Array_Unnamed( unsigned int*, delaunay->numFaces );
+		delaunay->triangleNeighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, delaunay->numFaces * 3 );
+
+		edgeToTriangle = Memory_Alloc_Array_Unnamed( int*, delaunay->qp->numElements );
+		edgeToTriangle[0] = Memory_Alloc_Array_Unnamed( int, delaunay->qp->numElements * 2 );
+	}
+	
+	for( i=0; i<delaunay->numFaces; i++ ){
+		delaunay->triangleIndices[i] = delaunay->triangleIndices[0]+i*3;
+
+		if( delaunay->attributes->BuildTriangleNeighbours ){
+			delaunay->triangleNeighbours[i] = delaunay->triangleNeighbours[0]+i*3;
+			
+			delaunay->triangleNeighbours[i][0] = delaunay->numFaces-1;
+			delaunay->triangleNeighbours[i][1] = delaunay->numFaces-1;
+			delaunay->triangleNeighbours[i][2] = delaunay->numFaces-1;
+		}
+	}
+	
+	if( delaunay->attributes->BuildTriangleNeighbours ){
+		for( i=0; i<delaunay->qp->numElements; i++ ){
+			edgeToTriangle[i] = edgeToTriangle[0]+i*2;
+			
+			edgeToTriangle[i][0] = delaunay->numFaces-1;
+			edgeToTriangle[i][1] = delaunay->numFaces-1;
+		}
+	}
+		
+	triIndices = delaunay->triangleIndices;
+	
+	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
+	sites = delaunay->sites;
+	maxEdges = delaunay->qp->numElements;
+		
+	for (i = 0; i < maxEdges; i++) {
+		edges[i].count = 0;
+	}
+
+	triCount = 0;
+	for (i = 0; i < maxEdges; i++) {
+		
+		e = eStart = (QuadEdgeRef)((void*)&(edges[i]));
+		
+		if( IS_FREE(e) )continue;
+		
+		do{
+			eOnext = ONEXT(e);
+			eLnext = LNEXT(e);
+			
+			if( (COUNT(e)<2) && (COUNT(LNEXT(e))<2) && (COUNT(eOnext)<2) ){
+					if( ((((Site*)ORG(eLnext)) == ((Site*)DEST(e)))) &&
+					 ((((Site*)DEST(eLnext)) == ((Site*)DEST(eOnext)))) ){
+		
+						if( delaunay->attributes->BuildBoundingTriangle ){
+							if( (!( delaunay->hull[(((Site*)ORG(e))->id) - delaunay->idOffset] )) &&
+								(!( delaunay->hull[(((Site*)DEST(e))->id) - delaunay->idOffset] )) && 
+								(!( delaunay->hull[(((Site*)DEST(eOnext))->id) - delaunay->idOffset] )) )
+							{
+								triIndices[triCount][0] = (((Site*)ORG(e))->id);
+								triIndices[triCount][1] = (((Site*)DEST(e))->id);
+								triIndices[triCount][2] = (((Site*)DEST(eOnext))->id);
+
+								if( delaunay->attributes->BuildTriangleNeighbours ){
+									index = (int)(((QuadEdge*)((void*)e)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
+									edgeToTriangle[index][COUNT(e)] = triCount;
+								
+									index = (int)(((QuadEdge*)((void*)eOnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
+									edgeToTriangle[index][COUNT(eOnext)] = triCount;
+								
+									index = (int)(((QuadEdge*)((void*)eLnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
+									edgeToTriangle[index][COUNT(eLnext)] = triCount;
+								}
+								
+								triCount++;
+							}
+						}
+						else{
+							triIndices[triCount][0] = (((Site*)ORG(e))->id);
+							triIndices[triCount][1] = (((Site*)DEST(e))->id);
+							triIndices[triCount][2] = (((Site*)DEST(eOnext))->id);
+							
+							if( delaunay->attributes->BuildTriangleNeighbours ){
+								index = (int)(((QuadEdge*)((void*)e)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
+								edgeToTriangle[index][COUNT(e)] = triCount;
+								
+								index = (int)(((QuadEdge*)((void*)eOnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
+								edgeToTriangle[index][COUNT(eOnext)] = triCount;
+								
+								index = (int)(((QuadEdge*)((void*)eLnext)) - (QuadEdge*)delaunay->qp->chunks[0].memory);
+								edgeToTriangle[index][COUNT(eLnext)] = triCount;
+							}
+
+							triCount++;
+						}
+
+						COUNT(e)++;
+						COUNT(LNEXT(e))++;
+						COUNT(eOnext)++;
+					}
+				}
+			e = eOnext;
+		}while( e != eStart );
+	}
+	
+	delaunay->numTriangles = triCount;
+
+	if( delaunay->attributes->BuildTriangleNeighbours ){
+		int *triangleNeighbourCount = NULL;
+
+		triangleNeighbourCount = Memory_Alloc_Array_Unnamed( int, delaunay->numFaces );
+		memset( triangleNeighbourCount, 0, sizeof( int ) * delaunay->numFaces );
+		
+		for( i=0; i<delaunay->qp->numElements; i++ ){
+			if( IS_FREE( (QuadEdgeRef)(&(delaunay->qp->chunks[0].memory[i*sizeof(QuadEdge)])) ) ) continue;
+
+		
+			if( edgeToTriangle[i][0] != (delaunay->numFaces-1) )
+				delaunay->triangleNeighbours[edgeToTriangle[i][0]][triangleNeighbourCount[edgeToTriangle[i][0]]++] = edgeToTriangle[i][1];
+		
+			if( edgeToTriangle[i][1] != (delaunay->numFaces-1) )
+				delaunay->triangleNeighbours[edgeToTriangle[i][1]][triangleNeighbourCount[edgeToTriangle[i][1]]++] = edgeToTriangle[i][0];
+		}
+		
+		Memory_Free( edgeToTriangle[0] );
+		Memory_Free( edgeToTriangle );
+		Memory_Free( triangleNeighbourCount );
+	}
+}
+
+/* Function for calculating voronoi vertices */
+void Delaunay_BuildVoronoiVertices( Delaunay *delaunay )
+{
+	int i = 0;
+	QuadEdgeRef e = 0, eStart = 0, eOnext = 0, eLnext = 0;
+	VoronoiVertex *new_voronoi_site = NULL;
+	QuadEdge *edges = NULL;
+	Site *sites = NULL;
+	int maxEdges = 0;
+
+	assert( delaunay );
+	
+	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
+	sites = delaunay->sites;
+	maxEdges = delaunay->qp->numElements;
+		
+	for (i = 0; i < maxEdges; i++) {
+		edges[i].count = 0;
+	}
+
+	for (i = 0; i < maxEdges; i++) {
+		
+		e = eStart = (QuadEdgeRef)((void*)&(edges[i]));
+		
+		if( IS_FREE(e) )continue;
+		
+		new_voronoi_site = NULL;
+		do{
+			eOnext = ONEXT(e);
+			eLnext = LNEXT(e);
+
+			if( (COUNT(e)<2) && (COUNT(LNEXT(e))<2) && (COUNT(eOnext)<2) ){
+					if( ((((Site*)ORG(eLnext)) == ((Site*)DEST(e)))) &&
+					 ((((Site*)DEST(eLnext)) == ((Site*)DEST(eOnext)))) ){
+						
+						/* voronoi */
+							
+						new_voronoi_site = MemoryPool_NewObject( VoronoiVertex, delaunay->vp );
+					
+						/* Fiding the center of the circumcircle defined by org(e), dest(eonext) and dest(e)
+						 * and retrieving the result via new_voronoi_site */
+						CIRCUM_CIRCLE( ((Site*)ORG(e))->coord, ((Site*)DEST(eOnext))->coord, ((Site*)DEST(e))->coord, &(new_voronoi_site) );
+						
+						/* Assigning the new voronoi vertex to the associated edges */
+						VDEST( e ) = new_voronoi_site;
+						VORG( eOnext ) = new_voronoi_site;
+						VDEST( eLnext ) = new_voronoi_site;
+						
+						/*         */
+						
+						/* Marking the edges so that we dont visit any edge more than twice */
+						COUNT(e)++;
+						COUNT(LNEXT(e))++;
+						COUNT(eOnext)++;
+					}
+				}
+			e = eOnext;
+		}while( e != eStart );
+	}
+}
+
+/* Function for finding the neighbours of each point, along with the sides
+ * of the voronoi cells and the surface area of the voronoi cells */
+void Delaunay_FindNeighbours( Delaunay *delaunay )
+{
+	int current_pos = 0, i = 0, count = 0, count1 = 0, numNeighboursSum;
+	int *tempNumNeighbours = NULL;
+	int maxEdges = 0, numSites = 0;
+	Site *src, *dst;
+	VoronoiVertex *vsrc, *vdst;
+	float dist = 0.0f, diffx = 0.0f, diffy = 0.0f, voronoiAreaResult = 0.0;
+	Site *sites = NULL;
+	QuadEdge *edges = NULL;
+	unsigned int *numNeighbours;
+	int *hull;
+	unsigned int **neighbours;
+	float *voronoiArea, **sides;
+	DelaunayAttributes *attr = NULL;
+
+	assert( delaunay );
+
+	attr = delaunay->attributes;
+	sites = delaunay->sites;
+	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
+	maxEdges = delaunay->qp->numElements;
+	numSites = delaunay->numSites;
+	
+	for (i = 0; i < maxEdges; i++) {
+		edges[i].count = 0;
+	}
+
+	delaunay->numNeighbours = Memory_Alloc_Array_Unnamed( unsigned int, numSites );
+	memset( delaunay->numNeighbours, 0, sizeof( unsigned int ) * numSites );
+	numNeighbours = delaunay->numNeighbours;
+	
+	hull = delaunay->hull;
+
+	numNeighboursSum = 0;
+	for( i=0; i<maxEdges; i++ ){
+		if( IS_FREE( (QuadEdgeRef)&(edges[i]) ) ) continue;
+		
+		if( edges[i].count == 0 ){
+			src = (Site*)ORG((QuadEdgeRef)((void*)(&(edges[i]))));
+			dst = (Site*)DEST((QuadEdgeRef)((void*)(&(edges[i]))));
+
+			if( (src->id < (delaunay->numInputSites+delaunay->idOffset)) 
+					&& (dst->id < (delaunay->numInputSites+delaunay->idOffset)) ){
+				
+				/* Finding the number of neighbours that each point has */
+				numNeighbours[src->id - delaunay->idOffset]++;
+				numNeighbours[dst->id - delaunay->idOffset]++;
+			
+				/* NumNeighboursSum is required for allocating just enough memory for storing the
+				 * actual neighbours and the sides of the voronoi celss */
+				numNeighboursSum += 2;
+
+			}
+
+			edges[i].count++;
+		}
+	}
+
+	/* allocating memory */
+	if( attr->CalculateVoronoiSurfaceArea ){
+		delaunay->voronoiArea = Memory_Alloc_Array_Unnamed( float, numSites );
+		memset( delaunay->voronoiArea, 0, sizeof( float ) * numSites );
+	}
+	
+	if( attr->FindNeighbours ){
+		delaunay->neighbours = Memory_Alloc_Array_Unnamed( unsigned int*, numSites );
+		delaunay->neighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, numNeighboursSum );
+		memset( delaunay->neighbours[0], 0, sizeof( unsigned int ) * numNeighboursSum );
+	}
+	
+	if( attr->CalculateVoronoiSides ){
+		delaunay->voronoiSides = Memory_Alloc_Array_Unnamed( float*, numSites );
+		delaunay->voronoiSides[0] = Memory_Alloc_Array_Unnamed( float, numNeighboursSum );
+		memset( delaunay->voronoiSides[0], 0, sizeof( float ) * numNeighboursSum );
+	}
+
+	tempNumNeighbours = Memory_Alloc_Array_Unnamed( int, numSites );
+	memcpy( tempNumNeighbours, numNeighbours, sizeof( int ) * numSites );
+
+	
+	voronoiArea = delaunay->voronoiArea;
+	neighbours = delaunay->neighbours;
+	sides = delaunay->voronoiSides;
+	
+	current_pos = 0;
+	for( i=0; i<numSites; i++ ){
+		
+		if( neighbours ) neighbours[i] = neighbours[0] + current_pos;
+		if( sides ) sides[i] = sides[0] + current_pos;
+		
+		current_pos += numNeighbours[i];
+	}
+	
+	for( i=0; i<maxEdges; i++ ){
+		if( IS_FREE( (QuadEdgeRef)&(edges[i]) ) ) continue;
+
+		src = (Site*)ORG((QuadEdgeRef)((void*)(&(edges[i]))));
+		dst = (Site*)DEST((QuadEdgeRef)((void*)(&(edges[i]))));
+
+		count = tempNumNeighbours[src->id - delaunay->idOffset];
+		count1 = tempNumNeighbours[dst->id - delaunay->idOffset];
+		
+		if( edges[i].count == 1 ){
+
+			if( (src->id < (delaunay->numInputSites+delaunay->idOffset)) 
+					&& (dst->id < (delaunay->numInputSites+delaunay->idOffset)) ){
+
+				vsrc = (VoronoiVertex*)VORG((QuadEdgeRef)((void*)(&(edges[i]))));
+				vdst = (VoronoiVertex*)VDEST((QuadEdgeRef)((void*)(&(edges[i]))));
+			
+				if( vsrc && vdst ){
+				
+					/* calculating the length of the voronoi sides */
+					if( attr->CalculateVoronoiSides ){
+					
+						diffx = ( vsrc->point[0] - vdst->point[0] );
+						diffy = ( vsrc->point[1] - vdst->point[1] );
+				
+						dist = sqrt( diffx*diffx + diffy*diffy );
+
+						sides[src->id - delaunay->idOffset][--count] = dist;
+						sides[dst->id - delaunay->idOffset][--count1] = dist;
+					}
+				
+					if( attr->CalculateVoronoiSurfaceArea ){
+					
+						/* calculating the voronoi surface area for each point, with the hull
+						 * nodes having an infinite unbounded area */
+
+						if( !(hull[src->id - delaunay->idOffset]) ){
+							CCW( src->coord, &(vsrc->point), &(vdst->point), &voronoiAreaResult );
+							voronoiArea[src->id - delaunay->idOffset] += FABS( voronoiAreaResult ) * 0.5;
+						}
+						else{
+							voronoiArea[src->id - delaunay->idOffset] = INFINITY;
+						}
+					
+						if( !(hull[dst->id - delaunay->idOffset]) ){
+							CCW( dst->coord, &(vsrc->point), &(vdst->point), &voronoiAreaResult );
+							voronoiArea[dst->id - delaunay->idOffset] += FABS( voronoiAreaResult ) * 0.5;
+						}
+						else{
+							voronoiArea[dst->id - delaunay->idOffset] = INFINITY;
+						}
+					}
+				}
+
+				/* Storing the actual neighbours of each node */
+				if( attr->FindNeighbours ){
+					neighbours[src->id - delaunay->idOffset][--tempNumNeighbours[src->id - delaunay->idOffset]] = dst->id;
+					neighbours[dst->id - delaunay->idOffset][--tempNumNeighbours[dst->id - delaunay->idOffset]] = src->id;
+				}
+			}
+			edges[i].count++;
+		}
+	}
+	Memory_Free(tempNumNeighbours);
+}
+
+/* Accessor functions below for accessing arrays inside the class */
+
+unsigned int **Delaunay_GetTriangleIndices( Delaunay *delaunay )
+{
+	assert( delaunay );
+
+	return delaunay->triangleIndices;
+}
+
+float **Delaunay_GetVoronoiSides( Delaunay *delaunay )
+{
+	assert( delaunay );
+
+	return delaunay->voronoiSides;
+}
+
+float *Delaunay_GetSurfaceArea( Delaunay *delaunay )
+{
+	assert( delaunay );
+
+	return delaunay->voronoiArea;
+}
+
+unsigned int *Delaunay_GetNumNeighbours( Delaunay *delaunay )
+{
+	assert( delaunay );
+
+	return delaunay->numNeighbours;
+}
+
+unsigned int **Delaunay_GetNeighbours( Delaunay *delaunay )
+{
+	assert( delaunay );
+
+	return delaunay->neighbours;
+}
+
+int *Delaunay_GetHull( Delaunay *delaunay )
+{
+	assert( delaunay );
+
+	return delaunay->hull;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Dimension.c
--- a/Geometry/src/Dimension.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Dimension.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-#include "units.h"
-#include "types.h"
-#include "Dimension.h"
-
-void Dimension_3DTo1D_3_Func( Index dim0, Index dim1, Index dim2, 
-		Index dim0Size, Index dim1Size, Index dim2Size, 
-		Index* outputIndexPtr )
-{		
-	Index dimSizes[3];
-	dimSizes[0] = (dim0Size) ? (dim0Size) : 1;
-	dimSizes[1] = (dim1Size) ? (dim1Size) : 1;
-	dimSizes[2] = (dim2Size) ? (dim2Size) : 1;
-	
-	#if DEBUG 
-	{
-		Stream* dimensionError = Journal_Register( Error_Type, (Name)"DimensionMacros" );
-		Journal_Firewall( (dim0 < dimSizes[0] ), dimensionError, "Error: Given coordinate[0] value %d >= "
-			"regionSize[0] %d\n", dim0, dimSizes[0] );
-		Journal_Firewall( (dim1 < dimSizes[1]), dimensionError, "Error: Given coordinate[1] value %d >= "
-			"regionSize[1] %d\n", dim1, dimSizes[1] );
-		Journal_Firewall( (dim2 < dimSizes[2]), dimensionError, "Error: Given coordinate[2] value %d >= "
-			"regionSize[2] %d\n", dim2, dimSizes[2] );
-	}	
-	#endif
-	
-	Dimension_3DTo1D_3_Macro( dim0, dim1, dim2, dim0Size, dim1Size, dim2Size, outputIndexPtr );
-}	
-
-void Dimension_1DTo3D_3_Func( Index index, Index dim0Size, Index dim1Size, Index dim2Size,
-		Index* dim0Ptr, Index* dim1Ptr, Index* dim2Ptr ) 
-{
-	Dimension_1DTo3D_3_Macro( index, dim0Size, dim1Size, dim2Size, dim0Ptr, dim1Ptr, dim2Ptr );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Dimension.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Dimension.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,68 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Dimension.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+#include "units.h"
+#include "types.h"
+#include "Dimension.h"
+
+void Dimension_3DTo1D_3_Func( Index dim0, Index dim1, Index dim2, 
+		Index dim0Size, Index dim1Size, Index dim2Size, 
+		Index* outputIndexPtr )
+{		
+	Index dimSizes[3];
+	dimSizes[0] = (dim0Size) ? (dim0Size) : 1;
+	dimSizes[1] = (dim1Size) ? (dim1Size) : 1;
+	dimSizes[2] = (dim2Size) ? (dim2Size) : 1;
+	
+	#if DEBUG 
+	{
+		Stream* dimensionError = Journal_Register( Error_Type, (Name)"DimensionMacros" );
+		Journal_Firewall( (dim0 < dimSizes[0] ), dimensionError, "Error: Given coordinate[0] value %d >= "
+			"regionSize[0] %d\n", dim0, dimSizes[0] );
+		Journal_Firewall( (dim1 < dimSizes[1]), dimensionError, "Error: Given coordinate[1] value %d >= "
+			"regionSize[1] %d\n", dim1, dimSizes[1] );
+		Journal_Firewall( (dim2 < dimSizes[2]), dimensionError, "Error: Given coordinate[2] value %d >= "
+			"regionSize[2] %d\n", dim2, dimSizes[2] );
+	}	
+	#endif
+	
+	Dimension_3DTo1D_3_Macro( dim0, dim1, dim2, dim0Size, dim1Size, dim2Size, outputIndexPtr );
+}	
+
+void Dimension_1DTo3D_3_Func( Index index, Index dim0Size, Index dim1Size, Index dim2Size,
+		Index* dim0Ptr, Index* dim1Ptr, Index* dim2Ptr ) 
+{
+	Dimension_1DTo3D_3_Macro( index, dim0Size, dim1Size, dim2Size, dim0Ptr, dim1Ptr, dim2Ptr );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Edge.c
--- a/Geometry/src/Edge.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,99 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Edge.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "Edge.h"
-
-#include <stdlib.h>
-#include <assert.h>
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-#define Edge_TriMax( triCount )		\
-	(2 * triCount + 1)
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-Edge_Index Edge_BuildList_FromTriangles(
-		Triangle_List		triTbl, 
-		Triangle_Index		triCount, 
-		Edge_List*		edgeTbl, 
-		EdgeFaces_List*		edgeFacesTbl )
-{
-	Edge_Index	cnt = 0;
-	Triangle_Index	tri_I;
-	
-	*edgeTbl = Memory_Alloc_Array( Edge, Edge_TriMax(triCount), "Edge->edgeTbl" );
-	*edgeFacesTbl = Memory_Alloc_Array( EdgeFaces, Edge_TriMax(triCount), "Edge->edgeFacesTbl" );
-	
-	for( tri_I = 0; tri_I < triCount; tri_I++ )
-	{
-		Index		i;
-		
-		for( i = 0; i < 3; i++ )
-		{
-			Coord_Index	p1 = triTbl[tri_I][i];
-			Coord_Index	p2 = triTbl[tri_I][(i + 1) % 3];
-			Edge_Index	edge_I;
-			
-			for( edge_I = 0; edge_I < cnt; edge_I++ )
-				if( (p1 == (*edgeTbl)[edge_I][0] && p2 == (*edgeTbl)[edge_I][1]) ||
-				    (p1 == (*edgeTbl)[edge_I][1] && p2 == (*edgeTbl)[edge_I][0]) ) break;
-			if (edge_I < cnt)
-			{
-				(*edgeFacesTbl)[edge_I][1] = tri_I;
-				continue;
-			}
-			
-			(*edgeTbl)[cnt][0] = p1;
-			(*edgeTbl)[cnt][1] = p2;
-			(*edgeFacesTbl)[cnt][0] = tri_I;
-			(*edgeFacesTbl)[cnt++][1] = triCount;
-		}
-	}
-	
-	*edgeTbl = Memory_Realloc_Array( *edgeTbl, Edge, cnt );
-	*edgeFacesTbl = Memory_Realloc_Array( *edgeFacesTbl, EdgeFaces, cnt );
-
-	return cnt;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Edge.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Edge.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,99 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Edge.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "Edge.h"
+
+#include <stdlib.h>
+#include <assert.h>
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+#define Edge_TriMax( triCount )		\
+	(2 * triCount + 1)
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+Edge_Index Edge_BuildList_FromTriangles(
+		Triangle_List		triTbl, 
+		Triangle_Index		triCount, 
+		Edge_List*		edgeTbl, 
+		EdgeFaces_List*		edgeFacesTbl )
+{
+	Edge_Index	cnt = 0;
+	Triangle_Index	tri_I;
+	
+	*edgeTbl = Memory_Alloc_Array( Edge, Edge_TriMax(triCount), "Edge->edgeTbl" );
+	*edgeFacesTbl = Memory_Alloc_Array( EdgeFaces, Edge_TriMax(triCount), "Edge->edgeFacesTbl" );
+	
+	for( tri_I = 0; tri_I < triCount; tri_I++ )
+	{
+		Index		i;
+		
+		for( i = 0; i < 3; i++ )
+		{
+			Coord_Index	p1 = triTbl[tri_I][i];
+			Coord_Index	p2 = triTbl[tri_I][(i + 1) % 3];
+			Edge_Index	edge_I;
+			
+			for( edge_I = 0; edge_I < cnt; edge_I++ )
+				if( (p1 == (*edgeTbl)[edge_I][0] && p2 == (*edgeTbl)[edge_I][1]) ||
+				    (p1 == (*edgeTbl)[edge_I][1] && p2 == (*edgeTbl)[edge_I][0]) ) break;
+			if (edge_I < cnt)
+			{
+				(*edgeFacesTbl)[edge_I][1] = tri_I;
+				continue;
+			}
+			
+			(*edgeTbl)[cnt][0] = p1;
+			(*edgeTbl)[cnt][1] = p2;
+			(*edgeFacesTbl)[cnt][0] = tri_I;
+			(*edgeFacesTbl)[cnt++][1] = triCount;
+		}
+	}
+	
+	*edgeTbl = Memory_Realloc_Array( *edgeTbl, Edge, cnt );
+	*edgeFacesTbl = Memory_Realloc_Array( *edgeFacesTbl, EdgeFaces, cnt );
+
+	return cnt;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Finalise.c
--- a/Geometry/src/Finalise.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool StgDomainGeometry_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Finalise.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,47 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool StgDomainGeometry_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Hex.c
--- a/Geometry/src/Hex.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Simplex.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include "StGermain/StGermain.h"
-#include "Geometry.h"
-
-
-double Hex_Volume( double** verts, unsigned* inc, unsigned* inds ) {
-	static const unsigned	nTets = 5;
-	static const unsigned	tets[5][4] = {{0, 1, 2, 4}, 
-					      {1, 2, 3, 7}, 
-					      {1, 4, 5, 7}, 
-					      {2, 4, 6, 7}, 
-					      {1, 2, 4, 7}};
-	unsigned		curTet[4];
-	double			vol;
-	unsigned		tet_i, ind_i;
-
-	assert( verts );
-	assert( inc );
-	assert( inds );
-
-	vol = 0.0;
-	for( tet_i = 0; tet_i < nTets; tet_i++ ) {
-		for( ind_i = 0; ind_i < 4; ind_i++ )
-			curTet[ind_i] = inds[tets[tet_i][ind_i]];
-		vol += Simplex_Volume( verts, inc, curTet );
-	}
-
-	return vol;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Hex.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Hex.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,66 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Simplex.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "StGermain/StGermain.h"
+#include "Geometry.h"
+
+
+double Hex_Volume( double** verts, unsigned* inc, unsigned* inds ) {
+	static const unsigned	nTets = 5;
+	static const unsigned	tets[5][4] = {{0, 1, 2, 4}, 
+					      {1, 2, 3, 7}, 
+					      {1, 4, 5, 7}, 
+					      {2, 4, 6, 7}, 
+					      {1, 2, 4, 7}};
+	unsigned		curTet[4];
+	double			vol;
+	unsigned		tet_i, ind_i;
+
+	assert( verts );
+	assert( inc );
+	assert( inds );
+
+	vol = 0.0;
+	for( tet_i = 0; tet_i < nTets; tet_i++ ) {
+		for( ind_i = 0; ind_i < 4; ind_i++ )
+			curTet[ind_i] = inds[tets[tet_i][ind_i]];
+		vol += Simplex_Volume( verts, inc, curTet );
+	}
+
+	return vol;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Init.c
--- a/Geometry/src/Init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,56 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Init.c 3882 2006-10-26 04:41:18Z KathleenHumble $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "Init.h"
-#include "Delaunay.h"
-#include "ParallelDelaunay.h"
-
-#include <stdio.h>
-
-Bool StgDomainGeometry_Init( int* argc, char** argv[] ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-		
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Delaunay_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ParallelDelaunay_Type, "0", (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew );
-
-	RegisterParent( Delaunay_Type,               Stg_Component_Type );
-	RegisterParent( ParallelDelaunay_Type,       Delaunay_Type );
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,56 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Init.c 3882 2006-10-26 04:41:18Z KathleenHumble $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "Init.h"
+#include "Delaunay.h"
+#include "ParallelDelaunay.h"
+
+#include <stdio.h>
+
+Bool StgDomainGeometry_Init( int* argc, char** argv[] ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+		
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Delaunay_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Delaunay_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ParallelDelaunay_Type, "0", (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew );
+
+	RegisterParent( Delaunay_Type,               Stg_Component_Type );
+	RegisterParent( ParallelDelaunay_Type,       Delaunay_Type );
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Line.c
--- a/Geometry/src/Line.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Line.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "VectorMath.h"
-#include "Line.h"
-
-#include <stdlib.h>
-#include <assert.h>
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Line.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Line.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,54 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Line.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "VectorMath.h"
+#include "Line.h"
+
+#include <stdlib.h>
+#include <assert.h>
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/ParallelDelaunay.c
--- a/Geometry/src/ParallelDelaunay.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1414 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-*/
-/** \file
-**  Role:
-** The ParallelDelaunay class computes the constrained delaunay triangulation of a set of points
-** in 2 Dimensions along with the voronoi diagram of the point-set.
-** Assumptions:
-**
-** Comments:
-**
-** The recursive divide and conquer algorithm has been implemented from the pseudo-code
-** given in "Primitives for the manipulation of general subdivisions and the computation
-** of voronoi diagrams" by Leonidas Guibas and Jorge Stolfi.
-** ACM transtactions on graphics, Vol. 4, No. 2, April 1985, Pages 74-123
-**
-**
-** $Id: ParallelDelaunay.c 3462 2006-02-19 06:53:24Z RaquibulHassan $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "QuadEdge.h"
-#include "Delaunay.h"
-#include "ParallelDelaunay.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type ParallelDelaunay_Type="ParallelDelaunay";
-#define PI 3.1415926535897932384626
-#define MERGE_FACTOR 1
-
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Constructors
-	*/
-	
-/** Create a ParallelDelaunay */
-ParallelDelaunay* ParallelDelaunay_DefaultNew( Name name )
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( ParallelDelaunay );
-	Type                                                      type = ParallelDelaunay_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ParallelDelaunay_Delete;
-	Stg_Class_PrintFunction*                                _print = _ParallelDelaunay_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ParallelDelaunay_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ParallelDelaunay_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ParallelDelaunay_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ParallelDelaunay_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ParallelDelaunay_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ParallelDelaunay_Destroy;
-	Bool                                                  initFlag = False;
-	Dictionary*                                         dictionary = NULL;
-	CoordF*                                                  sites = NULL;
-	int                                                   numSites = 0;
-	int                                                       rank = 0;
-	int                                                   numProcs = 0;
-	MPI_Comm*                                                 comm = NULL;
-	DelaunayAttributes*                                       attr = NULL;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-	int                       idOffset = ZERO;
-
-	ParallelDelaunay *d = _ParallelDelaunay_New(  PARALLELDELAUNAY_PASSARGS  );
-
-	return d;
-}
-	
-ParallelDelaunay* ParallelDelaunay_New(
-	Name						name,
-	Dictionary*					dictionary,
-	CoordF						*sites,
-	int							numSites,
-	int							rank,
-	int							numProcs,
-	MPI_Comm					*comm,
-	DelaunayAttributes			*attr )
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( ParallelDelaunay );
-	Type                                                      type = ParallelDelaunay_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ParallelDelaunay_Delete;
-	Stg_Class_PrintFunction*                                _print = _ParallelDelaunay_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ParallelDelaunay_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ParallelDelaunay_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ParallelDelaunay_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ParallelDelaunay_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ParallelDelaunay_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ParallelDelaunay_Destroy;
-	Bool                                                  initFlag = True;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-	int                       idOffset = ZERO;
-
-	ParallelDelaunay *d = _ParallelDelaunay_New(  PARALLELDELAUNAY_PASSARGS  );
-	
-	return d;
-}
-
-#define MASTER_PROC 0
-
-	/** Initialise a ParallelDelaunay */
-void ParallelDelaunay_Init(
-	ParallelDelaunay*					self,
-	Name						name,
-	Dictionary*					dictionary,
-	CoordF						*sites,
-	int							numSites,
-	int							rank,
-	int							numProcs,
-	MPI_Comm					*comm,
-	DelaunayAttributes			*attr )
-{
-	self->type = ParallelDelaunay_Type;
-	self->_sizeOfSelf = sizeof( ParallelDelaunay );
-	self->_deleteSelf = False;
-	self->dictionary = dictionary;
-
-	self->_delete = _ParallelDelaunay_Delete;
-	self->_print = _ParallelDelaunay_Print;
-	self->_copy = _ParallelDelaunay_Copy;
-	self->_defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew;
-	self->_construct = _ParallelDelaunay_AssignFromXML;
-	self->_build = _ParallelDelaunay_Build;
-	self->_initialise = _ParallelDelaunay_Initialise;
-	self->_execute = _ParallelDelaunay_Execute;
-	self->_destroy = _ParallelDelaunay_Destroy;
-
-	self->attributes = Memory_Alloc_Unnamed( DelaunayAttributes );
-	memcpy( self->attributes, attr, sizeof( DelaunayAttributes ) );
-	self->attributes->BuildBoundingTriangle = 0;
-
-	_Stg_Class_Init( (Stg_Class*)self );
-	_Stg_Object_Init( (Stg_Object*)self, name, NON_GLOBAL );
-	_Stg_Component_Init( (Stg_Component*)self );
-	_ParallelDelaunay_Init( self, sites, 0, 0, rank, numProcs, comm, numSites, numSites, dictionary, True );
-}
-
-/** Creation implementation */
-ParallelDelaunay* _ParallelDelaunay_New(  PARALLELDELAUNAY_DEFARGS  )
-{
-	DelaunayAttributes* attr_shadowed = attr;
-	Bool initFlag_shadowed = initFlag;
-	ParallelDelaunay *self = NULL;
-	DelaunayAttributes *myAttr = NULL;
-	
-	myAttr = Memory_Alloc_Unnamed( DelaunayAttributes );
-	memcpy( myAttr, attr_shadowed, sizeof( DelaunayAttributes ) );
-	myAttr->BuildBoundingTriangle = 0;
-	
-	assert( _sizeOfSelf >= sizeof(ParallelDelaunay) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	idOffset = 0;
-	initFlag = True;
-	attr     = myAttr;
-
-	self = (ParallelDelaunay*)_Delaunay_New(  DELAUNAY_PASSARGS  );
-	
-	_ParallelDelaunay_Init( self, sites, 0, 0, rank, numProcs, comm, numSites, numSites, dictionary, initFlag_shadowed );
-
-	return self;
-}
-
-int ParallelDelaunayBtreeCompareFunction( void *a, void *b )
-{
-	Site *s1, *s2;
-
-	s1 = (Site*)a;
-	s2 = (Site*)b;
-
-	if( (*(s1->coord))[0] > (*(s2->coord))[0] ){
-		return 1;
-	}
-	else if( (*(s1->coord))[0] == (*(s2->coord))[0] ){
-		if( (*(s1->coord))[1] > (*(s2->coord))[1] ){
-			return 1;
-		}
-		else if( (*(s1->coord))[1] < (*(s2->coord))[1] ){
-			return -1;
-		}
-		else{
-			return 0;
-		}
-	}
-	else{
-		return -1;
-	}
-}
-
-#define epsilon 0.0001
-#define LOAD_TAG 1
-#define DATA_TAG 1<<1
-#define NEW_SITE_FACTOR 100
-void _ParallelDelaunay_Init( ParallelDelaunay* self, CoordF* points, int leftProc, int rightProc, int rank, int numProcs, MPI_Comm* comm, int numSites, int numInputSites, Dictionary* dictionary, Bool initFlag )
-{
-	assert( self );
-
-	self->points = points;
-	self->leftProc = leftProc;
-	self->rightProc = rightProc;
-	self->haloSites[0] = NULL;
-	self->haloSites[1] = NULL;
-	self->localTriangulation = NULL;
-	self->rank = rank;
-	self->numProcs = numProcs;
-	self->comm = comm;
-
-	self->dictionary = dictionary;
-	self->numSites = numSites;
-	self->numInputSites = numInputSites;
-	
-    if (initFlag) {
-	    self->numHaloSites[0] = 0;
-	    self->numHaloSites[1] = 0;
-	    self->sitePool = MemoryPool_New( Site, NEW_SITE_FACTOR, NEW_SITE_FACTOR );
-	    self->coordPool = MemoryPool_New( CoordF, NEW_SITE_FACTOR, NEW_SITE_FACTOR );
-    }
-}
-
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Virtual functions
-	*/
-
-/** Stg_Class_Delete() implementation */
-void _ParallelDelaunay_Delete( void* pd )
-{
-	ParallelDelaunay *self = (ParallelDelaunay*)pd;
-	
-	assert( self );
-
-	_Delaunay_Delete( self );
-}
-
-/** Stg_Class_Print() implementation */
-void _ParallelDelaunay_Print( void* pd, Stream* stream )
-{
-	ParallelDelaunay *self = ( ParallelDelaunay* )pd;
-	
-	assert( self );
-	assert( stream );
-
-	_Delaunay_Print( (Delaunay*)self, stream );
-	Journal_Printf( stream, "ParallelDelaunay (ptr): (%p)\n", self );
-}
-
-void *_ParallelDelaunay_Copy( const void* pd, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap )
-{
-	return NULL;
-}
-
-void _ParallelDelaunay_AssignFromXML( void* pd, Stg_ComponentFactory* cf, void* data )
-{
-	
-}
-
-void _ParallelDelaunay_Build( void* pd, void* data ) {
-	float _minX, _maxX;
-	float _minY, _maxY;
-	int numProcs, numSites, i, j, count;
-	float stride, start;
-	int *alloced = NULL;
-	int offset;
-	ParallelDelaunay *self = (ParallelDelaunay*)pd;
-
-	assert( self );
-	
-	numProcs = self->numProcs;
-	numSites = self->numSites;
-
-	if( numProcs == 1 ){
-		self->leftProc = numProcs;
-		self->rightProc = numProcs;
-	}
-	else{
-		if( self->rank == MASTER_PROC ){
-			self->leftProc = numProcs;
-			self->rightProc = self->rank + 1;
-		}
-		else if( self->rank == (numProcs-1) ){
-			self->leftProc = self->rank - 1;
-			self->rightProc = numProcs;
-		}
-		else{
-			self->leftProc = self->rank - 1;
-			self->rightProc = self->rank + 1;
-		}
-	}
-	
-	self->mapGlobalToLocal = Memory_Alloc_Array_Unnamed( int, numSites );
-	self->processorLoad = Memory_Alloc_Array_Unnamed( int, numProcs );
-	memset( self->processorLoad, 0, sizeof( int )*numProcs );
-
-	if( self->rank == MASTER_PROC ){
-		self->processor = Memory_Alloc_Array_Unnamed( int, numSites );
-
-		alloced = Memory_Alloc_Array_Unnamed( int, numSites );
-		memset( alloced, 0, sizeof( int )*numSites );
-	
-		self->initialOrder = Memory_Alloc_Array_Unnamed( int, numSites );
-		memset( self->initialOrder, 0, sizeof( int )*numSites );
-		
-		Delaunay_FindMinMax( self->sites, self->numSites, &_minX, &_minY, &_maxX, &_maxY );
-		Delaunay_SortSites( self->sites, self->numSites );
-
-		for( i=0; i<numSites; i++ ){
-			self->initialOrder[i] = self->sites[i].id;
-		}
-		
-		stride = (_maxX - _minX)/((float)numProcs);
-
-		start = _minX;
-		for( i=0; i<numProcs; i++ ){
-			for( j=0; j<numSites; j++ ){
-				if( ((*(self->sites[j].coord))[0] >= start-epsilon) &&
-						((*(self->sites[j].coord))[0] <= (start+stride+epsilon)) &&
-						(!alloced[j]) ){
-					
-					alloced[j] = 1;
-					self->processorLoad[i]++;
-					self->processor[j] = i;
-				}
-			}
-			start+=stride;
-		}
-		
-		/*for( i=0; i<numProcs; i++ ){
-			printf( "processorLoad[%d] = %d\n", i, self->processorLoad[i] );
-		}*/
-		
-		for( i=MASTER_PROC+1; i<numProcs; i++ ){
-			MPI_Send( &(self->processorLoad[i]), 1, MPI_INT, i, LOAD_TAG, *self->comm );
-		}
-
-		self->numLocalSites = self->processorLoad[MASTER_PROC];
-		self->localPoints = Memory_Alloc_Array_Unnamed( CoordF, self->numLocalSites );
-		
-		{
-			CoordF **procCoords = NULL;
-			int *procCoordCounter = NULL;
-
-			procCoordCounter = (int*)malloc( sizeof(int)*numProcs );
-			memset( procCoordCounter, 0, sizeof(int)*numProcs );
-
-			procCoords = (float (**)[3])malloc( sizeof( CoordF* ) * numProcs );
-			for( i=MASTER_PROC+1; i<numProcs; i++ ){
-                          procCoords[i] = (float (*)[3])malloc( sizeof(CoordF) * self->processorLoad[i] );
-				memset( procCoords[i], 0, sizeof( CoordF ) * self->processorLoad[i] );
-			}
-
-			count = 0;
-			for( i=0; i<numSites; i++ ){
-				if( self->processor[i] == MASTER_PROC ){
-					memcpy( &(self->localPoints[count++]), self->sites[i].coord, sizeof(CoordF) );
-				}
-				else{
-					memcpy( &(procCoords[self->processor[i]][procCoordCounter[self->processor[i]]++]), self->sites[i].coord,  sizeof(CoordF) );
-				}			
-			}
-			
-			for( i=MASTER_PROC+1; i<numProcs; i++ ){
-				MPI_Send( procCoords[i], sizeof( CoordF )*self->processorLoad[i], MPI_BYTE, i, DATA_TAG, *self->comm );
-			}
-
-			free( procCoordCounter );
-			for( i=MASTER_PROC+1; i<numProcs; i++ ){
-				free( procCoords[i] );
-			}
-			free( procCoords );
-		}
-
-		Memory_Free( alloced );
-	}
-	else{
-		MPI_Status status;
-		
-		MPI_Recv( &self->numLocalSites, 1, MPI_INT, MASTER_PROC, LOAD_TAG, *self->comm, &status );
-
-		self->localPoints = Memory_Alloc_Array_Unnamed( CoordF, self->numLocalSites );
-
-		MPI_Recv( self->localPoints, sizeof(CoordF)*self->numLocalSites, MPI_BYTE, MASTER_PROC, DATA_TAG, *self->comm, &status );
-	}
-
-	MPI_Bcast( self->processorLoad, numProcs, MPI_INT, MASTER_PROC, *self->comm );
-	self->numTotalLocalSites = self->numLocalSites;
-
-	offset = 0;
-	for( i=0; i<self->rank; i++ ){
-		offset += self->processorLoad[i];
-	}
-	
-	self->localTriangulation = Delaunay_New( "delaunay", self->dictionary, self->localPoints, self->numLocalSites, offset, self->attributes );
-	self->localTriangulation->qp = MemoryPool_New( QuadEdge, self->localTriangulation->numSites * (3 + MERGE_FACTOR), 10 );
-	Delaunay_SortSites(self->localTriangulation->sites, self->localTriangulation->numSites);
-    Delaunay_Recurse(self->localTriangulation, 0, self->localTriangulation->numSites,
-			&self->localTriangulation->leftMost, &self->localTriangulation->rightMost);
-
-	for( i=0; i<numSites; i++ ){
-		self->mapGlobalToLocal[i] = numSites;
-	}
-	
-	for( i=0; i<self->numLocalSites; i++ ){
-		self->mapGlobalToLocal[self->localTriangulation->sites[i].id] = self->localTriangulation->sites[i].id;
-	}
-	
-	if( self->leftProc != self->numProcs ){
-		ParallelDelaunayMerge( self, self->comm, self->leftProc );
-	}
-		
-	if( self->rightProc != self->numProcs ){
-		ParallelDelaunayMerge( self, self->comm, self->rightProc );
-	}
-}
-
-void _ParallelDelaunay_Initialise( void* pd, void* data )
-{
-	
-}
-
-void _ParallelDelaunay_Execute( void* pd, void* data )
-{
-	DelaunayAttributes attr;
-	ParallelDelaunay *self = (ParallelDelaunay*)pd;
-	int offset, i;
-	
-	offset = 0;
-	for( i=0; i<self->rank; i++ ){
-		offset += self->processorLoad[i];
-	}
-
-	if( self->leftProc != self->numProcs ){
-		ParallelDelaunay_RetriangulateAfterMerge( self, LEFT );
-	}
-
-	if( self->rightProc != self->numProcs ){
-		ParallelDelaunay_RetriangulateAfterMerge( self, RIGHT );
-	}
-
-	Stg_Class_Delete( self->localTriangulation );
-	
-	memcpy( &attr, self->attributes, sizeof( DelaunayAttributes ) );
-	attr.BuildTriangleIndices = 0;
-	self->localTriangulation = Delaunay_New( "delaunay", self->dictionary, self->localPoints, self->numTotalLocalSites, offset, &attr );
-	Stg_Component_Build( self->localTriangulation, NULL, True );
-	
-	if( self->attributes->BuildTriangleIndices ){
-		ParallelDelaunay_BuildTriangleIndices( self );
-	}	
-}
-
-void _ParallelDelaunay_Destroy( void* pd, void* data ) { 
-   ParallelDelaunay *self = (ParallelDelaunay*)pd;
-	
-	assert( self );
-   Memory_Free( self->localPoints );
-	if( self->mappingTable[0] ) Memory_Free( self->mappingTable[0] );
-	if( self->mappingTable[1] ) Memory_Free( self->mappingTable[1] );
-	Memory_Free( self->mapGlobalToLocal );
-	if( self->processor ) Memory_Free( self->processor );
-	if( self->initialOrder ) Memory_Free( self->initialOrder );
-	Memory_Free( self->processorLoad );
-	Memory_Free( self->attributes );
-
-	Stg_Class_Delete( self->localTriangulation );
-	Stg_Class_Delete( self->sitePool );
-	Stg_Class_Delete( self->coordPool );
-
-   _Delaunay_Destroy(pd, data);
-}
-
-#define onCurrentProc( pd, id ) ( id < (pd->processorLoad[pd->rank]+pd->localTriangulation->idOffset) )
-#define onLeftProc( pd, id ) ( ( pd->numHaloSites[0]>0 ) && ( id >= (pd->processorLoad[pd->rank]+pd->localTriangulation->idOffset) ) && \
-				( id < (pd->processorLoad[pd->rank]+pd->numHaloSites[0]+pd->localTriangulation->idOffset) ) )
-#define onRightProc( pd, id ) ( ( pd->numHaloSites[1]>0 ) && ( id >= (pd->processorLoad[pd->rank]+pd->localTriangulation->idOffset+pd->numHaloSites[0]) ) && \
-				( id < (pd->numTotalLocalSites+pd->localTriangulation->idOffset) ) )
-
-void ParallelDelaunay_RetriangulateAfterMerge( ParallelDelaunay *pd, Direction d )
-{
-		BTreeIterator *iter = NULL;
-		Site *result = NULL;
-		ParallelDelaunay *self = pd;
-		int i = 0;
-		int numProcs;
-		int numSites;
-		int count;
-		int offset;
-
-		numProcs = self->numProcs;
-		numSites = self->numSites;
-		offset = 0;
-		for( i=0; i<self->rank; i++ ){
-			offset += self->processorLoad[i];
-		}
-		
-		self->haloSites[d] = BTree_New( ParallelDelaunayBtreeCompareFunction, NULL, NULL, NULL, BTREE_NO_DUPLICATES );
-		
-		for( i=0; i<self->localTriangulation->qp->numElements; i++ ){
-			if( IS_FREE((QuadEdgeRef)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)])) ) continue;
-	
-			if( self->mapGlobalToLocal[((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[0])->id] == numSites )
-				BTree_InsertNode( self->haloSites[d], ((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[0]), sizeof( Site* ) );
-			
-			if( self->mapGlobalToLocal[((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[2])->id] == numSites )
-				BTree_InsertNode( self->haloSites[d], ((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[2]), sizeof( Site* ) );
-		}
-
-		self->localPoints = Memory_Realloc_Array
-			( self->localPoints, CoordF, sizeof(CoordF) * (self->numTotalLocalSites + self->haloSites[d]->nodeCount) );
-		
-		self->mappingTable[d] = Memory_Alloc_Array_Unnamed( int, self->haloSites[d]->nodeCount );
-		memset( self->mappingTable[d], 0, sizeof( int ) * self->haloSites[d]->nodeCount );
-		
-		count=0;
-		i = self->numTotalLocalSites;
-		iter = BTreeIterator_New( self->haloSites[d] );
-		for( result=(Site*)BTreeIterator_First(iter);
-				result;
-				result=(Site*)BTreeIterator_Next(iter)){
-			
-			self->mappingTable[d][count++] = result->id;
-			memcpy( &(self->localPoints[i++]), result->coord, sizeof( CoordF ) );
-		}
-		Stg_Class_Delete( self->localTriangulation );
-
-		self->localTriangulation = Delaunay_New( "delaunay", self->dictionary, self->localPoints, self->numLocalSites, offset, self->attributes );
-		self->localTriangulation->qp = MemoryPool_New( QuadEdge, self->localTriangulation->numSites * 4, 10 );
-		Delaunay_SortSites(self->localTriangulation->sites, self->localTriangulation->numSites);
-    	Delaunay_Recurse(self->localTriangulation, 0, self->localTriangulation->numSites,
-				&self->localTriangulation->leftMost, &self->localTriangulation->rightMost);
-
-		self->numHaloSites[d] = self->haloSites[d]->nodeCount;
-		self->numTotalLocalSites += self->haloSites[d]->nodeCount;
-		
-		Stg_Class_Delete( self->haloSites[d] );
-		Stg_Class_Delete( iter );
-}
-
-void ParallelDelaunay_BuildTriangleIndices( ParallelDelaunay *pd )
-{
-	int i = 0, triCount;
-	QuadEdgeRef e = 0, eStart = 0, eOnext = 0, eLnext = 0;
-	QuadEdge *edges = NULL;
-	Site *sites = NULL;
-	int maxEdges = 0;
-	int rank = 0;
-	int pass = 0;
-	unsigned int **triIndices = NULL;
-	Delaunay *delaunay = NULL;
-
-	delaunay = pd->localTriangulation;
-
-	assert( delaunay );
-
-	delaunay->triangleIndices = Memory_Alloc_Array_Unnamed( unsigned int*, delaunay->numFaces );
-	delaunay->triangleIndices[0] = Memory_Alloc_Array_Unnamed( unsigned int, delaunay->numFaces * 3 );
-	memset( delaunay->triangleIndices[0] , 0, sizeof(unsigned int) * delaunay->numFaces * 3 );
-
-	for( i=0; i<delaunay->numFaces; i++ ){
-		delaunay->triangleIndices[i] = delaunay->triangleIndices[0]+i*3;
-	}
-	
-	triIndices = delaunay->triangleIndices;
-	
-	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
-	sites = delaunay->sites;
-	rank = pd->rank;
-	maxEdges = delaunay->qp->numElements;
-		
-	for (i = 0; i < maxEdges; i++) {
-		edges[i].count = 0;
-	}
-
-	triCount = 0;
-	for (i = 0; i < maxEdges; i++) {
-		
-		e = eStart = (QuadEdgeRef)((void*)&(edges[i]));
-		
-		if( IS_FREE(e) )continue;
-		
-		do{
-			eOnext = ONEXT(e);
-			eLnext = LNEXT(e);
-			
-			if( (COUNT(e)<2) && (COUNT(LNEXT(e))<2) && (COUNT(eOnext)<2) ){
-				if( ((((Site*)ORG(eLnext)) == ((Site*)DEST(e)))) &&
-				 ((((Site*)DEST(eLnext)) == ((Site*)DEST(eOnext)))) ){
-		
-					if( onCurrentProc( pd, ((Site*)ORG(e))->id ) ||
-						onCurrentProc( pd, ((Site*)DEST(e))->id ) ||
-						onCurrentProc( pd, ((Site*)DEST(eOnext))->id ) ){
-						
-						pass = 0;
-						if( !onCurrentProc( pd, ((Site*)ORG(e))->id ) ){
-							if( !onRightProc( pd, ((Site*)ORG(e))->id ) ) pass = 1;
-						}
-						
-						if( !onCurrentProc( pd, ((Site*)DEST(e))->id ) ){
-							if( !onRightProc( pd, ((Site*)DEST(e))->id ) ) pass = 1;
-						}
-						
-						if( !onCurrentProc( pd, ((Site*)DEST(eOnext))->id ) ){
-							if( !onRightProc( pd, ((Site*)DEST(eOnext))->id ) ) pass = 1;
-						}
-						
-						if( !pass ){
-							triIndices[triCount][0] = ParallelDelaunay_TranslateLocalToGlobal(pd, ((Site*)ORG(e))->id);
-							triIndices[triCount][1] = ParallelDelaunay_TranslateLocalToGlobal(pd, ((Site*)DEST(e))->id);
-							triIndices[triCount][2] = ParallelDelaunay_TranslateLocalToGlobal(pd, ((Site*)DEST(eOnext))->id);
-
-							triCount++;
-						}
-					}
-
-					COUNT(e)++;
-					COUNT(LNEXT(e))++;
-					COUNT(eOnext)++;
-				}
-			}
-			e = eOnext;
-		}while( e != eStart );
-	}
-	
-	delaunay->numTriangles = triCount;
-}
-
-#define NEIGHBOURS_TAG 1<<4
-#define VORONOI_SIDES_TAG 1<<5
-#define VORONOI_AREA_TAG 1<<6
-#define NUM_NEIGHBOUR_TAG 1<<7
-#define MAX_NEIGHBOURS 100
-
-void ParallelDelaunay_GatherTriangulation( ParallelDelaunay *pd )
-{
-	int i, j, k, l, count, count1;
-	MPI_Status st;
-	int numNeighboursSum = 0;
-	int stride = 0;
-	
-	assert( pd );
-
-	if( pd->rank == MASTER_PROC ){
-		
-		if( pd->attributes->CalculateVoronoiSurfaceArea ){
-			pd->voronoiArea = Memory_Alloc_Array_Unnamed( float, pd->numInputSites );
-		}
-
-		if( pd->attributes->FindNeighbours ){
-			pd->numNeighbours = Memory_Alloc_Array_Unnamed( unsigned int, pd->numInputSites );
-		}
-		
-		count = 0;
-		count1 = 0;
-		numNeighboursSum = 0;
-
-		{
-			float **procVoronoi = NULL;
-			int **procNumNeighbours = NULL;
-			int *procVoronoiCounter = NULL;
-			int *procNumNeighboursCounter = NULL;
-
-			procVoronoiCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
-			memset( procVoronoiCounter, 0, sizeof( int ) * pd->numProcs );
-			
-			procNumNeighboursCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
-			memset( procNumNeighboursCounter, 0, sizeof( int ) * pd->numProcs );
-
-			procVoronoi = (float**)malloc( sizeof( float* ) * pd->numProcs ); memset( procVoronoi, 0, sizeof(float*)*pd->numProcs );
-			procNumNeighbours = (int**)malloc( sizeof( int* ) * pd->numProcs ); memset( procNumNeighbours, 0, sizeof(int*)*pd->numProcs );
-
-			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
-
-				if( pd->attributes->CalculateVoronoiSurfaceArea ){
-                                  procVoronoi[i] = (float*)malloc( sizeof(float)*pd->processorLoad[i] );
-					memset( procVoronoi[i], 0, sizeof( float ) * pd->processorLoad[i] );
-					MPI_Recv( procVoronoi[i], pd->processorLoad[i], MPI_FLOAT, i, VORONOI_AREA_TAG, (*pd->comm), &st );
-				}
-
-				if( pd->attributes->FindNeighbours ){
-                                  procNumNeighbours[i] = (int*)malloc( sizeof(int)*pd->processorLoad[i] );
-					memset( procNumNeighbours[i], 0, sizeof(int) * pd->processorLoad[i] );
-					MPI_Recv( procNumNeighbours[i], pd->processorLoad[i], MPI_INT, i, NUM_NEIGHBOUR_TAG, (*pd->comm), &st );
-				}
-			}
-
-			for( i=0; i<pd->numInputSites; i++ ){
-				int proc, order;
-				proc = pd->processor[i];
-				order = pd->initialOrder[i];
-
-				if( pd->attributes->CalculateVoronoiSurfaceArea ){
-					if( pd->processor[i] == MASTER_PROC ){
-						memcpy( &(pd->voronoiArea[pd->initialOrder[i]]), &(pd->localTriangulation->voronoiArea[count++]), sizeof( float ) );
-					}
-					else{
-						memcpy( &(pd->voronoiArea[order]), &(procVoronoi[proc][procVoronoiCounter[proc]++]), sizeof(float) );
-					}
-				}
-			
-				if( pd->attributes->FindNeighbours ){
-					if( pd->processor[i] == MASTER_PROC ){
-						memcpy( &(pd->numNeighbours[pd->initialOrder[i]]), &(pd->localTriangulation->numNeighbours[count1++]), sizeof( int ) );
-					}
-					else{
-						memcpy( &(pd->numNeighbours[pd->initialOrder[i]]), &(procNumNeighbours[proc][procNumNeighboursCounter[proc]++]), sizeof( int ) );
-					}
-					numNeighboursSum += pd->numNeighbours[pd->initialOrder[i]];
-				}
-			}
-			
-			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
-				if( procVoronoi[i] ) free( procVoronoi[i] );
-				if( procNumNeighbours[i] ) free( procNumNeighbours[i] );
-			}
-			free( procVoronoi );
-			free( procNumNeighbours );
-			free( procVoronoiCounter );
-			free( procNumNeighboursCounter );
-		}
-
-		if( pd->attributes->FindNeighbours ){
-			pd->neighbours = Memory_Alloc_Array_Unnamed( unsigned int*, pd->numInputSites );
-			pd->neighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, numNeighboursSum );
-		}
-	
-		if( pd->attributes->CalculateVoronoiSides ){
-			pd->voronoiSides = Memory_Alloc_Array_Unnamed( float*, pd->numInputSites );
-			pd->voronoiSides[0] = Memory_Alloc_Array_Unnamed( float, numNeighboursSum );
-		}
-		
-		stride = 0;
-		for( j=0; j<pd->numInputSites; j++ ){
-			if( pd->attributes->FindNeighbours ){
-				pd->neighbours[j] = pd->neighbours[0]+stride;
-			}
-			
-			if( pd->attributes->CalculateVoronoiSides ){
-				pd->voronoiSides[j] = pd->voronoiSides[0]+stride;
-			}
-
-			if( pd->attributes->FindNeighbours ){
-				stride += pd->numNeighbours[j];
-			}
-		}
-		
-		{
-			float **procVoronoiSides = NULL;
-			float **procNeighbours = NULL;
-			int *procVoronoiSidesCounter = NULL;
-			int *procNeighboursCounter = NULL;
-			int *procNumNeighboursCount = NULL;
-
-			procVoronoiSidesCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
-			memset( procVoronoiSidesCounter, 0, sizeof( int ) * pd->numProcs );
-			
-			procNeighboursCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
-			memset( procNeighboursCounter, 0, sizeof( int ) * pd->numProcs );
-			
-			procNumNeighboursCount = (int*)malloc( sizeof( int ) * pd->numProcs );
-			memset( procNumNeighboursCount, 0, sizeof( int ) * pd->numProcs );
-
-			procVoronoiSides = (float**)malloc( sizeof( float* ) * pd->numProcs ); memset( procVoronoiSides, 0, sizeof(float*)*pd->numProcs );
-			procNeighbours = (float**)malloc( sizeof( unsigned int* ) * pd->numProcs ); memset( procNeighbours, 0, sizeof(unsigned int*)*pd->numProcs );
-
-			for( i=0; i<pd->numInputSites; i++ ){
-				procNumNeighboursCount[pd->processor[i]]+=pd->numNeighbours[pd->initialOrder[i]];
-			}
-
-			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
-				if( pd->attributes->CalculateVoronoiSides ){
-                                  procVoronoiSides[i] = (float*)malloc( sizeof(float)*procNumNeighboursCount[i] );
-					memset( procVoronoiSides[i], 0, sizeof( float ) * procNumNeighboursCount[i] );
-					MPI_Recv( procVoronoiSides[i], procNumNeighboursCount[i], MPI_FLOAT, i, VORONOI_SIDES_TAG, (*pd->comm), &st );
-				}
-
-				if( pd->attributes->FindNeighbours ){
-                                  procNeighbours[i] = (float*)malloc( sizeof(unsigned int)*procNumNeighboursCount[i] );
-					memset( procNeighbours[i], 0, sizeof(unsigned int) * procNumNeighboursCount[i] );
-					MPI_Recv( procNeighbours[i], procNumNeighboursCount[i], MPI_INT, i, NEIGHBOURS_TAG, (*pd->comm), &st );
-				}
-			}
-
-			count = 0;
-			for(j=0; j<pd->numInputSites; j++){
-				int proc, order;
-				proc = pd->processor[j];
-				order = pd->initialOrder[j];
-				
-				if( pd->processor[j] == MASTER_PROC ){
-					if( pd->attributes->CalculateVoronoiSides ){
-						memcpy( (pd->voronoiSides[pd->initialOrder[j]]), (pd->localTriangulation->voronoiSides[count]),
-								sizeof(float)*pd->localTriangulation->numNeighbours[count] );
-					}
-					if( pd->attributes->FindNeighbours ){
-						memcpy( (pd->neighbours[pd->initialOrder[j]]), (pd->localTriangulation->neighbours[count]),
-								sizeof(int)*pd->localTriangulation->numNeighbours[count] );
-						for( i=0; i<(int)(pd->numNeighbours[pd->initialOrder[j]]); i++ ){
-							pd->neighbours[pd->initialOrder[j]][i] = 
-								pd->initialOrder[ParallelDelaunay_TranslateLocalToGlobal(pd, pd->neighbours[pd->initialOrder[j]][i])];
-						}
-					}
-					count++;
-				}
-				else{
-					if( pd->attributes->CalculateVoronoiSides ){
-						memcpy( (pd->voronoiSides[pd->initialOrder[j]]),
-								&(procVoronoiSides[proc][procVoronoiSidesCounter[proc]]),
-								sizeof(float)*pd->numNeighbours[order] );
-						procVoronoiSidesCounter[proc]+=pd->numNeighbours[order];
-					}
-					if( pd->attributes->FindNeighbours ){
-						memcpy( (pd->neighbours[pd->initialOrder[j]]),
-								&(procNeighbours[proc][procNeighboursCounter[proc]]),
-								sizeof(int)*pd->numNeighbours[order] );
-						procNeighboursCounter[proc]+=pd->numNeighbours[order];
-
-						for( i=0; i<(int)(pd->numNeighbours[pd->initialOrder[j]]); i++ ){
-							pd->neighbours[pd->initialOrder[j]][i] = pd->initialOrder[pd->neighbours[pd->initialOrder[j]][i]];
-						}
-					}
-				}
-			}
-
-			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
-				if( procVoronoiSides[i] ) free( procVoronoiSides[i] );
-				if( procNeighbours[i] ) free( procNeighbours[i] );
-			}
-			free( procVoronoiSides );
-			free( procNeighbours );
-			free( procVoronoiSidesCounter );
-			free( procNeighboursCounter );			
-			free( procNumNeighboursCount );			
-		}
-	}
-	else{
-		if( pd->attributes->CalculateVoronoiSurfaceArea ){
-			MPI_Send( (pd->localTriangulation->voronoiArea), pd->numLocalSites, MPI_FLOAT, MASTER_PROC, VORONOI_AREA_TAG, (*pd->comm) );
-		}
-			
-		if( pd->attributes->FindNeighbours ){
-			MPI_Send( (pd->localTriangulation->numNeighbours), pd->numLocalSites, MPI_INT, MASTER_PROC, NUM_NEIGHBOUR_TAG, (*pd->comm) );
-		}
-		
-		if( pd->attributes->CalculateVoronoiSides ){
-			int sum = 0;
-			for( i=0; i<pd->numLocalSites; i++ ){
-				sum+=pd->localTriangulation->numNeighbours[i];
-			}
-			MPI_Send( pd->localTriangulation->voronoiSides[0], sum, 
-					MPI_FLOAT, MASTER_PROC, VORONOI_SIDES_TAG, *(pd->comm));
-		}
-
-		if( pd->attributes->FindNeighbours ){
-			int sum = 0;
-			for( i=0; i<pd->numLocalSites; i++ ){
-				sum+=pd->localTriangulation->numNeighbours[i];
-				
-				for( j=0; j<(int)(pd->localTriangulation->numNeighbours[i]); j++ ){
-					pd->localTriangulation->neighbours[i][j] = ParallelDelaunay_TranslateLocalToGlobal( pd, pd->localTriangulation->neighbours[i][j] );
-				}
-			}
-			MPI_Send( pd->localTriangulation->neighbours[0], sum, MPI_INT, MASTER_PROC, NEIGHBOURS_TAG, *(pd->comm) );
-		}
-	}
-	
-	if( pd->attributes->BuildTriangleIndices ){
-		unsigned int **triIndices = NULL;
-		int globalNumTriangles = 0;
-		Delaunay *delaunay = NULL;
-		int *triCountArray = NULL;
-		int triCount = 0;
-		int rank = 0;
-
-		delaunay = pd->localTriangulation;
-
-		assert( delaunay );
-	
-		triIndices = delaunay->triangleIndices;
-		triCount = delaunay->numTriangles;
-
-		MPI_Allreduce( &triCount, &globalNumTriangles, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
-	
-		pd->numTriangles = globalNumTriangles;
-		
-		triCountArray = Memory_Alloc_Array_Unnamed( int, pd->numProcs );
-		rank = pd->rank;
-	
-		if( rank == MASTER_PROC ){
-
-			pd->triangleIndices = Memory_Alloc_Array_Unnamed( unsigned int*,  globalNumTriangles );
-			pd->triangleIndices[0] = Memory_Alloc_Array_Unnamed( unsigned int, globalNumTriangles*3 );
-
-			if ( pd->attributes->BuildTriangleNeighbours ){
-				pd->triangleNeighbours = Memory_Alloc_Array_Unnamed( unsigned int*,  globalNumTriangles );
-				pd->triangleNeighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, globalNumTriangles*3 );
-			}
-
-			triCountArray[0] = triCount;
-			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
-				MPI_Recv( &(triCountArray[i]), 1, MPI_INT, i, DATA_TAG, MPI_COMM_WORLD, &st );					
-			}
-
-			for( i=0; i<globalNumTriangles; i++ ){
-				pd->triangleIndices[i] = pd->triangleIndices[0] + i*3;
-	
-				if ( pd->attributes->BuildTriangleNeighbours ){
-					pd->triangleNeighbours[i] = pd->triangleNeighbours[0] + i*3;
-
-					pd->triangleNeighbours[i][0] = pd->numTriangles;
-					pd->triangleNeighbours[i][1] = pd->numTriangles;
-					pd->triangleNeighbours[i][2] = pd->numTriangles;
-				}
-			}
-
-			for(j=0; j<triCountArray[0]; j++){
-				memcpy( pd->triangleIndices[j], triIndices[j], sizeof(int)*3 );
-			}
-		
-			stride = j;
-			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
-                          unsigned int *temp = (unsigned*)malloc( sizeof(unsigned int)*triCountArray[i]*3 );
-					MPI_Recv( temp, triCountArray[i]*3, MPI_INT, i, DATA_TAG, MPI_COMM_WORLD, &st );					
-				for(j=0; j<triCountArray[i]*3; j+=3){
-					memcpy( pd->triangleIndices[stride++], &(temp[j]), sizeof(int)*3 );
-				}
-				free( temp );
-			}
-
-			for( i=0; i<pd->numTriangles; i++ ){
-				pd->triangleIndices[i][0] = pd->initialOrder[pd->triangleIndices[i][0]];
-				pd->triangleIndices[i][1] = pd->initialOrder[pd->triangleIndices[i][1]];
-				pd->triangleIndices[i][2] = pd->initialOrder[pd->triangleIndices[i][2]];
-			}
-
-			/*for( j=0; j<globalNumTriangles; j++ ){
-				printf( "indices[%d] = [%d, %d, %d]\n", j, pd->triangleIndices[j][0], pd->triangleIndices[j][1], pd->triangleIndices[j][2] );
-			}*/
-			
-			stride = 0;
-			if ( pd->attributes->BuildTriangleNeighbours ){
-				int **nodeToTriangle = NULL;
-				int *nodeToTriangleCount = NULL;
-				int *triangleNeighboursCount = NULL;
-				int triangles[2];
-				int counter = 0;
-				int found = 0;
-				int m = 0;
-
-				nodeToTriangle = Memory_Alloc_Array_Unnamed( int*, pd->numInputSites );
-				nodeToTriangle[0] = Memory_Alloc_Array_Unnamed( int, numNeighboursSum );
-
-				nodeToTriangleCount = Memory_Alloc_Array_Unnamed( int, pd->numInputSites );
-				memset( nodeToTriangleCount, 0, sizeof( int ) * pd->numInputSites );
-				
-				triangleNeighboursCount = Memory_Alloc_Array_Unnamed( int, pd->numTriangles );
-				memset( triangleNeighboursCount, 0, sizeof( int ) * pd->numTriangles );
-
-				for( i=0; i<pd->numSites; i++ ){
-					nodeToTriangle[i] = nodeToTriangle[0] + stride;
-
-					stride += pd->numNeighbours[i];
-				}
-
-				for( i=0; i<pd->numTriangles; i++ ){
-					nodeToTriangle[pd->triangleIndices[i][0]][nodeToTriangleCount[pd->triangleIndices[i][0]]++] = i;
-					nodeToTriangle[pd->triangleIndices[i][1]][nodeToTriangleCount[pd->triangleIndices[i][1]]++] = i;
-					nodeToTriangle[pd->triangleIndices[i][2]][nodeToTriangleCount[pd->triangleIndices[i][2]]++] = i;
-				}
-				
-				for( i=0; i<pd->numInputSites; i++ ){
-                                  for( j=0; j<(int)(pd->numNeighbours[i]); j++ ){
-						triangles[0] = -1;
-						triangles[1] = -1;
-						counter = 0;
-						for( k=0; k<nodeToTriangleCount[i]; k++ ){
-							for( l=0; l<3; l++ ){
-								if( pd->neighbours[i][j] == pd->triangleIndices[nodeToTriangle[i][k]][l] ){
-									triangles[counter++] = nodeToTriangle[i][k];
-								}
-							}
-						}
-						
-						if( (triangles[0] > -1) ){
-							
-							found = 0;
-							for( m=0; m<3; m++ ){
-                                                          if( pd->triangleNeighbours[triangles[0]][m] == (unsigned)(triangles[1]) ) found = 1;
-							}
-							if( !found ){
-								pd->triangleNeighbours[triangles[0]][triangleNeighboursCount[triangles[0]]++] = triangles[1];
-							}
-						}
-						if( (triangles[1] > -1) ){
-						
-							found = 0;
-							for( m=0; m<3; m++ ){
-                                                          if( pd->triangleNeighbours[triangles[1]][m] == (unsigned)(triangles[0]) ) found = 1;
-							}
-							if( !found ){
-								pd->triangleNeighbours[triangles[1]][triangleNeighboursCount[triangles[1]]++] = triangles[0];
-							}
-						}
-					}
-				}
-				
-				Memory_Free( nodeToTriangle[0] );
-				Memory_Free( nodeToTriangle );
-				Memory_Free( nodeToTriangleCount );
-				Memory_Free( triangleNeighboursCount );
-			}
-		}
-		else{
-			MPI_Send( &triCount, 1, MPI_INT, MASTER_PROC, DATA_TAG, MPI_COMM_WORLD );
-			MPI_Send( triIndices[0], 3*triCount, MPI_INT, MASTER_PROC, DATA_TAG, MPI_COMM_WORLD );
-		}
-
-		Memory_Free( triCountArray );
-	}	
-}
-
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Private Member functions
-	*/
-
-int ParallelDelaunay_TranslateLocalToGlobal( ParallelDelaunay *self, int id )
-{
-	if( id >= (self->localTriangulation->idOffset+self->numLocalSites) ){
-	
-		if( (self->leftProc != self->numProcs) && (id < (self->localTriangulation->idOffset+self->numLocalSites + self->numHaloSites[0])) ){
-			
-			id = self->mappingTable[0][(id -
-						(self->localTriangulation->idOffset+
-						 self->numLocalSites))];
-		}
-		else{
-
-			id = self->mappingTable[1][(id -
-						(self->localTriangulation->idOffset+
-						 self->numLocalSites+
-						 self->numHaloSites[0]))];
-		}
-		return id;
-	}
-	else{
-		return id;
-	}
-}
-
-#define EDGE_TAG 102
-#define BREAK_TAG 103
-typedef struct SitePacket_t{
-	int id;
-	float xyz[3];
-}SitePacket;
-void ParallelDelaunaySendEdge( QuadEdgeRef edge, int rank, MPI_Comm *comm, MPI_Request *req )
-{
-	SitePacket sp[2];
-	assert(edge);
-
-	memcpy( sp[0].xyz, ((Site*)ORG(edge))->coord, sizeof( CoordF ) );
-	sp[0].id = ((Site*)ORG(edge))->id;
-	
-	memcpy( sp[1].xyz, ((Site*)DEST(edge))->coord, sizeof( CoordF ) );
-	sp[1].id = ((Site*)DEST(edge))->id;
-	MPI_Isend( sp, sizeof(SitePacket)*2, MPI_BYTE, rank, EDGE_TAG, *comm, req );
-}
-
-QuadEdgeRef ParallelDelaunayRecvEdge( ParallelDelaunay *pd, int rank, MPI_Comm *comm )
-{
-	QuadEdgeRef edge = 0;
-	CoordF *c[2];
-	Site *s[2];
-	MPI_Status st;
-	SitePacket sp[2];
-	Delaunay *d = NULL;
-	
-	assert( pd );
-	d = pd->localTriangulation;
-	
-	edge = MakeQuadEdge( d->qp );
-	
-	assert(edge);
-
-	s[0] = MemoryPool_NewObject( Site, pd->sitePool );
-	s[1] = MemoryPool_NewObject( Site, pd->sitePool );
-	
-	c[0] = MemoryPool_NewObject( CoordF, pd->coordPool );
-	c[1] = MemoryPool_NewObject( CoordF, pd->coordPool );
-	
-	MPI_Recv( sp, sizeof(SitePacket)*2, MPI_BYTE, rank, EDGE_TAG, *comm, &st );
-
-	memcpy( (c[0]), sp[0].xyz, sizeof( CoordF ) );
-	memcpy( (c[1]), sp[1].xyz, sizeof( CoordF ) );
-
-	s[0]->id = sp[0].id;
-	s[0]->coord = (c[0]);
-	s[1]->id = sp[1].id;
-	s[1]->coord = (c[1]);
-	
-	ORG(edge)=(s[0]);
-	DEST(edge)=(s[1]);
-
-	return edge;
-}
-
-int ParallelDelaunayListCompareFunction( void *a, void *b )
-{
-	QuadEdgeRef e1, e2;
-
-	e1 = (QuadEdgeRef)a;
-	e2 = (QuadEdgeRef)b;
-
-	if( e1 > e2 ){
-		return 1;
-	}
-	else if( e1 < e2 ){
-		return -1;
-	}
-	else{
-		return 0;
-	}
-}
-
-void ParallelDelaunayListDeleteFunction( void *a )
-{
-
-}
-
-QuadEdgeRef ParallelDelaunayFindLowestQuadEdge( ParallelDelaunay *pd, MPI_Comm *comm, int rank )
-{
-	QuadEdgeRef ldi=0, rdi=0;
-	MPI_Request r;
-	MPI_Status s;
-	int globalBreak, localBreak;
-	LinkedList *list = NULL;
-	LinkedListIterator *iter;
-	QuadEdgeRef result = 0;
-	Delaunay *d = NULL;
-
-	assert( pd );
-	d = pd->localTriangulation;
-	
-	list = LinkedList_New( ParallelDelaunayListCompareFunction, NULL, NULL, ParallelDelaunayListDeleteFunction, LINKEDLIST_UNSORTED );
-	iter = LinkedListIterator_New( list );
-	
-	if( rank == pd->leftProc ){
-		rdi = d->leftMost;
-	}
-	else if( rank == pd->rightProc ){
-		ldi = d->rightMost;
-	}
-	else{
-		fprintf( stderr, "Failed to find lowest edge on rank %d..!\n Aborting..!\n", rank );
-	}
-
-	if( rank == pd->numProcs ) return 0;
-	
-	localBreak = 0;
-	globalBreak = 0;
-
-	while (1) 
-	{
-		localBreak = 0;
-		globalBreak = 0;
-
-		if( rank == pd->leftProc ){
-			ParallelDelaunaySendEdge( rdi, rank, comm, &r );
-			ldi = ParallelDelaunayRecvEdge( pd, rank, comm );
-			MPI_Wait( &r, &s );
-			LinkedList_InsertNode( list, (void*)ldi, sizeof( QuadEdgeRef* ) );
-			
-			if (RightOf((Site*)ORG(ldi), rdi)){
-				rdi = ONEXT(SYM(rdi));
-				localBreak = 1;
-			}
-			else{
-			}
-		}
-		
-		if( rank == pd->rightProc ){
-			ParallelDelaunaySendEdge( ldi, rank, comm, &r );
-			rdi = ParallelDelaunayRecvEdge( pd, rank, comm );
-			MPI_Wait( &r, &s );
-			LinkedList_InsertNode( list, (void*)rdi, sizeof( QuadEdgeRef* ) );
-			
-			if (LeftOf((Site*)ORG(rdi), ldi)){
-				ldi = LNEXT(ldi);
-				localBreak = 1;
-			}
-			else{
-			}
-		}
-
-		MPI_Isend( &localBreak, 1, MPI_INT, rank, BREAK_TAG, *comm, &r );
-		MPI_Recv( &(globalBreak), 1, MPI_INT, rank, BREAK_TAG, *comm, &s );
-		MPI_Wait( &r, &s );
-		globalBreak |= localBreak;
-		
-		if( globalBreak == 0 ){
-			break;
-		}
-	}
-
-	for( result=(QuadEdgeRef)((void*)LinkedListIterator_First(iter));
-			result != 0;
-			result=(QuadEdgeRef)((void*)LinkedListIterator_Next(iter)) ){
-
-		DeleteQuadEdge( d->qp, result );
-	}
-
-	Stg_Class_Delete( list );
-	Stg_Class_Delete( iter );
-	
-	if( rank == pd->leftProc ){
-		return rdi;
-	}
-	else if( rank == pd->rightProc ){
-		return ldi;
-	}
-	
-	return 0;
-}
-
-void ParallelDelaunayMerge( ParallelDelaunay *pd, MPI_Comm *comm, int rank )
-{
-	QuadEdgeRef lowest = 0, lcand = 0, rcand = 0, basel = 0, baselPrev;
-	MPI_Request r;
-	MPI_Status s;
-	int localBreak=0, globalBreak=0;
-	double result = 0.0f;
-	Delaunay *d = NULL;
-	
-	assert( pd );
-
-	d = pd->localTriangulation;
-
-	lowest = ParallelDelaunayFindLowestQuadEdge( pd, comm, rank );
-	
-	localBreak = 0;
-	globalBreak = 0;
-
-	if( rank == pd->numProcs ){
-		fprintf( stderr, "Failed to merge rank %d with rank %d..!\nAborting..!\n", pd->rank, rank );
-		assert( 0 );
-	}
-	
-	if( rank == pd->leftProc ){
-		rcand = lowest;
-		
-		ParallelDelaunaySendEdge( lowest, rank, comm, &r );
-		lcand = ParallelDelaunayRecvEdge( pd, rank, comm );
-		MPI_Wait( &r, &s );
-		
-		basel = MakeQuadEdge( d->qp );
-		ORG(basel) = DEST(SYM(rcand));
-		DEST(basel) = ORG(lcand);
-
-		DeleteQuadEdge( d->qp, lcand );
-		
-		CCW( ((Site*)DEST(rcand))->coord, ((Site*)DEST(basel))->coord, ((Site*)ORG(basel))->coord, &result);
-		if( result == 0.0f ){
-			rcand = OPREV(rcand);
-		}
-		
-		while(1){
-			localBreak = 0;
-			if (RightOf((Site*)DEST(rcand), basel)){
-				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(rcand), (Site*)DEST(OPREV(rcand)))){
-					QuadEdgeRef t = OPREV(rcand);
-
-					DeleteQuadEdge(d->qp, rcand);
-					rcand = t;
-				}
-			}
-			
-			if (!RightOf((Site*)DEST(rcand), basel)) localBreak = 1;
-
-			MPI_Isend( &localBreak, 1, MPI_INT, rank, BREAK_TAG, *comm, &r );
-			MPI_Recv( &(globalBreak), 1, MPI_INT, rank, BREAK_TAG, *comm, &s );
-			MPI_Wait( &r, &s );
-			globalBreak &= localBreak;
-
-			if( globalBreak ){
-				break;
-			}
-
-			ParallelDelaunaySendEdge( rcand, rank, comm, &r );
-			lcand = ParallelDelaunayRecvEdge( pd, rank, comm );
-			MPI_Wait( &r, &s );
-
-			if ( !RightOf((Site*)DEST(lcand), basel) ||
-				( RightOf((Site*)DEST(rcand), basel) && 
-				InCircle((Site*)DEST(lcand), (Site*)ORG(lcand), (Site*)ORG(rcand), (Site*)DEST(rcand)))){
-			
-				baselPrev = basel;
-				basel = MakeQuadEdge(d->qp);
-				ORG(basel) = DEST(rcand);
-				DEST(basel) = ORG(SYM(baselPrev));
-				
-				rcand=LNEXT(rcand);
-				DeleteQuadEdge( d->qp, lcand );
-			}
-			else{
-				baselPrev = basel;
-				basel = MakeQuadEdge(d->qp);
-				ORG(basel) = DEST(SYM(baselPrev));
-				DEST(basel) = ORG(SYM(lcand));
-			}
-		}
-	}
-	else if( rank == pd->rightProc ){
-		lcand = lowest;
-		
-		ParallelDelaunaySendEdge( lowest, rank, comm, &r );
-		rcand = ParallelDelaunayRecvEdge( pd, rank, comm );
-		MPI_Wait( &r, &s );
-		
-		basel = MakeQuadEdge(d->qp);
-		ORG(basel) = DEST(SYM(rcand));
-		DEST(basel) = ORG(lcand);
-		
-		DeleteQuadEdge( d->qp, rcand );
-		
-		CCW( ((Site*)DEST(lcand))->coord, ((Site*)DEST(basel))->coord, ((Site*)ORG(basel))->coord, &result);
-		if( result == 0.0f ){
-			lcand = ONEXT(lcand);
-		}
-		
-		while(1){
-			localBreak = 0;
-			if (RightOf((Site*)DEST(lcand), basel)){
-				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(lcand), (Site*)DEST(ONEXT(lcand)))){
-					QuadEdgeRef t = ONEXT(lcand);
-					
-					DeleteQuadEdge(d->qp, lcand);
-					lcand = t;
-				}
-			}
-			
-			if (!RightOf((Site*)DEST(lcand), basel)) localBreak = 1;
-
-			MPI_Isend( &localBreak, 1, MPI_INT, rank, BREAK_TAG, *comm, &r );
-			MPI_Recv( &(globalBreak), 1, MPI_INT, rank, BREAK_TAG, *comm, &s );
-			MPI_Wait( &r, &s );
-			globalBreak &= localBreak;
-
-			if( globalBreak ){
-				break;
-			}
-			
-			ParallelDelaunaySendEdge( lcand, rank, comm, &r );
-			rcand = ParallelDelaunayRecvEdge( pd, rank, comm );
-			MPI_Wait( &r, &s );
-
-			if ( !RightOf((Site*)DEST(lcand), basel) ||
-				( RightOf((Site*)DEST(rcand), basel) && 
-				InCircle((Site*)DEST(lcand), (Site*)ORG(lcand), (Site*)ORG(rcand), (Site*)DEST(rcand)))){
-				
-				baselPrev = basel;
-				basel = MakeQuadEdge(d->qp);
-				ORG(basel) = DEST(rcand);
-				DEST(basel) = ORG(SYM(baselPrev));
-			}
-			else{
-				baselPrev = basel;
-				basel = MakeQuadEdge(d->qp);
-				ORG(basel) = DEST(SYM(baselPrev));
-				DEST(basel) = ORG(SYM(lcand));
-				
-				lcand = RPREV(lcand);
-				DeleteQuadEdge( d->qp, rcand );
-			}
-		}
-	}
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/ParallelDelaunay.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/ParallelDelaunay.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1414 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+*/
+/** \file
+**  Role:
+** The ParallelDelaunay class computes the constrained delaunay triangulation of a set of points
+** in 2 Dimensions along with the voronoi diagram of the point-set.
+** Assumptions:
+**
+** Comments:
+**
+** The recursive divide and conquer algorithm has been implemented from the pseudo-code
+** given in "Primitives for the manipulation of general subdivisions and the computation
+** of voronoi diagrams" by Leonidas Guibas and Jorge Stolfi.
+** ACM transtactions on graphics, Vol. 4, No. 2, April 1985, Pages 74-123
+**
+**
+** $Id: ParallelDelaunay.c 3462 2006-02-19 06:53:24Z RaquibulHassan $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "QuadEdge.h"
+#include "Delaunay.h"
+#include "ParallelDelaunay.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type ParallelDelaunay_Type="ParallelDelaunay";
+#define PI 3.1415926535897932384626
+#define MERGE_FACTOR 1
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Constructors
+	*/
+	
+/** Create a ParallelDelaunay */
+ParallelDelaunay* ParallelDelaunay_DefaultNew( Name name )
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( ParallelDelaunay );
+	Type                                                      type = ParallelDelaunay_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ParallelDelaunay_Delete;
+	Stg_Class_PrintFunction*                                _print = _ParallelDelaunay_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ParallelDelaunay_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ParallelDelaunay_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ParallelDelaunay_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ParallelDelaunay_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ParallelDelaunay_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ParallelDelaunay_Destroy;
+	Bool                                                  initFlag = False;
+	Dictionary*                                         dictionary = NULL;
+	CoordF*                                                  sites = NULL;
+	int                                                   numSites = 0;
+	int                                                       rank = 0;
+	int                                                   numProcs = 0;
+	MPI_Comm*                                                 comm = NULL;
+	DelaunayAttributes*                                       attr = NULL;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+	int                       idOffset = ZERO;
+
+	ParallelDelaunay *d = _ParallelDelaunay_New(  PARALLELDELAUNAY_PASSARGS  );
+
+	return d;
+}
+	
+ParallelDelaunay* ParallelDelaunay_New(
+	Name						name,
+	Dictionary*					dictionary,
+	CoordF						*sites,
+	int							numSites,
+	int							rank,
+	int							numProcs,
+	MPI_Comm					*comm,
+	DelaunayAttributes			*attr )
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( ParallelDelaunay );
+	Type                                                      type = ParallelDelaunay_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ParallelDelaunay_Delete;
+	Stg_Class_PrintFunction*                                _print = _ParallelDelaunay_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ParallelDelaunay_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ParallelDelaunay_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ParallelDelaunay_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ParallelDelaunay_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ParallelDelaunay_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ParallelDelaunay_Destroy;
+	Bool                                                  initFlag = True;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+	int                       idOffset = ZERO;
+
+	ParallelDelaunay *d = _ParallelDelaunay_New(  PARALLELDELAUNAY_PASSARGS  );
+	
+	return d;
+}
+
+#define MASTER_PROC 0
+
+	/** Initialise a ParallelDelaunay */
+void ParallelDelaunay_Init(
+	ParallelDelaunay*					self,
+	Name						name,
+	Dictionary*					dictionary,
+	CoordF						*sites,
+	int							numSites,
+	int							rank,
+	int							numProcs,
+	MPI_Comm					*comm,
+	DelaunayAttributes			*attr )
+{
+	self->type = ParallelDelaunay_Type;
+	self->_sizeOfSelf = sizeof( ParallelDelaunay );
+	self->_deleteSelf = False;
+	self->dictionary = dictionary;
+
+	self->_delete = _ParallelDelaunay_Delete;
+	self->_print = _ParallelDelaunay_Print;
+	self->_copy = _ParallelDelaunay_Copy;
+	self->_defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParallelDelaunay_DefaultNew;
+	self->_construct = _ParallelDelaunay_AssignFromXML;
+	self->_build = _ParallelDelaunay_Build;
+	self->_initialise = _ParallelDelaunay_Initialise;
+	self->_execute = _ParallelDelaunay_Execute;
+	self->_destroy = _ParallelDelaunay_Destroy;
+
+	self->attributes = Memory_Alloc_Unnamed( DelaunayAttributes );
+	memcpy( self->attributes, attr, sizeof( DelaunayAttributes ) );
+	self->attributes->BuildBoundingTriangle = 0;
+
+	_Stg_Class_Init( (Stg_Class*)self );
+	_Stg_Object_Init( (Stg_Object*)self, name, NON_GLOBAL );
+	_Stg_Component_Init( (Stg_Component*)self );
+	_ParallelDelaunay_Init( self, sites, 0, 0, rank, numProcs, comm, numSites, numSites, dictionary, True );
+}
+
+/** Creation implementation */
+ParallelDelaunay* _ParallelDelaunay_New(  PARALLELDELAUNAY_DEFARGS  )
+{
+	DelaunayAttributes* attr_shadowed = attr;
+	Bool initFlag_shadowed = initFlag;
+	ParallelDelaunay *self = NULL;
+	DelaunayAttributes *myAttr = NULL;
+	
+	myAttr = Memory_Alloc_Unnamed( DelaunayAttributes );
+	memcpy( myAttr, attr_shadowed, sizeof( DelaunayAttributes ) );
+	myAttr->BuildBoundingTriangle = 0;
+	
+	assert( _sizeOfSelf >= sizeof(ParallelDelaunay) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	idOffset = 0;
+	initFlag = True;
+	attr     = myAttr;
+
+	self = (ParallelDelaunay*)_Delaunay_New(  DELAUNAY_PASSARGS  );
+	
+	_ParallelDelaunay_Init( self, sites, 0, 0, rank, numProcs, comm, numSites, numSites, dictionary, initFlag_shadowed );
+
+	return self;
+}
+
+int ParallelDelaunayBtreeCompareFunction( void *a, void *b )
+{
+	Site *s1, *s2;
+
+	s1 = (Site*)a;
+	s2 = (Site*)b;
+
+	if( (*(s1->coord))[0] > (*(s2->coord))[0] ){
+		return 1;
+	}
+	else if( (*(s1->coord))[0] == (*(s2->coord))[0] ){
+		if( (*(s1->coord))[1] > (*(s2->coord))[1] ){
+			return 1;
+		}
+		else if( (*(s1->coord))[1] < (*(s2->coord))[1] ){
+			return -1;
+		}
+		else{
+			return 0;
+		}
+	}
+	else{
+		return -1;
+	}
+}
+
+#define epsilon 0.0001
+#define LOAD_TAG 1
+#define DATA_TAG 1<<1
+#define NEW_SITE_FACTOR 100
+void _ParallelDelaunay_Init( ParallelDelaunay* self, CoordF* points, int leftProc, int rightProc, int rank, int numProcs, MPI_Comm* comm, int numSites, int numInputSites, Dictionary* dictionary, Bool initFlag )
+{
+	assert( self );
+
+	self->points = points;
+	self->leftProc = leftProc;
+	self->rightProc = rightProc;
+	self->haloSites[0] = NULL;
+	self->haloSites[1] = NULL;
+	self->localTriangulation = NULL;
+	self->rank = rank;
+	self->numProcs = numProcs;
+	self->comm = comm;
+
+	self->dictionary = dictionary;
+	self->numSites = numSites;
+	self->numInputSites = numInputSites;
+	
+    if (initFlag) {
+	    self->numHaloSites[0] = 0;
+	    self->numHaloSites[1] = 0;
+	    self->sitePool = MemoryPool_New( Site, NEW_SITE_FACTOR, NEW_SITE_FACTOR );
+	    self->coordPool = MemoryPool_New( CoordF, NEW_SITE_FACTOR, NEW_SITE_FACTOR );
+    }
+}
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Virtual functions
+	*/
+
+/** Stg_Class_Delete() implementation */
+void _ParallelDelaunay_Delete( void* pd )
+{
+	ParallelDelaunay *self = (ParallelDelaunay*)pd;
+	
+	assert( self );
+
+	_Delaunay_Delete( self );
+}
+
+/** Stg_Class_Print() implementation */
+void _ParallelDelaunay_Print( void* pd, Stream* stream )
+{
+	ParallelDelaunay *self = ( ParallelDelaunay* )pd;
+	
+	assert( self );
+	assert( stream );
+
+	_Delaunay_Print( (Delaunay*)self, stream );
+	Journal_Printf( stream, "ParallelDelaunay (ptr): (%p)\n", self );
+}
+
+void *_ParallelDelaunay_Copy( const void* pd, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap )
+{
+	return NULL;
+}
+
+void _ParallelDelaunay_AssignFromXML( void* pd, Stg_ComponentFactory* cf, void* data )
+{
+	
+}
+
+void _ParallelDelaunay_Build( void* pd, void* data ) {
+	float _minX, _maxX;
+	float _minY, _maxY;
+	int numProcs, numSites, i, j, count;
+	float stride, start;
+	int *alloced = NULL;
+	int offset;
+	ParallelDelaunay *self = (ParallelDelaunay*)pd;
+
+	assert( self );
+	
+	numProcs = self->numProcs;
+	numSites = self->numSites;
+
+	if( numProcs == 1 ){
+		self->leftProc = numProcs;
+		self->rightProc = numProcs;
+	}
+	else{
+		if( self->rank == MASTER_PROC ){
+			self->leftProc = numProcs;
+			self->rightProc = self->rank + 1;
+		}
+		else if( self->rank == (numProcs-1) ){
+			self->leftProc = self->rank - 1;
+			self->rightProc = numProcs;
+		}
+		else{
+			self->leftProc = self->rank - 1;
+			self->rightProc = self->rank + 1;
+		}
+	}
+	
+	self->mapGlobalToLocal = Memory_Alloc_Array_Unnamed( int, numSites );
+	self->processorLoad = Memory_Alloc_Array_Unnamed( int, numProcs );
+	memset( self->processorLoad, 0, sizeof( int )*numProcs );
+
+	if( self->rank == MASTER_PROC ){
+		self->processor = Memory_Alloc_Array_Unnamed( int, numSites );
+
+		alloced = Memory_Alloc_Array_Unnamed( int, numSites );
+		memset( alloced, 0, sizeof( int )*numSites );
+	
+		self->initialOrder = Memory_Alloc_Array_Unnamed( int, numSites );
+		memset( self->initialOrder, 0, sizeof( int )*numSites );
+		
+		Delaunay_FindMinMax( self->sites, self->numSites, &_minX, &_minY, &_maxX, &_maxY );
+		Delaunay_SortSites( self->sites, self->numSites );
+
+		for( i=0; i<numSites; i++ ){
+			self->initialOrder[i] = self->sites[i].id;
+		}
+		
+		stride = (_maxX - _minX)/((float)numProcs);
+
+		start = _minX;
+		for( i=0; i<numProcs; i++ ){
+			for( j=0; j<numSites; j++ ){
+				if( ((*(self->sites[j].coord))[0] >= start-epsilon) &&
+						((*(self->sites[j].coord))[0] <= (start+stride+epsilon)) &&
+						(!alloced[j]) ){
+					
+					alloced[j] = 1;
+					self->processorLoad[i]++;
+					self->processor[j] = i;
+				}
+			}
+			start+=stride;
+		}
+		
+		/*for( i=0; i<numProcs; i++ ){
+			printf( "processorLoad[%d] = %d\n", i, self->processorLoad[i] );
+		}*/
+		
+		for( i=MASTER_PROC+1; i<numProcs; i++ ){
+			MPI_Send( &(self->processorLoad[i]), 1, MPI_INT, i, LOAD_TAG, *self->comm );
+		}
+
+		self->numLocalSites = self->processorLoad[MASTER_PROC];
+		self->localPoints = Memory_Alloc_Array_Unnamed( CoordF, self->numLocalSites );
+		
+		{
+			CoordF **procCoords = NULL;
+			int *procCoordCounter = NULL;
+
+			procCoordCounter = (int*)malloc( sizeof(int)*numProcs );
+			memset( procCoordCounter, 0, sizeof(int)*numProcs );
+
+			procCoords = (float (**)[3])malloc( sizeof( CoordF* ) * numProcs );
+			for( i=MASTER_PROC+1; i<numProcs; i++ ){
+                          procCoords[i] = (float (*)[3])malloc( sizeof(CoordF) * self->processorLoad[i] );
+				memset( procCoords[i], 0, sizeof( CoordF ) * self->processorLoad[i] );
+			}
+
+			count = 0;
+			for( i=0; i<numSites; i++ ){
+				if( self->processor[i] == MASTER_PROC ){
+					memcpy( &(self->localPoints[count++]), self->sites[i].coord, sizeof(CoordF) );
+				}
+				else{
+					memcpy( &(procCoords[self->processor[i]][procCoordCounter[self->processor[i]]++]), self->sites[i].coord,  sizeof(CoordF) );
+				}			
+			}
+			
+			for( i=MASTER_PROC+1; i<numProcs; i++ ){
+				MPI_Send( procCoords[i], sizeof( CoordF )*self->processorLoad[i], MPI_BYTE, i, DATA_TAG, *self->comm );
+			}
+
+			free( procCoordCounter );
+			for( i=MASTER_PROC+1; i<numProcs; i++ ){
+				free( procCoords[i] );
+			}
+			free( procCoords );
+		}
+
+		Memory_Free( alloced );
+	}
+	else{
+		MPI_Status status;
+		
+		MPI_Recv( &self->numLocalSites, 1, MPI_INT, MASTER_PROC, LOAD_TAG, *self->comm, &status );
+
+		self->localPoints = Memory_Alloc_Array_Unnamed( CoordF, self->numLocalSites );
+
+		MPI_Recv( self->localPoints, sizeof(CoordF)*self->numLocalSites, MPI_BYTE, MASTER_PROC, DATA_TAG, *self->comm, &status );
+	}
+
+	MPI_Bcast( self->processorLoad, numProcs, MPI_INT, MASTER_PROC, *self->comm );
+	self->numTotalLocalSites = self->numLocalSites;
+
+	offset = 0;
+	for( i=0; i<self->rank; i++ ){
+		offset += self->processorLoad[i];
+	}
+	
+	self->localTriangulation = Delaunay_New( "delaunay", self->dictionary, self->localPoints, self->numLocalSites, offset, self->attributes );
+	self->localTriangulation->qp = MemoryPool_New( QuadEdge, self->localTriangulation->numSites * (3 + MERGE_FACTOR), 10 );
+	Delaunay_SortSites(self->localTriangulation->sites, self->localTriangulation->numSites);
+    Delaunay_Recurse(self->localTriangulation, 0, self->localTriangulation->numSites,
+			&self->localTriangulation->leftMost, &self->localTriangulation->rightMost);
+
+	for( i=0; i<numSites; i++ ){
+		self->mapGlobalToLocal[i] = numSites;
+	}
+	
+	for( i=0; i<self->numLocalSites; i++ ){
+		self->mapGlobalToLocal[self->localTriangulation->sites[i].id] = self->localTriangulation->sites[i].id;
+	}
+	
+	if( self->leftProc != self->numProcs ){
+		ParallelDelaunayMerge( self, self->comm, self->leftProc );
+	}
+		
+	if( self->rightProc != self->numProcs ){
+		ParallelDelaunayMerge( self, self->comm, self->rightProc );
+	}
+}
+
+void _ParallelDelaunay_Initialise( void* pd, void* data )
+{
+	
+}
+
+void _ParallelDelaunay_Execute( void* pd, void* data )
+{
+	DelaunayAttributes attr;
+	ParallelDelaunay *self = (ParallelDelaunay*)pd;
+	int offset, i;
+	
+	offset = 0;
+	for( i=0; i<self->rank; i++ ){
+		offset += self->processorLoad[i];
+	}
+
+	if( self->leftProc != self->numProcs ){
+		ParallelDelaunay_RetriangulateAfterMerge( self, LEFT );
+	}
+
+	if( self->rightProc != self->numProcs ){
+		ParallelDelaunay_RetriangulateAfterMerge( self, RIGHT );
+	}
+
+	Stg_Class_Delete( self->localTriangulation );
+	
+	memcpy( &attr, self->attributes, sizeof( DelaunayAttributes ) );
+	attr.BuildTriangleIndices = 0;
+	self->localTriangulation = Delaunay_New( "delaunay", self->dictionary, self->localPoints, self->numTotalLocalSites, offset, &attr );
+	Stg_Component_Build( self->localTriangulation, NULL, True );
+	
+	if( self->attributes->BuildTriangleIndices ){
+		ParallelDelaunay_BuildTriangleIndices( self );
+	}	
+}
+
+void _ParallelDelaunay_Destroy( void* pd, void* data ) { 
+   ParallelDelaunay *self = (ParallelDelaunay*)pd;
+	
+	assert( self );
+   Memory_Free( self->localPoints );
+	if( self->mappingTable[0] ) Memory_Free( self->mappingTable[0] );
+	if( self->mappingTable[1] ) Memory_Free( self->mappingTable[1] );
+	Memory_Free( self->mapGlobalToLocal );
+	if( self->processor ) Memory_Free( self->processor );
+	if( self->initialOrder ) Memory_Free( self->initialOrder );
+	Memory_Free( self->processorLoad );
+	Memory_Free( self->attributes );
+
+	Stg_Class_Delete( self->localTriangulation );
+	Stg_Class_Delete( self->sitePool );
+	Stg_Class_Delete( self->coordPool );
+
+   _Delaunay_Destroy(pd, data);
+}
+
+#define onCurrentProc( pd, id ) ( id < (pd->processorLoad[pd->rank]+pd->localTriangulation->idOffset) )
+#define onLeftProc( pd, id ) ( ( pd->numHaloSites[0]>0 ) && ( id >= (pd->processorLoad[pd->rank]+pd->localTriangulation->idOffset) ) && \
+				( id < (pd->processorLoad[pd->rank]+pd->numHaloSites[0]+pd->localTriangulation->idOffset) ) )
+#define onRightProc( pd, id ) ( ( pd->numHaloSites[1]>0 ) && ( id >= (pd->processorLoad[pd->rank]+pd->localTriangulation->idOffset+pd->numHaloSites[0]) ) && \
+				( id < (pd->numTotalLocalSites+pd->localTriangulation->idOffset) ) )
+
+void ParallelDelaunay_RetriangulateAfterMerge( ParallelDelaunay *pd, Direction d )
+{
+		BTreeIterator *iter = NULL;
+		Site *result = NULL;
+		ParallelDelaunay *self = pd;
+		int i = 0;
+		int numProcs;
+		int numSites;
+		int count;
+		int offset;
+
+		numProcs = self->numProcs;
+		numSites = self->numSites;
+		offset = 0;
+		for( i=0; i<self->rank; i++ ){
+			offset += self->processorLoad[i];
+		}
+		
+		self->haloSites[d] = BTree_New( ParallelDelaunayBtreeCompareFunction, NULL, NULL, NULL, BTREE_NO_DUPLICATES );
+		
+		for( i=0; i<self->localTriangulation->qp->numElements; i++ ){
+			if( IS_FREE((QuadEdgeRef)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)])) ) continue;
+	
+			if( self->mapGlobalToLocal[((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[0])->id] == numSites )
+				BTree_InsertNode( self->haloSites[d], ((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[0]), sizeof( Site* ) );
+			
+			if( self->mapGlobalToLocal[((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[2])->id] == numSites )
+				BTree_InsertNode( self->haloSites[d], ((Site*)((QuadEdge*)&(self->localTriangulation->qp->chunks[0].memory[i*sizeof(QuadEdge)]))->data[2]), sizeof( Site* ) );
+		}
+
+		self->localPoints = Memory_Realloc_Array
+			( self->localPoints, CoordF, sizeof(CoordF) * (self->numTotalLocalSites + self->haloSites[d]->nodeCount) );
+		
+		self->mappingTable[d] = Memory_Alloc_Array_Unnamed( int, self->haloSites[d]->nodeCount );
+		memset( self->mappingTable[d], 0, sizeof( int ) * self->haloSites[d]->nodeCount );
+		
+		count=0;
+		i = self->numTotalLocalSites;
+		iter = BTreeIterator_New( self->haloSites[d] );
+		for( result=(Site*)BTreeIterator_First(iter);
+				result;
+				result=(Site*)BTreeIterator_Next(iter)){
+			
+			self->mappingTable[d][count++] = result->id;
+			memcpy( &(self->localPoints[i++]), result->coord, sizeof( CoordF ) );
+		}
+		Stg_Class_Delete( self->localTriangulation );
+
+		self->localTriangulation = Delaunay_New( "delaunay", self->dictionary, self->localPoints, self->numLocalSites, offset, self->attributes );
+		self->localTriangulation->qp = MemoryPool_New( QuadEdge, self->localTriangulation->numSites * 4, 10 );
+		Delaunay_SortSites(self->localTriangulation->sites, self->localTriangulation->numSites);
+    	Delaunay_Recurse(self->localTriangulation, 0, self->localTriangulation->numSites,
+				&self->localTriangulation->leftMost, &self->localTriangulation->rightMost);
+
+		self->numHaloSites[d] = self->haloSites[d]->nodeCount;
+		self->numTotalLocalSites += self->haloSites[d]->nodeCount;
+		
+		Stg_Class_Delete( self->haloSites[d] );
+		Stg_Class_Delete( iter );
+}
+
+void ParallelDelaunay_BuildTriangleIndices( ParallelDelaunay *pd )
+{
+	int i = 0, triCount;
+	QuadEdgeRef e = 0, eStart = 0, eOnext = 0, eLnext = 0;
+	QuadEdge *edges = NULL;
+	Site *sites = NULL;
+	int maxEdges = 0;
+	int rank = 0;
+	int pass = 0;
+	unsigned int **triIndices = NULL;
+	Delaunay *delaunay = NULL;
+
+	delaunay = pd->localTriangulation;
+
+	assert( delaunay );
+
+	delaunay->triangleIndices = Memory_Alloc_Array_Unnamed( unsigned int*, delaunay->numFaces );
+	delaunay->triangleIndices[0] = Memory_Alloc_Array_Unnamed( unsigned int, delaunay->numFaces * 3 );
+	memset( delaunay->triangleIndices[0] , 0, sizeof(unsigned int) * delaunay->numFaces * 3 );
+
+	for( i=0; i<delaunay->numFaces; i++ ){
+		delaunay->triangleIndices[i] = delaunay->triangleIndices[0]+i*3;
+	}
+	
+	triIndices = delaunay->triangleIndices;
+	
+	edges = (QuadEdge*)delaunay->qp->chunks[0].memory;
+	sites = delaunay->sites;
+	rank = pd->rank;
+	maxEdges = delaunay->qp->numElements;
+		
+	for (i = 0; i < maxEdges; i++) {
+		edges[i].count = 0;
+	}
+
+	triCount = 0;
+	for (i = 0; i < maxEdges; i++) {
+		
+		e = eStart = (QuadEdgeRef)((void*)&(edges[i]));
+		
+		if( IS_FREE(e) )continue;
+		
+		do{
+			eOnext = ONEXT(e);
+			eLnext = LNEXT(e);
+			
+			if( (COUNT(e)<2) && (COUNT(LNEXT(e))<2) && (COUNT(eOnext)<2) ){
+				if( ((((Site*)ORG(eLnext)) == ((Site*)DEST(e)))) &&
+				 ((((Site*)DEST(eLnext)) == ((Site*)DEST(eOnext)))) ){
+		
+					if( onCurrentProc( pd, ((Site*)ORG(e))->id ) ||
+						onCurrentProc( pd, ((Site*)DEST(e))->id ) ||
+						onCurrentProc( pd, ((Site*)DEST(eOnext))->id ) ){
+						
+						pass = 0;
+						if( !onCurrentProc( pd, ((Site*)ORG(e))->id ) ){
+							if( !onRightProc( pd, ((Site*)ORG(e))->id ) ) pass = 1;
+						}
+						
+						if( !onCurrentProc( pd, ((Site*)DEST(e))->id ) ){
+							if( !onRightProc( pd, ((Site*)DEST(e))->id ) ) pass = 1;
+						}
+						
+						if( !onCurrentProc( pd, ((Site*)DEST(eOnext))->id ) ){
+							if( !onRightProc( pd, ((Site*)DEST(eOnext))->id ) ) pass = 1;
+						}
+						
+						if( !pass ){
+							triIndices[triCount][0] = ParallelDelaunay_TranslateLocalToGlobal(pd, ((Site*)ORG(e))->id);
+							triIndices[triCount][1] = ParallelDelaunay_TranslateLocalToGlobal(pd, ((Site*)DEST(e))->id);
+							triIndices[triCount][2] = ParallelDelaunay_TranslateLocalToGlobal(pd, ((Site*)DEST(eOnext))->id);
+
+							triCount++;
+						}
+					}
+
+					COUNT(e)++;
+					COUNT(LNEXT(e))++;
+					COUNT(eOnext)++;
+				}
+			}
+			e = eOnext;
+		}while( e != eStart );
+	}
+	
+	delaunay->numTriangles = triCount;
+}
+
+#define NEIGHBOURS_TAG 1<<4
+#define VORONOI_SIDES_TAG 1<<5
+#define VORONOI_AREA_TAG 1<<6
+#define NUM_NEIGHBOUR_TAG 1<<7
+#define MAX_NEIGHBOURS 100
+
+void ParallelDelaunay_GatherTriangulation( ParallelDelaunay *pd )
+{
+	int i, j, k, l, count, count1;
+	MPI_Status st;
+	int numNeighboursSum = 0;
+	int stride = 0;
+	
+	assert( pd );
+
+	if( pd->rank == MASTER_PROC ){
+		
+		if( pd->attributes->CalculateVoronoiSurfaceArea ){
+			pd->voronoiArea = Memory_Alloc_Array_Unnamed( float, pd->numInputSites );
+		}
+
+		if( pd->attributes->FindNeighbours ){
+			pd->numNeighbours = Memory_Alloc_Array_Unnamed( unsigned int, pd->numInputSites );
+		}
+		
+		count = 0;
+		count1 = 0;
+		numNeighboursSum = 0;
+
+		{
+			float **procVoronoi = NULL;
+			int **procNumNeighbours = NULL;
+			int *procVoronoiCounter = NULL;
+			int *procNumNeighboursCounter = NULL;
+
+			procVoronoiCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
+			memset( procVoronoiCounter, 0, sizeof( int ) * pd->numProcs );
+			
+			procNumNeighboursCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
+			memset( procNumNeighboursCounter, 0, sizeof( int ) * pd->numProcs );
+
+			procVoronoi = (float**)malloc( sizeof( float* ) * pd->numProcs ); memset( procVoronoi, 0, sizeof(float*)*pd->numProcs );
+			procNumNeighbours = (int**)malloc( sizeof( int* ) * pd->numProcs ); memset( procNumNeighbours, 0, sizeof(int*)*pd->numProcs );
+
+			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
+
+				if( pd->attributes->CalculateVoronoiSurfaceArea ){
+                                  procVoronoi[i] = (float*)malloc( sizeof(float)*pd->processorLoad[i] );
+					memset( procVoronoi[i], 0, sizeof( float ) * pd->processorLoad[i] );
+					MPI_Recv( procVoronoi[i], pd->processorLoad[i], MPI_FLOAT, i, VORONOI_AREA_TAG, (*pd->comm), &st );
+				}
+
+				if( pd->attributes->FindNeighbours ){
+                                  procNumNeighbours[i] = (int*)malloc( sizeof(int)*pd->processorLoad[i] );
+					memset( procNumNeighbours[i], 0, sizeof(int) * pd->processorLoad[i] );
+					MPI_Recv( procNumNeighbours[i], pd->processorLoad[i], MPI_INT, i, NUM_NEIGHBOUR_TAG, (*pd->comm), &st );
+				}
+			}
+
+			for( i=0; i<pd->numInputSites; i++ ){
+				int proc, order;
+				proc = pd->processor[i];
+				order = pd->initialOrder[i];
+
+				if( pd->attributes->CalculateVoronoiSurfaceArea ){
+					if( pd->processor[i] == MASTER_PROC ){
+						memcpy( &(pd->voronoiArea[pd->initialOrder[i]]), &(pd->localTriangulation->voronoiArea[count++]), sizeof( float ) );
+					}
+					else{
+						memcpy( &(pd->voronoiArea[order]), &(procVoronoi[proc][procVoronoiCounter[proc]++]), sizeof(float) );
+					}
+				}
+			
+				if( pd->attributes->FindNeighbours ){
+					if( pd->processor[i] == MASTER_PROC ){
+						memcpy( &(pd->numNeighbours[pd->initialOrder[i]]), &(pd->localTriangulation->numNeighbours[count1++]), sizeof( int ) );
+					}
+					else{
+						memcpy( &(pd->numNeighbours[pd->initialOrder[i]]), &(procNumNeighbours[proc][procNumNeighboursCounter[proc]++]), sizeof( int ) );
+					}
+					numNeighboursSum += pd->numNeighbours[pd->initialOrder[i]];
+				}
+			}
+			
+			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
+				if( procVoronoi[i] ) free( procVoronoi[i] );
+				if( procNumNeighbours[i] ) free( procNumNeighbours[i] );
+			}
+			free( procVoronoi );
+			free( procNumNeighbours );
+			free( procVoronoiCounter );
+			free( procNumNeighboursCounter );
+		}
+
+		if( pd->attributes->FindNeighbours ){
+			pd->neighbours = Memory_Alloc_Array_Unnamed( unsigned int*, pd->numInputSites );
+			pd->neighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, numNeighboursSum );
+		}
+	
+		if( pd->attributes->CalculateVoronoiSides ){
+			pd->voronoiSides = Memory_Alloc_Array_Unnamed( float*, pd->numInputSites );
+			pd->voronoiSides[0] = Memory_Alloc_Array_Unnamed( float, numNeighboursSum );
+		}
+		
+		stride = 0;
+		for( j=0; j<pd->numInputSites; j++ ){
+			if( pd->attributes->FindNeighbours ){
+				pd->neighbours[j] = pd->neighbours[0]+stride;
+			}
+			
+			if( pd->attributes->CalculateVoronoiSides ){
+				pd->voronoiSides[j] = pd->voronoiSides[0]+stride;
+			}
+
+			if( pd->attributes->FindNeighbours ){
+				stride += pd->numNeighbours[j];
+			}
+		}
+		
+		{
+			float **procVoronoiSides = NULL;
+			float **procNeighbours = NULL;
+			int *procVoronoiSidesCounter = NULL;
+			int *procNeighboursCounter = NULL;
+			int *procNumNeighboursCount = NULL;
+
+			procVoronoiSidesCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
+			memset( procVoronoiSidesCounter, 0, sizeof( int ) * pd->numProcs );
+			
+			procNeighboursCounter = (int*)malloc( sizeof( int ) * pd->numProcs );
+			memset( procNeighboursCounter, 0, sizeof( int ) * pd->numProcs );
+			
+			procNumNeighboursCount = (int*)malloc( sizeof( int ) * pd->numProcs );
+			memset( procNumNeighboursCount, 0, sizeof( int ) * pd->numProcs );
+
+			procVoronoiSides = (float**)malloc( sizeof( float* ) * pd->numProcs ); memset( procVoronoiSides, 0, sizeof(float*)*pd->numProcs );
+			procNeighbours = (float**)malloc( sizeof( unsigned int* ) * pd->numProcs ); memset( procNeighbours, 0, sizeof(unsigned int*)*pd->numProcs );
+
+			for( i=0; i<pd->numInputSites; i++ ){
+				procNumNeighboursCount[pd->processor[i]]+=pd->numNeighbours[pd->initialOrder[i]];
+			}
+
+			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
+				if( pd->attributes->CalculateVoronoiSides ){
+                                  procVoronoiSides[i] = (float*)malloc( sizeof(float)*procNumNeighboursCount[i] );
+					memset( procVoronoiSides[i], 0, sizeof( float ) * procNumNeighboursCount[i] );
+					MPI_Recv( procVoronoiSides[i], procNumNeighboursCount[i], MPI_FLOAT, i, VORONOI_SIDES_TAG, (*pd->comm), &st );
+				}
+
+				if( pd->attributes->FindNeighbours ){
+                                  procNeighbours[i] = (float*)malloc( sizeof(unsigned int)*procNumNeighboursCount[i] );
+					memset( procNeighbours[i], 0, sizeof(unsigned int) * procNumNeighboursCount[i] );
+					MPI_Recv( procNeighbours[i], procNumNeighboursCount[i], MPI_INT, i, NEIGHBOURS_TAG, (*pd->comm), &st );
+				}
+			}
+
+			count = 0;
+			for(j=0; j<pd->numInputSites; j++){
+				int proc, order;
+				proc = pd->processor[j];
+				order = pd->initialOrder[j];
+				
+				if( pd->processor[j] == MASTER_PROC ){
+					if( pd->attributes->CalculateVoronoiSides ){
+						memcpy( (pd->voronoiSides[pd->initialOrder[j]]), (pd->localTriangulation->voronoiSides[count]),
+								sizeof(float)*pd->localTriangulation->numNeighbours[count] );
+					}
+					if( pd->attributes->FindNeighbours ){
+						memcpy( (pd->neighbours[pd->initialOrder[j]]), (pd->localTriangulation->neighbours[count]),
+								sizeof(int)*pd->localTriangulation->numNeighbours[count] );
+						for( i=0; i<(int)(pd->numNeighbours[pd->initialOrder[j]]); i++ ){
+							pd->neighbours[pd->initialOrder[j]][i] = 
+								pd->initialOrder[ParallelDelaunay_TranslateLocalToGlobal(pd, pd->neighbours[pd->initialOrder[j]][i])];
+						}
+					}
+					count++;
+				}
+				else{
+					if( pd->attributes->CalculateVoronoiSides ){
+						memcpy( (pd->voronoiSides[pd->initialOrder[j]]),
+								&(procVoronoiSides[proc][procVoronoiSidesCounter[proc]]),
+								sizeof(float)*pd->numNeighbours[order] );
+						procVoronoiSidesCounter[proc]+=pd->numNeighbours[order];
+					}
+					if( pd->attributes->FindNeighbours ){
+						memcpy( (pd->neighbours[pd->initialOrder[j]]),
+								&(procNeighbours[proc][procNeighboursCounter[proc]]),
+								sizeof(int)*pd->numNeighbours[order] );
+						procNeighboursCounter[proc]+=pd->numNeighbours[order];
+
+						for( i=0; i<(int)(pd->numNeighbours[pd->initialOrder[j]]); i++ ){
+							pd->neighbours[pd->initialOrder[j]][i] = pd->initialOrder[pd->neighbours[pd->initialOrder[j]][i]];
+						}
+					}
+				}
+			}
+
+			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
+				if( procVoronoiSides[i] ) free( procVoronoiSides[i] );
+				if( procNeighbours[i] ) free( procNeighbours[i] );
+			}
+			free( procVoronoiSides );
+			free( procNeighbours );
+			free( procVoronoiSidesCounter );
+			free( procNeighboursCounter );			
+			free( procNumNeighboursCount );			
+		}
+	}
+	else{
+		if( pd->attributes->CalculateVoronoiSurfaceArea ){
+			MPI_Send( (pd->localTriangulation->voronoiArea), pd->numLocalSites, MPI_FLOAT, MASTER_PROC, VORONOI_AREA_TAG, (*pd->comm) );
+		}
+			
+		if( pd->attributes->FindNeighbours ){
+			MPI_Send( (pd->localTriangulation->numNeighbours), pd->numLocalSites, MPI_INT, MASTER_PROC, NUM_NEIGHBOUR_TAG, (*pd->comm) );
+		}
+		
+		if( pd->attributes->CalculateVoronoiSides ){
+			int sum = 0;
+			for( i=0; i<pd->numLocalSites; i++ ){
+				sum+=pd->localTriangulation->numNeighbours[i];
+			}
+			MPI_Send( pd->localTriangulation->voronoiSides[0], sum, 
+					MPI_FLOAT, MASTER_PROC, VORONOI_SIDES_TAG, *(pd->comm));
+		}
+
+		if( pd->attributes->FindNeighbours ){
+			int sum = 0;
+			for( i=0; i<pd->numLocalSites; i++ ){
+				sum+=pd->localTriangulation->numNeighbours[i];
+				
+				for( j=0; j<(int)(pd->localTriangulation->numNeighbours[i]); j++ ){
+					pd->localTriangulation->neighbours[i][j] = ParallelDelaunay_TranslateLocalToGlobal( pd, pd->localTriangulation->neighbours[i][j] );
+				}
+			}
+			MPI_Send( pd->localTriangulation->neighbours[0], sum, MPI_INT, MASTER_PROC, NEIGHBOURS_TAG, *(pd->comm) );
+		}
+	}
+	
+	if( pd->attributes->BuildTriangleIndices ){
+		unsigned int **triIndices = NULL;
+		int globalNumTriangles = 0;
+		Delaunay *delaunay = NULL;
+		int *triCountArray = NULL;
+		int triCount = 0;
+		int rank = 0;
+
+		delaunay = pd->localTriangulation;
+
+		assert( delaunay );
+	
+		triIndices = delaunay->triangleIndices;
+		triCount = delaunay->numTriangles;
+
+		MPI_Allreduce( &triCount, &globalNumTriangles, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
+	
+		pd->numTriangles = globalNumTriangles;
+		
+		triCountArray = Memory_Alloc_Array_Unnamed( int, pd->numProcs );
+		rank = pd->rank;
+	
+		if( rank == MASTER_PROC ){
+
+			pd->triangleIndices = Memory_Alloc_Array_Unnamed( unsigned int*,  globalNumTriangles );
+			pd->triangleIndices[0] = Memory_Alloc_Array_Unnamed( unsigned int, globalNumTriangles*3 );
+
+			if ( pd->attributes->BuildTriangleNeighbours ){
+				pd->triangleNeighbours = Memory_Alloc_Array_Unnamed( unsigned int*,  globalNumTriangles );
+				pd->triangleNeighbours[0] = Memory_Alloc_Array_Unnamed( unsigned int, globalNumTriangles*3 );
+			}
+
+			triCountArray[0] = triCount;
+			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
+				MPI_Recv( &(triCountArray[i]), 1, MPI_INT, i, DATA_TAG, MPI_COMM_WORLD, &st );					
+			}
+
+			for( i=0; i<globalNumTriangles; i++ ){
+				pd->triangleIndices[i] = pd->triangleIndices[0] + i*3;
+	
+				if ( pd->attributes->BuildTriangleNeighbours ){
+					pd->triangleNeighbours[i] = pd->triangleNeighbours[0] + i*3;
+
+					pd->triangleNeighbours[i][0] = pd->numTriangles;
+					pd->triangleNeighbours[i][1] = pd->numTriangles;
+					pd->triangleNeighbours[i][2] = pd->numTriangles;
+				}
+			}
+
+			for(j=0; j<triCountArray[0]; j++){
+				memcpy( pd->triangleIndices[j], triIndices[j], sizeof(int)*3 );
+			}
+		
+			stride = j;
+			for( i=MASTER_PROC+1; i<pd->numProcs; i++ ){
+                          unsigned int *temp = (unsigned*)malloc( sizeof(unsigned int)*triCountArray[i]*3 );
+					MPI_Recv( temp, triCountArray[i]*3, MPI_INT, i, DATA_TAG, MPI_COMM_WORLD, &st );					
+				for(j=0; j<triCountArray[i]*3; j+=3){
+					memcpy( pd->triangleIndices[stride++], &(temp[j]), sizeof(int)*3 );
+				}
+				free( temp );
+			}
+
+			for( i=0; i<pd->numTriangles; i++ ){
+				pd->triangleIndices[i][0] = pd->initialOrder[pd->triangleIndices[i][0]];
+				pd->triangleIndices[i][1] = pd->initialOrder[pd->triangleIndices[i][1]];
+				pd->triangleIndices[i][2] = pd->initialOrder[pd->triangleIndices[i][2]];
+			}
+
+			/*for( j=0; j<globalNumTriangles; j++ ){
+				printf( "indices[%d] = [%d, %d, %d]\n", j, pd->triangleIndices[j][0], pd->triangleIndices[j][1], pd->triangleIndices[j][2] );
+			}*/
+			
+			stride = 0;
+			if ( pd->attributes->BuildTriangleNeighbours ){
+				int **nodeToTriangle = NULL;
+				int *nodeToTriangleCount = NULL;
+				int *triangleNeighboursCount = NULL;
+				int triangles[2];
+				int counter = 0;
+				int found = 0;
+				int m = 0;
+
+				nodeToTriangle = Memory_Alloc_Array_Unnamed( int*, pd->numInputSites );
+				nodeToTriangle[0] = Memory_Alloc_Array_Unnamed( int, numNeighboursSum );
+
+				nodeToTriangleCount = Memory_Alloc_Array_Unnamed( int, pd->numInputSites );
+				memset( nodeToTriangleCount, 0, sizeof( int ) * pd->numInputSites );
+				
+				triangleNeighboursCount = Memory_Alloc_Array_Unnamed( int, pd->numTriangles );
+				memset( triangleNeighboursCount, 0, sizeof( int ) * pd->numTriangles );
+
+				for( i=0; i<pd->numSites; i++ ){
+					nodeToTriangle[i] = nodeToTriangle[0] + stride;
+
+					stride += pd->numNeighbours[i];
+				}
+
+				for( i=0; i<pd->numTriangles; i++ ){
+					nodeToTriangle[pd->triangleIndices[i][0]][nodeToTriangleCount[pd->triangleIndices[i][0]]++] = i;
+					nodeToTriangle[pd->triangleIndices[i][1]][nodeToTriangleCount[pd->triangleIndices[i][1]]++] = i;
+					nodeToTriangle[pd->triangleIndices[i][2]][nodeToTriangleCount[pd->triangleIndices[i][2]]++] = i;
+				}
+				
+				for( i=0; i<pd->numInputSites; i++ ){
+                                  for( j=0; j<(int)(pd->numNeighbours[i]); j++ ){
+						triangles[0] = -1;
+						triangles[1] = -1;
+						counter = 0;
+						for( k=0; k<nodeToTriangleCount[i]; k++ ){
+							for( l=0; l<3; l++ ){
+								if( pd->neighbours[i][j] == pd->triangleIndices[nodeToTriangle[i][k]][l] ){
+									triangles[counter++] = nodeToTriangle[i][k];
+								}
+							}
+						}
+						
+						if( (triangles[0] > -1) ){
+							
+							found = 0;
+							for( m=0; m<3; m++ ){
+                                                          if( pd->triangleNeighbours[triangles[0]][m] == (unsigned)(triangles[1]) ) found = 1;
+							}
+							if( !found ){
+								pd->triangleNeighbours[triangles[0]][triangleNeighboursCount[triangles[0]]++] = triangles[1];
+							}
+						}
+						if( (triangles[1] > -1) ){
+						
+							found = 0;
+							for( m=0; m<3; m++ ){
+                                                          if( pd->triangleNeighbours[triangles[1]][m] == (unsigned)(triangles[0]) ) found = 1;
+							}
+							if( !found ){
+								pd->triangleNeighbours[triangles[1]][triangleNeighboursCount[triangles[1]]++] = triangles[0];
+							}
+						}
+					}
+				}
+				
+				Memory_Free( nodeToTriangle[0] );
+				Memory_Free( nodeToTriangle );
+				Memory_Free( nodeToTriangleCount );
+				Memory_Free( triangleNeighboursCount );
+			}
+		}
+		else{
+			MPI_Send( &triCount, 1, MPI_INT, MASTER_PROC, DATA_TAG, MPI_COMM_WORLD );
+			MPI_Send( triIndices[0], 3*triCount, MPI_INT, MASTER_PROC, DATA_TAG, MPI_COMM_WORLD );
+		}
+
+		Memory_Free( triCountArray );
+	}	
+}
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Private Member functions
+	*/
+
+int ParallelDelaunay_TranslateLocalToGlobal( ParallelDelaunay *self, int id )
+{
+	if( id >= (self->localTriangulation->idOffset+self->numLocalSites) ){
+	
+		if( (self->leftProc != self->numProcs) && (id < (self->localTriangulation->idOffset+self->numLocalSites + self->numHaloSites[0])) ){
+			
+			id = self->mappingTable[0][(id -
+						(self->localTriangulation->idOffset+
+						 self->numLocalSites))];
+		}
+		else{
+
+			id = self->mappingTable[1][(id -
+						(self->localTriangulation->idOffset+
+						 self->numLocalSites+
+						 self->numHaloSites[0]))];
+		}
+		return id;
+	}
+	else{
+		return id;
+	}
+}
+
+#define EDGE_TAG 102
+#define BREAK_TAG 103
+typedef struct SitePacket_t{
+	int id;
+	float xyz[3];
+}SitePacket;
+void ParallelDelaunaySendEdge( QuadEdgeRef edge, int rank, MPI_Comm *comm, MPI_Request *req )
+{
+	SitePacket sp[2];
+	assert(edge);
+
+	memcpy( sp[0].xyz, ((Site*)ORG(edge))->coord, sizeof( CoordF ) );
+	sp[0].id = ((Site*)ORG(edge))->id;
+	
+	memcpy( sp[1].xyz, ((Site*)DEST(edge))->coord, sizeof( CoordF ) );
+	sp[1].id = ((Site*)DEST(edge))->id;
+	MPI_Isend( sp, sizeof(SitePacket)*2, MPI_BYTE, rank, EDGE_TAG, *comm, req );
+}
+
+QuadEdgeRef ParallelDelaunayRecvEdge( ParallelDelaunay *pd, int rank, MPI_Comm *comm )
+{
+	QuadEdgeRef edge = 0;
+	CoordF *c[2];
+	Site *s[2];
+	MPI_Status st;
+	SitePacket sp[2];
+	Delaunay *d = NULL;
+	
+	assert( pd );
+	d = pd->localTriangulation;
+	
+	edge = MakeQuadEdge( d->qp );
+	
+	assert(edge);
+
+	s[0] = MemoryPool_NewObject( Site, pd->sitePool );
+	s[1] = MemoryPool_NewObject( Site, pd->sitePool );
+	
+	c[0] = MemoryPool_NewObject( CoordF, pd->coordPool );
+	c[1] = MemoryPool_NewObject( CoordF, pd->coordPool );
+	
+	MPI_Recv( sp, sizeof(SitePacket)*2, MPI_BYTE, rank, EDGE_TAG, *comm, &st );
+
+	memcpy( (c[0]), sp[0].xyz, sizeof( CoordF ) );
+	memcpy( (c[1]), sp[1].xyz, sizeof( CoordF ) );
+
+	s[0]->id = sp[0].id;
+	s[0]->coord = (c[0]);
+	s[1]->id = sp[1].id;
+	s[1]->coord = (c[1]);
+	
+	ORG(edge)=(s[0]);
+	DEST(edge)=(s[1]);
+
+	return edge;
+}
+
+int ParallelDelaunayListCompareFunction( void *a, void *b )
+{
+	QuadEdgeRef e1, e2;
+
+	e1 = (QuadEdgeRef)a;
+	e2 = (QuadEdgeRef)b;
+
+	if( e1 > e2 ){
+		return 1;
+	}
+	else if( e1 < e2 ){
+		return -1;
+	}
+	else{
+		return 0;
+	}
+}
+
+void ParallelDelaunayListDeleteFunction( void *a )
+{
+
+}
+
+QuadEdgeRef ParallelDelaunayFindLowestQuadEdge( ParallelDelaunay *pd, MPI_Comm *comm, int rank )
+{
+	QuadEdgeRef ldi=0, rdi=0;
+	MPI_Request r;
+	MPI_Status s;
+	int globalBreak, localBreak;
+	LinkedList *list = NULL;
+	LinkedListIterator *iter;
+	QuadEdgeRef result = 0;
+	Delaunay *d = NULL;
+
+	assert( pd );
+	d = pd->localTriangulation;
+	
+	list = LinkedList_New( ParallelDelaunayListCompareFunction, NULL, NULL, ParallelDelaunayListDeleteFunction, LINKEDLIST_UNSORTED );
+	iter = LinkedListIterator_New( list );
+	
+	if( rank == pd->leftProc ){
+		rdi = d->leftMost;
+	}
+	else if( rank == pd->rightProc ){
+		ldi = d->rightMost;
+	}
+	else{
+		fprintf( stderr, "Failed to find lowest edge on rank %d..!\n Aborting..!\n", rank );
+	}
+
+	if( rank == pd->numProcs ) return 0;
+	
+	localBreak = 0;
+	globalBreak = 0;
+
+	while (1) 
+	{
+		localBreak = 0;
+		globalBreak = 0;
+
+		if( rank == pd->leftProc ){
+			ParallelDelaunaySendEdge( rdi, rank, comm, &r );
+			ldi = ParallelDelaunayRecvEdge( pd, rank, comm );
+			MPI_Wait( &r, &s );
+			LinkedList_InsertNode( list, (void*)ldi, sizeof( QuadEdgeRef* ) );
+			
+			if (RightOf((Site*)ORG(ldi), rdi)){
+				rdi = ONEXT(SYM(rdi));
+				localBreak = 1;
+			}
+			else{
+			}
+		}
+		
+		if( rank == pd->rightProc ){
+			ParallelDelaunaySendEdge( ldi, rank, comm, &r );
+			rdi = ParallelDelaunayRecvEdge( pd, rank, comm );
+			MPI_Wait( &r, &s );
+			LinkedList_InsertNode( list, (void*)rdi, sizeof( QuadEdgeRef* ) );
+			
+			if (LeftOf((Site*)ORG(rdi), ldi)){
+				ldi = LNEXT(ldi);
+				localBreak = 1;
+			}
+			else{
+			}
+		}
+
+		MPI_Isend( &localBreak, 1, MPI_INT, rank, BREAK_TAG, *comm, &r );
+		MPI_Recv( &(globalBreak), 1, MPI_INT, rank, BREAK_TAG, *comm, &s );
+		MPI_Wait( &r, &s );
+		globalBreak |= localBreak;
+		
+		if( globalBreak == 0 ){
+			break;
+		}
+	}
+
+	for( result=(QuadEdgeRef)((void*)LinkedListIterator_First(iter));
+			result != 0;
+			result=(QuadEdgeRef)((void*)LinkedListIterator_Next(iter)) ){
+
+		DeleteQuadEdge( d->qp, result );
+	}
+
+	Stg_Class_Delete( list );
+	Stg_Class_Delete( iter );
+	
+	if( rank == pd->leftProc ){
+		return rdi;
+	}
+	else if( rank == pd->rightProc ){
+		return ldi;
+	}
+	
+	return 0;
+}
+
+void ParallelDelaunayMerge( ParallelDelaunay *pd, MPI_Comm *comm, int rank )
+{
+	QuadEdgeRef lowest = 0, lcand = 0, rcand = 0, basel = 0, baselPrev;
+	MPI_Request r;
+	MPI_Status s;
+	int localBreak=0, globalBreak=0;
+	double result = 0.0f;
+	Delaunay *d = NULL;
+	
+	assert( pd );
+
+	d = pd->localTriangulation;
+
+	lowest = ParallelDelaunayFindLowestQuadEdge( pd, comm, rank );
+	
+	localBreak = 0;
+	globalBreak = 0;
+
+	if( rank == pd->numProcs ){
+		fprintf( stderr, "Failed to merge rank %d with rank %d..!\nAborting..!\n", pd->rank, rank );
+		assert( 0 );
+	}
+	
+	if( rank == pd->leftProc ){
+		rcand = lowest;
+		
+		ParallelDelaunaySendEdge( lowest, rank, comm, &r );
+		lcand = ParallelDelaunayRecvEdge( pd, rank, comm );
+		MPI_Wait( &r, &s );
+		
+		basel = MakeQuadEdge( d->qp );
+		ORG(basel) = DEST(SYM(rcand));
+		DEST(basel) = ORG(lcand);
+
+		DeleteQuadEdge( d->qp, lcand );
+		
+		CCW( ((Site*)DEST(rcand))->coord, ((Site*)DEST(basel))->coord, ((Site*)ORG(basel))->coord, &result);
+		if( result == 0.0f ){
+			rcand = OPREV(rcand);
+		}
+		
+		while(1){
+			localBreak = 0;
+			if (RightOf((Site*)DEST(rcand), basel)){
+				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(rcand), (Site*)DEST(OPREV(rcand)))){
+					QuadEdgeRef t = OPREV(rcand);
+
+					DeleteQuadEdge(d->qp, rcand);
+					rcand = t;
+				}
+			}
+			
+			if (!RightOf((Site*)DEST(rcand), basel)) localBreak = 1;
+
+			MPI_Isend( &localBreak, 1, MPI_INT, rank, BREAK_TAG, *comm, &r );
+			MPI_Recv( &(globalBreak), 1, MPI_INT, rank, BREAK_TAG, *comm, &s );
+			MPI_Wait( &r, &s );
+			globalBreak &= localBreak;
+
+			if( globalBreak ){
+				break;
+			}
+
+			ParallelDelaunaySendEdge( rcand, rank, comm, &r );
+			lcand = ParallelDelaunayRecvEdge( pd, rank, comm );
+			MPI_Wait( &r, &s );
+
+			if ( !RightOf((Site*)DEST(lcand), basel) ||
+				( RightOf((Site*)DEST(rcand), basel) && 
+				InCircle((Site*)DEST(lcand), (Site*)ORG(lcand), (Site*)ORG(rcand), (Site*)DEST(rcand)))){
+			
+				baselPrev = basel;
+				basel = MakeQuadEdge(d->qp);
+				ORG(basel) = DEST(rcand);
+				DEST(basel) = ORG(SYM(baselPrev));
+				
+				rcand=LNEXT(rcand);
+				DeleteQuadEdge( d->qp, lcand );
+			}
+			else{
+				baselPrev = basel;
+				basel = MakeQuadEdge(d->qp);
+				ORG(basel) = DEST(SYM(baselPrev));
+				DEST(basel) = ORG(SYM(lcand));
+			}
+		}
+	}
+	else if( rank == pd->rightProc ){
+		lcand = lowest;
+		
+		ParallelDelaunaySendEdge( lowest, rank, comm, &r );
+		rcand = ParallelDelaunayRecvEdge( pd, rank, comm );
+		MPI_Wait( &r, &s );
+		
+		basel = MakeQuadEdge(d->qp);
+		ORG(basel) = DEST(SYM(rcand));
+		DEST(basel) = ORG(lcand);
+		
+		DeleteQuadEdge( d->qp, rcand );
+		
+		CCW( ((Site*)DEST(lcand))->coord, ((Site*)DEST(basel))->coord, ((Site*)ORG(basel))->coord, &result);
+		if( result == 0.0f ){
+			lcand = ONEXT(lcand);
+		}
+		
+		while(1){
+			localBreak = 0;
+			if (RightOf((Site*)DEST(lcand), basel)){
+				while (InCircle((Site*)DEST(basel), (Site*)ORG(basel), (Site*)DEST(lcand), (Site*)DEST(ONEXT(lcand)))){
+					QuadEdgeRef t = ONEXT(lcand);
+					
+					DeleteQuadEdge(d->qp, lcand);
+					lcand = t;
+				}
+			}
+			
+			if (!RightOf((Site*)DEST(lcand), basel)) localBreak = 1;
+
+			MPI_Isend( &localBreak, 1, MPI_INT, rank, BREAK_TAG, *comm, &r );
+			MPI_Recv( &(globalBreak), 1, MPI_INT, rank, BREAK_TAG, *comm, &s );
+			MPI_Wait( &r, &s );
+			globalBreak &= localBreak;
+
+			if( globalBreak ){
+				break;
+			}
+			
+			ParallelDelaunaySendEdge( lcand, rank, comm, &r );
+			rcand = ParallelDelaunayRecvEdge( pd, rank, comm );
+			MPI_Wait( &r, &s );
+
+			if ( !RightOf((Site*)DEST(lcand), basel) ||
+				( RightOf((Site*)DEST(rcand), basel) && 
+				InCircle((Site*)DEST(lcand), (Site*)ORG(lcand), (Site*)ORG(rcand), (Site*)DEST(rcand)))){
+				
+				baselPrev = basel;
+				basel = MakeQuadEdge(d->qp);
+				ORG(basel) = DEST(rcand);
+				DEST(basel) = ORG(SYM(baselPrev));
+			}
+			else{
+				baselPrev = basel;
+				basel = MakeQuadEdge(d->qp);
+				ORG(basel) = DEST(SYM(baselPrev));
+				DEST(basel) = ORG(SYM(lcand));
+				
+				lcand = RPREV(lcand);
+				DeleteQuadEdge( d->qp, rcand );
+			}
+		}
+	}
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Plane.c
--- a/Geometry/src/Plane.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Plane.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "VectorMath.h"
-#include "Plane.h"
-
-#include <stdio.h>
-#include <assert.h>
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-void Plane_LineIntersect( Plane plane, Line3 line, Coord point ) {
-	double		t = plane[3] - plane[0] * line[0][0] - plane[1] * line[0][1] - plane[2] * line[0][2];
-	
-	t /= plane[0] * line[1][0] + plane[1] * line[1][1] + plane[2] * line[1][2];
-	
-	point[0] = line[0][0] + line[1][0] * t;
-	point[1] = line[0][1] + line[1][1] * t;
-	point[2] = line[0][2] + line[1][2] * t;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Plane.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Plane.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,63 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Plane.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "VectorMath.h"
+#include "Plane.h"
+
+#include <stdio.h>
+#include <assert.h>
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+void Plane_LineIntersect( Plane plane, Line3 line, Coord point ) {
+	double		t = plane[3] - plane[0] * line[0][0] - plane[1] * line[0][1] - plane[2] * line[0][2];
+	
+	t /= plane[0] * line[1][0] + plane[1] * line[1][1] + plane[2] * line[1][2];
+	
+	point[0] = line[0][0] + line[1][0] * t;
+	point[1] = line[0][1] + line[1][1] * t;
+	point[2] = line[0][2] + line[1][2] * t;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/QuadEdge.c
--- a/Geometry/src/QuadEdge.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-*/
-/** \file
-**  Role:
-**
-** Assumptions:
-**
-** Comments:
-**
-** $Id: QuadEdge.c 3462 2006-02-19 06:53:24Z Raquibul Hassan$
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "QuadEdge.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Constructors
-	*/
-	
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Virtual functions
-	*/
-	
-	
-	/*--------------------------------------------------------------------------------------------------------------------------
-	** Private Member functions
-	*/
-
-QuadEdgeRef MakeQuadEdge( MemoryPool *qp )
-{
-	QuadEdge *qe = (QuadEdge*)NULL;
-	QuadEdgeRef e = 0;
-
-	qe = MemoryPool_NewObject( QuadEdge, qp );
-	memset( qe, 0, sizeof( QuadEdge ) );
-	e = (QuadEdgeRef) qe;
-	SET_IN_USE( (QuadEdgeRef)e );
-	
-	if( e == 0 ){
-		fprintf( stderr, "Out of memory..!\n Aborting..!\n" );
-		assert( 0 );
-	}
-	
-	ONEXT(e) = e;
-	SYMDNEXT(e) = SYM(e);
-	ROTRNEXT(e) = TOR(e);
-	TORLNEXT(e) = ROT(e);
-	COUNT(e) = 0;
-	
-	return e;
-}
-
-void DeleteQuadEdge( MemoryPool *qp, QuadEdgeRef e)
-{
-	QuadEdgeRef f = SYM(e);
-	
-	if (ONEXT(e) != e) SpliceQuadEdges(e, OPREV(e));
-	if (ONEXT(f) != f) SpliceQuadEdges(f, OPREV(f));  
-    
-	MemoryPool_DeleteObject( qp, (QuadEdge*) ((e) & WORD) );
-}
-
-void SpliceQuadEdges(QuadEdgeRef a, QuadEdgeRef b)
-{
-	QuadEdgeRef ta, tb;
-	QuadEdgeRef alpha = ROT(ONEXT(a));
-	QuadEdgeRef beta = ROT(ONEXT(b));
-
-	ta = ONEXT(a);
-	tb = ONEXT(b);
-	ONEXT(a) = tb;
-	ONEXT(b) = ta;
-	ta = ONEXT(alpha);
-	tb = ONEXT(beta);
-	ONEXT(alpha) = tb;
-	ONEXT(beta) = ta;    
-}
-
-QuadEdgeRef ConnectQuadEdges(MemoryPool *qp, QuadEdgeRef a, QuadEdgeRef b)
-{
-	QuadEdgeRef e;
-
-	e = MakeQuadEdge( qp );
-	ORG(e) = DEST(a);
-	DEST(e) = ORG(b);
-	
-	SpliceQuadEdges(e, LNEXT(a));
-	SpliceQuadEdges(SYM(e), b);
-	
-	return e;
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/QuadEdge.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/QuadEdge.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,131 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+*/
+/** \file
+**  Role:
+**
+** Assumptions:
+**
+** Comments:
+**
+** $Id: QuadEdge.c 3462 2006-02-19 06:53:24Z Raquibul Hassan$
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "QuadEdge.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Constructors
+	*/
+	
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Virtual functions
+	*/
+	
+	
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Private Member functions
+	*/
+
+QuadEdgeRef MakeQuadEdge( MemoryPool *qp )
+{
+	QuadEdge *qe = (QuadEdge*)NULL;
+	QuadEdgeRef e = 0;
+
+	qe = MemoryPool_NewObject( QuadEdge, qp );
+	memset( qe, 0, sizeof( QuadEdge ) );
+	e = (QuadEdgeRef) qe;
+	SET_IN_USE( (QuadEdgeRef)e );
+	
+	if( e == 0 ){
+		fprintf( stderr, "Out of memory..!\n Aborting..!\n" );
+		assert( 0 );
+	}
+	
+	ONEXT(e) = e;
+	SYMDNEXT(e) = SYM(e);
+	ROTRNEXT(e) = TOR(e);
+	TORLNEXT(e) = ROT(e);
+	COUNT(e) = 0;
+	
+	return e;
+}
+
+void DeleteQuadEdge( MemoryPool *qp, QuadEdgeRef e)
+{
+	QuadEdgeRef f = SYM(e);
+	
+	if (ONEXT(e) != e) SpliceQuadEdges(e, OPREV(e));
+	if (ONEXT(f) != f) SpliceQuadEdges(f, OPREV(f));  
+    
+	MemoryPool_DeleteObject( qp, (QuadEdge*) ((e) & WORD) );
+}
+
+void SpliceQuadEdges(QuadEdgeRef a, QuadEdgeRef b)
+{
+	QuadEdgeRef ta, tb;
+	QuadEdgeRef alpha = ROT(ONEXT(a));
+	QuadEdgeRef beta = ROT(ONEXT(b));
+
+	ta = ONEXT(a);
+	tb = ONEXT(b);
+	ONEXT(a) = tb;
+	ONEXT(b) = ta;
+	ta = ONEXT(alpha);
+	tb = ONEXT(beta);
+	ONEXT(alpha) = tb;
+	ONEXT(beta) = ta;    
+}
+
+QuadEdgeRef ConnectQuadEdges(MemoryPool *qp, QuadEdgeRef a, QuadEdgeRef b)
+{
+	QuadEdgeRef e;
+
+	e = MakeQuadEdge( qp );
+	ORG(e) = DEST(a);
+	DEST(e) = ORG(b);
+	
+	SpliceQuadEdges(e, LNEXT(a));
+	SpliceQuadEdges(SYM(e), b);
+	
+	return e;
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/RMatrix.c
--- a/Geometry/src/RMatrix.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: RMatrix.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "VectorMath.h"
-#include "RMatrix.h"
-#include "TrigMath.h"
-
-#include <math.h>
-#include <assert.h>
-#include <string.h>
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-void RMatrix_BuildOrientation( RMatrix dest, Coord zAxis, Coord xAxis ) {
-	Coord		nxa;
-	
-	RMatrix_LoadIdentity( dest );
-	RMatrix_ApplyRotationY( dest, ArcTan( zAxis[0], zAxis[2] ) );
-	RMatrix_ApplyRotationX( dest, asin( zAxis[1] / Vec_Mag3D( zAxis ) ) );
-	
-	RMatrix_VectorMult( nxa, dest, xAxis );
-	RMatrix_ApplyRotationZ( dest, asin( nxa[1] / Vec_Mag3D( nxa ) ) );
-}
-
-
-void RMatrix_ApplyRotationY( RMatrix dest, double angle ) {
-	RMatrix		tmp;
-	
-	tmp[0] = cos( angle );  tmp[1] = 0.0;   tmp[2] = -sin( angle );
-	tmp[3] = 0.0;		tmp[4] = 1.0;   tmp[5] = 0.0;
-	tmp[6] = sin( angle );  tmp[7] = 0.0;   tmp[8] = cos( angle );
-	
-	RMatrix_Mult( dest, dest, tmp );
-}
-
-
-void RMatrix_ApplyRotationZ( RMatrix dest, double angle ) {
-	RMatrix		tmp;
-	
-	tmp[0] = cos( angle );  tmp[1] = sin( angle );  tmp[2] = 0.0;
-	tmp[3] = -sin( angle);  tmp[4] = cos( angle );  tmp[5] = 0.0;
-	tmp[6] = 0.0;		tmp[7] = 0.0;		tmp[8] = 1.0;
-	
-	RMatrix_Mult( dest, dest, tmp );
-}
-
-
-void RMatrix_ApplyRotationX( RMatrix dest, double angle ) {
-	RMatrix		tmp;
-	
-	tmp[0] = 1.0;   tmp[1] = 0.0;		tmp[2] = 0.0;
-	tmp[3] = 0.0;   tmp[4] = cos( angle );  tmp[5] = sin( angle );
-	tmp[6] = 0.0;   tmp[7] = -sin( angle);  tmp[8] = cos( angle );
-	
-	RMatrix_Mult( dest, dest, tmp );
-}
-
-
-void RMatrix_Mult( RMatrix dest, RMatrix a, RMatrix b ) {
-	RMatrix		tmp;
-	
-	tmp[0] = a[0] * b[0] + a[1] * b[3] + a[2] * b[6];
-	tmp[1] = a[0] * b[1] + a[1] * b[4] + a[2] * b[7];
-	tmp[2] = a[0] * b[2] + a[1] * b[5] + a[2] * b[8];
-	tmp[3] = a[3] * b[0] + a[4] * b[3] + a[5] * b[6];
-	tmp[4] = a[3] * b[1] + a[4] * b[4] + a[5] * b[7];
-	tmp[5] = a[3] * b[2] + a[4] * b[5] + a[5] * b[8];
-	tmp[6] = a[6] * b[0] + a[7] * b[3] + a[8] * b[6];
-	tmp[7] = a[6] * b[1] + a[7] * b[4] + a[8] * b[7];
-	tmp[8] = a[6] * b[2] + a[7] * b[5] + a[8] * b[8];
-	
-	memcpy( dest, tmp, sizeof(RMatrix) );
-}
-
-
-void RMatrix_VectorMult( Coord dest, RMatrix mat, Coord vec ) {
-	Coord		tmp;
-	
-	tmp[0] = mat[0] * vec[0] + mat[1] * vec[1] + mat[2] * vec[2];
-	tmp[1] = mat[3] * vec[0] + mat[4] * vec[1] + mat[5] * vec[2];
-	tmp[2] = mat[6] * vec[0] + mat[7] * vec[1] + mat[8] * vec[2];
-	
-	Vec_Set3D( dest, tmp );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/RMatrix.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/RMatrix.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,122 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: RMatrix.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "VectorMath.h"
+#include "RMatrix.h"
+#include "TrigMath.h"
+
+#include <math.h>
+#include <assert.h>
+#include <string.h>
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+void RMatrix_BuildOrientation( RMatrix dest, Coord zAxis, Coord xAxis ) {
+	Coord		nxa;
+	
+	RMatrix_LoadIdentity( dest );
+	RMatrix_ApplyRotationY( dest, ArcTan( zAxis[0], zAxis[2] ) );
+	RMatrix_ApplyRotationX( dest, asin( zAxis[1] / Vec_Mag3D( zAxis ) ) );
+	
+	RMatrix_VectorMult( nxa, dest, xAxis );
+	RMatrix_ApplyRotationZ( dest, asin( nxa[1] / Vec_Mag3D( nxa ) ) );
+}
+
+
+void RMatrix_ApplyRotationY( RMatrix dest, double angle ) {
+	RMatrix		tmp;
+	
+	tmp[0] = cos( angle );  tmp[1] = 0.0;   tmp[2] = -sin( angle );
+	tmp[3] = 0.0;		tmp[4] = 1.0;   tmp[5] = 0.0;
+	tmp[6] = sin( angle );  tmp[7] = 0.0;   tmp[8] = cos( angle );
+	
+	RMatrix_Mult( dest, dest, tmp );
+}
+
+
+void RMatrix_ApplyRotationZ( RMatrix dest, double angle ) {
+	RMatrix		tmp;
+	
+	tmp[0] = cos( angle );  tmp[1] = sin( angle );  tmp[2] = 0.0;
+	tmp[3] = -sin( angle);  tmp[4] = cos( angle );  tmp[5] = 0.0;
+	tmp[6] = 0.0;		tmp[7] = 0.0;		tmp[8] = 1.0;
+	
+	RMatrix_Mult( dest, dest, tmp );
+}
+
+
+void RMatrix_ApplyRotationX( RMatrix dest, double angle ) {
+	RMatrix		tmp;
+	
+	tmp[0] = 1.0;   tmp[1] = 0.0;		tmp[2] = 0.0;
+	tmp[3] = 0.0;   tmp[4] = cos( angle );  tmp[5] = sin( angle );
+	tmp[6] = 0.0;   tmp[7] = -sin( angle);  tmp[8] = cos( angle );
+	
+	RMatrix_Mult( dest, dest, tmp );
+}
+
+
+void RMatrix_Mult( RMatrix dest, RMatrix a, RMatrix b ) {
+	RMatrix		tmp;
+	
+	tmp[0] = a[0] * b[0] + a[1] * b[3] + a[2] * b[6];
+	tmp[1] = a[0] * b[1] + a[1] * b[4] + a[2] * b[7];
+	tmp[2] = a[0] * b[2] + a[1] * b[5] + a[2] * b[8];
+	tmp[3] = a[3] * b[0] + a[4] * b[3] + a[5] * b[6];
+	tmp[4] = a[3] * b[1] + a[4] * b[4] + a[5] * b[7];
+	tmp[5] = a[3] * b[2] + a[4] * b[5] + a[5] * b[8];
+	tmp[6] = a[6] * b[0] + a[7] * b[3] + a[8] * b[6];
+	tmp[7] = a[6] * b[1] + a[7] * b[4] + a[8] * b[7];
+	tmp[8] = a[6] * b[2] + a[7] * b[5] + a[8] * b[8];
+	
+	memcpy( dest, tmp, sizeof(RMatrix) );
+}
+
+
+void RMatrix_VectorMult( Coord dest, RMatrix mat, Coord vec ) {
+	Coord		tmp;
+	
+	tmp[0] = mat[0] * vec[0] + mat[1] * vec[1] + mat[2] * vec[2];
+	tmp[1] = mat[3] * vec[0] + mat[4] * vec[1] + mat[5] * vec[2];
+	tmp[2] = mat[6] * vec[0] + mat[7] * vec[1] + mat[8] * vec[2];
+	
+	Vec_Set3D( dest, tmp );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Simplex.c
--- a/Geometry/src/Simplex.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,218 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Simplex.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include "StGermain/StGermain.h"
-#include "Geometry.h"
-
-
-Bool Simplex_Search3D( double** verts, unsigned* inc, 
-		       unsigned nSimplices, unsigned** inds, 
-		       double* point, double* bc, unsigned* inside )
-{
-	unsigned	s_i;
-
-	assert( inds );
-
-	for( s_i = 0; s_i < nSimplices; s_i++ ) {
-		unsigned	ind_i;
-
-		Simplex_Barycenter3D( verts, inc, inds[s_i], point, bc );
-		for( ind_i = 0; ind_i < 4; ind_i++ ) {
-			if( bc[ind_i] < 0.0 || bc[ind_i] > 1.0 )
-				break;
-		}
-		if( ind_i == 4 ) {
-			*inside = s_i;
-			return True;
-		}
-	}
-
-	return False;
-}
-
-Bool Simplex_Search2D( double** verts, unsigned* inc, 
-		       unsigned nSimplices, unsigned** inds, 
-		       double* point, double* bc, unsigned* inside )
-{
-	unsigned	s_i;
-
-	assert( inds );
-
-	for( s_i = 0; s_i < nSimplices; s_i++ ) {
-		unsigned	ind_i;
-
-		Simplex_Barycenter2D( verts, inc, inds[s_i], point, bc );
-		for( ind_i = 0; ind_i < 3; ind_i++ ) {
-			if( bc[ind_i] < 0.0 || bc[ind_i] > 1.0 )
-				break;
-		}
-		if( ind_i == 3 ) {
-			*inside = s_i;
-			return True;
-		}
-	}
-
-	return False;
-}
-
-void Simplex_Barycenter3D( double** verts, unsigned* inc, unsigned* inds, double* point, double* bc ) {
-	double*	tet[4];
-	double	x0, y0, z0;
-	double	x1, y1, z1;
-	double	x2, y2, z2;
-	double	x3, y3, z3;
-	double	px, py, pz;
-	double	den;
-
-	assert( verts );
-	assert( inc );
-	assert( inds );
-	assert( point );
-	assert( bc );
-	assert( verts[inc[inds[0]]] );
-	assert( verts[inc[inds[1]]] );
-	assert( verts[inc[inds[2]]] );
-	assert( verts[inc[inds[3]]] );
-
-	tet[0] = verts[inc[inds[0]]];
-	tet[1] = verts[inc[inds[1]]];
-	tet[2] = verts[inc[inds[2]]];
-	tet[3] = verts[inc[inds[3]]];
-	x0 = tet[0][0]; x1 = tet[1][0]; x2 = tet[2][0]; x3 = tet[3][0];
-	y0 = tet[0][1]; y1 = tet[1][1]; y2 = tet[2][1]; y3 = tet[3][1];
-	z0 = tet[0][2]; z1 = tet[1][2]; z2 = tet[2][2]; z3 = tet[3][2];
-	px = point[0]; py = point[1]; pz = point[2];
-	den = 1.0 / (x1*(y0*(z3 - z2) + y2*(z0 - z3) + y3*(z2 - z0)) + 
-			     x0*(y2*(z3 - z1) + y1*(z2 - z3) + y3*(z1 - z2)) + 
-			     x2*(y1*(z3 - z0) + y0*(z1 - z3) + y3*(z0 - z1)) + 
-			     x3*(y0*(z2 - z1) + y1*(z0 - z2) + y2*(z1 - z0)));
-
-	bc[1] = -(x0*(py*(z3 - z2) + y2*(pz - z3) + y3*(z2 - pz)) + 
-		   px*(y2*(z3 - z0) + y0*(z2 - z3) + y3*(z0 - z2)) + 
-		   x2*(y0*(z3 - pz) + py*(z0 - z3) + y3*(pz - z0)) + 
-		   x3*(py*(z2 - z0) + y0*(pz - z2) + y2*(z0 - pz))) * den;
-	if( Num_Approx( bc[1], 0.0 ) ) bc[1] = 0.0;
-	else if( Num_Approx( bc[1], 1.0 ) ) bc[1] = 1.0;
-
-	bc[2] = (x0*(py*(z3 - z1) + y1*(pz - z3) + y3*(z1 - pz)) + 
-		  px*(y1*(z3 - z0) + y0*(z1 - z3) + y3*(z0 - z1)) + 
-		  x1*(y0*(z3 - pz) + py*(z0 - z3) + y3*(pz - z0)) + 
-		  x3*(py*(z1 - z0) + y0*(pz - z1) + y1*(z0 - pz))) * den;
-	if( Num_Approx( bc[2], 0.0 ) ) bc[2] = 0.0;
-	else if( Num_Approx( bc[2], 1.0 ) ) bc[2] = 1.0;
-
-	bc[3] = -(x0*(py*(z2 - z1) + y1*(pz - z2) + y2*(z1 - pz)) + 
-		   px*(y1*(z2 - z0) + y0*(z1 - z2) + y2*(z0 - z1)) + 
-		   x1*(y0*(z2 - pz) + py*(z0 - z2) + y2*(pz - z0)) + 
-		   x2*(py*(z1 - z0) + y0*(pz - z1) + y1*(z0 - pz))) * den;
-	if( Num_Approx( bc[3], 0.0 ) ) bc[3] = 0.0;
-	else if( Num_Approx( bc[3], 1.0 ) ) bc[3] = 1.0;
-
-	bc[0] = 1.0 - bc[1] - bc[2] - bc[3];
-	if( Num_Approx( bc[0], 0.0 ) ) bc[0] = 0.0;
-	else if( Num_Approx( bc[0], 1.0 ) ) bc[0] = 1.0;
-}
-
-void Simplex_Barycenter2D( double** verts, unsigned* inc, unsigned* inds, double* point, double* bc ) {
-	double*	tri[3];
-	double	a;
-	double	b;
-	double	c;
-	double	d;
-	double	e;
-	double	f;
-
-	assert( verts );
-	assert( inc );
-	assert( inds );
-	assert( point );
-	assert( bc );
-	assert( verts[inc[inds[0]]] );
-	assert( verts[inc[inds[1]]] );
-	assert( verts[inc[inds[2]]] );
-
-	tri[0] = verts[inc[inds[0]]];
-	tri[1] = verts[inc[inds[1]]];
-	tri[2] = verts[inc[inds[2]]];
-	a = tri[0][0] - tri[2][0];
-	b = tri[1][0] - tri[2][0];
-	c = tri[2][0] - point[0];
-	d = tri[0][1] - tri[2][1];
-	e = tri[1][1] - tri[2][1];
-	f = tri[2][1] - point[1];
-
-	bc[0] = (b * f - c * e) / (a * e - b * d);
-	if( Num_Approx( bc[0], 0.0 ) ) bc[0] = 0.0;
-	else if( Num_Approx( bc[0], 1.0 ) ) bc[0] = 1.0;
-	bc[1] = (a * f - c * d) / (b * d - a * e);
-	if( Num_Approx( bc[1], 0.0 ) ) bc[1] = 0.0;
-	else if( Num_Approx( bc[1], 1.0 ) ) bc[1] = 1.0;
-	bc[2] = 1.0 - bc[0] - bc[1];
-	if( Num_Approx( bc[2], 0.0 ) ) bc[2] = 0.0;
-	else if( Num_Approx( bc[2], 1.0 ) ) bc[2] = 1.0;
-}
-
-double Simplex_Volume( double** verts, unsigned* inc, unsigned* inds ) {
-	static const double	fac = 1.0 / 6.0;
-	double			da[3], db[3], dc[3];
-
-	assert( verts );
-	assert( inc );
-	assert( inds );
-
-	Vec_Sub3D( da, verts[inc[inds[2]]], verts[inc[inds[0]]] );
-	Vec_Sub3D( db, verts[inc[inds[2]]], verts[inc[inds[1]]] );
-	Vec_Sub3D( dc, verts[inc[inds[2]]], verts[inc[inds[2]]] );
-	Vec_Cross3D( db, db, dc );
-
-	return fac * fabs( Vec_Dot3D( da, db ) );
-}
-
-double Simplex_Area( double** verts, unsigned* inc, unsigned* inds ) {
-	unsigned	a = inc[inds[0]];
-	unsigned	b = inc[inds[1]];
-	unsigned	c = inc[inds[2]];
-
-	assert( verts );
-	assert( inc );
-	assert( inds );
-
-	return 0.5 * fabs( verts[a][0] * (verts[c][1] - verts[b][1]) + 
-			   verts[b][0] * (verts[a][1] - verts[c][1]) + 
-			   verts[c][0] * (verts[b][1] - verts[a][1]) );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/Simplex.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/Simplex.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,218 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Simplex.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include "StGermain/StGermain.h"
+#include "Geometry.h"
+
+
+Bool Simplex_Search3D( double** verts, unsigned* inc, 
+		       unsigned nSimplices, unsigned** inds, 
+		       double* point, double* bc, unsigned* inside )
+{
+	unsigned	s_i;
+
+	assert( inds );
+
+	for( s_i = 0; s_i < nSimplices; s_i++ ) {
+		unsigned	ind_i;
+
+		Simplex_Barycenter3D( verts, inc, inds[s_i], point, bc );
+		for( ind_i = 0; ind_i < 4; ind_i++ ) {
+			if( bc[ind_i] < 0.0 || bc[ind_i] > 1.0 )
+				break;
+		}
+		if( ind_i == 4 ) {
+			*inside = s_i;
+			return True;
+		}
+	}
+
+	return False;
+}
+
+Bool Simplex_Search2D( double** verts, unsigned* inc, 
+		       unsigned nSimplices, unsigned** inds, 
+		       double* point, double* bc, unsigned* inside )
+{
+	unsigned	s_i;
+
+	assert( inds );
+
+	for( s_i = 0; s_i < nSimplices; s_i++ ) {
+		unsigned	ind_i;
+
+		Simplex_Barycenter2D( verts, inc, inds[s_i], point, bc );
+		for( ind_i = 0; ind_i < 3; ind_i++ ) {
+			if( bc[ind_i] < 0.0 || bc[ind_i] > 1.0 )
+				break;
+		}
+		if( ind_i == 3 ) {
+			*inside = s_i;
+			return True;
+		}
+	}
+
+	return False;
+}
+
+void Simplex_Barycenter3D( double** verts, unsigned* inc, unsigned* inds, double* point, double* bc ) {
+	double*	tet[4];
+	double	x0, y0, z0;
+	double	x1, y1, z1;
+	double	x2, y2, z2;
+	double	x3, y3, z3;
+	double	px, py, pz;
+	double	den;
+
+	assert( verts );
+	assert( inc );
+	assert( inds );
+	assert( point );
+	assert( bc );
+	assert( verts[inc[inds[0]]] );
+	assert( verts[inc[inds[1]]] );
+	assert( verts[inc[inds[2]]] );
+	assert( verts[inc[inds[3]]] );
+
+	tet[0] = verts[inc[inds[0]]];
+	tet[1] = verts[inc[inds[1]]];
+	tet[2] = verts[inc[inds[2]]];
+	tet[3] = verts[inc[inds[3]]];
+	x0 = tet[0][0]; x1 = tet[1][0]; x2 = tet[2][0]; x3 = tet[3][0];
+	y0 = tet[0][1]; y1 = tet[1][1]; y2 = tet[2][1]; y3 = tet[3][1];
+	z0 = tet[0][2]; z1 = tet[1][2]; z2 = tet[2][2]; z3 = tet[3][2];
+	px = point[0]; py = point[1]; pz = point[2];
+	den = 1.0 / (x1*(y0*(z3 - z2) + y2*(z0 - z3) + y3*(z2 - z0)) + 
+			     x0*(y2*(z3 - z1) + y1*(z2 - z3) + y3*(z1 - z2)) + 
+			     x2*(y1*(z3 - z0) + y0*(z1 - z3) + y3*(z0 - z1)) + 
+			     x3*(y0*(z2 - z1) + y1*(z0 - z2) + y2*(z1 - z0)));
+
+	bc[1] = -(x0*(py*(z3 - z2) + y2*(pz - z3) + y3*(z2 - pz)) + 
+		   px*(y2*(z3 - z0) + y0*(z2 - z3) + y3*(z0 - z2)) + 
+		   x2*(y0*(z3 - pz) + py*(z0 - z3) + y3*(pz - z0)) + 
+		   x3*(py*(z2 - z0) + y0*(pz - z2) + y2*(z0 - pz))) * den;
+	if( Num_Approx( bc[1], 0.0 ) ) bc[1] = 0.0;
+	else if( Num_Approx( bc[1], 1.0 ) ) bc[1] = 1.0;
+
+	bc[2] = (x0*(py*(z3 - z1) + y1*(pz - z3) + y3*(z1 - pz)) + 
+		  px*(y1*(z3 - z0) + y0*(z1 - z3) + y3*(z0 - z1)) + 
+		  x1*(y0*(z3 - pz) + py*(z0 - z3) + y3*(pz - z0)) + 
+		  x3*(py*(z1 - z0) + y0*(pz - z1) + y1*(z0 - pz))) * den;
+	if( Num_Approx( bc[2], 0.0 ) ) bc[2] = 0.0;
+	else if( Num_Approx( bc[2], 1.0 ) ) bc[2] = 1.0;
+
+	bc[3] = -(x0*(py*(z2 - z1) + y1*(pz - z2) + y2*(z1 - pz)) + 
+		   px*(y1*(z2 - z0) + y0*(z1 - z2) + y2*(z0 - z1)) + 
+		   x1*(y0*(z2 - pz) + py*(z0 - z2) + y2*(pz - z0)) + 
+		   x2*(py*(z1 - z0) + y0*(pz - z1) + y1*(z0 - pz))) * den;
+	if( Num_Approx( bc[3], 0.0 ) ) bc[3] = 0.0;
+	else if( Num_Approx( bc[3], 1.0 ) ) bc[3] = 1.0;
+
+	bc[0] = 1.0 - bc[1] - bc[2] - bc[3];
+	if( Num_Approx( bc[0], 0.0 ) ) bc[0] = 0.0;
+	else if( Num_Approx( bc[0], 1.0 ) ) bc[0] = 1.0;
+}
+
+void Simplex_Barycenter2D( double** verts, unsigned* inc, unsigned* inds, double* point, double* bc ) {
+	double*	tri[3];
+	double	a;
+	double	b;
+	double	c;
+	double	d;
+	double	e;
+	double	f;
+
+	assert( verts );
+	assert( inc );
+	assert( inds );
+	assert( point );
+	assert( bc );
+	assert( verts[inc[inds[0]]] );
+	assert( verts[inc[inds[1]]] );
+	assert( verts[inc[inds[2]]] );
+
+	tri[0] = verts[inc[inds[0]]];
+	tri[1] = verts[inc[inds[1]]];
+	tri[2] = verts[inc[inds[2]]];
+	a = tri[0][0] - tri[2][0];
+	b = tri[1][0] - tri[2][0];
+	c = tri[2][0] - point[0];
+	d = tri[0][1] - tri[2][1];
+	e = tri[1][1] - tri[2][1];
+	f = tri[2][1] - point[1];
+
+	bc[0] = (b * f - c * e) / (a * e - b * d);
+	if( Num_Approx( bc[0], 0.0 ) ) bc[0] = 0.0;
+	else if( Num_Approx( bc[0], 1.0 ) ) bc[0] = 1.0;
+	bc[1] = (a * f - c * d) / (b * d - a * e);
+	if( Num_Approx( bc[1], 0.0 ) ) bc[1] = 0.0;
+	else if( Num_Approx( bc[1], 1.0 ) ) bc[1] = 1.0;
+	bc[2] = 1.0 - bc[0] - bc[1];
+	if( Num_Approx( bc[2], 0.0 ) ) bc[2] = 0.0;
+	else if( Num_Approx( bc[2], 1.0 ) ) bc[2] = 1.0;
+}
+
+double Simplex_Volume( double** verts, unsigned* inc, unsigned* inds ) {
+	static const double	fac = 1.0 / 6.0;
+	double			da[3], db[3], dc[3];
+
+	assert( verts );
+	assert( inc );
+	assert( inds );
+
+	Vec_Sub3D( da, verts[inc[inds[2]]], verts[inc[inds[0]]] );
+	Vec_Sub3D( db, verts[inc[inds[2]]], verts[inc[inds[1]]] );
+	Vec_Sub3D( dc, verts[inc[inds[2]]], verts[inc[inds[2]]] );
+	Vec_Cross3D( db, db, dc );
+
+	return fac * fabs( Vec_Dot3D( da, db ) );
+}
+
+double Simplex_Area( double** verts, unsigned* inc, unsigned* inds ) {
+	unsigned	a = inc[inds[0]];
+	unsigned	b = inc[inds[1]];
+	unsigned	c = inc[inds[2]];
+
+	assert( verts );
+	assert( inc );
+	assert( inds );
+
+	return 0.5 * fabs( verts[a][0] * (verts[c][1] - verts[b][1]) + 
+			   verts[b][0] * (verts[a][1] - verts[c][1]) + 
+			   verts[c][0] * (verts[b][1] - verts[a][1]) );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/TensorMath.c
--- a/Geometry/src/TensorMath.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1047 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TensorMath.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-#include "units.h"
-#include "types.h"
-#include "TensorMath.h"
-#include "VectorMath.h"
-#include "TrigMath.h"
-
-#include <math.h>
-#include <string.h>
-
-/** Mappings from enumerated types to arrays
-This gives the user the option to use:
-References instead of enumerated types.
-TensorMapFT2D[0][0] = FT2D_00
-etc.
-*/
-const unsigned int TensorMapFT2D[2][2] = {{FT2D_00, FT2D_01},{FT2D_10, FT2D_11}};
-
-/** See explanation for TensorMapFT2D */
-const unsigned int TensorMapST2D[2][2] = {{ST2D_00, ST2D_01},{ST2D_01, ST2D_11}};
-
-/** See explanation for TensorMapFT2D */
-const unsigned int TensorMapFT3D[3][3] ={{FT3D_00, FT3D_01, FT3D_02},{FT3D_10, FT3D_11, FT3D_12},{FT3D_20, FT3D_21, FT3D_22}};
-
-/** See explanation for TensorMapFT2D */
-const unsigned int TensorMapST3D[3][3] ={{ST3D_00, ST3D_01, ST3D_02},{ST3D_01, ST3D_11, ST3D_12},{ST3D_02, ST3D_12, ST3D_22}};
-
-/** This is a wrapper that converts a row/col index and a dimension
-into the correct number to reference the correct address of the value
-in the tensorArray function.
-*/
-int TensorArray_TensorMap(Dimension_Index row_I, Dimension_Index col_I, Dimension_Index dim) {
-	switch (dim) {
-		case 3: {
-			return TensorMapFT3D[ row_I ][ col_I ];
-		}
-		case 2: {
-			return TensorMapFT2D[ row_I ][ col_I ];
-		}
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-		
-	}
-	return 0;
-}
-
-/** This is a wrapper that converts a row/col index and a dimension
-into the correct number to reference the correct address of the value
-in the symmetricTensor function.
-*/
-int SymmetricTensor_TensorMap(Dimension_Index row_I, Dimension_Index col_I, Dimension_Index dim) {
-	switch (dim) {
-		case 3: {
-			return TensorMapST3D[ row_I ][ col_I ];
-		}
-		case 2: {
-			return TensorMapST2D[ row_I ][ col_I ];
-		}
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-		
-	}
-	return 0;
-}
-
-/** This sets the values from a nxn array into a TensorArray */ 
-void TensorArray_SetFromDoubleArray( TensorArray tensor, double** array, Dimension_Index dim ) {
-	Dimension_Index row_I, col_I;
-
-	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
-		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
-			tensor[ MAP_TENSOR( row_I, col_I, dim ) ] = array[ row_I ][ col_I ];
-		}
-	}
-}
-
-/** Converts a symmetric tensor to a full tensor */
-void StGermain_SymmetricTensor_ToTensorArray(SymmetricTensor symTensor, Dimension_Index dim, TensorArray fullTensor) {
-	switch (dim) {
-		case 3:
-			StGermain_SymmetricTensor_ToTensorArray3D(symTensor, fullTensor);
-			return;
-		case 2:
-			StGermain_SymmetricTensor_ToTensorArray2D(symTensor, fullTensor);
-			return;
-		default: {
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-}
-/** This function uses enumerated types to convert symmetric tensors to full tensors */
-void StGermain_SymmetricTensor_ToTensorArray2D(SymmetricTensor symTensor, TensorArray fullTensor) {
-
-	fullTensor[FT2D_00] = symTensor[ST2D_00];
-	fullTensor[FT2D_01] = symTensor[ST2D_01];
-	fullTensor[FT2D_10] = symTensor[ST2D_01];
-	fullTensor[FT2D_11] = symTensor[ST2D_11];
-	
-
-}
-
-/** This function uses enumerated types to convert symmetric tensors to full tensors */
-void StGermain_SymmetricTensor_ToTensorArray3D(SymmetricTensor symTensor, TensorArray fullTensor) {
-	/*Using enumerated types to convert symmetric tensors to full tensors */
-	fullTensor[FT3D_00] = symTensor[ST3D_00];
-	fullTensor[FT3D_01] = symTensor[ST3D_01];
-	fullTensor[FT3D_02] = symTensor[ST3D_02];
-	fullTensor[FT3D_10] = symTensor[ST3D_01];
-	fullTensor[FT3D_11] = symTensor[ST3D_11];
-	fullTensor[FT3D_12] = symTensor[ST3D_12];
-	fullTensor[FT3D_20] = symTensor[ST3D_02];
-	fullTensor[FT3D_21] = symTensor[ST3D_12];
-	fullTensor[FT3D_22] = symTensor[ST3D_22];
-	
-
-}
-
-/** This function converts TensorArray's to square Matrixes */
-void TensorArray_ToMatrix( TensorArray tensor, Dimension_Index dim, double** matrix ) {
-	if (dim == 2) {
-		matrix[0][0] = tensor[FT2D_00] ; matrix[0][1] = tensor[FT2D_01] ;
-		matrix[1][0] = tensor[FT2D_10] ; matrix[1][1] = tensor[FT2D_11] ;
-	}
-	else if (dim == 3) {
-		matrix[0][0] = tensor[FT3D_00];	matrix[0][1] = tensor[FT3D_01];	matrix[0][2] = tensor[FT3D_02];
-		matrix[1][0] = tensor[FT3D_10];	matrix[1][1] = tensor[FT3D_11];	matrix[1][2] = tensor[FT3D_12];
-		matrix[2][0] = tensor[FT3D_20];	matrix[2][1] = tensor[FT3D_21];	matrix[2][2] = tensor[FT3D_22];
-	}
-	else {
-		Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-	}
-}
-
-
-void ZeroMatrix( double** matrix, Index rows, Index cols ) {
-	Index count_I;
-	for( count_I = 0 ; count_I < rows ; count_I++ ) {
-		memset( matrix[ count_I ], 0, (cols*sizeof(double)) );
-	}
-}
-
-
-/** This function extracts out the antiSymmetric part of a tensor Array
-v_{ij} = 0.5 * ( u_{ij} - u_{ji} )
-See http://mathworld.wolfram.com/AntisymmetricPart.html */
-void TensorArray_GetAntisymmetricPart( TensorArray tensor, Dimension_Index dim, TensorArray antiSymmetric ) {
-	switch (dim) {
-		case 3:
-			/* v_{xz} = 0.5*( u_{xz} - u_{zx} ) */
-			antiSymmetric[ TensorMapFT3D[0][2] ] = 0.5 * (tensor[ TensorMapFT3D[0][2] ] - 
-							tensor[ TensorMapFT3D[2][0] ] );
-			
-			/* v_{yz} = 0.5*( u_{yz} - u_{zy} ) */
-			antiSymmetric[ TensorMapFT3D[1][2] ] = 0.5 * (tensor[ TensorMapFT3D[1][2] ] - 
-							tensor[ TensorMapFT3D[2][1] ] );
-			
-			/* v_{zx} = 0.5*( u_{zx} - u_{xz} ) */
-			antiSymmetric[ TensorMapFT3D[2][0] ] = - antiSymmetric[ TensorMapFT3D[0][2] ];
-
-			/* v_{zy} = 0.5*( u_{zy} - u_{yz} ) */	
-			antiSymmetric[ TensorMapFT3D[2][1] ] = - antiSymmetric[ TensorMapFT3D[1][2] ];
-
-			/* v_{zz} = 0.5*( u_{zz} - u_{zz} ) */
-			antiSymmetric[ TensorMapFT3D[2][2] ] = 0.0;
-
-			/* v_{xy} = 0.5*( u_{xy} - u_{yx} ) */
-			antiSymmetric[ TensorMapFT3D[0][1] ] = 0.5 * (tensor[ TensorMapFT3D[0][1] ] - 
-						tensor[ TensorMapFT3D[1][0] ] );
-
-			/* v_{yx} = 0.5*( u_{yx} - u_{xy} ) */
-			antiSymmetric[ TensorMapFT3D[1][0] ] = - antiSymmetric[ TensorMapFT3D[0][1] ];
-
-			/* v_{yy} = 0.5*( u_{yy} - u_{yy} ) */
-			antiSymmetric[ TensorMapFT3D[1][1] ] = 0.0;
-			
-			/* v_{xx} = 0.5*( u_{xx} - u_{xx} ) */
-			antiSymmetric[ TensorMapFT3D[0][0] ] = 0.0;
-			return;
-		case 2:		
-			/* v_{xy} = 0.5*( u_{xy} - u_{yx} ) */
-			antiSymmetric[ TensorMapFT2D[0][1] ] = 0.5 * (tensor[ TensorMapFT2D[0][1] ] - 
-						tensor[ TensorMapFT2D[1][0] ] );
-
-			/* v_{yx} = 0.5*( u_{yx} - u_{xy} ) */
-			antiSymmetric[ TensorMapFT2D[1][0] ] = - antiSymmetric[ TensorMapFT2D[0][1] ];
-
-			/* v_{yy} = 0.5*( u_{yy} - u_{yy} ) */
-			antiSymmetric[ TensorMapFT2D[1][1] ] = 0.0;
-			
-			/* v_{xx} = 0.5*( u_{xx} - u_{xx} ) */
-			antiSymmetric[ TensorMapFT2D[0][0] ] = 0.0;
-			return;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot store tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-}
-
-/** This function calculates the symmetric part of a TensorArray and returns
-it in a SymmetricTensor: 
-v_{ij} = 0.5 * ( u_{ij} + u_{ji} ) 
-see http://mathworld.wolfram.com/SymmetricPart.html 
-It can also be used to convert a symmetric TensorArray to a SymmetricTensor
-if the TensorArray is guaranteed to be Symmetric. (It has no type checking)*/
-void TensorArray_GetSymmetricPart( TensorArray tensor, Dimension_Index dim, SymmetricTensor symmetricTensor ) {
-	switch (dim) {
-		case 2:
-			/* Diagonal Terms */
-			/* v_{xx} = 0.5*( u_{xx} + u_{xx} ) */
-			/* v_{yy} = 0.5*( u_{yy} + u_{yy} ) */
-			symmetricTensor[ TensorMapST2D[0][0] ] = tensor[ TensorMapFT2D[0][0] ]; 
-			symmetricTensor[ TensorMapST2D[1][1] ] = tensor[ TensorMapFT2D[1][1] ]; 
-			
-			/* Off-diagonal Term */
-			/* v_{xy} = 0.5*( u_{xy} + u_{yx} ) */
-			symmetricTensor[ TensorMapST2D[0][1] ] = 
-				0.5 * (tensor[ TensorMapFT2D[0][1] ] + tensor[ TensorMapFT2D[1][0] ]); 
-			return;
-		case 3:
-			/* Diagonal Terms */
-			/* v_{xx} = 0.5*( u_{xx} + u_{xx} ) */
-			/* v_{yy} = 0.5*( u_{yy} + u_{yy} ) */
-			/* v_{zz} = 0.5*( u_{zz} + u_{zz} ) */
-			symmetricTensor[ TensorMapST3D[0][0] ] = tensor[ TensorMapFT3D[0][0] ]; 
-			symmetricTensor[ TensorMapST3D[1][1] ] = tensor[ TensorMapFT3D[1][1] ]; 
-			symmetricTensor[ TensorMapST3D[2][2] ] = tensor[ TensorMapFT3D[2][2] ]; 
-			
-			/* Off-diagonal Terms */
-			/* v_{xy} = 0.5*( u_{xy} + u_{yx} ) */
-			/* v_{xz} = 0.5*( u_{xz} + u_{zx} ) */
-			/* v_{yz} = 0.5*( u_{yz} + u_{zy} ) */
-			symmetricTensor[ TensorMapST3D[0][1] ] =
-				0.5 * (tensor[ TensorMapFT3D[0][1] ] + tensor[ TensorMapFT3D[1][0] ]); 
-		
-			symmetricTensor[ TensorMapST3D[0][2] ] =
-				0.5 * (tensor[ TensorMapFT3D[0][2] ] + tensor[ TensorMapFT3D[2][0] ]); 
-		
-			symmetricTensor[ TensorMapST3D[1][2] ] =
-				0.5 * (tensor[ TensorMapFT3D[1][2] ] + tensor[ TensorMapFT3D[2][1] ]); 
-			return;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot store tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-}
-
-
-/** This function calculates the trace of a tenorArray 
-trace = u_{ii} */
-void TensorArray_GetTrace( TensorArray tensor, Dimension_Index dim, double *trace ) {
-	switch (dim) {
-	  case 1:
-		/* Sum the diagonal terms */
-		*trace = 	tensor[0];
-		break;
-	  case 2:
-		/* Sum the diagonal terms */
-		/*
-		*trace = 	tensor[ MAP_2D_TENSOR( 0, 0 ) ]
-		+ 	tensor[ MAP_2D_TENSOR( 1, 1 ) ];
-		*/
-		*trace = tensor[FT2D_00] + tensor[FT2D_11];
-		break;
-	  case 3:
-		/* Sum the diagonal terms */
-		/*
-		*trace = 	tensor[ MAP_3D_TENSOR( 0, 0 ) ]
-				+	tensor[ MAP_3D_TENSOR( 1, 1 ) ]
-				+	tensor[ MAP_3D_TENSOR( 2, 2 ) ];
-		*/
-		*trace = tensor[FT3D_00] + tensor[FT3D_11] + tensor[FT3D_22];
-		break;
-		  default:{
-		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot compute trace for tensor in dimension %d (in %s) since dim < 1.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-			break;
-		}
-	}
-}
-
-/** This function will calculate the trace of a symmetric tensor type */
-void SymmetricTensor_GetTrace( SymmetricTensor symmTensor, Dimension_Index dim, double *trace ) {
-	switch (dim) {
-	  case 1:
-		*trace = symmTensor[0];
-		break;
-	  case 2:
-		*trace = symmTensor[ST2D_00] + symmTensor[ST2D_11];
-		break;
-	  case 3:
-		*trace = symmTensor[ST3D_00] + symmTensor[ST3D_11] + symmTensor[ST3D_22];
-		break;
-	  default:{
-		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-		Journal_Printf( error, "Cannot compute trace for symmetric tensor in dimension %d (in %s) since dim is not in the range [1, 3].\n", dim, __func__);
-		Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-			"In func '%s' don't understand dim = %u\n", __func__, dim );
-		break;
-		  }
-	}
-
-}
-
-/** This function prints an unnamed tensorArray */
-void Journal_PrintTensorArray_Unnamed( Stream* stream, TensorArray tensor, Dimension_Index dim ) {
-	Dimension_Index row_I, col_I;
-
-	/* For efficency - Check if stream is enabled */
-	if (!Stream_IsEnable(stream)) return;
-
-	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
-		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
-			Journal_Printf( stream, "%7.5g     ", tensor[ MAP_TENSOR( row_I, col_I, dim ) ] );
-		}
-		Journal_Printf( stream, "\n" );
-	}
-}
-
-/** This function prints an unnamed square 2-D Array */
-void Journal_PrintSquareArray_Unnamed( Stream* stream, double** array, Dimension_Index dim ) {
-	Dimension_Index row_I, col_I;
-
-	/* For efficency - Check if stream is enabled */
-	if (!Stream_IsEnable(stream)) return;
-
-	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
-		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
-			Journal_Printf( stream, "%7.5g     ", array[row_I][col_I] );
-		}
-		Journal_Printf( stream, "\n" );
-	}
-}
-
-/** This function prints an unnamed SymmetricTensor */
-void Journal_PrintSymmetricTensor_Unnamed( Stream* stream, SymmetricTensor tensor, Dimension_Index dim ) {
-	Dimension_Index row_I, col_I;
-	/* For efficency - Check if stream is enabled */
-	if (!Stream_IsEnable(stream)) return;
-
-	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
-		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
-			Journal_Printf( stream, "%7.5g     ", tensor[ MAP_SYMM_TENSOR( row_I, col_I, dim ) ] );
-		}
-		Journal_Printf( stream, "\n" );
-	}
-}
-
-/** This function calculates the second Invariant of a TensorArray: 
-u = \sqrt{ 0.5 u_{ij} u_{ij} } */
-double TensorArray_2ndInvariant( TensorArray tensor, Dimension_Index dim ) {
-	double invariant = 0.0;
-	switch( dim ) {
-		case 3:
-			invariant += 
-				tensor[4] * tensor[4] +
-				tensor[5] * tensor[5] +
-				tensor[6] * tensor[6] +
-				tensor[7] * tensor[7] +
-				tensor[8] * tensor[8] ;
-		case 2:
-			invariant += 
-				tensor[1] * tensor[1] +
-				tensor[2] * tensor[2] +
-				tensor[3] * tensor[3] ;
-		case 1:
-			invariant += tensor[0] * tensor[0];
-			break;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-	return sqrt( 0.5 * invariant );
-}
-
-/** This function calculates the second Invariant of a SymmetricTensor:  
-u = \sqrt{ 0.5 u_{ij} u_{ij} } */
-double SymmetricTensor_2ndInvariant( SymmetricTensor tensor, Dimension_Index dim ) {
-	double invariant = 0.0;
-	
-	switch( dim ) {
-		case 3:
-			invariant = 
-				0.5 * ( tensor[ TensorMapST3D[0][0] ] * tensor[ TensorMapST3D[0][0] ]   +
-				        tensor[ TensorMapST3D[1][1] ] * tensor[ TensorMapST3D[1][1] ]   +
-				        tensor[ TensorMapST3D[2][2] ] * tensor[ TensorMapST3D[2][2] ] ) +
-				
-				tensor[ TensorMapST3D[0][1] ] * tensor[ TensorMapST3D[1][0] ] +
-				tensor[ TensorMapST3D[0][2] ] * tensor[ TensorMapST3D[2][0] ] +
-				tensor[ TensorMapST3D[1][2] ] * tensor[ TensorMapST3D[2][1] ] ;
-			break;
-		case 2:
-			invariant = 
-				0.5 * ( tensor[ TensorMapST2D[0][0] ] * tensor[ TensorMapST2D[0][0] ]   +
-				        tensor[ TensorMapST2D[1][1] ] * tensor[ TensorMapST2D[1][1] ] ) +
-				tensor[ TensorMapST2D[0][1] ] * tensor[ TensorMapST2D[1][0] ] ;
-			break;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-	return sqrt( invariant );
-}
-
-
-/** a_i * u_{ij} * b_j */
-double TensorArray_MultiplyByVectors( TensorArray tensor, double* a, double* b, Dimension_Index dim ) {
-	double result = 0.0;
-
-	switch( dim ) {
-		case 3:
-			result = 
-				a[0] * tensor[ FT3D_00 ] * b[0] +
-				a[0] * tensor[ FT3D_01 ] * b[1] +
-				a[0] * tensor[ FT3D_02 ] * b[2] +
-
-				a[1] * tensor[ FT3D_10 ] * b[0] +
-				a[1] * tensor[ FT3D_11 ] * b[1] +
-				a[1] * tensor[ FT3D_12 ] * b[2] +
-
-				a[2] * tensor[ FT3D_20 ] * b[0] +
-				a[2] * tensor[ FT3D_21 ] * b[1] +
-				a[2] * tensor[ FT3D_22 ] * b[2] ;
-			break;
-		case 2:
-			result = 
-				a[0] * tensor[ FT2D_00 ] * b[0] +
-				a[0] * tensor[ FT2D_01 ] * b[1] +
-
-				a[1] * tensor[ FT2D_10 ] * b[0] +
-				a[1] * tensor[ FT2D_11 ] * b[1] ;
-			break;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-	return result;
-}
-
-/** returns u_{ij} * a_j */
-void SymmetricTensor_ApplyOnVector( SymmetricTensor tensor, double* vector, Dimension_Index dim, XYZ result ) {
-	switch( dim ) {
-		case 3:
-			result[0] = 
-				tensor[ TensorMapST3D[0][0] ] * vector[0] +
-				tensor[ TensorMapST3D[0][1] ] * vector[1] +
-				tensor[ TensorMapST3D[0][2] ] * vector[2] ;
-
-			result[1] = 	
-				tensor[ TensorMapST3D[1][0] ] * vector[0] +
-				tensor[ TensorMapST3D[1][1] ] * vector[1] +
-				tensor[ TensorMapST3D[1][2] ] * vector[2] ;
-
-			result[2] = 	
-				tensor[ TensorMapST3D[2][0] ] * vector[0] +
-				tensor[ TensorMapST3D[2][1] ] * vector[1] +
-				tensor[ TensorMapST3D[2][2] ] * vector[2] ;
-			break;
-		case 2:
-			result[0] = 
-				tensor[ TensorMapST2D[0][0] ] * vector[0] +
-				tensor[ TensorMapST2D[0][1] ] * vector[1] ;
-
-			result[1] = 
-				tensor[ TensorMapST2D[1][0] ] * vector[0] +
-				tensor[ TensorMapST2D[1][1] ] * vector[1] ;
-			break;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-}
-
-
-/** returns a_i * u_{ij} * b_j */
-double SymmetricTensor_MultiplyByVectors( SymmetricTensor tensor, double* a, double* b, Dimension_Index dim ) {
-	double result = 0.0;
-
-	switch( dim ) {
-		case 3:
-			result = 
-				a[0] * tensor[ TensorMapST3D[0][0] ] * b[0] +
-				a[0] * tensor[ TensorMapST3D[0][1] ] * b[1] +
-				a[0] * tensor[ TensorMapST3D[0][2] ] * b[2] +
-
-				a[1] * tensor[ TensorMapST3D[1][0] ] * b[0] +
-				a[1] * tensor[ TensorMapST3D[1][1] ] * b[1] +
-				a[1] * tensor[ TensorMapST3D[1][2] ] * b[2] +
-
-				a[2] * tensor[ TensorMapST3D[2][0] ] * b[0] +
-				a[2] * tensor[ TensorMapST3D[2][1] ] * b[1] +
-				a[2] * tensor[ TensorMapST3D[2][2] ] * b[2] ;
-			break;
-		case 2:
-			result = 
-				a[0] * tensor[ TensorMapST2D[0][0] ] * b[0] +
-				a[0] * tensor[ TensorMapST2D[0][1] ] * b[1] +
-
-				a[1] * tensor[ TensorMapST2D[1][0] ] * b[0] +
-				a[1] * tensor[ TensorMapST2D[1][1] ] * b[1] ;
-			break;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
-			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-	return result;
-}
-
-void SymmetricTensor_ToMatrix( SymmetricTensor tensor, Dimension_Index dim, double** matrix ) {
-	if (dim == 2) {
-		matrix[0][0] = tensor[ST2D_00] ; matrix[0][1] = tensor[ST2D_01] ;
-		matrix[1][0] = tensor[ST2D_01] ; matrix[1][1] = tensor[ST2D_11] ;
-	}
-	else if (dim == 3) {
-		matrix[0][0] = tensor[ST3D_00];	matrix[0][1] = tensor[ST3D_01];	matrix[0][2] = tensor[ST3D_02];
-		matrix[1][0] = tensor[ST3D_01];	matrix[1][1] = tensor[ST3D_11];	matrix[1][2] = tensor[ST3D_12];
-		matrix[2][0] = tensor[ST3D_02];	matrix[2][1] = tensor[ST3D_12];	matrix[2][2] = tensor[ST3D_22];
-	}
-	else {
-		Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-	}
-}
-		
-void TensorArray_Zero( TensorArray tensor ) {
-	memset( tensor, 0, sizeof(TensorArray) );
-}
-void SymmetricTensor_Zero( SymmetricTensor tensor ) {
-	memset( tensor, 0, sizeof(SymmetricTensor) );
-}
-
-
-int _QsortEigenvalue( const void* _a, const void* _b ) {
-	Eigenvector* a = (Eigenvector*) _a;
-	Eigenvector* b = (Eigenvector*) _b;
-
-	if ( a->eigenvalue > b->eigenvalue )
-		return 1;
-	else
-		return -1;
-}
-
-
-void SymmetricTensor_CalcAllEigenvalues( SymmetricTensor tensor, Dimension_Index dim, Eigenvector* eigenvectorList ) {
-	if ( dim == 2 ) 
-		SymmetricTensor_CalcAllEigenvalues2D( tensor, eigenvectorList );
-	else 
-		SymmetricTensor_CalcAllEigenvalues3D( tensor, eigenvectorList );
-}
-
-/* 
-For a symmetric 2D Matrix, Eigenvalues are given by: 
-\lambda = \frac{u_{00} + u_{11}}{2} \pm \sqrt{ \left(\frac{u_{00} - u_{11}}{2}\right)^2 + u_{01} }
-*/
-void SymmetricTensor_CalcAllEigenvalues2D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
-	double descriminantRoot, average;
-	
-	descriminantRoot = sqrt( 0.25 * (tensor[ST2D_00] - tensor[ST2D_11]) * 
-				(tensor[ST2D_00] - tensor[ST2D_11]) + tensor[ST2D_01] * tensor[ST2D_01] );
-
-	average = 0.5 * (tensor[ST2D_00] + tensor[ST2D_11]);
-
-	eigenvectorList[0].eigenvalue = average - descriminantRoot;
-	eigenvectorList[1].eigenvalue = average + descriminantRoot;
-}
-
-#define EQL(A,B)    (fabs( (A) - (B) ) < 1.0e-8) 
-/**
-Calculates the roots of the characteristic polynomial given by
-det( [tensor] - \lambda [I] ) = 0
-1.0 \lambda^3 + a2 \lambda^2 + a1 \lambda + a0 = 0
-Results compared with applet located at http://www.math.ubc.ca/~israel/applet/mcalc/matcalc.html */
-void SymmetricTensor_CalcAllEigenvalues3D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
-	double a2, a1, a0;
-	double rootList[3];
-
-	/*
-	a3 = 1.0
-	a2 = - tensor_xx - tensor_yy - tensor_zz
-	a1 = tensor_xx * tensor_yy  +  tensor_xx * tensor_zz  +  
-		tensor_yy * tensor_zz  -  tensor_xy^2  -  tensor_xz^2  - tensor_yz^2 
-	a0 = -tensor_xx * tensor_yy * tensor_zz  - 
-		2 * tensor_xy * tensor_xz * tensor_yz  + 
-		tensor_xx * tensor_yz^2  +  tensor_yy * tensor_xz^2  +  tensor_zz * tensor_xy^2
-	*/
-
-	a2 = - tensor[ST3D_00] - tensor[ST3D_11] - tensor[ST3D_22];
-	a1 = (tensor[ST3D_00] * tensor[ST3D_11])  +  
-		 (tensor[ST3D_00] * tensor[ST3D_22])  +  
-		 (tensor[ST3D_11] * tensor[ST3D_22])  -  
-		 (tensor[ST3D_01] * tensor[ST3D_01])  -  
-		 (tensor[ST3D_02] * tensor[ST3D_02])  -  
-		 (tensor[ST3D_12] * tensor[ST3D_12]);
-	a0 = - 	  (tensor[ST3D_00] * tensor[ST3D_11] * tensor[ST3D_22])  -  
-		2.0 * (tensor[ST3D_01] * tensor[ST3D_02] * tensor[ST3D_12]) +  
-			  (tensor[ST3D_00] * tensor[ST3D_12] * tensor[ST3D_12])  +  
-			  (tensor[ST3D_11] * tensor[ST3D_02] * tensor[ST3D_02])  +  
-			  (tensor[ST3D_22] * tensor[ST3D_01] * tensor[ST3D_01]);
-	
-	CubicSolver_OnlyRealRoots( a2, a1, a0, rootList );
-
-	eigenvectorList[0].eigenvalue = rootList[0];
-	eigenvectorList[1].eigenvalue = rootList[1];
-	eigenvectorList[2].eigenvalue = rootList[2];
-}
-/** Wrapper to calculate 2 and 3D eigenvectors */
-void SymmetricTensor_CalcAllEigenvectors( SymmetricTensor tensor, Dimension_Index dim, Eigenvector* eigenvectorList ) {
-	if ( dim == 2 ) 
-		SymmetricTensor_CalcAllEigenvectors2D( tensor, eigenvectorList );
-	else 
-		SymmetricTensor_CalcAllEigenvectors3D( tensor, eigenvectorList );
-}
-/** Calculates an eigenvector for a given 2D SymmetricTensor */
-Bool SymmetricTensor_CalcEigenvector2D( SymmetricTensor tensor, Eigenvector* eigenvector ) {
-	if ( fabs(tensor[ST2D_01]) > fabs(eigenvector->eigenvalue - tensor[ST2D_00]) ) {
-		eigenvector->vector[0] = 1.0;
-		eigenvector->vector[1] = (eigenvector->eigenvalue - tensor[ST2D_00])/tensor[ST2D_01];
-	}
-	else {
-		eigenvector->vector[0] = tensor[ST2D_01]/(eigenvector->eigenvalue - tensor[ST2D_00]);
-		eigenvector->vector[1] = 1.0;
-	}
-	StGermain_VectorNormalise( eigenvector->vector, 2 );
-
-	return True;
-}
-
-/** Calculates eigenvectors for 2D SymmetricTensor's only. This is guaranteed to
-return real eigenvectors and eigenvalues */
-void SymmetricTensor_CalcAllEigenvectors2D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
-	SymmetricTensor_CalcAllEigenvalues2D( tensor, eigenvectorList );
-	
-	if ( EQL(tensor[ST2D_01],0.0) ) {
-		/* [ a 0 ] */
-		/* [ 0 b ] */
-		if ( EQL(eigenvectorList[0].eigenvalue, tensor[ST2D_00]) ) {
-			eigenvectorList[0].vector[0] = 1.0;
-			eigenvectorList[0].vector[1] = 0.0;
-
-			eigenvectorList[1].vector[0] = 0.0;
-			eigenvectorList[1].vector[1] = 1.0;
-			return;
-		}
-		else {
-			eigenvectorList[0].vector[0] = 0.0;
-			eigenvectorList[0].vector[1] = 1.0;
-
-			eigenvectorList[1].vector[0] = 1.0;
-			eigenvectorList[1].vector[1] = 0.0;
-			return;
-		}
-	}
-
-	/* First Eigenvector */
-	SymmetricTensor_CalcEigenvector2D( tensor, &eigenvectorList[0] );
-	SymmetricTensor_CalcEigenvector2D( tensor, &eigenvectorList[1] );
-
-	/* Don't need to sort here because SymmetricTensor_CalcEigenvalues2D already has them sorted */
-}
-
-/** Calculates an eigenvector for a given 3D SymmetricTensor */
-Bool SymmetricTensor_CalcEigenvector3D( SymmetricTensor tensor, Eigenvector* eigenvector ) {
-	double A, B, C, d, e, f;
-
-	A = tensor[ST3D_00] - eigenvector->eigenvalue;
-	B = tensor[ST3D_11] - eigenvector->eigenvalue;
-	C = tensor[ST3D_22] - eigenvector->eigenvalue;
-	d = tensor[ST3D_01];
-	e = tensor[ST3D_02];
-	f = tensor[ST3D_12];
-
-	if ( ! EQL(B*e, f*d) && ! EQL( e, 0.0 ) ) {
-		eigenvector->vector[0] = 1.0;
-		eigenvector->vector[1] = (f*A - d*e)/(B*e - f*d);
-		eigenvector->vector[2] = (-A - d * eigenvector->vector[1] ) / e ;
-	}	
-	else if ( ! EQL(f*A, d*e) && ! EQL( e, 0.0 ) ) {
-		eigenvector->vector[0] = (B*e - f*d)/(f*A - d*e);
-		eigenvector->vector[1] = 1.0;
-		eigenvector->vector[2] = (-d - A*eigenvector->vector[0])/e;
-	}
-	else if ( ! EQL(d*d, B*A) && ! EQL( d, 0.0 ) ) {
-		eigenvector->vector[0] = (B*e - f*d)/(d*d - B*A);
-		eigenvector->vector[1] = (-e - A*eigenvector->vector[0])/d;
-		eigenvector->vector[2] = 1.0;
-	}
-	else {
-		return False;
-	}
-
-	StGermain_VectorNormalise( eigenvector->vector, 3 );
-
-	return True;
-}
-
-/** Calculates eigenvectors for 3D SymmetricTensor's only. This is guaranteed to
-return real eigenvectors and eigenvalues */
-void SymmetricTensor_CalcAllEigenvectors3D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
-	Dimension_Index dim_I;
-	Bool            result;
-
-	SymmetricTensor_CalcAllEigenvalues3D( tensor, eigenvectorList );
-
-	for ( dim_I = 0 ; dim_I < 3 ; dim_I++ ) {
-		result = SymmetricTensor_CalcEigenvector3D( tensor, &eigenvectorList[dim_I] );
-
-		if ( ! result ) {
-			SymmetricTensor_CalcAllEigenvectorsJacobi( tensor, 3, eigenvectorList );
-			return;
-		}
-	}
-
-	EigenvectorList_Sort( eigenvectorList, 3 );
-}
-
-
-void SymmetricTensor_CalcAllEigenvectorsJacobi( SymmetricTensor tensor, Dimension_Index dim, Eigenvector* eigenvectorList ){
-	double** matrix = Memory_Alloc_2DArray( double, dim, dim, (Name)"Matrix"  );
-		
-	SymmetricTensor_ToMatrix( tensor, dim, matrix);
-	Matrix_CalcAllEigenvectorsJacobi( matrix, dim, eigenvectorList );
-	Memory_Free( matrix );
-}
-
-/** Modified code from Numerical Recipies */
-/**
-Numerical Recipies in C
-Second Edition, 1992
-pp. 463-469
-*/
-/* Works for symmetric matrix */
-/* Order N^3 !! */
-/**
-Compared results with applet located at
-http://www.math.ubc.ca/~israel/applet/mcalc/matcalc.html
-*/
-#define ROTATE(a,i,j,k,l)\
-	g=a[i][j];\
-	h=a[k][l];\
-	a[i][j]=g-s*(h+g*tau);\
-	a[k][l]=h+s*(g-h*tau);
-
-#define ROTATE_EIGENVECTOR_LIST(eigenvectorList,i,j,k,l)\
-	g=eigenvectorList[i].vector[j];\
-	h=eigenvectorList[k].vector[l];\
-	eigenvectorList[i].vector[j]=g-s*(h+g*tau);\
-	eigenvectorList[k].vector[l]=h+s*(g-h*tau); 
-
-/** Calculate all Eigenvectors for a Symmetric Tensor converted to a Matrix 
-using the Jacobi Method. This method will ONLY work with symmetric real tensors.
-See: Numerical Recipies in C
-Second Edition, 1992
-pp. 463-469,
-
-*/
-void Matrix_CalcAllEigenvectorsJacobi(double **matrix, Index count, Eigenvector* eigenvectorList ) {
-	int j,i;
-        unsigned ip, iq;
-	double tresh,theta,tau,t,sum,s,h,g,c,*b,*z;
-
-	b = Memory_Alloc_Array( double, count, "b" );
-	z = Memory_Alloc_Array( double, count, "z" );
-
-	for ( ip = 0 ; ip < count ; ip++ ) {
-		/* Initialise Identity Matrix */
-		for ( iq = 0 ; iq < count ; iq++ ) eigenvectorList[ip].vector[iq]=0.0;
-		eigenvectorList[ip].vector[ip]=1.0;
-		
-		/* Initialise b and eigenvalues to diagonal of matrix */
-		b[ip] = eigenvectorList[ip].eigenvalue = matrix[ip][ip];
-		/* This vector will accumulate terms of the form ta_{pq} as in eq 11.1.14 of Numerical Recipies */
-		z[ip]=0.0;
-	}
-
-	for ( i = 1 ; i <= 50 ; i++ ) {
-
-		/* Sum the off-diagonal elements */
-		sum = 0.0;
-		for ( ip = 0 ; ip+1 < count ; ip++ ) {
-			for ( iq = ip+1 ; iq < count ; iq++ )
-				sum += fabs(matrix[ip][iq]);
-		}
-		/* The normal return, which relies on quadratic convergence to machine underflow */
-		if (sum == 0.0) 
-			break;
-
-		if (i < 4)
-			tresh = 0.2 * sum / (count*count);
-		else
-			tresh=0.0;
-
-		for ( ip = 0; ip+1 < count ; ip++ ) {
-			for ( iq = ip+1 ; iq < count ; iq++) {
-				g=100.0*fabs(matrix[ip][iq]);
-
-				/* After the first four sweeps, skip the rotation if the off-diagonal element is small */
-				if (i > 4 && (fabs(eigenvectorList[ip].eigenvalue)+g) == fabs(eigenvectorList[ip].eigenvalue)
-								&& (fabs(eigenvectorList[iq].eigenvalue)+g) == fabs(eigenvectorList[iq].eigenvalue))
-					matrix[ip][iq]=0.0;
-				else if (fabs(matrix[ip][iq]) > tresh) {
-					h=eigenvectorList[iq].eigenvalue - eigenvectorList[ip].eigenvalue;
-					if ((double)(fabs(h)+g) == (double)fabs(h))
-						t=(matrix[ip][iq])/h;	/* t = 1/(2theta) */
-					else {
-						theta=0.5*h/(matrix[ip][iq]);
-						t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
-						if (theta < 0.0) t = -t;
-					}
-					c=1.0/sqrt(1+t*t);
-					s=t*c;
-					tau=s/(1.0+c);
-					h=t*matrix[ip][iq];
-					z[ip] -= h;
-					z[iq] += h;
-					eigenvectorList[ip].eigenvalue -= h;
-					eigenvectorList[iq].eigenvalue += h;
-					matrix[ip][iq]=0.0;
-					for ( j = 0 ; j <= (int)(ip-1) ; j++ ) {
-						ROTATE(matrix,j,ip,j,iq)
-					}
-					for ( j = ip+1 ; j <= (int)(iq-1) ;j++ ) {
-						ROTATE(matrix,ip,j,j,iq)
-					}
-					for ( j = iq+1 ; j < (int)count ; j++ ) {
-						ROTATE(matrix,ip,j,iq,j)
-					}
-					for ( j = 0 ; j < (int)count ; j++ ) {
-						ROTATE_EIGENVECTOR_LIST(eigenvectorList,ip,j,iq,j)
-					}
-				}
-			}
-		}
-		for ( ip = 0 ; ip < count ; ip++ ) {
-			b[ip] += z[ip];
-			eigenvectorList[ip].eigenvalue =b[ip];
-			z[ip]=0.0;
-		}
-	}
-	
-	Memory_Free(z);
-	Memory_Free(b);
-	
-	EigenvectorList_Sort( eigenvectorList, count );
-}
-
-
-/** Sorts the eigenvectors according to the value of the eigenvalue - from smallest to greatest */
-void EigenvectorList_Sort( Eigenvector* eigenvectorList, Index count ) {
-	qsort( eigenvectorList, count, sizeof( Eigenvector ), _QsortEigenvalue );
-}
-/** Calculates the determinant of a matrix, independent of the ordering of the axis.*/
-double StGermain_MatrixDeterminant_AxisIndependent( double** matrix, Dimension_Index dim, Coord_Index A_axis, Coord_Index B_axis, Coord_Index C_axis ) {
-	switch (dim) {
-		case 1:
-			return matrix[A_axis][A_axis];
-		case 2:
-			return matrix[A_axis][A_axis]*matrix[B_axis][B_axis] - matrix[A_axis][B_axis]*matrix[B_axis][A_axis];
-		case 3:
-			return 
-				matrix[A_axis][A_axis] *
-					( matrix[B_axis][B_axis]*matrix[C_axis][C_axis] - matrix[B_axis][C_axis]*matrix[C_axis][B_axis] ) 
-				- matrix[A_axis][B_axis] *
-					( matrix[B_axis][A_axis]*matrix[C_axis][C_axis] - matrix[B_axis][C_axis]*matrix[C_axis][A_axis] )
-				+ matrix[A_axis][C_axis] *
-					( matrix[B_axis][A_axis]*matrix[C_axis][B_axis] - matrix[B_axis][B_axis]*matrix[C_axis][A_axis] );
-		default: {
-			Stream* error = Journal_Register( Error_Type , (Name)CURR_MODULE_NAME  );
-			Journal_Printf(error, "Function %s doesn't support dimension %d.\n", __func__, dim);
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}
-	return 0; /* Silly, but TAU-PDT complains otherwise */
-}
-
-/** Solves a cubic. See:  
-Eric W. Weisstein. "Cubic Formula." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CubicFormula.html */
-void CubicSolver_OnlyRealRoots( double a2, double a1, double a0, double* rootList ) {
-	double Q, R;
-	double D;
-	double theta;
-	double factor;
-
-	Q = (3.0 * a1 - a2 * a2)/9.0;                                   /* Equation 20 */
-	R = (9.0*a2*a1 - 27.0 * a0 - 2.0 * a2 * a2 * a2)/54.0;          /* Equation 21 */
-
-	/* Get Polynomial Discrimanent  (Equation 47) */
-	D = Q*Q*Q + R*R;
-		
-	if ( EQL( D, 0.0 ) ) {
-		double halfB;
-
-		if ( R < 0.0 ) 
-			halfB = - pow( -R, 1.0/3.0 );
-		else
-			halfB = pow( R, 1.0/3.0 );
-
-		rootList[0] = -a2/3.0 + 2.0 * halfB;
-		rootList[1] = rootList[2] = -a2/3.0 - halfB;
-		return;
-	}
-	Journal_Firewall( D <= 0.0, Journal_Register( Error_Type, (Name)"CubicSolver"  ),
-			"In func %s - Polynomial discrimanent %g is positive which means there are complex solutions.\nCannot solve equation x^3 + %.4f x^2 + %.4f x + %.4f = 0\n", __func__ , D, a2, a1, a0 );
-
-
-	theta = acos( R/sqrt( -Q*Q*Q ) )/3.0;
-	factor = 2.0 * sqrt( -Q );
-
-	rootList[0] = factor * cos( theta ) - a2/3.0;
-	rootList[1] = factor * cos( theta + 2.0*M_PI/3.0 ) - a2/3.0;
-	rootList[2] = factor * cos( theta + 4.0*M_PI/3.0 ) - a2/3.0;
-}
-
-
-/** Uses Cramer's rule to solve a system of linear equations 
- * see http://mathworld.wolfram.com/CramersRule.html */
-void TensorArray_SolveSystem( TensorArray tensorArray, double* solution, double* rightHandSide, Dimension_Index dim ) {
-	double determinant;
-	switch ( dim ) {
-		case 3: {
-			determinant = + tensorArray[ FT3D_00 ] *
-								( tensorArray[ FT3D_11 ] * tensorArray[ FT3D_22 ] -
-								  tensorArray[ FT3D_21 ] * tensorArray[ FT3D_12 ] )
-							- tensorArray[ FT3D_01 ] *
-								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_22 ] -
-								  tensorArray[ FT3D_12 ] * tensorArray[ FT3D_20 ] )
-							+ tensorArray[ FT3D_02 ] *
-								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_21 ] -
-								  tensorArray[ FT3D_11 ] * tensorArray[ FT3D_20 ] );
-
-			solution[ 0 ] = ( rightHandSide[0] * 
-								( tensorArray[ FT3D_11 ] * tensorArray[ FT3D_22 ] -
-								  tensorArray[ FT3D_21 ] * tensorArray[ FT3D_12 ] )
-							- tensorArray[ FT3D_01 ] *
-								( rightHandSide[1] * tensorArray[ FT3D_22 ] -
-								  tensorArray[ FT3D_12 ] * rightHandSide[2] )
-							+ tensorArray[ FT3D_02 ] *
-								( rightHandSide[1] * tensorArray[ FT3D_21 ] -
-								  tensorArray[ FT3D_11 ] * rightHandSide[2] ))/determinant;
-
-			solution[ 1 ] = ( tensorArray[ FT3D_00 ] *
-								( rightHandSide[1] * tensorArray[ FT3D_22 ] -
-								  rightHandSide[2] * tensorArray[ FT3D_12 ] )
-							- rightHandSide[0] * 
-								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_22 ] -
-								  tensorArray[ FT3D_12 ] * tensorArray[ FT3D_20 ] )
-							+ tensorArray[ FT3D_02 ] *
-								( tensorArray[ FT3D_10 ] * rightHandSide[2] -
-								  rightHandSide[1] * tensorArray[ FT3D_20 ] ))/determinant;
-
-			solution[ 2 ] = ( tensorArray[ FT3D_00 ] *
-								( tensorArray[ FT3D_11 ] * rightHandSide[2] -
-								  tensorArray[ FT3D_21 ] * rightHandSide[1] )
-							- tensorArray[ FT3D_01 ] *
-								( tensorArray[ FT3D_10 ] * rightHandSide[2] -
-								  rightHandSide[1] * tensorArray[ FT3D_20 ] )
-							+ rightHandSide[0] *
-								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_21 ] -
-								  tensorArray[ FT3D_11 ] * tensorArray[ FT3D_20 ] ))/determinant;
-			return;
-		}
-
-		case 2:
-			determinant = tensorArray[ FT2D_00 ] * tensorArray[ FT2D_11 ] 
-			            - tensorArray[ FT2D_10 ] * tensorArray[ FT2D_01 ];
-			
-			solution[ 0 ] = (rightHandSide[0] * tensorArray[ FT2D_11 ] - 
-				tensorArray[ FT2D_01 ] * rightHandSide[1])/determinant;
-			
-			solution[ 1 ] = (rightHandSide[1] * tensorArray[ FT2D_00 ] - 
-				tensorArray[ FT2D_10 ] * rightHandSide[0])/determinant;
-
-			return;
-		default: 
-			Journal_Firewall( 
-					False, 
-					Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ),
-					"Function %s - doesn't understand dim = %u\n", __func__, dim );
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/TensorMath.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/TensorMath.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1047 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TensorMath.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+#include "units.h"
+#include "types.h"
+#include "TensorMath.h"
+#include "VectorMath.h"
+#include "TrigMath.h"
+
+#include <math.h>
+#include <string.h>
+
+/** Mappings from enumerated types to arrays
+This gives the user the option to use:
+References instead of enumerated types.
+TensorMapFT2D[0][0] = FT2D_00
+etc.
+*/
+const unsigned int TensorMapFT2D[2][2] = {{FT2D_00, FT2D_01},{FT2D_10, FT2D_11}};
+
+/** See explanation for TensorMapFT2D */
+const unsigned int TensorMapST2D[2][2] = {{ST2D_00, ST2D_01},{ST2D_01, ST2D_11}};
+
+/** See explanation for TensorMapFT2D */
+const unsigned int TensorMapFT3D[3][3] ={{FT3D_00, FT3D_01, FT3D_02},{FT3D_10, FT3D_11, FT3D_12},{FT3D_20, FT3D_21, FT3D_22}};
+
+/** See explanation for TensorMapFT2D */
+const unsigned int TensorMapST3D[3][3] ={{ST3D_00, ST3D_01, ST3D_02},{ST3D_01, ST3D_11, ST3D_12},{ST3D_02, ST3D_12, ST3D_22}};
+
+/** This is a wrapper that converts a row/col index and a dimension
+into the correct number to reference the correct address of the value
+in the tensorArray function.
+*/
+int TensorArray_TensorMap(Dimension_Index row_I, Dimension_Index col_I, Dimension_Index dim) {
+	switch (dim) {
+		case 3: {
+			return TensorMapFT3D[ row_I ][ col_I ];
+		}
+		case 2: {
+			return TensorMapFT2D[ row_I ][ col_I ];
+		}
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+		
+	}
+	return 0;
+}
+
+/** This is a wrapper that converts a row/col index and a dimension
+into the correct number to reference the correct address of the value
+in the symmetricTensor function.
+*/
+int SymmetricTensor_TensorMap(Dimension_Index row_I, Dimension_Index col_I, Dimension_Index dim) {
+	switch (dim) {
+		case 3: {
+			return TensorMapST3D[ row_I ][ col_I ];
+		}
+		case 2: {
+			return TensorMapST2D[ row_I ][ col_I ];
+		}
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+		
+	}
+	return 0;
+}
+
+/** This sets the values from a nxn array into a TensorArray */ 
+void TensorArray_SetFromDoubleArray( TensorArray tensor, double** array, Dimension_Index dim ) {
+	Dimension_Index row_I, col_I;
+
+	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
+		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
+			tensor[ MAP_TENSOR( row_I, col_I, dim ) ] = array[ row_I ][ col_I ];
+		}
+	}
+}
+
+/** Converts a symmetric tensor to a full tensor */
+void StGermain_SymmetricTensor_ToTensorArray(SymmetricTensor symTensor, Dimension_Index dim, TensorArray fullTensor) {
+	switch (dim) {
+		case 3:
+			StGermain_SymmetricTensor_ToTensorArray3D(symTensor, fullTensor);
+			return;
+		case 2:
+			StGermain_SymmetricTensor_ToTensorArray2D(symTensor, fullTensor);
+			return;
+		default: {
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+}
+/** This function uses enumerated types to convert symmetric tensors to full tensors */
+void StGermain_SymmetricTensor_ToTensorArray2D(SymmetricTensor symTensor, TensorArray fullTensor) {
+
+	fullTensor[FT2D_00] = symTensor[ST2D_00];
+	fullTensor[FT2D_01] = symTensor[ST2D_01];
+	fullTensor[FT2D_10] = symTensor[ST2D_01];
+	fullTensor[FT2D_11] = symTensor[ST2D_11];
+	
+
+}
+
+/** This function uses enumerated types to convert symmetric tensors to full tensors */
+void StGermain_SymmetricTensor_ToTensorArray3D(SymmetricTensor symTensor, TensorArray fullTensor) {
+	/*Using enumerated types to convert symmetric tensors to full tensors */
+	fullTensor[FT3D_00] = symTensor[ST3D_00];
+	fullTensor[FT3D_01] = symTensor[ST3D_01];
+	fullTensor[FT3D_02] = symTensor[ST3D_02];
+	fullTensor[FT3D_10] = symTensor[ST3D_01];
+	fullTensor[FT3D_11] = symTensor[ST3D_11];
+	fullTensor[FT3D_12] = symTensor[ST3D_12];
+	fullTensor[FT3D_20] = symTensor[ST3D_02];
+	fullTensor[FT3D_21] = symTensor[ST3D_12];
+	fullTensor[FT3D_22] = symTensor[ST3D_22];
+	
+
+}
+
+/** This function converts TensorArray's to square Matrixes */
+void TensorArray_ToMatrix( TensorArray tensor, Dimension_Index dim, double** matrix ) {
+	if (dim == 2) {
+		matrix[0][0] = tensor[FT2D_00] ; matrix[0][1] = tensor[FT2D_01] ;
+		matrix[1][0] = tensor[FT2D_10] ; matrix[1][1] = tensor[FT2D_11] ;
+	}
+	else if (dim == 3) {
+		matrix[0][0] = tensor[FT3D_00];	matrix[0][1] = tensor[FT3D_01];	matrix[0][2] = tensor[FT3D_02];
+		matrix[1][0] = tensor[FT3D_10];	matrix[1][1] = tensor[FT3D_11];	matrix[1][2] = tensor[FT3D_12];
+		matrix[2][0] = tensor[FT3D_20];	matrix[2][1] = tensor[FT3D_21];	matrix[2][2] = tensor[FT3D_22];
+	}
+	else {
+		Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+	}
+}
+
+
+void ZeroMatrix( double** matrix, Index rows, Index cols ) {
+	Index count_I;
+	for( count_I = 0 ; count_I < rows ; count_I++ ) {
+		memset( matrix[ count_I ], 0, (cols*sizeof(double)) );
+	}
+}
+
+
+/** This function extracts out the antiSymmetric part of a tensor Array
+v_{ij} = 0.5 * ( u_{ij} - u_{ji} )
+See http://mathworld.wolfram.com/AntisymmetricPart.html */
+void TensorArray_GetAntisymmetricPart( TensorArray tensor, Dimension_Index dim, TensorArray antiSymmetric ) {
+	switch (dim) {
+		case 3:
+			/* v_{xz} = 0.5*( u_{xz} - u_{zx} ) */
+			antiSymmetric[ TensorMapFT3D[0][2] ] = 0.5 * (tensor[ TensorMapFT3D[0][2] ] - 
+							tensor[ TensorMapFT3D[2][0] ] );
+			
+			/* v_{yz} = 0.5*( u_{yz} - u_{zy} ) */
+			antiSymmetric[ TensorMapFT3D[1][2] ] = 0.5 * (tensor[ TensorMapFT3D[1][2] ] - 
+							tensor[ TensorMapFT3D[2][1] ] );
+			
+			/* v_{zx} = 0.5*( u_{zx} - u_{xz} ) */
+			antiSymmetric[ TensorMapFT3D[2][0] ] = - antiSymmetric[ TensorMapFT3D[0][2] ];
+
+			/* v_{zy} = 0.5*( u_{zy} - u_{yz} ) */	
+			antiSymmetric[ TensorMapFT3D[2][1] ] = - antiSymmetric[ TensorMapFT3D[1][2] ];
+
+			/* v_{zz} = 0.5*( u_{zz} - u_{zz} ) */
+			antiSymmetric[ TensorMapFT3D[2][2] ] = 0.0;
+
+			/* v_{xy} = 0.5*( u_{xy} - u_{yx} ) */
+			antiSymmetric[ TensorMapFT3D[0][1] ] = 0.5 * (tensor[ TensorMapFT3D[0][1] ] - 
+						tensor[ TensorMapFT3D[1][0] ] );
+
+			/* v_{yx} = 0.5*( u_{yx} - u_{xy} ) */
+			antiSymmetric[ TensorMapFT3D[1][0] ] = - antiSymmetric[ TensorMapFT3D[0][1] ];
+
+			/* v_{yy} = 0.5*( u_{yy} - u_{yy} ) */
+			antiSymmetric[ TensorMapFT3D[1][1] ] = 0.0;
+			
+			/* v_{xx} = 0.5*( u_{xx} - u_{xx} ) */
+			antiSymmetric[ TensorMapFT3D[0][0] ] = 0.0;
+			return;
+		case 2:		
+			/* v_{xy} = 0.5*( u_{xy} - u_{yx} ) */
+			antiSymmetric[ TensorMapFT2D[0][1] ] = 0.5 * (tensor[ TensorMapFT2D[0][1] ] - 
+						tensor[ TensorMapFT2D[1][0] ] );
+
+			/* v_{yx} = 0.5*( u_{yx} - u_{xy} ) */
+			antiSymmetric[ TensorMapFT2D[1][0] ] = - antiSymmetric[ TensorMapFT2D[0][1] ];
+
+			/* v_{yy} = 0.5*( u_{yy} - u_{yy} ) */
+			antiSymmetric[ TensorMapFT2D[1][1] ] = 0.0;
+			
+			/* v_{xx} = 0.5*( u_{xx} - u_{xx} ) */
+			antiSymmetric[ TensorMapFT2D[0][0] ] = 0.0;
+			return;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot store tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+}
+
+/** This function calculates the symmetric part of a TensorArray and returns
+it in a SymmetricTensor: 
+v_{ij} = 0.5 * ( u_{ij} + u_{ji} ) 
+see http://mathworld.wolfram.com/SymmetricPart.html 
+It can also be used to convert a symmetric TensorArray to a SymmetricTensor
+if the TensorArray is guaranteed to be Symmetric. (It has no type checking)*/
+void TensorArray_GetSymmetricPart( TensorArray tensor, Dimension_Index dim, SymmetricTensor symmetricTensor ) {
+	switch (dim) {
+		case 2:
+			/* Diagonal Terms */
+			/* v_{xx} = 0.5*( u_{xx} + u_{xx} ) */
+			/* v_{yy} = 0.5*( u_{yy} + u_{yy} ) */
+			symmetricTensor[ TensorMapST2D[0][0] ] = tensor[ TensorMapFT2D[0][0] ]; 
+			symmetricTensor[ TensorMapST2D[1][1] ] = tensor[ TensorMapFT2D[1][1] ]; 
+			
+			/* Off-diagonal Term */
+			/* v_{xy} = 0.5*( u_{xy} + u_{yx} ) */
+			symmetricTensor[ TensorMapST2D[0][1] ] = 
+				0.5 * (tensor[ TensorMapFT2D[0][1] ] + tensor[ TensorMapFT2D[1][0] ]); 
+			return;
+		case 3:
+			/* Diagonal Terms */
+			/* v_{xx} = 0.5*( u_{xx} + u_{xx} ) */
+			/* v_{yy} = 0.5*( u_{yy} + u_{yy} ) */
+			/* v_{zz} = 0.5*( u_{zz} + u_{zz} ) */
+			symmetricTensor[ TensorMapST3D[0][0] ] = tensor[ TensorMapFT3D[0][0] ]; 
+			symmetricTensor[ TensorMapST3D[1][1] ] = tensor[ TensorMapFT3D[1][1] ]; 
+			symmetricTensor[ TensorMapST3D[2][2] ] = tensor[ TensorMapFT3D[2][2] ]; 
+			
+			/* Off-diagonal Terms */
+			/* v_{xy} = 0.5*( u_{xy} + u_{yx} ) */
+			/* v_{xz} = 0.5*( u_{xz} + u_{zx} ) */
+			/* v_{yz} = 0.5*( u_{yz} + u_{zy} ) */
+			symmetricTensor[ TensorMapST3D[0][1] ] =
+				0.5 * (tensor[ TensorMapFT3D[0][1] ] + tensor[ TensorMapFT3D[1][0] ]); 
+		
+			symmetricTensor[ TensorMapST3D[0][2] ] =
+				0.5 * (tensor[ TensorMapFT3D[0][2] ] + tensor[ TensorMapFT3D[2][0] ]); 
+		
+			symmetricTensor[ TensorMapST3D[1][2] ] =
+				0.5 * (tensor[ TensorMapFT3D[1][2] ] + tensor[ TensorMapFT3D[2][1] ]); 
+			return;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot store tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+}
+
+
+/** This function calculates the trace of a tenorArray 
+trace = u_{ii} */
+void TensorArray_GetTrace( TensorArray tensor, Dimension_Index dim, double *trace ) {
+	switch (dim) {
+	  case 1:
+		/* Sum the diagonal terms */
+		*trace = 	tensor[0];
+		break;
+	  case 2:
+		/* Sum the diagonal terms */
+		/*
+		*trace = 	tensor[ MAP_2D_TENSOR( 0, 0 ) ]
+		+ 	tensor[ MAP_2D_TENSOR( 1, 1 ) ];
+		*/
+		*trace = tensor[FT2D_00] + tensor[FT2D_11];
+		break;
+	  case 3:
+		/* Sum the diagonal terms */
+		/*
+		*trace = 	tensor[ MAP_3D_TENSOR( 0, 0 ) ]
+				+	tensor[ MAP_3D_TENSOR( 1, 1 ) ]
+				+	tensor[ MAP_3D_TENSOR( 2, 2 ) ];
+		*/
+		*trace = tensor[FT3D_00] + tensor[FT3D_11] + tensor[FT3D_22];
+		break;
+		  default:{
+		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot compute trace for tensor in dimension %d (in %s) since dim < 1.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+			break;
+		}
+	}
+}
+
+/** This function will calculate the trace of a symmetric tensor type */
+void SymmetricTensor_GetTrace( SymmetricTensor symmTensor, Dimension_Index dim, double *trace ) {
+	switch (dim) {
+	  case 1:
+		*trace = symmTensor[0];
+		break;
+	  case 2:
+		*trace = symmTensor[ST2D_00] + symmTensor[ST2D_11];
+		break;
+	  case 3:
+		*trace = symmTensor[ST3D_00] + symmTensor[ST3D_11] + symmTensor[ST3D_22];
+		break;
+	  default:{
+		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+		Journal_Printf( error, "Cannot compute trace for symmetric tensor in dimension %d (in %s) since dim is not in the range [1, 3].\n", dim, __func__);
+		Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+			"In func '%s' don't understand dim = %u\n", __func__, dim );
+		break;
+		  }
+	}
+
+}
+
+/** This function prints an unnamed tensorArray */
+void Journal_PrintTensorArray_Unnamed( Stream* stream, TensorArray tensor, Dimension_Index dim ) {
+	Dimension_Index row_I, col_I;
+
+	/* For efficency - Check if stream is enabled */
+	if (!Stream_IsEnable(stream)) return;
+
+	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
+		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
+			Journal_Printf( stream, "%7.5g     ", tensor[ MAP_TENSOR( row_I, col_I, dim ) ] );
+		}
+		Journal_Printf( stream, "\n" );
+	}
+}
+
+/** This function prints an unnamed square 2-D Array */
+void Journal_PrintSquareArray_Unnamed( Stream* stream, double** array, Dimension_Index dim ) {
+	Dimension_Index row_I, col_I;
+
+	/* For efficency - Check if stream is enabled */
+	if (!Stream_IsEnable(stream)) return;
+
+	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
+		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
+			Journal_Printf( stream, "%7.5g     ", array[row_I][col_I] );
+		}
+		Journal_Printf( stream, "\n" );
+	}
+}
+
+/** This function prints an unnamed SymmetricTensor */
+void Journal_PrintSymmetricTensor_Unnamed( Stream* stream, SymmetricTensor tensor, Dimension_Index dim ) {
+	Dimension_Index row_I, col_I;
+	/* For efficency - Check if stream is enabled */
+	if (!Stream_IsEnable(stream)) return;
+
+	for ( row_I = 0 ; row_I < dim ; row_I++ ) {
+		for ( col_I = 0 ; col_I < dim ; col_I++ ) {
+			Journal_Printf( stream, "%7.5g     ", tensor[ MAP_SYMM_TENSOR( row_I, col_I, dim ) ] );
+		}
+		Journal_Printf( stream, "\n" );
+	}
+}
+
+/** This function calculates the second Invariant of a TensorArray: 
+u = \sqrt{ 0.5 u_{ij} u_{ij} } */
+double TensorArray_2ndInvariant( TensorArray tensor, Dimension_Index dim ) {
+	double invariant = 0.0;
+	switch( dim ) {
+		case 3:
+			invariant += 
+				tensor[4] * tensor[4] +
+				tensor[5] * tensor[5] +
+				tensor[6] * tensor[6] +
+				tensor[7] * tensor[7] +
+				tensor[8] * tensor[8] ;
+		case 2:
+			invariant += 
+				tensor[1] * tensor[1] +
+				tensor[2] * tensor[2] +
+				tensor[3] * tensor[3] ;
+		case 1:
+			invariant += tensor[0] * tensor[0];
+			break;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+	return sqrt( 0.5 * invariant );
+}
+
+/** This function calculates the second Invariant of a SymmetricTensor:  
+u = \sqrt{ 0.5 u_{ij} u_{ij} } */
+double SymmetricTensor_2ndInvariant( SymmetricTensor tensor, Dimension_Index dim ) {
+	double invariant = 0.0;
+	
+	switch( dim ) {
+		case 3:
+			invariant = 
+				0.5 * ( tensor[ TensorMapST3D[0][0] ] * tensor[ TensorMapST3D[0][0] ]   +
+				        tensor[ TensorMapST3D[1][1] ] * tensor[ TensorMapST3D[1][1] ]   +
+				        tensor[ TensorMapST3D[2][2] ] * tensor[ TensorMapST3D[2][2] ] ) +
+				
+				tensor[ TensorMapST3D[0][1] ] * tensor[ TensorMapST3D[1][0] ] +
+				tensor[ TensorMapST3D[0][2] ] * tensor[ TensorMapST3D[2][0] ] +
+				tensor[ TensorMapST3D[1][2] ] * tensor[ TensorMapST3D[2][1] ] ;
+			break;
+		case 2:
+			invariant = 
+				0.5 * ( tensor[ TensorMapST2D[0][0] ] * tensor[ TensorMapST2D[0][0] ]   +
+				        tensor[ TensorMapST2D[1][1] ] * tensor[ TensorMapST2D[1][1] ] ) +
+				tensor[ TensorMapST2D[0][1] ] * tensor[ TensorMapST2D[1][0] ] ;
+			break;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+	return sqrt( invariant );
+}
+
+
+/** a_i * u_{ij} * b_j */
+double TensorArray_MultiplyByVectors( TensorArray tensor, double* a, double* b, Dimension_Index dim ) {
+	double result = 0.0;
+
+	switch( dim ) {
+		case 3:
+			result = 
+				a[0] * tensor[ FT3D_00 ] * b[0] +
+				a[0] * tensor[ FT3D_01 ] * b[1] +
+				a[0] * tensor[ FT3D_02 ] * b[2] +
+
+				a[1] * tensor[ FT3D_10 ] * b[0] +
+				a[1] * tensor[ FT3D_11 ] * b[1] +
+				a[1] * tensor[ FT3D_12 ] * b[2] +
+
+				a[2] * tensor[ FT3D_20 ] * b[0] +
+				a[2] * tensor[ FT3D_21 ] * b[1] +
+				a[2] * tensor[ FT3D_22 ] * b[2] ;
+			break;
+		case 2:
+			result = 
+				a[0] * tensor[ FT2D_00 ] * b[0] +
+				a[0] * tensor[ FT2D_01 ] * b[1] +
+
+				a[1] * tensor[ FT2D_10 ] * b[0] +
+				a[1] * tensor[ FT2D_11 ] * b[1] ;
+			break;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+	return result;
+}
+
+/** returns u_{ij} * a_j */
+void SymmetricTensor_ApplyOnVector( SymmetricTensor tensor, double* vector, Dimension_Index dim, XYZ result ) {
+	switch( dim ) {
+		case 3:
+			result[0] = 
+				tensor[ TensorMapST3D[0][0] ] * vector[0] +
+				tensor[ TensorMapST3D[0][1] ] * vector[1] +
+				tensor[ TensorMapST3D[0][2] ] * vector[2] ;
+
+			result[1] = 	
+				tensor[ TensorMapST3D[1][0] ] * vector[0] +
+				tensor[ TensorMapST3D[1][1] ] * vector[1] +
+				tensor[ TensorMapST3D[1][2] ] * vector[2] ;
+
+			result[2] = 	
+				tensor[ TensorMapST3D[2][0] ] * vector[0] +
+				tensor[ TensorMapST3D[2][1] ] * vector[1] +
+				tensor[ TensorMapST3D[2][2] ] * vector[2] ;
+			break;
+		case 2:
+			result[0] = 
+				tensor[ TensorMapST2D[0][0] ] * vector[0] +
+				tensor[ TensorMapST2D[0][1] ] * vector[1] ;
+
+			result[1] = 
+				tensor[ TensorMapST2D[1][0] ] * vector[0] +
+				tensor[ TensorMapST2D[1][1] ] * vector[1] ;
+			break;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+}
+
+
+/** returns a_i * u_{ij} * b_j */
+double SymmetricTensor_MultiplyByVectors( SymmetricTensor tensor, double* a, double* b, Dimension_Index dim ) {
+	double result = 0.0;
+
+	switch( dim ) {
+		case 3:
+			result = 
+				a[0] * tensor[ TensorMapST3D[0][0] ] * b[0] +
+				a[0] * tensor[ TensorMapST3D[0][1] ] * b[1] +
+				a[0] * tensor[ TensorMapST3D[0][2] ] * b[2] +
+
+				a[1] * tensor[ TensorMapST3D[1][0] ] * b[0] +
+				a[1] * tensor[ TensorMapST3D[1][1] ] * b[1] +
+				a[1] * tensor[ TensorMapST3D[1][2] ] * b[2] +
+
+				a[2] * tensor[ TensorMapST3D[2][0] ] * b[0] +
+				a[2] * tensor[ TensorMapST3D[2][1] ] * b[1] +
+				a[2] * tensor[ TensorMapST3D[2][2] ] * b[2] ;
+			break;
+		case 2:
+			result = 
+				a[0] * tensor[ TensorMapST2D[0][0] ] * b[0] +
+				a[0] * tensor[ TensorMapST2D[0][1] ] * b[1] +
+
+				a[1] * tensor[ TensorMapST2D[1][0] ] * b[0] +
+				a[1] * tensor[ TensorMapST2D[1][1] ] * b[1] ;
+			break;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMath"  );
+			Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+	return result;
+}
+
+void SymmetricTensor_ToMatrix( SymmetricTensor tensor, Dimension_Index dim, double** matrix ) {
+	if (dim == 2) {
+		matrix[0][0] = tensor[ST2D_00] ; matrix[0][1] = tensor[ST2D_01] ;
+		matrix[1][0] = tensor[ST2D_01] ; matrix[1][1] = tensor[ST2D_11] ;
+	}
+	else if (dim == 3) {
+		matrix[0][0] = tensor[ST3D_00];	matrix[0][1] = tensor[ST3D_01];	matrix[0][2] = tensor[ST3D_02];
+		matrix[1][0] = tensor[ST3D_01];	matrix[1][1] = tensor[ST3D_11];	matrix[1][2] = tensor[ST3D_12];
+		matrix[2][0] = tensor[ST3D_02];	matrix[2][1] = tensor[ST3D_12];	matrix[2][2] = tensor[ST3D_22];
+	}
+	else {
+		Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+	}
+}
+		
+void TensorArray_Zero( TensorArray tensor ) {
+	memset( tensor, 0, sizeof(TensorArray) );
+}
+void SymmetricTensor_Zero( SymmetricTensor tensor ) {
+	memset( tensor, 0, sizeof(SymmetricTensor) );
+}
+
+
+int _QsortEigenvalue( const void* _a, const void* _b ) {
+	Eigenvector* a = (Eigenvector*) _a;
+	Eigenvector* b = (Eigenvector*) _b;
+
+	if ( a->eigenvalue > b->eigenvalue )
+		return 1;
+	else
+		return -1;
+}
+
+
+void SymmetricTensor_CalcAllEigenvalues( SymmetricTensor tensor, Dimension_Index dim, Eigenvector* eigenvectorList ) {
+	if ( dim == 2 ) 
+		SymmetricTensor_CalcAllEigenvalues2D( tensor, eigenvectorList );
+	else 
+		SymmetricTensor_CalcAllEigenvalues3D( tensor, eigenvectorList );
+}
+
+/* 
+For a symmetric 2D Matrix, Eigenvalues are given by: 
+\lambda = \frac{u_{00} + u_{11}}{2} \pm \sqrt{ \left(\frac{u_{00} - u_{11}}{2}\right)^2 + u_{01} }
+*/
+void SymmetricTensor_CalcAllEigenvalues2D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
+	double descriminantRoot, average;
+	
+	descriminantRoot = sqrt( 0.25 * (tensor[ST2D_00] - tensor[ST2D_11]) * 
+				(tensor[ST2D_00] - tensor[ST2D_11]) + tensor[ST2D_01] * tensor[ST2D_01] );
+
+	average = 0.5 * (tensor[ST2D_00] + tensor[ST2D_11]);
+
+	eigenvectorList[0].eigenvalue = average - descriminantRoot;
+	eigenvectorList[1].eigenvalue = average + descriminantRoot;
+}
+
+#define EQL(A,B)    (fabs( (A) - (B) ) < 1.0e-8) 
+/**
+Calculates the roots of the characteristic polynomial given by
+det( [tensor] - \lambda [I] ) = 0
+1.0 \lambda^3 + a2 \lambda^2 + a1 \lambda + a0 = 0
+Results compared with applet located at http://www.math.ubc.ca/~israel/applet/mcalc/matcalc.html */
+void SymmetricTensor_CalcAllEigenvalues3D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
+	double a2, a1, a0;
+	double rootList[3];
+
+	/*
+	a3 = 1.0
+	a2 = - tensor_xx - tensor_yy - tensor_zz
+	a1 = tensor_xx * tensor_yy  +  tensor_xx * tensor_zz  +  
+		tensor_yy * tensor_zz  -  tensor_xy^2  -  tensor_xz^2  - tensor_yz^2 
+	a0 = -tensor_xx * tensor_yy * tensor_zz  - 
+		2 * tensor_xy * tensor_xz * tensor_yz  + 
+		tensor_xx * tensor_yz^2  +  tensor_yy * tensor_xz^2  +  tensor_zz * tensor_xy^2
+	*/
+
+	a2 = - tensor[ST3D_00] - tensor[ST3D_11] - tensor[ST3D_22];
+	a1 = (tensor[ST3D_00] * tensor[ST3D_11])  +  
+		 (tensor[ST3D_00] * tensor[ST3D_22])  +  
+		 (tensor[ST3D_11] * tensor[ST3D_22])  -  
+		 (tensor[ST3D_01] * tensor[ST3D_01])  -  
+		 (tensor[ST3D_02] * tensor[ST3D_02])  -  
+		 (tensor[ST3D_12] * tensor[ST3D_12]);
+	a0 = - 	  (tensor[ST3D_00] * tensor[ST3D_11] * tensor[ST3D_22])  -  
+		2.0 * (tensor[ST3D_01] * tensor[ST3D_02] * tensor[ST3D_12]) +  
+			  (tensor[ST3D_00] * tensor[ST3D_12] * tensor[ST3D_12])  +  
+			  (tensor[ST3D_11] * tensor[ST3D_02] * tensor[ST3D_02])  +  
+			  (tensor[ST3D_22] * tensor[ST3D_01] * tensor[ST3D_01]);
+	
+	CubicSolver_OnlyRealRoots( a2, a1, a0, rootList );
+
+	eigenvectorList[0].eigenvalue = rootList[0];
+	eigenvectorList[1].eigenvalue = rootList[1];
+	eigenvectorList[2].eigenvalue = rootList[2];
+}
+/** Wrapper to calculate 2 and 3D eigenvectors */
+void SymmetricTensor_CalcAllEigenvectors( SymmetricTensor tensor, Dimension_Index dim, Eigenvector* eigenvectorList ) {
+	if ( dim == 2 ) 
+		SymmetricTensor_CalcAllEigenvectors2D( tensor, eigenvectorList );
+	else 
+		SymmetricTensor_CalcAllEigenvectors3D( tensor, eigenvectorList );
+}
+/** Calculates an eigenvector for a given 2D SymmetricTensor */
+Bool SymmetricTensor_CalcEigenvector2D( SymmetricTensor tensor, Eigenvector* eigenvector ) {
+	if ( fabs(tensor[ST2D_01]) > fabs(eigenvector->eigenvalue - tensor[ST2D_00]) ) {
+		eigenvector->vector[0] = 1.0;
+		eigenvector->vector[1] = (eigenvector->eigenvalue - tensor[ST2D_00])/tensor[ST2D_01];
+	}
+	else {
+		eigenvector->vector[0] = tensor[ST2D_01]/(eigenvector->eigenvalue - tensor[ST2D_00]);
+		eigenvector->vector[1] = 1.0;
+	}
+	StGermain_VectorNormalise( eigenvector->vector, 2 );
+
+	return True;
+}
+
+/** Calculates eigenvectors for 2D SymmetricTensor's only. This is guaranteed to
+return real eigenvectors and eigenvalues */
+void SymmetricTensor_CalcAllEigenvectors2D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
+	SymmetricTensor_CalcAllEigenvalues2D( tensor, eigenvectorList );
+	
+	if ( EQL(tensor[ST2D_01],0.0) ) {
+		/* [ a 0 ] */
+		/* [ 0 b ] */
+		if ( EQL(eigenvectorList[0].eigenvalue, tensor[ST2D_00]) ) {
+			eigenvectorList[0].vector[0] = 1.0;
+			eigenvectorList[0].vector[1] = 0.0;
+
+			eigenvectorList[1].vector[0] = 0.0;
+			eigenvectorList[1].vector[1] = 1.0;
+			return;
+		}
+		else {
+			eigenvectorList[0].vector[0] = 0.0;
+			eigenvectorList[0].vector[1] = 1.0;
+
+			eigenvectorList[1].vector[0] = 1.0;
+			eigenvectorList[1].vector[1] = 0.0;
+			return;
+		}
+	}
+
+	/* First Eigenvector */
+	SymmetricTensor_CalcEigenvector2D( tensor, &eigenvectorList[0] );
+	SymmetricTensor_CalcEigenvector2D( tensor, &eigenvectorList[1] );
+
+	/* Don't need to sort here because SymmetricTensor_CalcEigenvalues2D already has them sorted */
+}
+
+/** Calculates an eigenvector for a given 3D SymmetricTensor */
+Bool SymmetricTensor_CalcEigenvector3D( SymmetricTensor tensor, Eigenvector* eigenvector ) {
+	double A, B, C, d, e, f;
+
+	A = tensor[ST3D_00] - eigenvector->eigenvalue;
+	B = tensor[ST3D_11] - eigenvector->eigenvalue;
+	C = tensor[ST3D_22] - eigenvector->eigenvalue;
+	d = tensor[ST3D_01];
+	e = tensor[ST3D_02];
+	f = tensor[ST3D_12];
+
+	if ( ! EQL(B*e, f*d) && ! EQL( e, 0.0 ) ) {
+		eigenvector->vector[0] = 1.0;
+		eigenvector->vector[1] = (f*A - d*e)/(B*e - f*d);
+		eigenvector->vector[2] = (-A - d * eigenvector->vector[1] ) / e ;
+	}	
+	else if ( ! EQL(f*A, d*e) && ! EQL( e, 0.0 ) ) {
+		eigenvector->vector[0] = (B*e - f*d)/(f*A - d*e);
+		eigenvector->vector[1] = 1.0;
+		eigenvector->vector[2] = (-d - A*eigenvector->vector[0])/e;
+	}
+	else if ( ! EQL(d*d, B*A) && ! EQL( d, 0.0 ) ) {
+		eigenvector->vector[0] = (B*e - f*d)/(d*d - B*A);
+		eigenvector->vector[1] = (-e - A*eigenvector->vector[0])/d;
+		eigenvector->vector[2] = 1.0;
+	}
+	else {
+		return False;
+	}
+
+	StGermain_VectorNormalise( eigenvector->vector, 3 );
+
+	return True;
+}
+
+/** Calculates eigenvectors for 3D SymmetricTensor's only. This is guaranteed to
+return real eigenvectors and eigenvalues */
+void SymmetricTensor_CalcAllEigenvectors3D( SymmetricTensor tensor, Eigenvector* eigenvectorList ) {
+	Dimension_Index dim_I;
+	Bool            result;
+
+	SymmetricTensor_CalcAllEigenvalues3D( tensor, eigenvectorList );
+
+	for ( dim_I = 0 ; dim_I < 3 ; dim_I++ ) {
+		result = SymmetricTensor_CalcEigenvector3D( tensor, &eigenvectorList[dim_I] );
+
+		if ( ! result ) {
+			SymmetricTensor_CalcAllEigenvectorsJacobi( tensor, 3, eigenvectorList );
+			return;
+		}
+	}
+
+	EigenvectorList_Sort( eigenvectorList, 3 );
+}
+
+
+void SymmetricTensor_CalcAllEigenvectorsJacobi( SymmetricTensor tensor, Dimension_Index dim, Eigenvector* eigenvectorList ){
+	double** matrix = Memory_Alloc_2DArray( double, dim, dim, (Name)"Matrix"  );
+		
+	SymmetricTensor_ToMatrix( tensor, dim, matrix);
+	Matrix_CalcAllEigenvectorsJacobi( matrix, dim, eigenvectorList );
+	Memory_Free( matrix );
+}
+
+/** Modified code from Numerical Recipies */
+/**
+Numerical Recipies in C
+Second Edition, 1992
+pp. 463-469
+*/
+/* Works for symmetric matrix */
+/* Order N^3 !! */
+/**
+Compared results with applet located at
+http://www.math.ubc.ca/~israel/applet/mcalc/matcalc.html
+*/
+#define ROTATE(a,i,j,k,l)\
+	g=a[i][j];\
+	h=a[k][l];\
+	a[i][j]=g-s*(h+g*tau);\
+	a[k][l]=h+s*(g-h*tau);
+
+#define ROTATE_EIGENVECTOR_LIST(eigenvectorList,i,j,k,l)\
+	g=eigenvectorList[i].vector[j];\
+	h=eigenvectorList[k].vector[l];\
+	eigenvectorList[i].vector[j]=g-s*(h+g*tau);\
+	eigenvectorList[k].vector[l]=h+s*(g-h*tau); 
+
+/** Calculate all Eigenvectors for a Symmetric Tensor converted to a Matrix 
+using the Jacobi Method. This method will ONLY work with symmetric real tensors.
+See: Numerical Recipies in C
+Second Edition, 1992
+pp. 463-469,
+
+*/
+void Matrix_CalcAllEigenvectorsJacobi(double **matrix, Index count, Eigenvector* eigenvectorList ) {
+	int j,i;
+        unsigned ip, iq;
+	double tresh,theta,tau,t,sum,s,h,g,c,*b,*z;
+
+	b = Memory_Alloc_Array( double, count, "b" );
+	z = Memory_Alloc_Array( double, count, "z" );
+
+	for ( ip = 0 ; ip < count ; ip++ ) {
+		/* Initialise Identity Matrix */
+		for ( iq = 0 ; iq < count ; iq++ ) eigenvectorList[ip].vector[iq]=0.0;
+		eigenvectorList[ip].vector[ip]=1.0;
+		
+		/* Initialise b and eigenvalues to diagonal of matrix */
+		b[ip] = eigenvectorList[ip].eigenvalue = matrix[ip][ip];
+		/* This vector will accumulate terms of the form ta_{pq} as in eq 11.1.14 of Numerical Recipies */
+		z[ip]=0.0;
+	}
+
+	for ( i = 1 ; i <= 50 ; i++ ) {
+
+		/* Sum the off-diagonal elements */
+		sum = 0.0;
+		for ( ip = 0 ; ip+1 < count ; ip++ ) {
+			for ( iq = ip+1 ; iq < count ; iq++ )
+				sum += fabs(matrix[ip][iq]);
+		}
+		/* The normal return, which relies on quadratic convergence to machine underflow */
+		if (sum == 0.0) 
+			break;
+
+		if (i < 4)
+			tresh = 0.2 * sum / (count*count);
+		else
+			tresh=0.0;
+
+		for ( ip = 0; ip+1 < count ; ip++ ) {
+			for ( iq = ip+1 ; iq < count ; iq++) {
+				g=100.0*fabs(matrix[ip][iq]);
+
+				/* After the first four sweeps, skip the rotation if the off-diagonal element is small */
+				if (i > 4 && (fabs(eigenvectorList[ip].eigenvalue)+g) == fabs(eigenvectorList[ip].eigenvalue)
+								&& (fabs(eigenvectorList[iq].eigenvalue)+g) == fabs(eigenvectorList[iq].eigenvalue))
+					matrix[ip][iq]=0.0;
+				else if (fabs(matrix[ip][iq]) > tresh) {
+					h=eigenvectorList[iq].eigenvalue - eigenvectorList[ip].eigenvalue;
+					if ((double)(fabs(h)+g) == (double)fabs(h))
+						t=(matrix[ip][iq])/h;	/* t = 1/(2theta) */
+					else {
+						theta=0.5*h/(matrix[ip][iq]);
+						t=1.0/(fabs(theta)+sqrt(1.0+theta*theta));
+						if (theta < 0.0) t = -t;
+					}
+					c=1.0/sqrt(1+t*t);
+					s=t*c;
+					tau=s/(1.0+c);
+					h=t*matrix[ip][iq];
+					z[ip] -= h;
+					z[iq] += h;
+					eigenvectorList[ip].eigenvalue -= h;
+					eigenvectorList[iq].eigenvalue += h;
+					matrix[ip][iq]=0.0;
+					for ( j = 0 ; j <= (int)(ip-1) ; j++ ) {
+						ROTATE(matrix,j,ip,j,iq)
+					}
+					for ( j = ip+1 ; j <= (int)(iq-1) ;j++ ) {
+						ROTATE(matrix,ip,j,j,iq)
+					}
+					for ( j = iq+1 ; j < (int)count ; j++ ) {
+						ROTATE(matrix,ip,j,iq,j)
+					}
+					for ( j = 0 ; j < (int)count ; j++ ) {
+						ROTATE_EIGENVECTOR_LIST(eigenvectorList,ip,j,iq,j)
+					}
+				}
+			}
+		}
+		for ( ip = 0 ; ip < count ; ip++ ) {
+			b[ip] += z[ip];
+			eigenvectorList[ip].eigenvalue =b[ip];
+			z[ip]=0.0;
+		}
+	}
+	
+	Memory_Free(z);
+	Memory_Free(b);
+	
+	EigenvectorList_Sort( eigenvectorList, count );
+}
+
+
+/** Sorts the eigenvectors according to the value of the eigenvalue - from smallest to greatest */
+void EigenvectorList_Sort( Eigenvector* eigenvectorList, Index count ) {
+	qsort( eigenvectorList, count, sizeof( Eigenvector ), _QsortEigenvalue );
+}
+/** Calculates the determinant of a matrix, independent of the ordering of the axis.*/
+double StGermain_MatrixDeterminant_AxisIndependent( double** matrix, Dimension_Index dim, Coord_Index A_axis, Coord_Index B_axis, Coord_Index C_axis ) {
+	switch (dim) {
+		case 1:
+			return matrix[A_axis][A_axis];
+		case 2:
+			return matrix[A_axis][A_axis]*matrix[B_axis][B_axis] - matrix[A_axis][B_axis]*matrix[B_axis][A_axis];
+		case 3:
+			return 
+				matrix[A_axis][A_axis] *
+					( matrix[B_axis][B_axis]*matrix[C_axis][C_axis] - matrix[B_axis][C_axis]*matrix[C_axis][B_axis] ) 
+				- matrix[A_axis][B_axis] *
+					( matrix[B_axis][A_axis]*matrix[C_axis][C_axis] - matrix[B_axis][C_axis]*matrix[C_axis][A_axis] )
+				+ matrix[A_axis][C_axis] *
+					( matrix[B_axis][A_axis]*matrix[C_axis][B_axis] - matrix[B_axis][B_axis]*matrix[C_axis][A_axis] );
+		default: {
+			Stream* error = Journal_Register( Error_Type , (Name)CURR_MODULE_NAME  );
+			Journal_Printf(error, "Function %s doesn't support dimension %d.\n", __func__, dim);
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)"TensorMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}
+	return 0; /* Silly, but TAU-PDT complains otherwise */
+}
+
+/** Solves a cubic. See:  
+Eric W. Weisstein. "Cubic Formula." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CubicFormula.html */
+void CubicSolver_OnlyRealRoots( double a2, double a1, double a0, double* rootList ) {
+	double Q, R;
+	double D;
+	double theta;
+	double factor;
+
+	Q = (3.0 * a1 - a2 * a2)/9.0;                                   /* Equation 20 */
+	R = (9.0*a2*a1 - 27.0 * a0 - 2.0 * a2 * a2 * a2)/54.0;          /* Equation 21 */
+
+	/* Get Polynomial Discrimanent  (Equation 47) */
+	D = Q*Q*Q + R*R;
+		
+	if ( EQL( D, 0.0 ) ) {
+		double halfB;
+
+		if ( R < 0.0 ) 
+			halfB = - pow( -R, 1.0/3.0 );
+		else
+			halfB = pow( R, 1.0/3.0 );
+
+		rootList[0] = -a2/3.0 + 2.0 * halfB;
+		rootList[1] = rootList[2] = -a2/3.0 - halfB;
+		return;
+	}
+	Journal_Firewall( D <= 0.0, Journal_Register( Error_Type, (Name)"CubicSolver"  ),
+			"In func %s - Polynomial discrimanent %g is positive which means there are complex solutions.\nCannot solve equation x^3 + %.4f x^2 + %.4f x + %.4f = 0\n", __func__ , D, a2, a1, a0 );
+
+
+	theta = acos( R/sqrt( -Q*Q*Q ) )/3.0;
+	factor = 2.0 * sqrt( -Q );
+
+	rootList[0] = factor * cos( theta ) - a2/3.0;
+	rootList[1] = factor * cos( theta + 2.0*M_PI/3.0 ) - a2/3.0;
+	rootList[2] = factor * cos( theta + 4.0*M_PI/3.0 ) - a2/3.0;
+}
+
+
+/** Uses Cramer's rule to solve a system of linear equations 
+ * see http://mathworld.wolfram.com/CramersRule.html */
+void TensorArray_SolveSystem( TensorArray tensorArray, double* solution, double* rightHandSide, Dimension_Index dim ) {
+	double determinant;
+	switch ( dim ) {
+		case 3: {
+			determinant = + tensorArray[ FT3D_00 ] *
+								( tensorArray[ FT3D_11 ] * tensorArray[ FT3D_22 ] -
+								  tensorArray[ FT3D_21 ] * tensorArray[ FT3D_12 ] )
+							- tensorArray[ FT3D_01 ] *
+								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_22 ] -
+								  tensorArray[ FT3D_12 ] * tensorArray[ FT3D_20 ] )
+							+ tensorArray[ FT3D_02 ] *
+								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_21 ] -
+								  tensorArray[ FT3D_11 ] * tensorArray[ FT3D_20 ] );
+
+			solution[ 0 ] = ( rightHandSide[0] * 
+								( tensorArray[ FT3D_11 ] * tensorArray[ FT3D_22 ] -
+								  tensorArray[ FT3D_21 ] * tensorArray[ FT3D_12 ] )
+							- tensorArray[ FT3D_01 ] *
+								( rightHandSide[1] * tensorArray[ FT3D_22 ] -
+								  tensorArray[ FT3D_12 ] * rightHandSide[2] )
+							+ tensorArray[ FT3D_02 ] *
+								( rightHandSide[1] * tensorArray[ FT3D_21 ] -
+								  tensorArray[ FT3D_11 ] * rightHandSide[2] ))/determinant;
+
+			solution[ 1 ] = ( tensorArray[ FT3D_00 ] *
+								( rightHandSide[1] * tensorArray[ FT3D_22 ] -
+								  rightHandSide[2] * tensorArray[ FT3D_12 ] )
+							- rightHandSide[0] * 
+								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_22 ] -
+								  tensorArray[ FT3D_12 ] * tensorArray[ FT3D_20 ] )
+							+ tensorArray[ FT3D_02 ] *
+								( tensorArray[ FT3D_10 ] * rightHandSide[2] -
+								  rightHandSide[1] * tensorArray[ FT3D_20 ] ))/determinant;
+
+			solution[ 2 ] = ( tensorArray[ FT3D_00 ] *
+								( tensorArray[ FT3D_11 ] * rightHandSide[2] -
+								  tensorArray[ FT3D_21 ] * rightHandSide[1] )
+							- tensorArray[ FT3D_01 ] *
+								( tensorArray[ FT3D_10 ] * rightHandSide[2] -
+								  rightHandSide[1] * tensorArray[ FT3D_20 ] )
+							+ rightHandSide[0] *
+								( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_21 ] -
+								  tensorArray[ FT3D_11 ] * tensorArray[ FT3D_20 ] ))/determinant;
+			return;
+		}
+
+		case 2:
+			determinant = tensorArray[ FT2D_00 ] * tensorArray[ FT2D_11 ] 
+			            - tensorArray[ FT2D_10 ] * tensorArray[ FT2D_01 ];
+			
+			solution[ 0 ] = (rightHandSide[0] * tensorArray[ FT2D_11 ] - 
+				tensorArray[ FT2D_01 ] * rightHandSide[1])/determinant;
+			
+			solution[ 1 ] = (rightHandSide[1] * tensorArray[ FT2D_00 ] - 
+				tensorArray[ FT2D_10 ] * rightHandSide[0])/determinant;
+
+			return;
+		default: 
+			Journal_Firewall( 
+					False, 
+					Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ),
+					"Function %s - doesn't understand dim = %u\n", __func__, dim );
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/TensorMultMath.c
--- a/Geometry/src/TensorMultMath.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,671 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
-**	Kathleen M. Humble, Computational Scientist, VPAC. (khumble at vpac.org)
-**	Alireza Asgari, Researcher, Deakin University.
-**  Julian Giordani, Researcher, Monash Cluster Computing, Monash University
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TensorMultMath.c  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-#include "units.h"
-#include "types.h"
-#include "TensorMath.h"
-#include "VectorMath.h"
-#include "TensorMultMath.h"
-#include <math.h>
-#include <string.h>
-
-#define STG_TENSORMULT_ERROR 1.0e-15;
-
-/** Create Identity Tensor */
-void TensorArray_Identity(Dimension_Index dim, TensorArray tensorArray){
-
-	Dimension_Index index;
-	/* Check dimension */
-	if ( (dim != 2)&&(dim != 3) ) {		
-		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-		Journal_Firewall( dim, error,
-			"In func '%s' don't understand dim = %u\n", __func__, dim );
-	}
-	
-	/* Calculate indentity matrix */
-	for (index = 0; index < (dim * dim); index++){
-		tensorArray[index] = 0.0;	
-	}
-	for (index = 0; index < dim; index++ ){
-		tensorArray[TensorArray_TensorMap(index, index, dim)] = 1.0;
-	}			
-	return;
-}
-
-/** Create Identity SymmetricTensor */
-void SymmetricTensor_Identity(Dimension_Index dim, SymmetricTensor symmetricTensor) {
-
-	Dimension_Index index;
-	/* Check dimension */
-	if ( (dim != 2)&&(dim != 3) ) {		
-		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-		Journal_Firewall( dim, error,
-			"In func '%s' don't understand dim = %u\n", __func__, dim );
-	}
-	
-	/* Calculate indentity matrix: zero max = (0.5 * ((dim) * ((dim) + 1)) [Triangular number]*/
-	for (index = 0; index < (0.5 * (dim * (dim + 1 )) ); index++){
-		symmetricTensor[index] = 0.0;	
-	}
-	for (index = 0; index < dim; index++ ){
-		symmetricTensor[SymmetricTensor_TensorMap(index, index, dim)] = 1.0;
-	}			
-	return;
-}
-
-/** Calculates the transpose of a given tensor array */
-void TensorArray_Transpose(TensorArray tensor, Dimension_Index dim, TensorArray result){
-switch (dim) {
-        case 3:
-            result[FT3D_00] = tensor[FT3D_00];
-            result[FT3D_01] = tensor[FT3D_10];
-            result[FT3D_02] = tensor[FT3D_20];
-            result[FT3D_10] = tensor[FT3D_01];
-            result[FT3D_11] = tensor[FT3D_11];
-            result[FT3D_12] = tensor[FT3D_21];
-            result[FT3D_20] = tensor[FT3D_02];
-            result[FT3D_21] = tensor[FT3D_12];
-            result[FT3D_22] = tensor[FT3D_22];
-            return;
-        case 2:
-            result[FT2D_00] = tensor[FT2D_00];
-            result[FT2D_01] = tensor[FT2D_10];
-            result[FT2D_10] = tensor[FT2D_01];
-            result[FT2D_11] = tensor[FT2D_11];
-            break;
-        default: {
-           	Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-           	Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );;
-            }
-        }
-}
-
-/** Adds tensorA to tensorB and returns answer in TensorArray result */
-void TensorArray_Add(TensorArray tensorA, TensorArray tensorB, Dimension_Index dim, TensorArray result) {
-    Dimension_Index index;
-	
-	if ( (dim != 2)&&(dim != 3) ) {		
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-    for (index = 0; index < (dim * dim); index++){
-        result[index] = tensorA[index] + tensorB[index];
-    }
-}
-
-/** Subtracts tensorB from tensorA and returns answer in TensorArray result*/
-void TensorArray_Subtract(	TensorArray tensorArrayA, TensorArray tensorArrayB, Dimension_Index dim, 
-							TensorArray result) 
-{
-	Dimension_Index index;
-	
-		if ( (dim != 2)&&(dim != 3) ) {		
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	    for (index = 0; index < (dim * dim); index++){
-        result[index] = tensorArrayA[index] - tensorArrayB[index];
-    }
-}
-
-/** Multiplies two TensorArray's */ 
-void TensorArray_MultiplyByTensorArray(	TensorArray tensorA, TensorArray tensorB, Dimension_Index dim, TensorArray result) {
-	
-	switch (dim) {
-        case 3:
-            result[FT3D_00] = 	tensorA[FT3D_00] * tensorB[FT3D_00] 
-							+ 	tensorA[FT3D_01] * tensorB[FT3D_10]
-							+ 	tensorA[FT3D_02] * tensorB[FT3D_20];
-		
-            result[FT3D_01] =	tensorA[FT3D_00] * tensorB[FT3D_01]
-							+	tensorA[FT3D_01] * tensorB[FT3D_11]
-							+	tensorA[FT3D_02] * tensorB[FT3D_21];
-        
-			result[FT3D_02] =	tensorA[FT3D_00] * tensorB[FT3D_02]
-							+	tensorA[FT3D_01] * tensorB[FT3D_12]
-							+ 	tensorA[FT3D_02] * tensorB[FT3D_22];
-
-            result[FT3D_10] =	tensorA[FT3D_10] * tensorB[FT3D_00]
-							+	tensorA[FT3D_11] * tensorB[FT3D_10]
-							+	tensorA[FT3D_12] * tensorB[FT3D_20];
-		
-            result[FT3D_11] =	tensorA[FT3D_10] * tensorB[FT3D_01]
-							+ 	tensorA[FT3D_11] * tensorB[FT3D_11]
-							+	tensorA[FT3D_12] * tensorB[FT3D_21];
-        
-			result[FT3D_12] =	tensorA[FT3D_10] * tensorB[FT3D_02]
-							+ 	tensorA[FT3D_11] * tensorB[FT3D_12]
-							+	tensorA[FT3D_12] * tensorB[FT3D_22];
-
-            result[FT3D_20] =	tensorA[FT3D_20] * tensorB[FT3D_00]
-							+	tensorA[FT3D_21] * tensorB[FT3D_10]
-							+	tensorA[FT3D_22] * tensorB[FT3D_20];
-							
-            result[FT3D_21]	=	tensorA[FT3D_20] * tensorB[FT3D_01]
-							+	tensorA[FT3D_21] * tensorB[FT3D_11]
-							+	tensorA[FT3D_22] * tensorB[FT3D_21];
-							
-            result[FT3D_22] =	tensorA[FT3D_20] * tensorB[FT3D_02]
-							+	tensorA[FT3D_21] * tensorB[FT3D_12]
-							+	tensorA[FT3D_22] * tensorB[FT3D_22];
-            return;
-        case 2:
-            result[FT2D_00]	=	tensorA[FT2D_00] * tensorB[FT2D_00] 
-							+ 	tensorA[FT2D_01] * tensorB[FT2D_10];
-		
-            result[FT2D_01]	=	tensorA[FT2D_00] * tensorB[FT2D_01]
-							+ 	tensorA[FT2D_01] * tensorB[FT2D_11];
-
-            result[FT2D_10]	=	tensorA[FT2D_10] * tensorB[FT2D_00]
-							+	tensorA[FT2D_11] * tensorB[FT2D_10];
-		
-            result[FT2D_11]	=	tensorA[FT2D_10] * tensorB[FT2D_01]
-							+	tensorA[FT2D_11] * tensorB[FT2D_11];
-            return;
-        default: {
-           Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-           Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-           	Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMultMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );;
-            }
-    }
-
-}
-
-
-
-/** Multiplies tensor A, on the right by it's transpose, A^T to give A*A^T 
-And returns the answer in a symmetric tensor*/
-void TensorArray_MultiplyByRightTranspose(TensorArray tensor, Dimension_Index dim, SymmetricTensor result) {
-
-	TensorArray tensorTranspose;
-	TensorArray fullTensorResult;
-
-
-	TensorArray_Transpose(tensor, dim, tensorTranspose);
-	TensorArray_MultiplyByTensorArray(tensor, tensorTranspose, dim, fullTensorResult);
-	
-	/** Answer is automatically a symmetric tensor by definition */	
-	TensorArray_GetSymmetricPart( fullTensorResult, dim, result ) ;
-
-	return;
-}
-
-/** Multiplies tensor A, on the left by it's transpose, A^T to give A^T * A 
-And returns the answer in a symmetric tensor*/
-void TensorArray_MultiplyByLeftTranspose(TensorArray tensor, Dimension_Index dim, SymmetricTensor result) {
-
-	TensorArray tensorTranspose;
-	TensorArray fullTensorResult;
-
-	TensorArray_Transpose( tensor, dim, tensorTranspose);
-	TensorArray_MultiplyByTensorArray( tensorTranspose, tensor, dim, fullTensorResult );
-	
-	/** Answer is automatically a symmetric tensor by definition */	
-	TensorArray_GetSymmetricPart( fullTensorResult, dim, result);
-	return;
-}
-
-/**	Multiplies TensorArray by SymmetricTensor, and gives answer in a TensorArray:
-	A * symB */
-void TensorArray_MultiplyBySymmetricTensor(	TensorArray tensorArray, SymmetricTensor symmetricTensor,
-											Dimension_Index dim, TensorArray result)
-{
-switch (dim) {
-        case 3:
-            result[FT3D_00] = 	tensorArray[FT3D_00] * symmetricTensor[ST3D_00] 
-							+ 	tensorArray[FT3D_01] * symmetricTensor[ST3D_01]
-							+ 	tensorArray[FT3D_02] * symmetricTensor[ST3D_02];
-		
-            result[FT3D_01] =	tensorArray[FT3D_00] * symmetricTensor[ST3D_01]
-							+	tensorArray[FT3D_01] * symmetricTensor[ST3D_11]
-							+	tensorArray[FT3D_02] * symmetricTensor[ST3D_12];
-        
-			result[FT3D_02] =	tensorArray[FT3D_00] * symmetricTensor[ST3D_02]
-							+	tensorArray[FT3D_01] * symmetricTensor[ST3D_12]
-							+ 	tensorArray[FT3D_02] * symmetricTensor[ST3D_22];
-
-            result[FT3D_10] =	tensorArray[FT3D_10] * symmetricTensor[ST3D_00]
-							+	tensorArray[FT3D_11] * symmetricTensor[ST3D_01]
-							+	tensorArray[FT3D_12] * symmetricTensor[ST3D_02];
-		
-            result[FT3D_11] =	tensorArray[FT3D_10] * symmetricTensor[ST3D_01]
-							+ 	tensorArray[FT3D_11] * symmetricTensor[ST3D_11]
-							+	tensorArray[FT3D_12] * symmetricTensor[ST3D_12];
-        
-			result[FT3D_12] =	tensorArray[FT3D_10] * symmetricTensor[ST3D_02]
-							+ 	tensorArray[FT3D_11] * symmetricTensor[ST3D_12]
-							+	tensorArray[FT3D_12] * symmetricTensor[ST3D_22];
-
-            result[FT3D_20] =	tensorArray[FT3D_20] * symmetricTensor[ST3D_00]
-							+	tensorArray[FT3D_21] * symmetricTensor[ST3D_01]
-							+	tensorArray[FT3D_22] * symmetricTensor[ST3D_02];
-							
-            result[FT3D_21]	=	tensorArray[FT3D_20] * symmetricTensor[ST3D_01]
-							+	tensorArray[FT3D_21] * symmetricTensor[ST3D_11]
-							+	tensorArray[FT3D_22] * symmetricTensor[ST3D_12];
-							
-            result[FT3D_22] =	tensorArray[FT3D_20] * symmetricTensor[ST3D_02]
-							+	tensorArray[FT3D_21] * symmetricTensor[ST3D_12]
-							+	tensorArray[FT3D_22] * symmetricTensor[ST3D_22];
-            return;
-        case 2:
-            result[FT2D_00]	=	tensorArray[FT2D_00] * symmetricTensor[ST2D_00] 
-							+ 	tensorArray[FT2D_01] * symmetricTensor[ST2D_01];
-		
-            result[FT2D_01]	=	tensorArray[FT2D_00] * symmetricTensor[ST2D_01]
-							+ 	tensorArray[FT2D_01] * symmetricTensor[ST2D_11];
-
-            result[FT2D_10]	=	tensorArray[FT2D_10] * symmetricTensor[ST2D_00]
-							+	tensorArray[FT2D_11] * symmetricTensor[ST2D_01];
-		
-            result[FT2D_11]	=	tensorArray[FT2D_10] * symmetricTensor[ST2D_01]
-							+	tensorArray[FT2D_11] * symmetricTensor[ST2D_11];
-            return;
-        default: {
-           Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-           Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
-           	Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMultMath"  ),
-				"In func '%s' don't understand dim = %u\n", __func__, dim );;
-            }
-		}
-}
-
-/**	Multiplies SymmetricTensor by TensorArray and gives answer in a TensorArray:
-	symA * B */
-void SymmetricTensor_MultiplyByTensorArray(	TensorArray tensorArray, SymmetricTensor symmetricTensor,
-											Dimension_Index dim, TensorArray result)
-{
-	TensorArray fullTensor;
-	StGermain_SymmetricTensor_ToTensorArray(symmetricTensor, dim, fullTensor);
-	TensorArray_MultiplyByTensorArray(fullTensor, tensorArray, dim, result);
-	return;
-}
-
-/** Multiplies a tensorArray by vector on the left: v * A */
-void TensorArray_MultiplyByLeftVector(	TensorArray tensorArray, double* vector, 
-										Dimension_Index dim, double* result) 
-{
-	switch (dim) {
-		case 3:
-			result[0] = vector[0] * tensorArray[FT3D_00] +
-						vector[1] * tensorArray[FT3D_10] +
-						vector[2] * tensorArray[FT3D_20];
-		
-			result[1] = vector[0] * tensorArray[FT3D_01] +
-						vector[1] * tensorArray[FT3D_11] +
-						vector[2] * tensorArray[FT3D_21];
-		
-			result[2] = vector[0] * tensorArray[FT3D_02] +
-						vector[1] * tensorArray[FT3D_12] +
-						vector[2] * tensorArray[FT3D_22];		
-			return;
-		case 2:
-			result[0] = vector[0] * tensorArray[FT2D_00] 
-					  + vector[1] * tensorArray[FT2D_10];
-		
-			result[1] = vector[0] * tensorArray[FT2D_01] 
-					  + vector[1] * tensorArray[FT2D_11];		
-			return;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}		
-		return;
-}
-
-/** Multiplies a tensorArray by vector on the right:  A * v */
-void TensorArray_MultiplyByRightVector(	TensorArray tensorArray, double* vector, 
-										Dimension_Index dim, double* result)
-{
-	switch (dim) {
-		case 3:
-			result[0] = tensorArray[FT3D_00] * vector[0] +
-						tensorArray[FT3D_01] * vector[1] +
-						tensorArray[FT3D_02] * vector[2];
-		
-			result[1] = tensorArray[FT3D_10] * vector[0] +
-						tensorArray[FT3D_11] * vector[1] +
-						tensorArray[FT3D_12] * vector[2];
-		
-			result[2] = tensorArray[FT3D_20] * vector[0] +
-						tensorArray[FT3D_21] * vector[1] +
-						tensorArray[FT3D_22] * vector[2];		
-			return;
-		case 2:
-			result[0] = tensorArray[FT2D_00] * vector[0] + 
-						tensorArray[FT2D_01] * vector[1];
-		
-			result[1] = tensorArray[FT2D_10] * vector[0] +
-					  	tensorArray[FT2D_11] * vector[1];		
-			return;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-		}
-	}		
-	return;	
-	
-}
-
-/** Calculates the determinant of a TensorArray*/
-double TensorArray_CalcDeterminant(TensorArray tensorArray, Dimension_Index dim) {
-
-    double determinant;
-    switch ( dim ) {
-        case 3:{
-            determinant =   tensorArray[ FT3D_00] *
-                                ( tensorArray[ FT3D_11 ] * tensorArray[ FT3D_22 ] -
-                                  tensorArray[ FT3D_21 ] * tensorArray[ FT3D_12 ] )
-                            - tensorArray[ FT3D_01 ] *
-                                ( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_22 ] -
-                                  tensorArray[ FT3D_12 ] * tensorArray[ FT3D_20 ] )
-                            + tensorArray[ FT3D_02 ] *
-                                ( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_21 ] -
-                                  tensorArray[ FT3D_11 ] * tensorArray[ FT3D_20 ] );
-            return determinant;
-            }
-        case 2:{
-            determinant = tensorArray[ FT2D_00 ] * tensorArray[ FT2D_11 ]
-                        - tensorArray[ FT2D_10 ] * tensorArray[ FT2D_01 ];
-            return determinant;
-            }
-        default: {
- 			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-			Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-        }
-    }
-	return 0;
-}
-
-/** Calculates the inverse of a tensorArray for non-zero determinants.  */
-void TensorArray_CalcInverse(TensorArray tensor, Dimension_Index dim, TensorArray result) {
-	
-	double determinant;
-	/* Calculate determinant */
-	determinant = TensorArray_CalcDeterminant(tensor, dim);	
-	TensorArray_CalcInverseWithDeterminant(tensor, determinant, dim, result);
-	return;
-}
-
-/** Calculates inverse of tensorArray for non-zero determinant when given a value 
-for the determinant. This allows the use of different determinants 
-if such calculation is needed.*/
-void TensorArray_CalcInverseWithDeterminant(TensorArray tensor, double determinant, Dimension_Index dim, TensorArray result) {
-	double  errorValue;
-
-	/* Check if determinant is zero or close to zero*/
-	errorValue = STG_TENSORMULT_ERROR;
-	if (fabs(determinant) <= errorValue) {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-			Journal_Printf( error, "Error in '%s', Cannot calculate inverse of singular tensorArray:\n", 
-							__func__); 
-			Journal_PrintTensorArray( error, tensor, dim);
-			Journal_Printf( error, "Determinant, %g is zero or near zero. \n", determinant);
-		Journal_Firewall( False, Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
-				"In func '%s',TensorArray is singular, cannot divide by zero determinant, %g\n", __func__, determinant );
-		return;		
-	}
-	
-	/** Uses formula : 
-	A^{-1} \= \frac{(-1)^i + j(M_{ij})}{detA} 
-	*/ 
-	switch (dim) {
-			case 3:
-				result[FT3D_00] = ( tensor[FT3D_11] * tensor[FT3D_22] - 
-									tensor[FT3D_21] * tensor[FT3D_12] ) / determinant;
-				result[FT3D_10] = ( tensor[FT3D_20] * tensor[FT3D_12] - 
-									tensor[FT3D_10] * tensor[FT3D_22] ) / determinant;
-				result[FT3D_20] = ( tensor[FT3D_10] * tensor[FT3D_21] - 
-									tensor[FT3D_20] * tensor[FT3D_11] ) / determinant;
-	
-				result[FT3D_01] = ( tensor[FT3D_21] * tensor[FT3D_02] - 
-									tensor[FT3D_01] * tensor[FT3D_22] ) / determinant;
-				result[FT3D_11] = ( tensor[FT3D_00] * tensor[FT3D_22] - 
-									tensor[FT3D_20] * tensor[FT3D_02] ) / determinant;
-				result[FT3D_21] = ( tensor[FT3D_20] * tensor[FT3D_01] - 
-									tensor[FT3D_00] * tensor[FT3D_21] ) / determinant;
-	
-				result[FT3D_02] = ( tensor[FT3D_01] * tensor[FT3D_12] - 
-									tensor[FT3D_11] * tensor[FT3D_02] ) / determinant;
-				result[FT3D_12] = ( tensor[FT3D_10] * tensor[FT3D_02] - 
-									tensor[FT3D_00] * tensor[FT3D_12] ) / determinant;
-				result[FT3D_22] = ( tensor[FT3D_00] * tensor[FT3D_11] - 
-									tensor[FT3D_10] * tensor[FT3D_01] ) / determinant;
-				break;
-			case 2:
-				result[FT2D_00] = tensor[FT2D_11] / determinant;
-				result[FT2D_01] = ( -1.0 * tensor[FT2D_01] ) / determinant;
-				result[FT2D_10] = ( -1.0 * tensor[FT2D_10] ) / determinant;
-				result[FT2D_11] = tensor[FT2D_00] / determinant;
-				break;
-			default: {
- 				Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-				Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-				Journal_Firewall( dim, error,
-				"In func '%s' don't understand dim = %u\n", __func__, dim );
-				}
-		}
-}
-
-
-/** Calculate double dot product of two tensors */
-double TensorArray_DoubleContraction(TensorArray tensorA,TensorArray tensorB, Dimension_Index dim){
-    double contraction;
-    Dimension_Index i, j;
-	/** \[\sigma:\epsilon=\sum_{i=1}^{n}\sum_{i=1}^{n}\sigma_{ij}\epsilon_{ij}\]  */
-	/* Check dimension */
-	if ( (dim != 2)&&(dim != 3) ) {		
-		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-		Journal_Firewall( dim, error,
-			"In func '%s' don't understand dim = %u\n", __func__, dim );
-	}
-	
-	/* Calculate contraction */
-	contraction = 0.0;
-	for ( i = 0; i < dim; i++) {
-		for (j = 0; j < dim; j++) {
-			contraction = 	contraction + 
-							tensorA[ TensorArray_TensorMap(i, j, dim) ] * 
-							tensorB[ TensorArray_TensorMap(i, j, dim) ];       
-		}        
-	}
-
-    return contraction;
-}
-
-/** Calculate double dot product of two symmteric tensors */
-double SymmetricTensor_DoubleContraction(SymmetricTensor tensorA, SymmetricTensor tensorB, Dimension_Index dim)
-{
-    double contraction;
-    Dimension_Index i, j;
-	
-	/* Check dimension */
-	if ( (dim != 2)&&(dim != 3) ) {		
-		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
-		Journal_Firewall( dim, error,
-			"In func '%s' don't understand dim = %u\n", __func__, dim );
-	}
-	
-	/* Calculate contraction */
-	contraction = 0.0;
-	for ( i = 0; i < dim; i++) {
-		for (j = 0; j < dim; j++) {
-			contraction = 	contraction + 
-							tensorA[ SymmetricTensor_TensorMap(i, j, dim) ] * 
-							tensorB[ SymmetricTensor_TensorMap(i, j, dim) ];       
-		}        
-	}
-
-    return contraction;
-}
-
-/************ All NonSquareMatrix Functions assume the output Matrix/Vector data structure is already initialised *******/
-/** This function calculates the transpose of a non-square nxm 2D matrix
-	It requires the row and column dimensions, and assumes an answer matrix
-	that is the correct size, ie mxn */
-void NonSquareMatrix_Transpose( double** originalMatrix, Dimension_Index rowDimOrig, 
-	Dimension_Index colDimOrig, double** newMatrix ) {
-	Dimension_Index row_I, col_I;
-	if ((rowDimOrig <=0) || (colDimOrig <=0)) {
-        Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
-
-		Journal_Firewall( False, error,
-				"In func '%s' don't understand rows = %u or cols = %u\n", 
-			__func__, rowDimOrig, colDimOrig );
-	}
-	for( row_I = 0 ; row_I < rowDimOrig ; row_I++ ) {
-		for( col_I = 0 ; col_I < colDimOrig ; col_I++ ) {
-			newMatrix[ col_I ][ row_I ] = originalMatrix[ row_I ][ col_I ];
-		}
-	}
-	return;
-}
-
-/** This function multiplies 2 non square matrices and returns the in the resultMatrix. 
- * It requires the columns in MatrixA = rows in BMatrix
- * resultMatrix_ik = AMatrix_ij x BMatrix_jk */
-void NonSquareMatrix_MultiplicationByNonSquareMatrix( double **AMatrix, int rowDimA, int colDimA,
-					 double **BMatrix, int rowDimB, int colDimB, 
-					 double** resultMatrix ) {
-	int counter;
-	for( counter = 0 ; counter < rowDimA ; counter++ ) {
-		memset( resultMatrix[counter], 0, sizeof( double ) * colDimB );
-	}
-
-	NonSquareMatrix_CumulativeMultiplicationByNonSquareMatrix(AMatrix,rowDimA,colDimA,
-		 	BMatrix,rowDimB, colDimB, 
-			resultMatrix );	
-	
-}
-
-/** This function multiplies 2 non square matrices and adds the result to the passed in resultMatrix. 
- * It requires the columns in MatrixA = rows in BMatrix
- * resultMatrix_ik += AMatrix_ij x BMatrix_jk */
-void NonSquareMatrix_CumulativeMultiplicationByNonSquareMatrix( double **AMatrix, 
-					 int rowDimA, int colDimA,
-					 double **BMatrix, int rowDimB, int colDimB, 
-					 double** resultMatrix ) {
-			
-  int row_I, col_I; /* location with resultMatrix  */
-  int counter;      /* counter which facilitates the multiplication of AMatrix and BMatrix */
-	/** Error Checking Code */				 
-	Journal_Firewall( (colDimA == rowDimB), Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
-			"In func '%s'  row dimension B, %u != column dimension A, %u\n", 
-		__func__, rowDimB, colDimA );
-	Journal_Firewall( (AMatrix && BMatrix && resultMatrix), Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
-			"In func '%s', Input matrices: %s %s, or Output matrix: %s is NULL \n", 
-		__func__, AMatrix, BMatrix, resultMatrix);
-
-	/** Calculate result matrix */
-	for( row_I = 0 ; row_I < rowDimA ; row_I++ ) {
-		for( col_I = 0 ; col_I < colDimB ; col_I++ ) {
-			/** resultMatrix[ row_I ][ col_I] = AMatrix_ij x BMatrix_jk */
-		       	for( counter = 0 ; counter < colDimA ; counter++ ) {
-				resultMatrix[ row_I ][ col_I ] += ( AMatrix[row_I][counter] * BMatrix[counter][col_I] );
-			}
-		}
-	}
-}
-
-/** This function multiplies a M x N matrices by a N vector.. It requires the columns in AMatrix = rows in BVec
-	resultVector_i = AMatrix_ij x BVec_j */
-void NonSquareMatrix_MatrixVectorMultiplication( double** AMatrix, int rowsInA, int colsInA,
-		     double* BVec, int rowsInB,double* resultVector ) {
-  /*This assumes the resultVector is of the correct length. */
-	memset(resultVector,0,sizeof(double)* rowsInA);		 
-	NonSquareMatrix_CumulativeMatrixVectorMultiplication( AMatrix, rowsInA, colsInA,
-		                     BVec, rowsInB, resultVector);						   
-}
-
-/** This function multiplies a M x N matrices by a N vector, and then adds this result
- * to the passed in 'solution Vector'. It requires the columns in MatrixA = rows in BVec
- * resultVector_i = AMatrix_ij x BVec_j */
-void NonSquareMatrix_CumulativeMatrixVectorMultiplication( double** AMatrix, int rowsInA, int colsInA,
-		                               double* BVec, int rowsInB, double* resultVector ) {
-  int row_I, col_I; /* counters through matrix rows and columns respectively */
-	/** Error Checking Code */  
-	Journal_Firewall( ( colsInA == rowsInB ), Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
-		"In func '%s' column dimensions of A_Matrix = %d is not equal to the row dimensions of B_Vec = %d\n",
-		__func__, colsInA, rowsInB );
-	Journal_Firewall( (resultVector && AMatrix && BVec) , Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
-		"In func '%s', Input matrices: %p %p, or Output matrix: %p is NULL \n", 
-		__func__, AMatrix, BVec, resultVector);
-
-	/* calculate the result Vector */
-	for( row_I = 0 ; row_I < rowsInA ; row_I++ ) {
-		for( col_I = 0 ; col_I < colsInA ; col_I++ ) {
-			resultVector[ row_I ] += AMatrix[ row_I ][ col_I ] * BVec[ col_I ];
-		}
-	}
-}
-
-/** Prints out a non square matrix if given the row and col dimension */
-void Journal_PrintNonSquareMatrix_Unnamed( Stream* stream, double** NonSquareMatrix, 
-	Dimension_Index rowDim, Dimension_Index colDim ) 
-{
-	Dimension_Index row_I, col_I;
-
-	/* For efficency - Check if stream is enabled */
-	if (!Stream_IsEnable(stream)) return;
-	
-	for ( row_I = 0 ; row_I < rowDim ; row_I++ ) {
-		for ( col_I = 0 ; col_I < colDim ; col_I++ ) {
-			Journal_Printf( stream, "%7.5g	", NonSquareMatrix[row_I][col_I] );
-			}
-		Journal_Printf( stream, "\n" );
-	}
-		
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/TensorMultMath.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/TensorMultMath.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,671 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
+**	Kathleen M. Humble, Computational Scientist, VPAC. (khumble at vpac.org)
+**	Alireza Asgari, Researcher, Deakin University.
+**  Julian Giordani, Researcher, Monash Cluster Computing, Monash University
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TensorMultMath.c  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+#include "units.h"
+#include "types.h"
+#include "TensorMath.h"
+#include "VectorMath.h"
+#include "TensorMultMath.h"
+#include <math.h>
+#include <string.h>
+
+#define STG_TENSORMULT_ERROR 1.0e-15;
+
+/** Create Identity Tensor */
+void TensorArray_Identity(Dimension_Index dim, TensorArray tensorArray){
+
+	Dimension_Index index;
+	/* Check dimension */
+	if ( (dim != 2)&&(dim != 3) ) {		
+		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+		Journal_Firewall( dim, error,
+			"In func '%s' don't understand dim = %u\n", __func__, dim );
+	}
+	
+	/* Calculate indentity matrix */
+	for (index = 0; index < (dim * dim); index++){
+		tensorArray[index] = 0.0;	
+	}
+	for (index = 0; index < dim; index++ ){
+		tensorArray[TensorArray_TensorMap(index, index, dim)] = 1.0;
+	}			
+	return;
+}
+
+/** Create Identity SymmetricTensor */
+void SymmetricTensor_Identity(Dimension_Index dim, SymmetricTensor symmetricTensor) {
+
+	Dimension_Index index;
+	/* Check dimension */
+	if ( (dim != 2)&&(dim != 3) ) {		
+		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+		Journal_Firewall( dim, error,
+			"In func '%s' don't understand dim = %u\n", __func__, dim );
+	}
+	
+	/* Calculate indentity matrix: zero max = (0.5 * ((dim) * ((dim) + 1)) [Triangular number]*/
+	for (index = 0; index < (0.5 * (dim * (dim + 1 )) ); index++){
+		symmetricTensor[index] = 0.0;	
+	}
+	for (index = 0; index < dim; index++ ){
+		symmetricTensor[SymmetricTensor_TensorMap(index, index, dim)] = 1.0;
+	}			
+	return;
+}
+
+/** Calculates the transpose of a given tensor array */
+void TensorArray_Transpose(TensorArray tensor, Dimension_Index dim, TensorArray result){
+switch (dim) {
+        case 3:
+            result[FT3D_00] = tensor[FT3D_00];
+            result[FT3D_01] = tensor[FT3D_10];
+            result[FT3D_02] = tensor[FT3D_20];
+            result[FT3D_10] = tensor[FT3D_01];
+            result[FT3D_11] = tensor[FT3D_11];
+            result[FT3D_12] = tensor[FT3D_21];
+            result[FT3D_20] = tensor[FT3D_02];
+            result[FT3D_21] = tensor[FT3D_12];
+            result[FT3D_22] = tensor[FT3D_22];
+            return;
+        case 2:
+            result[FT2D_00] = tensor[FT2D_00];
+            result[FT2D_01] = tensor[FT2D_10];
+            result[FT2D_10] = tensor[FT2D_01];
+            result[FT2D_11] = tensor[FT2D_11];
+            break;
+        default: {
+           	Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+           	Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );;
+            }
+        }
+}
+
+/** Adds tensorA to tensorB and returns answer in TensorArray result */
+void TensorArray_Add(TensorArray tensorA, TensorArray tensorB, Dimension_Index dim, TensorArray result) {
+    Dimension_Index index;
+	
+	if ( (dim != 2)&&(dim != 3) ) {		
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+    for (index = 0; index < (dim * dim); index++){
+        result[index] = tensorA[index] + tensorB[index];
+    }
+}
+
+/** Subtracts tensorB from tensorA and returns answer in TensorArray result*/
+void TensorArray_Subtract(	TensorArray tensorArrayA, TensorArray tensorArrayB, Dimension_Index dim, 
+							TensorArray result) 
+{
+	Dimension_Index index;
+	
+		if ( (dim != 2)&&(dim != 3) ) {		
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	    for (index = 0; index < (dim * dim); index++){
+        result[index] = tensorArrayA[index] - tensorArrayB[index];
+    }
+}
+
+/** Multiplies two TensorArray's */ 
+void TensorArray_MultiplyByTensorArray(	TensorArray tensorA, TensorArray tensorB, Dimension_Index dim, TensorArray result) {
+	
+	switch (dim) {
+        case 3:
+            result[FT3D_00] = 	tensorA[FT3D_00] * tensorB[FT3D_00] 
+							+ 	tensorA[FT3D_01] * tensorB[FT3D_10]
+							+ 	tensorA[FT3D_02] * tensorB[FT3D_20];
+		
+            result[FT3D_01] =	tensorA[FT3D_00] * tensorB[FT3D_01]
+							+	tensorA[FT3D_01] * tensorB[FT3D_11]
+							+	tensorA[FT3D_02] * tensorB[FT3D_21];
+        
+			result[FT3D_02] =	tensorA[FT3D_00] * tensorB[FT3D_02]
+							+	tensorA[FT3D_01] * tensorB[FT3D_12]
+							+ 	tensorA[FT3D_02] * tensorB[FT3D_22];
+
+            result[FT3D_10] =	tensorA[FT3D_10] * tensorB[FT3D_00]
+							+	tensorA[FT3D_11] * tensorB[FT3D_10]
+							+	tensorA[FT3D_12] * tensorB[FT3D_20];
+		
+            result[FT3D_11] =	tensorA[FT3D_10] * tensorB[FT3D_01]
+							+ 	tensorA[FT3D_11] * tensorB[FT3D_11]
+							+	tensorA[FT3D_12] * tensorB[FT3D_21];
+        
+			result[FT3D_12] =	tensorA[FT3D_10] * tensorB[FT3D_02]
+							+ 	tensorA[FT3D_11] * tensorB[FT3D_12]
+							+	tensorA[FT3D_12] * tensorB[FT3D_22];
+
+            result[FT3D_20] =	tensorA[FT3D_20] * tensorB[FT3D_00]
+							+	tensorA[FT3D_21] * tensorB[FT3D_10]
+							+	tensorA[FT3D_22] * tensorB[FT3D_20];
+							
+            result[FT3D_21]	=	tensorA[FT3D_20] * tensorB[FT3D_01]
+							+	tensorA[FT3D_21] * tensorB[FT3D_11]
+							+	tensorA[FT3D_22] * tensorB[FT3D_21];
+							
+            result[FT3D_22] =	tensorA[FT3D_20] * tensorB[FT3D_02]
+							+	tensorA[FT3D_21] * tensorB[FT3D_12]
+							+	tensorA[FT3D_22] * tensorB[FT3D_22];
+            return;
+        case 2:
+            result[FT2D_00]	=	tensorA[FT2D_00] * tensorB[FT2D_00] 
+							+ 	tensorA[FT2D_01] * tensorB[FT2D_10];
+		
+            result[FT2D_01]	=	tensorA[FT2D_00] * tensorB[FT2D_01]
+							+ 	tensorA[FT2D_01] * tensorB[FT2D_11];
+
+            result[FT2D_10]	=	tensorA[FT2D_10] * tensorB[FT2D_00]
+							+	tensorA[FT2D_11] * tensorB[FT2D_10];
+		
+            result[FT2D_11]	=	tensorA[FT2D_10] * tensorB[FT2D_01]
+							+	tensorA[FT2D_11] * tensorB[FT2D_11];
+            return;
+        default: {
+           Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+           Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+           	Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMultMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );;
+            }
+    }
+
+}
+
+
+
+/** Multiplies tensor A, on the right by it's transpose, A^T to give A*A^T 
+And returns the answer in a symmetric tensor*/
+void TensorArray_MultiplyByRightTranspose(TensorArray tensor, Dimension_Index dim, SymmetricTensor result) {
+
+	TensorArray tensorTranspose;
+	TensorArray fullTensorResult;
+
+
+	TensorArray_Transpose(tensor, dim, tensorTranspose);
+	TensorArray_MultiplyByTensorArray(tensor, tensorTranspose, dim, fullTensorResult);
+	
+	/** Answer is automatically a symmetric tensor by definition */	
+	TensorArray_GetSymmetricPart( fullTensorResult, dim, result ) ;
+
+	return;
+}
+
+/** Multiplies tensor A, on the left by it's transpose, A^T to give A^T * A 
+And returns the answer in a symmetric tensor*/
+void TensorArray_MultiplyByLeftTranspose(TensorArray tensor, Dimension_Index dim, SymmetricTensor result) {
+
+	TensorArray tensorTranspose;
+	TensorArray fullTensorResult;
+
+	TensorArray_Transpose( tensor, dim, tensorTranspose);
+	TensorArray_MultiplyByTensorArray( tensorTranspose, tensor, dim, fullTensorResult );
+	
+	/** Answer is automatically a symmetric tensor by definition */	
+	TensorArray_GetSymmetricPart( fullTensorResult, dim, result);
+	return;
+}
+
+/**	Multiplies TensorArray by SymmetricTensor, and gives answer in a TensorArray:
+	A * symB */
+void TensorArray_MultiplyBySymmetricTensor(	TensorArray tensorArray, SymmetricTensor symmetricTensor,
+											Dimension_Index dim, TensorArray result)
+{
+switch (dim) {
+        case 3:
+            result[FT3D_00] = 	tensorArray[FT3D_00] * symmetricTensor[ST3D_00] 
+							+ 	tensorArray[FT3D_01] * symmetricTensor[ST3D_01]
+							+ 	tensorArray[FT3D_02] * symmetricTensor[ST3D_02];
+		
+            result[FT3D_01] =	tensorArray[FT3D_00] * symmetricTensor[ST3D_01]
+							+	tensorArray[FT3D_01] * symmetricTensor[ST3D_11]
+							+	tensorArray[FT3D_02] * symmetricTensor[ST3D_12];
+        
+			result[FT3D_02] =	tensorArray[FT3D_00] * symmetricTensor[ST3D_02]
+							+	tensorArray[FT3D_01] * symmetricTensor[ST3D_12]
+							+ 	tensorArray[FT3D_02] * symmetricTensor[ST3D_22];
+
+            result[FT3D_10] =	tensorArray[FT3D_10] * symmetricTensor[ST3D_00]
+							+	tensorArray[FT3D_11] * symmetricTensor[ST3D_01]
+							+	tensorArray[FT3D_12] * symmetricTensor[ST3D_02];
+		
+            result[FT3D_11] =	tensorArray[FT3D_10] * symmetricTensor[ST3D_01]
+							+ 	tensorArray[FT3D_11] * symmetricTensor[ST3D_11]
+							+	tensorArray[FT3D_12] * symmetricTensor[ST3D_12];
+        
+			result[FT3D_12] =	tensorArray[FT3D_10] * symmetricTensor[ST3D_02]
+							+ 	tensorArray[FT3D_11] * symmetricTensor[ST3D_12]
+							+	tensorArray[FT3D_12] * symmetricTensor[ST3D_22];
+
+            result[FT3D_20] =	tensorArray[FT3D_20] * symmetricTensor[ST3D_00]
+							+	tensorArray[FT3D_21] * symmetricTensor[ST3D_01]
+							+	tensorArray[FT3D_22] * symmetricTensor[ST3D_02];
+							
+            result[FT3D_21]	=	tensorArray[FT3D_20] * symmetricTensor[ST3D_01]
+							+	tensorArray[FT3D_21] * symmetricTensor[ST3D_11]
+							+	tensorArray[FT3D_22] * symmetricTensor[ST3D_12];
+							
+            result[FT3D_22] =	tensorArray[FT3D_20] * symmetricTensor[ST3D_02]
+							+	tensorArray[FT3D_21] * symmetricTensor[ST3D_12]
+							+	tensorArray[FT3D_22] * symmetricTensor[ST3D_22];
+            return;
+        case 2:
+            result[FT2D_00]	=	tensorArray[FT2D_00] * symmetricTensor[ST2D_00] 
+							+ 	tensorArray[FT2D_01] * symmetricTensor[ST2D_01];
+		
+            result[FT2D_01]	=	tensorArray[FT2D_00] * symmetricTensor[ST2D_01]
+							+ 	tensorArray[FT2D_01] * symmetricTensor[ST2D_11];
+
+            result[FT2D_10]	=	tensorArray[FT2D_10] * symmetricTensor[ST2D_00]
+							+	tensorArray[FT2D_11] * symmetricTensor[ST2D_01];
+		
+            result[FT2D_11]	=	tensorArray[FT2D_10] * symmetricTensor[ST2D_01]
+							+	tensorArray[FT2D_11] * symmetricTensor[ST2D_11];
+            return;
+        default: {
+           Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+           Journal_Printf( error, "Cannot read tensor for dimension %d in %s.\n", dim, __func__);
+           	Journal_Firewall( dim, Journal_Register( Error_Type, (Name)"TensorMultMath"  ),
+				"In func '%s' don't understand dim = %u\n", __func__, dim );;
+            }
+		}
+}
+
+/**	Multiplies SymmetricTensor by TensorArray and gives answer in a TensorArray:
+	symA * B */
+void SymmetricTensor_MultiplyByTensorArray(	TensorArray tensorArray, SymmetricTensor symmetricTensor,
+											Dimension_Index dim, TensorArray result)
+{
+	TensorArray fullTensor;
+	StGermain_SymmetricTensor_ToTensorArray(symmetricTensor, dim, fullTensor);
+	TensorArray_MultiplyByTensorArray(fullTensor, tensorArray, dim, result);
+	return;
+}
+
+/** Multiplies a tensorArray by vector on the left: v * A */
+void TensorArray_MultiplyByLeftVector(	TensorArray tensorArray, double* vector, 
+										Dimension_Index dim, double* result) 
+{
+	switch (dim) {
+		case 3:
+			result[0] = vector[0] * tensorArray[FT3D_00] +
+						vector[1] * tensorArray[FT3D_10] +
+						vector[2] * tensorArray[FT3D_20];
+		
+			result[1] = vector[0] * tensorArray[FT3D_01] +
+						vector[1] * tensorArray[FT3D_11] +
+						vector[2] * tensorArray[FT3D_21];
+		
+			result[2] = vector[0] * tensorArray[FT3D_02] +
+						vector[1] * tensorArray[FT3D_12] +
+						vector[2] * tensorArray[FT3D_22];		
+			return;
+		case 2:
+			result[0] = vector[0] * tensorArray[FT2D_00] 
+					  + vector[1] * tensorArray[FT2D_10];
+		
+			result[1] = vector[0] * tensorArray[FT2D_01] 
+					  + vector[1] * tensorArray[FT2D_11];		
+			return;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}		
+		return;
+}
+
+/** Multiplies a tensorArray by vector on the right:  A * v */
+void TensorArray_MultiplyByRightVector(	TensorArray tensorArray, double* vector, 
+										Dimension_Index dim, double* result)
+{
+	switch (dim) {
+		case 3:
+			result[0] = tensorArray[FT3D_00] * vector[0] +
+						tensorArray[FT3D_01] * vector[1] +
+						tensorArray[FT3D_02] * vector[2];
+		
+			result[1] = tensorArray[FT3D_10] * vector[0] +
+						tensorArray[FT3D_11] * vector[1] +
+						tensorArray[FT3D_12] * vector[2];
+		
+			result[2] = tensorArray[FT3D_20] * vector[0] +
+						tensorArray[FT3D_21] * vector[1] +
+						tensorArray[FT3D_22] * vector[2];		
+			return;
+		case 2:
+			result[0] = tensorArray[FT2D_00] * vector[0] + 
+						tensorArray[FT2D_01] * vector[1];
+		
+			result[1] = tensorArray[FT2D_10] * vector[0] +
+					  	tensorArray[FT2D_11] * vector[1];		
+			return;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+		}
+	}		
+	return;	
+	
+}
+
+/** Calculates the determinant of a TensorArray*/
+double TensorArray_CalcDeterminant(TensorArray tensorArray, Dimension_Index dim) {
+
+    double determinant;
+    switch ( dim ) {
+        case 3:{
+            determinant =   tensorArray[ FT3D_00] *
+                                ( tensorArray[ FT3D_11 ] * tensorArray[ FT3D_22 ] -
+                                  tensorArray[ FT3D_21 ] * tensorArray[ FT3D_12 ] )
+                            - tensorArray[ FT3D_01 ] *
+                                ( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_22 ] -
+                                  tensorArray[ FT3D_12 ] * tensorArray[ FT3D_20 ] )
+                            + tensorArray[ FT3D_02 ] *
+                                ( tensorArray[ FT3D_10 ] * tensorArray[ FT3D_21 ] -
+                                  tensorArray[ FT3D_11 ] * tensorArray[ FT3D_20 ] );
+            return determinant;
+            }
+        case 2:{
+            determinant = tensorArray[ FT2D_00 ] * tensorArray[ FT2D_11 ]
+                        - tensorArray[ FT2D_10 ] * tensorArray[ FT2D_01 ];
+            return determinant;
+            }
+        default: {
+ 			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+			Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+			Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+        }
+    }
+	return 0;
+}
+
+/** Calculates the inverse of a tensorArray for non-zero determinants.  */
+void TensorArray_CalcInverse(TensorArray tensor, Dimension_Index dim, TensorArray result) {
+	
+	double determinant;
+	/* Calculate determinant */
+	determinant = TensorArray_CalcDeterminant(tensor, dim);	
+	TensorArray_CalcInverseWithDeterminant(tensor, determinant, dim, result);
+	return;
+}
+
+/** Calculates inverse of tensorArray for non-zero determinant when given a value 
+for the determinant. This allows the use of different determinants 
+if such calculation is needed.*/
+void TensorArray_CalcInverseWithDeterminant(TensorArray tensor, double determinant, Dimension_Index dim, TensorArray result) {
+	double  errorValue;
+
+	/* Check if determinant is zero or close to zero*/
+	errorValue = STG_TENSORMULT_ERROR;
+	if (fabs(determinant) <= errorValue) {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+			Journal_Printf( error, "Error in '%s', Cannot calculate inverse of singular tensorArray:\n", 
+							__func__); 
+			Journal_PrintTensorArray( error, tensor, dim);
+			Journal_Printf( error, "Determinant, %g is zero or near zero. \n", determinant);
+		Journal_Firewall( False, Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
+				"In func '%s',TensorArray is singular, cannot divide by zero determinant, %g\n", __func__, determinant );
+		return;		
+	}
+	
+	/** Uses formula : 
+	A^{-1} \= \frac{(-1)^i + j(M_{ij})}{detA} 
+	*/ 
+	switch (dim) {
+			case 3:
+				result[FT3D_00] = ( tensor[FT3D_11] * tensor[FT3D_22] - 
+									tensor[FT3D_21] * tensor[FT3D_12] ) / determinant;
+				result[FT3D_10] = ( tensor[FT3D_20] * tensor[FT3D_12] - 
+									tensor[FT3D_10] * tensor[FT3D_22] ) / determinant;
+				result[FT3D_20] = ( tensor[FT3D_10] * tensor[FT3D_21] - 
+									tensor[FT3D_20] * tensor[FT3D_11] ) / determinant;
+	
+				result[FT3D_01] = ( tensor[FT3D_21] * tensor[FT3D_02] - 
+									tensor[FT3D_01] * tensor[FT3D_22] ) / determinant;
+				result[FT3D_11] = ( tensor[FT3D_00] * tensor[FT3D_22] - 
+									tensor[FT3D_20] * tensor[FT3D_02] ) / determinant;
+				result[FT3D_21] = ( tensor[FT3D_20] * tensor[FT3D_01] - 
+									tensor[FT3D_00] * tensor[FT3D_21] ) / determinant;
+	
+				result[FT3D_02] = ( tensor[FT3D_01] * tensor[FT3D_12] - 
+									tensor[FT3D_11] * tensor[FT3D_02] ) / determinant;
+				result[FT3D_12] = ( tensor[FT3D_10] * tensor[FT3D_02] - 
+									tensor[FT3D_00] * tensor[FT3D_12] ) / determinant;
+				result[FT3D_22] = ( tensor[FT3D_00] * tensor[FT3D_11] - 
+									tensor[FT3D_10] * tensor[FT3D_01] ) / determinant;
+				break;
+			case 2:
+				result[FT2D_00] = tensor[FT2D_11] / determinant;
+				result[FT2D_01] = ( -1.0 * tensor[FT2D_01] ) / determinant;
+				result[FT2D_10] = ( -1.0 * tensor[FT2D_10] ) / determinant;
+				result[FT2D_11] = tensor[FT2D_00] / determinant;
+				break;
+			default: {
+ 				Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+				Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+				Journal_Firewall( dim, error,
+				"In func '%s' don't understand dim = %u\n", __func__, dim );
+				}
+		}
+}
+
+
+/** Calculate double dot product of two tensors */
+double TensorArray_DoubleContraction(TensorArray tensorA,TensorArray tensorB, Dimension_Index dim){
+    double contraction;
+    Dimension_Index i, j;
+	/** \[\sigma:\epsilon=\sum_{i=1}^{n}\sum_{i=1}^{n}\sigma_{ij}\epsilon_{ij}\]  */
+	/* Check dimension */
+	if ( (dim != 2)&&(dim != 3) ) {		
+		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+		Journal_Firewall( dim, error,
+			"In func '%s' don't understand dim = %u\n", __func__, dim );
+	}
+	
+	/* Calculate contraction */
+	contraction = 0.0;
+	for ( i = 0; i < dim; i++) {
+		for (j = 0; j < dim; j++) {
+			contraction = 	contraction + 
+							tensorA[ TensorArray_TensorMap(i, j, dim) ] * 
+							tensorB[ TensorArray_TensorMap(i, j, dim) ];       
+		}        
+	}
+
+    return contraction;
+}
+
+/** Calculate double dot product of two symmteric tensors */
+double SymmetricTensor_DoubleContraction(SymmetricTensor tensorA, SymmetricTensor tensorB, Dimension_Index dim)
+{
+    double contraction;
+    Dimension_Index i, j;
+	
+	/* Check dimension */
+	if ( (dim != 2)&&(dim != 3) ) {		
+		Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+		Journal_Printf( error, "Cannot get tensor value for dimension %d in %s.\n", dim, __func__);
+		Journal_Firewall( dim, error,
+			"In func '%s' don't understand dim = %u\n", __func__, dim );
+	}
+	
+	/* Calculate contraction */
+	contraction = 0.0;
+	for ( i = 0; i < dim; i++) {
+		for (j = 0; j < dim; j++) {
+			contraction = 	contraction + 
+							tensorA[ SymmetricTensor_TensorMap(i, j, dim) ] * 
+							tensorB[ SymmetricTensor_TensorMap(i, j, dim) ];       
+		}        
+	}
+
+    return contraction;
+}
+
+/************ All NonSquareMatrix Functions assume the output Matrix/Vector data structure is already initialised *******/
+/** This function calculates the transpose of a non-square nxm 2D matrix
+	It requires the row and column dimensions, and assumes an answer matrix
+	that is the correct size, ie mxn */
+void NonSquareMatrix_Transpose( double** originalMatrix, Dimension_Index rowDimOrig, 
+	Dimension_Index colDimOrig, double** newMatrix ) {
+	Dimension_Index row_I, col_I;
+	if ((rowDimOrig <=0) || (colDimOrig <=0)) {
+        Stream* error = Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  );
+
+		Journal_Firewall( False, error,
+				"In func '%s' don't understand rows = %u or cols = %u\n", 
+			__func__, rowDimOrig, colDimOrig );
+	}
+	for( row_I = 0 ; row_I < rowDimOrig ; row_I++ ) {
+		for( col_I = 0 ; col_I < colDimOrig ; col_I++ ) {
+			newMatrix[ col_I ][ row_I ] = originalMatrix[ row_I ][ col_I ];
+		}
+	}
+	return;
+}
+
+/** This function multiplies 2 non square matrices and returns the in the resultMatrix. 
+ * It requires the columns in MatrixA = rows in BMatrix
+ * resultMatrix_ik = AMatrix_ij x BMatrix_jk */
+void NonSquareMatrix_MultiplicationByNonSquareMatrix( double **AMatrix, int rowDimA, int colDimA,
+					 double **BMatrix, int rowDimB, int colDimB, 
+					 double** resultMatrix ) {
+	int counter;
+	for( counter = 0 ; counter < rowDimA ; counter++ ) {
+		memset( resultMatrix[counter], 0, sizeof( double ) * colDimB );
+	}
+
+	NonSquareMatrix_CumulativeMultiplicationByNonSquareMatrix(AMatrix,rowDimA,colDimA,
+		 	BMatrix,rowDimB, colDimB, 
+			resultMatrix );	
+	
+}
+
+/** This function multiplies 2 non square matrices and adds the result to the passed in resultMatrix. 
+ * It requires the columns in MatrixA = rows in BMatrix
+ * resultMatrix_ik += AMatrix_ij x BMatrix_jk */
+void NonSquareMatrix_CumulativeMultiplicationByNonSquareMatrix( double **AMatrix, 
+					 int rowDimA, int colDimA,
+					 double **BMatrix, int rowDimB, int colDimB, 
+					 double** resultMatrix ) {
+			
+  int row_I, col_I; /* location with resultMatrix  */
+  int counter;      /* counter which facilitates the multiplication of AMatrix and BMatrix */
+	/** Error Checking Code */				 
+	Journal_Firewall( (colDimA == rowDimB), Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
+			"In func '%s'  row dimension B, %u != column dimension A, %u\n", 
+		__func__, rowDimB, colDimA );
+	Journal_Firewall( (AMatrix && BMatrix && resultMatrix), Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
+			"In func '%s', Input matrices: %s %s, or Output matrix: %s is NULL \n", 
+		__func__, AMatrix, BMatrix, resultMatrix);
+
+	/** Calculate result matrix */
+	for( row_I = 0 ; row_I < rowDimA ; row_I++ ) {
+		for( col_I = 0 ; col_I < colDimB ; col_I++ ) {
+			/** resultMatrix[ row_I ][ col_I] = AMatrix_ij x BMatrix_jk */
+		       	for( counter = 0 ; counter < colDimA ; counter++ ) {
+				resultMatrix[ row_I ][ col_I ] += ( AMatrix[row_I][counter] * BMatrix[counter][col_I] );
+			}
+		}
+	}
+}
+
+/** This function multiplies a M x N matrices by a N vector.. It requires the columns in AMatrix = rows in BVec
+	resultVector_i = AMatrix_ij x BVec_j */
+void NonSquareMatrix_MatrixVectorMultiplication( double** AMatrix, int rowsInA, int colsInA,
+		     double* BVec, int rowsInB,double* resultVector ) {
+  /*This assumes the resultVector is of the correct length. */
+	memset(resultVector,0,sizeof(double)* rowsInA);		 
+	NonSquareMatrix_CumulativeMatrixVectorMultiplication( AMatrix, rowsInA, colsInA,
+		                     BVec, rowsInB, resultVector);						   
+}
+
+/** This function multiplies a M x N matrices by a N vector, and then adds this result
+ * to the passed in 'solution Vector'. It requires the columns in MatrixA = rows in BVec
+ * resultVector_i = AMatrix_ij x BVec_j */
+void NonSquareMatrix_CumulativeMatrixVectorMultiplication( double** AMatrix, int rowsInA, int colsInA,
+		                               double* BVec, int rowsInB, double* resultVector ) {
+  int row_I, col_I; /* counters through matrix rows and columns respectively */
+	/** Error Checking Code */  
+	Journal_Firewall( ( colsInA == rowsInB ), Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
+		"In func '%s' column dimensions of A_Matrix = %d is not equal to the row dimensions of B_Vec = %d\n",
+		__func__, colsInA, rowsInB );
+	Journal_Firewall( (resultVector && AMatrix && BVec) , Journal_Register( ErrorStream_Type, (Name)"TensorMultMath"  ),
+		"In func '%s', Input matrices: %p %p, or Output matrix: %p is NULL \n", 
+		__func__, AMatrix, BVec, resultVector);
+
+	/* calculate the result Vector */
+	for( row_I = 0 ; row_I < rowsInA ; row_I++ ) {
+		for( col_I = 0 ; col_I < colsInA ; col_I++ ) {
+			resultVector[ row_I ] += AMatrix[ row_I ][ col_I ] * BVec[ col_I ];
+		}
+	}
+}
+
+/** Prints out a non square matrix if given the row and col dimension */
+void Journal_PrintNonSquareMatrix_Unnamed( Stream* stream, double** NonSquareMatrix, 
+	Dimension_Index rowDim, Dimension_Index colDim ) 
+{
+	Dimension_Index row_I, col_I;
+
+	/* For efficency - Check if stream is enabled */
+	if (!Stream_IsEnable(stream)) return;
+	
+	for ( row_I = 0 ; row_I < rowDim ; row_I++ ) {
+		for ( col_I = 0 ; col_I < colDim ; col_I++ ) {
+			Journal_Printf( stream, "%7.5g	", NonSquareMatrix[row_I][col_I] );
+			}
+		Journal_Printf( stream, "\n" );
+	}
+		
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/TrigMath.c
--- a/Geometry/src/TrigMath.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TrigMath.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-#include <math.h>
-
-#include "units.h"
-#include "types.h"
-#include "TrigMath.h"
-
-#include <assert.h>
-
-#define RADIUS sphericalCoords[0]
-#define THETA  sphericalCoords[1]
-#define PHI    sphericalCoords[2]
-#define X      rectangularCoords[0]
-#define Y      rectangularCoords[1]
-#define Z      rectangularCoords[2]
-
-/** StGermain_RectangularToSpherical - Converts a from rectanglar coordinates to spherical coordinates */
-/* Macros (X, Y, Z) and (RADIUS, THETA, PHI) are used for clarity - See macros defined above */
-void StGermain_RectangularToSpherical(double* sphericalCoords, double* rectangularCoords, Index dim) {
-	double theta_sin_solution1, theta_sin_solution2;
-	double theta_cos_solution1, theta_cos_solution2;
-	
-	if (dim == 2) {
-		RADIUS = sqrt(X*X + Y*Y);
-
-		/* Get first solution for arcos */
-		theta_cos_solution1 = acos(X/RADIUS);		
-		
-		/* Get first solution for arcsin */
-		theta_sin_solution1 = asin(Y/RADIUS);		
-	}
-	else if (dim == 3) { 
-		RADIUS = sqrt(X*X + Y*Y + Z*Z);
-		PHI = acos(Z/RADIUS);
-
-		/* Get first solution for arcos */
-		theta_cos_solution1 = acos( X/ (RADIUS*sin(PHI)) );		/* Solution is between 0 and PI i.e. quadrant 1 and 2 */
-		
-		/* Get first solution for arcsin */
-		theta_sin_solution1 = asin( Y/(RADIUS*sin(PHI)) );		/* Solution is between -PI/2 and PI/2 i.e. quadrant 1 and 4 */
-	}
-	else {
-		Stream* error = Journal_Register( Error_Type , (Name)__FILE__  );
-		Journal_Printf( error, "Func %s does not work with dimension %u\n", __func__, dim );
-		exit(EXIT_FAILURE);
-	}
-
-	/* Get second solution for arcos */
-	theta_cos_solution2 = 2.0 * M_PI - theta_cos_solution1;			/* Solution is between PI and 2 PI - i.e. quadrant 3 and 4 */
-
-	/* Get second solution for arcsin */
-	theta_sin_solution2 = M_PI - theta_sin_solution1;			/* Solution is between PI/2 and 3PI/2 - i.e. quadrant 2 and 3 */
-	
-	/* Find sine and cosine solutions that match up */
-	if ( StGermain_TrigQuadrant( theta_cos_solution1 ) ==  StGermain_TrigQuadrant(theta_sin_solution1) 
-		||  StGermain_TrigQuadrant( theta_cos_solution1 ) ==  StGermain_TrigQuadrant( theta_sin_solution2 ) ) { 
-		THETA = theta_cos_solution1;
-	}
-	else { 
-		THETA = theta_cos_solution2;
-	}
-}
-
-
-/** StGermain_SphericalToRectangular - Converts a from spherical coordinates to rectanglar coordinates */
-/* Macros (X, Y, Z) and (RADIUS, THETA, PHI) are used for clarity - See macros defined above */
-void StGermain_SphericalToRectangular(double* rectangularCoords, double* sphericalCoords, Index dim) {
-	X = RADIUS * cos(THETA);
-	Y = RADIUS * sin(THETA);
-	
-	if (dim == 3) {
-		X = X * sin(PHI);
-		Y = Y * sin(PHI);
-		Z = RADIUS * cos(PHI);
-	}
-}
-
-/** StGermain_TrigDomain - Gets angle into domain between 0 and 2\pi */
-double StGermain_TrigDomain(double angle) {
-	if (angle > 0)
-		return fmod( angle, 2.0 * M_PI );
-	else 
-		return (2.0 * M_PI - fmod( fabs(angle), 2.0 * M_PI ));
-}
-
-/** StGermain_TrigQuadrant - Returns 0 (UPPER_RIGHT_QUADRANT), 1 (UPPER_LEFT_QUADRANT), 
-2 (LOWER_RIGHT_QUADRANT), or 3 (LOWER_RIGHT_QUADRANT) depending on what quadrant the angle is in */
-char StGermain_TrigQuadrant(double angle) {
-	/* Gets radian into correct domain */
-	angle = StGermain_TrigDomain(angle);
-	
-	/* return angle * \frac{2}{\pi} */
-	return (char) (angle * M_2_PI);
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/TrigMath.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/TrigMath.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,129 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TrigMath.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+#include <math.h>
+
+#include "units.h"
+#include "types.h"
+#include "TrigMath.h"
+
+#include <assert.h>
+
+#define RADIUS sphericalCoords[0]
+#define THETA  sphericalCoords[1]
+#define PHI    sphericalCoords[2]
+#define X      rectangularCoords[0]
+#define Y      rectangularCoords[1]
+#define Z      rectangularCoords[2]
+
+/** StGermain_RectangularToSpherical - Converts a from rectanglar coordinates to spherical coordinates */
+/* Macros (X, Y, Z) and (RADIUS, THETA, PHI) are used for clarity - See macros defined above */
+void StGermain_RectangularToSpherical(double* sphericalCoords, double* rectangularCoords, Index dim) {
+	double theta_sin_solution1, theta_sin_solution2;
+	double theta_cos_solution1, theta_cos_solution2;
+	
+	if (dim == 2) {
+		RADIUS = sqrt(X*X + Y*Y);
+
+		/* Get first solution for arcos */
+		theta_cos_solution1 = acos(X/RADIUS);		
+		
+		/* Get first solution for arcsin */
+		theta_sin_solution1 = asin(Y/RADIUS);		
+	}
+	else if (dim == 3) { 
+		RADIUS = sqrt(X*X + Y*Y + Z*Z);
+		PHI = acos(Z/RADIUS);
+
+		/* Get first solution for arcos */
+		theta_cos_solution1 = acos( X/ (RADIUS*sin(PHI)) );		/* Solution is between 0 and PI i.e. quadrant 1 and 2 */
+		
+		/* Get first solution for arcsin */
+		theta_sin_solution1 = asin( Y/(RADIUS*sin(PHI)) );		/* Solution is between -PI/2 and PI/2 i.e. quadrant 1 and 4 */
+	}
+	else {
+		Stream* error = Journal_Register( Error_Type , (Name)__FILE__  );
+		Journal_Printf( error, "Func %s does not work with dimension %u\n", __func__, dim );
+		exit(EXIT_FAILURE);
+	}
+
+	/* Get second solution for arcos */
+	theta_cos_solution2 = 2.0 * M_PI - theta_cos_solution1;			/* Solution is between PI and 2 PI - i.e. quadrant 3 and 4 */
+
+	/* Get second solution for arcsin */
+	theta_sin_solution2 = M_PI - theta_sin_solution1;			/* Solution is between PI/2 and 3PI/2 - i.e. quadrant 2 and 3 */
+	
+	/* Find sine and cosine solutions that match up */
+	if ( StGermain_TrigQuadrant( theta_cos_solution1 ) ==  StGermain_TrigQuadrant(theta_sin_solution1) 
+		||  StGermain_TrigQuadrant( theta_cos_solution1 ) ==  StGermain_TrigQuadrant( theta_sin_solution2 ) ) { 
+		THETA = theta_cos_solution1;
+	}
+	else { 
+		THETA = theta_cos_solution2;
+	}
+}
+
+
+/** StGermain_SphericalToRectangular - Converts a from spherical coordinates to rectanglar coordinates */
+/* Macros (X, Y, Z) and (RADIUS, THETA, PHI) are used for clarity - See macros defined above */
+void StGermain_SphericalToRectangular(double* rectangularCoords, double* sphericalCoords, Index dim) {
+	X = RADIUS * cos(THETA);
+	Y = RADIUS * sin(THETA);
+	
+	if (dim == 3) {
+		X = X * sin(PHI);
+		Y = Y * sin(PHI);
+		Z = RADIUS * cos(PHI);
+	}
+}
+
+/** StGermain_TrigDomain - Gets angle into domain between 0 and 2\pi */
+double StGermain_TrigDomain(double angle) {
+	if (angle > 0)
+		return fmod( angle, 2.0 * M_PI );
+	else 
+		return (2.0 * M_PI - fmod( fabs(angle), 2.0 * M_PI ));
+}
+
+/** StGermain_TrigQuadrant - Returns 0 (UPPER_RIGHT_QUADRANT), 1 (UPPER_LEFT_QUADRANT), 
+2 (LOWER_RIGHT_QUADRANT), or 3 (LOWER_RIGHT_QUADRANT) depending on what quadrant the angle is in */
+char StGermain_TrigQuadrant(double angle) {
+	/* Gets radian into correct domain */
+	angle = StGermain_TrigDomain(angle);
+	
+	/* return angle * \frac{2}{\pi} */
+	return (char) (angle * M_2_PI);
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/VectorMath.c
--- a/Geometry/src/VectorMath.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,479 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: VectorMath.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-
-
-#include "units.h"
-#include "types.h"
-#include "VectorMath.h"
-#include "TrigMath.h"
-
-#include <math.h>
-#include <assert.h>
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-/** (Assumes 3D) Define a cross product of 2 vectors */
-void Vec_Cross3D( double* dst, double* a, double* b ) {
-	double	tmp[3];
-
-	tmp[0] = a[1] * b[2] - a[2] * b[1];
-	tmp[1] = a[2] * b[0] - a[0] * b[2];
-	tmp[2] = a[0] * b[1] - a[1] * b[0];
-
-	Vec_Set3D( dst, tmp );
-}
-
-/** (Assumes 3D) Divide a vector by a real */
-void Vec_Div2D( double* dst, double* a, double s ) {
-	double	inv = 1.0 / s;
-
-	Vec_Scale2D( dst, a, inv );
-}
-
-void Vec_Div3D( double* dst, double* a, double s ) {
-	double	inv = 1.0 / s;
-
-	Vec_Scale3D( dst, a, inv );
-}
-
-/** Calculate the normal of the vector. (ie length = 1 )*/
-void Vec_Norm3D( double* dst, double* a ) {
-	double	invMag = 1.0 / Vec_Mag3D( a );
-
-	Vec_Scale3D( dst, a, invMag );
-}
-
-void Vec_Norm2D( double* dst, double* a ) {
-	double	invMag = 1.0 / Vec_Mag2D( a );
-
-	Vec_Scale2D( dst, a, invMag );
-}
-
-/** Swap coordinates according to i,j, k index */
-void Vec_Swizzle( double* dst, double* src, unsigned char iInd, unsigned char jInd, unsigned char kInd ) {
-	assert( iInd < 3 && jInd < 3 && kInd < 3 );
-	
-	dst[0] = src[iInd];
-	dst[1] = src[jInd];
-	dst[2] = src[kInd];
-}
-
-
-/** StGermain_RotateVector takes an argument 'vectorToRotate', to rotate around a second vector 'axis' through an angle 
-'theta' radians. The rotated vector is stored in vector from the first argument. Each vector: 'rotatedVector', 
-'vectorToRotate' and 'axis' must be the size of 3 doubles. The function uses Rodrigues' Rotation Formula 
-which was taken from: 
-Eric W. Weisstein et al. "Rodrigues' Rotation Formula." From MathWorld--A Wolfram Web Resource. 
-http://mathworld.wolfram.com/RodriguesRotationFormula.html. */
-void StGermain_RotateVector(double* rotatedVector, double* vector, double* w, double theta) {
-	double rotationMatrix[3][3]; 	/* Indicies [Column][Row] */
-	double cosTheta = cos(theta);
-	double sinTheta = sin(theta);
-	
-	rotationMatrix[0][0] = cosTheta + w[0] * w[0] * (1.0 - cosTheta);
-	rotationMatrix[0][1] = w[0] * w[1] * (1.0 - cosTheta) - w[2] * sinTheta;
-	rotationMatrix[0][2] = w[1] * sinTheta + w[0] * w[2] * (1.0 - cosTheta);
-
-	rotationMatrix[1][0] = w[2] * sinTheta + w[0] * w[1] * (1.0 - cosTheta);
-	rotationMatrix[1][1] = cosTheta + w[1] * w[1] * (1.0 - cosTheta);
-	rotationMatrix[1][2] = -w[0] * sinTheta + w[1] * w[2] * (1.0 - cosTheta);
-	
-	rotationMatrix[2][0] = -w[1] * sinTheta + w[0] * w[2] * (1.0 - cosTheta);
-	rotationMatrix[2][1] = w[0] * sinTheta + w[1] * w[2] * (1.0 - cosTheta);
-	rotationMatrix[2][2] = cosTheta + w[2] * w[2] * (1.0 - cosTheta);
-
-	rotatedVector[0] = rotationMatrix[0][0]*vector[0] + rotationMatrix[0][1]*vector[1] + rotationMatrix[0][2]*vector[2];
-	rotatedVector[1] = rotationMatrix[1][0]*vector[0] + rotationMatrix[1][1]*vector[1] + rotationMatrix[1][2]*vector[2];
-	rotatedVector[2] = rotationMatrix[2][0]*vector[0] + rotationMatrix[2][1]*vector[1] + rotationMatrix[2][2]*vector[2];
-}		
-
-/** StGermain_RotateCoordinateAxis multiplies a vector with a Rotation Matrix to rotate it around a co-ordinate axis -
-Is a simpler function than StGermain_RotateVector for more specific cases where the vector is to be rotated around one of the axes of the co-ordinate system. The arguments are the same except the the 'axis' argument is of type 'Index' which could be either I_AXIS, J_AXIS or K_AXIS. Vectors have to be the size of 3 doubles.
-See, Eric W. Weisstein. "Rotation Matrix." 
-From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/RotationMatrix.htm */
-void StGermain_RotateCoordinateAxis( double* rotatedVector, double* vector, Index axis, double theta ) {
-	
-	/* Rotation around one axis will always leave the component on that axis alone */
-	rotatedVector[axis] = vector[axis];
-	
-	switch (axis) {
-		case K_AXIS: /* Rotate around Z axis */
-			rotatedVector[0] =  vector[0]*cos(theta) - vector[1]*sin(theta);
-			rotatedVector[1] =  vector[0]*sin(theta) + vector[1]*cos(theta);
-			return;
-		case I_AXIS:  /* Rotate around X axis */
-			rotatedVector[1] =  vector[1]*cos(theta) - vector[2]*sin(theta);
-			rotatedVector[2] =  vector[1]*sin(theta) + vector[2]*cos(theta);
-			return;
-		case J_AXIS: /* Rotate around Y axis */
-			rotatedVector[0] =  vector[0]*cos(theta) + vector[2]*sin(theta);
-			rotatedVector[2] = -vector[0]*sin(theta) + vector[2]*cos(theta);
-			return;
-		default: {
-			Stream* error = Journal_Register( ErrorStream_Type, (Name)"VectorMath"  );
-			Journal_Printf( error, "Impossible axis to rotate around in %s.", __func__);
-			exit(EXIT_FAILURE);
-		}
-	}
-}
-
-/** Subtracts one vector from another - 
-destination = vector1 - vector2
-Destination vector may be the same as either of the other two input vectors 
-Function is optimised for 1-3 dimensions but will work for any dimension */
-void StGermain_VectorSubtraction(double* destination, double* vector1, double* vector2, Index dim) {
-	switch (dim) {
-		case 3: 
-			destination[2] = vector1[2] - vector2[2];
-		case 2:
-			destination[1] = vector1[1] - vector2[1];
-		case 1: 
-			destination[0] = vector1[0] - vector2[0];
-			return;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				destination[d] = vector1[d] - vector2[d];
-			return;
-		}
-	}	
-}
-
-/** Adds two vectors - 
-destination = vector1 + vector2
-Destination vector may be the same as either of the other two input vectors 
-Function is optimised for 1-3 dimensions but will work for any dimension */
-void StGermain_VectorAddition(double* destination, double* vector1, double* vector2, Index dim) {
-	switch (dim) {
-		case 3: 
-			destination[2] = vector1[2] + vector2[2];
-		case 2:
-			destination[1] = vector1[1] + vector2[1];
-		case 1: 
-			destination[0] = vector1[0] + vector2[0];
-			return;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				destination[d] = vector1[d] + vector2[d];
-			return;
-		}
-	}	
-}
-
-/** StGermain_VectorMagnitude calculates the magnitude of a vector
-|v| = \sqrt{ v . v } 
-This function uses function StGermain_VectorDotProduct to calculate v . v. 
-Vector has to be of size dim doubles */
-double StGermain_VectorMagnitude(double* vector, Index dim) {
-	return sqrt(StGermain_VectorDotProduct(vector,vector,dim));
-}
-
-/** StGermain_VectorDotProduct calculates the magnitude of a vector
-|v| = \sqrt{ v . v } 
-This function uses function StGermain_VectorDotProduct to calculate v . v. 
-Vectors have to be of size dim doubles
-*/
-double StGermain_VectorDotProduct(double* vector1, double* vector2, Index dim) {
-	double dotProduct = 0.0;
-
-	switch (dim) {
-		case 3:	
-			dotProduct = dotProduct + vector1[2] * vector2[2];
-		case 2:
-			dotProduct = dotProduct + vector1[1] * vector2[1];
-		case 1:
-			dotProduct = dotProduct + vector1[0] * vector2[0];
-			break;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				dotProduct = dotProduct + vector1[d] * vector2[d];
-			break;
-		}
-	}
-	
-	return dotProduct;
-}
-
-/** See Eric W. Weisstein. "Cross Product." 
-From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
-Tested against http://www.engplanet.com/redirect.html?3859 */
-void StGermain_VectorCrossProduct(double* destination, double* vector1, double* vector2) {
-	destination[0] = vector1[1]*vector2[2] - vector1[2]*vector2[1];
-	destination[1] = vector1[2]*vector2[0] - vector1[0]*vector2[2];
-	destination[2] = vector1[0]*vector2[1] - vector1[1]*vector2[0];
-}
-
-/** StGermain_VectorCrossProductMagnitude - See Eric W. Weisstein. "Cross Product." 
-From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
-|a \times b| = |a||b|\sqrt{ 1 - (\hat a . \hat b)^2}
-*/
-double StGermain_VectorCrossProductMagnitude( double* vector1, double* vector2, Dimension_Index dim ) {
-	double mag1       = StGermain_VectorMagnitude( vector1, dim );
-	double mag2       = StGermain_VectorMagnitude( vector2, dim );
-	double dotProduct = StGermain_VectorDotProduct( vector1, vector2, dim );
-	
-	return mag1 * mag2 * sqrt( 1.0 - dotProduct * dotProduct / (mag1 * mag1 * mag2 * mag2) );
-}
-
-
-/** StGermain_ScalarTripleProduct - Calculates the scalar vector product of three vectors -
- * see Eric W. Weisstein. "Scalar Triple Product." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ScalarTripleProduct.html
- * Assumes 3 Dimensions */
-double StGermain_ScalarTripleProduct( double* vectorA, double* vectorB, double* vectorC ) {
-	double crossProduct[3];
-	
-	StGermain_VectorCrossProduct( crossProduct, vectorB, vectorC );
-	return StGermain_VectorDotProduct( vectorA, crossProduct, 3 );
-}
-
-
-/** StGermain_VectorNormalise calculates the magnitude of a vector
-\hat v = frac{v} / {|v|}
-This function uses function StGermain_VectorDotProduct to calculate v . v. 
-Vector has to be of size dim doubles */
-void StGermain_VectorNormalise(double* vector, Index dim) {
-	double mag;
-
-	mag = StGermain_VectorMagnitude( vector , dim );
-	switch (dim) {
-		case 3: 
-			vector[2] = vector[2]/mag;
-		case 2:
-			vector[1] = vector[1]/mag;
-		case 1: 
-			vector[0] = vector[0]/mag;
-			break;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				vector[d] = vector[d]/mag;
-			break;
-		}
-	}	
-}
-
-/** Finds the angle between two vectors 
-\cos{\theta} = \frac{a.b}{|a||b|}
-Uses StGermain_AngleBetweenVectors and StGermain_VectorMagnitude
-Vectors has to be of size dim doubles */
-double StGermain_AngleBetweenVectors( double* vectorA, double* vectorB, Index dim ) {
-	double dotProduct = StGermain_VectorDotProduct(vectorA, vectorB, dim);
-	double magA = StGermain_VectorMagnitude( vectorA, dim );
-	double magB = StGermain_VectorMagnitude( vectorB, dim );
-
-	double value = dotProduct/ (magA * magB);
-
-	if (value >= 1.0)
-		return 0.0;
-	if (value <= -1.0)
-		return M_PI;
-
-	return acos( value );
-}
-
-/** Calculates the distance between two points - given by their position vectors relative to the origin
-distance = |a - b|
-Uses StGermain_VectorSubtraction and StGermain_VectorMagnitude
-Position vectors have to be of size dim doubles */
-double StGermain_DistanceBetweenPoints( double* pos1, double* pos2, Index dim) {
-	double mag;
-	double *vector;
-	
-	/* Allocate memory */
-	vector = Memory_Alloc_Array( double, dim, "Vector" );
-	
-	/* vector between points */
-	StGermain_VectorSubtraction( vector, pos1, pos2, dim ) ;
-	mag = StGermain_VectorMagnitude( vector, dim );
-
-	Memory_Free( vector );
-	return mag;
-}
-
-/** Given three points which define a plane, StGermain_NormalToPlane will give the unit vector which is normal to that plane
-Uses StGermain_VectorSubtraction, StGermain_VectorCrossProduct and StGermain_VectorNormalise
-Position vectors and normal have to be of size 3 doubles */
-void StGermain_NormalToPlane( double* normal, double* pos0, double* pos1, double* pos2) {
-	double vector1[3], vector2[3];
-
-	StGermain_VectorSubtraction( vector1, pos1, pos0, 3) ;
-	StGermain_VectorSubtraction( vector2, pos2, pos0, 3) ;
-	
-	StGermain_VectorCrossProduct( normal, vector1, vector2 );
-
-	StGermain_VectorNormalise( normal, 3 );
-}
-
-#define ONE_THIRD 0.3333333333333333333
-/** Calculates the position vector to the centroid of a triangle whose vertices are given by position vectors 
-Position vectors have to be of size dim doubles */
-void StGermain_TriangleCentroid( double* centroid, double* pos0, double* pos1, double* pos2, Index dim) {
-
-	switch (dim) {
-		case 3:
-			centroid[2] = ONE_THIRD * (pos0[2] + pos1[2] + pos2[2]);
-		case 2: 
-			centroid[1] = ONE_THIRD * (pos0[1] + pos1[1] + pos2[1]);
-		case 1:
-			centroid[0] = ONE_THIRD * (pos0[0] + pos1[0] + pos2[0]);
-			return;
-		default: {
-			Index d;
-			for ( d = 0 ; d < dim ; d++ ) 
-				centroid[d] = ONE_THIRD * (pos0[d] + pos1[d] + pos2[d]);
-			return;
-		}
-	}
-}
-
-/** Calculates the area of a triangle whose vertices are given by position vectors 
-Position vectors have to be of size dim doubles 
-Only works for dim == 2 or dim == 3
-*/
-double StGermain_TriangleArea( double* pos0, double* pos1, double* pos2, Index dim ) {
-	double normal[3];
-	double vector1[3], vector2[3];
-	double area;
-
-	if (dim != 2 && dim != 3) return 0.0;
-
-	vector1[2] = vector2[2] = 0.0;
-
-	StGermain_VectorSubtraction( vector1, pos1, pos0, dim) ;
-	StGermain_VectorSubtraction( vector2, pos2, pos0, dim) ;
-
-	StGermain_VectorCrossProduct( normal, vector1, vector2 );
-	
-	area = 0.5 * StGermain_VectorMagnitude(normal, dim);
-	return area;
-}
-
-/** StGermain_ConvexQuadrilateralArea - See Eric W. Weisstein. "Quadrilateral." 
- * From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Quadrilateral.html
- * Area = \frac{1}{2}| p \times q | where p and q are diagonals of a convex polygon
- * This function will not work for dim > 3 and vertices have to be given in a winding direction
-*/
-double StGermain_ConvexQuadrilateralArea( double* vertexCoord1, double* vertexCoord2, double* vertexCoord3, double* vertexCoord4, Dimension_Index dim ) {
-	Coord diagonal1;	
-	Coord diagonal2;
-
-	/* Calculate Diagonals */
-	StGermain_VectorSubtraction( diagonal1, vertexCoord3, vertexCoord1, dim );
-	StGermain_VectorSubtraction( diagonal2, vertexCoord4, vertexCoord2, dim );
-
-	return 0.5 * StGermain_VectorCrossProductMagnitude( diagonal1, diagonal2, dim );
-}
-
-/** StGermain_ParallelepipedVolume - Calculates the volume of parallelepiped -
- * see Eric W. Weisstein et al. "Parallelepiped." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Parallelepiped.html
- * Assumes 3 Dimensions */
-double StGermain_ParallelepipedVolume( 
-		double* coordLeftBottomFront, 
-		double* coordRightBottomFront, 
-		double* coordLeftTopFront, 
-		double* coordLeftBottomBack ) {
-
-	double vectorA[3], vectorB[3], vectorC[3];
-
-	/* Find vectors which define Parallelepiped */
-	StGermain_VectorSubtraction( vectorA, coordRightBottomFront, coordLeftBottomFront, 3 );
-	StGermain_VectorSubtraction( vectorB, coordLeftTopFront,     coordLeftBottomFront, 3 );
-	StGermain_VectorSubtraction( vectorC, coordLeftBottomBack,   coordLeftBottomFront, 3 );
-
-	return fabs( StGermain_ScalarTripleProduct( vectorA, vectorB, vectorC ) );
-}	
-
-/** StGermain_ParallelepipedVolumeFromCoordList - 
- * shortcut for StGermain_ParallelepipedVolume - assuming nodes laid out in order of
- * 	Left Bottom Front        
- * 	Right Bottom Front        
- * 	Right Top Front
- * 	Left Top_Front             
- * 	Left Bottom Back       
- * 	Right Bottom Back      
- * 	Right Top Back 
- * 	Left Top Back   */
-double StGermain_ParallelepipedVolumeFromCoordList( Coord_List list ) {
-	return StGermain_ParallelepipedVolume( list[ 0 ], list[ 1 ], list[ 3 ], list[ 4 ] );
-}
-
-/** StGermain_AverageCoord - Does simple average of coordinates */
-void StGermain_AverageCoord( double* coord, double** coordList, Index count, Dimension_Index dim ) {
-	double factor = 1.0/(double)count;
-	Index  coord_I;
-	
-	/* Initialise */
-	coord[ I_AXIS ] = coord[ J_AXIS ] = coord[ K_AXIS ] = 0.0;
-
-	/* Sum vertices */
-	for ( coord_I = 0 ; coord_I < count ; coord_I++ ) {
-		coord[ I_AXIS ] += coordList[ coord_I ][ I_AXIS ];
-		coord[ J_AXIS ] += coordList[ coord_I ][ J_AXIS ];
-		if (dim == 3)
-			coord[ K_AXIS ] += coordList[ coord_I ][ K_AXIS ];
-	}
-
-	/* Find Average */
-	coord[ I_AXIS ] *= factor;
-	coord[ J_AXIS ] *= factor;
-	if (dim == 3)
-		coord[ K_AXIS ] *= factor;
-}
-/** Prints a vector of any non-zero positive length 
-Uses %lf print statement*/
-void StGermain_PrintVector( Stream* stream, double* vector, Index dim ) {
-	Index d;
-
-	if ( dim <= 0 ) {
-		Journal_Printf( stream, "{<NON_POSITIVE DIMENSION %d>}\n", dim );
-		return;
-	}
-
-	Journal_Printf( stream, "{");
-	for ( d = 0 ; d < dim - 1 ; d++ ) 
-		Journal_Printf( stream, "%lf, ", vector[d] );
-	
-	Journal_Printf( stream, "%lf}\n", vector[d] );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/src/VectorMath.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/src/VectorMath.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,479 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Robert B. Turnbull, Monash Cluster Computing. (Robert.Turnbull at sci.monash.edu.au)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: VectorMath.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+
+
+#include "units.h"
+#include "types.h"
+#include "VectorMath.h"
+#include "TrigMath.h"
+
+#include <math.h>
+#include <assert.h>
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+/** (Assumes 3D) Define a cross product of 2 vectors */
+void Vec_Cross3D( double* dst, double* a, double* b ) {
+	double	tmp[3];
+
+	tmp[0] = a[1] * b[2] - a[2] * b[1];
+	tmp[1] = a[2] * b[0] - a[0] * b[2];
+	tmp[2] = a[0] * b[1] - a[1] * b[0];
+
+	Vec_Set3D( dst, tmp );
+}
+
+/** (Assumes 3D) Divide a vector by a real */
+void Vec_Div2D( double* dst, double* a, double s ) {
+	double	inv = 1.0 / s;
+
+	Vec_Scale2D( dst, a, inv );
+}
+
+void Vec_Div3D( double* dst, double* a, double s ) {
+	double	inv = 1.0 / s;
+
+	Vec_Scale3D( dst, a, inv );
+}
+
+/** Calculate the normal of the vector. (ie length = 1 )*/
+void Vec_Norm3D( double* dst, double* a ) {
+	double	invMag = 1.0 / Vec_Mag3D( a );
+
+	Vec_Scale3D( dst, a, invMag );
+}
+
+void Vec_Norm2D( double* dst, double* a ) {
+	double	invMag = 1.0 / Vec_Mag2D( a );
+
+	Vec_Scale2D( dst, a, invMag );
+}
+
+/** Swap coordinates according to i,j, k index */
+void Vec_Swizzle( double* dst, double* src, unsigned char iInd, unsigned char jInd, unsigned char kInd ) {
+	assert( iInd < 3 && jInd < 3 && kInd < 3 );
+	
+	dst[0] = src[iInd];
+	dst[1] = src[jInd];
+	dst[2] = src[kInd];
+}
+
+
+/** StGermain_RotateVector takes an argument 'vectorToRotate', to rotate around a second vector 'axis' through an angle 
+'theta' radians. The rotated vector is stored in vector from the first argument. Each vector: 'rotatedVector', 
+'vectorToRotate' and 'axis' must be the size of 3 doubles. The function uses Rodrigues' Rotation Formula 
+which was taken from: 
+Eric W. Weisstein et al. "Rodrigues' Rotation Formula." From MathWorld--A Wolfram Web Resource. 
+http://mathworld.wolfram.com/RodriguesRotationFormula.html. */
+void StGermain_RotateVector(double* rotatedVector, double* vector, double* w, double theta) {
+	double rotationMatrix[3][3]; 	/* Indicies [Column][Row] */
+	double cosTheta = cos(theta);
+	double sinTheta = sin(theta);
+	
+	rotationMatrix[0][0] = cosTheta + w[0] * w[0] * (1.0 - cosTheta);
+	rotationMatrix[0][1] = w[0] * w[1] * (1.0 - cosTheta) - w[2] * sinTheta;
+	rotationMatrix[0][2] = w[1] * sinTheta + w[0] * w[2] * (1.0 - cosTheta);
+
+	rotationMatrix[1][0] = w[2] * sinTheta + w[0] * w[1] * (1.0 - cosTheta);
+	rotationMatrix[1][1] = cosTheta + w[1] * w[1] * (1.0 - cosTheta);
+	rotationMatrix[1][2] = -w[0] * sinTheta + w[1] * w[2] * (1.0 - cosTheta);
+	
+	rotationMatrix[2][0] = -w[1] * sinTheta + w[0] * w[2] * (1.0 - cosTheta);
+	rotationMatrix[2][1] = w[0] * sinTheta + w[1] * w[2] * (1.0 - cosTheta);
+	rotationMatrix[2][2] = cosTheta + w[2] * w[2] * (1.0 - cosTheta);
+
+	rotatedVector[0] = rotationMatrix[0][0]*vector[0] + rotationMatrix[0][1]*vector[1] + rotationMatrix[0][2]*vector[2];
+	rotatedVector[1] = rotationMatrix[1][0]*vector[0] + rotationMatrix[1][1]*vector[1] + rotationMatrix[1][2]*vector[2];
+	rotatedVector[2] = rotationMatrix[2][0]*vector[0] + rotationMatrix[2][1]*vector[1] + rotationMatrix[2][2]*vector[2];
+}		
+
+/** StGermain_RotateCoordinateAxis multiplies a vector with a Rotation Matrix to rotate it around a co-ordinate axis -
+Is a simpler function than StGermain_RotateVector for more specific cases where the vector is to be rotated around one of the axes of the co-ordinate system. The arguments are the same except the the 'axis' argument is of type 'Index' which could be either I_AXIS, J_AXIS or K_AXIS. Vectors have to be the size of 3 doubles.
+See, Eric W. Weisstein. "Rotation Matrix." 
+From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/RotationMatrix.htm */
+void StGermain_RotateCoordinateAxis( double* rotatedVector, double* vector, Index axis, double theta ) {
+	
+	/* Rotation around one axis will always leave the component on that axis alone */
+	rotatedVector[axis] = vector[axis];
+	
+	switch (axis) {
+		case K_AXIS: /* Rotate around Z axis */
+			rotatedVector[0] =  vector[0]*cos(theta) - vector[1]*sin(theta);
+			rotatedVector[1] =  vector[0]*sin(theta) + vector[1]*cos(theta);
+			return;
+		case I_AXIS:  /* Rotate around X axis */
+			rotatedVector[1] =  vector[1]*cos(theta) - vector[2]*sin(theta);
+			rotatedVector[2] =  vector[1]*sin(theta) + vector[2]*cos(theta);
+			return;
+		case J_AXIS: /* Rotate around Y axis */
+			rotatedVector[0] =  vector[0]*cos(theta) + vector[2]*sin(theta);
+			rotatedVector[2] = -vector[0]*sin(theta) + vector[2]*cos(theta);
+			return;
+		default: {
+			Stream* error = Journal_Register( ErrorStream_Type, (Name)"VectorMath"  );
+			Journal_Printf( error, "Impossible axis to rotate around in %s.", __func__);
+			exit(EXIT_FAILURE);
+		}
+	}
+}
+
+/** Subtracts one vector from another - 
+destination = vector1 - vector2
+Destination vector may be the same as either of the other two input vectors 
+Function is optimised for 1-3 dimensions but will work for any dimension */
+void StGermain_VectorSubtraction(double* destination, double* vector1, double* vector2, Index dim) {
+	switch (dim) {
+		case 3: 
+			destination[2] = vector1[2] - vector2[2];
+		case 2:
+			destination[1] = vector1[1] - vector2[1];
+		case 1: 
+			destination[0] = vector1[0] - vector2[0];
+			return;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				destination[d] = vector1[d] - vector2[d];
+			return;
+		}
+	}	
+}
+
+/** Adds two vectors - 
+destination = vector1 + vector2
+Destination vector may be the same as either of the other two input vectors 
+Function is optimised for 1-3 dimensions but will work for any dimension */
+void StGermain_VectorAddition(double* destination, double* vector1, double* vector2, Index dim) {
+	switch (dim) {
+		case 3: 
+			destination[2] = vector1[2] + vector2[2];
+		case 2:
+			destination[1] = vector1[1] + vector2[1];
+		case 1: 
+			destination[0] = vector1[0] + vector2[0];
+			return;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				destination[d] = vector1[d] + vector2[d];
+			return;
+		}
+	}	
+}
+
+/** StGermain_VectorMagnitude calculates the magnitude of a vector
+|v| = \sqrt{ v . v } 
+This function uses function StGermain_VectorDotProduct to calculate v . v. 
+Vector has to be of size dim doubles */
+double StGermain_VectorMagnitude(double* vector, Index dim) {
+	return sqrt(StGermain_VectorDotProduct(vector,vector,dim));
+}
+
+/** StGermain_VectorDotProduct calculates the magnitude of a vector
+|v| = \sqrt{ v . v } 
+This function uses function StGermain_VectorDotProduct to calculate v . v. 
+Vectors have to be of size dim doubles
+*/
+double StGermain_VectorDotProduct(double* vector1, double* vector2, Index dim) {
+	double dotProduct = 0.0;
+
+	switch (dim) {
+		case 3:	
+			dotProduct = dotProduct + vector1[2] * vector2[2];
+		case 2:
+			dotProduct = dotProduct + vector1[1] * vector2[1];
+		case 1:
+			dotProduct = dotProduct + vector1[0] * vector2[0];
+			break;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				dotProduct = dotProduct + vector1[d] * vector2[d];
+			break;
+		}
+	}
+	
+	return dotProduct;
+}
+
+/** See Eric W. Weisstein. "Cross Product." 
+From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
+Tested against http://www.engplanet.com/redirect.html?3859 */
+void StGermain_VectorCrossProduct(double* destination, double* vector1, double* vector2) {
+	destination[0] = vector1[1]*vector2[2] - vector1[2]*vector2[1];
+	destination[1] = vector1[2]*vector2[0] - vector1[0]*vector2[2];
+	destination[2] = vector1[0]*vector2[1] - vector1[1]*vector2[0];
+}
+
+/** StGermain_VectorCrossProductMagnitude - See Eric W. Weisstein. "Cross Product." 
+From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CrossProduct.html 
+|a \times b| = |a||b|\sqrt{ 1 - (\hat a . \hat b)^2}
+*/
+double StGermain_VectorCrossProductMagnitude( double* vector1, double* vector2, Dimension_Index dim ) {
+	double mag1       = StGermain_VectorMagnitude( vector1, dim );
+	double mag2       = StGermain_VectorMagnitude( vector2, dim );
+	double dotProduct = StGermain_VectorDotProduct( vector1, vector2, dim );
+	
+	return mag1 * mag2 * sqrt( 1.0 - dotProduct * dotProduct / (mag1 * mag1 * mag2 * mag2) );
+}
+
+
+/** StGermain_ScalarTripleProduct - Calculates the scalar vector product of three vectors -
+ * see Eric W. Weisstein. "Scalar Triple Product." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/ScalarTripleProduct.html
+ * Assumes 3 Dimensions */
+double StGermain_ScalarTripleProduct( double* vectorA, double* vectorB, double* vectorC ) {
+	double crossProduct[3];
+	
+	StGermain_VectorCrossProduct( crossProduct, vectorB, vectorC );
+	return StGermain_VectorDotProduct( vectorA, crossProduct, 3 );
+}
+
+
+/** StGermain_VectorNormalise calculates the magnitude of a vector
+\hat v = frac{v} / {|v|}
+This function uses function StGermain_VectorDotProduct to calculate v . v. 
+Vector has to be of size dim doubles */
+void StGermain_VectorNormalise(double* vector, Index dim) {
+	double mag;
+
+	mag = StGermain_VectorMagnitude( vector , dim );
+	switch (dim) {
+		case 3: 
+			vector[2] = vector[2]/mag;
+		case 2:
+			vector[1] = vector[1]/mag;
+		case 1: 
+			vector[0] = vector[0]/mag;
+			break;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				vector[d] = vector[d]/mag;
+			break;
+		}
+	}	
+}
+
+/** Finds the angle between two vectors 
+\cos{\theta} = \frac{a.b}{|a||b|}
+Uses StGermain_AngleBetweenVectors and StGermain_VectorMagnitude
+Vectors has to be of size dim doubles */
+double StGermain_AngleBetweenVectors( double* vectorA, double* vectorB, Index dim ) {
+	double dotProduct = StGermain_VectorDotProduct(vectorA, vectorB, dim);
+	double magA = StGermain_VectorMagnitude( vectorA, dim );
+	double magB = StGermain_VectorMagnitude( vectorB, dim );
+
+	double value = dotProduct/ (magA * magB);
+
+	if (value >= 1.0)
+		return 0.0;
+	if (value <= -1.0)
+		return M_PI;
+
+	return acos( value );
+}
+
+/** Calculates the distance between two points - given by their position vectors relative to the origin
+distance = |a - b|
+Uses StGermain_VectorSubtraction and StGermain_VectorMagnitude
+Position vectors have to be of size dim doubles */
+double StGermain_DistanceBetweenPoints( double* pos1, double* pos2, Index dim) {
+	double mag;
+	double *vector;
+	
+	/* Allocate memory */
+	vector = Memory_Alloc_Array( double, dim, "Vector" );
+	
+	/* vector between points */
+	StGermain_VectorSubtraction( vector, pos1, pos2, dim ) ;
+	mag = StGermain_VectorMagnitude( vector, dim );
+
+	Memory_Free( vector );
+	return mag;
+}
+
+/** Given three points which define a plane, StGermain_NormalToPlane will give the unit vector which is normal to that plane
+Uses StGermain_VectorSubtraction, StGermain_VectorCrossProduct and StGermain_VectorNormalise
+Position vectors and normal have to be of size 3 doubles */
+void StGermain_NormalToPlane( double* normal, double* pos0, double* pos1, double* pos2) {
+	double vector1[3], vector2[3];
+
+	StGermain_VectorSubtraction( vector1, pos1, pos0, 3) ;
+	StGermain_VectorSubtraction( vector2, pos2, pos0, 3) ;
+	
+	StGermain_VectorCrossProduct( normal, vector1, vector2 );
+
+	StGermain_VectorNormalise( normal, 3 );
+}
+
+#define ONE_THIRD 0.3333333333333333333
+/** Calculates the position vector to the centroid of a triangle whose vertices are given by position vectors 
+Position vectors have to be of size dim doubles */
+void StGermain_TriangleCentroid( double* centroid, double* pos0, double* pos1, double* pos2, Index dim) {
+
+	switch (dim) {
+		case 3:
+			centroid[2] = ONE_THIRD * (pos0[2] + pos1[2] + pos2[2]);
+		case 2: 
+			centroid[1] = ONE_THIRD * (pos0[1] + pos1[1] + pos2[1]);
+		case 1:
+			centroid[0] = ONE_THIRD * (pos0[0] + pos1[0] + pos2[0]);
+			return;
+		default: {
+			Index d;
+			for ( d = 0 ; d < dim ; d++ ) 
+				centroid[d] = ONE_THIRD * (pos0[d] + pos1[d] + pos2[d]);
+			return;
+		}
+	}
+}
+
+/** Calculates the area of a triangle whose vertices are given by position vectors 
+Position vectors have to be of size dim doubles 
+Only works for dim == 2 or dim == 3
+*/
+double StGermain_TriangleArea( double* pos0, double* pos1, double* pos2, Index dim ) {
+	double normal[3];
+	double vector1[3], vector2[3];
+	double area;
+
+	if (dim != 2 && dim != 3) return 0.0;
+
+	vector1[2] = vector2[2] = 0.0;
+
+	StGermain_VectorSubtraction( vector1, pos1, pos0, dim) ;
+	StGermain_VectorSubtraction( vector2, pos2, pos0, dim) ;
+
+	StGermain_VectorCrossProduct( normal, vector1, vector2 );
+	
+	area = 0.5 * StGermain_VectorMagnitude(normal, dim);
+	return area;
+}
+
+/** StGermain_ConvexQuadrilateralArea - See Eric W. Weisstein. "Quadrilateral." 
+ * From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Quadrilateral.html
+ * Area = \frac{1}{2}| p \times q | where p and q are diagonals of a convex polygon
+ * This function will not work for dim > 3 and vertices have to be given in a winding direction
+*/
+double StGermain_ConvexQuadrilateralArea( double* vertexCoord1, double* vertexCoord2, double* vertexCoord3, double* vertexCoord4, Dimension_Index dim ) {
+	Coord diagonal1;	
+	Coord diagonal2;
+
+	/* Calculate Diagonals */
+	StGermain_VectorSubtraction( diagonal1, vertexCoord3, vertexCoord1, dim );
+	StGermain_VectorSubtraction( diagonal2, vertexCoord4, vertexCoord2, dim );
+
+	return 0.5 * StGermain_VectorCrossProductMagnitude( diagonal1, diagonal2, dim );
+}
+
+/** StGermain_ParallelepipedVolume - Calculates the volume of parallelepiped -
+ * see Eric W. Weisstein et al. "Parallelepiped." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Parallelepiped.html
+ * Assumes 3 Dimensions */
+double StGermain_ParallelepipedVolume( 
+		double* coordLeftBottomFront, 
+		double* coordRightBottomFront, 
+		double* coordLeftTopFront, 
+		double* coordLeftBottomBack ) {
+
+	double vectorA[3], vectorB[3], vectorC[3];
+
+	/* Find vectors which define Parallelepiped */
+	StGermain_VectorSubtraction( vectorA, coordRightBottomFront, coordLeftBottomFront, 3 );
+	StGermain_VectorSubtraction( vectorB, coordLeftTopFront,     coordLeftBottomFront, 3 );
+	StGermain_VectorSubtraction( vectorC, coordLeftBottomBack,   coordLeftBottomFront, 3 );
+
+	return fabs( StGermain_ScalarTripleProduct( vectorA, vectorB, vectorC ) );
+}	
+
+/** StGermain_ParallelepipedVolumeFromCoordList - 
+ * shortcut for StGermain_ParallelepipedVolume - assuming nodes laid out in order of
+ * 	Left Bottom Front        
+ * 	Right Bottom Front        
+ * 	Right Top Front
+ * 	Left Top_Front             
+ * 	Left Bottom Back       
+ * 	Right Bottom Back      
+ * 	Right Top Back 
+ * 	Left Top Back   */
+double StGermain_ParallelepipedVolumeFromCoordList( Coord_List list ) {
+	return StGermain_ParallelepipedVolume( list[ 0 ], list[ 1 ], list[ 3 ], list[ 4 ] );
+}
+
+/** StGermain_AverageCoord - Does simple average of coordinates */
+void StGermain_AverageCoord( double* coord, double** coordList, Index count, Dimension_Index dim ) {
+	double factor = 1.0/(double)count;
+	Index  coord_I;
+	
+	/* Initialise */
+	coord[ I_AXIS ] = coord[ J_AXIS ] = coord[ K_AXIS ] = 0.0;
+
+	/* Sum vertices */
+	for ( coord_I = 0 ; coord_I < count ; coord_I++ ) {
+		coord[ I_AXIS ] += coordList[ coord_I ][ I_AXIS ];
+		coord[ J_AXIS ] += coordList[ coord_I ][ J_AXIS ];
+		if (dim == 3)
+			coord[ K_AXIS ] += coordList[ coord_I ][ K_AXIS ];
+	}
+
+	/* Find Average */
+	coord[ I_AXIS ] *= factor;
+	coord[ J_AXIS ] *= factor;
+	if (dim == 3)
+		coord[ K_AXIS ] *= factor;
+}
+/** Prints a vector of any non-zero positive length 
+Uses %lf print statement*/
+void StGermain_PrintVector( Stream* stream, double* vector, Index dim ) {
+	Index d;
+
+	if ( dim <= 0 ) {
+		Journal_Printf( stream, "{<NON_POSITIVE DIMENSION %d>}\n", dim );
+		return;
+	}
+
+	Journal_Printf( stream, "{");
+	for ( d = 0 ; d < dim - 1 ; d++ ) 
+		Journal_Printf( stream, "%lf, ", vector[d] );
+	
+	Journal_Printf( stream, "%lf}\n", vector[d] );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/ComplexMathSuite.c
--- a/Geometry/tests/ComplexMathSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,453 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ComplexMathSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "ComplexMathSuite.h"
-
-#undef Journal_PrintCmplx
-/** Print a complex number.  Will use %.7f formatting */
-#define Journal_PrintCmplx( stream, self ) \
-                Journal_Printf( stream, #self " = %.7f %c %.7f i\n", (self)[ REAL_PART ], (self)[ IMAG_PART ] >= 0.0 ? '+' : '-', fabs( (self)[ IMAG_PART ] ) )
-
-#define TESTCOMPLEXMATH_TOL 1e-15
-
-typedef struct {
-	MPI_Comm	comm;
-	int rank;
-	int nProcs;
-} ComplexMathSuiteData;
-
-void ComplexMathSuite_Setup( ComplexMathSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void ComplexMathSuite_Teardown( ComplexMathSuiteData* data ) {
-}
-
-void ComplexMathSuite_TestComplexJournalPrintingMacro( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		u = {-1.5, -3};
-		Cmplx		v = {1.5, -3};
-		Cmplx		i = {0, 1};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathPrintingMacro"  );
-		Stream_RedirectFile( stream, "testComplexMathPrintingMacro.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Complex Journal Printing Macro -----------------\n" );
-		Journal_PrintCmplx( stream, x );	
-		Journal_PrintCmplx( stream, y );	
-		Journal_PrintCmplx( stream, u );	
-		Journal_PrintCmplx( stream, v );	
-		Journal_PrintCmplx( stream, i );	
-
-		pcu_filename_expected( "testComplexJournalPrintingMacro.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathPrintingMacro.dat", expected_file );
-		remove( "testComplexMathPrintingMacro.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestAddition( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathAddition"  );
-		Stream_RedirectFile( stream, "testComplexMathAddition.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Addition -----------------\n" );
-		Cmplx_Add( x, y, dest );
-		Cmplx_Add( x, y, x );
-		Journal_PrintCmplx( stream, dest );	
-		Journal_PrintCmplx( stream, x );	
-
-		pcu_filename_expected( "testComplexMathAddition.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathAddition.dat", expected_file );
-		remove( "testComplexMathAddition.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestSubtraction( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathSubtraction"  );
-		Stream_RedirectFile( stream, "testComplexMathSubtraction.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Subtraction -----------------\n" );
-		Cmplx_Subtract( x, y, x );
-		Cmplx_Subtract( x, y, dest );
-		Journal_PrintCmplx( stream, x );
-		Journal_PrintCmplx( stream, dest );
-
-		pcu_filename_expected( "testComplexMathSubtraction.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathSubtraction.dat", expected_file );
-		remove( "testComplexMathSubtraction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestMultiplication( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathMultiplication"  );
-		Stream_RedirectFile( stream, "testComplexMathMultiplication.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Multiplication -----------------\n" );
-		Cmplx_Multiply( x, y, dest );
-		Cmplx_Multiply( x, y, y );
-		Journal_PrintCmplx( stream, dest );	
-		Journal_PrintCmplx( stream, y );	
-
-		pcu_filename_expected( "testComplexMathMultiplication.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathMultiplication.dat", expected_file );
-		remove( "testComplexMathMultiplication.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestDivision( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathDivision"  );
-		Stream_RedirectFile( stream, "testComplexMathDivision.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Division -----------------\n" );
-		Cmplx_Division( y, x, y );
-		Cmplx_Division( x, y, dest );
-		Journal_PrintCmplx( stream, y );	
-		Journal_PrintCmplx( stream, dest );	
-
-		pcu_filename_expected( "testComplexMathDivision.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathDivision.dat", expected_file );
-		remove( "testComplexMathDivision.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestRealNumber( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		y = {-1.5, 3};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathRealNumber"  );
-		Stream_RedirectFile( stream, "testComplexMathRealNumber.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Real Number Math stuff -----------------\n" );
-		Cmplx_AddReal( y, 2, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_RealMinusCmplx( y, 4, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_RealMultiply( y, 0.1, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_RealDivideByCmplx( y, 1.0, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_Multiply( y, dest, dest );
-
-		if (fabs(dest[IMAG_PART]) <= TESTCOMPLEXMATH_TOL ) {
-			Journal_Printf(stream, "Answer within tolerance %g of %.5f + i %.5f\n", TESTCOMPLEXMATH_TOL,
-				dest[REAL_PART], fabs(0));
-		}
-		else{
-			Journal_Printf(stream, "Answer not within tolerance %g of %.5f + i %.5f\n", 
-				TESTCOMPLEXMATH_TOL, 1, 0);
-		}
-
-		pcu_filename_expected( "testComplexMathRealNumber.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathRealNumber.dat", expected_file );
-		remove( "testComplexMathRealNumber.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestConjugate( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathConjugate"  );
-		Stream_RedirectFile( stream, "testComplexMathConjugate.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Conjugate -----------------\n" );
-		Cmplx_Conjugate( x, x );
-		Journal_PrintCmplx( stream, x );	
-		Cmplx_Conjugate( x, x );
-		Journal_PrintCmplx( stream, x );	
-
-		pcu_filename_expected( "testComplexMathConjugate.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathConjugate.dat", expected_file );
-		remove( "testComplexMathConjugate.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestPolar( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		u = {-1.5, -3};
-		Cmplx		v = {1.5, -3};
-		Cmplx		i = {0, 1};
-		Cmplx		minus_i = {0, -1};
-		double	mod, theta;
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathPolar"  );
-		Stream_RedirectFile( stream, "testComplexMathPolar.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Complex Polar Stuff -----------------\n" );
-		mod = Cmplx_Modulus(x);
-		theta = Cmplx_Argument( x );
-		Journal_Printf(stream, "x = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
-		mod = Cmplx_Modulus(y);
-		theta = Cmplx_Argument( y );
-		Journal_Printf(stream, "y = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
-		mod = Cmplx_Modulus(u);
-		theta = Cmplx_Argument( u );
-		Journal_Printf(stream, "u = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
-		mod = Cmplx_Modulus(v);
-		theta = Cmplx_Argument( v );
-		Journal_Printf(stream, "v = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
-		mod = Cmplx_Modulus(i);
-		theta = Cmplx_Argument( i );
-		Journal_Printf(stream, "i = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
-		mod = Cmplx_Modulus(minus_i);
-		theta = Cmplx_Argument( minus_i );
-		Journal_Printf(stream, "-i = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
-
-		pcu_filename_expected( "testComplexMathPolar.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathPolar.dat", expected_file );
-		remove( "testComplexMathPolar.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestPower( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		y = {-1.5, 3};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathPower"  );
-		Stream_RedirectFile( stream, "testComplexMathPower.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Complex to real Power Stuff -----------------\n" );
-		Cmplx_RealPower( x, 2.0, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_Multiply( x, x, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_Multiply( dest, x, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_RealPower( x, 3.0, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_Sqrt( y, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_RealPower( dest, 2.0, dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		Journal_Printf(stream, "\n----------------- Testing Complex to complex Power Stuff -----------------\n" );
-		Cmplx_CmplxPower( x, y, dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		pcu_filename_expected( "testComplexMathPower.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathPower.dat", expected_file );
-		remove( "testComplexMathPower.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestBeautifulEquation( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		i = {0, 1};
-		Cmplx		e = {M_E, 0};
-		Cmplx		ipi = {0, M_PI};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathBeautifulEquation"  );
-		Stream_RedirectFile( stream, "testComplexMathBeautifulEquation.dat" );
-
-		Journal_Printf(stream, "----------------- Testing The Most Beautiful Equation in Mathematics e^{i \\pi} + 1 = 0 -----------------\n" );
-		Journal_Printf( stream, "e^{i \\pi} = ");
-		Cmplx_CmplxPower( e, ipi, dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		Journal_Printf(stream, "\n----------------- Another Beautiful Equation i^i = e^{-\\pi/2} -----------------\n" );
-		Cmplx_CmplxPower( i, i, dest );
-		Journal_Printf( stream, "e^{-\\pi/2} = %2.5lf = ", exp( -M_PI * 0.5 ) );
-		Journal_PrintCmplx( stream, dest );	
-
-		pcu_filename_expected( "testComplexMathBeautifulEquation.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathBeautifulEquation.dat", expected_file );
-		remove( "testComplexMathBeautifulEquation.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestExponential( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		e = {M_E, 0};
-		Cmplx		ipi = {0, M_PI};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathExponential"  );
-		Stream_RedirectFile( stream, "testComplexMathExponential.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Exponential -----------------\n" );
-		Journal_Printf( stream, "e^{2 + 3i} = ");
-		x[ REAL_PART ] = 2.0;
-		x[ IMAG_PART ] = 3.0;
-		Cmplx_Exp( x, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_CmplxPower( e, x, dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		Journal_Printf( stream, "e^{-5 + 7i} = ");
-		x[ REAL_PART ] = -5.0;
-		x[ IMAG_PART ] = 7.0;
-		Cmplx_Exp( x, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_CmplxPower( e, x, dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		Journal_Printf( stream, "e^{i \\pi} = ");
-		Cmplx_Exp( ipi, dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		pcu_filename_expected( "testComplexMathExponential.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathExponential.dat", expected_file );
-		remove( "testComplexMathExponential.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite_TestCopyAndZero( ComplexMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if (data->rank == procToWatch) {
-		Cmplx		x = {1, 2};
-		Cmplx		dest = {0, 0};
-		char		expected_file[PCU_PATH_MAX];
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathCopyAndZero"  );
-		Stream_RedirectFile( stream, "testComplexMathCopyAndZero.dat" );
-
-		Journal_Printf(stream, "----------------- Testing Copy and Zero -----------------\n" );
-		Journal_PrintCmplx( stream, x );	
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_Copy( x, dest );
-		Journal_PrintCmplx( stream, dest );	
-		Cmplx_Zero( dest );
-		Journal_PrintCmplx( stream, dest );	
-
-		pcu_filename_expected( "testComplexMathCopyAndZero.expected", expected_file );
-		pcu_check_fileEq( "testComplexMathCopyAndZero.dat", expected_file );
-		remove( "testComplexMathCopyAndZero.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexMathSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, ComplexMathSuiteData );
-   pcu_suite_setFixtures( suite, ComplexMathSuite_Setup, ComplexMathSuite_Teardown );
-	pcu_suite_addTest( suite, ComplexMathSuite_TestComplexJournalPrintingMacro );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestAddition );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestSubtraction );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestMultiplication );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestDivision );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestRealNumber );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestConjugate );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestPolar );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestPower );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestBeautifulEquation );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestExponential );
-   pcu_suite_addTest( suite, ComplexMathSuite_TestCopyAndZero );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/ComplexMathSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/ComplexMathSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,453 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ComplexMathSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "ComplexMathSuite.h"
+
+#undef Journal_PrintCmplx
+/** Print a complex number.  Will use %.7f formatting */
+#define Journal_PrintCmplx( stream, self ) \
+                Journal_Printf( stream, #self " = %.7f %c %.7f i\n", (self)[ REAL_PART ], (self)[ IMAG_PART ] >= 0.0 ? '+' : '-', fabs( (self)[ IMAG_PART ] ) )
+
+#define TESTCOMPLEXMATH_TOL 1e-15
+
+typedef struct {
+	MPI_Comm	comm;
+	int rank;
+	int nProcs;
+} ComplexMathSuiteData;
+
+void ComplexMathSuite_Setup( ComplexMathSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void ComplexMathSuite_Teardown( ComplexMathSuiteData* data ) {
+}
+
+void ComplexMathSuite_TestComplexJournalPrintingMacro( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		u = {-1.5, -3};
+		Cmplx		v = {1.5, -3};
+		Cmplx		i = {0, 1};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathPrintingMacro"  );
+		Stream_RedirectFile( stream, "testComplexMathPrintingMacro.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Complex Journal Printing Macro -----------------\n" );
+		Journal_PrintCmplx( stream, x );	
+		Journal_PrintCmplx( stream, y );	
+		Journal_PrintCmplx( stream, u );	
+		Journal_PrintCmplx( stream, v );	
+		Journal_PrintCmplx( stream, i );	
+
+		pcu_filename_expected( "testComplexJournalPrintingMacro.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathPrintingMacro.dat", expected_file );
+		remove( "testComplexMathPrintingMacro.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestAddition( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathAddition"  );
+		Stream_RedirectFile( stream, "testComplexMathAddition.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Addition -----------------\n" );
+		Cmplx_Add( x, y, dest );
+		Cmplx_Add( x, y, x );
+		Journal_PrintCmplx( stream, dest );	
+		Journal_PrintCmplx( stream, x );	
+
+		pcu_filename_expected( "testComplexMathAddition.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathAddition.dat", expected_file );
+		remove( "testComplexMathAddition.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestSubtraction( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathSubtraction"  );
+		Stream_RedirectFile( stream, "testComplexMathSubtraction.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Subtraction -----------------\n" );
+		Cmplx_Subtract( x, y, x );
+		Cmplx_Subtract( x, y, dest );
+		Journal_PrintCmplx( stream, x );
+		Journal_PrintCmplx( stream, dest );
+
+		pcu_filename_expected( "testComplexMathSubtraction.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathSubtraction.dat", expected_file );
+		remove( "testComplexMathSubtraction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestMultiplication( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathMultiplication"  );
+		Stream_RedirectFile( stream, "testComplexMathMultiplication.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Multiplication -----------------\n" );
+		Cmplx_Multiply( x, y, dest );
+		Cmplx_Multiply( x, y, y );
+		Journal_PrintCmplx( stream, dest );	
+		Journal_PrintCmplx( stream, y );	
+
+		pcu_filename_expected( "testComplexMathMultiplication.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathMultiplication.dat", expected_file );
+		remove( "testComplexMathMultiplication.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestDivision( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathDivision"  );
+		Stream_RedirectFile( stream, "testComplexMathDivision.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Division -----------------\n" );
+		Cmplx_Division( y, x, y );
+		Cmplx_Division( x, y, dest );
+		Journal_PrintCmplx( stream, y );	
+		Journal_PrintCmplx( stream, dest );	
+
+		pcu_filename_expected( "testComplexMathDivision.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathDivision.dat", expected_file );
+		remove( "testComplexMathDivision.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestRealNumber( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		y = {-1.5, 3};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathRealNumber"  );
+		Stream_RedirectFile( stream, "testComplexMathRealNumber.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Real Number Math stuff -----------------\n" );
+		Cmplx_AddReal( y, 2, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_RealMinusCmplx( y, 4, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_RealMultiply( y, 0.1, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_RealDivideByCmplx( y, 1.0, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_Multiply( y, dest, dest );
+
+		if (fabs(dest[IMAG_PART]) <= TESTCOMPLEXMATH_TOL ) {
+			Journal_Printf(stream, "Answer within tolerance %g of %.5f + i %.5f\n", TESTCOMPLEXMATH_TOL,
+				dest[REAL_PART], fabs(0));
+		}
+		else{
+			Journal_Printf(stream, "Answer not within tolerance %g of %.5f + i %.5f\n", 
+				TESTCOMPLEXMATH_TOL, 1, 0);
+		}
+
+		pcu_filename_expected( "testComplexMathRealNumber.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathRealNumber.dat", expected_file );
+		remove( "testComplexMathRealNumber.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestConjugate( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathConjugate"  );
+		Stream_RedirectFile( stream, "testComplexMathConjugate.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Conjugate -----------------\n" );
+		Cmplx_Conjugate( x, x );
+		Journal_PrintCmplx( stream, x );	
+		Cmplx_Conjugate( x, x );
+		Journal_PrintCmplx( stream, x );	
+
+		pcu_filename_expected( "testComplexMathConjugate.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathConjugate.dat", expected_file );
+		remove( "testComplexMathConjugate.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestPolar( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		u = {-1.5, -3};
+		Cmplx		v = {1.5, -3};
+		Cmplx		i = {0, 1};
+		Cmplx		minus_i = {0, -1};
+		double	mod, theta;
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathPolar"  );
+		Stream_RedirectFile( stream, "testComplexMathPolar.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Complex Polar Stuff -----------------\n" );
+		mod = Cmplx_Modulus(x);
+		theta = Cmplx_Argument( x );
+		Journal_Printf(stream, "x = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
+		mod = Cmplx_Modulus(y);
+		theta = Cmplx_Argument( y );
+		Journal_Printf(stream, "y = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
+		mod = Cmplx_Modulus(u);
+		theta = Cmplx_Argument( u );
+		Journal_Printf(stream, "u = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
+		mod = Cmplx_Modulus(v);
+		theta = Cmplx_Argument( v );
+		Journal_Printf(stream, "v = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
+		mod = Cmplx_Modulus(i);
+		theta = Cmplx_Argument( i );
+		Journal_Printf(stream, "i = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
+		mod = Cmplx_Modulus(minus_i);
+		theta = Cmplx_Argument( minus_i );
+		Journal_Printf(stream, "-i = %2.4lf e^{i %2.4lf} = %2.4lf + %2.4lf\n", mod, theta, mod * cos(theta), mod *sin(theta));
+
+		pcu_filename_expected( "testComplexMathPolar.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathPolar.dat", expected_file );
+		remove( "testComplexMathPolar.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestPower( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		y = {-1.5, 3};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathPower"  );
+		Stream_RedirectFile( stream, "testComplexMathPower.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Complex to real Power Stuff -----------------\n" );
+		Cmplx_RealPower( x, 2.0, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_Multiply( x, x, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_Multiply( dest, x, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_RealPower( x, 3.0, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_Sqrt( y, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_RealPower( dest, 2.0, dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		Journal_Printf(stream, "\n----------------- Testing Complex to complex Power Stuff -----------------\n" );
+		Cmplx_CmplxPower( x, y, dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		pcu_filename_expected( "testComplexMathPower.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathPower.dat", expected_file );
+		remove( "testComplexMathPower.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestBeautifulEquation( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		i = {0, 1};
+		Cmplx		e = {M_E, 0};
+		Cmplx		ipi = {0, M_PI};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathBeautifulEquation"  );
+		Stream_RedirectFile( stream, "testComplexMathBeautifulEquation.dat" );
+
+		Journal_Printf(stream, "----------------- Testing The Most Beautiful Equation in Mathematics e^{i \\pi} + 1 = 0 -----------------\n" );
+		Journal_Printf( stream, "e^{i \\pi} = ");
+		Cmplx_CmplxPower( e, ipi, dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		Journal_Printf(stream, "\n----------------- Another Beautiful Equation i^i = e^{-\\pi/2} -----------------\n" );
+		Cmplx_CmplxPower( i, i, dest );
+		Journal_Printf( stream, "e^{-\\pi/2} = %2.5lf = ", exp( -M_PI * 0.5 ) );
+		Journal_PrintCmplx( stream, dest );	
+
+		pcu_filename_expected( "testComplexMathBeautifulEquation.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathBeautifulEquation.dat", expected_file );
+		remove( "testComplexMathBeautifulEquation.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestExponential( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		e = {M_E, 0};
+		Cmplx		ipi = {0, M_PI};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathExponential"  );
+		Stream_RedirectFile( stream, "testComplexMathExponential.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Exponential -----------------\n" );
+		Journal_Printf( stream, "e^{2 + 3i} = ");
+		x[ REAL_PART ] = 2.0;
+		x[ IMAG_PART ] = 3.0;
+		Cmplx_Exp( x, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_CmplxPower( e, x, dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		Journal_Printf( stream, "e^{-5 + 7i} = ");
+		x[ REAL_PART ] = -5.0;
+		x[ IMAG_PART ] = 7.0;
+		Cmplx_Exp( x, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_CmplxPower( e, x, dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		Journal_Printf( stream, "e^{i \\pi} = ");
+		Cmplx_Exp( ipi, dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		pcu_filename_expected( "testComplexMathExponential.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathExponential.dat", expected_file );
+		remove( "testComplexMathExponential.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite_TestCopyAndZero( ComplexMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if (data->rank == procToWatch) {
+		Cmplx		x = {1, 2};
+		Cmplx		dest = {0, 0};
+		char		expected_file[PCU_PATH_MAX];
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"ComplexMathCopyAndZero"  );
+		Stream_RedirectFile( stream, "testComplexMathCopyAndZero.dat" );
+
+		Journal_Printf(stream, "----------------- Testing Copy and Zero -----------------\n" );
+		Journal_PrintCmplx( stream, x );	
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_Copy( x, dest );
+		Journal_PrintCmplx( stream, dest );	
+		Cmplx_Zero( dest );
+		Journal_PrintCmplx( stream, dest );	
+
+		pcu_filename_expected( "testComplexMathCopyAndZero.expected", expected_file );
+		pcu_check_fileEq( "testComplexMathCopyAndZero.dat", expected_file );
+		remove( "testComplexMathCopyAndZero.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexMathSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, ComplexMathSuiteData );
+   pcu_suite_setFixtures( suite, ComplexMathSuite_Setup, ComplexMathSuite_Teardown );
+	pcu_suite_addTest( suite, ComplexMathSuite_TestComplexJournalPrintingMacro );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestAddition );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestSubtraction );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestMultiplication );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestDivision );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestRealNumber );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestConjugate );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestPolar );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestPower );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestBeautifulEquation );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestExponential );
+   pcu_suite_addTest( suite, ComplexMathSuite_TestCopyAndZero );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/ComplexVectorMathSuite.c
--- a/Geometry/tests/ComplexVectorMathSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,542 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ComplexVectorMathSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "ComplexVectorMathSuite.h"
-
-#undef Journal_PrintCmplx
-/** Print a complex number.
-Will use %.5f formatting */
-#define Journal_PrintCmplx( stream, self ) \
-                Journal_Printf( stream, #self " = %.7f %c %.7f i\n", (self)[ REAL_PART ], (self)[ IMAG_PART ] >= 0.0 ? '+' : '-', fabs( (self)[ IMAG_PART ] ) )
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} ComplexVectorMathSuiteData;
-
-void ComplexVectorMathSuite_Setup( ComplexVectorMathSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void ComplexVectorMathSuite_Teardown( ComplexVectorMathSuiteData* data ) {
-}
-
-void ComplexVectorMathSuite_TestComplexVectorMathBasic( ComplexVectorMathSuiteData* data ) {
-	int	procToWatch;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"VectorMathBasicStream" );
-	char		expected_file[PCU_PATH_MAX];
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch ) {
-		CoordC	a, b, c;
-		CoordC	d = { {1.0, 1.0}, {1.0, 0.0}, {0.0, 1.0} };
-		CoordC	e = { {1.0, 0.0}, {2.0, 2.0}, {-3.0, -1.0} };
-		Cmplx		value = {1.0, 1.0}; 
-		Cmplx		c1 = {1.0, 0.0};
-		Cmplx		c2 = {2.0, 1.0};
-		Cmplx		c3 = {1.5, 1.0};
-
-		Stream_RedirectFile( stream, "testComplexVectorMathBasic.dat" );
-
-		Journal_Printf( stream,  "Basic tests:\n" );
-		Journal_Printf( stream, "d = \n");
-		Journal_PrintCmplx( stream, d[0]);
-		Journal_PrintCmplx( stream, d[1]);
-		Journal_PrintCmplx( stream, d[2]);
-		 
-		Journal_Printf( stream, "Set Complex Scalar\n");
-		ComplexVector_SetScalar( c1, c2, c3, d );
-		Journal_Printf( stream, "d = \n");
-		Journal_PrintCmplx( stream, d[0]);
-		Journal_PrintCmplx( stream, d[1]);
-		Journal_PrintCmplx( stream, d[2]);
-
-		Journal_Printf( stream, "Set c = d\n");
-		ComplexVector_Set( d, c );
-		Journal_Printf( stream, "c = \n");
-		Journal_PrintCmplx( stream, c[0]);
-		Journal_PrintCmplx( stream, c[1]);
-		Journal_PrintCmplx( stream, c[2]);
-
-		ComplexVector_Add(c, d, b );
-		Journal_Printf( stream,  "b = c + d \n");
-		Journal_Printf( stream, "b = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);
-
-		ComplexVector_Sub( b, d, a );
-		Journal_Printf( stream,  "a = b - d \n");
-		Journal_Printf( stream, "a = \n");
-		Journal_PrintCmplx( stream, a[0]);
-		Journal_PrintCmplx( stream, a[1]);
-		Journal_PrintCmplx( stream, a[2]);
-
-		ComplexVector_Cross( a, e, d );		
-		Journal_Printf( stream,  "d = a x e \n");
-		Journal_Printf( stream, "e = \n");
-		Journal_PrintCmplx( stream, e[0]);
-		Journal_PrintCmplx( stream, e[1]);
-		Journal_PrintCmplx( stream, e[2]);		
-		Journal_Printf( stream, "d = \n");
-		Journal_PrintCmplx( stream, d[0]);
-		Journal_PrintCmplx( stream, d[1]);
-		Journal_PrintCmplx( stream, d[2]);
-		
-		ComplexVector_Dot( a, e, value );
-		Journal_Printf( stream,  "value = a . e \n");
-		Journal_PrintCmplx( stream, value);
-		
-		value[REAL_PART] = 2.0;
-		value[IMAG_PART] = 1.0;
-		Journal_Printf( stream, "b = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);		
-		ComplexVector_Mult( b, value, b);
-		Journal_Printf( stream,  "b = (2 + i) * b \n");
-		Journal_Printf( stream, "b = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);
-		
-		ComplexVector_MultReal(b, 3.0, b);
-		Journal_Printf( stream,  "b = 3 * b \n");
-		Journal_Printf( stream, "b = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);	
-
-		b[0][REAL_PART] = 0.0; b[0][IMAG_PART] = 1.0; 
-		b[1][REAL_PART] = 1.0; b[1][IMAG_PART] = 1.0;
-		b[2][REAL_PART] = 0.0; b[2][IMAG_PART] = 1.0;
-		
-		Journal_Printf( stream,  "b = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);
-
-		Journal_Printf( stream,  "|b| = %g\n", ComplexVector_Mag(b));
-				
-		ComplexVector_Proj(a, b, d);
-		Journal_Printf( stream,  "d = proj a onto b \n");
-		Journal_Printf( stream, "d = \n");
-		Journal_PrintCmplx( stream, d[0]);
-		Journal_PrintCmplx( stream, d[1]);
-		Journal_PrintCmplx( stream, d[2]);			
-		
-		ComplexVector_Div(a, value, e);
-		Journal_Printf( stream,  "e = a / value \n");
-		Journal_PrintCmplx( stream, value);
-		Journal_Printf( stream, "e = \n");
-		Journal_PrintCmplx( stream, e[0]);
-		Journal_PrintCmplx( stream, e[1]);
-		Journal_PrintCmplx( stream, e[2]);
-
-		Journal_Printf( stream, "b = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);
-		ComplexVector_Norm( b, b );
-		Journal_Printf( stream,  "Norm(b) = \n");
-		Journal_PrintCmplx( stream, b[0]);
-		Journal_PrintCmplx( stream, b[1]);
-		Journal_PrintCmplx( stream, b[2]);
-	
-		Journal_Printf( stream,  "|b| = %g\n", ComplexVector_Mag(b));
-		
-		Journal_Printf( stream,  "a  = \n");
-		Journal_PrintCmplx( stream, a[0]);
-		Journal_PrintCmplx( stream, a[1]);
-		Journal_PrintCmplx( stream, a[2]);
-		
-		ComplexVector_Swizzle(a, K_AXIS, I_AXIS, J_AXIS, a);
-		Journal_Printf( stream,  "swizzle(a)(k, i, j) = \n");
-		Journal_PrintCmplx( stream, a[0]);
-		Journal_PrintCmplx( stream, a[1]);
-		Journal_PrintCmplx( stream, a[2]);
-
-		pcu_filename_expected( "testComplexVectorMathBasic.expected", expected_file );
-		pcu_check_fileEq( "testComplexVectorMathBasic.dat", expected_file );
-		remove( "testComplexVectorMathBasic.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexVectorMathSuite_TestComplexVectorMathOperations( ComplexVectorMathSuiteData* data ) {
-	int	procToWatch;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"VectorMathOperationsStream" );
-	char		expected_file[PCU_PATH_MAX];
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch ) {
-		#define STG_COMPLEXVECTOR_TOL 1e-16;
-		
-		Cmplx		i[] = {{1.00000000, 0.000000000},{0.00000000, 0.000000000},{0.000000000, 0.00000000}};
-		Cmplx		j[] = {{0.00000000, 0.00000000},{1.0000000, 0.00000000},{0.00000000, 0.0000000}};
-		Cmplx		k[] = {{0.00000000, 0.000000000},{0.00000000, 0.000000000},{1.000000000, 0.000000000}};
-		Cmplx		A[] = {{7.4, 1.0}, {  2, 0.0}, {  5, 1.0}, { 1, 0.0}, {  3, 2.0}, {  -42, 0.0}};
-		Cmplx		B[] = {{  4, 2.0}, {2.3, 0.0}, {5.8, 0.0}, { 6, 0.0}, {-12, 0.0}, {39289, 0.0}};
-		Cmplx		C[] = {{23, 0.0}, {  5, 0.0}, {-14, 0.0}, {32, 0.0}, {-21, 1.0}, {	78, 0.0}};
-		Cmplx		D[] = {{23, 0.0}, {  5, 0.0}, {-14, 0.0}, {32, 0.0}, {-21, 0.0}, {   78, 0.0}};
-		double	angle;
-		Cmplx		**matrix;
-		Cmplx		vector[6], differenceVector[6];
-		Cmplx		*coordList[4];
-		int		d;
-		double	realVector[3], tolerance;
-		Cmplx		dotProductResult;
-		Cmplx		value;
-		
-		Stream_RedirectFile( stream, "testComplexVectorMathOperations.dat" );
-
-		tolerance = STG_COMPLEXVECTOR_TOL;
-		
-		coordList[0] = A;
-		coordList[1] = B;
-		coordList[2] = C;
-		coordList[3] = D;
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf(stream, "Vectors - A, B, C, and D\n");
-		
-		StGermain_PrintNamedComplexVector( stream, A, 6 );
-		StGermain_PrintNamedComplexVector( stream, B, 6 );
-		StGermain_PrintNamedComplexVector( stream, C, 6 );
-		StGermain_PrintNamedComplexVector( stream, D, 6 );
-
-		/* Check Rotation functions */
-		Journal_Printf( stream, "\n****************************\n");
-
-		StGermain_PrintNamedComplexVector( stream, i, 3 );
-		StGermain_PrintNamedComplexVector( stream, j, 3 );
-		StGermain_PrintNamedComplexVector( stream, k, 3 );
-		
-		angle = M_PI / 2.0;
-		
-		Journal_Printf(stream, "Axis Rotation\n");				
-		StGermain_RotateCoordinateAxisComplex( k, I_AXIS, angle, vector ) ;
-		Journal_Printf( stream, "K Rotated %g radians around I axis - \n", angle);
-		Cmplx_Subtract(vector[0], j[0], differenceVector[0]);
-		Cmplx_Subtract(vector[1], j[1], differenceVector[1]);
-		Cmplx_Subtract(vector[2], j[2], differenceVector[2]);
-		
-		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
-			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
-			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, j, 3);
-		}
-		else {
-			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, j, 3);
-		}
-		
-		Journal_Printf(stream, "Angle Rotation\n");		
-		StGermain_RotateComplexVector(k, angle,0.0, 0.0, vector);
-		Journal_Printf( stream, "K Rotated %g radians around I axis - \n", angle); 
-		Cmplx_Subtract(vector[0], j[0], differenceVector[0]);
-		Cmplx_Subtract(vector[1], j[1], differenceVector[1]);
-		Cmplx_Subtract(vector[2], j[2], differenceVector[2]);
-		
-		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
-			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
-			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, j, 3);
-		}
-		else {
-			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, j, 3);
-		}
-		
-		Journal_Printf(stream, "Axis Rotation\n");		
-		StGermain_RotateCoordinateAxisComplex( i, J_AXIS, angle, vector );
-		Journal_Printf( stream, "I Rotated %g radians around J axis - \n", angle); 
-		Cmplx_Subtract(vector[0], k[0], differenceVector[0]);
-		Cmplx_Subtract(vector[1], k[1], differenceVector[1]);
-		Cmplx_Subtract(vector[2], k[2], differenceVector[2]);
-		
-		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
-			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
-			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, k, 3);
-		}
-		else {
-			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, k, 3);
-		}
-		
-		Journal_Printf(stream, "Angle Rotation\n");
-		StGermain_RotateComplexVector(i, 0.0, angle, 0.0, vector );
-		Journal_Printf( stream, "I Rotated %g radians around J axis - \n", angle); 
-		Cmplx_Subtract(vector[0], k[0], differenceVector[0]);
-		Cmplx_Subtract(vector[1], k[1], differenceVector[1]);
-		Cmplx_Subtract(vector[2], k[2], differenceVector[2]);
-		
-		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
-			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
-			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, k, 3);
-		}
-		else {
-			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, k, 3);
-		}
-		
-		Journal_Printf(stream, "Axis Rotation\n");		
-		StGermain_RotateCoordinateAxisComplex( j, K_AXIS, angle, vector );
-		Journal_Printf( stream, "J Rotated %g radians around K axis - \n", angle); 
-		Cmplx_Subtract(vector[0], i[0], differenceVector[0]);
-		Cmplx_Subtract(vector[1], i[1], differenceVector[1]);
-		Cmplx_Subtract(vector[2], i[2], differenceVector[2]);
-		
-		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
-			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
-			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, i, 3);
-		}
-		else {
-			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, i, 3);
-		}
-
-		Journal_Printf(stream, "Angle Rotation\n");
-		StGermain_RotateComplexVector( j, 0.0, 0.0, angle, vector );
-		Journal_Printf( stream, "J Rotated %g radians around K axis - \n", angle); 
-		Cmplx_Subtract(vector[0], i[0], differenceVector[0]);
-		Cmplx_Subtract(vector[1], i[1], differenceVector[1]);
-		Cmplx_Subtract(vector[2], i[2], differenceVector[2]);
-		
-		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
-			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
-			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, i, 3);
-		}
-		else {
-			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
-			StGermain_PrintNamedComplexVector( stream, i, 3);
-		}
-
-		angle = M_PI / 4.0;
-
-		StGermain_RotateComplexVector(i, 0.0, angle, angle, vector );
-		Journal_Printf( stream, "I Rotated %g radians around J axis "
-		"and %2g radians around K axis: \n", angle, angle);
-		StGermain_PrintNamedComplexVector( stream, vector, 3 );
-
-		StGermain_RotateComplexVector(j, angle, 0.0, angle, vector );
-		Journal_Printf( stream, "J Rotated %g radians around I axis "
-		"and %g radians around K axis: \n", angle, angle); 
-		StGermain_PrintNamedComplexVector( stream, vector, 3 );
-
-		StGermain_RotateComplexVector(k, angle, angle, 0.0, vector );
-		Journal_Printf( stream, "K Rotated %g radians around I axis "
-		"and %g radians around J axis: \n", angle, angle); 
-		StGermain_PrintNamedComplexVector( stream, vector, 3 );
-
-		/* Check addition function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "vector = A + B\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			StGermain_ComplexVectorAddition( vector, A, B, d );
-			StGermain_PrintNamedComplexVector( stream, vector, d );
-		}
-
-		/* Check subtraction function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "vector = A - B\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			StGermain_ComplexVectorSubtraction( vector, A, B, d );
-			StGermain_PrintNamedComplexVector( stream, vector, d );
-		}
-	
-		/* Check Magnitude Function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check Magnitude Function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			Journal_Printf( stream, "dim = %d magnitude A = %2.3f\n", d, StGermain_ComplexVectorMagnitude( A, d ) );
-			Journal_Printf( stream, "dim = %d magnitude B = %2.3f\n", d, StGermain_ComplexVectorMagnitude( B, d ) );
-		}
-
-		/* Check Dot Product */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check Dot Product Function\n");
-		Journal_Printf( stream, "value = A . B \n");
-		
-		for (d = 0; d <=6; d++) {
-		StGermain_ComplexVectorDotProduct(A, B, d, dotProductResult);			
-		Journal_Printf( stream, "dim = %d dot product = %2.3f + %2.3f i\n",
-			d, dotProductResult[0], dotProductResult[1] );
-		}
-
-		/* Check Cross Product */
-		/* Tested against http://www.engplanet.com/redirect.html?3859 */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check Cross Product Function\n");
-		Journal_Printf( stream, " A x B in 3-D\n");
-		StGermain_ComplexVectorCrossProduct( vector, A, B );
-		StGermain_PrintNamedComplexVector( stream, vector, 3 );
-
-		/* Checking centroid function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Checking centroid function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			StGermain_ComplexTriangleCentroid( vector, A, B, C, d );
-			StGermain_PrintNamedComplexVector( stream, vector, d );
-		}
-
-		/* Check Normalisation Function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check Normalisation Function\n");
-		
-		Journal_Printf( stream, "2-D\n\n");
-		d = 2;
-		StGermain_PrintNamedComplexVector( stream, A, d );
-		StGermain_ComplexVectorNormalise( A, d );
-		StGermain_PrintNamedComplexVector( stream, A, d);
-		Journal_Printf( stream, "mag = %2.3f\n", StGermain_ComplexVectorMagnitude( A, d ) );
-
-		Journal_Printf( stream, "3-D\n\n");
-		d = 3;
-		StGermain_PrintNamedComplexVector( stream, B, d );
-		StGermain_ComplexVectorNormalise( B, d );
-		StGermain_PrintNamedComplexVector( stream, B, d);
-		Journal_Printf( stream, "mag = %2.3f\n", StGermain_ComplexVectorMagnitude( B, d ) );
-
-		Journal_Printf( stream, "5-D\n\n");
-		d = 5;
-		StGermain_PrintNamedComplexVector( stream, C, d );
-		StGermain_ComplexVectorNormalise( C, d );
-		StGermain_PrintNamedComplexVector( stream, C, d);
-		Journal_Printf( stream, "mag = %2.3f\n", StGermain_ComplexVectorMagnitude( C, d ) );
-
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check StGermain_ComplexVectorCrossProductMagnitude\n");
-		A[0][REAL_PART] = 1.0; A[0][IMAG_PART] = 1.0; 
-		A[1][REAL_PART] = 2.0; A[1][IMAG_PART] = 0.0;
-		A[2][REAL_PART] = 3.0; A[2][IMAG_PART] = 0.0;
-		B[0][REAL_PART] = 4.0; B[0][IMAG_PART] = 0.0;
-		B[1][REAL_PART] = 5.0; B[1][IMAG_PART] = 0.0;
-		B[2][REAL_PART] = 6.0; B[2][IMAG_PART] = 3.0;
-		StGermain_PrintNamedComplexVector( stream, A, 3);
-		StGermain_PrintNamedComplexVector( stream, B, 3);
-		
-		StGermain_ComplexVectorCrossProductMagnitude(A, B, 2, value ) ;
-		Journal_Printf( stream, "mag = %2.3g + %2.3g i (2D)\n", value[REAL_PART], value[IMAG_PART] );
-		
-		StGermain_ComplexVectorCrossProductMagnitude(A, B, 3, value ) ;
-		Journal_Printf( stream, "mag = %2.3g + %2.3g i (3D)\n", value[REAL_PART], value[IMAG_PART] );
-
-
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check StGermain_ComplexScalarTripleProduct \n");
-		
-		matrix = Memory_Alloc_2DArray( Cmplx, 3, 3, (Name)"matrix"  );
-		
-		matrix[0][0][REAL_PART] = 1.0; 	matrix[0][0][IMAG_PART] = 1.0;
-		matrix[0][1][REAL_PART] = 2.0; 	matrix[0][1][IMAG_PART] = 0.0; 
-		matrix[0][2][REAL_PART] = 3.0; 	matrix[0][2][IMAG_PART] = 2.0;
-		matrix[1][0][REAL_PART] = 4.0; 	matrix[1][0][IMAG_PART] = 0.0;
-		matrix[1][1][REAL_PART] = 5.0; 	matrix[1][1][IMAG_PART] = 3.0; 
-		matrix[1][2][REAL_PART] = 6.0; 	matrix[1][2][IMAG_PART] = 0.0;
-		matrix[2][0][REAL_PART] = 7.0; 	matrix[2][0][IMAG_PART] = 1.0;
-		matrix[2][1][REAL_PART] = 8.0; 	matrix[2][1][IMAG_PART] = 0.0;
-		matrix[2][2][REAL_PART] = 11.0; matrix[2][2][IMAG_PART] = 1.0;
-		StGermain_PrintNamedComplexVector( stream, matrix[0], 3);
-		StGermain_PrintNamedComplexVector( stream, matrix[1], 3);
-		StGermain_PrintNamedComplexVector( stream, matrix[2], 3);
-
-		StGermain_ComplexScalarTripleProduct( matrix[0], matrix[1], matrix[2], value );
-		Journal_Printf( stream, "scalar triple product: ");
-		Journal_PrintCmplx( stream, value );
-		
-		StGermain_ComplexScalarTripleProduct( matrix[2], matrix[0], matrix[1], value );
-		Journal_Printf( stream, "scalar triple product: ");
-		Journal_PrintCmplx( stream, value );
-		StGermain_ComplexScalarTripleProduct( matrix[1], matrix[2], matrix[0], value );
-		Journal_Printf( stream, "scalar triple product: ");
-		Journal_PrintCmplx( stream, value );
-		
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check Vector_ToComplexVector function \n");
-		
-		realVector[0] = 1.0; realVector[1] = 2.0; realVector[2] = 3.0;
-		
-		StGermain_PrintNamedVector(stream, realVector, 3);
-		Vector_ToComplexVector(realVector, 3, matrix[0]) ;
-		StGermain_PrintNamedComplexVector( stream, matrix[0], 3);
-
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "Check ComplexVector_ToVector function \n");	
-		
-		matrix[0][0][REAL_PART] = 5.0; 	matrix[0][0][IMAG_PART] = 0.0;
-		matrix[0][1][REAL_PART] = 6.0; 	matrix[0][1][IMAG_PART] = 0.0; 
-		matrix[0][2][REAL_PART] = 7.0; 	matrix[0][2][IMAG_PART] = 0.0;
-		
-		StGermain_PrintNamedComplexVector( stream, matrix[0], 3);
-		ComplexVector_ToVector(matrix[0], 3, realVector) ;
-		StGermain_PrintNamedVector(stream, realVector, 3);
-
-		pcu_filename_expected( "testComplexVectorMathOperations.expected", expected_file );
-		pcu_check_fileEq( "testComplexVectorMathOperations.dat", expected_file );
-		remove( "testComplexVectorMathOperations.dat" );
-
-		Memory_Free( matrix );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void ComplexVectorMathSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, ComplexVectorMathSuiteData );
-   pcu_suite_setFixtures( suite, ComplexVectorMathSuite_Setup, ComplexVectorMathSuite_Teardown );
-   pcu_suite_addTest( suite, ComplexVectorMathSuite_TestComplexVectorMathBasic );
-   pcu_suite_addTest( suite, ComplexVectorMathSuite_TestComplexVectorMathOperations );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/ComplexVectorMathSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/ComplexVectorMathSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,542 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ComplexVectorMathSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "ComplexVectorMathSuite.h"
+
+#undef Journal_PrintCmplx
+/** Print a complex number.
+Will use %.5f formatting */
+#define Journal_PrintCmplx( stream, self ) \
+                Journal_Printf( stream, #self " = %.7f %c %.7f i\n", (self)[ REAL_PART ], (self)[ IMAG_PART ] >= 0.0 ? '+' : '-', fabs( (self)[ IMAG_PART ] ) )
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} ComplexVectorMathSuiteData;
+
+void ComplexVectorMathSuite_Setup( ComplexVectorMathSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void ComplexVectorMathSuite_Teardown( ComplexVectorMathSuiteData* data ) {
+}
+
+void ComplexVectorMathSuite_TestComplexVectorMathBasic( ComplexVectorMathSuiteData* data ) {
+	int	procToWatch;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"VectorMathBasicStream" );
+	char		expected_file[PCU_PATH_MAX];
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch ) {
+		CoordC	a, b, c;
+		CoordC	d = { {1.0, 1.0}, {1.0, 0.0}, {0.0, 1.0} };
+		CoordC	e = { {1.0, 0.0}, {2.0, 2.0}, {-3.0, -1.0} };
+		Cmplx		value = {1.0, 1.0}; 
+		Cmplx		c1 = {1.0, 0.0};
+		Cmplx		c2 = {2.0, 1.0};
+		Cmplx		c3 = {1.5, 1.0};
+
+		Stream_RedirectFile( stream, "testComplexVectorMathBasic.dat" );
+
+		Journal_Printf( stream,  "Basic tests:\n" );
+		Journal_Printf( stream, "d = \n");
+		Journal_PrintCmplx( stream, d[0]);
+		Journal_PrintCmplx( stream, d[1]);
+		Journal_PrintCmplx( stream, d[2]);
+		 
+		Journal_Printf( stream, "Set Complex Scalar\n");
+		ComplexVector_SetScalar( c1, c2, c3, d );
+		Journal_Printf( stream, "d = \n");
+		Journal_PrintCmplx( stream, d[0]);
+		Journal_PrintCmplx( stream, d[1]);
+		Journal_PrintCmplx( stream, d[2]);
+
+		Journal_Printf( stream, "Set c = d\n");
+		ComplexVector_Set( d, c );
+		Journal_Printf( stream, "c = \n");
+		Journal_PrintCmplx( stream, c[0]);
+		Journal_PrintCmplx( stream, c[1]);
+		Journal_PrintCmplx( stream, c[2]);
+
+		ComplexVector_Add(c, d, b );
+		Journal_Printf( stream,  "b = c + d \n");
+		Journal_Printf( stream, "b = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);
+
+		ComplexVector_Sub( b, d, a );
+		Journal_Printf( stream,  "a = b - d \n");
+		Journal_Printf( stream, "a = \n");
+		Journal_PrintCmplx( stream, a[0]);
+		Journal_PrintCmplx( stream, a[1]);
+		Journal_PrintCmplx( stream, a[2]);
+
+		ComplexVector_Cross( a, e, d );		
+		Journal_Printf( stream,  "d = a x e \n");
+		Journal_Printf( stream, "e = \n");
+		Journal_PrintCmplx( stream, e[0]);
+		Journal_PrintCmplx( stream, e[1]);
+		Journal_PrintCmplx( stream, e[2]);		
+		Journal_Printf( stream, "d = \n");
+		Journal_PrintCmplx( stream, d[0]);
+		Journal_PrintCmplx( stream, d[1]);
+		Journal_PrintCmplx( stream, d[2]);
+		
+		ComplexVector_Dot( a, e, value );
+		Journal_Printf( stream,  "value = a . e \n");
+		Journal_PrintCmplx( stream, value);
+		
+		value[REAL_PART] = 2.0;
+		value[IMAG_PART] = 1.0;
+		Journal_Printf( stream, "b = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);		
+		ComplexVector_Mult( b, value, b);
+		Journal_Printf( stream,  "b = (2 + i) * b \n");
+		Journal_Printf( stream, "b = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);
+		
+		ComplexVector_MultReal(b, 3.0, b);
+		Journal_Printf( stream,  "b = 3 * b \n");
+		Journal_Printf( stream, "b = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);	
+
+		b[0][REAL_PART] = 0.0; b[0][IMAG_PART] = 1.0; 
+		b[1][REAL_PART] = 1.0; b[1][IMAG_PART] = 1.0;
+		b[2][REAL_PART] = 0.0; b[2][IMAG_PART] = 1.0;
+		
+		Journal_Printf( stream,  "b = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);
+
+		Journal_Printf( stream,  "|b| = %g\n", ComplexVector_Mag(b));
+				
+		ComplexVector_Proj(a, b, d);
+		Journal_Printf( stream,  "d = proj a onto b \n");
+		Journal_Printf( stream, "d = \n");
+		Journal_PrintCmplx( stream, d[0]);
+		Journal_PrintCmplx( stream, d[1]);
+		Journal_PrintCmplx( stream, d[2]);			
+		
+		ComplexVector_Div(a, value, e);
+		Journal_Printf( stream,  "e = a / value \n");
+		Journal_PrintCmplx( stream, value);
+		Journal_Printf( stream, "e = \n");
+		Journal_PrintCmplx( stream, e[0]);
+		Journal_PrintCmplx( stream, e[1]);
+		Journal_PrintCmplx( stream, e[2]);
+
+		Journal_Printf( stream, "b = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);
+		ComplexVector_Norm( b, b );
+		Journal_Printf( stream,  "Norm(b) = \n");
+		Journal_PrintCmplx( stream, b[0]);
+		Journal_PrintCmplx( stream, b[1]);
+		Journal_PrintCmplx( stream, b[2]);
+	
+		Journal_Printf( stream,  "|b| = %g\n", ComplexVector_Mag(b));
+		
+		Journal_Printf( stream,  "a  = \n");
+		Journal_PrintCmplx( stream, a[0]);
+		Journal_PrintCmplx( stream, a[1]);
+		Journal_PrintCmplx( stream, a[2]);
+		
+		ComplexVector_Swizzle(a, K_AXIS, I_AXIS, J_AXIS, a);
+		Journal_Printf( stream,  "swizzle(a)(k, i, j) = \n");
+		Journal_PrintCmplx( stream, a[0]);
+		Journal_PrintCmplx( stream, a[1]);
+		Journal_PrintCmplx( stream, a[2]);
+
+		pcu_filename_expected( "testComplexVectorMathBasic.expected", expected_file );
+		pcu_check_fileEq( "testComplexVectorMathBasic.dat", expected_file );
+		remove( "testComplexVectorMathBasic.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexVectorMathSuite_TestComplexVectorMathOperations( ComplexVectorMathSuiteData* data ) {
+	int	procToWatch;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"VectorMathOperationsStream" );
+	char		expected_file[PCU_PATH_MAX];
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch ) {
+		#define STG_COMPLEXVECTOR_TOL 1e-16;
+		
+		Cmplx		i[] = {{1.00000000, 0.000000000},{0.00000000, 0.000000000},{0.000000000, 0.00000000}};
+		Cmplx		j[] = {{0.00000000, 0.00000000},{1.0000000, 0.00000000},{0.00000000, 0.0000000}};
+		Cmplx		k[] = {{0.00000000, 0.000000000},{0.00000000, 0.000000000},{1.000000000, 0.000000000}};
+		Cmplx		A[] = {{7.4, 1.0}, {  2, 0.0}, {  5, 1.0}, { 1, 0.0}, {  3, 2.0}, {  -42, 0.0}};
+		Cmplx		B[] = {{  4, 2.0}, {2.3, 0.0}, {5.8, 0.0}, { 6, 0.0}, {-12, 0.0}, {39289, 0.0}};
+		Cmplx		C[] = {{23, 0.0}, {  5, 0.0}, {-14, 0.0}, {32, 0.0}, {-21, 1.0}, {	78, 0.0}};
+		Cmplx		D[] = {{23, 0.0}, {  5, 0.0}, {-14, 0.0}, {32, 0.0}, {-21, 0.0}, {   78, 0.0}};
+		double	angle;
+		Cmplx		**matrix;
+		Cmplx		vector[6], differenceVector[6];
+		Cmplx		*coordList[4];
+		int		d;
+		double	realVector[3], tolerance;
+		Cmplx		dotProductResult;
+		Cmplx		value;
+		
+		Stream_RedirectFile( stream, "testComplexVectorMathOperations.dat" );
+
+		tolerance = STG_COMPLEXVECTOR_TOL;
+		
+		coordList[0] = A;
+		coordList[1] = B;
+		coordList[2] = C;
+		coordList[3] = D;
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf(stream, "Vectors - A, B, C, and D\n");
+		
+		StGermain_PrintNamedComplexVector( stream, A, 6 );
+		StGermain_PrintNamedComplexVector( stream, B, 6 );
+		StGermain_PrintNamedComplexVector( stream, C, 6 );
+		StGermain_PrintNamedComplexVector( stream, D, 6 );
+
+		/* Check Rotation functions */
+		Journal_Printf( stream, "\n****************************\n");
+
+		StGermain_PrintNamedComplexVector( stream, i, 3 );
+		StGermain_PrintNamedComplexVector( stream, j, 3 );
+		StGermain_PrintNamedComplexVector( stream, k, 3 );
+		
+		angle = M_PI / 2.0;
+		
+		Journal_Printf(stream, "Axis Rotation\n");				
+		StGermain_RotateCoordinateAxisComplex( k, I_AXIS, angle, vector ) ;
+		Journal_Printf( stream, "K Rotated %g radians around I axis - \n", angle);
+		Cmplx_Subtract(vector[0], j[0], differenceVector[0]);
+		Cmplx_Subtract(vector[1], j[1], differenceVector[1]);
+		Cmplx_Subtract(vector[2], j[2], differenceVector[2]);
+		
+		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
+			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
+			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, j, 3);
+		}
+		else {
+			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, j, 3);
+		}
+		
+		Journal_Printf(stream, "Angle Rotation\n");		
+		StGermain_RotateComplexVector(k, angle,0.0, 0.0, vector);
+		Journal_Printf( stream, "K Rotated %g radians around I axis - \n", angle); 
+		Cmplx_Subtract(vector[0], j[0], differenceVector[0]);
+		Cmplx_Subtract(vector[1], j[1], differenceVector[1]);
+		Cmplx_Subtract(vector[2], j[2], differenceVector[2]);
+		
+		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
+			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
+			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, j, 3);
+		}
+		else {
+			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, j, 3);
+		}
+		
+		Journal_Printf(stream, "Axis Rotation\n");		
+		StGermain_RotateCoordinateAxisComplex( i, J_AXIS, angle, vector );
+		Journal_Printf( stream, "I Rotated %g radians around J axis - \n", angle); 
+		Cmplx_Subtract(vector[0], k[0], differenceVector[0]);
+		Cmplx_Subtract(vector[1], k[1], differenceVector[1]);
+		Cmplx_Subtract(vector[2], k[2], differenceVector[2]);
+		
+		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
+			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
+			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, k, 3);
+		}
+		else {
+			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, k, 3);
+		}
+		
+		Journal_Printf(stream, "Angle Rotation\n");
+		StGermain_RotateComplexVector(i, 0.0, angle, 0.0, vector );
+		Journal_Printf( stream, "I Rotated %g radians around J axis - \n", angle); 
+		Cmplx_Subtract(vector[0], k[0], differenceVector[0]);
+		Cmplx_Subtract(vector[1], k[1], differenceVector[1]);
+		Cmplx_Subtract(vector[2], k[2], differenceVector[2]);
+		
+		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
+			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
+			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, k, 3);
+		}
+		else {
+			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, k, 3);
+		}
+		
+		Journal_Printf(stream, "Axis Rotation\n");		
+		StGermain_RotateCoordinateAxisComplex( j, K_AXIS, angle, vector );
+		Journal_Printf( stream, "J Rotated %g radians around K axis - \n", angle); 
+		Cmplx_Subtract(vector[0], i[0], differenceVector[0]);
+		Cmplx_Subtract(vector[1], i[1], differenceVector[1]);
+		Cmplx_Subtract(vector[2], i[2], differenceVector[2]);
+		
+		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
+			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
+			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, i, 3);
+		}
+		else {
+			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, i, 3);
+		}
+
+		Journal_Printf(stream, "Angle Rotation\n");
+		StGermain_RotateComplexVector( j, 0.0, 0.0, angle, vector );
+		Journal_Printf( stream, "J Rotated %g radians around K axis - \n", angle); 
+		Cmplx_Subtract(vector[0], i[0], differenceVector[0]);
+		Cmplx_Subtract(vector[1], i[1], differenceVector[1]);
+		Cmplx_Subtract(vector[2], i[2], differenceVector[2]);
+		
+		if ( (Cmplx_Modulus(differenceVector[0]) < tolerance) && (Cmplx_Modulus(differenceVector[1]) < tolerance) &&
+			 (Cmplx_Modulus(differenceVector[2]) < tolerance) ) {
+			Journal_Printf( stream, "Answer within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, i, 3);
+		}
+		else {
+			Journal_Printf( stream, "Answer not within tolerance %g of expected result: ", tolerance);
+			StGermain_PrintNamedComplexVector( stream, i, 3);
+		}
+
+		angle = M_PI / 4.0;
+
+		StGermain_RotateComplexVector(i, 0.0, angle, angle, vector );
+		Journal_Printf( stream, "I Rotated %g radians around J axis "
+		"and %2g radians around K axis: \n", angle, angle);
+		StGermain_PrintNamedComplexVector( stream, vector, 3 );
+
+		StGermain_RotateComplexVector(j, angle, 0.0, angle, vector );
+		Journal_Printf( stream, "J Rotated %g radians around I axis "
+		"and %g radians around K axis: \n", angle, angle); 
+		StGermain_PrintNamedComplexVector( stream, vector, 3 );
+
+		StGermain_RotateComplexVector(k, angle, angle, 0.0, vector );
+		Journal_Printf( stream, "K Rotated %g radians around I axis "
+		"and %g radians around J axis: \n", angle, angle); 
+		StGermain_PrintNamedComplexVector( stream, vector, 3 );
+
+		/* Check addition function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "vector = A + B\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			StGermain_ComplexVectorAddition( vector, A, B, d );
+			StGermain_PrintNamedComplexVector( stream, vector, d );
+		}
+
+		/* Check subtraction function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "vector = A - B\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			StGermain_ComplexVectorSubtraction( vector, A, B, d );
+			StGermain_PrintNamedComplexVector( stream, vector, d );
+		}
+	
+		/* Check Magnitude Function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check Magnitude Function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			Journal_Printf( stream, "dim = %d magnitude A = %2.3f\n", d, StGermain_ComplexVectorMagnitude( A, d ) );
+			Journal_Printf( stream, "dim = %d magnitude B = %2.3f\n", d, StGermain_ComplexVectorMagnitude( B, d ) );
+		}
+
+		/* Check Dot Product */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check Dot Product Function\n");
+		Journal_Printf( stream, "value = A . B \n");
+		
+		for (d = 0; d <=6; d++) {
+		StGermain_ComplexVectorDotProduct(A, B, d, dotProductResult);			
+		Journal_Printf( stream, "dim = %d dot product = %2.3f + %2.3f i\n",
+			d, dotProductResult[0], dotProductResult[1] );
+		}
+
+		/* Check Cross Product */
+		/* Tested against http://www.engplanet.com/redirect.html?3859 */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check Cross Product Function\n");
+		Journal_Printf( stream, " A x B in 3-D\n");
+		StGermain_ComplexVectorCrossProduct( vector, A, B );
+		StGermain_PrintNamedComplexVector( stream, vector, 3 );
+
+		/* Checking centroid function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Checking centroid function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			StGermain_ComplexTriangleCentroid( vector, A, B, C, d );
+			StGermain_PrintNamedComplexVector( stream, vector, d );
+		}
+
+		/* Check Normalisation Function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check Normalisation Function\n");
+		
+		Journal_Printf( stream, "2-D\n\n");
+		d = 2;
+		StGermain_PrintNamedComplexVector( stream, A, d );
+		StGermain_ComplexVectorNormalise( A, d );
+		StGermain_PrintNamedComplexVector( stream, A, d);
+		Journal_Printf( stream, "mag = %2.3f\n", StGermain_ComplexVectorMagnitude( A, d ) );
+
+		Journal_Printf( stream, "3-D\n\n");
+		d = 3;
+		StGermain_PrintNamedComplexVector( stream, B, d );
+		StGermain_ComplexVectorNormalise( B, d );
+		StGermain_PrintNamedComplexVector( stream, B, d);
+		Journal_Printf( stream, "mag = %2.3f\n", StGermain_ComplexVectorMagnitude( B, d ) );
+
+		Journal_Printf( stream, "5-D\n\n");
+		d = 5;
+		StGermain_PrintNamedComplexVector( stream, C, d );
+		StGermain_ComplexVectorNormalise( C, d );
+		StGermain_PrintNamedComplexVector( stream, C, d);
+		Journal_Printf( stream, "mag = %2.3f\n", StGermain_ComplexVectorMagnitude( C, d ) );
+
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check StGermain_ComplexVectorCrossProductMagnitude\n");
+		A[0][REAL_PART] = 1.0; A[0][IMAG_PART] = 1.0; 
+		A[1][REAL_PART] = 2.0; A[1][IMAG_PART] = 0.0;
+		A[2][REAL_PART] = 3.0; A[2][IMAG_PART] = 0.0;
+		B[0][REAL_PART] = 4.0; B[0][IMAG_PART] = 0.0;
+		B[1][REAL_PART] = 5.0; B[1][IMAG_PART] = 0.0;
+		B[2][REAL_PART] = 6.0; B[2][IMAG_PART] = 3.0;
+		StGermain_PrintNamedComplexVector( stream, A, 3);
+		StGermain_PrintNamedComplexVector( stream, B, 3);
+		
+		StGermain_ComplexVectorCrossProductMagnitude(A, B, 2, value ) ;
+		Journal_Printf( stream, "mag = %2.3g + %2.3g i (2D)\n", value[REAL_PART], value[IMAG_PART] );
+		
+		StGermain_ComplexVectorCrossProductMagnitude(A, B, 3, value ) ;
+		Journal_Printf( stream, "mag = %2.3g + %2.3g i (3D)\n", value[REAL_PART], value[IMAG_PART] );
+
+
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check StGermain_ComplexScalarTripleProduct \n");
+		
+		matrix = Memory_Alloc_2DArray( Cmplx, 3, 3, (Name)"matrix"  );
+		
+		matrix[0][0][REAL_PART] = 1.0; 	matrix[0][0][IMAG_PART] = 1.0;
+		matrix[0][1][REAL_PART] = 2.0; 	matrix[0][1][IMAG_PART] = 0.0; 
+		matrix[0][2][REAL_PART] = 3.0; 	matrix[0][2][IMAG_PART] = 2.0;
+		matrix[1][0][REAL_PART] = 4.0; 	matrix[1][0][IMAG_PART] = 0.0;
+		matrix[1][1][REAL_PART] = 5.0; 	matrix[1][1][IMAG_PART] = 3.0; 
+		matrix[1][2][REAL_PART] = 6.0; 	matrix[1][2][IMAG_PART] = 0.0;
+		matrix[2][0][REAL_PART] = 7.0; 	matrix[2][0][IMAG_PART] = 1.0;
+		matrix[2][1][REAL_PART] = 8.0; 	matrix[2][1][IMAG_PART] = 0.0;
+		matrix[2][2][REAL_PART] = 11.0; matrix[2][2][IMAG_PART] = 1.0;
+		StGermain_PrintNamedComplexVector( stream, matrix[0], 3);
+		StGermain_PrintNamedComplexVector( stream, matrix[1], 3);
+		StGermain_PrintNamedComplexVector( stream, matrix[2], 3);
+
+		StGermain_ComplexScalarTripleProduct( matrix[0], matrix[1], matrix[2], value );
+		Journal_Printf( stream, "scalar triple product: ");
+		Journal_PrintCmplx( stream, value );
+		
+		StGermain_ComplexScalarTripleProduct( matrix[2], matrix[0], matrix[1], value );
+		Journal_Printf( stream, "scalar triple product: ");
+		Journal_PrintCmplx( stream, value );
+		StGermain_ComplexScalarTripleProduct( matrix[1], matrix[2], matrix[0], value );
+		Journal_Printf( stream, "scalar triple product: ");
+		Journal_PrintCmplx( stream, value );
+		
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check Vector_ToComplexVector function \n");
+		
+		realVector[0] = 1.0; realVector[1] = 2.0; realVector[2] = 3.0;
+		
+		StGermain_PrintNamedVector(stream, realVector, 3);
+		Vector_ToComplexVector(realVector, 3, matrix[0]) ;
+		StGermain_PrintNamedComplexVector( stream, matrix[0], 3);
+
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "Check ComplexVector_ToVector function \n");	
+		
+		matrix[0][0][REAL_PART] = 5.0; 	matrix[0][0][IMAG_PART] = 0.0;
+		matrix[0][1][REAL_PART] = 6.0; 	matrix[0][1][IMAG_PART] = 0.0; 
+		matrix[0][2][REAL_PART] = 7.0; 	matrix[0][2][IMAG_PART] = 0.0;
+		
+		StGermain_PrintNamedComplexVector( stream, matrix[0], 3);
+		ComplexVector_ToVector(matrix[0], 3, realVector) ;
+		StGermain_PrintNamedVector(stream, realVector, 3);
+
+		pcu_filename_expected( "testComplexVectorMathOperations.expected", expected_file );
+		pcu_check_fileEq( "testComplexVectorMathOperations.dat", expected_file );
+		remove( "testComplexVectorMathOperations.dat" );
+
+		Memory_Free( matrix );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void ComplexVectorMathSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, ComplexVectorMathSuiteData );
+   pcu_suite_setFixtures( suite, ComplexVectorMathSuite_Setup, ComplexVectorMathSuite_Teardown );
+   pcu_suite_addTest( suite, ComplexVectorMathSuite_TestComplexVectorMathBasic );
+   pcu_suite_addTest( suite, ComplexVectorMathSuite_TestComplexVectorMathOperations );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/DelaunaySuite.c
--- a/Geometry/tests/DelaunaySuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the DelaunaySuite
-**
-** $Id: testDelaunay.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "DelaunaySuite.h"
-
-#define PI 3.1415926535897932384626
-#define epsilon 0.001
-
-typedef enum pointsType_t {
-	Irregular,
-	Regular,
-	Polygon
-} pointsType;
-
-typedef struct {
-	DelaunayAttributes 	attr;
-	Dictionary*		dict;
-} DelaunaySuiteData;
-
-void GeneratePoints( CoordF* sites, int numSites, pointsType *p ) {
-	int i, j, count;
-	int num = numSites;
-
-	if( *p == Irregular ) {
-		for( i = 0; i < num; i++ ) {
-			sites[i][0] = drand48();
-			sites[i][1] = drand48();
-		}
-	}
-	else if( *p == Regular ) {
-		count = 0;
-		num = sqrt((float)num);
-		for( i = 0; i < num; i++ ) {
-			for( j = 0; j < num; j++ ) {
-				sites[count][0] = ((float)i)*(1.0/((float)num));
-				sites[count][1] = ((float)j)*(1.0/((float)num));
-
-				count++;
-			}
-		}
-	}
-	else if( *p == Polygon ) {
-		for( i = 0; i < num-1; i++ ) {
-			sites[i][0] = cos( ((float)i)*2.0*PI/((float)(num-1)) );
-			sites[i][1] = sin( ((float)i)*2.0*PI/((float)(num-1)) );
-		}
-	}
-}
-
-void DelaunaySuite_Setup( DelaunaySuiteData* data ) {
-	data->attr.BuildBoundingTriangle = 0;
-	data->attr.BuildTriangleIndices = 1;
-	data->attr.BuildTriangleNeighbours = 1;
-	data->attr.CreateVoronoiVertices = 1;
-	data->attr.CalculateVoronoiSides = 1;
-	data->attr.CalculateVoronoiSurfaceArea = 1;
-	data->attr.FindNeighbours = 1;
-
-	data->dict = Dictionary_New();
-}
-
-void DelaunaySuite_Teardown( DelaunaySuiteData* data ) {
-	Stg_Class_Delete( data->dict );
-}
-
-void DelaunaySuite_TriangulateRegularMesh( DelaunaySuiteData* data ) {
-	Delaunay*	delaunay;
-	pointsType	p		= Regular;
-	CoordF*		sites;
-	int		array[10]	= { 16, 25, 36, 49, 64, 81, 100, 121, 144, 269 };
-	float		sqroot, area;
-	int 		i, j;
-	Bool		pass		= True;
-
-	for( i = 0; i < 10; i++ ) {
-		sites = Memory_Alloc_Array_Unnamed( CoordF, array[i] );
-		memset( sites, 0, sizeof(CoordF)*array[i] );
-
-		GeneratePoints( sites, array[i], &p );
-
-		delaunay = Delaunay_New( "Delaunay-Regular", data->dict, sites, array[i], 0, &data->attr );
-		Stg_Component_Build( delaunay, NULL, True );
-
-		sqroot = sqrt((float)array[i]);
-		area = (1.0/sqroot)*(1.0/sqroot);
-		
-		for( j = 0; j < array[i]; j++ ) {
-			if( delaunay->hull[j] )
-				continue;
-
-			if( j > 0 && j < sqrt((float)j) )
-				if( FABS( area - delaunay->voronoiArea[j] ) > epsilon )
-					pass = False;
-		}
-
-		Stg_Class_Delete( delaunay );
-		Memory_Free( sites );
-	}
-
-	pcu_check_true( pass );
-}
-
-void DelaunaySuite_TriangulateIrregularMesh( DelaunaySuiteData* data ) {
-	Delaunay*	delaunay;
-	pointsType	p		= Irregular;
-	CoordF*		sites;
-	int 		pass		= True;
-	int 		i;
-		
-	for( i = 10; i < 210; i++ ) {
-		sites = Memory_Alloc_Array_Unnamed( CoordF, i );
-		memset( sites, 0, sizeof( CoordF )*i );
-		
-		GeneratePoints( sites, i, &p );
-	
-		delaunay = Delaunay_New( "Delaunay-Regular", data->dict, sites, i, 0, &data->attr );
-		Stg_Component_Build( delaunay, NULL, True );
-
-		if( delaunay->numFaces != delaunay->numEdges - delaunay->numSites + 2 )
-			pass = False;
-
-		Stg_Class_Delete( delaunay );
-		Memory_Free( sites );
-	}
-
-	pcu_check_true( pass );
-}
-
-void DelaunaySuite_TriangulatePolygonMesh( DelaunaySuiteData* data ) {
-	Delaunay*	delaunay;
-	CoordF*		sites;
-	char		filename[PCU_PATH_MAX];
-	FILE*		fp;
-	float		theta;
-	float		voronoiArea;
-	float		a, area, side;
-	int 		i, j;
-	int		pass		= True;
-	
-	pcu_filename_input( "small.txt", filename );
-	fp = fopen( filename, "r+" );
-
-	fscanf( fp, "%d", &i );
-
-	theta = 2.0*PI/((float)(i-1));
-
-	sites = Memory_Alloc_Array_Unnamed( CoordF, i );
-	memset( sites, 0, sizeof(CoordF)*i );
-
-	j = 0;
-	while( fscanf( fp, "%f %f", sites[j], sites[j] + 1 ) != EOF ) {
-		j++;
-	}
-
-	delaunay = Delaunay_New( "Delaunay-Polygon", data->dict, sites, i, 0, &data->attr );
-	Stg_Component_Build( delaunay, NULL, True );
-
-	for( j = 0; j < i; j++ ) {
-		if( fabs( sites[j][0] ) < 0.00001 && fabs( sites[j][1] ) < 0.00001 ) {
-			side = delaunay->voronoiSides[j][0];
-			voronoiArea = delaunay->voronoiArea[j];
-			break;
-		}
-	}
-
-	a = ( (0.5*side)/sin(0.5*theta) );
-	area = (0.5*a*a*sin(theta))*((float)(i-1));
-
-	if( FABS( area - voronoiArea ) > epsilon )
-		pass = False;
-
-	fclose( fp );
-
-	Stg_Class_Delete( delaunay );
-	Memory_Free( sites );
-
-	pcu_check_true( pass );
-}
-
-void DelaunaySuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, DelaunaySuiteData );
-   pcu_suite_setFixtures( suite, DelaunaySuite_Setup, DelaunaySuite_Teardown );
-   pcu_suite_addTest( suite, DelaunaySuite_TriangulateRegularMesh );
-   pcu_suite_addTest( suite, DelaunaySuite_TriangulateIrregularMesh );
-   pcu_suite_addTest( suite, DelaunaySuite_TriangulatePolygonMesh );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/DelaunaySuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/DelaunaySuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,224 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the DelaunaySuite
+**
+** $Id: testDelaunay.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "DelaunaySuite.h"
+
+#define PI 3.1415926535897932384626
+#define epsilon 0.001
+
+typedef enum pointsType_t {
+	Irregular,
+	Regular,
+	Polygon
+} pointsType;
+
+typedef struct {
+	DelaunayAttributes 	attr;
+	Dictionary*		dict;
+} DelaunaySuiteData;
+
+void GeneratePoints( CoordF* sites, int numSites, pointsType *p ) {
+	int i, j, count;
+	int num = numSites;
+
+	if( *p == Irregular ) {
+		for( i = 0; i < num; i++ ) {
+			sites[i][0] = drand48();
+			sites[i][1] = drand48();
+		}
+	}
+	else if( *p == Regular ) {
+		count = 0;
+		num = sqrt((float)num);
+		for( i = 0; i < num; i++ ) {
+			for( j = 0; j < num; j++ ) {
+				sites[count][0] = ((float)i)*(1.0/((float)num));
+				sites[count][1] = ((float)j)*(1.0/((float)num));
+
+				count++;
+			}
+		}
+	}
+	else if( *p == Polygon ) {
+		for( i = 0; i < num-1; i++ ) {
+			sites[i][0] = cos( ((float)i)*2.0*PI/((float)(num-1)) );
+			sites[i][1] = sin( ((float)i)*2.0*PI/((float)(num-1)) );
+		}
+	}
+}
+
+void DelaunaySuite_Setup( DelaunaySuiteData* data ) {
+	data->attr.BuildBoundingTriangle = 0;
+	data->attr.BuildTriangleIndices = 1;
+	data->attr.BuildTriangleNeighbours = 1;
+	data->attr.CreateVoronoiVertices = 1;
+	data->attr.CalculateVoronoiSides = 1;
+	data->attr.CalculateVoronoiSurfaceArea = 1;
+	data->attr.FindNeighbours = 1;
+
+	data->dict = Dictionary_New();
+}
+
+void DelaunaySuite_Teardown( DelaunaySuiteData* data ) {
+	Stg_Class_Delete( data->dict );
+}
+
+void DelaunaySuite_TriangulateRegularMesh( DelaunaySuiteData* data ) {
+	Delaunay*	delaunay;
+	pointsType	p		= Regular;
+	CoordF*		sites;
+	int		array[10]	= { 16, 25, 36, 49, 64, 81, 100, 121, 144, 269 };
+	float		sqroot, area;
+	int 		i, j;
+	Bool		pass		= True;
+
+	for( i = 0; i < 10; i++ ) {
+		sites = Memory_Alloc_Array_Unnamed( CoordF, array[i] );
+		memset( sites, 0, sizeof(CoordF)*array[i] );
+
+		GeneratePoints( sites, array[i], &p );
+
+		delaunay = Delaunay_New( "Delaunay-Regular", data->dict, sites, array[i], 0, &data->attr );
+		Stg_Component_Build( delaunay, NULL, True );
+
+		sqroot = sqrt((float)array[i]);
+		area = (1.0/sqroot)*(1.0/sqroot);
+		
+		for( j = 0; j < array[i]; j++ ) {
+			if( delaunay->hull[j] )
+				continue;
+
+			if( j > 0 && j < sqrt((float)j) )
+				if( FABS( area - delaunay->voronoiArea[j] ) > epsilon )
+					pass = False;
+		}
+
+		Stg_Class_Delete( delaunay );
+		Memory_Free( sites );
+	}
+
+	pcu_check_true( pass );
+}
+
+void DelaunaySuite_TriangulateIrregularMesh( DelaunaySuiteData* data ) {
+	Delaunay*	delaunay;
+	pointsType	p		= Irregular;
+	CoordF*		sites;
+	int 		pass		= True;
+	int 		i;
+		
+	for( i = 10; i < 210; i++ ) {
+		sites = Memory_Alloc_Array_Unnamed( CoordF, i );
+		memset( sites, 0, sizeof( CoordF )*i );
+		
+		GeneratePoints( sites, i, &p );
+	
+		delaunay = Delaunay_New( "Delaunay-Regular", data->dict, sites, i, 0, &data->attr );
+		Stg_Component_Build( delaunay, NULL, True );
+
+		if( delaunay->numFaces != delaunay->numEdges - delaunay->numSites + 2 )
+			pass = False;
+
+		Stg_Class_Delete( delaunay );
+		Memory_Free( sites );
+	}
+
+	pcu_check_true( pass );
+}
+
+void DelaunaySuite_TriangulatePolygonMesh( DelaunaySuiteData* data ) {
+	Delaunay*	delaunay;
+	CoordF*		sites;
+	char		filename[PCU_PATH_MAX];
+	FILE*		fp;
+	float		theta;
+	float		voronoiArea;
+	float		a, area, side;
+	int 		i, j;
+	int		pass		= True;
+	
+	pcu_filename_input( "small.txt", filename );
+	fp = fopen( filename, "r+" );
+
+	fscanf( fp, "%d", &i );
+
+	theta = 2.0*PI/((float)(i-1));
+
+	sites = Memory_Alloc_Array_Unnamed( CoordF, i );
+	memset( sites, 0, sizeof(CoordF)*i );
+
+	j = 0;
+	while( fscanf( fp, "%f %f", sites[j], sites[j] + 1 ) != EOF ) {
+		j++;
+	}
+
+	delaunay = Delaunay_New( "Delaunay-Polygon", data->dict, sites, i, 0, &data->attr );
+	Stg_Component_Build( delaunay, NULL, True );
+
+	for( j = 0; j < i; j++ ) {
+		if( fabs( sites[j][0] ) < 0.00001 && fabs( sites[j][1] ) < 0.00001 ) {
+			side = delaunay->voronoiSides[j][0];
+			voronoiArea = delaunay->voronoiArea[j];
+			break;
+		}
+	}
+
+	a = ( (0.5*side)/sin(0.5*theta) );
+	area = (0.5*a*a*sin(theta))*((float)(i-1));
+
+	if( FABS( area - voronoiArea ) > epsilon )
+		pass = False;
+
+	fclose( fp );
+
+	Stg_Class_Delete( delaunay );
+	Memory_Free( sites );
+
+	pcu_check_true( pass );
+}
+
+void DelaunaySuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, DelaunaySuiteData );
+   pcu_suite_setFixtures( suite, DelaunaySuite_Setup, DelaunaySuite_Teardown );
+   pcu_suite_addTest( suite, DelaunaySuite_TriangulateRegularMesh );
+   pcu_suite_addTest( suite, DelaunaySuite_TriangulateIrregularMesh );
+   pcu_suite_addTest( suite, DelaunaySuite_TriangulatePolygonMesh );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/DimensionMacrosSuite.c
--- a/Geometry/tests/DimensionMacrosSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,137 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the DimensionMacrosSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "DimensionMacrosSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} DimensionMacrosSuiteData;
-
-void DimensionMacrosSuite_testDimensionMacros_DoOneTest( IJK coord, IJK meshSize, Stream* stream ) {
-   IJK newCoord;
-   Index element_I;
-
-   Journal_Printf( stream,  "(%d,%d,%d) in mesh sized %d*%d*%d -> ",
-      coord[0], coord[1], coord[2],
-      meshSize[0], meshSize[1], meshSize[2] );
-
-   Dimension_3DTo1D( coord, meshSize, &element_I );
-   Journal_Printf( stream,  "index %d\n", element_I );
-   Dimension_1DTo3D( element_I, meshSize, newCoord );
-   Journal_Printf( stream,  "which maps back to (%d,%d,%d)\n",
-      newCoord[0], newCoord[1], newCoord[2] );
-}
-
-void DimensionMacrosSuite_Setup( DimensionMacrosSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void DimensionMacrosSuite_Teardown( DimensionMacrosSuiteData* data ) {
-}
-
-void DimensionMacrosSuite_TestDimensionMacros( DimensionMacrosSuiteData* data ) {
-	char		expected_file[PCU_PATH_MAX];
-	Stream*  stream = Journal_Register( Info_Type, (Name)"DimensionMacrosStream"  );
-	IJK		coord;
-   IJK		meshSize;
-   Index		i, j, k;
-
-	Stream_RedirectFile( stream, "testDimensionMacros.dat" );
-
-	Journal_Printf( stream,  "+++ 1D Tests +++\n\n" );
-	coord[I_AXIS] = 3; coord[J_AXIS] = 0; coord[K_AXIS] = 0;
-	meshSize[I_AXIS] = 8; meshSize[J_AXIS] = 0; meshSize[K_AXIS] = 0;
-	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-	
-	coord[I_AXIS] = 0; coord[J_AXIS] = 3; coord[K_AXIS] = 0;
-	meshSize[I_AXIS] = 0; meshSize[J_AXIS] = 8; meshSize[K_AXIS] = 0;
-	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-	
-	coord[I_AXIS] = 0; coord[J_AXIS] = 0; coord[K_AXIS] = 3;
-	meshSize[I_AXIS] = 0; meshSize[J_AXIS] = 0; meshSize[K_AXIS] = 8;
-	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-
-	Journal_Printf( stream,  "\n+++ 2D Tests +++\n\n" );
-	coord[I_AXIS] = 3; coord[J_AXIS] = 4; coord[K_AXIS] = 0;
-	meshSize[I_AXIS] = 8; meshSize[J_AXIS] = 8; meshSize[K_AXIS] = 0;
-	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-	
-	coord[I_AXIS] = 3; coord[J_AXIS] = 0; coord[K_AXIS] = 4;
-	meshSize[I_AXIS] = 8; meshSize[J_AXIS] = 0; meshSize[K_AXIS] = 8;
-	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-	
-	coord[I_AXIS] = 0; coord[J_AXIS] = 3; coord[K_AXIS] = 4;
-	meshSize[I_AXIS] = 0; meshSize[J_AXIS] = 8; meshSize[K_AXIS] = 8;
-	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-	
-	Journal_Printf( stream,  "\n+++ 3D Tests +++\n\n" );
-	meshSize[I_AXIS] = 3; meshSize[J_AXIS] = 4; meshSize[K_AXIS] = 5;
-	for ( k=0; k < meshSize[K_AXIS]; k++ ) {
-		for ( j=0; j < meshSize[J_AXIS]; j++ ) {
-			for ( i=0; i < meshSize[I_AXIS]; i++ ) {
-				coord[I_AXIS] = i; coord[J_AXIS] = j; coord[K_AXIS] = k;
-				DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
-			}
-		}
-	}	
-
-	pcu_filename_expected( "testDimensionMacros.expected", expected_file );
-	pcu_check_fileEq( "testDimensionMacros.dat", expected_file );
-	remove( "testDimensionMacros.dat" );
-
-	Stream_CloseAndFreeFile( stream );
-}
-
-void DimensionMacrosSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, DimensionMacrosSuiteData );
-   pcu_suite_setFixtures( suite, DimensionMacrosSuite_Setup, DimensionMacrosSuite_Teardown );
-   pcu_suite_addTest( suite, DimensionMacrosSuite_TestDimensionMacros );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/DimensionMacrosSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/DimensionMacrosSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,137 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the DimensionMacrosSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "DimensionMacrosSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} DimensionMacrosSuiteData;
+
+void DimensionMacrosSuite_testDimensionMacros_DoOneTest( IJK coord, IJK meshSize, Stream* stream ) {
+   IJK newCoord;
+   Index element_I;
+
+   Journal_Printf( stream,  "(%d,%d,%d) in mesh sized %d*%d*%d -> ",
+      coord[0], coord[1], coord[2],
+      meshSize[0], meshSize[1], meshSize[2] );
+
+   Dimension_3DTo1D( coord, meshSize, &element_I );
+   Journal_Printf( stream,  "index %d\n", element_I );
+   Dimension_1DTo3D( element_I, meshSize, newCoord );
+   Journal_Printf( stream,  "which maps back to (%d,%d,%d)\n",
+      newCoord[0], newCoord[1], newCoord[2] );
+}
+
+void DimensionMacrosSuite_Setup( DimensionMacrosSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void DimensionMacrosSuite_Teardown( DimensionMacrosSuiteData* data ) {
+}
+
+void DimensionMacrosSuite_TestDimensionMacros( DimensionMacrosSuiteData* data ) {
+	char		expected_file[PCU_PATH_MAX];
+	Stream*  stream = Journal_Register( Info_Type, (Name)"DimensionMacrosStream"  );
+	IJK		coord;
+   IJK		meshSize;
+   Index		i, j, k;
+
+	Stream_RedirectFile( stream, "testDimensionMacros.dat" );
+
+	Journal_Printf( stream,  "+++ 1D Tests +++\n\n" );
+	coord[I_AXIS] = 3; coord[J_AXIS] = 0; coord[K_AXIS] = 0;
+	meshSize[I_AXIS] = 8; meshSize[J_AXIS] = 0; meshSize[K_AXIS] = 0;
+	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+	
+	coord[I_AXIS] = 0; coord[J_AXIS] = 3; coord[K_AXIS] = 0;
+	meshSize[I_AXIS] = 0; meshSize[J_AXIS] = 8; meshSize[K_AXIS] = 0;
+	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+	
+	coord[I_AXIS] = 0; coord[J_AXIS] = 0; coord[K_AXIS] = 3;
+	meshSize[I_AXIS] = 0; meshSize[J_AXIS] = 0; meshSize[K_AXIS] = 8;
+	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+
+	Journal_Printf( stream,  "\n+++ 2D Tests +++\n\n" );
+	coord[I_AXIS] = 3; coord[J_AXIS] = 4; coord[K_AXIS] = 0;
+	meshSize[I_AXIS] = 8; meshSize[J_AXIS] = 8; meshSize[K_AXIS] = 0;
+	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+	
+	coord[I_AXIS] = 3; coord[J_AXIS] = 0; coord[K_AXIS] = 4;
+	meshSize[I_AXIS] = 8; meshSize[J_AXIS] = 0; meshSize[K_AXIS] = 8;
+	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+	
+	coord[I_AXIS] = 0; coord[J_AXIS] = 3; coord[K_AXIS] = 4;
+	meshSize[I_AXIS] = 0; meshSize[J_AXIS] = 8; meshSize[K_AXIS] = 8;
+	DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+	
+	Journal_Printf( stream,  "\n+++ 3D Tests +++\n\n" );
+	meshSize[I_AXIS] = 3; meshSize[J_AXIS] = 4; meshSize[K_AXIS] = 5;
+	for ( k=0; k < meshSize[K_AXIS]; k++ ) {
+		for ( j=0; j < meshSize[J_AXIS]; j++ ) {
+			for ( i=0; i < meshSize[I_AXIS]; i++ ) {
+				coord[I_AXIS] = i; coord[J_AXIS] = j; coord[K_AXIS] = k;
+				DimensionMacrosSuite_testDimensionMacros_DoOneTest( coord, meshSize, stream );
+			}
+		}
+	}	
+
+	pcu_filename_expected( "testDimensionMacros.expected", expected_file );
+	pcu_check_fileEq( "testDimensionMacros.dat", expected_file );
+	remove( "testDimensionMacros.dat" );
+
+	Stream_CloseAndFreeFile( stream );
+}
+
+void DimensionMacrosSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, DimensionMacrosSuiteData );
+   pcu_suite_setFixtures( suite, DimensionMacrosSuite_Setup, DimensionMacrosSuite_Teardown );
+   pcu_suite_addTest( suite, DimensionMacrosSuite_TestDimensionMacros );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/EdgeSuite.c
--- a/Geometry/tests/EdgeSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the EdgeSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "EdgeSuite.h"
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} EdgeSuiteData;
-
-void EdgeSuite_Setup( EdgeSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void EdgeSuite_Teardown( EdgeSuiteData* data ) {
-}
-
-void EdgeSuite_TestEdge( EdgeSuiteData* data ) {
-	Stream*	stream;
-	char		expected_file[PCU_PATH_MAX];
-	int procToWatch;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-   if( data->rank == procToWatch ) {
-		Triangle			tri[100];
-      Triangle_Index	triCount = 100;
-		Edge_Index		edgeCount;
-		Edge_List		edge;
-		EdgeFaces_List	edgeFace;
-		Triangle_Index	tri_I;
-		Edge_Index		edge_I;
-
-		stream = Journal_Register( Info_Type, (Name)"EdgeStream" );
-		Stream_RedirectFile( stream, "testEdge.dat" );
- 
-		tri[0][0] = 0;
-		tri[0][1] = 1;
-		tri[0][2] = 2;
-		for( tri_I = 1; tri_I < triCount; tri_I++ ) {
-			tri[tri_I][0] = tri[tri_I - 1][0] + 1;
-			tri[tri_I][1] = tri[tri_I - 1][2] + 1;
-			tri[tri_I][2] = tri[tri_I - 1][1] + 1;
-		}
-
-		edgeCount = Edge_BuildList_FromTriangles( tri, triCount, &edge, &edgeFace );
-
-		for( edge_I = 0; edge_I < edgeCount; edge_I++ ) {
-			Journal_Printf( stream, "Edge: %u, points: { %u, %u }, ", edge_I, edge[edge_I][0], edge[edge_I][1] );
-			Journal_Printf( stream, "faces: { %u, %u }\n", edgeFace[edge_I][0], edgeFace[edge_I][1] );
-		}
-
-		pcu_filename_expected( "testEdge.expected", expected_file );
-		pcu_check_fileEq( "testEdge.dat", expected_file );
-		remove( "testEdge.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-
-		if( edge ) Memory_Free( edge );
-		if( edgeFace ) Memory_Free( edgeFace );
-	}
-}
-
-void EdgeSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, EdgeSuiteData );
-   pcu_suite_setFixtures( suite, EdgeSuite_Setup, EdgeSuite_Teardown );
-   pcu_suite_addTest( suite, EdgeSuite_TestEdge );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/EdgeSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/EdgeSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,115 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the EdgeSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "EdgeSuite.h"
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} EdgeSuiteData;
+
+void EdgeSuite_Setup( EdgeSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void EdgeSuite_Teardown( EdgeSuiteData* data ) {
+}
+
+void EdgeSuite_TestEdge( EdgeSuiteData* data ) {
+	Stream*	stream;
+	char		expected_file[PCU_PATH_MAX];
+	int procToWatch;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+   if( data->rank == procToWatch ) {
+		Triangle			tri[100];
+      Triangle_Index	triCount = 100;
+		Edge_Index		edgeCount;
+		Edge_List		edge;
+		EdgeFaces_List	edgeFace;
+		Triangle_Index	tri_I;
+		Edge_Index		edge_I;
+
+		stream = Journal_Register( Info_Type, (Name)"EdgeStream" );
+		Stream_RedirectFile( stream, "testEdge.dat" );
+ 
+		tri[0][0] = 0;
+		tri[0][1] = 1;
+		tri[0][2] = 2;
+		for( tri_I = 1; tri_I < triCount; tri_I++ ) {
+			tri[tri_I][0] = tri[tri_I - 1][0] + 1;
+			tri[tri_I][1] = tri[tri_I - 1][2] + 1;
+			tri[tri_I][2] = tri[tri_I - 1][1] + 1;
+		}
+
+		edgeCount = Edge_BuildList_FromTriangles( tri, triCount, &edge, &edgeFace );
+
+		for( edge_I = 0; edge_I < edgeCount; edge_I++ ) {
+			Journal_Printf( stream, "Edge: %u, points: { %u, %u }, ", edge_I, edge[edge_I][0], edge[edge_I][1] );
+			Journal_Printf( stream, "faces: { %u, %u }\n", edgeFace[edge_I][0], edgeFace[edge_I][1] );
+		}
+
+		pcu_filename_expected( "testEdge.expected", expected_file );
+		pcu_check_fileEq( "testEdge.dat", expected_file );
+		remove( "testEdge.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+
+		if( edge ) Memory_Free( edge );
+		if( edgeFace ) Memory_Free( edgeFace );
+	}
+}
+
+void EdgeSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, EdgeSuiteData );
+   pcu_suite_setFixtures( suite, EdgeSuite_Setup, EdgeSuite_Teardown );
+   pcu_suite_addTest( suite, EdgeSuite_TestEdge );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/LineSuite.c
--- a/Geometry/tests/LineSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the LineSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "LineSuite.h"
-
-typedef struct {
-	MPI_Comm comm;
-	int rank;
-	int nProcs;
-} LineSuiteData;
-
-void LineSuite_Setup( LineSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void LineSuite_Teardown( LineSuiteData* data ) {
-}
-
-void LineSuite_TestLine( LineSuiteData* data ) {
-	Coord		points[4] = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.5, 0.9, 0.5 }, { 1.2, 0.7, 0.8 } };
-	Coord		insidePoint = { 0.7, 0.3, 0.0 };
-	Coord		outsidePoint = { -0.2, 0.3, 0.0 };
-	Stg_Line	lines[4];
-
-	/*
-	** When lines are to be used as boundaries (ie. determining whether other points lay
-	** to the left or right of the line), points must be specified from left to right, where
-	** the region in front of the line is considered the 'inside'.
-	*/
-	Stg_Line_CalcFromPoints( lines[0], points[0], points[1] );
-	Stg_Line_CalcFromPoints( lines[1], points[2], points[0] );
-	Stg_Line_CalcFromPoints( lines[2], points[1], points[3] );
-	Stg_Line_CalcFromPoints( lines[3], points[3], points[2] );
-
-	pcu_check_true( Stg_Line_PointIsInside( lines[0], insidePoint ) );
-	pcu_check_true( Stg_Line_PointIsInside( lines[0], outsidePoint ) );
-	pcu_check_true( Stg_Line_PointIsInside( lines[1], insidePoint ) );
-	pcu_check_true( !Stg_Line_PointIsInside( lines[1], outsidePoint ) );
-	pcu_check_true( Stg_Line_PointIsInside( lines[2], insidePoint ) );
-	pcu_check_true( Stg_Line_PointIsInside( lines[2], outsidePoint ) );
-	pcu_check_true( Stg_Line_PointIsInside( lines[3], insidePoint ) );
-	pcu_check_true( Stg_Line_PointIsInside( lines[3], outsidePoint ) );
-}
-
-void LineSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, LineSuiteData );
-   pcu_suite_setFixtures( suite, LineSuite_Setup, LineSuite_Teardown );
-   pcu_suite_addTest( suite, LineSuite_TestLine );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/LineSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/LineSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,95 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the LineSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "LineSuite.h"
+
+typedef struct {
+	MPI_Comm comm;
+	int rank;
+	int nProcs;
+} LineSuiteData;
+
+void LineSuite_Setup( LineSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void LineSuite_Teardown( LineSuiteData* data ) {
+}
+
+void LineSuite_TestLine( LineSuiteData* data ) {
+	Coord		points[4] = { { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 }, { 0.5, 0.9, 0.5 }, { 1.2, 0.7, 0.8 } };
+	Coord		insidePoint = { 0.7, 0.3, 0.0 };
+	Coord		outsidePoint = { -0.2, 0.3, 0.0 };
+	Stg_Line	lines[4];
+
+	/*
+	** When lines are to be used as boundaries (ie. determining whether other points lay
+	** to the left or right of the line), points must be specified from left to right, where
+	** the region in front of the line is considered the 'inside'.
+	*/
+	Stg_Line_CalcFromPoints( lines[0], points[0], points[1] );
+	Stg_Line_CalcFromPoints( lines[1], points[2], points[0] );
+	Stg_Line_CalcFromPoints( lines[2], points[1], points[3] );
+	Stg_Line_CalcFromPoints( lines[3], points[3], points[2] );
+
+	pcu_check_true( Stg_Line_PointIsInside( lines[0], insidePoint ) );
+	pcu_check_true( Stg_Line_PointIsInside( lines[0], outsidePoint ) );
+	pcu_check_true( Stg_Line_PointIsInside( lines[1], insidePoint ) );
+	pcu_check_true( !Stg_Line_PointIsInside( lines[1], outsidePoint ) );
+	pcu_check_true( Stg_Line_PointIsInside( lines[2], insidePoint ) );
+	pcu_check_true( Stg_Line_PointIsInside( lines[2], outsidePoint ) );
+	pcu_check_true( Stg_Line_PointIsInside( lines[3], insidePoint ) );
+	pcu_check_true( Stg_Line_PointIsInside( lines[3], outsidePoint ) );
+}
+
+void LineSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, LineSuiteData );
+   pcu_suite_setFixtures( suite, LineSuite_Setup, LineSuite_Teardown );
+   pcu_suite_addTest( suite, LineSuite_TestLine );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/ParallelDelaunaySuite.c
--- a/Geometry/tests/ParallelDelaunaySuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,293 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ParallelDelaunaySuite
-**
-** $Id: testParallelDelaunay.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include "ParallelDelaunaySuite.h"
-
-typedef enum pointsType_t{
-	Irregular,
-	Regular,
-	Polygon
-}pointsType;
-
-#define PI 3.1415926535897932384626
-#define EPS 0.0001
-#define MAX_NEIGHBOURS 10000
-
-typedef struct {
-	DelaunayAttributes	attr;
-	Dictionary*		dict;
-} ParallelDelaunaySuiteData;
-
-void _GeneratePoints( CoordF* sites, int numSites, pointsType *p ) {
-	int i, j, count;
-	int num = numSites;
-
-	if( *p == Irregular ) {
-		for( i = 0; i < num; i++ ) {
-			sites[i][0] = drand48();
-			sites[i][1] = drand48();
-		}
-	}
-	else if( *p == Regular ) {
-		count = 0;
-		num = sqrt((float)num);
-		for( i = 0; i < num; i++ ) {
-			for( j = 0; j < num; j++ ) {
-				sites[count][0] = ((float)i)*(1.0/((float)num));
-				sites[count][1] = ((float)j)*(1.0/((float)num));
-
-				count++;
-			}
-		}
-	}
-	else if( *p == Polygon ) {
-		for( i = 0; i < num-1; i++ ) {
-			sites[i][0] = cos( ((float)i)*2.0*PI/((float)(num-1)) );
-			sites[i][1] = sin( ((float)i)*2.0*PI/((float)(num-1)) );
-		}
-	}
-}
-
-int CompareFunction( const void* a, const void* b ) {
-	int *p, *q;
-
-	p = (int*)a;
-	q = (int*)b;
-
-	if( *p > *q )
-		return 1;
-	else if( *p < *q )
-		return -1;
-	else
-		return 0;
-}
-
-void ParallelDelaunaySuite_Setup( ParallelDelaunaySuiteData* data ) {
-	data->attr.BuildBoundingTriangle = 0;
-	data->attr.BuildTriangleIndices = 1;
-	data->attr.BuildTriangleNeighbours = 1;
-	data->attr.CreateVoronoiVertices = 1;
-	data->attr.CalculateVoronoiSides = 1;
-	data->attr.CalculateVoronoiSurfaceArea = 1;
-	data->attr.FindNeighbours = 1;
-
-	data->dict = Dictionary_New();
-}
-
-void ParallelDelaunaySuite_Teardown( ParallelDelaunaySuiteData* data ) {
-	Stg_Class_Delete( data->dict );
-}
-
-/* NOTE: neither this test, nor the next one, works for a triangulation of 900 sites
- *       or greater... note sure why
- */
-void ParallelDelaunaySuite_TestIrregular( ParallelDelaunaySuiteData* data ) {
-	ParallelDelaunay*	pd;
-	Delaunay*		d;
-	CoordF*			sites;
-	pointsType		p 		= Irregular;
-	int			numSites[4]	= { 100, 400, 900, 1600 };
-	int			nsites;
-	MPI_Comm		mpiComm;
-	int			rank, nRanks;
-	int			i, j, k = 0, m;
-	int			dNeighbours[MAX_NEIGHBOURS];
-	int			pdNeighbours[MAX_NEIGHBOURS];
-	int			voronoiAreaTest	= 1;
-	int			voronoiSideTest	= 1;
-	int			triangleCountTest = 1;
-
-	MPI_Comm_dup( MPI_COMM_WORLD, &mpiComm );
-	MPI_Comm_rank( mpiComm, &rank );
-	MPI_Comm_size( mpiComm, &nRanks );
-
-	for( i = 0; i < 4; i++ ) {
-		nsites = numSites[i];
-
-		if( rank == 0 ) {
-			sites = Memory_Alloc_Array( CoordF, nsites, "testDelaunayParallel_sites" );
-			memset( sites, 0, sizeof( CoordF ) * nsites );
-			_GeneratePoints( sites, nsites, &p );
-		}
-
-		pd = ParallelDelaunay_New( "Delaunay-Parallel", data->dict, sites, nsites, rank, nRanks, &mpiComm, &data->attr );
-		Stg_Component_Build( pd, NULL, True );
-		Stg_Component_Execute( pd, NULL, True );
-
-		ParallelDelaunay_GatherTriangulation( pd );
-		MPI_Barrier( mpiComm );
-
-		if( rank == 0 ) {
-			d = Delaunay_New( "Delaunay-Serial", data->dict, sites, nsites, 0, &data->attr );
-			Stg_Component_Build( d, NULL, True );
-
-			for( j = 0; j < nsites; j++ ) {
-				if( fabs( d->voronoiArea[j] - pd->voronoiArea[j] ) > EPS )
-					voronoiAreaTest = 0;
-
-				if( dNeighbours[k] != pdNeighbours[k] )
-					continue;
-
-				memset( dNeighbours, 0, sizeof( dNeighbours ) );
-				memset( pdNeighbours, 0, sizeof( pdNeighbours ) );
-
-				memcpy( dNeighbours, d->neighbours[j], sizeof( int ) * d->numNeighbours[j] );
-				memcpy( pdNeighbours, pd->neighbours[j], sizeof( int ) * pd->numNeighbours[j] );
-
-				qsort( dNeighbours, d->numNeighbours[j], sizeof( int ), CompareFunction );
-				qsort( pdNeighbours, pd->numNeighbours[j], sizeof( int ), CompareFunction );
-
-				for( k = 0; k < (int)(d->numNeighbours[j]); k++ ) {
-					if( dNeighbours[k] != pdNeighbours[k] )
-						continue;
-
-					for( m = 0; m < (int)(d->numNeighbours[j]); m++ ) {
-						if( d->neighbours[j][k] == pd->neighbours[j][m] )
-							if( fabs( d->voronoiSides[j][k] - pd->voronoiSides[j][m] ) > EPS )
-								voronoiSideTest = 0;
-					}
-				}
-			}
-
-			if( d->numTriangles != pd->numTriangles )
-				triangleCountTest = 0;
-
-			Stg_Class_Delete( d );
-		}
-
-		Stg_Class_Delete( pd );
-		
-		if( rank == 0 ) {
-			Memory_Free( sites );
-
-			pcu_check_true( voronoiAreaTest );
-			pcu_check_true( voronoiSideTest );
-			pcu_check_true( triangleCountTest );
-		}
-	}
-}
-
-void ParallelDelaunaySuite_TestRegular( ParallelDelaunaySuiteData* data ) {
-	ParallelDelaunay*	pd;
-	Delaunay*		d;
-	CoordF*			sites;
-	pointsType		p 		= Regular;
-	int			numSites[4]	= { 100, 400, 900, 1600 };
-	MPI_Comm		mpiComm;
-	int			rank, nRanks;
-	int			i, j, k, m;
-	int			dNeighbours[MAX_NEIGHBOURS];
-	int			pdNeighbours[MAX_NEIGHBOURS];
-	int			voronoiAreaTest	= 1;
-	int			voronoiSideTest	= 1;
-	int			triangleCountTest = 1;
-
-	MPI_Comm_dup( MPI_COMM_WORLD, &mpiComm );
-	MPI_Comm_rank( mpiComm, &rank );
-	MPI_Comm_size( mpiComm, &nRanks );
-
-	for( i = 0; i < 4; i++ ) {
-		if( rank == 0 ) {
-			sites = Memory_Alloc_Array( CoordF, numSites[i], "testDelaunayParallel_sites" );
-			memset( sites, 0, sizeof( CoordF ) * numSites[i] );
-			_GeneratePoints( sites, numSites[i], &p );
-		}
-
-		pd = ParallelDelaunay_New( "Delaunay-Parallel", data->dict, sites, numSites[i], rank, nRanks, &mpiComm, &data->attr );
-		Stg_Component_Build( pd, NULL, True );
-		Stg_Component_Execute( pd, NULL, True );
-
-		ParallelDelaunay_GatherTriangulation( pd );
-		MPI_Barrier( mpiComm );
-
-		if( rank == 0 ) {
-			d = Delaunay_New( "Delaunay-Serial", data->dict, sites, numSites[i], 0, &data->attr );
-			Stg_Component_Build( d, NULL, True );
-
-			for( j = 0; j < numSites[i]; j++ ) {
-				if( fabs( d->voronoiArea[j] - pd->voronoiArea[j] ) > EPS )
-					voronoiAreaTest = 0;
-
-				memset( dNeighbours, 0, sizeof( dNeighbours ) );
-				memset( pdNeighbours, 0, sizeof( pdNeighbours ) );
-
-				memcpy( dNeighbours, d->neighbours[j], sizeof( int ) * d->numNeighbours[j] );
-				memcpy( pdNeighbours, pd->neighbours[j], sizeof( int ) * pd->numNeighbours[j] );
-
-				qsort( dNeighbours, d->numNeighbours[j], sizeof( int ), CompareFunction );
-				qsort( pdNeighbours, pd->numNeighbours[j], sizeof( int ), CompareFunction );
-
-				for( k = 0; k < (int)(d->numNeighbours[j]); k++ ) {
-					if( dNeighbours[k] != pdNeighbours[k] )
-						continue;
-
-					for( m = 0; m < (int)(d->numNeighbours[j]); m++ ) {
-						if( d->neighbours[j][k] == pd->neighbours[j][m] )
-							if( fabs( d->voronoiSides[j][k] - pd->voronoiSides[j][m] ) > EPS )
-								voronoiSideTest = 0;
-					}
-				}
-			}
-
-			if( d->numTriangles != pd->numTriangles )
-				triangleCountTest = 0;
-
-			Stg_Class_Delete( d );
-		}
-
-		Stg_Class_Delete( pd );
-		
-		if( rank == 0 ) {
-			Memory_Free( sites );
-
-			pcu_check_true( voronoiAreaTest );
-			pcu_check_true( voronoiSideTest );
-			pcu_check_true( triangleCountTest );
-		}
-	}
-}
-
-void ParallelDelaunaySuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, ParallelDelaunaySuiteData );
-   pcu_suite_setFixtures( suite, ParallelDelaunaySuite_Setup, ParallelDelaunaySuite_Teardown );
-   pcu_suite_addTest( suite, ParallelDelaunaySuite_TestIrregular );
-   pcu_suite_addTest( suite, ParallelDelaunaySuite_TestRegular );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/ParallelDelaunaySuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/ParallelDelaunaySuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,293 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ParallelDelaunaySuite
+**
+** $Id: testParallelDelaunay.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include "ParallelDelaunaySuite.h"
+
+typedef enum pointsType_t{
+	Irregular,
+	Regular,
+	Polygon
+}pointsType;
+
+#define PI 3.1415926535897932384626
+#define EPS 0.0001
+#define MAX_NEIGHBOURS 10000
+
+typedef struct {
+	DelaunayAttributes	attr;
+	Dictionary*		dict;
+} ParallelDelaunaySuiteData;
+
+void _GeneratePoints( CoordF* sites, int numSites, pointsType *p ) {
+	int i, j, count;
+	int num = numSites;
+
+	if( *p == Irregular ) {
+		for( i = 0; i < num; i++ ) {
+			sites[i][0] = drand48();
+			sites[i][1] = drand48();
+		}
+	}
+	else if( *p == Regular ) {
+		count = 0;
+		num = sqrt((float)num);
+		for( i = 0; i < num; i++ ) {
+			for( j = 0; j < num; j++ ) {
+				sites[count][0] = ((float)i)*(1.0/((float)num));
+				sites[count][1] = ((float)j)*(1.0/((float)num));
+
+				count++;
+			}
+		}
+	}
+	else if( *p == Polygon ) {
+		for( i = 0; i < num-1; i++ ) {
+			sites[i][0] = cos( ((float)i)*2.0*PI/((float)(num-1)) );
+			sites[i][1] = sin( ((float)i)*2.0*PI/((float)(num-1)) );
+		}
+	}
+}
+
+int CompareFunction( const void* a, const void* b ) {
+	int *p, *q;
+
+	p = (int*)a;
+	q = (int*)b;
+
+	if( *p > *q )
+		return 1;
+	else if( *p < *q )
+		return -1;
+	else
+		return 0;
+}
+
+void ParallelDelaunaySuite_Setup( ParallelDelaunaySuiteData* data ) {
+	data->attr.BuildBoundingTriangle = 0;
+	data->attr.BuildTriangleIndices = 1;
+	data->attr.BuildTriangleNeighbours = 1;
+	data->attr.CreateVoronoiVertices = 1;
+	data->attr.CalculateVoronoiSides = 1;
+	data->attr.CalculateVoronoiSurfaceArea = 1;
+	data->attr.FindNeighbours = 1;
+
+	data->dict = Dictionary_New();
+}
+
+void ParallelDelaunaySuite_Teardown( ParallelDelaunaySuiteData* data ) {
+	Stg_Class_Delete( data->dict );
+}
+
+/* NOTE: neither this test, nor the next one, works for a triangulation of 900 sites
+ *       or greater... note sure why
+ */
+void ParallelDelaunaySuite_TestIrregular( ParallelDelaunaySuiteData* data ) {
+	ParallelDelaunay*	pd;
+	Delaunay*		d;
+	CoordF*			sites;
+	pointsType		p 		= Irregular;
+	int			numSites[4]	= { 100, 400, 900, 1600 };
+	int			nsites;
+	MPI_Comm		mpiComm;
+	int			rank, nRanks;
+	int			i, j, k = 0, m;
+	int			dNeighbours[MAX_NEIGHBOURS];
+	int			pdNeighbours[MAX_NEIGHBOURS];
+	int			voronoiAreaTest	= 1;
+	int			voronoiSideTest	= 1;
+	int			triangleCountTest = 1;
+
+	MPI_Comm_dup( MPI_COMM_WORLD, &mpiComm );
+	MPI_Comm_rank( mpiComm, &rank );
+	MPI_Comm_size( mpiComm, &nRanks );
+
+	for( i = 0; i < 4; i++ ) {
+		nsites = numSites[i];
+
+		if( rank == 0 ) {
+			sites = Memory_Alloc_Array( CoordF, nsites, "testDelaunayParallel_sites" );
+			memset( sites, 0, sizeof( CoordF ) * nsites );
+			_GeneratePoints( sites, nsites, &p );
+		}
+
+		pd = ParallelDelaunay_New( "Delaunay-Parallel", data->dict, sites, nsites, rank, nRanks, &mpiComm, &data->attr );
+		Stg_Component_Build( pd, NULL, True );
+		Stg_Component_Execute( pd, NULL, True );
+
+		ParallelDelaunay_GatherTriangulation( pd );
+		MPI_Barrier( mpiComm );
+
+		if( rank == 0 ) {
+			d = Delaunay_New( "Delaunay-Serial", data->dict, sites, nsites, 0, &data->attr );
+			Stg_Component_Build( d, NULL, True );
+
+			for( j = 0; j < nsites; j++ ) {
+				if( fabs( d->voronoiArea[j] - pd->voronoiArea[j] ) > EPS )
+					voronoiAreaTest = 0;
+
+				if( dNeighbours[k] != pdNeighbours[k] )
+					continue;
+
+				memset( dNeighbours, 0, sizeof( dNeighbours ) );
+				memset( pdNeighbours, 0, sizeof( pdNeighbours ) );
+
+				memcpy( dNeighbours, d->neighbours[j], sizeof( int ) * d->numNeighbours[j] );
+				memcpy( pdNeighbours, pd->neighbours[j], sizeof( int ) * pd->numNeighbours[j] );
+
+				qsort( dNeighbours, d->numNeighbours[j], sizeof( int ), CompareFunction );
+				qsort( pdNeighbours, pd->numNeighbours[j], sizeof( int ), CompareFunction );
+
+				for( k = 0; k < (int)(d->numNeighbours[j]); k++ ) {
+					if( dNeighbours[k] != pdNeighbours[k] )
+						continue;
+
+					for( m = 0; m < (int)(d->numNeighbours[j]); m++ ) {
+						if( d->neighbours[j][k] == pd->neighbours[j][m] )
+							if( fabs( d->voronoiSides[j][k] - pd->voronoiSides[j][m] ) > EPS )
+								voronoiSideTest = 0;
+					}
+				}
+			}
+
+			if( d->numTriangles != pd->numTriangles )
+				triangleCountTest = 0;
+
+			Stg_Class_Delete( d );
+		}
+
+		Stg_Class_Delete( pd );
+		
+		if( rank == 0 ) {
+			Memory_Free( sites );
+
+			pcu_check_true( voronoiAreaTest );
+			pcu_check_true( voronoiSideTest );
+			pcu_check_true( triangleCountTest );
+		}
+	}
+}
+
+void ParallelDelaunaySuite_TestRegular( ParallelDelaunaySuiteData* data ) {
+	ParallelDelaunay*	pd;
+	Delaunay*		d;
+	CoordF*			sites;
+	pointsType		p 		= Regular;
+	int			numSites[4]	= { 100, 400, 900, 1600 };
+	MPI_Comm		mpiComm;
+	int			rank, nRanks;
+	int			i, j, k, m;
+	int			dNeighbours[MAX_NEIGHBOURS];
+	int			pdNeighbours[MAX_NEIGHBOURS];
+	int			voronoiAreaTest	= 1;
+	int			voronoiSideTest	= 1;
+	int			triangleCountTest = 1;
+
+	MPI_Comm_dup( MPI_COMM_WORLD, &mpiComm );
+	MPI_Comm_rank( mpiComm, &rank );
+	MPI_Comm_size( mpiComm, &nRanks );
+
+	for( i = 0; i < 4; i++ ) {
+		if( rank == 0 ) {
+			sites = Memory_Alloc_Array( CoordF, numSites[i], "testDelaunayParallel_sites" );
+			memset( sites, 0, sizeof( CoordF ) * numSites[i] );
+			_GeneratePoints( sites, numSites[i], &p );
+		}
+
+		pd = ParallelDelaunay_New( "Delaunay-Parallel", data->dict, sites, numSites[i], rank, nRanks, &mpiComm, &data->attr );
+		Stg_Component_Build( pd, NULL, True );
+		Stg_Component_Execute( pd, NULL, True );
+
+		ParallelDelaunay_GatherTriangulation( pd );
+		MPI_Barrier( mpiComm );
+
+		if( rank == 0 ) {
+			d = Delaunay_New( "Delaunay-Serial", data->dict, sites, numSites[i], 0, &data->attr );
+			Stg_Component_Build( d, NULL, True );
+
+			for( j = 0; j < numSites[i]; j++ ) {
+				if( fabs( d->voronoiArea[j] - pd->voronoiArea[j] ) > EPS )
+					voronoiAreaTest = 0;
+
+				memset( dNeighbours, 0, sizeof( dNeighbours ) );
+				memset( pdNeighbours, 0, sizeof( pdNeighbours ) );
+
+				memcpy( dNeighbours, d->neighbours[j], sizeof( int ) * d->numNeighbours[j] );
+				memcpy( pdNeighbours, pd->neighbours[j], sizeof( int ) * pd->numNeighbours[j] );
+
+				qsort( dNeighbours, d->numNeighbours[j], sizeof( int ), CompareFunction );
+				qsort( pdNeighbours, pd->numNeighbours[j], sizeof( int ), CompareFunction );
+
+				for( k = 0; k < (int)(d->numNeighbours[j]); k++ ) {
+					if( dNeighbours[k] != pdNeighbours[k] )
+						continue;
+
+					for( m = 0; m < (int)(d->numNeighbours[j]); m++ ) {
+						if( d->neighbours[j][k] == pd->neighbours[j][m] )
+							if( fabs( d->voronoiSides[j][k] - pd->voronoiSides[j][m] ) > EPS )
+								voronoiSideTest = 0;
+					}
+				}
+			}
+
+			if( d->numTriangles != pd->numTriangles )
+				triangleCountTest = 0;
+
+			Stg_Class_Delete( d );
+		}
+
+		Stg_Class_Delete( pd );
+		
+		if( rank == 0 ) {
+			Memory_Free( sites );
+
+			pcu_check_true( voronoiAreaTest );
+			pcu_check_true( voronoiSideTest );
+			pcu_check_true( triangleCountTest );
+		}
+	}
+}
+
+void ParallelDelaunaySuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, ParallelDelaunaySuiteData );
+   pcu_suite_setFixtures( suite, ParallelDelaunaySuite_Setup, ParallelDelaunaySuite_Teardown );
+   pcu_suite_addTest( suite, ParallelDelaunaySuite_TestIrregular );
+   pcu_suite_addTest( suite, ParallelDelaunaySuite_TestRegular );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/PlaneSuite.c
--- a/Geometry/tests/PlaneSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the PlaneSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "PlaneSuite.h"
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} PlaneSuiteData;
-
-void PlaneSuite_Setup( PlaneSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void PlaneSuite_Teardown( PlaneSuiteData* data ) {
-}
-
-void PlaneSuite_TestDistanceToPoint( PlaneSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-   if( data->rank == procToWatch ) {
-		Coord axisA = { 1.0, 0.3, 0.0 };
-		Coord axisB = { -0.3, 1.0, 0.0 };
-		Coord point1 = { 0.0, 0.0, 2.0 };
-		Coord point2 = { 20.0, 100.0, 6.0 };
-		Plane a;
-
-		Plane_CalcFromVec( a, axisA, axisB, point1 );
-		pcu_check_true( a[0] == 0 && a[1] == -0 && a[2] == 1 && a[3] == 2 );
-		pcu_check_true( Plane_DistanceToPoint( a, point2 ) == 4 );
-	}
-}
-
-void PlaneSuite_TestPointIsInFront( PlaneSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-   if( data->rank == procToWatch ) {
-		Coord axisA = { 1.0, 0.3, 0.0 };
-		Coord axisB = { -0.3, 1.0, 0.0 };
-		Coord point1 = { 0.0, 0.0, 2.0 };
-		Coord point2 = { 20.0, 100.0, 6.0 };
-		Coord point3 = { 20.0, 100.0, -60.0 };
-		Plane a;
-
-		Plane_CalcFromVec( a, axisA, axisB, point1 );
-		pcu_check_true( a[0] == 0 && a[1] == -0 && a[2] == 1 && a[3] == 2 );
-		pcu_check_true( Plane_PointIsInFront( a, point2 ) );
-		pcu_check_true( !Plane_PointIsInFront( a, point3 ) );
-	}
-}
-
-void PlaneSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, PlaneSuiteData );
-   pcu_suite_setFixtures( suite, PlaneSuite_Setup, PlaneSuite_Teardown );
-   pcu_suite_addTest( suite, PlaneSuite_TestDistanceToPoint );
-   pcu_suite_addTest( suite, PlaneSuite_TestPointIsInFront );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/PlaneSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/PlaneSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,104 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the PlaneSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "PlaneSuite.h"
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} PlaneSuiteData;
+
+void PlaneSuite_Setup( PlaneSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void PlaneSuite_Teardown( PlaneSuiteData* data ) {
+}
+
+void PlaneSuite_TestDistanceToPoint( PlaneSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+   if( data->rank == procToWatch ) {
+		Coord axisA = { 1.0, 0.3, 0.0 };
+		Coord axisB = { -0.3, 1.0, 0.0 };
+		Coord point1 = { 0.0, 0.0, 2.0 };
+		Coord point2 = { 20.0, 100.0, 6.0 };
+		Plane a;
+
+		Plane_CalcFromVec( a, axisA, axisB, point1 );
+		pcu_check_true( a[0] == 0 && a[1] == -0 && a[2] == 1 && a[3] == 2 );
+		pcu_check_true( Plane_DistanceToPoint( a, point2 ) == 4 );
+	}
+}
+
+void PlaneSuite_TestPointIsInFront( PlaneSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+   if( data->rank == procToWatch ) {
+		Coord axisA = { 1.0, 0.3, 0.0 };
+		Coord axisB = { -0.3, 1.0, 0.0 };
+		Coord point1 = { 0.0, 0.0, 2.0 };
+		Coord point2 = { 20.0, 100.0, 6.0 };
+		Coord point3 = { 20.0, 100.0, -60.0 };
+		Plane a;
+
+		Plane_CalcFromVec( a, axisA, axisB, point1 );
+		pcu_check_true( a[0] == 0 && a[1] == -0 && a[2] == 1 && a[3] == 2 );
+		pcu_check_true( Plane_PointIsInFront( a, point2 ) );
+		pcu_check_true( !Plane_PointIsInFront( a, point3 ) );
+	}
+}
+
+void PlaneSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, PlaneSuiteData );
+   pcu_suite_setFixtures( suite, PlaneSuite_Setup, PlaneSuite_Teardown );
+   pcu_suite_addTest( suite, PlaneSuite_TestDistanceToPoint );
+   pcu_suite_addTest( suite, PlaneSuite_TestPointIsInFront );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/TensorMathSuite.c
--- a/Geometry/tests/TensorMathSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,959 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the TensorMathSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "TensorMathSuite.h"
-
-typedef struct {
-	MPI_Comm comm;
-	int rank;
-	int nProcs;
-} TensorMathSuiteData;
-
-void TensorMathSuite_testCubic( double a3, double a2, double a1, double a0, Stream* stream ) { 
-	double rootList[3];
-	Index  root_I;
-
-	Journal_Printf( stream, "\nTrying to solve %.4f x^3 + %.4f x^2 + %.4f x + %.4f = 0\n", a3, a2, a1, a0 );
-
-	CubicSolver_OnlyRealRoots( a2/a3, a1/a3, a0/a3, rootList );
-
-	for ( root_I = 0 ; root_I < 3 ; root_I++ ) { 
-		double root =  rootList[ root_I ];
-		Journal_Printf( stream, "Found root %.4f: ", root );
-
-		if (  fabs( a3*root*root*root + a2*root*root + a1 * root + a0 ) > 1.0e-5 )
-			Journal_Printf( stream, "Failed root test - %.4f x^3 + %.4f x^2 + %.4f x + %.4f = %.4f\n", a3, a2, a1, a0, a3*root*root*root + a2*root*root + a1 * root + a0 );
-		else 
-			Journal_Printf( stream, "Passed.\n" );
-   }   
-}
-
-void TensorMathSuite_Setup( TensorMathSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void TensorMathSuite_Teardown( TensorMathSuiteData* data ) {
-}
-
-void TensorMathSuite_TestSymmetricTensorVectorComponents( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		int		dim;
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorVectorComponents"  );
-		char		expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathSymmetricTensorVectorComponents.dat" );
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Check StGermain_nSymmetricTensorVectorComponents function\n");
-		dim = 2;
-		Journal_Printf( stream, "Number of unique components of symmetric tensor of dimension %d is %d\n", dim, StGermain_nSymmetricTensorVectorComponents( dim ) );
-		dim = 3;
-		Journal_Printf( stream, "Number of unique components of symmetric tensor of dimension %d is %d\n", dim, StGermain_nSymmetricTensorVectorComponents( dim ) );
-
-		pcu_filename_expected( "testTensorMathSymmetricTensorVectorComponents.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathSymmetricTensorVectorComponents.dat", expected_file );
-		remove( "testTensorMathSymmetricTensorVectorComponents.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestJournalPrintTensorArray( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double		**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		TensorArray	tensorArray;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"JournalPrintTensorArray"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathJournalPrintTensorArray.dat" );
-
-		tensor[0][0] = 3;		tensor[0][1] = 21;	tensor[0][2] = -1;	tensor[0][3] = -99;	tensor[0][4] = 9;
-		tensor[1][0] = 6;		tensor[1][1] = 5.8;	tensor[1][2] = 32;	tensor[1][3] = 3  ;	tensor[1][4] = -2.5;
-		tensor[2][0] = 2;		tensor[2][1] = 2;		tensor[2][2] = -7;	tensor[2][3] = 2  ;	tensor[2][4] = 3.1;
-		tensor[3][0] = -4;	tensor[3][1] = 9;		tensor[3][2] = 3 ;	tensor[3][3] = 8  ;	tensor[3][4] = 6;
-		tensor[4][0] = 3;		tensor[4][1] = 1;		tensor[4][2] = 9 ;	tensor[4][3] = 2  ;	tensor[4][4] = 12; 
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing Journal_PrintTensorArray\n");
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, 3 );
-		Journal_PrintTensorArray( stream, tensorArray, 3 );
-
-		pcu_filename_expected( "testTensorMathJournalPrintTensorArray.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathJournalPrintTensorArray.dat", expected_file );
-		remove( "testTensorMathJournalPrintTensorArray.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestTensorToTensorArrayFunction( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorToTensorArrayFunction"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathArrayFunction.dat" );
-
-		Journal_Printf( stream, "/*******************************************/\n");
-		Journal_Printf( stream, "Test Symmetric Tensor to Tensor Array function\n\n");
-
-		Journal_Printf( stream, "2-D\n");
-		Journal_Printf( stream, "Symmetric Tensor\n");
-		symmTensor[ST2D_00] = 1; symmTensor[ST2D_11] = 8;
-		symmTensor[ST2D_01] = 7;
-		Journal_PrintSymmetricTensor_Unnamed(stream, symmTensor, 2); 
-    
-		StGermain_SymmetricTensor_ToTensorArray2D(symmTensor, tensorArray);
-		Journal_Printf( stream, "Tensor Array - 2D\n");
-		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 2); 
-    
-		Journal_Printf( stream, "Tensor Array \n");
-		StGermain_SymmetricTensor_ToTensorArray(symmTensor, 2, tensorArray);
-		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 2); 
-    
-		Journal_Printf( stream, "3-D\n");
-		Journal_Printf( stream, "Symmetric Tensor\n");
-		symmTensor[ST3D_00] = 1; symmTensor[ST3D_11] = 8; symmTensor[ST3D_22] = 5;
-		symmTensor[ST3D_01] = 7; symmTensor[ST3D_02] = 0; symmTensor[ST3D_12] = 3;
-    
-		Journal_PrintSymmetricTensor_Unnamed(stream, symmTensor, 3); 
-    
-		StGermain_SymmetricTensor_ToTensorArray3D(symmTensor, tensorArray);
-		Journal_Printf( stream, "Tensor Array - 3D\n");
-		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 3);
-
-		Journal_Printf( stream, "Tensor Array \n");
-		StGermain_SymmetricTensor_ToTensorArray(symmTensor, 3, tensorArray);
-		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 3);
-
-		pcu_filename_expected( "testTensorMathArrayFunction.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathArrayFunction.dat", expected_file );
-		remove( "testTensorMathArrayFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestMathArrayToMatrix( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayToMatrix"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathArrayToMatrix.dat" );
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing TensorArray_ToMatrix\n");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1;  tensorArray[FT2D_01] = 3;
-		tensorArray[FT2D_10] = 2;  tensorArray[FT2D_11] = 6.8;
-
-		Journal_PrintTensorArray( stream, tensorArray,2);
-		TensorArray_ToMatrix(tensorArray, 2, tensor );
-		Journal_PrintSquareArray( stream, tensor, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 30;  tensorArray[FT3D_01] = 27;  tensorArray[FT3D_02] = -24;
-		tensorArray[FT3D_10] = 29;  tensorArray[FT3D_11] = 26.8; tensorArray[FT3D_12] = 23;
-		tensorArray[FT3D_20] = 28;  tensorArray[FT3D_21] = 25;   tensorArray[FT3D_22] = -0.22;
-
-		Journal_PrintTensorArray( stream, tensorArray,3);
-		TensorArray_ToMatrix(tensorArray, 3, tensor );
-		Journal_PrintSquareArray( stream, tensor, 3);
-
-		pcu_filename_expected( "testTensorMathArrayToMatrix.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathArrayToMatrix.dat", expected_file );
-		remove( "testTensorMathArrayToMatrix.dat" );
-
-      Memory_Free( tensor );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestSymmetricTensorToMatrix( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		SymmetricTensor	symmTensor;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorToMatrix"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathSymmetricTensorToMatrix.dat" );
-
-		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
-		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
-		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
-		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
-		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing SymmetricTensor_ToMatrix\n");
-
-		Journal_Printf( stream, "2-D\n");
-		symmTensor[ST2D_00] = 7;  symmTensor[ST2D_01] = 11;
-		symmTensor[ST2D_11] = 9.8;
-
-		Journal_PrintSymmetricTensor( stream, symmTensor,2);
-		SymmetricTensor_ToMatrix(symmTensor, 2, tensor );
-		Journal_PrintSquareArray( stream, tensor, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		symmTensor[ST3D_00] = 0;   symmTensor[ST3D_01] = 12;  symmTensor[ST3D_02] = -100;
-		symmTensor[ST3D_11] = 0.8; symmTensor[ST3D_12] = 20.3;
-		symmTensor[ST3D_22] = -7.5;
-
-		Journal_PrintSymmetricTensor( stream, symmTensor,3);
-		SymmetricTensor_ToMatrix(symmTensor, 3, tensor );
-		Journal_PrintSquareArray( stream, tensor, 3);
-		
-		pcu_filename_expected( "testTensorMathSymmetricTensorToMatrix.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathSymmetricTensorToMatrix.dat", expected_file );
-		remove( "testTensorMathSymmetricTensorToMatrix.dat" );
-
-      Memory_Free( tensor );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestGetAntisymmetricPart( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		TensorArray			tensorArray;
-		TensorArray			tensor2;
-		int					dim;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"GetAntisymmetricPart"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathGetAntisymmetricPart.dat" );
-
-		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
-		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
-		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
-		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
-		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing GetAntisymmetricPart\n");
-		dim = 2;
-		Journal_Printf( stream, "dim = %d\n", dim);
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		TensorArray_GetAntisymmetricPart( tensorArray, dim, tensor2 );
-		Journal_PrintTensorArray( stream, tensor2, dim );
-
-		dim = 3;
-		Journal_Printf( stream, "dim = %d\n", dim);
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		TensorArray_GetAntisymmetricPart( tensorArray, dim, tensor2 );
-		Journal_PrintTensorArray( stream, tensor2, dim );
-			
-		pcu_filename_expected( "testTensorMathGetAntisymmetricPart.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathGetAntisymmetricPart.dat", expected_file );
-		remove( "testTensorMathGetAntisymmetricPart.dat" );
-
-      Memory_Free( tensor );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestGetSymmetricPart( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		SymmetricTensor	symmTensor;
-		TensorArray			tensorArray;
-		int					dim;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"GetSymmetricPart"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathGetSymmetricPart.dat" );
-
-		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
-		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
-		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
-		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
-		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing GetSymmetricPart\n");
-		dim = 2;
-		Journal_Printf( stream, "dim = %d\n", dim);
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
-		Journal_PrintSymmetricTensor( stream, symmTensor, dim );
-
-		dim = 3;
-		Journal_Printf( stream, "dim = %d\n", dim);
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
-		Journal_PrintSymmetricTensor( stream, symmTensor, dim );
-			
-		pcu_filename_expected( "testTensorMathGetSymmetricPart.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathGetSymmetricPart.dat", expected_file );
-		remove( "testTensorMathGetSymmetricPart.dat" );
-
-      Memory_Free( tensor );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_Test2ndInvariant( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		SymmetricTensor	symmTensor;
-		TensorArray			tensorArray;
-		int					dim;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"2ndInvariant"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMath2ndInvariant.dat" );
-
-		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
-		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
-		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
-		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
-		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing 2ndInvariant\n");
-		dim = 2;
-		Journal_Printf( stream, "dim = %d\n", dim);
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		Journal_Printf( stream, "inv = %0.5g\n", TensorArray_2ndInvariant( tensorArray, dim ));
-		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
-		Journal_Printf( stream, "inv = %0.5g\n", SymmetricTensor_2ndInvariant( symmTensor, dim ));
-
-		dim = 3;
-		Journal_Printf( stream, "dim = %d\n", dim);
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		Journal_Printf( stream, "inv = %0.5g\n", TensorArray_2ndInvariant( tensorArray, dim ));
-		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
-		Journal_Printf( stream, "inv = %0.5g\n", SymmetricTensor_2ndInvariant( symmTensor, dim ));
-			
-		pcu_filename_expected( "testTensorMath2ndInvariant.expected", expected_file );
-		pcu_check_fileEq( "testTensorMath2ndInvariant.dat", expected_file );
-		remove( "testTensorMath2ndInvariant.dat" );
-
-      Memory_Free( tensor );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestVectorTensorVector( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		TensorArray			tensorArray;
-		int					dim;
-		double				a[] = {2,3,6,-2,9.1};
-		double				b[] = {1,-3,2.6,-2.2,-1.91};
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"VectorTensorVector"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathVectorTensorVector.dat" );
-
-		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
-		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
-		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
-		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
-		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing StGermain_VectorTensorVector\n");
-		dim = 2;
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		Journal_Printf( stream, "dim = %d - a_i u_ij b_j = %2.4lf\n", dim, TensorArray_MultiplyByVectors( tensorArray, a, b,dim));
-		dim = 3;
-		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
-		Journal_Printf( stream, "dim = %d - a_i u_ij b_j = %2.4lf\n", dim, TensorArray_MultiplyByVectors( tensorArray, a, b,dim));
-			
-		pcu_filename_expected( "testTensorMathVectorTensorVector.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathVectorTensorVector.dat", expected_file );
-		remove( "testTensorMathVectorTensorVector.dat" );
-
-      Memory_Free( tensor );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestZeroTensor( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		TensorArray			tensor2;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"ZeroTensor"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathZeroTensor.dat" );
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing ZeroTensor\n");
-		TensorArray_Zero( tensor2 );
-		Journal_PrintTensorArray( stream, tensor2, 2 );
-		Journal_PrintTensorArray( stream, tensor2, 3 );
-		SymmetricTensor_Zero( symmTensor );
-		Journal_PrintSymmetricTensor( stream, symmTensor, 2 );
-		Journal_PrintSymmetricTensor( stream, symmTensor, 3 );
-		
-		pcu_filename_expected( "testTensorMathZeroTensor.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathZeroTensor.dat", expected_file );
-		remove( "testTensorMathZeroTensor.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestMatrixDeterminant( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double	**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
-		double	determinant;
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"MatrixDeterminant"  );
-		char		expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathMatrixDeterminant.dat" );
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing StGermain_MatrixDeterminant\n");
-		tensor[0][0] = 1.0; tensor[0][1] = 2.0; tensor[0][2] = 3.0;
-		tensor[1][0] = 4.0; tensor[1][1] = 5.0; tensor[1][2] = 6.0;
-		tensor[2][0] = 7.0; tensor[2][1] = 8.0; tensor[2][2] = 11.0;
-
-		determinant = StGermain_MatrixDeterminant( tensor, 1 );
-		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
-		Journal_PrintSquareArray( stream, tensor, 1 );
-
-		determinant = StGermain_MatrixDeterminant( tensor, 2 );
-		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
-		Journal_PrintSquareArray( stream, tensor, 2 );
-
-		determinant = StGermain_MatrixDeterminant( tensor, 3 );
-		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
-		Journal_PrintSquareArray( stream, tensor, 3 );
-
-		determinant = StGermain_MatrixDeterminant( tensor, 3 );
-		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
-		Journal_PrintSquareArray( stream, tensor, 3 );
-
-		determinant = StGermain_MatrixDeterminant_AxisIndependent( tensor, 2, I_AXIS, K_AXIS, J_AXIS );
-		Journal_Printf( stream, "%2.4g is determinant of matrix :\n" , determinant );
-		Journal_Printf( stream, "%2.4g \t %2.4g\n", tensor[I_AXIS][I_AXIS], tensor[I_AXIS][K_AXIS] );
-		Journal_Printf( stream, "%2.4g \t %2.4g\n", tensor[K_AXIS][I_AXIS], tensor[K_AXIS][K_AXIS] );
-		
-		pcu_filename_expected( "testTensorMathMatrixDeterminant.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathMatrixDeterminant.dat", expected_file );
-		remove( "testTensorMathMatrixDeterminant.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestCubicSolver( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"CubicSolver"  );
-		char		expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathCubicSolver.dat" );
-
-		Journal_Printf( stream, "****************************************\n");
-		Journal_Printf( stream, "Testing Cubic Solver\n");
-		TensorMathSuite_testCubic( 2.0, 0.0, -2.0,0.0, stream );
-		TensorMathSuite_testCubic( 1.0, -4.0, 5.0, -2.0, stream );
-		TensorMathSuite_testCubic( 1.0, 4.0, -11.0, -30.0, stream );
-		
-		pcu_filename_expected( "testTensorMathCubicSolver.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathCubicSolver.dat", expected_file );
-		remove( "testTensorMathCubicSolver.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestMappingFunctions( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"MappingFunctions"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathMappingFunctions.dat" );
-
-		Journal_Printf(stream, "****************************************\n");
-		Journal_Printf( stream, "Test Mapping functions\n\n");
-		Journal_Printf( stream, "2-D\n");
-
-		tensorArray[0] = 0.5; tensorArray[1] = 10; tensorArray[2] = 20; tensorArray[3] = 30;
-		symmTensor[0] = 40; symmTensor[1] = 50; symmTensor[2] = 60;
-
-		Journal_Printf( stream, "The full tensor:\n");
-		Journal_PrintTensorArray( stream, tensorArray, 2 );
-
-		Journal_Printf( stream, "The tensor Mapping using enumerated types:\n");
-		Journal_PrintValue( stream, tensorArray[FT2D_00]);
-		Journal_PrintValue( stream, tensorArray[FT2D_01]);
-		Journal_Printf( stream, " ---\n");
-		Journal_PrintValue( stream, tensorArray[FT2D_10]);
-		Journal_PrintValue( stream, tensorArray[FT2D_11]);
-
-		Journal_Printf( stream, "The symmetric tensor:\n");
-		Journal_PrintSymmetricTensor( stream, symmTensor, 2 );
-
-		Journal_Printf( stream, "The symmetric tensor Mapping using enumerated types:\n");
-		Journal_PrintValue( stream, symmTensor[ST2D_00]);
-		Journal_PrintValue( stream, symmTensor[ST2D_01]);
-		Journal_Printf( stream, " ---\n");
-		Journal_PrintValue( stream, symmTensor[ST2D_11]);
-
-		Journal_Printf( stream, "Test Mapping functions for Full Tensor ");
-		Journal_Printf( stream, "using TensorArray_TensorMap\n\n");
-		Journal_Printf( stream, "(0,0): %d  = %d  ", FT2D_00, TensorArray_TensorMap(0,0,2));
-		Journal_Printf( stream, "(0,1): %d  = %d\n", FT2D_01, TensorArray_TensorMap(0,1,2));
-		Journal_Printf( stream, "(1,0): %d  = %d  ", FT2D_10, TensorArray_TensorMap(1,0,2));
-		Journal_Printf( stream, "(1,1): %d  = %d\n", FT2D_11, TensorArray_TensorMap(1,1,2));
-
-      Journal_Printf( stream, "Test Mapping functions for Symmetric Tensor ");
-      Journal_Printf( stream, "using SymmetricTensor_TensorMap\n\n");
-      Journal_Printf( stream, "(0,0): %d  = %d  ", ST2D_00, SymmetricTensor_TensorMap(0,0,2));
-      Journal_Printf( stream, "(0,1): %d  = %d\n", ST2D_01, SymmetricTensor_TensorMap(0,1,2));
-      Journal_Printf( stream, "(1,0): %d  = %d  ", ST2D_01, SymmetricTensor_TensorMap(1,0,2));
-      Journal_Printf( stream, "(1,1): %d  = %d\n", ST2D_11, SymmetricTensor_TensorMap(1,1,2));
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[0] = 0; tensorArray[1] = 1; tensorArray[2] = 2;
-		tensorArray[3] = 3; tensorArray[4] = 4; tensorArray[5] = 5;
-		tensorArray[6] = 6; tensorArray[7] = 7; tensorArray[8] = 8;
-
-		symmTensor[0] = 90; symmTensor[1] = 100; symmTensor[2] = 110;
-		symmTensor[3] = 120; symmTensor[4] = 130; symmTensor[5] = 140;
-
-		Journal_Printf( stream, "The full tensor:\n");
-		Journal_PrintTensorArray( stream, tensorArray, 3 );
-
-		Journal_Printf( stream, "The tensor Mapping using enumerated types:\n");
-		Journal_PrintValue( stream, tensorArray[FT3D_00]);
-		Journal_PrintValue( stream, tensorArray[FT3D_01]);
-		Journal_PrintValue( stream, tensorArray[FT3D_02]);
-		Journal_Printf( stream, " ---\n");
-		Journal_PrintValue( stream, tensorArray[FT3D_10]);
-		Journal_PrintValue( stream, tensorArray[FT3D_11]);
-		Journal_PrintValue( stream, tensorArray[FT3D_12]);
-		Journal_Printf( stream, " ---\n");
-		Journal_PrintValue( stream, tensorArray[FT3D_20]);
-		Journal_PrintValue( stream, tensorArray[FT3D_21]);
-		Journal_PrintValue( stream, tensorArray[FT3D_22]);
-
-		Journal_Printf( stream, "The symmetric tensor:\n");
-		Journal_PrintSymmetricTensor( stream, symmTensor, 3 );
-
-		Journal_Printf( stream, "The symmetric tensor Mapping using enumerated types:\n");
-		Journal_PrintValue( stream, symmTensor[ST3D_00]);
-		Journal_PrintValue( stream, symmTensor[ST3D_01]);
-		Journal_PrintValue( stream, symmTensor[ST3D_02]);
-		Journal_Printf( stream, " ---\n");
-		Journal_PrintValue( stream, symmTensor[ST3D_11]);
-		Journal_PrintValue( stream, symmTensor[ST3D_12]);
-		Journal_Printf( stream, " ---\n");
-		Journal_PrintValue( stream, symmTensor[ST3D_22]);
-
-		Journal_Printf( stream, "Test Mapping functions for Full Tensor ");
-		Journal_Printf( stream, "using TensorArray_TensorMap\n\n");
-		Journal_Printf( stream, "(0,0): %d  = %d  ", FT3D_00, TensorArray_TensorMap(0,0,3));
-		Journal_Printf( stream, "(0,1): %d  = %d  ", FT3D_01, TensorArray_TensorMap(0,1,3));
-		Journal_Printf( stream, "(0,2): %d  = %d\n", FT3D_02, TensorArray_TensorMap(0,2,3));
-
-		Journal_Printf( stream, "(1,0): %d  = %d  ", FT3D_10, TensorArray_TensorMap(1,0,3));
-		Journal_Printf( stream, "(1,1): %d  = %d  ", FT3D_11, TensorArray_TensorMap(1,1,3));
-		Journal_Printf( stream, "(1,2): %d  = %d\n", FT3D_12, TensorArray_TensorMap(1,2,3));
-
-		Journal_Printf( stream, "(2,0): %d  = %d  ", FT3D_20, TensorArray_TensorMap(2,0,3));
-		Journal_Printf( stream, "(2,1): %d  = %d  ", FT3D_21, TensorArray_TensorMap(2,1,3));
-		Journal_Printf( stream, "(2,2): %d  = %d\n", FT3D_22, TensorArray_TensorMap(2,2,3));
-
-		Journal_Printf( stream, "Test Mapping functions for Symmetric Tensor ");
-		Journal_Printf( stream, "using SymmetricTensor_TensorMap\n\n");
-		Journal_Printf( stream, "(0,0): %d  = %d  ", ST3D_00, SymmetricTensor_TensorMap(0,0,3));
-		Journal_Printf( stream, "(0,1): %d  = %d  ", ST3D_01, SymmetricTensor_TensorMap(0,1,3));
-		Journal_Printf( stream, "(0,2): %d  = %d\n", ST3D_02, SymmetricTensor_TensorMap(0,2,3));
-
-		Journal_Printf( stream, "(1,0): %d  = %d  ", ST3D_01, SymmetricTensor_TensorMap(1,0,3));
-		Journal_Printf( stream, "(1,1): %d  = %d  ", ST3D_11, SymmetricTensor_TensorMap(1,1,3));
-		Journal_Printf( stream, "(1,2): %d  = %d\n", ST3D_12, SymmetricTensor_TensorMap(1,2,3));
-
-		Journal_Printf( stream, "(2,0): %d  = %d  ", ST3D_02, SymmetricTensor_TensorMap(2,0,3));
-		Journal_Printf( stream, "(2,1): %d  = %d  ", ST3D_12, SymmetricTensor_TensorMap(2,1,3));
-		Journal_Printf( stream, "(2,2): %d  = %d\n", ST3D_22, SymmetricTensor_TensorMap(2,2,3));
-
-		pcu_filename_expected( "testTensorMathMappingFunctions.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathMappingFunctions.dat", expected_file );
-		remove( "testTensorMathMappingFunctions.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestEigenVectorListSort( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		Eigenvector	eigenvectorList[3];
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"EigenVectorListSort"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathEigenVectorListSort.dat" );
-
-		Journal_Printf( stream, "*************************************\n" );
-		Journal_Printf( stream, "Test function EigenvectorList_Sort\n" );
-		/*  Matrix that gives eigenvalues and vectors  */
-		/* | 1.000 1.000 2.000 | */
-		/* | 1.000 2.000 1.000 | */
-		/* | 2.000 1.000 1.000 | */
-		Journal_Printf( stream, " 3-D\n");
-		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
-		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
-		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
-		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
-
-		Journal_Printf( stream, "Unsorted eigenvectorList\n");
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
-
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
-
-		EigenvectorList_Sort( eigenvectorList, 3);
-
-		Journal_Printf( stream, "Sorted eigenvectorList\n");
-
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
-
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
-
-		Journal_Printf( stream, "2-D\n");
-
-		/*  Matrix that gives eigenvalues and vectors  */
-		/* | 5.000 1.000 | */
-		/* | 1.000 5.000 | */
-
-		eigenvectorList[0].eigenvalue = 6; eigenvectorList[1].eigenvalue = 4;
-		eigenvectorList[0].vector[0] = 0.707; eigenvectorList[0].vector[1] = 0.707;
-		eigenvectorList[1].vector[0] = 0.707; eigenvectorList[1].vector[1] = -0.707;
-
-		Journal_Printf( stream, "Unsorted eigenvectorList\n");
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
-
-		EigenvectorList_Sort( eigenvectorList, 2);
-
-		Journal_Printf( stream, "Sorted eigenvectorList\n");
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
-			
-		pcu_filename_expected( "testTensorMathEigenVectorListSort.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathEigenVectorListSort.dat", expected_file );
-		remove( "testTensorMathEigenVectorListSort.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestEigenVector1( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		Eigenvector			eigenvectorList[3];
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector1"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathEigenVector1.dat" );
-
-		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
-		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
-		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
-		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
-
-		Journal_Printf(stream, "****************    Test Eigenvector 1   *********************\n");
-		Journal_Printf( stream, "2D Case from Kresig, p. 371f\n\n");
-		symmTensor[0] = -5;
-		symmTensor[1] = -2;
-		symmTensor[2] = 2;
-
-		Journal_Printf( stream, "Matrix to solve for eigenvectors is:\n");
-		Journal_PrintSymmetricTensor( stream, symmTensor, 2 );
-
-		SymmetricTensor_CalcAllEigenvectors( symmTensor, 2, eigenvectorList );
-
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
-
-		pcu_filename_expected( "testTensorMathEigenVector1.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathEigenVector1.dat", expected_file );
-		remove( "testTensorMathEigenVector1.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestEigenVector2( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		Eigenvector			eigenvectorList[3];
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector2"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathEigenVector2.dat" );
-
-		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
-		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
-		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
-		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
-
-		Journal_Printf( stream, "****************    Test Eigenvector 2   **********************\n");
-		Journal_Printf( stream, "Same test as above - but using Numerical Recipies function\n\n");
-		symmTensor[0] = -5;
-		symmTensor[1] = -2;
-		symmTensor[2] = 2;
-
-		SymmetricTensor_CalcAllEigenvectorsJacobi( symmTensor, 2, eigenvectorList );
-
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
-
-		pcu_filename_expected( "testTensorMathEigenVector2.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathEigenVector2.dat", expected_file );
-		remove( "testTensorMathEigenVector2.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestEigenVector3( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		Eigenvector			eigenvectorList[3];
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector3"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathEigenVector3.dat" );
-
-		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
-		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
-		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
-		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
-
-		Journal_Printf( stream, "****************    Test Eigenvector 3   *********************\n");
-		Journal_Printf( stream, "3D Case -tested on 3/11/04, against: \n");
-		Journal_Printf( stream, "http://www.arndt-bruenner.de/mathe/scripts/engl_eigenwert.htm\n");
-		symmTensor[0] = 2; symmTensor[1] = 3; symmTensor[2] = 5;
-		symmTensor[3] = 7; symmTensor[4] = 11; symmTensor[5] = 13;
-
-		Journal_Printf( stream, "Matrix to solve for eigenvectors is:\n");
-		Journal_PrintSymmetricTensor( stream, symmTensor, 3 );
-
-		SymmetricTensor_CalcAllEigenvectors( symmTensor, 3, eigenvectorList );
-
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
-
-		pcu_filename_expected( "testTensorMathEigenVector3.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathEigenVector3.dat", expected_file );
-		remove( "testTensorMathEigenVector3.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite_TestEigenVector4( TensorMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		TensorArray			tensorArray;
-		Eigenvector			eigenvectorList[3];
-		XYZ					rightHandSide;
-		XYZ					solution;
-		int					dim;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector4"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorMathEigenVector4.dat" );
-
-		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
-		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
-		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
-		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
-
-		Journal_Printf( stream, "****************    Test Eigenvector 4   *********************\n");
-		Journal_Printf( stream, "Same test as above - but using Numerical Recipies function\n\n");
-		symmTensor[0] = 2; symmTensor[1] = 3; symmTensor[2] = 5;
-		symmTensor[3] = 7; symmTensor[4] = 11; symmTensor[5] = 13;
-
-		SymmetricTensor_CalcAllEigenvectorsJacobi( symmTensor, 3, eigenvectorList );
-
-		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
-		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
-		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
-		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
-
-		Journal_Printf( stream, "\n");
-
-		/* Test Matrix Solve */
-		dim = 2;
-		tensorArray[ FT2D_00 ] = 10;
-		tensorArray[ FT2D_01 ] = 11;
-		tensorArray[ FT2D_10 ] = 12;
-		tensorArray[ FT2D_11 ] = 13;
-		Journal_PrintTensorArray( stream, tensorArray, dim );
-
-		rightHandSide[0] = 24;
-		rightHandSide[1] = 35;
-		Journal_PrintArray( stream, rightHandSide, (unsigned)dim );
-
-		TensorArray_SolveSystem( tensorArray, solution, rightHandSide, dim );
-		Journal_PrintArray( stream, solution, (unsigned)dim );
-
-		dim = 3;
-		tensorArray[ FT3D_00 ] = 10;
-		tensorArray[ FT3D_01 ] = 11;
-		tensorArray[ FT3D_02 ] = 12;
-		tensorArray[ FT3D_10 ] = 13;
-		tensorArray[ FT3D_11 ] = 14;
-		tensorArray[ FT3D_12 ] = 15;
-		tensorArray[ FT3D_20 ] = 16;
-		tensorArray[ FT3D_21 ] = 17;
-		tensorArray[ FT3D_22 ] = 19;
-		Journal_PrintTensorArray( stream, tensorArray, dim );
-
-		rightHandSide[0] = 24;
-		rightHandSide[1] = 35;
-		rightHandSide[2] = 45;
-		Journal_PrintArray( stream, rightHandSide, (unsigned)dim );
-
-		TensorArray_SolveSystem( tensorArray, solution, rightHandSide, dim );
-		Journal_PrintArray( stream, solution, (unsigned)dim );
-
-		pcu_filename_expected( "testTensorMathEigenVector4.expected", expected_file );
-		pcu_check_fileEq( "testTensorMathEigenVector4.dat", expected_file );
-		remove( "testTensorMathEigenVector4.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMathSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, TensorMathSuiteData );
-   pcu_suite_setFixtures( suite, TensorMathSuite_Setup, TensorMathSuite_Teardown );
-   pcu_suite_addTest( suite, TensorMathSuite_TestSymmetricTensorVectorComponents );
-   pcu_suite_addTest( suite, TensorMathSuite_TestJournalPrintTensorArray );
-   pcu_suite_addTest( suite, TensorMathSuite_TestTensorToTensorArrayFunction );
-   pcu_suite_addTest( suite, TensorMathSuite_TestMathArrayToMatrix );
-   pcu_suite_addTest( suite, TensorMathSuite_TestSymmetricTensorToMatrix );
-   pcu_suite_addTest( suite, TensorMathSuite_TestGetAntisymmetricPart );
-   pcu_suite_addTest( suite, TensorMathSuite_TestGetSymmetricPart );
-   pcu_suite_addTest( suite, TensorMathSuite_Test2ndInvariant );
-   pcu_suite_addTest( suite, TensorMathSuite_TestVectorTensorVector );
-   pcu_suite_addTest( suite, TensorMathSuite_TestZeroTensor );
-   pcu_suite_addTest( suite, TensorMathSuite_TestMatrixDeterminant );
-   pcu_suite_addTest( suite, TensorMathSuite_TestCubicSolver );
-   pcu_suite_addTest( suite, TensorMathSuite_TestMappingFunctions );
-   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVectorListSort );
-   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector1 );
-   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector2 );
-   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector3 );
-   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector4 );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/TensorMathSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/TensorMathSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,959 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the TensorMathSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "TensorMathSuite.h"
+
+typedef struct {
+	MPI_Comm comm;
+	int rank;
+	int nProcs;
+} TensorMathSuiteData;
+
+void TensorMathSuite_testCubic( double a3, double a2, double a1, double a0, Stream* stream ) { 
+	double rootList[3];
+	Index  root_I;
+
+	Journal_Printf( stream, "\nTrying to solve %.4f x^3 + %.4f x^2 + %.4f x + %.4f = 0\n", a3, a2, a1, a0 );
+
+	CubicSolver_OnlyRealRoots( a2/a3, a1/a3, a0/a3, rootList );
+
+	for ( root_I = 0 ; root_I < 3 ; root_I++ ) { 
+		double root =  rootList[ root_I ];
+		Journal_Printf( stream, "Found root %.4f: ", root );
+
+		if (  fabs( a3*root*root*root + a2*root*root + a1 * root + a0 ) > 1.0e-5 )
+			Journal_Printf( stream, "Failed root test - %.4f x^3 + %.4f x^2 + %.4f x + %.4f = %.4f\n", a3, a2, a1, a0, a3*root*root*root + a2*root*root + a1 * root + a0 );
+		else 
+			Journal_Printf( stream, "Passed.\n" );
+   }   
+}
+
+void TensorMathSuite_Setup( TensorMathSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void TensorMathSuite_Teardown( TensorMathSuiteData* data ) {
+}
+
+void TensorMathSuite_TestSymmetricTensorVectorComponents( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		int		dim;
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorVectorComponents"  );
+		char		expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathSymmetricTensorVectorComponents.dat" );
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Check StGermain_nSymmetricTensorVectorComponents function\n");
+		dim = 2;
+		Journal_Printf( stream, "Number of unique components of symmetric tensor of dimension %d is %d\n", dim, StGermain_nSymmetricTensorVectorComponents( dim ) );
+		dim = 3;
+		Journal_Printf( stream, "Number of unique components of symmetric tensor of dimension %d is %d\n", dim, StGermain_nSymmetricTensorVectorComponents( dim ) );
+
+		pcu_filename_expected( "testTensorMathSymmetricTensorVectorComponents.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathSymmetricTensorVectorComponents.dat", expected_file );
+		remove( "testTensorMathSymmetricTensorVectorComponents.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestJournalPrintTensorArray( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double		**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		TensorArray	tensorArray;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"JournalPrintTensorArray"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathJournalPrintTensorArray.dat" );
+
+		tensor[0][0] = 3;		tensor[0][1] = 21;	tensor[0][2] = -1;	tensor[0][3] = -99;	tensor[0][4] = 9;
+		tensor[1][0] = 6;		tensor[1][1] = 5.8;	tensor[1][2] = 32;	tensor[1][3] = 3  ;	tensor[1][4] = -2.5;
+		tensor[2][0] = 2;		tensor[2][1] = 2;		tensor[2][2] = -7;	tensor[2][3] = 2  ;	tensor[2][4] = 3.1;
+		tensor[3][0] = -4;	tensor[3][1] = 9;		tensor[3][2] = 3 ;	tensor[3][3] = 8  ;	tensor[3][4] = 6;
+		tensor[4][0] = 3;		tensor[4][1] = 1;		tensor[4][2] = 9 ;	tensor[4][3] = 2  ;	tensor[4][4] = 12; 
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing Journal_PrintTensorArray\n");
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, 3 );
+		Journal_PrintTensorArray( stream, tensorArray, 3 );
+
+		pcu_filename_expected( "testTensorMathJournalPrintTensorArray.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathJournalPrintTensorArray.dat", expected_file );
+		remove( "testTensorMathJournalPrintTensorArray.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestTensorToTensorArrayFunction( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorToTensorArrayFunction"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathArrayFunction.dat" );
+
+		Journal_Printf( stream, "/*******************************************/\n");
+		Journal_Printf( stream, "Test Symmetric Tensor to Tensor Array function\n\n");
+
+		Journal_Printf( stream, "2-D\n");
+		Journal_Printf( stream, "Symmetric Tensor\n");
+		symmTensor[ST2D_00] = 1; symmTensor[ST2D_11] = 8;
+		symmTensor[ST2D_01] = 7;
+		Journal_PrintSymmetricTensor_Unnamed(stream, symmTensor, 2); 
+    
+		StGermain_SymmetricTensor_ToTensorArray2D(symmTensor, tensorArray);
+		Journal_Printf( stream, "Tensor Array - 2D\n");
+		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 2); 
+    
+		Journal_Printf( stream, "Tensor Array \n");
+		StGermain_SymmetricTensor_ToTensorArray(symmTensor, 2, tensorArray);
+		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 2); 
+    
+		Journal_Printf( stream, "3-D\n");
+		Journal_Printf( stream, "Symmetric Tensor\n");
+		symmTensor[ST3D_00] = 1; symmTensor[ST3D_11] = 8; symmTensor[ST3D_22] = 5;
+		symmTensor[ST3D_01] = 7; symmTensor[ST3D_02] = 0; symmTensor[ST3D_12] = 3;
+    
+		Journal_PrintSymmetricTensor_Unnamed(stream, symmTensor, 3); 
+    
+		StGermain_SymmetricTensor_ToTensorArray3D(symmTensor, tensorArray);
+		Journal_Printf( stream, "Tensor Array - 3D\n");
+		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 3);
+
+		Journal_Printf( stream, "Tensor Array \n");
+		StGermain_SymmetricTensor_ToTensorArray(symmTensor, 3, tensorArray);
+		Journal_PrintTensorArray_Unnamed(stream, tensorArray, 3);
+
+		pcu_filename_expected( "testTensorMathArrayFunction.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathArrayFunction.dat", expected_file );
+		remove( "testTensorMathArrayFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestMathArrayToMatrix( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayToMatrix"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathArrayToMatrix.dat" );
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing TensorArray_ToMatrix\n");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1;  tensorArray[FT2D_01] = 3;
+		tensorArray[FT2D_10] = 2;  tensorArray[FT2D_11] = 6.8;
+
+		Journal_PrintTensorArray( stream, tensorArray,2);
+		TensorArray_ToMatrix(tensorArray, 2, tensor );
+		Journal_PrintSquareArray( stream, tensor, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 30;  tensorArray[FT3D_01] = 27;  tensorArray[FT3D_02] = -24;
+		tensorArray[FT3D_10] = 29;  tensorArray[FT3D_11] = 26.8; tensorArray[FT3D_12] = 23;
+		tensorArray[FT3D_20] = 28;  tensorArray[FT3D_21] = 25;   tensorArray[FT3D_22] = -0.22;
+
+		Journal_PrintTensorArray( stream, tensorArray,3);
+		TensorArray_ToMatrix(tensorArray, 3, tensor );
+		Journal_PrintSquareArray( stream, tensor, 3);
+
+		pcu_filename_expected( "testTensorMathArrayToMatrix.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathArrayToMatrix.dat", expected_file );
+		remove( "testTensorMathArrayToMatrix.dat" );
+
+      Memory_Free( tensor );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestSymmetricTensorToMatrix( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		SymmetricTensor	symmTensor;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorToMatrix"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathSymmetricTensorToMatrix.dat" );
+
+		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
+		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
+		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
+		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
+		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing SymmetricTensor_ToMatrix\n");
+
+		Journal_Printf( stream, "2-D\n");
+		symmTensor[ST2D_00] = 7;  symmTensor[ST2D_01] = 11;
+		symmTensor[ST2D_11] = 9.8;
+
+		Journal_PrintSymmetricTensor( stream, symmTensor,2);
+		SymmetricTensor_ToMatrix(symmTensor, 2, tensor );
+		Journal_PrintSquareArray( stream, tensor, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		symmTensor[ST3D_00] = 0;   symmTensor[ST3D_01] = 12;  symmTensor[ST3D_02] = -100;
+		symmTensor[ST3D_11] = 0.8; symmTensor[ST3D_12] = 20.3;
+		symmTensor[ST3D_22] = -7.5;
+
+		Journal_PrintSymmetricTensor( stream, symmTensor,3);
+		SymmetricTensor_ToMatrix(symmTensor, 3, tensor );
+		Journal_PrintSquareArray( stream, tensor, 3);
+		
+		pcu_filename_expected( "testTensorMathSymmetricTensorToMatrix.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathSymmetricTensorToMatrix.dat", expected_file );
+		remove( "testTensorMathSymmetricTensorToMatrix.dat" );
+
+      Memory_Free( tensor );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestGetAntisymmetricPart( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		TensorArray			tensorArray;
+		TensorArray			tensor2;
+		int					dim;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"GetAntisymmetricPart"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathGetAntisymmetricPart.dat" );
+
+		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
+		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
+		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
+		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
+		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing GetAntisymmetricPart\n");
+		dim = 2;
+		Journal_Printf( stream, "dim = %d\n", dim);
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		TensorArray_GetAntisymmetricPart( tensorArray, dim, tensor2 );
+		Journal_PrintTensorArray( stream, tensor2, dim );
+
+		dim = 3;
+		Journal_Printf( stream, "dim = %d\n", dim);
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		TensorArray_GetAntisymmetricPart( tensorArray, dim, tensor2 );
+		Journal_PrintTensorArray( stream, tensor2, dim );
+			
+		pcu_filename_expected( "testTensorMathGetAntisymmetricPart.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathGetAntisymmetricPart.dat", expected_file );
+		remove( "testTensorMathGetAntisymmetricPart.dat" );
+
+      Memory_Free( tensor );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestGetSymmetricPart( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		SymmetricTensor	symmTensor;
+		TensorArray			tensorArray;
+		int					dim;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"GetSymmetricPart"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathGetSymmetricPart.dat" );
+
+		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
+		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
+		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
+		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
+		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing GetSymmetricPart\n");
+		dim = 2;
+		Journal_Printf( stream, "dim = %d\n", dim);
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
+		Journal_PrintSymmetricTensor( stream, symmTensor, dim );
+
+		dim = 3;
+		Journal_Printf( stream, "dim = %d\n", dim);
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
+		Journal_PrintSymmetricTensor( stream, symmTensor, dim );
+			
+		pcu_filename_expected( "testTensorMathGetSymmetricPart.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathGetSymmetricPart.dat", expected_file );
+		remove( "testTensorMathGetSymmetricPart.dat" );
+
+      Memory_Free( tensor );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_Test2ndInvariant( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		SymmetricTensor	symmTensor;
+		TensorArray			tensorArray;
+		int					dim;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"2ndInvariant"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMath2ndInvariant.dat" );
+
+		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
+		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
+		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
+		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
+		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing 2ndInvariant\n");
+		dim = 2;
+		Journal_Printf( stream, "dim = %d\n", dim);
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		Journal_Printf( stream, "inv = %0.5g\n", TensorArray_2ndInvariant( tensorArray, dim ));
+		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
+		Journal_Printf( stream, "inv = %0.5g\n", SymmetricTensor_2ndInvariant( symmTensor, dim ));
+
+		dim = 3;
+		Journal_Printf( stream, "dim = %d\n", dim);
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		Journal_Printf( stream, "inv = %0.5g\n", TensorArray_2ndInvariant( tensorArray, dim ));
+		TensorArray_GetSymmetricPart( tensorArray, dim, symmTensor );
+		Journal_Printf( stream, "inv = %0.5g\n", SymmetricTensor_2ndInvariant( symmTensor, dim ));
+			
+		pcu_filename_expected( "testTensorMath2ndInvariant.expected", expected_file );
+		pcu_check_fileEq( "testTensorMath2ndInvariant.dat", expected_file );
+		remove( "testTensorMath2ndInvariant.dat" );
+
+      Memory_Free( tensor );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestVectorTensorVector( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double				**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		TensorArray			tensorArray;
+		int					dim;
+		double				a[] = {2,3,6,-2,9.1};
+		double				b[] = {1,-3,2.6,-2.2,-1.91};
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"VectorTensorVector"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathVectorTensorVector.dat" );
+
+		tensor[0][0] = 3;  tensor[0][1] = 21;   tensor[0][2] = -1; tensor[0][3] = -99; tensor[0][4] = 9;
+		tensor[1][0] = 6;  tensor[1][1] = 5.8;  tensor[1][2] = 32; tensor[1][3] = 3  ; tensor[1][4] = -2.5;
+		tensor[2][0] = 2;  tensor[2][1] = 2;    tensor[2][2] = -7; tensor[2][3] = 2  ; tensor[2][4] = 3.1;
+		tensor[3][0] = -4; tensor[3][1] = 9;    tensor[3][2] = 3 ; tensor[3][3] = 8  ; tensor[3][4] = 6;
+		tensor[4][0] = 3;  tensor[4][1] = 1;    tensor[4][2] = 9 ; tensor[4][3] = 2  ; tensor[4][4] = 12;
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing StGermain_VectorTensorVector\n");
+		dim = 2;
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		Journal_Printf( stream, "dim = %d - a_i u_ij b_j = %2.4lf\n", dim, TensorArray_MultiplyByVectors( tensorArray, a, b,dim));
+		dim = 3;
+		TensorArray_SetFromDoubleArray( tensorArray, tensor, dim );
+		Journal_Printf( stream, "dim = %d - a_i u_ij b_j = %2.4lf\n", dim, TensorArray_MultiplyByVectors( tensorArray, a, b,dim));
+			
+		pcu_filename_expected( "testTensorMathVectorTensorVector.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathVectorTensorVector.dat", expected_file );
+		remove( "testTensorMathVectorTensorVector.dat" );
+
+      Memory_Free( tensor );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestZeroTensor( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		TensorArray			tensor2;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"ZeroTensor"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathZeroTensor.dat" );
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing ZeroTensor\n");
+		TensorArray_Zero( tensor2 );
+		Journal_PrintTensorArray( stream, tensor2, 2 );
+		Journal_PrintTensorArray( stream, tensor2, 3 );
+		SymmetricTensor_Zero( symmTensor );
+		Journal_PrintSymmetricTensor( stream, symmTensor, 2 );
+		Journal_PrintSymmetricTensor( stream, symmTensor, 3 );
+		
+		pcu_filename_expected( "testTensorMathZeroTensor.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathZeroTensor.dat", expected_file );
+		remove( "testTensorMathZeroTensor.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestMatrixDeterminant( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double	**tensor = Memory_Alloc_2DArray( double , 5, 5, (Name)"Tensor"  );
+		double	determinant;
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"MatrixDeterminant"  );
+		char		expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathMatrixDeterminant.dat" );
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing StGermain_MatrixDeterminant\n");
+		tensor[0][0] = 1.0; tensor[0][1] = 2.0; tensor[0][2] = 3.0;
+		tensor[1][0] = 4.0; tensor[1][1] = 5.0; tensor[1][2] = 6.0;
+		tensor[2][0] = 7.0; tensor[2][1] = 8.0; tensor[2][2] = 11.0;
+
+		determinant = StGermain_MatrixDeterminant( tensor, 1 );
+		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
+		Journal_PrintSquareArray( stream, tensor, 1 );
+
+		determinant = StGermain_MatrixDeterminant( tensor, 2 );
+		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
+		Journal_PrintSquareArray( stream, tensor, 2 );
+
+		determinant = StGermain_MatrixDeterminant( tensor, 3 );
+		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
+		Journal_PrintSquareArray( stream, tensor, 3 );
+
+		determinant = StGermain_MatrixDeterminant( tensor, 3 );
+		Journal_Printf( stream, "%2.4g is determinant of matrix : " , determinant );
+		Journal_PrintSquareArray( stream, tensor, 3 );
+
+		determinant = StGermain_MatrixDeterminant_AxisIndependent( tensor, 2, I_AXIS, K_AXIS, J_AXIS );
+		Journal_Printf( stream, "%2.4g is determinant of matrix :\n" , determinant );
+		Journal_Printf( stream, "%2.4g \t %2.4g\n", tensor[I_AXIS][I_AXIS], tensor[I_AXIS][K_AXIS] );
+		Journal_Printf( stream, "%2.4g \t %2.4g\n", tensor[K_AXIS][I_AXIS], tensor[K_AXIS][K_AXIS] );
+		
+		pcu_filename_expected( "testTensorMathMatrixDeterminant.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathMatrixDeterminant.dat", expected_file );
+		remove( "testTensorMathMatrixDeterminant.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestCubicSolver( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"CubicSolver"  );
+		char		expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathCubicSolver.dat" );
+
+		Journal_Printf( stream, "****************************************\n");
+		Journal_Printf( stream, "Testing Cubic Solver\n");
+		TensorMathSuite_testCubic( 2.0, 0.0, -2.0,0.0, stream );
+		TensorMathSuite_testCubic( 1.0, -4.0, 5.0, -2.0, stream );
+		TensorMathSuite_testCubic( 1.0, 4.0, -11.0, -30.0, stream );
+		
+		pcu_filename_expected( "testTensorMathCubicSolver.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathCubicSolver.dat", expected_file );
+		remove( "testTensorMathCubicSolver.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestMappingFunctions( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"MappingFunctions"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathMappingFunctions.dat" );
+
+		Journal_Printf(stream, "****************************************\n");
+		Journal_Printf( stream, "Test Mapping functions\n\n");
+		Journal_Printf( stream, "2-D\n");
+
+		tensorArray[0] = 0.5; tensorArray[1] = 10; tensorArray[2] = 20; tensorArray[3] = 30;
+		symmTensor[0] = 40; symmTensor[1] = 50; symmTensor[2] = 60;
+
+		Journal_Printf( stream, "The full tensor:\n");
+		Journal_PrintTensorArray( stream, tensorArray, 2 );
+
+		Journal_Printf( stream, "The tensor Mapping using enumerated types:\n");
+		Journal_PrintValue( stream, tensorArray[FT2D_00]);
+		Journal_PrintValue( stream, tensorArray[FT2D_01]);
+		Journal_Printf( stream, " ---\n");
+		Journal_PrintValue( stream, tensorArray[FT2D_10]);
+		Journal_PrintValue( stream, tensorArray[FT2D_11]);
+
+		Journal_Printf( stream, "The symmetric tensor:\n");
+		Journal_PrintSymmetricTensor( stream, symmTensor, 2 );
+
+		Journal_Printf( stream, "The symmetric tensor Mapping using enumerated types:\n");
+		Journal_PrintValue( stream, symmTensor[ST2D_00]);
+		Journal_PrintValue( stream, symmTensor[ST2D_01]);
+		Journal_Printf( stream, " ---\n");
+		Journal_PrintValue( stream, symmTensor[ST2D_11]);
+
+		Journal_Printf( stream, "Test Mapping functions for Full Tensor ");
+		Journal_Printf( stream, "using TensorArray_TensorMap\n\n");
+		Journal_Printf( stream, "(0,0): %d  = %d  ", FT2D_00, TensorArray_TensorMap(0,0,2));
+		Journal_Printf( stream, "(0,1): %d  = %d\n", FT2D_01, TensorArray_TensorMap(0,1,2));
+		Journal_Printf( stream, "(1,0): %d  = %d  ", FT2D_10, TensorArray_TensorMap(1,0,2));
+		Journal_Printf( stream, "(1,1): %d  = %d\n", FT2D_11, TensorArray_TensorMap(1,1,2));
+
+      Journal_Printf( stream, "Test Mapping functions for Symmetric Tensor ");
+      Journal_Printf( stream, "using SymmetricTensor_TensorMap\n\n");
+      Journal_Printf( stream, "(0,0): %d  = %d  ", ST2D_00, SymmetricTensor_TensorMap(0,0,2));
+      Journal_Printf( stream, "(0,1): %d  = %d\n", ST2D_01, SymmetricTensor_TensorMap(0,1,2));
+      Journal_Printf( stream, "(1,0): %d  = %d  ", ST2D_01, SymmetricTensor_TensorMap(1,0,2));
+      Journal_Printf( stream, "(1,1): %d  = %d\n", ST2D_11, SymmetricTensor_TensorMap(1,1,2));
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[0] = 0; tensorArray[1] = 1; tensorArray[2] = 2;
+		tensorArray[3] = 3; tensorArray[4] = 4; tensorArray[5] = 5;
+		tensorArray[6] = 6; tensorArray[7] = 7; tensorArray[8] = 8;
+
+		symmTensor[0] = 90; symmTensor[1] = 100; symmTensor[2] = 110;
+		symmTensor[3] = 120; symmTensor[4] = 130; symmTensor[5] = 140;
+
+		Journal_Printf( stream, "The full tensor:\n");
+		Journal_PrintTensorArray( stream, tensorArray, 3 );
+
+		Journal_Printf( stream, "The tensor Mapping using enumerated types:\n");
+		Journal_PrintValue( stream, tensorArray[FT3D_00]);
+		Journal_PrintValue( stream, tensorArray[FT3D_01]);
+		Journal_PrintValue( stream, tensorArray[FT3D_02]);
+		Journal_Printf( stream, " ---\n");
+		Journal_PrintValue( stream, tensorArray[FT3D_10]);
+		Journal_PrintValue( stream, tensorArray[FT3D_11]);
+		Journal_PrintValue( stream, tensorArray[FT3D_12]);
+		Journal_Printf( stream, " ---\n");
+		Journal_PrintValue( stream, tensorArray[FT3D_20]);
+		Journal_PrintValue( stream, tensorArray[FT3D_21]);
+		Journal_PrintValue( stream, tensorArray[FT3D_22]);
+
+		Journal_Printf( stream, "The symmetric tensor:\n");
+		Journal_PrintSymmetricTensor( stream, symmTensor, 3 );
+
+		Journal_Printf( stream, "The symmetric tensor Mapping using enumerated types:\n");
+		Journal_PrintValue( stream, symmTensor[ST3D_00]);
+		Journal_PrintValue( stream, symmTensor[ST3D_01]);
+		Journal_PrintValue( stream, symmTensor[ST3D_02]);
+		Journal_Printf( stream, " ---\n");
+		Journal_PrintValue( stream, symmTensor[ST3D_11]);
+		Journal_PrintValue( stream, symmTensor[ST3D_12]);
+		Journal_Printf( stream, " ---\n");
+		Journal_PrintValue( stream, symmTensor[ST3D_22]);
+
+		Journal_Printf( stream, "Test Mapping functions for Full Tensor ");
+		Journal_Printf( stream, "using TensorArray_TensorMap\n\n");
+		Journal_Printf( stream, "(0,0): %d  = %d  ", FT3D_00, TensorArray_TensorMap(0,0,3));
+		Journal_Printf( stream, "(0,1): %d  = %d  ", FT3D_01, TensorArray_TensorMap(0,1,3));
+		Journal_Printf( stream, "(0,2): %d  = %d\n", FT3D_02, TensorArray_TensorMap(0,2,3));
+
+		Journal_Printf( stream, "(1,0): %d  = %d  ", FT3D_10, TensorArray_TensorMap(1,0,3));
+		Journal_Printf( stream, "(1,1): %d  = %d  ", FT3D_11, TensorArray_TensorMap(1,1,3));
+		Journal_Printf( stream, "(1,2): %d  = %d\n", FT3D_12, TensorArray_TensorMap(1,2,3));
+
+		Journal_Printf( stream, "(2,0): %d  = %d  ", FT3D_20, TensorArray_TensorMap(2,0,3));
+		Journal_Printf( stream, "(2,1): %d  = %d  ", FT3D_21, TensorArray_TensorMap(2,1,3));
+		Journal_Printf( stream, "(2,2): %d  = %d\n", FT3D_22, TensorArray_TensorMap(2,2,3));
+
+		Journal_Printf( stream, "Test Mapping functions for Symmetric Tensor ");
+		Journal_Printf( stream, "using SymmetricTensor_TensorMap\n\n");
+		Journal_Printf( stream, "(0,0): %d  = %d  ", ST3D_00, SymmetricTensor_TensorMap(0,0,3));
+		Journal_Printf( stream, "(0,1): %d  = %d  ", ST3D_01, SymmetricTensor_TensorMap(0,1,3));
+		Journal_Printf( stream, "(0,2): %d  = %d\n", ST3D_02, SymmetricTensor_TensorMap(0,2,3));
+
+		Journal_Printf( stream, "(1,0): %d  = %d  ", ST3D_01, SymmetricTensor_TensorMap(1,0,3));
+		Journal_Printf( stream, "(1,1): %d  = %d  ", ST3D_11, SymmetricTensor_TensorMap(1,1,3));
+		Journal_Printf( stream, "(1,2): %d  = %d\n", ST3D_12, SymmetricTensor_TensorMap(1,2,3));
+
+		Journal_Printf( stream, "(2,0): %d  = %d  ", ST3D_02, SymmetricTensor_TensorMap(2,0,3));
+		Journal_Printf( stream, "(2,1): %d  = %d  ", ST3D_12, SymmetricTensor_TensorMap(2,1,3));
+		Journal_Printf( stream, "(2,2): %d  = %d\n", ST3D_22, SymmetricTensor_TensorMap(2,2,3));
+
+		pcu_filename_expected( "testTensorMathMappingFunctions.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathMappingFunctions.dat", expected_file );
+		remove( "testTensorMathMappingFunctions.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestEigenVectorListSort( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		Eigenvector	eigenvectorList[3];
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"EigenVectorListSort"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathEigenVectorListSort.dat" );
+
+		Journal_Printf( stream, "*************************************\n" );
+		Journal_Printf( stream, "Test function EigenvectorList_Sort\n" );
+		/*  Matrix that gives eigenvalues and vectors  */
+		/* | 1.000 1.000 2.000 | */
+		/* | 1.000 2.000 1.000 | */
+		/* | 2.000 1.000 1.000 | */
+		Journal_Printf( stream, " 3-D\n");
+		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
+		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
+		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
+		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
+
+		Journal_Printf( stream, "Unsorted eigenvectorList\n");
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
+
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
+
+		EigenvectorList_Sort( eigenvectorList, 3);
+
+		Journal_Printf( stream, "Sorted eigenvectorList\n");
+
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
+
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
+
+		Journal_Printf( stream, "2-D\n");
+
+		/*  Matrix that gives eigenvalues and vectors  */
+		/* | 5.000 1.000 | */
+		/* | 1.000 5.000 | */
+
+		eigenvectorList[0].eigenvalue = 6; eigenvectorList[1].eigenvalue = 4;
+		eigenvectorList[0].vector[0] = 0.707; eigenvectorList[0].vector[1] = 0.707;
+		eigenvectorList[1].vector[0] = 0.707; eigenvectorList[1].vector[1] = -0.707;
+
+		Journal_Printf( stream, "Unsorted eigenvectorList\n");
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
+
+		EigenvectorList_Sort( eigenvectorList, 2);
+
+		Journal_Printf( stream, "Sorted eigenvectorList\n");
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
+			
+		pcu_filename_expected( "testTensorMathEigenVectorListSort.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathEigenVectorListSort.dat", expected_file );
+		remove( "testTensorMathEigenVectorListSort.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestEigenVector1( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		Eigenvector			eigenvectorList[3];
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector1"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathEigenVector1.dat" );
+
+		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
+		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
+		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
+		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
+
+		Journal_Printf(stream, "****************    Test Eigenvector 1   *********************\n");
+		Journal_Printf( stream, "2D Case from Kresig, p. 371f\n\n");
+		symmTensor[0] = -5;
+		symmTensor[1] = -2;
+		symmTensor[2] = 2;
+
+		Journal_Printf( stream, "Matrix to solve for eigenvectors is:\n");
+		Journal_PrintSymmetricTensor( stream, symmTensor, 2 );
+
+		SymmetricTensor_CalcAllEigenvectors( symmTensor, 2, eigenvectorList );
+
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
+
+		pcu_filename_expected( "testTensorMathEigenVector1.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathEigenVector1.dat", expected_file );
+		remove( "testTensorMathEigenVector1.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestEigenVector2( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		Eigenvector			eigenvectorList[3];
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector2"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathEigenVector2.dat" );
+
+		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
+		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
+		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
+		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
+
+		Journal_Printf( stream, "****************    Test Eigenvector 2   **********************\n");
+		Journal_Printf( stream, "Same test as above - but using Numerical Recipies function\n\n");
+		symmTensor[0] = -5;
+		symmTensor[1] = -2;
+		symmTensor[2] = 2;
+
+		SymmetricTensor_CalcAllEigenvectorsJacobi( symmTensor, 2, eigenvectorList );
+
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 2 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 2 );
+
+		pcu_filename_expected( "testTensorMathEigenVector2.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathEigenVector2.dat", expected_file );
+		remove( "testTensorMathEigenVector2.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestEigenVector3( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		Eigenvector			eigenvectorList[3];
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector3"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathEigenVector3.dat" );
+
+		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
+		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
+		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
+		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
+
+		Journal_Printf( stream, "****************    Test Eigenvector 3   *********************\n");
+		Journal_Printf( stream, "3D Case -tested on 3/11/04, against: \n");
+		Journal_Printf( stream, "http://www.arndt-bruenner.de/mathe/scripts/engl_eigenwert.htm\n");
+		symmTensor[0] = 2; symmTensor[1] = 3; symmTensor[2] = 5;
+		symmTensor[3] = 7; symmTensor[4] = 11; symmTensor[5] = 13;
+
+		Journal_Printf( stream, "Matrix to solve for eigenvectors is:\n");
+		Journal_PrintSymmetricTensor( stream, symmTensor, 3 );
+
+		SymmetricTensor_CalcAllEigenvectors( symmTensor, 3, eigenvectorList );
+
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
+
+		pcu_filename_expected( "testTensorMathEigenVector3.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathEigenVector3.dat", expected_file );
+		remove( "testTensorMathEigenVector3.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite_TestEigenVector4( TensorMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		TensorArray			tensorArray;
+		Eigenvector			eigenvectorList[3];
+		XYZ					rightHandSide;
+		XYZ					solution;
+		int					dim;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"EigenVector4"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorMathEigenVector4.dat" );
+
+		eigenvectorList[0].eigenvalue = 4; eigenvectorList[1].eigenvalue = -1; eigenvectorList[2].eigenvalue = 1;
+		eigenvectorList[0].vector[0] = 0.577; eigenvectorList[0].vector[1] = 0.577; eigenvectorList[0].vector[2] = 0.577;
+		eigenvectorList[1].vector[0] = -0.707; eigenvectorList[1].vector[1] = 0; eigenvectorList[1].vector[2] = 0.707;
+		eigenvectorList[2].vector[0] = 0.408; eigenvectorList[2].vector[1] = -0.816; eigenvectorList[2].vector[2] = 0.408;
+
+		Journal_Printf( stream, "****************    Test Eigenvector 4   *********************\n");
+		Journal_Printf( stream, "Same test as above - but using Numerical Recipies function\n\n");
+		symmTensor[0] = 2; symmTensor[1] = 3; symmTensor[2] = 5;
+		symmTensor[3] = 7; symmTensor[4] = 11; symmTensor[5] = 13;
+
+		SymmetricTensor_CalcAllEigenvectorsJacobi( symmTensor, 3, eigenvectorList );
+
+		Journal_PrintValue( stream, eigenvectorList[0].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[1].eigenvalue );
+		Journal_PrintValue( stream, eigenvectorList[2].eigenvalue );
+		Journal_PrintArray( stream, eigenvectorList[0].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[1].vector, 3 );
+		Journal_PrintArray( stream, eigenvectorList[2].vector, 3 );
+
+		Journal_Printf( stream, "\n");
+
+		/* Test Matrix Solve */
+		dim = 2;
+		tensorArray[ FT2D_00 ] = 10;
+		tensorArray[ FT2D_01 ] = 11;
+		tensorArray[ FT2D_10 ] = 12;
+		tensorArray[ FT2D_11 ] = 13;
+		Journal_PrintTensorArray( stream, tensorArray, dim );
+
+		rightHandSide[0] = 24;
+		rightHandSide[1] = 35;
+		Journal_PrintArray( stream, rightHandSide, (unsigned)dim );
+
+		TensorArray_SolveSystem( tensorArray, solution, rightHandSide, dim );
+		Journal_PrintArray( stream, solution, (unsigned)dim );
+
+		dim = 3;
+		tensorArray[ FT3D_00 ] = 10;
+		tensorArray[ FT3D_01 ] = 11;
+		tensorArray[ FT3D_02 ] = 12;
+		tensorArray[ FT3D_10 ] = 13;
+		tensorArray[ FT3D_11 ] = 14;
+		tensorArray[ FT3D_12 ] = 15;
+		tensorArray[ FT3D_20 ] = 16;
+		tensorArray[ FT3D_21 ] = 17;
+		tensorArray[ FT3D_22 ] = 19;
+		Journal_PrintTensorArray( stream, tensorArray, dim );
+
+		rightHandSide[0] = 24;
+		rightHandSide[1] = 35;
+		rightHandSide[2] = 45;
+		Journal_PrintArray( stream, rightHandSide, (unsigned)dim );
+
+		TensorArray_SolveSystem( tensorArray, solution, rightHandSide, dim );
+		Journal_PrintArray( stream, solution, (unsigned)dim );
+
+		pcu_filename_expected( "testTensorMathEigenVector4.expected", expected_file );
+		pcu_check_fileEq( "testTensorMathEigenVector4.dat", expected_file );
+		remove( "testTensorMathEigenVector4.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMathSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, TensorMathSuiteData );
+   pcu_suite_setFixtures( suite, TensorMathSuite_Setup, TensorMathSuite_Teardown );
+   pcu_suite_addTest( suite, TensorMathSuite_TestSymmetricTensorVectorComponents );
+   pcu_suite_addTest( suite, TensorMathSuite_TestJournalPrintTensorArray );
+   pcu_suite_addTest( suite, TensorMathSuite_TestTensorToTensorArrayFunction );
+   pcu_suite_addTest( suite, TensorMathSuite_TestMathArrayToMatrix );
+   pcu_suite_addTest( suite, TensorMathSuite_TestSymmetricTensorToMatrix );
+   pcu_suite_addTest( suite, TensorMathSuite_TestGetAntisymmetricPart );
+   pcu_suite_addTest( suite, TensorMathSuite_TestGetSymmetricPart );
+   pcu_suite_addTest( suite, TensorMathSuite_Test2ndInvariant );
+   pcu_suite_addTest( suite, TensorMathSuite_TestVectorTensorVector );
+   pcu_suite_addTest( suite, TensorMathSuite_TestZeroTensor );
+   pcu_suite_addTest( suite, TensorMathSuite_TestMatrixDeterminant );
+   pcu_suite_addTest( suite, TensorMathSuite_TestCubicSolver );
+   pcu_suite_addTest( suite, TensorMathSuite_TestMappingFunctions );
+   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVectorListSort );
+   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector1 );
+   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector2 );
+   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector3 );
+   pcu_suite_addTest( suite, TensorMathSuite_TestEigenVector4 );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/TensorMultMathSuite.c
--- a/Geometry/tests/TensorMultMathSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1112 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the TensorMultMathSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "TensorMultMathSuite.h"
-
-#define TENSORMULTMATH_TEST_ERROR 1e-05
-
-typedef struct {
-	MPI_Comm comm;
-	int rank;
-	int nProcs;
-} TensorMultMathSuiteData;
-
-void TensorMultMathSuite_Setup( TensorMultMathSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void TensorMultMathSuite_Teardown( TensorMultMathSuiteData* data ) {
-}
-
-void TensorMultMathSuite_TestTensorArrayIdentity( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray	tensorArray;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayIdentity"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayIdentity.dat" );
-		Journal_Printf( stream, "*******************    Test 1   ************************\n");
-		Journal_Printf( stream, "Test TensorArray Identity\n\n");
-    
-		Journal_Printf( stream, "2-D\n");
-		TensorArray_Identity(2, tensorArray );
-		Journal_PrintTensorArray( stream, tensorArray, 2); 
-    
-		Journal_Printf( stream, "3-D\n");
-		TensorArray_Identity(3, tensorArray );
-		Journal_PrintTensorArray( stream, tensorArray, 3); 
-
-		pcu_filename_expected( "testTensorMultMathArrayIdentity.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayIdentity.dat", expected_file );
-		remove( "testTensorArrayIdentity.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestSymmetricTensorIdentity( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorIdentity"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testSymmetricTensorIdentity.dat" );
-
-		Journal_Printf(stream, "*******************    Test 2   ************************\n");
-		Journal_Printf( stream, "Test SymmetricTensor Identity\n\n");
-    
-		Journal_Printf( stream, "2-D\n");
-		SymmetricTensor_Identity(2, symmTensor );
-		Journal_PrintSymmetricTensor( stream, symmTensor, 2); 
-    
-		Journal_Printf( stream, "3-D\n");
-		SymmetricTensor_Identity(3, symmTensor );
-		Journal_PrintSymmetricTensor( stream, symmTensor, 3); 
-
-		pcu_filename_expected( "testTensorMultMathSymmetricTensorIdentity.expected", expected_file );
-		pcu_check_fileEq( "testSymmetricTensorIdentity.dat", expected_file );
-		remove( "testSymmetricTensorIdentity.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayTranspose( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray	tensorArray, tensorResult;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayTranspose"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayTranspose.dat" );
-
-		Journal_Printf(stream, "*******************    Test 3   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_Transpose \n\n");
-
-		Journal_Printf( stream, "2-D\n");    
-		tensorArray[FT2D_00] = 0.7; tensorArray[FT2D_01] = 1;
-		tensorArray[FT2D_10] = 2; tensorArray[FT2D_11] = 3;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2); 
-		TensorArray_Transpose(tensorArray, 2, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 2); 
-
-		Journal_Printf( stream, "3-D\n");    
-		tensorArray[FT3D_00] = 0.5; tensorArray[FT3D_01] = 10; tensorArray[FT3D_02] = 20; 
-		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 40; tensorArray[FT3D_12] = 50; 
-		tensorArray[FT3D_20] = 60; tensorArray[FT3D_21] = 70; tensorArray[FT3D_22] = 80;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		TensorArray_Transpose(tensorArray, 3, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultTranspose.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayTranspose.dat", expected_file );
-		remove( "testTensorArrayTranspose.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayAdd( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray	tensorArray, tensorArray2, tensorResult;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayAdd"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayAdd.dat" );
-
-		Journal_Printf( stream, "*******************    Test 4   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_Add \n\n");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 0.7; tensorArray[FT2D_01] = 1;
-		tensorArray[FT2D_10] = 2; tensorArray[FT2D_11] = 3;
-
-		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
-		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		Journal_PrintTensorArray( stream, tensorArray2, 2);
-		TensorArray_Add(tensorArray, tensorArray2, 2, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 0.5; tensorArray[FT3D_01] = 10; tensorArray[FT3D_02] = 20; 
-		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 40; tensorArray[FT3D_12] = 50; 
-		tensorArray[FT3D_20] = 60; tensorArray[FT3D_21] = 70; tensorArray[FT3D_22] = 80;
-
-		tensorArray2[FT3D_00] = 5; tensorArray2[FT3D_01] = 1; tensorArray2[FT3D_02] = 2;
-		tensorArray2[FT3D_10] = 3; tensorArray2[FT3D_11] = 4; tensorArray2[FT3D_12] = 5;
-		tensorArray2[FT3D_20] = 6; tensorArray2[FT3D_21] = 7; tensorArray2[FT3D_22] = 8;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		Journal_PrintTensorArray( stream, tensorArray2, 3);
-		TensorArray_Add(tensorArray, tensorArray2, 3, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultAdd.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayAdd.dat", expected_file );
-		remove( "testTensorArrayAdd.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArraySubstract( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray	tensorArray, tensorArray2, tensorResult;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArraySubstract"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArraySubstract.dat" );
-
-		Journal_Printf(stream, "*******************    Test 5   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_Subtract \n\n");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 0.7; tensorArray[FT2D_01] = 1;
-		tensorArray[FT2D_10] = 2; tensorArray[FT2D_11] = 3;
-
-		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
-		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		Journal_PrintTensorArray( stream, tensorArray2, 2);
-		TensorArray_Subtract(tensorArray, tensorArray2, 2, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 0.5; tensorArray[FT3D_01] = 10; tensorArray[FT3D_02] = 20; 
-		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 40; tensorArray[FT3D_12] = 50; 
-		tensorArray[FT3D_20] = 60; tensorArray[FT3D_21] = 70; tensorArray[FT3D_22] = 80;
-
-		tensorArray2[FT3D_00] = 50; tensorArray2[FT3D_01] = 1; tensorArray2[FT3D_02] = 2;
-		tensorArray2[FT3D_10] = 3; tensorArray2[FT3D_11] = 4; tensorArray2[FT3D_12] = 5;
-		tensorArray2[FT3D_20] = 6; tensorArray2[FT3D_21] = 7; tensorArray2[FT3D_22] = 8;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		Journal_PrintTensorArray( stream, tensorArray2, 3);
-		TensorArray_Subtract(tensorArray, tensorArray2, 3, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultSubstract.expected", expected_file );
-		pcu_check_fileEq( "testTensorArraySubstract.dat", expected_file );
-		remove( "testTensorArraySubstract.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayMultiplyByTensorArray( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray	tensorArray, tensorArray2, tensorResult;
-		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByTensorArray"  );
-		char			expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayMultiplyByTensorArray.dat" );
-
-		Journal_Printf(stream, "*******************    Test 6   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_MultiplyByTensorArray \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
-		Journal_Printf( stream, "2-D\n");
-
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
-		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		Journal_PrintTensorArray( stream, tensorArray2, 2);
-		TensorArray_MultiplyByTensorArray(tensorArray, tensorArray2, 2, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-
-		tensorArray2[FT3D_00] = 10; tensorArray2[FT3D_01] = 11; tensorArray2[FT3D_02] = 12;
-		tensorArray2[FT3D_10] = 13; tensorArray2[FT3D_11] = 14; tensorArray2[FT3D_12] = 15;
-		tensorArray2[FT3D_20] = 16; tensorArray2[FT3D_21] = 17; tensorArray2[FT3D_22] = 18;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		Journal_PrintTensorArray( stream, tensorArray2, 3);
-		TensorArray_MultiplyByTensorArray(tensorArray, tensorArray2, 3, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultMultiplyByTensorArray.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayMultiplyByTensorArray.dat", expected_file );
-		remove( "testTensorArrayMultiplyByTensorArray.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayMultiplyByRightTranspose( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensorResult;
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByRightTranspose"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayMultiplyByRightTranspose.dat" );
-
-		Journal_Printf(stream, "*******************    Test 7   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_MultiplyByRightTranspose \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		TensorArray_MultiplyByRightTranspose(tensorArray, 2, symmTensorResult);
-		Journal_Printf( stream, "The answer, A * A^T = \n");
-		Journal_PrintSymmetricTensor( stream, symmTensorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		TensorArray_MultiplyByRightTranspose(tensorArray, 3, symmTensorResult);
-		Journal_Printf( stream, "The answer, A * A^T = \n");
-		Journal_PrintSymmetricTensor( stream, symmTensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultMultiplyByRightTranspose.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayMultiplyByRightTranspose.dat", expected_file );
-		remove( "testTensorArrayMultiplyByRightTranspose.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayMultiplyByLeftTranspose( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensorResult;
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByLeftTranspose"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayMultiplyByLeftTranspose.dat" );
-
-		Journal_Printf(stream, "*******************    Test 8   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_MultiplyByLeftTranspose \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		TensorArray_MultiplyByLeftTranspose(tensorArray, 2, symmTensorResult);
-		Journal_Printf( stream, "The answer, A^T * A = \n");
-		Journal_PrintSymmetricTensor( stream, symmTensorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		TensorArray_MultiplyByLeftTranspose(tensorArray, 3, symmTensorResult);
-		Journal_Printf( stream, "The answer, A^T * A = \n");
-		Journal_PrintSymmetricTensor( stream, symmTensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultMultiplyByLeftTranspose.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayMultiplyByLeftTranspose.dat", expected_file );
-		remove( "testTensorArrayMultiplyByLeftTranspose.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayMultiplyBySymmetricTensor( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor;
-		TensorArray			tensorArray, tensorResult;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyBySymmetricTensor"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayMultiplyBySymemtricTensor.dat" );
-
-		Journal_Printf(stream, "*******************    Test 9   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_MultiplyBySymmetricTensor \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		symmTensor[ST2D_00] = 5; symmTensor[ST2D_01] = 6; symmTensor[ST2D_11] = 7;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		Journal_PrintSymmetricTensor( stream, symmTensor, 2);
-		TensorArray_MultiplyBySymmetricTensor(tensorArray, symmTensor, 2, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-
-		symmTensor[ST3D_00] = 10; symmTensor[ST3D_01] = 11; symmTensor[ST3D_02] = 12;
-		symmTensor[ST3D_11] = 13; symmTensor[ST3D_12] = 14; symmTensor[ST3D_22] = 15;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		Journal_PrintSymmetricTensor( stream, symmTensor, 3);
-		TensorArray_MultiplyBySymmetricTensor(tensorArray, symmTensor, 3, tensorResult);
-		Journal_PrintTensorArray( stream, tensorResult, 3);
-
-		pcu_filename_expected( "testTensorMultMultiplyBySymmetricTensor.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayMultiplyBySymemtricTensor.dat", expected_file );
-		remove( "testTensorArrayMultiplyBySymemtricTensor.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayMultiplyByLeftVector( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		XYZ					vector, vectorResult;
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByLeftVector"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayMultiplyByLeftVector.dat" );
-
-		Journal_Printf(stream, "*******************    Test 10   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_MultiplyByLeftVector \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		vector[0] = 5; vector[1] = 6;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		StGermain_PrintNamedVector( stream, vector, 2);
-		TensorArray_MultiplyByLeftVector(tensorArray, vector, 2, vectorResult);
-		StGermain_PrintNamedVector( stream, vectorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-
-		vector[0] = 10; vector[1] = 11; vector[2] = 12;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		StGermain_PrintNamedVector( stream, vector, 3);
-		TensorArray_MultiplyByLeftVector(tensorArray, vector, 3, vectorResult);
-		StGermain_PrintNamedVector( stream, vectorResult, 3);
-
-		pcu_filename_expected( "testTensorMultMultiplyByLeftVector.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayMultiplyByLeftVector.dat", expected_file );
-		remove( "testTensorArrayMultiplyByLeftVector.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayMultiplyByRightVector( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		XYZ					vector, vectorResult;
-		TensorArray			tensorArray;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByRightVector"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTensorArrayMultiplyByRightVector.dat" );
-
-		Journal_Printf(stream, "*******************    Test 11   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_MultiplyByRightVector \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		vector[0] = 5; vector[1] = 6;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		StGermain_PrintNamedVector( stream, vector, 2);
-		TensorArray_MultiplyByRightVector(tensorArray, vector, 2, vectorResult);
-		StGermain_PrintNamedVector( stream, vectorResult, 2);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-
-		vector[0] = 10; vector[1] = 11; vector[2] = 12;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		StGermain_PrintNamedVector( stream, vector, 3);
-		TensorArray_MultiplyByRightVector(tensorArray, vector, 3, vectorResult);
-		StGermain_PrintNamedVector( stream, vectorResult, 3);
-
-		pcu_filename_expected( "testTensorMultMultiplyByRightVector.expected", expected_file );
-		pcu_check_fileEq( "testTensorArrayMultiplyByRightVector.dat", expected_file );
-		remove( "testTensorArrayMultiplyByRightVector.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestCalcDeterminant( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray			tensorArray;
-		double				result;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"CalcDeterminant"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testCalcDeterminant.dat" );
-
-		Journal_Printf(stream, "*******************    Test 12   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_CalcDeterminant \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.bluebit.gr/matrix-calculator/");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		result = TensorArray_CalcDeterminant(tensorArray, 2);
-		Journal_Printf( stream, "Determinant = \n");
-		Journal_PrintValue( stream, result);
-
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 22; tensorArray[FT3D_12] = 4;
-		tensorArray[FT3D_20] = 5; tensorArray[FT3D_21] = 7; tensorArray[FT3D_22] = 9;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		result = TensorArray_CalcDeterminant(tensorArray, 3);
-		Journal_Printf( stream, "Determinant = \n");
-		Journal_PrintValue( stream, result);
-
-		pcu_filename_expected( "testTensorMultCalcDeterminant.expected", expected_file );
-		pcu_check_fileEq( "testCalcDeterminant.dat", expected_file );
-		remove( "testCalcDeterminant.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestCalcInverseWithDeterminant( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray			tensorArray, tensorResult, tensorCompare, tensorDiff;
-		double				result, errorValue;
-		Dimension_Index	row, col;
-		Bool					tensorMultMathTest_Flag;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"CalcInverseWithDeterminant"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testCalcInverseWithDeterminant.dat" );
-
-      #define STG_TENSORMULTMATHTEST_ERROR 1.0e-14;
-		errorValue = STG_TENSORMULTMATHTEST_ERROR;
-
-		Journal_Printf(stream, "*******************    Test 13   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_CalcInverseWithDeterminant \n\n");
-
-		Journal_Printf( stream, "2-D\n");
-
-		tensorMultMathTest_Flag = True;
-
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		tensorCompare[FT2D_00] = -2; tensorCompare[FT2D_01] = 1;
-		tensorCompare[FT2D_10] = 1.5; tensorCompare[FT2D_11] = -0.5;
-
-		Journal_PrintTensorArray( stream, tensorArray, 2);
-		result = TensorArray_CalcDeterminant(tensorArray, 2);
-		TensorArray_CalcInverseWithDeterminant(tensorArray, result, 2, tensorResult);
-
-		TensorArray_Subtract(tensorResult, tensorCompare, 2, tensorDiff);
-
-		for (row = 0; row < 2; row++ ){
-			for ( col = 0; col < 2; col++ ){
-				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 2)]) > errorValue ) {
-					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n",
-						tensorResult[TensorArray_TensorMap(row, col, 2)],row, col, errorValue);
-					tensorMultMathTest_Flag = False;
-				}
-			}
-		}
-		if (tensorMultMathTest_Flag == True) {
-			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
-		}
-		else {
-			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);
-		}
-
-		Journal_Printf( stream, "Inverse of tensor:\n");
-		Journal_PrintTensorArray( stream, tensorCompare, 2);
-
-		Journal_Printf( stream, "3-D\n");
-
-		tensorMultMathTest_Flag = True;
-
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 22; tensorArray[FT3D_12] = 4;
-		tensorArray[FT3D_20] = 5; tensorArray[FT3D_21] = 7; tensorArray[FT3D_22] = 9;
-
-		tensorCompare[FT3D_00] = -5.666666666666667; tensorCompare[FT3D_01] = -0.100000000000000;
-		tensorCompare[FT3D_02] =  1.933333333333333; tensorCompare[FT3D_10] =  8.333333333333333;
-		tensorCompare[FT3D_11] =  0.200000000000000; tensorCompare[FT3D_12] = -2.866666666666667;
-		tensorCompare[FT3D_20] = -3.333333333333333; tensorCompare[FT3D_21] = -0.100000000000000;
-		tensorCompare[FT3D_22] =  1.266666666666667;
-
-		Journal_PrintTensorArray( stream, tensorArray, 3);
-		result = TensorArray_CalcDeterminant(tensorArray, 3);
-		TensorArray_CalcInverseWithDeterminant(tensorArray,result, 3, tensorResult);
-
-		TensorArray_Subtract(tensorResult, tensorCompare, 3, tensorDiff);
-
-		for (row = 0; row < 3; row++ ){
-			for ( col = 0; col < 3; col++ ){
-				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 3)]) > errorValue ) {
-					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n",
-						tensorResult[TensorArray_TensorMap(row, col, 3)],row, col, errorValue);
-					tensorMultMathTest_Flag = False;
-				}
-			}
-		}
-		if (tensorMultMathTest_Flag == True) {
-			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
-		}
-		else {
-			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);
-		}
-
-      Journal_Printf( stream, "Inverse of tensor:\n");
-      Journal_PrintTensorArray( stream, tensorCompare, 3);
-
-		pcu_filename_expected( "testTensorMultCalcInverseWithDeterminant.expected", expected_file );
-		pcu_check_fileEq( "testCalcInverseWithDeterminant.dat", expected_file );
-		remove( "testCalcInverseWithDeterminant.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestCalcInverse( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray			tensorArray, tensorResult, tensorCompare, tensorDiff;
-		double				errorValue;
-		Dimension_Index	row, col;
-		Bool					tensorMultMathTest_Flag;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"CalcInverse"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testCalcInverse.dat" );
-
-      #define STG_TENSORMULTMATHTEST_ERROR 1.0e-14;
-		errorValue = STG_TENSORMULTMATHTEST_ERROR;
-
-		Journal_Printf(stream, "*******************    Test 14   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_CalcInverse \n\n");
-		Journal_Printf( stream, "Solutions tested against: http://www.bluebit.gr/matrix-calculator/");		
-
-		Journal_Printf( stream, "2-D\n");
-
-		tensorMultMathTest_Flag = True;		
-		
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		tensorCompare[FT2D_00] = -2; tensorCompare[FT2D_01] =  1;
-		tensorCompare[FT2D_10] =  1.5; tensorCompare[FT2D_11] = -0.5;
-		
-		Journal_PrintTensorArray( stream, tensorArray, 2);	
-		TensorArray_CalcInverse(tensorArray, 2, tensorResult);
-		
-		TensorArray_Subtract(tensorResult, tensorCompare, 2, tensorDiff);
-		
-		for (row = 0; row < 2; row++ ){
-			for ( col = 0; col < 2; col++ ){
-				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 2)]) > errorValue ) {
-					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n", 
-							tensorResult[TensorArray_TensorMap(row, col, 2)],row, col, errorValue);
-					tensorMultMathTest_Flag = False;
-				}
-			}
-		}
-		if (tensorMultMathTest_Flag == True) {
-			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
-		}
-		else {
-			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);			
-		}
-		
-		Journal_Printf( stream, "Inverse of tensor:\n");
-		Journal_PrintTensorArray( stream, tensorCompare, 2);
-		
-		Journal_Printf( stream, "3-D\n");
-
-		tensorMultMathTest_Flag = True;
-
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 22; tensorArray[FT3D_12] = 4;
-		tensorArray[FT3D_20] = 5; tensorArray[FT3D_21] = 7; tensorArray[FT3D_22] = 9;
-
-		tensorCompare[FT3D_00] = -5.666666666666667; tensorCompare[FT3D_01] = -0.1;
-		tensorCompare[FT3D_02] =  1.933333333333333; tensorCompare[FT3D_10] =  8.333333333333333;
-		tensorCompare[FT3D_11] =  0.200000000000; tensorCompare[FT3D_12] = -2.866666666666667;
-		tensorCompare[FT3D_20] = -3.333333333333333; tensorCompare[FT3D_21] = -0.1;
-		tensorCompare[FT3D_22] =  1.266666666666667;
-		
-		Journal_PrintTensorArray( stream, tensorArray, 3);	
-		TensorArray_CalcInverse(tensorArray, 3, tensorResult);
-		
-		TensorArray_Subtract(tensorResult, tensorCompare, 3, tensorDiff);
-		
-		for (row = 0; row < 3; row++ ){
-			for ( col = 0; col < 3; col++ ){
-				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 3)]) > errorValue ) {
-					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n", 
-							tensorResult[TensorArray_TensorMap(row, col, 3)],row, col, errorValue);
-					tensorMultMathTest_Flag = False;
-				}
-			}
-		}
-		
-		if (tensorMultMathTest_Flag == True) {
-			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
-		}
-		else {
-			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);			
-		}
-		
-		Journal_Printf( stream, "Inverse of tensor:\n");
-		Journal_PrintTensorArray( stream, tensorCompare, 3);
-
-		pcu_filename_expected( "testTensorMultCalcInverse.expected", expected_file );
-		pcu_check_fileEq( "testCalcInverse.dat", expected_file );
-		remove( "testCalcInverse.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestTensorArrayDoubleContraction( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		TensorArray			tensorArray, tensorArray2;
-		double				result;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayDoubleContraction"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testTADoubleContraction.dat" );
-
-		Journal_Printf(stream, "*******************    Test 15   ************************\n");
-		Journal_Printf( stream, "Test function TensorArray_DoubleContraction \n\n");
-		Journal_Printf( stream, "Hand verified\n");
-
-		Journal_Printf( stream, "2-D\n");
-		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
-		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
-
-		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
-		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
-		
-		Journal_PrintTensorArray( stream, tensorArray, 2);	
-		Journal_PrintTensorArray( stream, tensorArray2, 2);	
-		result = TensorArray_DoubleContraction(tensorArray, tensorArray2, 2);
-		Journal_Printf( stream, "Double Contraction = \n");
-		Journal_PrintValue( stream, result);
-		
-		Journal_Printf( stream, "3-D\n");
-		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
-		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
-		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
-		
-		tensorArray2[FT3D_00] = 11; tensorArray2[FT3D_01] = 12; tensorArray2[FT3D_02] = 13;
-		tensorArray2[FT3D_10] = 14; tensorArray2[FT3D_11] = 15; tensorArray2[FT3D_12] = 16;
-		tensorArray2[FT3D_20] = 17; tensorArray2[FT3D_21] = 18; tensorArray2[FT3D_22] = 19;
-		
-		Journal_PrintTensorArray( stream, tensorArray, 3);	
-		Journal_PrintTensorArray( stream, tensorArray2, 3);	
-		result = TensorArray_DoubleContraction(tensorArray, tensorArray2, 3);
-		Journal_Printf( stream, "Double Contraction = \n");
-		Journal_PrintValue( stream, result);
-
-		pcu_filename_expected( "testTensorMultTADoubleContraction.expected", expected_file );
-		pcu_check_fileEq( "testTADoubleContraction.dat", expected_file );
-		remove( "testTADoubleContraction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestSymmetricTensorDoubleContraction( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		SymmetricTensor	symmTensor, symmTensor2;
-		double				result;
-		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorDoubleContraction"  );
-		char					expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testSTDoubleContraction.dat" );
-
-		Journal_Printf(stream, "*******************    Test 16   ************************\n");
-		Journal_Printf( stream, "Test function SymmetricTensor_DoubleContraction \n\n");
-		Journal_Printf( stream, "Hand verified\n");
-		Journal_Printf( stream, "2-D\n");		
-		symmTensor[ST2D_00] = 1; symmTensor[ST2D_01] = 2; symmTensor[ST2D_11] = 4;
-
-		symmTensor2[ST2D_00] = 10; symmTensor2[ST2D_01] = 20; symmTensor2[ST2D_11] = 40;
-
-		Journal_PrintSymmetricTensor( stream, symmTensor, 2);
-		Journal_PrintSymmetricTensor( stream, symmTensor2, 2);
-		result = SymmetricTensor_DoubleContraction(symmTensor,symmTensor2, 2);
-		Journal_Printf( stream, "Double Contraction = \n");
-		Journal_PrintValue( stream, result);
-
-		Journal_Printf( stream, "3-D\n");
-		symmTensor[ST3D_00] = 1; symmTensor[ST3D_01] = 2; symmTensor[ST3D_02] = 3;
-		symmTensor[ST3D_11] = 4; symmTensor[ST3D_12] = 5; symmTensor[ST3D_22] = 6;
-
-		symmTensor2[ST3D_00] = 10; symmTensor2[ST3D_01] = 20; symmTensor2[ST3D_02] = 30;
-		symmTensor2[ST3D_11] = 40; symmTensor2[ST3D_12] = 50; symmTensor2[ST3D_22] = 60;
-		
-		Journal_PrintSymmetricTensor( stream, symmTensor, 3);
-		Journal_PrintSymmetricTensor( stream, symmTensor2, 3);
-		result = SymmetricTensor_DoubleContraction(symmTensor,symmTensor2, 3);
-		Journal_Printf( stream, "Double Contraction = \n");
-		Journal_PrintValue( stream, result);
-
-		pcu_filename_expected( "testTensorMultSTDoubleContraction.expected", expected_file );
-		pcu_check_fileEq( "testSTDoubleContraction.dat", expected_file );
-		remove( "testSTDoubleContraction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestPrintNonSquareMatrix( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double	**nonSquareMatrixA, **nonSquareMatrixB;
-		double	**nonSquareMatrixResult, **nonSquareMatrixAT;
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"PrintNonSquareMatrix"  );
-		char		expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testPrintNonSquareMatrix.dat" );
-
-		Journal_Printf(stream, "*******************    Test 17   ************************\n");
-		Journal_Printf( stream, "Test function Journal_PrintNonSquareMatrix \n\n");
-
-		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
-		nonSquareMatrixB = Memory_Alloc_2DArray( double, 4, 2, (Name)"NonSquareMatrixB"  );
-		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
-		nonSquareMatrixResult = Memory_Alloc_2DArray( double, 3, 2, (Name)"NonSquareMatrixResult"  );
-		/* Matrix A */
-		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
-		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
-		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
-		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
-		
-		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
-		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
-		/* Matrix B */
-		nonSquareMatrixB[0][0] = 0; nonSquareMatrixB[1][0] =  2;
-		nonSquareMatrixB[0][1] = 1; nonSquareMatrixB[1][1] =  3;
-		
-		nonSquareMatrixB[2][0] = 4; nonSquareMatrixB[3][0] =  6;
-		nonSquareMatrixB[2][1] = 5; nonSquareMatrixB[3][1] =  7;
-		
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixA, 3, 4);
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixB, 4, 2);
-
-		pcu_filename_expected( "testTensorMultPrintNonSquareMatrix.expected", expected_file );
-		pcu_check_fileEq( "testPrintNonSquareMatrix.dat", expected_file );
-		remove( "testPrintNonSquareMatrix.dat" );
-
-		Memory_Free(nonSquareMatrixA);
-		Memory_Free(nonSquareMatrixB);
-		Memory_Free(nonSquareMatrixAT);
-		Memory_Free(nonSquareMatrixResult);
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestNonSquareMatrixTranspose( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double	**nonSquareMatrixA, **nonSquareMatrixB;
-		double	**nonSquareMatrixResult, **nonSquareMatrixAT;
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"NonSquareMatrixTranspose"  );
-		char		expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testNonSquareMatrixTranspose.dat" );
-
-		Journal_Printf(stream, "*******************    Test 18   ************************\n");
-		Journal_Printf( stream, "Test function NonSquareMatrix_Transpose \n\n");
-
-		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
-		nonSquareMatrixB = Memory_Alloc_2DArray( double, 4, 2, (Name)"NonSquareMatrixB"  );
-		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
-		nonSquareMatrixResult = Memory_Alloc_2DArray( double, 3, 2, (Name)"NonSquareMatrixResult"  );
-		/* Matrix A */
-		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
-		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
-		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
-		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
-		
-		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
-		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
-		/* Matrix B */
-		nonSquareMatrixB[0][0] = 0; nonSquareMatrixB[1][0] =  2;
-		nonSquareMatrixB[0][1] = 1; nonSquareMatrixB[1][1] =  3;
-		
-		nonSquareMatrixB[2][0] = 4; nonSquareMatrixB[3][0] =  6;
-		nonSquareMatrixB[2][1] = 5; nonSquareMatrixB[3][1] =  7;
-
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixA, 3, 4);
-		NonSquareMatrix_Transpose( nonSquareMatrixA, 3, 4, nonSquareMatrixAT);
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixAT, 4, 3);
-
-		pcu_filename_expected( "testTensorMultNonSquareMatrixTranspose.expected", expected_file );
-		pcu_check_fileEq( "testNonSquareMatrixTranspose.dat", expected_file );
-		remove( "testNonSquareMatrixTranspose.dat" );
-
-		Memory_Free(nonSquareMatrixA);
-		Memory_Free(nonSquareMatrixB);
-		Memory_Free(nonSquareMatrixAT);
-		Memory_Free(nonSquareMatrixResult);
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestMultiplicationByNonSquareMatrix( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		double	**nonSquareMatrixA, **nonSquareMatrixB;
-		double	**nonSquareMatrixResult, **nonSquareMatrixAT;
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"MultiplicationByNonSquareMatrix"  );
-		char		expected_file[PCU_PATH_MAX];
-
-		Stream_RedirectFile( stream, "testMultiplicationByNonSquareMatrix.dat" );
-
-		Journal_Printf(stream, "*******************    Test 19   ************************\n");
-		Journal_Printf( stream, "Test function NonSquareMatrix_MultiplicationByNonSquareMatrix \n\n");
-		
-		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
-		nonSquareMatrixB = Memory_Alloc_2DArray( double, 4, 2, (Name)"NonSquareMatrixB"  );
-		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
-		nonSquareMatrixResult = Memory_Alloc_2DArray( double, 3, 2, (Name)"NonSquareMatrixResult"  );
-		/* Matrix A */
-		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
-		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
-		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
-		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
-		
-		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
-		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
-		/* Matrix B */
-		nonSquareMatrixB[0][0] = 0; nonSquareMatrixB[1][0] =  2;
-		nonSquareMatrixB[0][1] = 1; nonSquareMatrixB[1][1] =  3;
-		
-		nonSquareMatrixB[2][0] = 4; nonSquareMatrixB[3][0] =  6;
-		nonSquareMatrixB[2][1] = 5; nonSquareMatrixB[3][1] =  7;
-
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixA, 3, 4);
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixB, 4, 2);
-
-		NonSquareMatrix_MultiplicationByNonSquareMatrix(nonSquareMatrixA, 3, 4, nonSquareMatrixB, 4,2, nonSquareMatrixResult );
-
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixResult, 3, 2);
-
-		pcu_filename_expected( "testTensorMultMultiplicationByNonSquareMatrix.expected", expected_file );
-		pcu_check_fileEq( "testMultiplicationByNonSquareMatrix.dat", expected_file );
-		remove( "testMultiplicationByNonSquareMatrix.dat" );
-
-		Memory_Free(nonSquareMatrixA);
-		Memory_Free(nonSquareMatrixB);
-		Memory_Free(nonSquareMatrixAT);
-		Memory_Free(nonSquareMatrixResult);
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite_TestMatrixVectorMultiplication( TensorMultMathSuiteData* data ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if (data->rank == procToWatch) {
-		XYZ		vector;
-		Bool		error_flag;
-		double	**nonSquareMatrixA, **nonSquareMatrixAT;
-		double	solutionVector[4], solutionVectorCompare[4];
-		Dimension_Index	row;
-		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"MatrixVectorMultiplication"  );
-		char		expected_file[PCU_PATH_MAX];
-
-      #define STG_TENSORMULTMATHTEST_ERROR 1.0e-14;
-		Stream_RedirectFile( stream, "testMatrixVectorMultiplication.dat" );
-
-		Journal_Printf(stream, "*******************    Test 20   ************************\n");
-		Journal_Printf( stream, "Test function NonSquareMatrix_MatrixVectorMultiplication \n\n");
-		Journal_Printf( stream, "Tested against solutions at http://www.uni-bonn.de/~manfear/solve_lineq.php\n\n");
-
-		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
-		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
-		/* Matrix A */
-		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
-		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
-		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
-		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
-		
-		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
-		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
-
-		NonSquareMatrix_Transpose( nonSquareMatrixA, 3, 4, nonSquareMatrixAT);
-		
-		vector[0] = 1; vector[1] = 2; vector[2] = 3;
-
-		solutionVectorCompare[0] = 32; solutionVectorCompare[1] = 38;
-		solutionVectorCompare[2] = 44; solutionVectorCompare[3] = 50;
-
-		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixAT, 4, 3);
-		StGermain_PrintNamedVector(stream, vector, 3);
-		
-		NonSquareMatrix_MatrixVectorMultiplication( nonSquareMatrixAT, 4, 3, vector, 3, solutionVector );
-		error_flag = False;
-
-		for ( row = 0; row < 4; row++ ) {
-			if (fabs(solutionVector[row] - solutionVectorCompare[row]) > TENSORMULTMATH_TEST_ERROR ) {
-				error_flag = True;
-				Journal_Printf(stream, "solutionVector[%d]=%f not within tolerance of solution, %f\n", row, solutionVector[row], solutionVectorCompare[row]);
-			}
-		}
-		if (error_flag == False) {
-			Journal_Printf(stream, "SolutionVector within tolerance %g of solution:\n", TENSORMULTMATH_TEST_ERROR);
-			StGermain_PrintNamedVector(stream, solutionVectorCompare, 4);
-		}
-		else {
-			Journal_Printf(stream, "SolutionVector not within tolerance %g of solution:\n", TENSORMULTMATH_TEST_ERROR);
-			StGermain_PrintNamedVector(stream, solutionVectorCompare, 4);
-		}
-
-		pcu_filename_expected( "testTensorMultMatrixVectorMultiplication.expected", expected_file );
-		pcu_check_fileEq( "testMatrixVectorMultiplication.dat", expected_file );
-		remove( "testMatrixVectorMultiplication.dat" );
-
-		Memory_Free(nonSquareMatrixA);
-		Memory_Free(nonSquareMatrixAT);
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void TensorMultMathSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, TensorMultMathSuiteData );
-   pcu_suite_setFixtures( suite, TensorMultMathSuite_Setup, TensorMultMathSuite_Teardown );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayIdentity );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestSymmetricTensorIdentity );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayTranspose );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayAdd );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArraySubstract );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByTensorArray );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByRightTranspose );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByLeftTranspose );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyBySymmetricTensor );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByRightVector );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByLeftVector );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestCalcDeterminant );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestCalcInverseWithDeterminant );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestCalcInverse );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayDoubleContraction );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestSymmetricTensorDoubleContraction );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestPrintNonSquareMatrix );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestNonSquareMatrixTranspose );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestMultiplicationByNonSquareMatrix );
-   pcu_suite_addTest( suite, TensorMultMathSuite_TestMatrixVectorMultiplication );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/TensorMultMathSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/TensorMultMathSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1112 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the TensorMultMathSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "TensorMultMathSuite.h"
+
+#define TENSORMULTMATH_TEST_ERROR 1e-05
+
+typedef struct {
+	MPI_Comm comm;
+	int rank;
+	int nProcs;
+} TensorMultMathSuiteData;
+
+void TensorMultMathSuite_Setup( TensorMultMathSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void TensorMultMathSuite_Teardown( TensorMultMathSuiteData* data ) {
+}
+
+void TensorMultMathSuite_TestTensorArrayIdentity( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray	tensorArray;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayIdentity"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayIdentity.dat" );
+		Journal_Printf( stream, "*******************    Test 1   ************************\n");
+		Journal_Printf( stream, "Test TensorArray Identity\n\n");
+    
+		Journal_Printf( stream, "2-D\n");
+		TensorArray_Identity(2, tensorArray );
+		Journal_PrintTensorArray( stream, tensorArray, 2); 
+    
+		Journal_Printf( stream, "3-D\n");
+		TensorArray_Identity(3, tensorArray );
+		Journal_PrintTensorArray( stream, tensorArray, 3); 
+
+		pcu_filename_expected( "testTensorMultMathArrayIdentity.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayIdentity.dat", expected_file );
+		remove( "testTensorArrayIdentity.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestSymmetricTensorIdentity( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorIdentity"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testSymmetricTensorIdentity.dat" );
+
+		Journal_Printf(stream, "*******************    Test 2   ************************\n");
+		Journal_Printf( stream, "Test SymmetricTensor Identity\n\n");
+    
+		Journal_Printf( stream, "2-D\n");
+		SymmetricTensor_Identity(2, symmTensor );
+		Journal_PrintSymmetricTensor( stream, symmTensor, 2); 
+    
+		Journal_Printf( stream, "3-D\n");
+		SymmetricTensor_Identity(3, symmTensor );
+		Journal_PrintSymmetricTensor( stream, symmTensor, 3); 
+
+		pcu_filename_expected( "testTensorMultMathSymmetricTensorIdentity.expected", expected_file );
+		pcu_check_fileEq( "testSymmetricTensorIdentity.dat", expected_file );
+		remove( "testSymmetricTensorIdentity.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayTranspose( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray	tensorArray, tensorResult;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayTranspose"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayTranspose.dat" );
+
+		Journal_Printf(stream, "*******************    Test 3   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_Transpose \n\n");
+
+		Journal_Printf( stream, "2-D\n");    
+		tensorArray[FT2D_00] = 0.7; tensorArray[FT2D_01] = 1;
+		tensorArray[FT2D_10] = 2; tensorArray[FT2D_11] = 3;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2); 
+		TensorArray_Transpose(tensorArray, 2, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 2); 
+
+		Journal_Printf( stream, "3-D\n");    
+		tensorArray[FT3D_00] = 0.5; tensorArray[FT3D_01] = 10; tensorArray[FT3D_02] = 20; 
+		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 40; tensorArray[FT3D_12] = 50; 
+		tensorArray[FT3D_20] = 60; tensorArray[FT3D_21] = 70; tensorArray[FT3D_22] = 80;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		TensorArray_Transpose(tensorArray, 3, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultTranspose.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayTranspose.dat", expected_file );
+		remove( "testTensorArrayTranspose.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayAdd( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray	tensorArray, tensorArray2, tensorResult;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayAdd"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayAdd.dat" );
+
+		Journal_Printf( stream, "*******************    Test 4   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_Add \n\n");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 0.7; tensorArray[FT2D_01] = 1;
+		tensorArray[FT2D_10] = 2; tensorArray[FT2D_11] = 3;
+
+		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
+		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		Journal_PrintTensorArray( stream, tensorArray2, 2);
+		TensorArray_Add(tensorArray, tensorArray2, 2, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 0.5; tensorArray[FT3D_01] = 10; tensorArray[FT3D_02] = 20; 
+		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 40; tensorArray[FT3D_12] = 50; 
+		tensorArray[FT3D_20] = 60; tensorArray[FT3D_21] = 70; tensorArray[FT3D_22] = 80;
+
+		tensorArray2[FT3D_00] = 5; tensorArray2[FT3D_01] = 1; tensorArray2[FT3D_02] = 2;
+		tensorArray2[FT3D_10] = 3; tensorArray2[FT3D_11] = 4; tensorArray2[FT3D_12] = 5;
+		tensorArray2[FT3D_20] = 6; tensorArray2[FT3D_21] = 7; tensorArray2[FT3D_22] = 8;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		Journal_PrintTensorArray( stream, tensorArray2, 3);
+		TensorArray_Add(tensorArray, tensorArray2, 3, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultAdd.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayAdd.dat", expected_file );
+		remove( "testTensorArrayAdd.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArraySubstract( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray	tensorArray, tensorArray2, tensorResult;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArraySubstract"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArraySubstract.dat" );
+
+		Journal_Printf(stream, "*******************    Test 5   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_Subtract \n\n");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 0.7; tensorArray[FT2D_01] = 1;
+		tensorArray[FT2D_10] = 2; tensorArray[FT2D_11] = 3;
+
+		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
+		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		Journal_PrintTensorArray( stream, tensorArray2, 2);
+		TensorArray_Subtract(tensorArray, tensorArray2, 2, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 0.5; tensorArray[FT3D_01] = 10; tensorArray[FT3D_02] = 20; 
+		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 40; tensorArray[FT3D_12] = 50; 
+		tensorArray[FT3D_20] = 60; tensorArray[FT3D_21] = 70; tensorArray[FT3D_22] = 80;
+
+		tensorArray2[FT3D_00] = 50; tensorArray2[FT3D_01] = 1; tensorArray2[FT3D_02] = 2;
+		tensorArray2[FT3D_10] = 3; tensorArray2[FT3D_11] = 4; tensorArray2[FT3D_12] = 5;
+		tensorArray2[FT3D_20] = 6; tensorArray2[FT3D_21] = 7; tensorArray2[FT3D_22] = 8;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		Journal_PrintTensorArray( stream, tensorArray2, 3);
+		TensorArray_Subtract(tensorArray, tensorArray2, 3, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultSubstract.expected", expected_file );
+		pcu_check_fileEq( "testTensorArraySubstract.dat", expected_file );
+		remove( "testTensorArraySubstract.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayMultiplyByTensorArray( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray	tensorArray, tensorArray2, tensorResult;
+		Stream*		stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByTensorArray"  );
+		char			expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayMultiplyByTensorArray.dat" );
+
+		Journal_Printf(stream, "*******************    Test 6   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_MultiplyByTensorArray \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
+		Journal_Printf( stream, "2-D\n");
+
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
+		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		Journal_PrintTensorArray( stream, tensorArray2, 2);
+		TensorArray_MultiplyByTensorArray(tensorArray, tensorArray2, 2, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+
+		tensorArray2[FT3D_00] = 10; tensorArray2[FT3D_01] = 11; tensorArray2[FT3D_02] = 12;
+		tensorArray2[FT3D_10] = 13; tensorArray2[FT3D_11] = 14; tensorArray2[FT3D_12] = 15;
+		tensorArray2[FT3D_20] = 16; tensorArray2[FT3D_21] = 17; tensorArray2[FT3D_22] = 18;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		Journal_PrintTensorArray( stream, tensorArray2, 3);
+		TensorArray_MultiplyByTensorArray(tensorArray, tensorArray2, 3, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultMultiplyByTensorArray.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayMultiplyByTensorArray.dat", expected_file );
+		remove( "testTensorArrayMultiplyByTensorArray.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayMultiplyByRightTranspose( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensorResult;
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByRightTranspose"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayMultiplyByRightTranspose.dat" );
+
+		Journal_Printf(stream, "*******************    Test 7   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_MultiplyByRightTranspose \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		TensorArray_MultiplyByRightTranspose(tensorArray, 2, symmTensorResult);
+		Journal_Printf( stream, "The answer, A * A^T = \n");
+		Journal_PrintSymmetricTensor( stream, symmTensorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		TensorArray_MultiplyByRightTranspose(tensorArray, 3, symmTensorResult);
+		Journal_Printf( stream, "The answer, A * A^T = \n");
+		Journal_PrintSymmetricTensor( stream, symmTensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultMultiplyByRightTranspose.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayMultiplyByRightTranspose.dat", expected_file );
+		remove( "testTensorArrayMultiplyByRightTranspose.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayMultiplyByLeftTranspose( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensorResult;
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByLeftTranspose"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayMultiplyByLeftTranspose.dat" );
+
+		Journal_Printf(stream, "*******************    Test 8   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_MultiplyByLeftTranspose \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		TensorArray_MultiplyByLeftTranspose(tensorArray, 2, symmTensorResult);
+		Journal_Printf( stream, "The answer, A^T * A = \n");
+		Journal_PrintSymmetricTensor( stream, symmTensorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		TensorArray_MultiplyByLeftTranspose(tensorArray, 3, symmTensorResult);
+		Journal_Printf( stream, "The answer, A^T * A = \n");
+		Journal_PrintSymmetricTensor( stream, symmTensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultMultiplyByLeftTranspose.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayMultiplyByLeftTranspose.dat", expected_file );
+		remove( "testTensorArrayMultiplyByLeftTranspose.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayMultiplyBySymmetricTensor( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor;
+		TensorArray			tensorArray, tensorResult;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyBySymmetricTensor"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayMultiplyBySymemtricTensor.dat" );
+
+		Journal_Printf(stream, "*******************    Test 9   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_MultiplyBySymmetricTensor \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		symmTensor[ST2D_00] = 5; symmTensor[ST2D_01] = 6; symmTensor[ST2D_11] = 7;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		Journal_PrintSymmetricTensor( stream, symmTensor, 2);
+		TensorArray_MultiplyBySymmetricTensor(tensorArray, symmTensor, 2, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+
+		symmTensor[ST3D_00] = 10; symmTensor[ST3D_01] = 11; symmTensor[ST3D_02] = 12;
+		symmTensor[ST3D_11] = 13; symmTensor[ST3D_12] = 14; symmTensor[ST3D_22] = 15;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		Journal_PrintSymmetricTensor( stream, symmTensor, 3);
+		TensorArray_MultiplyBySymmetricTensor(tensorArray, symmTensor, 3, tensorResult);
+		Journal_PrintTensorArray( stream, tensorResult, 3);
+
+		pcu_filename_expected( "testTensorMultMultiplyBySymmetricTensor.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayMultiplyBySymemtricTensor.dat", expected_file );
+		remove( "testTensorArrayMultiplyBySymemtricTensor.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayMultiplyByLeftVector( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		XYZ					vector, vectorResult;
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByLeftVector"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayMultiplyByLeftVector.dat" );
+
+		Journal_Printf(stream, "*******************    Test 10   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_MultiplyByLeftVector \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		vector[0] = 5; vector[1] = 6;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		StGermain_PrintNamedVector( stream, vector, 2);
+		TensorArray_MultiplyByLeftVector(tensorArray, vector, 2, vectorResult);
+		StGermain_PrintNamedVector( stream, vectorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+
+		vector[0] = 10; vector[1] = 11; vector[2] = 12;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		StGermain_PrintNamedVector( stream, vector, 3);
+		TensorArray_MultiplyByLeftVector(tensorArray, vector, 3, vectorResult);
+		StGermain_PrintNamedVector( stream, vectorResult, 3);
+
+		pcu_filename_expected( "testTensorMultMultiplyByLeftVector.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayMultiplyByLeftVector.dat", expected_file );
+		remove( "testTensorArrayMultiplyByLeftVector.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayMultiplyByRightVector( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		XYZ					vector, vectorResult;
+		TensorArray			tensorArray;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayMultiplyByRightVector"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTensorArrayMultiplyByRightVector.dat" );
+
+		Journal_Printf(stream, "*******************    Test 11   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_MultiplyByRightVector \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.uni-bonn.de/~manfear/matrixcalc.php");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		vector[0] = 5; vector[1] = 6;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		StGermain_PrintNamedVector( stream, vector, 2);
+		TensorArray_MultiplyByRightVector(tensorArray, vector, 2, vectorResult);
+		StGermain_PrintNamedVector( stream, vectorResult, 2);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+
+		vector[0] = 10; vector[1] = 11; vector[2] = 12;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		StGermain_PrintNamedVector( stream, vector, 3);
+		TensorArray_MultiplyByRightVector(tensorArray, vector, 3, vectorResult);
+		StGermain_PrintNamedVector( stream, vectorResult, 3);
+
+		pcu_filename_expected( "testTensorMultMultiplyByRightVector.expected", expected_file );
+		pcu_check_fileEq( "testTensorArrayMultiplyByRightVector.dat", expected_file );
+		remove( "testTensorArrayMultiplyByRightVector.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestCalcDeterminant( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray			tensorArray;
+		double				result;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"CalcDeterminant"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testCalcDeterminant.dat" );
+
+		Journal_Printf(stream, "*******************    Test 12   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_CalcDeterminant \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.bluebit.gr/matrix-calculator/");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		result = TensorArray_CalcDeterminant(tensorArray, 2);
+		Journal_Printf( stream, "Determinant = \n");
+		Journal_PrintValue( stream, result);
+
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 22; tensorArray[FT3D_12] = 4;
+		tensorArray[FT3D_20] = 5; tensorArray[FT3D_21] = 7; tensorArray[FT3D_22] = 9;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		result = TensorArray_CalcDeterminant(tensorArray, 3);
+		Journal_Printf( stream, "Determinant = \n");
+		Journal_PrintValue( stream, result);
+
+		pcu_filename_expected( "testTensorMultCalcDeterminant.expected", expected_file );
+		pcu_check_fileEq( "testCalcDeterminant.dat", expected_file );
+		remove( "testCalcDeterminant.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestCalcInverseWithDeterminant( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray			tensorArray, tensorResult, tensorCompare, tensorDiff;
+		double				result, errorValue;
+		Dimension_Index	row, col;
+		Bool					tensorMultMathTest_Flag;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"CalcInverseWithDeterminant"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testCalcInverseWithDeterminant.dat" );
+
+      #define STG_TENSORMULTMATHTEST_ERROR 1.0e-14;
+		errorValue = STG_TENSORMULTMATHTEST_ERROR;
+
+		Journal_Printf(stream, "*******************    Test 13   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_CalcInverseWithDeterminant \n\n");
+
+		Journal_Printf( stream, "2-D\n");
+
+		tensorMultMathTest_Flag = True;
+
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		tensorCompare[FT2D_00] = -2; tensorCompare[FT2D_01] = 1;
+		tensorCompare[FT2D_10] = 1.5; tensorCompare[FT2D_11] = -0.5;
+
+		Journal_PrintTensorArray( stream, tensorArray, 2);
+		result = TensorArray_CalcDeterminant(tensorArray, 2);
+		TensorArray_CalcInverseWithDeterminant(tensorArray, result, 2, tensorResult);
+
+		TensorArray_Subtract(tensorResult, tensorCompare, 2, tensorDiff);
+
+		for (row = 0; row < 2; row++ ){
+			for ( col = 0; col < 2; col++ ){
+				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 2)]) > errorValue ) {
+					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n",
+						tensorResult[TensorArray_TensorMap(row, col, 2)],row, col, errorValue);
+					tensorMultMathTest_Flag = False;
+				}
+			}
+		}
+		if (tensorMultMathTest_Flag == True) {
+			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
+		}
+		else {
+			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);
+		}
+
+		Journal_Printf( stream, "Inverse of tensor:\n");
+		Journal_PrintTensorArray( stream, tensorCompare, 2);
+
+		Journal_Printf( stream, "3-D\n");
+
+		tensorMultMathTest_Flag = True;
+
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 22; tensorArray[FT3D_12] = 4;
+		tensorArray[FT3D_20] = 5; tensorArray[FT3D_21] = 7; tensorArray[FT3D_22] = 9;
+
+		tensorCompare[FT3D_00] = -5.666666666666667; tensorCompare[FT3D_01] = -0.100000000000000;
+		tensorCompare[FT3D_02] =  1.933333333333333; tensorCompare[FT3D_10] =  8.333333333333333;
+		tensorCompare[FT3D_11] =  0.200000000000000; tensorCompare[FT3D_12] = -2.866666666666667;
+		tensorCompare[FT3D_20] = -3.333333333333333; tensorCompare[FT3D_21] = -0.100000000000000;
+		tensorCompare[FT3D_22] =  1.266666666666667;
+
+		Journal_PrintTensorArray( stream, tensorArray, 3);
+		result = TensorArray_CalcDeterminant(tensorArray, 3);
+		TensorArray_CalcInverseWithDeterminant(tensorArray,result, 3, tensorResult);
+
+		TensorArray_Subtract(tensorResult, tensorCompare, 3, tensorDiff);
+
+		for (row = 0; row < 3; row++ ){
+			for ( col = 0; col < 3; col++ ){
+				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 3)]) > errorValue ) {
+					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n",
+						tensorResult[TensorArray_TensorMap(row, col, 3)],row, col, errorValue);
+					tensorMultMathTest_Flag = False;
+				}
+			}
+		}
+		if (tensorMultMathTest_Flag == True) {
+			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
+		}
+		else {
+			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);
+		}
+
+      Journal_Printf( stream, "Inverse of tensor:\n");
+      Journal_PrintTensorArray( stream, tensorCompare, 3);
+
+		pcu_filename_expected( "testTensorMultCalcInverseWithDeterminant.expected", expected_file );
+		pcu_check_fileEq( "testCalcInverseWithDeterminant.dat", expected_file );
+		remove( "testCalcInverseWithDeterminant.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestCalcInverse( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray			tensorArray, tensorResult, tensorCompare, tensorDiff;
+		double				errorValue;
+		Dimension_Index	row, col;
+		Bool					tensorMultMathTest_Flag;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"CalcInverse"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testCalcInverse.dat" );
+
+      #define STG_TENSORMULTMATHTEST_ERROR 1.0e-14;
+		errorValue = STG_TENSORMULTMATHTEST_ERROR;
+
+		Journal_Printf(stream, "*******************    Test 14   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_CalcInverse \n\n");
+		Journal_Printf( stream, "Solutions tested against: http://www.bluebit.gr/matrix-calculator/");		
+
+		Journal_Printf( stream, "2-D\n");
+
+		tensorMultMathTest_Flag = True;		
+		
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		tensorCompare[FT2D_00] = -2; tensorCompare[FT2D_01] =  1;
+		tensorCompare[FT2D_10] =  1.5; tensorCompare[FT2D_11] = -0.5;
+		
+		Journal_PrintTensorArray( stream, tensorArray, 2);	
+		TensorArray_CalcInverse(tensorArray, 2, tensorResult);
+		
+		TensorArray_Subtract(tensorResult, tensorCompare, 2, tensorDiff);
+		
+		for (row = 0; row < 2; row++ ){
+			for ( col = 0; col < 2; col++ ){
+				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 2)]) > errorValue ) {
+					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n", 
+							tensorResult[TensorArray_TensorMap(row, col, 2)],row, col, errorValue);
+					tensorMultMathTest_Flag = False;
+				}
+			}
+		}
+		if (tensorMultMathTest_Flag == True) {
+			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
+		}
+		else {
+			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);			
+		}
+		
+		Journal_Printf( stream, "Inverse of tensor:\n");
+		Journal_PrintTensorArray( stream, tensorCompare, 2);
+		
+		Journal_Printf( stream, "3-D\n");
+
+		tensorMultMathTest_Flag = True;
+
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 30; tensorArray[FT3D_11] = 22; tensorArray[FT3D_12] = 4;
+		tensorArray[FT3D_20] = 5; tensorArray[FT3D_21] = 7; tensorArray[FT3D_22] = 9;
+
+		tensorCompare[FT3D_00] = -5.666666666666667; tensorCompare[FT3D_01] = -0.1;
+		tensorCompare[FT3D_02] =  1.933333333333333; tensorCompare[FT3D_10] =  8.333333333333333;
+		tensorCompare[FT3D_11] =  0.200000000000; tensorCompare[FT3D_12] = -2.866666666666667;
+		tensorCompare[FT3D_20] = -3.333333333333333; tensorCompare[FT3D_21] = -0.1;
+		tensorCompare[FT3D_22] =  1.266666666666667;
+		
+		Journal_PrintTensorArray( stream, tensorArray, 3);	
+		TensorArray_CalcInverse(tensorArray, 3, tensorResult);
+		
+		TensorArray_Subtract(tensorResult, tensorCompare, 3, tensorDiff);
+		
+		for (row = 0; row < 3; row++ ){
+			for ( col = 0; col < 3; col++ ){
+				if (fabs(tensorDiff[TensorArray_TensorMap(row, col, 3)]) > errorValue ) {
+					Journal_Printf( stream, "Value, %g at index ( %d, %d) not within tolerance, %g\n", 
+							tensorResult[TensorArray_TensorMap(row, col, 3)],row, col, errorValue);
+					tensorMultMathTest_Flag = False;
+				}
+			}
+		}
+		
+		if (tensorMultMathTest_Flag == True) {
+			Journal_Printf( stream, "Answer calculated within tolerance %g, for solution:\n", errorValue);
+		}
+		else {
+			Journal_Printf( stream, "Answer calculated not within tolerance %g, for solution:\n", errorValue);			
+		}
+		
+		Journal_Printf( stream, "Inverse of tensor:\n");
+		Journal_PrintTensorArray( stream, tensorCompare, 3);
+
+		pcu_filename_expected( "testTensorMultCalcInverse.expected", expected_file );
+		pcu_check_fileEq( "testCalcInverse.dat", expected_file );
+		remove( "testCalcInverse.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestTensorArrayDoubleContraction( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		TensorArray			tensorArray, tensorArray2;
+		double				result;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"TensorArrayDoubleContraction"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testTADoubleContraction.dat" );
+
+		Journal_Printf(stream, "*******************    Test 15   ************************\n");
+		Journal_Printf( stream, "Test function TensorArray_DoubleContraction \n\n");
+		Journal_Printf( stream, "Hand verified\n");
+
+		Journal_Printf( stream, "2-D\n");
+		tensorArray[FT2D_00] = 1; tensorArray[FT2D_01] = 2;
+		tensorArray[FT2D_10] = 3; tensorArray[FT2D_11] = 4;
+
+		tensorArray2[FT2D_00] = 5; tensorArray2[FT2D_01] = 6;
+		tensorArray2[FT2D_10] = 7; tensorArray2[FT2D_11] = 8;
+		
+		Journal_PrintTensorArray( stream, tensorArray, 2);	
+		Journal_PrintTensorArray( stream, tensorArray2, 2);	
+		result = TensorArray_DoubleContraction(tensorArray, tensorArray2, 2);
+		Journal_Printf( stream, "Double Contraction = \n");
+		Journal_PrintValue( stream, result);
+		
+		Journal_Printf( stream, "3-D\n");
+		tensorArray[FT3D_00] = 1; tensorArray[FT3D_01] = 2; tensorArray[FT3D_02] = 3;
+		tensorArray[FT3D_10] = 4; tensorArray[FT3D_11] = 5; tensorArray[FT3D_12] = 6;
+		tensorArray[FT3D_20] = 7; tensorArray[FT3D_21] = 8; tensorArray[FT3D_22] = 9;
+		
+		tensorArray2[FT3D_00] = 11; tensorArray2[FT3D_01] = 12; tensorArray2[FT3D_02] = 13;
+		tensorArray2[FT3D_10] = 14; tensorArray2[FT3D_11] = 15; tensorArray2[FT3D_12] = 16;
+		tensorArray2[FT3D_20] = 17; tensorArray2[FT3D_21] = 18; tensorArray2[FT3D_22] = 19;
+		
+		Journal_PrintTensorArray( stream, tensorArray, 3);	
+		Journal_PrintTensorArray( stream, tensorArray2, 3);	
+		result = TensorArray_DoubleContraction(tensorArray, tensorArray2, 3);
+		Journal_Printf( stream, "Double Contraction = \n");
+		Journal_PrintValue( stream, result);
+
+		pcu_filename_expected( "testTensorMultTADoubleContraction.expected", expected_file );
+		pcu_check_fileEq( "testTADoubleContraction.dat", expected_file );
+		remove( "testTADoubleContraction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestSymmetricTensorDoubleContraction( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		SymmetricTensor	symmTensor, symmTensor2;
+		double				result;
+		Stream*				stream = Journal_Register( InfoStream_Type, (Name)"SymmetricTensorDoubleContraction"  );
+		char					expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testSTDoubleContraction.dat" );
+
+		Journal_Printf(stream, "*******************    Test 16   ************************\n");
+		Journal_Printf( stream, "Test function SymmetricTensor_DoubleContraction \n\n");
+		Journal_Printf( stream, "Hand verified\n");
+		Journal_Printf( stream, "2-D\n");		
+		symmTensor[ST2D_00] = 1; symmTensor[ST2D_01] = 2; symmTensor[ST2D_11] = 4;
+
+		symmTensor2[ST2D_00] = 10; symmTensor2[ST2D_01] = 20; symmTensor2[ST2D_11] = 40;
+
+		Journal_PrintSymmetricTensor( stream, symmTensor, 2);
+		Journal_PrintSymmetricTensor( stream, symmTensor2, 2);
+		result = SymmetricTensor_DoubleContraction(symmTensor,symmTensor2, 2);
+		Journal_Printf( stream, "Double Contraction = \n");
+		Journal_PrintValue( stream, result);
+
+		Journal_Printf( stream, "3-D\n");
+		symmTensor[ST3D_00] = 1; symmTensor[ST3D_01] = 2; symmTensor[ST3D_02] = 3;
+		symmTensor[ST3D_11] = 4; symmTensor[ST3D_12] = 5; symmTensor[ST3D_22] = 6;
+
+		symmTensor2[ST3D_00] = 10; symmTensor2[ST3D_01] = 20; symmTensor2[ST3D_02] = 30;
+		symmTensor2[ST3D_11] = 40; symmTensor2[ST3D_12] = 50; symmTensor2[ST3D_22] = 60;
+		
+		Journal_PrintSymmetricTensor( stream, symmTensor, 3);
+		Journal_PrintSymmetricTensor( stream, symmTensor2, 3);
+		result = SymmetricTensor_DoubleContraction(symmTensor,symmTensor2, 3);
+		Journal_Printf( stream, "Double Contraction = \n");
+		Journal_PrintValue( stream, result);
+
+		pcu_filename_expected( "testTensorMultSTDoubleContraction.expected", expected_file );
+		pcu_check_fileEq( "testSTDoubleContraction.dat", expected_file );
+		remove( "testSTDoubleContraction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestPrintNonSquareMatrix( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double	**nonSquareMatrixA, **nonSquareMatrixB;
+		double	**nonSquareMatrixResult, **nonSquareMatrixAT;
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"PrintNonSquareMatrix"  );
+		char		expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testPrintNonSquareMatrix.dat" );
+
+		Journal_Printf(stream, "*******************    Test 17   ************************\n");
+		Journal_Printf( stream, "Test function Journal_PrintNonSquareMatrix \n\n");
+
+		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
+		nonSquareMatrixB = Memory_Alloc_2DArray( double, 4, 2, (Name)"NonSquareMatrixB"  );
+		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
+		nonSquareMatrixResult = Memory_Alloc_2DArray( double, 3, 2, (Name)"NonSquareMatrixResult"  );
+		/* Matrix A */
+		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
+		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
+		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
+		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
+		
+		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
+		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
+		/* Matrix B */
+		nonSquareMatrixB[0][0] = 0; nonSquareMatrixB[1][0] =  2;
+		nonSquareMatrixB[0][1] = 1; nonSquareMatrixB[1][1] =  3;
+		
+		nonSquareMatrixB[2][0] = 4; nonSquareMatrixB[3][0] =  6;
+		nonSquareMatrixB[2][1] = 5; nonSquareMatrixB[3][1] =  7;
+		
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixA, 3, 4);
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixB, 4, 2);
+
+		pcu_filename_expected( "testTensorMultPrintNonSquareMatrix.expected", expected_file );
+		pcu_check_fileEq( "testPrintNonSquareMatrix.dat", expected_file );
+		remove( "testPrintNonSquareMatrix.dat" );
+
+		Memory_Free(nonSquareMatrixA);
+		Memory_Free(nonSquareMatrixB);
+		Memory_Free(nonSquareMatrixAT);
+		Memory_Free(nonSquareMatrixResult);
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestNonSquareMatrixTranspose( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double	**nonSquareMatrixA, **nonSquareMatrixB;
+		double	**nonSquareMatrixResult, **nonSquareMatrixAT;
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"NonSquareMatrixTranspose"  );
+		char		expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testNonSquareMatrixTranspose.dat" );
+
+		Journal_Printf(stream, "*******************    Test 18   ************************\n");
+		Journal_Printf( stream, "Test function NonSquareMatrix_Transpose \n\n");
+
+		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
+		nonSquareMatrixB = Memory_Alloc_2DArray( double, 4, 2, (Name)"NonSquareMatrixB"  );
+		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
+		nonSquareMatrixResult = Memory_Alloc_2DArray( double, 3, 2, (Name)"NonSquareMatrixResult"  );
+		/* Matrix A */
+		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
+		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
+		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
+		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
+		
+		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
+		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
+		/* Matrix B */
+		nonSquareMatrixB[0][0] = 0; nonSquareMatrixB[1][0] =  2;
+		nonSquareMatrixB[0][1] = 1; nonSquareMatrixB[1][1] =  3;
+		
+		nonSquareMatrixB[2][0] = 4; nonSquareMatrixB[3][0] =  6;
+		nonSquareMatrixB[2][1] = 5; nonSquareMatrixB[3][1] =  7;
+
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixA, 3, 4);
+		NonSquareMatrix_Transpose( nonSquareMatrixA, 3, 4, nonSquareMatrixAT);
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixAT, 4, 3);
+
+		pcu_filename_expected( "testTensorMultNonSquareMatrixTranspose.expected", expected_file );
+		pcu_check_fileEq( "testNonSquareMatrixTranspose.dat", expected_file );
+		remove( "testNonSquareMatrixTranspose.dat" );
+
+		Memory_Free(nonSquareMatrixA);
+		Memory_Free(nonSquareMatrixB);
+		Memory_Free(nonSquareMatrixAT);
+		Memory_Free(nonSquareMatrixResult);
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestMultiplicationByNonSquareMatrix( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		double	**nonSquareMatrixA, **nonSquareMatrixB;
+		double	**nonSquareMatrixResult, **nonSquareMatrixAT;
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"MultiplicationByNonSquareMatrix"  );
+		char		expected_file[PCU_PATH_MAX];
+
+		Stream_RedirectFile( stream, "testMultiplicationByNonSquareMatrix.dat" );
+
+		Journal_Printf(stream, "*******************    Test 19   ************************\n");
+		Journal_Printf( stream, "Test function NonSquareMatrix_MultiplicationByNonSquareMatrix \n\n");
+		
+		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
+		nonSquareMatrixB = Memory_Alloc_2DArray( double, 4, 2, (Name)"NonSquareMatrixB"  );
+		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
+		nonSquareMatrixResult = Memory_Alloc_2DArray( double, 3, 2, (Name)"NonSquareMatrixResult"  );
+		/* Matrix A */
+		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
+		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
+		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
+		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
+		
+		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
+		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
+		/* Matrix B */
+		nonSquareMatrixB[0][0] = 0; nonSquareMatrixB[1][0] =  2;
+		nonSquareMatrixB[0][1] = 1; nonSquareMatrixB[1][1] =  3;
+		
+		nonSquareMatrixB[2][0] = 4; nonSquareMatrixB[3][0] =  6;
+		nonSquareMatrixB[2][1] = 5; nonSquareMatrixB[3][1] =  7;
+
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixA, 3, 4);
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixB, 4, 2);
+
+		NonSquareMatrix_MultiplicationByNonSquareMatrix(nonSquareMatrixA, 3, 4, nonSquareMatrixB, 4,2, nonSquareMatrixResult );
+
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixResult, 3, 2);
+
+		pcu_filename_expected( "testTensorMultMultiplicationByNonSquareMatrix.expected", expected_file );
+		pcu_check_fileEq( "testMultiplicationByNonSquareMatrix.dat", expected_file );
+		remove( "testMultiplicationByNonSquareMatrix.dat" );
+
+		Memory_Free(nonSquareMatrixA);
+		Memory_Free(nonSquareMatrixB);
+		Memory_Free(nonSquareMatrixAT);
+		Memory_Free(nonSquareMatrixResult);
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite_TestMatrixVectorMultiplication( TensorMultMathSuiteData* data ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if (data->rank == procToWatch) {
+		XYZ		vector;
+		Bool		error_flag;
+		double	**nonSquareMatrixA, **nonSquareMatrixAT;
+		double	solutionVector[4], solutionVectorCompare[4];
+		Dimension_Index	row;
+		Stream*	stream = Journal_Register( InfoStream_Type, (Name)"MatrixVectorMultiplication"  );
+		char		expected_file[PCU_PATH_MAX];
+
+      #define STG_TENSORMULTMATHTEST_ERROR 1.0e-14;
+		Stream_RedirectFile( stream, "testMatrixVectorMultiplication.dat" );
+
+		Journal_Printf(stream, "*******************    Test 20   ************************\n");
+		Journal_Printf( stream, "Test function NonSquareMatrix_MatrixVectorMultiplication \n\n");
+		Journal_Printf( stream, "Tested against solutions at http://www.uni-bonn.de/~manfear/solve_lineq.php\n\n");
+
+		nonSquareMatrixA = Memory_Alloc_2DArray( double, 3, 4, (Name)"NonSquareMatrixA"  );
+		nonSquareMatrixAT = Memory_Alloc_2DArray( double, 4, 3, (Name)"NonSquareMatrixAT"  );
+		/* Matrix A */
+		nonSquareMatrixA[0][0] = 0; nonSquareMatrixA[1][0] =  4;
+		nonSquareMatrixA[0][1] = 1; nonSquareMatrixA[1][1] =  5;
+		nonSquareMatrixA[0][2] = 2; nonSquareMatrixA[1][2] =  6;		
+		nonSquareMatrixA[0][3] = 3; nonSquareMatrixA[1][3] =  7;
+		
+		nonSquareMatrixA[2][0] = 8; nonSquareMatrixA[2][1] = 9;
+		nonSquareMatrixA[2][2] = 10; nonSquareMatrixA[2][3] = 11;
+
+		NonSquareMatrix_Transpose( nonSquareMatrixA, 3, 4, nonSquareMatrixAT);
+		
+		vector[0] = 1; vector[1] = 2; vector[2] = 3;
+
+		solutionVectorCompare[0] = 32; solutionVectorCompare[1] = 38;
+		solutionVectorCompare[2] = 44; solutionVectorCompare[3] = 50;
+
+		Journal_PrintNonSquareMatrix(stream, nonSquareMatrixAT, 4, 3);
+		StGermain_PrintNamedVector(stream, vector, 3);
+		
+		NonSquareMatrix_MatrixVectorMultiplication( nonSquareMatrixAT, 4, 3, vector, 3, solutionVector );
+		error_flag = False;
+
+		for ( row = 0; row < 4; row++ ) {
+			if (fabs(solutionVector[row] - solutionVectorCompare[row]) > TENSORMULTMATH_TEST_ERROR ) {
+				error_flag = True;
+				Journal_Printf(stream, "solutionVector[%d]=%f not within tolerance of solution, %f\n", row, solutionVector[row], solutionVectorCompare[row]);
+			}
+		}
+		if (error_flag == False) {
+			Journal_Printf(stream, "SolutionVector within tolerance %g of solution:\n", TENSORMULTMATH_TEST_ERROR);
+			StGermain_PrintNamedVector(stream, solutionVectorCompare, 4);
+		}
+		else {
+			Journal_Printf(stream, "SolutionVector not within tolerance %g of solution:\n", TENSORMULTMATH_TEST_ERROR);
+			StGermain_PrintNamedVector(stream, solutionVectorCompare, 4);
+		}
+
+		pcu_filename_expected( "testTensorMultMatrixVectorMultiplication.expected", expected_file );
+		pcu_check_fileEq( "testMatrixVectorMultiplication.dat", expected_file );
+		remove( "testMatrixVectorMultiplication.dat" );
+
+		Memory_Free(nonSquareMatrixA);
+		Memory_Free(nonSquareMatrixAT);
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void TensorMultMathSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, TensorMultMathSuiteData );
+   pcu_suite_setFixtures( suite, TensorMultMathSuite_Setup, TensorMultMathSuite_Teardown );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayIdentity );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestSymmetricTensorIdentity );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayTranspose );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayAdd );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArraySubstract );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByTensorArray );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByRightTranspose );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByLeftTranspose );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyBySymmetricTensor );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByRightVector );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayMultiplyByLeftVector );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestCalcDeterminant );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestCalcInverseWithDeterminant );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestCalcInverse );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestTensorArrayDoubleContraction );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestSymmetricTensorDoubleContraction );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestPrintNonSquareMatrix );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestNonSquareMatrixTranspose );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestMultiplicationByNonSquareMatrix );
+   pcu_suite_addTest( suite, TensorMultMathSuite_TestMatrixVectorMultiplication );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/TrigMathSuite.c
--- a/Geometry/tests/TrigMathSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,166 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the TrigMathSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "TrigMathSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-	double	angle;
-	double	rectOriginal[3];
-	double	spherical[3];
-	double	rectangular[3];
-	Index		dim;
-} TrigMathSuiteData;
-
-void TrigMathSuite_DomainFindingFunction( TrigMathSuiteData* data, double angle ) {
-	char base[24];
-	char stg[24];	
-
-	data->angle = angle;
-	sprintf( base, "%lf", sin(data->angle) );
-	sprintf( stg, "%lf", sin( StGermain_TrigDomain(data->angle) ) );
-	pcu_check_streq( base, stg );
-}
-
-void TrigMathSuite_Setup( TrigMathSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-
-	data->rectOriginal[0] = 2.4; data->rectOriginal[1] = 5; data->rectOriginal[2] = -10;
-}
-
-void TrigMathSuite_Teardown( TrigMathSuiteData* data ) {
-}
-
-void TrigMathSuite_TestAngleConversionMacros( TrigMathSuiteData* data ) {
-	char buffer[24];
-	
-	sprintf( buffer, "%2.3f", StGermain_DegreeToRadian( 37.0 + 3 ));
-	pcu_check_streq( buffer, "0.698" );
-	sprintf( buffer, "%2.3f", StGermain_RadianToDegree( 1.234 * 2 ));
-	pcu_check_streq( buffer, "141.406" );
-}
-
-void TrigMathSuite_TestDomainFindingFunction( TrigMathSuiteData* data ) {
-	TrigMathSuite_DomainFindingFunction( data, 1.5 );
-	TrigMathSuite_DomainFindingFunction( data, -1.2 );
-	TrigMathSuite_DomainFindingFunction( data, 20.0 );
-}
-
-void TrigMathSuite_TestQuadrantFindingFunction( TrigMathSuiteData* data ) {
-	data->angle = 45;
-	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 0 );
-	data->angle = 120;
-	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 1 );
-	data->angle = 195;
-	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 2 );
-	data->angle = 340;
-	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 3 );
-	data->angle = 730;
-	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 0 );
-	data->angle = -135;
-	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 2 );
-}
-
-void TrigMathSuite_TestCoordinateConversionFunction2D( TrigMathSuiteData* data ) {
-	char x[24], y[24];
-
-	data->dim = 2;
-	sprintf( x, "%lf", data->rectOriginal[0] );
-	sprintf( y, "%lf", data->rectOriginal[1] );
-	pcu_check_streq( x, "2.400000" );
-	pcu_check_streq( y, "5.000000" );
-	StGermain_RectangularToSpherical( data->spherical, data->rectOriginal, data->dim );
-	sprintf( x, "%lf", data->spherical[0] );
-	sprintf( y, "%lf", data->spherical[1] );
-	pcu_check_streq( x, "5.546170" );
-	pcu_check_streq( y, "1.123276" );
-	StGermain_SphericalToRectangular( data->rectangular, data->spherical,data-> dim );
-	sprintf( x, "%lf", data->rectangular[0] );
-	sprintf( y, "%lf", data->rectangular[1] );
-	pcu_check_streq( x, "2.400000" );
-	pcu_check_streq( y, "5.000000" );
-}
-
-void TrigMathSuite_TestCoordinateConversionFunction3D( TrigMathSuiteData* data ) {
-	char x[24], y[24], z[24];
-
-	data->dim = 3;
-	sprintf( x, "%lf", data->rectOriginal[0] );
-	sprintf( y, "%lf", data->rectOriginal[1] );
-	sprintf( z, "%lf", data->rectOriginal[2] );
-	pcu_check_streq( x, "2.400000" );
-	pcu_check_streq( y, "5.000000" );
-	pcu_check_streq( z, "-10.000000" );
-	StGermain_RectangularToSpherical( data->spherical, data->rectOriginal, data->dim );
-	sprintf( x, "%lf", data->spherical[0] );
-	sprintf( y, "%lf", data->spherical[1] );
-	sprintf( z, "%lf", data->spherical[2] );
-	pcu_check_streq( x, "11.435034" );
-	pcu_check_streq( y, "1.123276" );
-	pcu_check_streq( z, "2.635212" );
-	StGermain_SphericalToRectangular( data->rectangular, data->spherical,data-> dim );
-	sprintf( x, "%lf", data->rectangular[0] );
-	sprintf( y, "%lf", data->rectangular[1] );
-	sprintf( z, "%lf", data->rectangular[2] );
-	pcu_check_streq( x, "2.400000" );
-	pcu_check_streq( y, "5.000000" );
-	pcu_check_streq( z, "-10.000000" );
-}
-
-void TrigMathSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, TrigMathSuiteData );
-   pcu_suite_setFixtures( suite, TrigMathSuite_Setup, TrigMathSuite_Teardown );
-   pcu_suite_addTest( suite, TrigMathSuite_TestAngleConversionMacros );
-   pcu_suite_addTest( suite, TrigMathSuite_TestDomainFindingFunction );
-   pcu_suite_addTest( suite, TrigMathSuite_TestQuadrantFindingFunction );
-   pcu_suite_addTest( suite, TrigMathSuite_TestCoordinateConversionFunction2D );
-   pcu_suite_addTest( suite, TrigMathSuite_TestCoordinateConversionFunction3D );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/TrigMathSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/TrigMathSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,166 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the TrigMathSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "TrigMathSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+	double	angle;
+	double	rectOriginal[3];
+	double	spherical[3];
+	double	rectangular[3];
+	Index		dim;
+} TrigMathSuiteData;
+
+void TrigMathSuite_DomainFindingFunction( TrigMathSuiteData* data, double angle ) {
+	char base[24];
+	char stg[24];	
+
+	data->angle = angle;
+	sprintf( base, "%lf", sin(data->angle) );
+	sprintf( stg, "%lf", sin( StGermain_TrigDomain(data->angle) ) );
+	pcu_check_streq( base, stg );
+}
+
+void TrigMathSuite_Setup( TrigMathSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+
+	data->rectOriginal[0] = 2.4; data->rectOriginal[1] = 5; data->rectOriginal[2] = -10;
+}
+
+void TrigMathSuite_Teardown( TrigMathSuiteData* data ) {
+}
+
+void TrigMathSuite_TestAngleConversionMacros( TrigMathSuiteData* data ) {
+	char buffer[24];
+	
+	sprintf( buffer, "%2.3f", StGermain_DegreeToRadian( 37.0 + 3 ));
+	pcu_check_streq( buffer, "0.698" );
+	sprintf( buffer, "%2.3f", StGermain_RadianToDegree( 1.234 * 2 ));
+	pcu_check_streq( buffer, "141.406" );
+}
+
+void TrigMathSuite_TestDomainFindingFunction( TrigMathSuiteData* data ) {
+	TrigMathSuite_DomainFindingFunction( data, 1.5 );
+	TrigMathSuite_DomainFindingFunction( data, -1.2 );
+	TrigMathSuite_DomainFindingFunction( data, 20.0 );
+}
+
+void TrigMathSuite_TestQuadrantFindingFunction( TrigMathSuiteData* data ) {
+	data->angle = 45;
+	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 0 );
+	data->angle = 120;
+	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 1 );
+	data->angle = 195;
+	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 2 );
+	data->angle = 340;
+	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 3 );
+	data->angle = 730;
+	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 0 );
+	data->angle = -135;
+	pcu_check_true( StGermain_TrigQuadrant( StGermain_DegreeToRadian(data->angle) ) == 2 );
+}
+
+void TrigMathSuite_TestCoordinateConversionFunction2D( TrigMathSuiteData* data ) {
+	char x[24], y[24];
+
+	data->dim = 2;
+	sprintf( x, "%lf", data->rectOriginal[0] );
+	sprintf( y, "%lf", data->rectOriginal[1] );
+	pcu_check_streq( x, "2.400000" );
+	pcu_check_streq( y, "5.000000" );
+	StGermain_RectangularToSpherical( data->spherical, data->rectOriginal, data->dim );
+	sprintf( x, "%lf", data->spherical[0] );
+	sprintf( y, "%lf", data->spherical[1] );
+	pcu_check_streq( x, "5.546170" );
+	pcu_check_streq( y, "1.123276" );
+	StGermain_SphericalToRectangular( data->rectangular, data->spherical,data-> dim );
+	sprintf( x, "%lf", data->rectangular[0] );
+	sprintf( y, "%lf", data->rectangular[1] );
+	pcu_check_streq( x, "2.400000" );
+	pcu_check_streq( y, "5.000000" );
+}
+
+void TrigMathSuite_TestCoordinateConversionFunction3D( TrigMathSuiteData* data ) {
+	char x[24], y[24], z[24];
+
+	data->dim = 3;
+	sprintf( x, "%lf", data->rectOriginal[0] );
+	sprintf( y, "%lf", data->rectOriginal[1] );
+	sprintf( z, "%lf", data->rectOriginal[2] );
+	pcu_check_streq( x, "2.400000" );
+	pcu_check_streq( y, "5.000000" );
+	pcu_check_streq( z, "-10.000000" );
+	StGermain_RectangularToSpherical( data->spherical, data->rectOriginal, data->dim );
+	sprintf( x, "%lf", data->spherical[0] );
+	sprintf( y, "%lf", data->spherical[1] );
+	sprintf( z, "%lf", data->spherical[2] );
+	pcu_check_streq( x, "11.435034" );
+	pcu_check_streq( y, "1.123276" );
+	pcu_check_streq( z, "2.635212" );
+	StGermain_SphericalToRectangular( data->rectangular, data->spherical,data-> dim );
+	sprintf( x, "%lf", data->rectangular[0] );
+	sprintf( y, "%lf", data->rectangular[1] );
+	sprintf( z, "%lf", data->rectangular[2] );
+	pcu_check_streq( x, "2.400000" );
+	pcu_check_streq( y, "5.000000" );
+	pcu_check_streq( z, "-10.000000" );
+}
+
+void TrigMathSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, TrigMathSuiteData );
+   pcu_suite_setFixtures( suite, TrigMathSuite_Setup, TrigMathSuite_Teardown );
+   pcu_suite_addTest( suite, TrigMathSuite_TestAngleConversionMacros );
+   pcu_suite_addTest( suite, TrigMathSuite_TestDomainFindingFunction );
+   pcu_suite_addTest( suite, TrigMathSuite_TestQuadrantFindingFunction );
+   pcu_suite_addTest( suite, TrigMathSuite_TestCoordinateConversionFunction2D );
+   pcu_suite_addTest( suite, TrigMathSuite_TestCoordinateConversionFunction3D );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/VectorMathSuite.c
--- a/Geometry/tests/VectorMathSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,627 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the VectorMathSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "VectorMathSuite.h"
-
-typedef struct {
-	MPI_Comm comm;
-	int rank;
-	int nProcs;
-} VectorMathSuiteData;
-
-void VectorMathSuite_Setup( VectorMathSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void VectorMathSuite_Teardown( VectorMathSuiteData* data ) {
-}
-
-void VectorMathSuite_BasicTest( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"BasicTest" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		Coord a, b, c;
-		Coord d = { 1.0, 1.0, 1.0 };
-		Coord e = { 1.0, 2.0, -3.0 };
-
-		Stream_RedirectFile( stream, "testBasicTest.dat" );
-
-		Journal_Printf( stream, "Basic tests:\n" );
-		Journal_Printf( stream, "d = { %g, %g, %g }\n", d[0], d[1], d[2] );
-		Vec_SetScalar3D( d, 2.0, 0.5, 1.5 );
-		Journal_Printf( stream, "d = { %g, %g, %g }\n", d[0], d[1], d[2] );
-
-		Vec_Set3D( c, d );
-		Journal_Printf( stream, "c = d = { %g, %g, %g }\n", c[0], c[1], c[2] );
-
-		Vec_Add3D( b, c, d );
-		Journal_Printf( stream, "b = c + d = {%g, %g, %g}\n", b[0], b[1], b[2] );
-
-		Vec_Sub3D( a, d, b );
-		Journal_Printf( stream, "a = d - b = {%g, %g, %g}\n", a[0], a[1], a[2] );
-
-		Vec_Cross3D( d, a, e );
-		Journal_Printf( stream, "d = a x e = {%g, %g, %g}\n", d[0], d[1], d[2] );
-
-		Journal_Printf( stream, "a . c = %g\n", Vec_Dot3D( a, c ) );
-
-		Vec_Scale3D( b, b, 2.0 );
-		Journal_Printf( stream, "b = 2b = { %g, %g, %g }\n", b[0], b[1], b[2] );
-
-		Vec_Norm3D( b, b );
-		Journal_Printf( stream, "b^ = { %g, %g, %g }\n", b[0], b[1], b[2] );
-
-		pcu_filename_expected( "testVectorMathBasicTest.expected", expected_file );
-		pcu_check_fileEq( "testBasicTest.dat", expected_file );
-		remove( "testBasicTest.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_CompleteTest( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"CompleteTest" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		Coord a, b, c;
-		Index i;
-
-		Stream_RedirectFile( stream, "testCompleteTest.dat" );
-
-		Journal_Printf( stream, "Complete test:\n" );
-		for( i = 1; i <= 10; i++ ) {
-			Index	j;
-			a[0] = 10.0 / (double)i;
-			b[0] = 30.0 / (double)i;
-
-			for( j = 1; j <= 10; j++ ) {
-				Index	k;
-				a[1] = 10.0 / (double)j;
-				b[1] = 30.0 / (double)j;
-
-				for( k = 1; k <= 10; k++ ) {
-					a[2] = 10.0 / (double)k;
-					b[2] = 30.0 / (double)k;
-					Vec_Proj3D( c, a, b );
-					Journal_Printf( stream, "{ %g, %g, %g }\n", c[0], c[1], c[2] );
-				}
-			}
-		}
-		Vec_SetScalar2D( a, 5.0, 9.0);
-		Journal_Printf( stream, "2D: { %g, %g }\n", a[0], a[1]);
-
-		pcu_filename_expected( "testVectorMathCompleteTest.expected", expected_file );
-		pcu_check_fileEq( "testCompleteTest.dat", expected_file );
-		remove( "testCompleteTest.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestVectorFunctions( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"CompleteTest" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double i[] = {1.0,0.0,0.0};
-		double j[] = {0.0,1.0,0.0};
-		double k[] = {0.0,0.0,1.0};
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		double D[] = {23  , 5  , -14  , 32, -21,    78};
-		double angle;
-		double vector[6];
-		double *coordList[4];
-		int d;
-		
-		coordList[0] = A;
-		coordList[1] = B;
-		coordList[2] = C;
-		coordList[3] = D;
-
-		Stream_RedirectFile( stream, "testFunctions.dat" );
-
-		/* Check Rotation functions */
-		Journal_Printf( stream, "****************************\n");
-		angle = 1.0;
-		StGermain_RotateCoordinateAxis( vector, k, I_AXIS, angle );
-		Journal_Printf( stream, "K Rotated %2.3f degrees around I axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
-		StGermain_RotateVector( vector, k, i, angle );
-		Journal_Printf( stream, "K Rotated %2.3f degrees around I axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
-		Journal_Printf( stream, "Angle between vectors = %2.3f\n", StGermain_AngleBetweenVectors( vector, k, 3 ));
-
-		angle = 2.3;
-		StGermain_RotateCoordinateAxis( vector, i, J_AXIS, angle );
-		Journal_Printf( stream, "I Rotated %2.3f degrees around J axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
-		StGermain_RotateVector( vector, i, j, angle );
-		Journal_Printf( stream, "I Rotated %2.3f degrees around J axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
-		Journal_Printf( stream, "Angle between vectors = %2.3f\n", StGermain_AngleBetweenVectors( vector, i, 3 ));
-
-		angle = 1.8;
-		StGermain_RotateCoordinateAxis( vector, j, K_AXIS, ( angle ) );
-		Journal_Printf( stream, "J Rotated %2.3f degrees around K axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
-		StGermain_RotateVector( vector, j, k, ( angle ) );
-		Journal_Printf( stream, "J Rotated %2.3f degrees around K axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
-		Journal_Printf( stream, "Angle between vectors = %2.3f\n", StGermain_AngleBetweenVectors( vector, j, 3 ));
-		
-		/* Check addition function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "vector = A + B\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			StGermain_VectorAddition( vector, A, B, d );
-			StGermain_PrintNamedVector( stream, vector, d );
-		}
-
-		/* Check subtraction function */
-		Journal_Printf( stream, "\n****************************\n");
-		Journal_Printf( stream, "vector = A - B\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			StGermain_VectorSubtraction( vector, A, B, d );
-			StGermain_PrintNamedVector( stream, vector, d );
-		}
-
-		pcu_filename_expected( "testVectorMathFunctions.expected", expected_file );
-		pcu_check_fileEq( "testFunctions.dat", expected_file );
-		remove( "testFunctions.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestMagnitudeFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"MagnitudeFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		int d;
-
-		Stream_RedirectFile( stream, "testMagnitudeFunction.dat" );
-
-		/* Check Magnitude Function */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check Magnitude Function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			Journal_Printf( stream, "dim = %d magnitude = %2.3f\n", d, StGermain_VectorMagnitude( A, d ) );
-			Journal_Printf( stream, "dim = %d magnitude = %2.3f\n", d, StGermain_VectorMagnitude( B, d ) );
-		}
-
-		pcu_filename_expected( "testVectorMathMagnitudeFunction.expected", expected_file );
-		pcu_check_fileEq( "testMagnitudeFunction.dat", expected_file );
-		remove( "testMagnitudeFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestDotProductFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"DotProductFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		int d;
-
-		Stream_RedirectFile( stream, "testDotProductFunction.dat" );
-
-		/* Check Dot Product */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check Dot Product Function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) 
-			Journal_Printf( stream, "dim = %d dot product = %2.3f\n", d, StGermain_VectorDotProduct( A, B, d ) );
-
-		pcu_filename_expected( "testVectorMathDotProductFunction.expected", expected_file );
-		pcu_check_fileEq( "testDotProductFunction.dat", expected_file );
-		remove( "testDotProductFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestCrossProductFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"CrossProductFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double vector[6];
-
-		Stream_RedirectFile( stream, "testCrossProductFunction.dat" );
-
-		/* Check Cross Product */
-		/* Tested against http://www.engplanet.com/redirect.html?3859 */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check Cross Product Function\n");
-		StGermain_VectorCrossProduct( vector, A, B );
-		StGermain_PrintNamedVector( stream, vector, 3 );
-
-		pcu_filename_expected( "testVectorMathCrossProductFunction.expected", expected_file );
-		pcu_check_fileEq( "testCrossProductFunction.dat", expected_file );
-		remove( "testCrossProductFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestDistancePointsFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"DistancePointsFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		int d;
-
-		Stream_RedirectFile( stream, "testDistancePointsFunction.dat" );
-
-		/* Checking distance between points function */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Checking distance between points Function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) 
-			Journal_Printf( stream, "dim = %d distance = %2.3f\n", d, StGermain_DistanceBetweenPoints( A, B, d ) );
-
-		pcu_filename_expected( "testVectorMathDistancePointsFunction.expected", expected_file );
-		pcu_check_fileEq( "testDistancePointsFunction.dat", expected_file );
-		remove( "testDistancePointsFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestNormalToPlaneFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"NormalToPlaneFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		double vector[6];
-
-		Stream_RedirectFile( stream, "testNormalToPlaneFunction.dat" );
-
-		/* Checking normal to plane function */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Checking normal to plane function function\n");
-		vector[0] = vector[1] = vector[2] = vector[3] = vector[4] = vector[5] = 0.0;
-		StGermain_NormalToPlane( vector, A, B, C );
-		StGermain_PrintNamedVector( stream, vector, 3 );
-
-		pcu_filename_expected( "testVectorMathNormalToPlaneFunction.expected", expected_file );
-		pcu_check_fileEq( "testNormalToPlaneFunction.dat", expected_file );
-		remove( "testNormalToPlaneFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestCentroidFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"CentroidFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		int d;
-		double vector[6];
-
-		Stream_RedirectFile( stream, "testCentroidFunction.dat" );
-
-		/* Checking centroid function */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Checking centroid function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) {
-			vector[0] = vector[1] = vector[2] = vector[3] = vector[4] = vector[5] = 0.0;
-			StGermain_TriangleCentroid( vector, A, B, C, d );
-			StGermain_PrintNamedVector( stream, vector, d );
-		}
-
-		pcu_filename_expected( "testVectorMathCentroidFunction.expected", expected_file );
-		pcu_check_fileEq( "testCentroidFunction.dat", expected_file );
-		remove( "testCentroidFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestTriangleArea( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"TriangleArea" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		int d;
-
-		Stream_RedirectFile( stream, "testTriangleArea.dat" );
-
-		/* Check Triangle Area */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check Triangle Area Function\n");
-		for ( d = 0 ; d <= 6 ; d++ ) 
-			Journal_Printf( stream, "dim = %d Triangle Area = %2.3f\n", d, StGermain_TriangleArea( A, B, C, d ) );
-
-		pcu_filename_expected( "testVectorMathTriangleArea.expected", expected_file );
-		pcu_check_fileEq( "testTriangleArea.dat", expected_file );
-		remove( "testTriangleArea.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestNormalisationFunction( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"NormalisationFunction" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		int d;
-
-		Stream_RedirectFile( stream, "testNormalisationFunction.dat" );
-
-		/* Check Normalisation Function */
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check Normalisation Function\n");
-		d = 2;
-		StGermain_VectorNormalise( A, d );
-		StGermain_PrintNamedVector( stream, A, d);
-		Journal_Printf( stream, "mag = %2.3f\n", StGermain_VectorMagnitude( A, d ) );
-
-		d = 3;
-		StGermain_VectorNormalise( B, d );
-		StGermain_PrintNamedVector( stream, B, d);
-		Journal_Printf( stream, "mag = %2.3f\n", StGermain_VectorMagnitude( B, d ) );
-
-		d = 5;
-		StGermain_VectorNormalise( C, d );
-		StGermain_PrintNamedVector( stream, C, d);
-		Journal_Printf( stream, "mag = %2.3f\n", StGermain_VectorMagnitude( C, d ) );
-
-		pcu_filename_expected( "testVectorMathNormalisationFunction.expected", expected_file );
-		pcu_check_fileEq( "testNormalisationFunction.dat", expected_file );
-		remove( "testNormalisationFunction.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestVectorCrossProductMagnitude( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"VectorCrossProductMagnitude" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-
-		Stream_RedirectFile( stream, "testVectorCrossProducMagnitude.dat" );
-
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check StGermain_VectorCrossProductMagnitude\n");
-		A[0] = 1.0; A[1] = 2.0 ; A[2] = 3.0;
-		B[0] = 4.0; B[1] = 5.0 ; B[2] = 6.0;
-		StGermain_PrintNamedVector( stream, A, 3);
-		StGermain_PrintNamedVector( stream, B, 3);
-		Journal_Printf( stream, "mag = %2.3g (2D)\n", StGermain_VectorCrossProductMagnitude( A, B, 2 ) );
-		Journal_Printf( stream, "mag = %2.3g (3D)\n", StGermain_VectorCrossProductMagnitude( A, B, 3 ) );
-
-		pcu_filename_expected( "testVectorMathCrossProductMagnitude.expected", expected_file );
-		pcu_check_fileEq( "testVectorCrossProducMagnitude.dat", expected_file );
-		remove( "testVectorCrossProducMagnitude.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestConvexQuadrilateralArea( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"ConvexQuadrilateralArea" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		double D[] = {23  , 5  , -14  , 32, -21,    78};
-
-		Stream_RedirectFile( stream, "testConvexQuadrilateralArea.dat" );
-
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check StGermain_ConvexQuadrilateralArea\n");
-		A[0] = 0.0; A[1] = 0.0 ; A[2] = 0.0;
-		B[0] = 0.0; B[1] = 4.0 ; B[2] = 2.3;
-		C[0] = 1.2; C[1] = 4.0 ; C[2] = 2.3;
-		D[0] = 1.2; D[1] = 0.0 ; D[2] = 0.0;
-		Journal_Printf( stream, "area = %2.3g (2D)\n", StGermain_ConvexQuadrilateralArea( A, B, C, D, 2 ) );
-		Journal_Printf( stream, "area = %2.3g (3D)\n", StGermain_ConvexQuadrilateralArea( A, B, C, D, 3 ) );
-
-		pcu_filename_expected( "testVectorMathConvexQuadrilateralArea.expected", expected_file );
-		pcu_check_fileEq( "testConvexQuadrilateralArea.dat", expected_file );
-		remove( "testConvexQuadrilateralArea.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestScalarTripleProduct( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"ScalarTripleProduct" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double **matrix;
-
-		Stream_RedirectFile( stream, "testScalarTripleProduct.dat" );
-
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check StGermain_ScalarTripleProduct \n");
-		matrix = Memory_Alloc_2DArray( double, 3, 3, (Name)"matrix"  );
-		matrix[0][0] = 1.0; matrix[0][1] = 2.0 ; matrix[0][2] = 3.0;
-		matrix[1][0] = 4.0; matrix[1][1] = 5.0 ; matrix[1][2] = 6.0;
-		matrix[2][0] = 7.0; matrix[2][1] = 8.0 ; matrix[2][2] = 11.0;
-		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_ScalarTripleProduct( matrix[0], matrix[1], matrix[2] ));
-		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_ScalarTripleProduct( matrix[2], matrix[0], matrix[1] ));
-		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_ScalarTripleProduct( matrix[1], matrix[2], matrix[0] ));
-		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_MatrixDeterminant( matrix , 3 ));
-		Memory_Free( matrix );
-
-		pcu_filename_expected( "testVectorMathScalarTripleProduct.expected", expected_file );
-		pcu_check_fileEq( "testScalarTripleProduct.dat", expected_file );
-		remove( "testScalarTripleProduct.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestParallelPipedVolume( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"ParallelPipedVolume" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		double D[] = {23  , 5  , -14  , 32, -21,    78};
-
-		Stream_RedirectFile( stream, "testParallelPipedVolume.dat" );
-
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check StGermain_ParallelepipedVolume \n");
-		A[0] = 0.0; A[1] = 0.0 ; A[2] = 0.0;
-		B[0] = 1.1; B[1] = 0.0 ; B[2] = 0.0;
-		C[0] = 0.2; C[1] = 1.7 ; C[2] = 0.0;
-		D[0] = 0.0; D[1] = 0.0 ; D[2] = 1.3;
-		Journal_Printf( stream, "volume = %2.3g\n", StGermain_ParallelepipedVolume( A, B, C, D ));
-
-		pcu_filename_expected( "testVectorMathParallelPipedVolume.expected", expected_file );
-		pcu_check_fileEq( "testParallelPipedVolume.dat", expected_file );
-		remove( "testParallelPipedVolume.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite_TestAverageCoord( VectorMathSuiteData* data ) {
-	int	procToWatch = data->nProcs >=2 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"AverageCoord" );
-	char		expected_file[PCU_PATH_MAX];	
-
-	if (data->rank == procToWatch ) {
-		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
-		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
-		double C[] = {23  , 5  , -14  , 32, -21,    78};
-		double D[] = {23  , 5  , -14  , 32, -21,    78};
-		double *coordList[4];
-
-		coordList[0] = A;
-		coordList[1] = B;
-		coordList[2] = C;
-		coordList[3] = D;
-
-		Stream_RedirectFile( stream, "testAverageCoord.dat" );
-
-		Journal_Printf( stream, "****************************\n");
-		Journal_Printf( stream, "Check StGermain_AverageCoord \n");
-		A[0] = 1.0;  A[1] = 2.2 ; A[2] = 3.2;
-		B[0] = 41.0; B[1] = 5.0 ; B[2] = 6.9;
-		C[0] = -7.0; C[1] = 8.7 ; C[2] = 11.0;
-
-		StGermain_AverageCoord( D, coordList, 3, 3 );
-		StGermain_PrintNamedVector( stream, D, 3);
-
-		pcu_filename_expected( "testVectorMathAverageCoord.expected", expected_file );
-		pcu_check_fileEq( "testAverageCoord.dat", expected_file );
-		remove( "testAverageCoord.dat" );
-
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void VectorMathSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, VectorMathSuiteData );
-   pcu_suite_setFixtures( suite, VectorMathSuite_Setup, VectorMathSuite_Teardown );
-   pcu_suite_addTest( suite, VectorMathSuite_BasicTest );
-   pcu_suite_addTest( suite, VectorMathSuite_CompleteTest );
-   pcu_suite_addTest( suite, VectorMathSuite_TestVectorFunctions );
-   pcu_suite_addTest( suite, VectorMathSuite_TestMagnitudeFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestDotProductFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestCrossProductFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestDistancePointsFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestNormalToPlaneFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestCentroidFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestTriangleArea );
-   pcu_suite_addTest( suite, VectorMathSuite_TestNormalisationFunction );
-   pcu_suite_addTest( suite, VectorMathSuite_TestVectorCrossProductMagnitude );
-   pcu_suite_addTest( suite, VectorMathSuite_TestConvexQuadrilateralArea );
-   pcu_suite_addTest( suite, VectorMathSuite_TestScalarTripleProduct );
-   pcu_suite_addTest( suite, VectorMathSuite_TestParallelPipedVolume );
-   pcu_suite_addTest( suite, VectorMathSuite_TestAverageCoord );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Geometry/tests/VectorMathSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Geometry/tests/VectorMathSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,627 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the VectorMathSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "VectorMathSuite.h"
+
+typedef struct {
+	MPI_Comm comm;
+	int rank;
+	int nProcs;
+} VectorMathSuiteData;
+
+void VectorMathSuite_Setup( VectorMathSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void VectorMathSuite_Teardown( VectorMathSuiteData* data ) {
+}
+
+void VectorMathSuite_BasicTest( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"BasicTest" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		Coord a, b, c;
+		Coord d = { 1.0, 1.0, 1.0 };
+		Coord e = { 1.0, 2.0, -3.0 };
+
+		Stream_RedirectFile( stream, "testBasicTest.dat" );
+
+		Journal_Printf( stream, "Basic tests:\n" );
+		Journal_Printf( stream, "d = { %g, %g, %g }\n", d[0], d[1], d[2] );
+		Vec_SetScalar3D( d, 2.0, 0.5, 1.5 );
+		Journal_Printf( stream, "d = { %g, %g, %g }\n", d[0], d[1], d[2] );
+
+		Vec_Set3D( c, d );
+		Journal_Printf( stream, "c = d = { %g, %g, %g }\n", c[0], c[1], c[2] );
+
+		Vec_Add3D( b, c, d );
+		Journal_Printf( stream, "b = c + d = {%g, %g, %g}\n", b[0], b[1], b[2] );
+
+		Vec_Sub3D( a, d, b );
+		Journal_Printf( stream, "a = d - b = {%g, %g, %g}\n", a[0], a[1], a[2] );
+
+		Vec_Cross3D( d, a, e );
+		Journal_Printf( stream, "d = a x e = {%g, %g, %g}\n", d[0], d[1], d[2] );
+
+		Journal_Printf( stream, "a . c = %g\n", Vec_Dot3D( a, c ) );
+
+		Vec_Scale3D( b, b, 2.0 );
+		Journal_Printf( stream, "b = 2b = { %g, %g, %g }\n", b[0], b[1], b[2] );
+
+		Vec_Norm3D( b, b );
+		Journal_Printf( stream, "b^ = { %g, %g, %g }\n", b[0], b[1], b[2] );
+
+		pcu_filename_expected( "testVectorMathBasicTest.expected", expected_file );
+		pcu_check_fileEq( "testBasicTest.dat", expected_file );
+		remove( "testBasicTest.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_CompleteTest( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"CompleteTest" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		Coord a, b, c;
+		Index i;
+
+		Stream_RedirectFile( stream, "testCompleteTest.dat" );
+
+		Journal_Printf( stream, "Complete test:\n" );
+		for( i = 1; i <= 10; i++ ) {
+			Index	j;
+			a[0] = 10.0 / (double)i;
+			b[0] = 30.0 / (double)i;
+
+			for( j = 1; j <= 10; j++ ) {
+				Index	k;
+				a[1] = 10.0 / (double)j;
+				b[1] = 30.0 / (double)j;
+
+				for( k = 1; k <= 10; k++ ) {
+					a[2] = 10.0 / (double)k;
+					b[2] = 30.0 / (double)k;
+					Vec_Proj3D( c, a, b );
+					Journal_Printf( stream, "{ %g, %g, %g }\n", c[0], c[1], c[2] );
+				}
+			}
+		}
+		Vec_SetScalar2D( a, 5.0, 9.0);
+		Journal_Printf( stream, "2D: { %g, %g }\n", a[0], a[1]);
+
+		pcu_filename_expected( "testVectorMathCompleteTest.expected", expected_file );
+		pcu_check_fileEq( "testCompleteTest.dat", expected_file );
+		remove( "testCompleteTest.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestVectorFunctions( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"CompleteTest" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double i[] = {1.0,0.0,0.0};
+		double j[] = {0.0,1.0,0.0};
+		double k[] = {0.0,0.0,1.0};
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		double D[] = {23  , 5  , -14  , 32, -21,    78};
+		double angle;
+		double vector[6];
+		double *coordList[4];
+		int d;
+		
+		coordList[0] = A;
+		coordList[1] = B;
+		coordList[2] = C;
+		coordList[3] = D;
+
+		Stream_RedirectFile( stream, "testFunctions.dat" );
+
+		/* Check Rotation functions */
+		Journal_Printf( stream, "****************************\n");
+		angle = 1.0;
+		StGermain_RotateCoordinateAxis( vector, k, I_AXIS, angle );
+		Journal_Printf( stream, "K Rotated %2.3f degrees around I axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
+		StGermain_RotateVector( vector, k, i, angle );
+		Journal_Printf( stream, "K Rotated %2.3f degrees around I axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
+		Journal_Printf( stream, "Angle between vectors = %2.3f\n", StGermain_AngleBetweenVectors( vector, k, 3 ));
+
+		angle = 2.3;
+		StGermain_RotateCoordinateAxis( vector, i, J_AXIS, angle );
+		Journal_Printf( stream, "I Rotated %2.3f degrees around J axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
+		StGermain_RotateVector( vector, i, j, angle );
+		Journal_Printf( stream, "I Rotated %2.3f degrees around J axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
+		Journal_Printf( stream, "Angle between vectors = %2.3f\n", StGermain_AngleBetweenVectors( vector, i, 3 ));
+
+		angle = 1.8;
+		StGermain_RotateCoordinateAxis( vector, j, K_AXIS, ( angle ) );
+		Journal_Printf( stream, "J Rotated %2.3f degrees around K axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
+		StGermain_RotateVector( vector, j, k, ( angle ) );
+		Journal_Printf( stream, "J Rotated %2.3f degrees around K axis -  %2.3f %2.3f %2.3f\n", angle, vector[0], vector[1], vector[2] );
+		Journal_Printf( stream, "Angle between vectors = %2.3f\n", StGermain_AngleBetweenVectors( vector, j, 3 ));
+		
+		/* Check addition function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "vector = A + B\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			StGermain_VectorAddition( vector, A, B, d );
+			StGermain_PrintNamedVector( stream, vector, d );
+		}
+
+		/* Check subtraction function */
+		Journal_Printf( stream, "\n****************************\n");
+		Journal_Printf( stream, "vector = A - B\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			StGermain_VectorSubtraction( vector, A, B, d );
+			StGermain_PrintNamedVector( stream, vector, d );
+		}
+
+		pcu_filename_expected( "testVectorMathFunctions.expected", expected_file );
+		pcu_check_fileEq( "testFunctions.dat", expected_file );
+		remove( "testFunctions.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestMagnitudeFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"MagnitudeFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		int d;
+
+		Stream_RedirectFile( stream, "testMagnitudeFunction.dat" );
+
+		/* Check Magnitude Function */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check Magnitude Function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			Journal_Printf( stream, "dim = %d magnitude = %2.3f\n", d, StGermain_VectorMagnitude( A, d ) );
+			Journal_Printf( stream, "dim = %d magnitude = %2.3f\n", d, StGermain_VectorMagnitude( B, d ) );
+		}
+
+		pcu_filename_expected( "testVectorMathMagnitudeFunction.expected", expected_file );
+		pcu_check_fileEq( "testMagnitudeFunction.dat", expected_file );
+		remove( "testMagnitudeFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestDotProductFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"DotProductFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		int d;
+
+		Stream_RedirectFile( stream, "testDotProductFunction.dat" );
+
+		/* Check Dot Product */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check Dot Product Function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) 
+			Journal_Printf( stream, "dim = %d dot product = %2.3f\n", d, StGermain_VectorDotProduct( A, B, d ) );
+
+		pcu_filename_expected( "testVectorMathDotProductFunction.expected", expected_file );
+		pcu_check_fileEq( "testDotProductFunction.dat", expected_file );
+		remove( "testDotProductFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestCrossProductFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"CrossProductFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double vector[6];
+
+		Stream_RedirectFile( stream, "testCrossProductFunction.dat" );
+
+		/* Check Cross Product */
+		/* Tested against http://www.engplanet.com/redirect.html?3859 */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check Cross Product Function\n");
+		StGermain_VectorCrossProduct( vector, A, B );
+		StGermain_PrintNamedVector( stream, vector, 3 );
+
+		pcu_filename_expected( "testVectorMathCrossProductFunction.expected", expected_file );
+		pcu_check_fileEq( "testCrossProductFunction.dat", expected_file );
+		remove( "testCrossProductFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestDistancePointsFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"DistancePointsFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		int d;
+
+		Stream_RedirectFile( stream, "testDistancePointsFunction.dat" );
+
+		/* Checking distance between points function */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Checking distance between points Function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) 
+			Journal_Printf( stream, "dim = %d distance = %2.3f\n", d, StGermain_DistanceBetweenPoints( A, B, d ) );
+
+		pcu_filename_expected( "testVectorMathDistancePointsFunction.expected", expected_file );
+		pcu_check_fileEq( "testDistancePointsFunction.dat", expected_file );
+		remove( "testDistancePointsFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestNormalToPlaneFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"NormalToPlaneFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		double vector[6];
+
+		Stream_RedirectFile( stream, "testNormalToPlaneFunction.dat" );
+
+		/* Checking normal to plane function */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Checking normal to plane function function\n");
+		vector[0] = vector[1] = vector[2] = vector[3] = vector[4] = vector[5] = 0.0;
+		StGermain_NormalToPlane( vector, A, B, C );
+		StGermain_PrintNamedVector( stream, vector, 3 );
+
+		pcu_filename_expected( "testVectorMathNormalToPlaneFunction.expected", expected_file );
+		pcu_check_fileEq( "testNormalToPlaneFunction.dat", expected_file );
+		remove( "testNormalToPlaneFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestCentroidFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"CentroidFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		int d;
+		double vector[6];
+
+		Stream_RedirectFile( stream, "testCentroidFunction.dat" );
+
+		/* Checking centroid function */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Checking centroid function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) {
+			vector[0] = vector[1] = vector[2] = vector[3] = vector[4] = vector[5] = 0.0;
+			StGermain_TriangleCentroid( vector, A, B, C, d );
+			StGermain_PrintNamedVector( stream, vector, d );
+		}
+
+		pcu_filename_expected( "testVectorMathCentroidFunction.expected", expected_file );
+		pcu_check_fileEq( "testCentroidFunction.dat", expected_file );
+		remove( "testCentroidFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestTriangleArea( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"TriangleArea" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		int d;
+
+		Stream_RedirectFile( stream, "testTriangleArea.dat" );
+
+		/* Check Triangle Area */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check Triangle Area Function\n");
+		for ( d = 0 ; d <= 6 ; d++ ) 
+			Journal_Printf( stream, "dim = %d Triangle Area = %2.3f\n", d, StGermain_TriangleArea( A, B, C, d ) );
+
+		pcu_filename_expected( "testVectorMathTriangleArea.expected", expected_file );
+		pcu_check_fileEq( "testTriangleArea.dat", expected_file );
+		remove( "testTriangleArea.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestNormalisationFunction( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"NormalisationFunction" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		int d;
+
+		Stream_RedirectFile( stream, "testNormalisationFunction.dat" );
+
+		/* Check Normalisation Function */
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check Normalisation Function\n");
+		d = 2;
+		StGermain_VectorNormalise( A, d );
+		StGermain_PrintNamedVector( stream, A, d);
+		Journal_Printf( stream, "mag = %2.3f\n", StGermain_VectorMagnitude( A, d ) );
+
+		d = 3;
+		StGermain_VectorNormalise( B, d );
+		StGermain_PrintNamedVector( stream, B, d);
+		Journal_Printf( stream, "mag = %2.3f\n", StGermain_VectorMagnitude( B, d ) );
+
+		d = 5;
+		StGermain_VectorNormalise( C, d );
+		StGermain_PrintNamedVector( stream, C, d);
+		Journal_Printf( stream, "mag = %2.3f\n", StGermain_VectorMagnitude( C, d ) );
+
+		pcu_filename_expected( "testVectorMathNormalisationFunction.expected", expected_file );
+		pcu_check_fileEq( "testNormalisationFunction.dat", expected_file );
+		remove( "testNormalisationFunction.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestVectorCrossProductMagnitude( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"VectorCrossProductMagnitude" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+
+		Stream_RedirectFile( stream, "testVectorCrossProducMagnitude.dat" );
+
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check StGermain_VectorCrossProductMagnitude\n");
+		A[0] = 1.0; A[1] = 2.0 ; A[2] = 3.0;
+		B[0] = 4.0; B[1] = 5.0 ; B[2] = 6.0;
+		StGermain_PrintNamedVector( stream, A, 3);
+		StGermain_PrintNamedVector( stream, B, 3);
+		Journal_Printf( stream, "mag = %2.3g (2D)\n", StGermain_VectorCrossProductMagnitude( A, B, 2 ) );
+		Journal_Printf( stream, "mag = %2.3g (3D)\n", StGermain_VectorCrossProductMagnitude( A, B, 3 ) );
+
+		pcu_filename_expected( "testVectorMathCrossProductMagnitude.expected", expected_file );
+		pcu_check_fileEq( "testVectorCrossProducMagnitude.dat", expected_file );
+		remove( "testVectorCrossProducMagnitude.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestConvexQuadrilateralArea( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"ConvexQuadrilateralArea" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		double D[] = {23  , 5  , -14  , 32, -21,    78};
+
+		Stream_RedirectFile( stream, "testConvexQuadrilateralArea.dat" );
+
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check StGermain_ConvexQuadrilateralArea\n");
+		A[0] = 0.0; A[1] = 0.0 ; A[2] = 0.0;
+		B[0] = 0.0; B[1] = 4.0 ; B[2] = 2.3;
+		C[0] = 1.2; C[1] = 4.0 ; C[2] = 2.3;
+		D[0] = 1.2; D[1] = 0.0 ; D[2] = 0.0;
+		Journal_Printf( stream, "area = %2.3g (2D)\n", StGermain_ConvexQuadrilateralArea( A, B, C, D, 2 ) );
+		Journal_Printf( stream, "area = %2.3g (3D)\n", StGermain_ConvexQuadrilateralArea( A, B, C, D, 3 ) );
+
+		pcu_filename_expected( "testVectorMathConvexQuadrilateralArea.expected", expected_file );
+		pcu_check_fileEq( "testConvexQuadrilateralArea.dat", expected_file );
+		remove( "testConvexQuadrilateralArea.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestScalarTripleProduct( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"ScalarTripleProduct" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double **matrix;
+
+		Stream_RedirectFile( stream, "testScalarTripleProduct.dat" );
+
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check StGermain_ScalarTripleProduct \n");
+		matrix = Memory_Alloc_2DArray( double, 3, 3, (Name)"matrix"  );
+		matrix[0][0] = 1.0; matrix[0][1] = 2.0 ; matrix[0][2] = 3.0;
+		matrix[1][0] = 4.0; matrix[1][1] = 5.0 ; matrix[1][2] = 6.0;
+		matrix[2][0] = 7.0; matrix[2][1] = 8.0 ; matrix[2][2] = 11.0;
+		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_ScalarTripleProduct( matrix[0], matrix[1], matrix[2] ));
+		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_ScalarTripleProduct( matrix[2], matrix[0], matrix[1] ));
+		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_ScalarTripleProduct( matrix[1], matrix[2], matrix[0] ));
+		Journal_Printf( stream, "scalar triple product = %2.3g\n", StGermain_MatrixDeterminant( matrix , 3 ));
+		Memory_Free( matrix );
+
+		pcu_filename_expected( "testVectorMathScalarTripleProduct.expected", expected_file );
+		pcu_check_fileEq( "testScalarTripleProduct.dat", expected_file );
+		remove( "testScalarTripleProduct.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestParallelPipedVolume( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"ParallelPipedVolume" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		double D[] = {23  , 5  , -14  , 32, -21,    78};
+
+		Stream_RedirectFile( stream, "testParallelPipedVolume.dat" );
+
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check StGermain_ParallelepipedVolume \n");
+		A[0] = 0.0; A[1] = 0.0 ; A[2] = 0.0;
+		B[0] = 1.1; B[1] = 0.0 ; B[2] = 0.0;
+		C[0] = 0.2; C[1] = 1.7 ; C[2] = 0.0;
+		D[0] = 0.0; D[1] = 0.0 ; D[2] = 1.3;
+		Journal_Printf( stream, "volume = %2.3g\n", StGermain_ParallelepipedVolume( A, B, C, D ));
+
+		pcu_filename_expected( "testVectorMathParallelPipedVolume.expected", expected_file );
+		pcu_check_fileEq( "testParallelPipedVolume.dat", expected_file );
+		remove( "testParallelPipedVolume.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite_TestAverageCoord( VectorMathSuiteData* data ) {
+	int	procToWatch = data->nProcs >=2 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"AverageCoord" );
+	char		expected_file[PCU_PATH_MAX];	
+
+	if (data->rank == procToWatch ) {
+		double A[] = { 7.4, 2  ,   5  ,  1,  3 ,   -42};
+		double B[] = { 4  , 2.3,   5.8,  6, -12, 39289};
+		double C[] = {23  , 5  , -14  , 32, -21,    78};
+		double D[] = {23  , 5  , -14  , 32, -21,    78};
+		double *coordList[4];
+
+		coordList[0] = A;
+		coordList[1] = B;
+		coordList[2] = C;
+		coordList[3] = D;
+
+		Stream_RedirectFile( stream, "testAverageCoord.dat" );
+
+		Journal_Printf( stream, "****************************\n");
+		Journal_Printf( stream, "Check StGermain_AverageCoord \n");
+		A[0] = 1.0;  A[1] = 2.2 ; A[2] = 3.2;
+		B[0] = 41.0; B[1] = 5.0 ; B[2] = 6.9;
+		C[0] = -7.0; C[1] = 8.7 ; C[2] = 11.0;
+
+		StGermain_AverageCoord( D, coordList, 3, 3 );
+		StGermain_PrintNamedVector( stream, D, 3);
+
+		pcu_filename_expected( "testVectorMathAverageCoord.expected", expected_file );
+		pcu_check_fileEq( "testAverageCoord.dat", expected_file );
+		remove( "testAverageCoord.dat" );
+
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void VectorMathSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, VectorMathSuiteData );
+   pcu_suite_setFixtures( suite, VectorMathSuite_Setup, VectorMathSuite_Teardown );
+   pcu_suite_addTest( suite, VectorMathSuite_BasicTest );
+   pcu_suite_addTest( suite, VectorMathSuite_CompleteTest );
+   pcu_suite_addTest( suite, VectorMathSuite_TestVectorFunctions );
+   pcu_suite_addTest( suite, VectorMathSuite_TestMagnitudeFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestDotProductFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestCrossProductFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestDistancePointsFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestNormalToPlaneFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestCentroidFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestTriangleArea );
+   pcu_suite_addTest( suite, VectorMathSuite_TestNormalisationFunction );
+   pcu_suite_addTest( suite, VectorMathSuite_TestVectorCrossProductMagnitude );
+   pcu_suite_addTest( suite, VectorMathSuite_TestConvexQuadrilateralArea );
+   pcu_suite_addTest( suite, VectorMathSuite_TestScalarTripleProduct );
+   pcu_suite_addTest( suite, VectorMathSuite_TestParallelPipedVolume );
+   pcu_suite_addTest( suite, VectorMathSuite_TestAverageCoord );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/CartesianGenerator.c
--- a/Mesh/src/CartesianGenerator.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2487 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: CartesianGenerator.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#ifdef READ_HDF5
-#include <hdf5.h>
-#endif
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Grid.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "IGraph.h"
-#include "Mesh_ElementType.h"
-#include "Mesh_HexType.h"
-#include "MeshClass.h"
-#include "MeshGenerator.h"
-#include "Mesh_Algorithms.h"
-#include "Mesh_RegularAlgorithms.h"
-#include "CartesianGenerator.h"
-
-#define OFFSET_TAG 6
-
-/* Textual name of this class */
-const Type CartesianGenerator_Type = "CartesianGenerator";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-CartesianGenerator* CartesianGenerator_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                                    _sizeOfSelf = sizeof(CartesianGenerator);
-	Type                                                            type = CartesianGenerator_Type;
-	Stg_Class_DeleteFunction*                                    _delete = _CartesianGenerator_Delete;
-	Stg_Class_PrintFunction*                                      _print = _CartesianGenerator_Print;
-	Stg_Class_CopyFunction*                                        _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*        _defaultConstructor = (void* (*)(Name))_CartesianGenerator_New;
-	Stg_Component_ConstructFunction*                          _construct = _CartesianGenerator_AssignFromXML;
-	Stg_Component_BuildFunction*                                  _build = _CartesianGenerator_Build;
-	Stg_Component_InitialiseFunction*                        _initialise = _CartesianGenerator_Initialise;
-	Stg_Component_ExecuteFunction*                              _execute = _CartesianGenerator_Execute;
-	Stg_Component_DestroyFunction*                              _destroy = _CartesianGenerator_Destroy;
-	AllocationType                                    nameAllocationType = NON_GLOBAL;
-	MeshGenerator_SetDimSizeFunc*                         setDimSizeFunc = CartesianGenerator_SetDimSize;
-	MeshGenerator_GenerateFunc*                             generateFunc = CartesianGenerator_Generate;
-	CartesianGenerator_SetTopologyParamsFunc*      setTopologyParamsFunc = _CartesianGenerator_SetTopologyParams;
-	CartesianGenerator_GenElementsFunc*                  genElementsFunc = _CartesianGenerator_GenElements;
-	CartesianGenerator_GenFacesFunc*                        genFacesFunc = _CartesianGenerator_GenFaces;
-	CartesianGenerator_GenEdgesFunc*                        genEdgesFunc = _CartesianGenerator_GenEdges;
-	CartesianGenerator_GenVerticesFunc*                  genVerticesFunc = _CartesianGenerator_GenVertices;
-	CartesianGenerator_GenElementVertexIncFunc*  genElementVertexIncFunc = _CartesianGenerator_GenElementVertexInc;
-	CartesianGenerator_GenVolumeEdgeIncFunc*        genVolumeEdgeIncFunc = _CartesianGenerator_GenVolumeEdgeInc;
-	CartesianGenerator_GenVolumeFaceIncFunc*        genVolumeFaceIncFunc = _CartesianGenerator_GenVolumeFaceInc;
-	CartesianGenerator_GenFaceVertexIncFunc*        genFaceVertexIncFunc = _CartesianGenerator_GenFaceVertexInc;
-	CartesianGenerator_GenFaceEdgeIncFunc*            genFaceEdgeIncFunc = _CartesianGenerator_GenFaceEdgeInc;
-	CartesianGenerator_GenEdgeVertexIncFunc*        genEdgeVertexIncFunc = _CartesianGenerator_GenEdgeVertexInc;
-	CartesianGenerator_GenElementTypesFunc*          genElementTypesFunc = _CartesianGenerator_GenElementTypes;
-
-	CartesianGenerator* self = _CartesianGenerator_New(  CARTESIANGENERATOR_PASSARGS  );
-	/* CartesianGenerator info */
-   _MeshGenerator_Init( (MeshGenerator*)self, context );
-	_CartesianGenerator_Init( self );
-   return self;
-}
-
-CartesianGenerator* _CartesianGenerator_New(  CARTESIANGENERATOR_DEFARGS  ) {
-	CartesianGenerator* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(CartesianGenerator) );
-	self = (CartesianGenerator*)_MeshGenerator_New(  MESHGENERATOR_PASSARGS  );
-
-	/* Virtual info */
-	self->setTopologyParamsFunc = setTopologyParamsFunc;
-	self->genElementsFunc = genElementsFunc;
-	self->genFacesFunc = genFacesFunc;
-	self->genEdgesFunc = genEdgesFunc;
-	self->genVerticesFunc = genVerticesFunc;
-	self->genElementVertexIncFunc = genElementVertexIncFunc;
-	self->genVolumeEdgeIncFunc = genVolumeEdgeIncFunc;
-	self->genVolumeFaceIncFunc = genVolumeFaceIncFunc;
-	self->genFaceVertexIncFunc = genFaceVertexIncFunc;
-	self->genFaceEdgeIncFunc = genFaceEdgeIncFunc;
-	self->genEdgeVertexIncFunc = genEdgeVertexIncFunc;
-	self->genElementTypesFunc = genElementTypesFunc;
-
-
-	return self;
-}
-
-void _CartesianGenerator_Init( CartesianGenerator* self ) {
-	Stream*	stream;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-
-	stream = Journal_Register( Info_Type, (Name)self->type  );
-	Stream_SetPrintingRank( stream, 0 );
-
-	self->comm = NULL;
-	self->regular = True;
-	memset( self->periodic, 0, 3 * sizeof(Bool) );
-	self->maxDecompDims = 0;
-	self->minDecomp = NULL;
-	self->maxDecomp = NULL;
-	self->shadowDepth = 1;
-	self->crdMin = NULL;
-	self->crdMax = NULL;
-
-	self->vertGrid = NULL;
-	self->elGrid = NULL;
-	self->procGrid = NULL;
-	self->origin = NULL;
-	self->range = NULL;
-	self->vertOrigin = NULL;
-	self->vertRange = NULL;
-   
-   /* set load from checkpoint to false by default */
-   self->readFromFile = False;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _CartesianGenerator_Delete( void* meshGenerator ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	/* Delete the parent. */
-	_MeshGenerator_Delete( self );
-}
-
-void _CartesianGenerator_Print( void* meshGenerator, Stream* stream ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	
-	/* Set the Journal for printing informations */
-	Stream* meshGeneratorStream;
-	meshGeneratorStream = Journal_Register( InfoStream_Type, (Name)"CartesianGeneratorStream"  );
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-
-	/* Print parent */
-	Journal_Printf( stream, "CartesianGenerator (ptr): (%p)\n", self );
-	_MeshGenerator_Print( self, stream );
-}
-
-void _CartesianGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
-	CartesianGenerator*		self = (CartesianGenerator*)meshGenerator;
-	Dictionary*					dict;
-	Dictionary_Entry_Value*	tmp;
-	char*							rootKey;
-	Dictionary_Entry_Value*	sizeList;
-	Dictionary_Entry_Value	*minList, *maxList;
-	unsigned						maxDecompDims;
-	unsigned						*minDecomp, *maxDecomp;
-	double						*crdMin, *crdMax;
-	unsigned*					size;
-	unsigned						shadowDepth;
-	Stream*						stream;
-	Stream*						errorStream = Journal_Register( Error_Type, (Name)self->type  );
-	unsigned						d_i;
-	unsigned						restartTimestep;
-   AbstractContext*        context;	
-#ifdef READ_HDF5
-	hid_t file, fileData;
-#endif
-	
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( cf );
-
-   /* get the context which is required for filename determination */
-   context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ) ;
-
-	/* Call parent construct. */
-	_MeshGenerator_AssignFromXML( self, cf, data );
-
-	/* Rip out the components structure as a dictionary. */
-	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
-
-	/* Read the sizes. */
-	sizeList = Dictionary_Get( dict, (Dictionary_Entry_Key)"size" );
-	assert( sizeList );
-	assert( Dictionary_Entry_Value_GetCount( sizeList ) >= self->nDims  );
-	size = Memory_Alloc_Array_Unnamed( unsigned, self->nDims );
-	for( d_i = 0; d_i < self->nDims; d_i++ ) {
-		tmp = Dictionary_Entry_Value_GetElement( sizeList, d_i );
-		rootKey = Dictionary_Entry_Value_AsString( tmp );
-
-		if( !Stg_StringIsNumeric( (char *)rootKey )  )
-			tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
-		size[d_i] = Dictionary_Entry_Value_AsUnsignedInt( tmp  );
-	}
-
-	/* Read decomposition restrictions. */
-	maxDecompDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxDecomposedDims", 0  );
-
-	minList = Dictionary_Get( dict, (Dictionary_Entry_Key)"minDecompositions" );
-	if( minList  ) {
-		minDecomp = AllocArray( unsigned, self->nDims );
-		for( d_i = 0; d_i < self->nDims; d_i++ ) {
-			tmp = Dictionary_Entry_Value_GetElement( minList, d_i );
-			rootKey = Dictionary_Entry_Value_AsString( tmp );
-
-			if( !Stg_StringIsNumeric( (char *)rootKey )  )
-				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
-			minDecomp[d_i] = Dictionary_Entry_Value_AsUnsignedInt( tmp  );
-		}
-	}
-	else
-		minDecomp = NULL;
-
-	maxList = Dictionary_Get( dict, (Dictionary_Entry_Key)"maxDecompositions" );
-	if( maxList  ) {
-		maxDecomp = AllocArray( unsigned, self->nDims );
-		for( d_i = 0; d_i < self->nDims; d_i++ ) {
-			tmp = Dictionary_Entry_Value_GetElement( maxList, d_i );
-			rootKey = Dictionary_Entry_Value_AsString( tmp );
-
-			if( !Stg_StringIsNumeric( (char *)rootKey )  )
-				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
-			maxDecomp[d_i] = Dictionary_Entry_Value_AsUnsignedInt( tmp  );
-		}
-	}
-	else
-		maxDecomp = NULL;
-
-	/* Initial setup. */
-	CartesianGenerator_SetTopologyParams( self, size, maxDecompDims, minDecomp, maxDecomp );
-
-        /* Contact stuff. */
-        self->contactDepth[0][0] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-left", 0  );
-        self->contactDepth[0][1] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-right", 0  );
-        self->contactDepth[1][0] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-bottom", 0  );
-        self->contactDepth[1][1] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-top", 0  );
-        self->contactDepth[2][0] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-back", 0  );
-        self->contactDepth[2][1] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-front", 0  );
-        self->contactGeom[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactGeometry-x", 0.0  );
-        self->contactGeom[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactGeometry-y", 0.0  );
-        self->contactGeom[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactGeometry-z", 0.0  );
-
-	/* Read geometry. */
-	minList = Dictionary_Get( dict, (Dictionary_Entry_Key)"minCoord"  );
-	maxList = Dictionary_Get( dict, (Dictionary_Entry_Key)"maxCoord" );
-	if( minList && maxList ) {
-		assert( Dictionary_Entry_Value_GetCount( minList ) >= self->nDims );
-		assert( Dictionary_Entry_Value_GetCount( maxList ) >= self->nDims  );
-		crdMin = Memory_Alloc_Array_Unnamed( double, 3 );
-		crdMax = Memory_Alloc_Array_Unnamed( double, 3 );
-		for( d_i = 0; d_i < self->nDims; d_i++ ) {
-		   double maxVal;
-			tmp = Dictionary_Entry_Value_GetElement( minList, d_i );
-			rootKey = Dictionary_Entry_Value_AsString( tmp );
-
-			if( !Stg_StringIsNumeric( (char *)rootKey )  )
-				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
-			crdMin[d_i] = Dictionary_Entry_Value_AsDouble( tmp  );
-
-			tmp = Dictionary_Entry_Value_GetElement( maxList, d_i );
-			rootKey = Dictionary_Entry_Value_AsString( tmp );
-
-			if( !Stg_StringIsNumeric( (char *)rootKey )  )
-				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
-			crdMax[d_i] = Dictionary_Entry_Value_AsDouble( tmp );
-			/* test to ensure provided domain is valid */
-			maxVal =  (abs(crdMax[d_i]) > abs(crdMin[d_i])) ? abs(crdMax[d_i]) : abs(crdMin[d_i]);
-			if( maxVal == 0  ) maxVal = 1;  /* if maxVal is zero, then both numbers must be zero, set to one as next test will fail */
-         Journal_Firewall( ( ( (crdMax[d_i] - crdMin[d_i])/maxVal) > 1E-10 || d_i==J_AXIS), errorStream,
-                     "\n\nError in %s for %s '%s'\n\n"
-                     "Dimension of domain (min = %f, max = %f) for component number %u is not valid.\n\n",
-                     __func__, self->type, self->name,
-                     crdMin[d_i], crdMax[d_i], d_i);
-		}
-
-		restartTimestep = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"restartTimestep", 0 );	
-		if( restartTimestep  ) {
-         char*   meshReadFileName;
-         char*   meshReadFileNamePart;
-         self->readFromFile = True;
-#ifdef READ_HDF5
-         hid_t   attrib_id, group_id;
-         herr_t  status;
-
-         meshReadFileNamePart = Context_GetCheckPointReadPrefixString( context );
-
-         /** assumption: that the generator only generates one mesh, or that the information in that mesh's checkpoint
-         file is valid for all meshes being generated TODO: generalise **/
-         Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.h5", meshReadFileNamePart, self->meshes[0]->name, restartTimestep );
-	      
-	      /** Read in minimum coord. */
-	      file = H5Fopen( meshReadFileName, H5F_ACC_RDONLY, H5P_DEFAULT );
-	      
-	      if( !file ) {
-            /** file not found, so don't load from checkpoint */
-            self->readFromFile = False;
-				Journal_Printf( errorStream, 
-					"Warning - Couldn't find checkpoint mesh file with filename \"%s\".\n", 
-					meshReadFileName );
-			}
-			else {
-         int res[self->nDims];
-
-         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-	         fileData = H5Dopen( file, "/min" );
-         #else
-	         fileData = H5Dopen2( file, "/min", H5P_DEFAULT );
-         #endif
-	         H5Dread( fileData, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, crdMin );
-	         H5Dclose( fileData );
-	         
-	         /** Read in maximum coord. */
-         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-	         fileData = H5Dopen( file, "/max" );
-         #else
-	         fileData = H5Dopen2( file, "/max", H5P_DEFAULT );
-         #endif
-	         H5Dread( fileData, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, crdMax );
-	         H5Dclose( fileData );
-
-            /** get the file attributes  */
-         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-            group_id  = H5Gopen(file, "/");
-            attrib_id = H5Aopen_name(group_id, "checkpoint file version");
-         #else
-            group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
-            attrib_id = H5Aopen(group_id, "checkpoint file version", H5P_DEFAULT);
-         #endif
-
-         /** check for correct mesh size */
-      
-         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-            attrib_id = H5Aopen_name(group_id, "mesh resolution");
-         #else
-            attrib_id = H5Aopen(group_id, "mesh resolution", H5P_DEFAULT);
-         #endif
-         status = H5Aread(attrib_id, H5T_NATIVE_INT, &res);
-         H5Aclose(attrib_id);
-   
-         if(self->nDims == 2){
-           if(!((size[0]==(unsigned)(res[0])) && (size[1]==(unsigned)(res[1])))){
-               if (context->interpolateRestart)
-                  self->readFromFile = False;
-               else
-                  Journal_Firewall( 
-                     0, 
-                     errorStream,
-                     "\n\nError in %s for %s '%s'\n"
-                     "Size of mesh (%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u,%u).\n\n"
-                     "If you would like to interpolate checkpoint data to simulation mesh size\n"
-                     "    please re-launch using '--interpolateRestart=1' flag\n\n", 
-                     __func__, self->type, self->name, 
-                     (unsigned int) res[0], (unsigned int) res[1],
-                     meshReadFileName,
-                     (unsigned int) size[0], (unsigned int) size[1]);
-            }
-         } else {
-           if(!((size[0]==(unsigned)(res[0])) && (size[1]==(unsigned)(res[1]))
-                && (size[2]==(unsigned)(res[2])))){
-               if (context->interpolateRestart)
-                  self->readFromFile = False;
-               else
-                  Journal_Firewall( 
-                     0, 
-                     errorStream,
-                     "\n\nError in %s for %s '%s'\n"
-                     "Size of mesh (%u,%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u,%u,%u).\n\n"
-                     "If you would like to interpolate checkpoint data to simulation mesh size\n"
-                     "    please re-launch using '--interpolateRestart=1' flag\n\n", 
-                     __func__, self->type, self->name, 
-                     (unsigned int) res[0], (unsigned int) res[1], (unsigned int) res[2],
-                     meshReadFileName,
-                     (unsigned int) size[0], (unsigned int) size[1], (unsigned int) size[2]);
-               }
-            }
-
-         H5Gclose(group_id);
-         H5Fclose( file );
-
-         }
-
-#else
-         Journal_Firewall(!context->interpolateRestart,  
-                     errorStream,"\n\n Interpolation restart not supported for ASCII checkpoint files \n\n");
-
-         meshReadFileNamePart = Context_GetCheckPointReadPrefixString( context );
-
-         Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.dat", meshReadFileNamePart, self->meshes[0]->name, restartTimestep );
-	        
-			FILE* meshFile = fopen( meshReadFileName, "r" );	
-			/*Journal_Firewall( 
-				meshFile != 0, 
-				errorStream, 
-				"Error in %s - Couldn't find checkpoint mesh file with filename \"%s\" - aborting.\n", 
-				__func__,  
-				meshReadFileName );*/
-
-			if( meshFile == 0 ) {
-            /* file not found, so don't load from checkpoint */
-            self->readFromFile = False;            
-				Journal_Printf( errorStream, 
-					"Warning - Couldn't find checkpoint mesh file with filename \"%s\".\n", 
-					meshReadFileName );
-			}
-			else {
-				/* Read min and max coords from file */
-		      if(self->nDims==2)
-                  fscanf( meshFile, "Min: %lg %lg 0\n", &crdMin[0], &crdMin[1] );
-            else
-                  fscanf( meshFile, "Min: %lg %lg %lg\n", &crdMin[0], &crdMin[1], &crdMin[2] );
-		      if(self->nDims==2)
-                  fscanf( meshFile, "Max: %lg %lg 0\n", &crdMax[0], &crdMax[1] );
-            else
-                  fscanf( meshFile, "Max: %lg %lg %lg\n", &crdMax[0], &crdMax[1], &crdMax[2] );
-            
-				fclose( meshFile );
-			}
-#endif
-				
-			Memory_Free( meshReadFileName );
-			Memory_Free( meshReadFileNamePart );
-
-		}	
-		   
-		/* Initial setup. */
-		CartesianGenerator_SetGeometryParams( self, crdMin, crdMax );
-
-		/* Free coordinate arrays. */
-		FreeArray( crdMin );
-		FreeArray( crdMax );
-	}
-
-	/* Read and set shadow depth. */
-	shadowDepth = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"shadowDepth", 1  );
-	CartesianGenerator_SetShadowDepth( self, shadowDepth );
-
-	/* Read regular flag. */
-	self->regular = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"regular", True  );
-
-	/* Read periodic flags. */
-	self->periodic[0] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"periodic_x", False  );
-	self->periodic[1] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"periodic_y", False  );
-	self->periodic[2] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"periodic_z", False  );
-
-	/* Read a general dictionary flag for which processor to watch. */
-	stream = Journal_Register( Info_Type, (Name)self->type  );
-	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( cf->rootDict, "rankToWatch", 0 ) );
-
-	/* Free stuff. */
-	FreeArray( size );
-	FreeArray( minDecomp );
-	FreeArray( maxDecomp );
-}
-
-void _CartesianGenerator_Build( void* meshGenerator, void* data ) {
-	_MeshGenerator_Build( meshGenerator, data );
-}
-
-void _CartesianGenerator_Initialise( void* meshGenerator, void* data ) {
-}
-
-void _CartesianGenerator_Execute( void* meshGenerator, void* data ) {
-}
-
-void _CartesianGenerator_Destroy( void* meshGenerator, void* data ) {
-   CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-   CartesianGenerator_Destruct( self );
-
-   /* Destroy Parent */
-   _MeshGenerator_Destroy( self, data );
-}
-
-void CartesianGenerator_SetDimSize( void* meshGenerator, unsigned nDims ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-
-	_MeshGenerator_SetDimSize( self, nDims );
-
-	self->minDecomp = MemRearray( self->minDecomp, unsigned, self->nDims, CartesianGenerator_Type );
-	memset( self->minDecomp, 0, nDims * sizeof(unsigned) );
-	self->maxDecomp = MemRearray( self->maxDecomp, unsigned, self->nDims, CartesianGenerator_Type );
-	memset( self->maxDecomp, 0, nDims * sizeof(unsigned) );
-}
-
-void CartesianGenerator_Generate( void* meshGenerator, void* _mesh, void* data ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type );
-	Mesh*			mesh = (Mesh* )_mesh;
-	Grid**			grid;
-	unsigned		*localRange, *localOrigin;
-	Bool			*periodic;
-	
-	/* Sanity check. */
-	assert( self );
-	assert( !self->elGrid || mesh );
-
-	Journal_Printf( stream, "Cartesian generator: '%s'\n", self->name );
-	Stream_Indent( stream );
-
-	/* If we havn't been given anything, don't do anything. */
-	if( self->elGrid ) {
-		unsigned	d_i;
-
-		Journal_Printf( stream, "Target mesh: '%s'\n", mesh->name );
-		Journal_Printf( stream, "Global element size: %d", self->elGrid->sizes[0] );
-		for( d_i = 1; d_i < (unsigned)(self->elGrid->nDims); d_i++ )
-			Journal_Printf( stream, "x%d", self->elGrid->sizes[d_i] );
-		Journal_Printf( stream, "\n" );
-		Journal_Printf( stream, "Local offset of rank %d: %d", stream->_printingRank, self->origin[0] );
-		for( d_i = 1; d_i < (unsigned)(self->elGrid->nDims); d_i++ )
-			Journal_Printf( stream, "x%d", self->origin[d_i] );
-		Journal_Printf( stream, "\n" );
-		Journal_Printf( stream, "Local range of rank %d: %d", stream->_printingRank, self->range[0] );
-		for( d_i = 1; d_i < (unsigned)(self->elGrid->nDims); d_i++ )
-			Journal_Printf( stream, "x%d", self->range[d_i] );
-		Journal_Printf( stream, "\n" );
-
-		/* Fill topological values. */
-		MeshTopology_SetComm( mesh->topo, self->comm );
-		MeshTopology_SetNumDims( mesh->topo, self->elGrid->nDims );
-		CartesianGenerator_GenTopo( self, (IGraph*)mesh->topo );
-
-		/* Fill geometric values. */
-		CartesianGenerator_GenGeom( self, mesh, data );
-
-		/* Fill element types. */
-		CartesianGenerator_GenElementTypes( self, mesh );
-	}
-	else {
-          MeshTopology_SetNumDims( mesh->topo, 0 );
-	}
-
-	/* Add extensions to the mesh and fill with cartesian information. */
-	ExtensionManager_Add( mesh->info, (Name)"vertexGrid", sizeof(Grid*) );
-	grid = (Grid** )ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-	*grid = Grid_New( );
-	Grid_SetNumDims( *grid, self->vertGrid->nDims );
-	Grid_SetSizes( *grid, self->vertGrid->sizes );
-
-	ExtensionManager_Add( mesh->info, (Name)"elementGrid", sizeof(Grid*) );
-	grid = (Grid** )ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" ) );
-	*grid = Grid_New( );
-	Grid_SetNumDims( *grid, self->elGrid->nDims );
-	Grid_SetSizes( *grid, self->elGrid->sizes );
-
-	ExtensionManager_AddArray( mesh->info, "localOrigin", sizeof(unsigned), Mesh_GetDimSize( mesh ) );
-	localOrigin = (unsigned*)ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"localOrigin" )  );
-	memcpy( localOrigin, self->origin, Mesh_GetDimSize( mesh ) * sizeof(unsigned) );
-
-	ExtensionManager_AddArray( mesh->info, "localRange", sizeof(unsigned), Mesh_GetDimSize( mesh ) );
-	localRange = (unsigned*)ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"localRange" )  );
-	memcpy( localRange, self->range, Mesh_GetDimSize( mesh ) * sizeof(unsigned) );
-
-	ExtensionManager_AddArray( mesh->info, "periodic", sizeof(Bool), 3 );
-	periodic = (Bool*)ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"periodic" ) );
-	memcpy( periodic, self->periodic, 3 * sizeof(Bool) );
-
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_SetTopologyParams( void* meshGenerator, unsigned* sizes, unsigned maxDecompDims, unsigned* minDecomp, unsigned* maxDecomp ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	unsigned		d_i;
-
-	/* Sanity check. */
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( !self->nDims || sizes );
-	assert( self->nDims <= 3 );
-
-	/* Kill everything we have, topologically. */
-	CartesianGenerator_DestructTopology( self );
-
-	/* Don't continue if we have nothing. */
-	if( !self->nDims )
-		return;
-
-	/* Set the parameters. */
-	self->elGrid = Grid_New();
-	Grid_SetNumDims( self->elGrid, self->nDims );
-	Grid_SetSizes( self->elGrid, sizes );
-
-	self->vertGrid = Grid_New();
-	Grid_SetNumDims( self->vertGrid, self->nDims );
-	for( d_i = 0; d_i < self->nDims; d_i++ )
-		sizes[d_i]++;
-	Grid_SetSizes( self->vertGrid, sizes );
-	for( d_i = 0; d_i < self->nDims; d_i++ )
-		sizes[d_i]--;
-
-	if( minDecomp )
-		memcpy( self->minDecomp, minDecomp, self->nDims * sizeof(unsigned) );
-	else
-		memset( self->minDecomp, 0, self->nDims * sizeof(unsigned) );
-	if( maxDecomp )
-		memcpy( self->maxDecomp, maxDecomp, self->nDims * sizeof(unsigned) );
-	else
-		memset( self->maxDecomp, 0, self->nDims * sizeof(unsigned) );
-	self->maxDecompDims = maxDecompDims;
-
-	/* As soon as we know the topology, we can decompose. */
-	CartesianGenerator_BuildDecomp( self );
-}
-
-void _CartesianGenerator_GenElements( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	Grid*			grid;
-	unsigned		nEls;
-	unsigned*		els;
-	unsigned*		dimInds;
-	unsigned	d_i, e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-
-	Journal_Printf( stream, "Generating elements...\n" );
-	Stream_Indent( stream );
-
-	grid = Grid_New();
-	Grid_SetNumDims( grid, self->elGrid->nDims );
-	Grid_SetSizes( grid, self->range );
-
-	nEls = grid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ )
-		nEls *= grid->sizes[d_i];
-	els = Memory_Alloc_Array_Unnamed( unsigned, nEls );
-
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
-
-	for( e_i = 0; e_i < nEls; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[e_i] = Grid_Project( self->elGrid, dimInds );
-	}
-
-	IGraph_SetLocalElements( topo, grid->nDims, nEls, (int*)els );
-	FreeArray( els );
-	FreeArray( dimInds );
-	FreeObject( grid );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenVertices( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	unsigned		rank;
-	Grid*			globalGrid;
-	Grid*			grid;
-	unsigned		nEls;
-	unsigned		nLocals, *locals;
-	unsigned		nRemotes/*, *remotes*/;
-	unsigned		*dstArray, *dstCount;
-	unsigned		*dimInds, *rankInds;
-	unsigned	d_i, e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-
-	Journal_Printf( stream, "Generating vertices...\n" );
-	Stream_Indent( stream );
-
-	MPI_Comm_rank( Comm_GetMPIComm( self->comm ), (int*)&rank );
-
-	globalGrid = self->vertGrid;
-
-	grid = Grid_New();
-	Grid_SetNumDims( grid, self->elGrid->nDims );
-	Grid_SetSizes( grid, self->vertRange );
-
-	nEls = grid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ )
-		nEls *= grid->sizes[d_i];
-	locals = Memory_Alloc_Array_Unnamed( unsigned, nEls );
-/*
-	remotes = Memory_Alloc_Array_Unnamed( unsigned, nEls );
-*/
-
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
-	rankInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
-	Grid_Lift( self->procGrid, rank, rankInds );
-
-	nLocals = 0;
-	nRemotes = 0;
-	for( e_i = 0; e_i < nEls; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-/*
-		for( d_i = 0; d_i < grid->nDims; d_i++ ) {
-			if( dimInds[d_i] == 0 && rankInds[d_i] > 0 )
-				break;
-		}
-		if( d_i < grid->nDims ) {
-			dstArray = remotes;
-			dstCount = &nRemotes;
-		}
-		else {
-*/
-			dstArray = locals;
-			dstCount = &nLocals;
-/*
-		}
-*/
-
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->vertOrigin[d_i];
-
-		dstArray[(*dstCount)++] = Grid_Project( globalGrid, dimInds );
-	}
-
-/*
-	MeshTopology_SetLocalElements( topo, 0, nLocals, locals );
-	MeshTopology_SetRemoteElements( topo, 0, nRemotes, remotes );
-*/
-	IGraph_SetElements( topo, 0, nLocals, (int*)locals );
-	FreeArray( locals );
-/*
-	FreeArray( remotes );
-*/
-	FreeArray( dimInds );
-	FreeArray( rankInds );
-	FreeObject( grid );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenEdges( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( self->elGrid->nDims >= 2 );
-	assert( self->elGrid->nDims <= 3 );
-
-	Journal_Printf( stream, "Generating edges...\n" );
-	Stream_Indent( stream );
-
-	if( self->elGrid->nDims == 2 )
-		CartesianGenerator_GenEdges2D( self, topo, grids );
-	else
-		CartesianGenerator_GenEdges3D( self, topo, grids );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenFaces( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	Grid*			globalGrid;
-	unsigned		nGlobalEls[2];
-	Grid*			grid;
-	unsigned		nEls[3];
-	unsigned*		els;
-	unsigned*		dimInds;
-	unsigned		d_i, e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-	assert( self->elGrid->nDims == 3 );
-
-	Journal_Printf( stream, "Generating faces...\n" );
-	Stream_Indent( stream );
-
-	globalGrid = Grid_New();
-	Grid_SetNumDims( globalGrid, self->elGrid->nDims );
-	self->elGrid->sizes[2]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[2]--;
-
-	grid = Grid_New();
-	Grid_SetNumDims( grid, self->elGrid->nDims );
-	self->range[2]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[2]--;
-
-	nEls[0] = grid->sizes[0];
-	nGlobalEls[0] = globalGrid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
-		nEls[0] *= grid->sizes[d_i];
-		nGlobalEls[0] *= globalGrid->sizes[d_i];
-	}
-	els = Memory_Alloc_Array_Unnamed( unsigned, nEls[0] );
-
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
-
-	for( e_i = 0; e_i < nEls[0]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[e_i] = Grid_Project( globalGrid, dimInds );
-	}
-
-	self->elGrid->sizes[1]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[1]--;
-
-	self->range[1]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[1]--;
-
-	nEls[1] = grid->sizes[0];
-	nGlobalEls[1] = globalGrid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
-		nEls[1] *= grid->sizes[d_i];
-		nGlobalEls[1] *= globalGrid->sizes[d_i];
-	}
-	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] );
-
-	for( e_i = 0; e_i < nEls[1]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[nEls[0] + e_i] = nGlobalEls[0] + Grid_Project( globalGrid, dimInds );
-	}
-
-	self->elGrid->sizes[0]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[0]--;
-
-	self->range[0]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[0]--;
-
-	nEls[2] = grid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ )
-		nEls[2] *= grid->sizes[d_i];
-	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] + nEls[2] );
-
-	for( e_i = 0; e_i < nEls[2]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[nEls[0] + nEls[1] + e_i] = nGlobalEls[0] + nGlobalEls[1] + Grid_Project( globalGrid, dimInds );
-	}
-
-	IGraph_SetElements(topo,MT_FACE, nEls[0] + nEls[1] + nEls[2],(int*)els);
-
-	FreeArray( dimInds );
-	FreeArray( els );
-	FreeObject( grid );
-	FreeObject( globalGrid );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenElementVertexInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	int			nDomainEls;
-	unsigned*		incEls;
-	unsigned*		dimInds;
-	unsigned		vertsPerEl;
-	const Sync*		sync;
-	unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-
-	Journal_Printf( stream, "Generating element-vertex incidence...\n" );
-	Stream_Indent( stream );
-
-	vertsPerEl = (topo->nDims == 1) ? 2 : (topo->nDims == 2) ? 4 : 8;
-
-	sync = IGraph_GetDomain( topo, topo->nDims );
-	nDomainEls = Sync_GetNumDomains( sync );
-	incEls = Memory_Alloc_Array_Unnamed( unsigned, vertsPerEl );
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
-	for( e_i = 0; e_i < (unsigned)nDomainEls; e_i++ ) {
-		unsigned	gInd = Sync_DomainToGlobal( sync, e_i );
-		unsigned	curNode = 0;
-
-		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
-
-		incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-
-		dimInds[0]++;
-		incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-		dimInds[0]--;
-
-		if( topo->nDims >= 2 ) {
-			dimInds[1]++;
-			incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[0]++;
-			incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-			dimInds[0]--;
-			dimInds[1]--;
-
-			if( topo->nDims >= 3 ) {
-				dimInds[2]++;
-				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-
-				dimInds[0]++;
-				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-				dimInds[0]--;
-
-				dimInds[1]++;
-				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-
-				dimInds[0]++;
-				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
-				dimInds[0]--;
-				dimInds[1]--;
-				dimInds[2]--;
-			}
-		}
-
-		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 0 ), 
-						vertsPerEl, incEls );
-		IGraph_SetIncidence( topo, topo->nDims, e_i, MT_VERTEX,
-                                     vertsPerEl, (int*)incEls );
-	}
-
-	FreeArray( incEls );
-	FreeArray( dimInds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenVolumeEdgeInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	unsigned		nIncEls;
-	unsigned*		incEls;
-	unsigned*		dimInds;
-	unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-	assert( topo->nDims >= 3 );
-
-	Journal_Printf( stream, "Generating volume-edge incidence...\n" );
-	Stream_Indent( stream );
-
-	incEls = Memory_Alloc_Array_Unnamed( unsigned, 12 );
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
-	for( e_i = 0; e_i < (unsigned)(topo->remotes[3]->nDomains); e_i++ ) {
-		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[3], e_i );
-
-		nIncEls = 12;
-		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
-
-		incEls[0] = Grid_Project( grids[1][0], dimInds );
-
-		dimInds[1]++;
-		incEls[1] = Grid_Project( grids[1][0], dimInds );
-		dimInds[1]--;
-
-		incEls[2] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-
-		dimInds[0]++;
-		incEls[3] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-		dimInds[0]--;
-
-		dimInds[2]++;
-		incEls[4] = Grid_Project( grids[1][0], dimInds );
-
-		dimInds[1]++;
-		incEls[5] = Grid_Project( grids[1][0], dimInds );
-		dimInds[1]--;
-
-		incEls[6] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-
-		dimInds[0]++;
-		incEls[7] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-		dimInds[0]--;
-		dimInds[2]--;
-
-		incEls[8] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-
-		dimInds[0]++;
-		incEls[9] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-		dimInds[0]--;
-
-		dimInds[1]++;
-		incEls[10] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-
-		dimInds[0]++;
-		incEls[11] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-		dimInds[0]--;
-		dimInds[1]--;
-
-		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 1 ), 
-						nIncEls, incEls );
-		IGraph_SetIncidence(topo,topo->nDims,e_i,1,nIncEls,(int*)incEls);
-	}
-
-	FreeArray( incEls );
-	FreeArray( dimInds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenVolumeFaceInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	unsigned		nIncEls;
-	unsigned*		incEls;
-	unsigned*		dimInds;
-	unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-	assert( topo->nDims >= 3 );
-
-	Journal_Printf( stream, "Generating volume-face incidence...\n" );
-	Stream_Indent( stream );
-
-	incEls = Memory_Alloc_Array_Unnamed( unsigned, 6 );
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
-	for(e_i=0;e_i<(unsigned)(topo->remotes[MT_VOLUME]->nDomains);e_i++) {
-		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[MT_VOLUME], e_i );
-
-		nIncEls = 6;
-		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
-
-		incEls[0] = Grid_Project( grids[2][0], dimInds );
-
-		dimInds[2]++;
-		incEls[1] = Grid_Project( grids[2][0], dimInds );
-		dimInds[2]--;
-
-		incEls[2] = Grid_Project( grids[2][1], dimInds ) + grids[2][0]->nPoints;
-
-		dimInds[1]++;
-		incEls[3] = Grid_Project( grids[2][1], dimInds ) + grids[2][0]->nPoints;
-		dimInds[1]--;
-
-		incEls[4] = Grid_Project( grids[2][2], dimInds ) + grids[2][0]->nPoints + grids[2][1]->nPoints;
-
-		dimInds[0]++;
-		incEls[5] = Grid_Project( grids[2][2], dimInds ) + grids[2][0]->nPoints + grids[2][1]->nPoints;
-		dimInds[0]--;
-
-		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 2 ), 
-						nIncEls, incEls );
-		IGraph_SetIncidence(topo,topo->nDims,e_i,2,nIncEls,(int*)incEls);
-	}
-
-	FreeArray( incEls );
-	FreeArray( dimInds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenFaceVertexInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	unsigned		nIncEls;
-	unsigned*		incEls;
-	unsigned*		dimInds;
-	unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-	assert( topo->nDims >= 2 );
-
-	Journal_Printf( stream, "Generating face-vertex incidence...\n" );
-	Stream_Indent( stream );
-
-	incEls = Memory_Alloc_Array_Unnamed( unsigned, 4 );
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
-	for(e_i=0;e_i<(unsigned)(topo->remotes[MT_FACE]->nDomains);e_i++) {
-		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[MT_FACE], e_i );
-
-		nIncEls = 4;
-
-		if( gInd < grids[2][0]->nPoints ) {
-			Grid_Lift( grids[2][0], gInd, dimInds );
-
-			incEls[0] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[0]++;
-			incEls[1] = Grid_Project( grids[0][0], dimInds );
-			dimInds[0]--;
-
-			dimInds[1]++;
-			incEls[2] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[0]++;
-			incEls[3] = Grid_Project( grids[0][0], dimInds );
-			dimInds[0]--;
-			dimInds[1]--;
-		}
-		else if( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints ) {
-			assert( topo->nDims >= 3 );
-
-			Grid_Lift( grids[2][1], gInd - grids[2][0]->nPoints, dimInds );
-
-			incEls[0] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[0]++;
-			incEls[1] = Grid_Project( grids[0][0], dimInds );
-			dimInds[0]--;
-
-			dimInds[2]++;
-			incEls[2] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[0]++;
-			incEls[3] = Grid_Project( grids[0][0], dimInds );
-			dimInds[0]--;
-			dimInds[2]--;
-		}
-		else {
-			assert( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints + grids[2][2]->nPoints );
-			assert( topo->nDims >= 3 );
-
-			Grid_Lift( grids[2][2], gInd - grids[2][0]->nPoints - grids[2][1]->nPoints, dimInds );
-
-			incEls[0] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[1]++;
-			incEls[1] = Grid_Project( grids[0][0], dimInds );
-			dimInds[1]--;
-
-			dimInds[2]++;
-			incEls[2] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[1]++;
-			incEls[3] = Grid_Project( grids[0][0], dimInds );
-			dimInds[1]--;
-			dimInds[2]--;
-		}
-
-		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 0 ), 
-						nIncEls, incEls );
-		IGraph_SetIncidence( topo, 2, e_i, 0, nIncEls, (int*)incEls );
-	}
-
-	FreeArray( incEls );
-	FreeArray( dimInds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenFaceEdgeInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-	unsigned		nIncEls;
-	unsigned*		incEls;
-	unsigned*		dimInds;
-	unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-	assert( topo->nDims >= 2 );
-
-	Journal_Printf( stream, "Generating face-edge incidence...\n" );
-	Stream_Indent( stream );
-
-	incEls = Memory_Alloc_Array_Unnamed( unsigned, 4 );
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
-	for( e_i = 0; e_i < (unsigned)(topo->remotes[MT_FACE]->nDomains);e_i++ ) {
-		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[MT_FACE], e_i );
-
-		nIncEls = 4;
-
-		if( gInd < grids[2][0]->nPoints ) {
-			Grid_Lift( grids[2][0], gInd, dimInds );
-
-			incEls[0] = Grid_Project( grids[1][0], dimInds );
-
-			dimInds[1]++;
-			incEls[1] = Grid_Project( grids[1][0], dimInds );
-			dimInds[1]--;
-
-			incEls[2] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-
-			dimInds[0]++;
-			incEls[3] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-			dimInds[0]--;
-		}
-		else if( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints ) {
-			assert( topo->nDims >= 3 );
-
-			Grid_Lift( grids[2][1], gInd - grids[2][0]->nPoints, dimInds );
-
-			incEls[0] = Grid_Project( grids[1][0], dimInds );
-
-			dimInds[2]++;
-			incEls[1] = Grid_Project( grids[1][0], dimInds );
-			dimInds[2]--;
-
-			incEls[2] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-
-			dimInds[0]++;
-			incEls[3] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-			dimInds[0]--;
-		}
-		else {
-			assert( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints + grids[2][2]->nPoints );
-			assert( topo->nDims >= 3 );
-
-			Grid_Lift( grids[2][2], gInd - grids[2][0]->nPoints - grids[2][1]->nPoints, dimInds );
-
-			incEls[0] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-
-			dimInds[2]++;
-			incEls[1] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
-			dimInds[2]--;
-
-			incEls[2] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-
-			dimInds[1]++;
-			incEls[3] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
-			dimInds[1]--;
-		}
-
-		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 1 ), 
-						nIncEls, incEls );
-		IGraph_SetIncidence( topo, 2, e_i, 1, nIncEls, (int*)incEls );
-	}
-
-	FreeArray( incEls );
-	FreeArray( dimInds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenEdgeVertexInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
-   CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-   Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
-   unsigned		nIncEls;
-   unsigned*		incEls;
-   unsigned*		dimInds;
-   const Sync* sync;
-   unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-	assert( topo );
-	assert( grids );
-
-	Journal_Printf( stream, "Generating edge-vertex incidence...\n" );
-	Stream_Indent( stream );
-
-	sync = IGraph_GetDomain( topo, 1 );
-	incEls = MemArray( unsigned, 2, CartesianGenerator_Type );
-	dimInds = MemArray( unsigned, topo->nDims, CartesianGenerator_Type );
-	for( e_i = 0; e_i < (unsigned)Sync_GetNumDomains( sync ); e_i++ ) {
-		unsigned	gInd = Sync_DomainToGlobal( sync, e_i );
-
-		nIncEls = 2;
-
-		if( gInd < grids[1][0]->nPoints ) {
-			Grid_Lift( grids[1][0], gInd, dimInds );
-
-			incEls[0] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[0]++;
-			incEls[1] = Grid_Project( grids[0][0], dimInds );
-			dimInds[0]--;
-		}
-		else if( gInd < grids[1][0]->nPoints + grids[1][1]->nPoints ) {
-			assert( topo->nDims >= 2 );
-
-			Grid_Lift( grids[1][1], gInd - grids[1][0]->nPoints, dimInds );
-
-			incEls[0] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[1]++;
-			incEls[1] = Grid_Project( grids[0][0], dimInds );
-			dimInds[1]--;
-		}
-		else {
-			assert( gInd < grids[1][0]->nPoints + grids[1][1]->nPoints + grids[1][2]->nPoints );
-			assert( topo->nDims >= 3 );
-
-			Grid_Lift( grids[1][2], gInd - grids[1][0]->nPoints - grids[1][1]->nPoints, dimInds );
-
-			incEls[0] = Grid_Project( grids[0][0], dimInds );
-
-			dimInds[2]++;
-			incEls[1] = Grid_Project( grids[0][0], dimInds );
-			dimInds[2]--;
-		}
-
-		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 0 ), 
-						nIncEls, incEls );
-		IGraph_SetIncidence( topo, MT_EDGE, e_i, MT_VERTEX, nIncEls,
-                                     (int*)incEls );
-	}
-
-	FreeArray( incEls );
-	FreeArray( dimInds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void _CartesianGenerator_GenElementTypes( void* meshGenerator, Mesh* mesh ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-	Stream*			stream;
-	unsigned		nDomainEls;
-	unsigned		e_i;
-
-	assert( self && Stg_CheckType( self, CartesianGenerator ) );
-
-	stream = Journal_Register( Info_Type, (Name)self->type  );
-	Journal_Printf( stream, "Generating element types...\n" );
-	Stream_Indent( stream );
-
-	mesh->nElTypes = 1;
-	mesh->elTypes = Memory_Alloc_Array( Mesh_ElementType*, mesh->nElTypes, "Mesh::elTypes" );
-	mesh->elTypes[0] = (Mesh_ElementType*)Mesh_HexType_New();
-	Mesh_ElementType_SetMesh( mesh->elTypes[0], mesh );
-	nDomainEls = Mesh_GetDomainSize(mesh,Mesh_GetDimSize(mesh));
-	mesh->elTypeMap = Memory_Alloc_Array( unsigned, nDomainEls, "Mesh::elTypeMap" );
-	for( e_i = 0; e_i < nDomainEls; e_i++ )
-		mesh->elTypeMap[e_i] = 0;
-
-	if( self->regular )
-		Mesh_SetAlgorithms( mesh, Mesh_RegularAlgorithms_New( "", NULL ) );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... element types are '%s',\n", mesh->elTypes[0]->type );
-	Journal_Printf( stream, "... mesh algorithm type is '%s',\n", mesh->algorithms->type );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void CartesianGenerator_SetGeometryParams( void* meshGenerator, double* min, double* max ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-
-	/* Sanity check. */
-	assert( self );
-	assert( !self->elGrid->nDims || (min && max) );
-
-	/* Kill everything we have, geometrically. */
-	KillArray( self->crdMin );
-	KillArray( self->crdMax );
-
-	/* Set the parameters. */
-	if( self->elGrid->nDims ) {
-		self->crdMin = Memory_Alloc_Array( double, self->elGrid->nDims, "CartesianGenerator::min" );
-		self->crdMax = Memory_Alloc_Array( double, self->elGrid->nDims, "CartesianGenerator::max" );
-		memcpy( self->crdMin, min, self->elGrid->nDims * sizeof(double) );
-		memcpy( self->crdMax, max, self->elGrid->nDims * sizeof(double) );
-	}
-}
-
-void CartesianGenerator_SetShadowDepth( void* meshGenerator, unsigned depth ) {
-	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
-
-	/* Sanity check. */
-	assert( self );
-
-	self->shadowDepth = depth;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-void CartesianGenerator_BuildDecomp( CartesianGenerator* self ) {
-	unsigned	nProcs, rank;
-	unsigned	nPos = 0;
-	unsigned**	posNSubDomains = NULL;
-	unsigned*	tmpSubDomains;
-	double		bestRatio;
-	unsigned	bestPos;
-	unsigned	*myRankInds, *rankInds;
-	unsigned	nNbrs, *nbrs;
-	unsigned	p_i, d_i, r_i;
-
-	/* Sanity check. */
-	assert( self );
-
-	/* Collect information regarding parallel configuration. */
-	MPI_Comm_size( self->mpiComm, (int*)&nProcs );
-	MPI_Comm_rank( self->mpiComm, (int*)&rank );
-
-	/* Allocate for possible sub-domains. */
-	tmpSubDomains = Memory_Alloc_Array( unsigned, self->elGrid->nDims, "" );
-
-	/* Build a list of all acceptable decompositions. */
-	CartesianGenerator_RecurseDecomps( self, 0, nProcs, 
-					   tmpSubDomains, &nPos, &posNSubDomains );
-	assert( nPos );
-
-	/* Free unneeded memory. */
-	FreeArray( tmpSubDomains );
-
-	/* Now check for the best ratio. */
-	bestRatio = HUGE_VAL;
-	bestPos = -1;
-	for( p_i = 0; p_i < nPos; p_i++ ) {
-		double		curRatio = 0.0;
-		unsigned	decompDims = 0;
-
-		/* If decomposed in more dimensions than allowed, skip. */
-		for( d_i = 0; d_i < self->elGrid->nDims; d_i++ )
-			decompDims += (posNSubDomains[p_i][d_i] > 1) ? 1 : 0;
-		if( self->maxDecompDims && decompDims > self->maxDecompDims )
-			continue;
-
-		/* Evaluate ratios. */
-		for( d_i = 0; d_i < self->elGrid->nDims; d_i++ ) {
-			double		nI = (double)self->elGrid->sizes[d_i] / (double)posNSubDomains[p_i][d_i];
-			unsigned	d_j;
-
-			for( d_j = d_i + 1; d_j < self->elGrid->nDims; d_j++ ) {
-				double	nJ = (double)self->elGrid->sizes[d_j] / (double)posNSubDomains[p_i][d_j];
-
-				curRatio += (nI > nJ) ? nI / nJ : nJ / nI;
-			}
-		}
-
-		/* Better than best? */
-		if( curRatio < bestRatio ) {
-			bestRatio = curRatio;
-			bestPos = p_i;
-		}
-	}
-	assert( bestPos != (unsigned)(-1) );
-
-	/* Allocate for results. */
-	self->origin = Memory_Alloc_Array( unsigned, self->elGrid->nDims, "CartesianGenerator::origin" );
-	self->range = Memory_Alloc_Array( unsigned, self->elGrid->nDims, "CartesianGenerator::range" );
-
-	/* Build a sub-domain grid. */
-	self->procGrid = Grid_New();
-	Grid_SetNumDims( self->procGrid, self->elGrid->nDims );
-	Grid_SetSizes( self->procGrid, posNSubDomains[bestPos] );
-
-	/* Free unneeded space. */
-	FreeArray( posNSubDomains );
-
-	/* Lift the rank to a parameterised offset. */
-	Grid_Lift( self->procGrid, rank, self->origin );
-	for( d_i = 0; d_i < self->elGrid->nDims; d_i++ ) {
-		unsigned	base = self->elGrid->sizes[d_i] / self->procGrid->sizes[d_i];
-		unsigned	mod = self->elGrid->sizes[d_i] % self->procGrid->sizes[d_i];
-		unsigned	origin = self->origin[d_i];
-
-		self->origin[d_i] *= base;
-		self->range[d_i] = base;
-		if( origin < mod ) {
-			self->origin[d_i] += origin;
-			self->range[d_i]++;
-		}
-		else
-			self->origin[d_i] += mod;
-	}
-
-	/* Copy to the vertex equivalents. */
-	self->vertOrigin = AllocArray( unsigned, self->elGrid->nDims );
-	self->vertRange = AllocArray( unsigned, self->elGrid->nDims );
-	for( d_i = 0; d_i < self->elGrid->nDims; d_i++ ) {
-		self->vertOrigin[d_i] = self->origin[d_i];
-		self->vertRange[d_i] = self->range[d_i] + 1;
-	}
-
-	/* Build the comm topology. */
-	myRankInds = AllocArray( unsigned, Grid_GetNumDims( self->procGrid ) );
-	rankInds = AllocArray( unsigned, Grid_GetNumDims( self->procGrid ) );
-	Grid_Lift( self->procGrid, rank, myRankInds );
-	nNbrs = 0;
-	nbrs = NULL;
-	for( r_i = 0; r_i < Grid_GetNumPoints( self->procGrid ); r_i++ ) {
-		if( r_i == rank )
-			continue;
-
-		Grid_Lift( self->procGrid, r_i, rankInds );
-		for( d_i = 0; d_i < Grid_GetNumDims( self->procGrid ); d_i++ ) {
-			if( (myRankInds[d_i] > 0 && rankInds[d_i] < myRankInds[d_i] - 1) || 
-			    (myRankInds[d_i] < self->procGrid->sizes[d_i] - 1 && rankInds[d_i] > myRankInds[d_i] + 1) )
-			{
-				break;
-			}
-		}
-		if( d_i == Grid_GetNumDims( self->procGrid ) ) {
-			nbrs = ReallocArray( nbrs, unsigned, nNbrs + 1 );
-			nbrs[nNbrs++] = r_i;
-		}
-	}
-
-	FreeArray( myRankInds );
-	FreeArray( rankInds );
-
-	NewClass_RemoveRef( self->comm );
-	self->comm = Comm_New();
-	NewClass_AddRef( self->comm );
-	Comm_SetMPIComm( self->comm, self->mpiComm );
-	Comm_SetNeighbours( self->comm, nNbrs, (int*)nbrs );
-	FreeArray( nbrs );
-}
-
-void CartesianGenerator_RecurseDecomps( CartesianGenerator* self, 
-					unsigned dim, unsigned max, 
-					unsigned* nSubDomains, 
-					unsigned* nPos, unsigned*** posNSubDomains )
-{
-	unsigned	nProcs;
-	unsigned	nSDs = 1;
-	unsigned	d_i;
-
-	MPI_Comm_size( self->mpiComm, (int*)&nProcs );
-
-	/* If we're over the limit, return immediately. */
-	for( d_i = 0; d_i < dim; d_i++ )
-		nSDs *= nSubDomains[d_i];
-	if( nSDs > nProcs )
-		return;
-
-	/* Where are we up to? */
-	if( dim == self->elGrid->nDims ) {
-		/* If this covers all processors, store it. */
-		if( nSDs == nProcs ) {
-			/* If we havn't already allocated do it now. */
-			if( !*posNSubDomains ) {
-				*nPos = 1;
-				*posNSubDomains = Memory_Alloc_2DArray_Unnamed( unsigned, 2, self->elGrid->nDims );
-			}
-			else {
-				/* Reallocate the arrays. */
-				(*nPos)++;
-				if( *nPos != 2 ) {
-					*posNSubDomains = Memory_Realloc_2DArray( *posNSubDomains, unsigned, 
-										  *nPos, self->elGrid->nDims );
-				}
-			}
-
-			/* Store status. */
-			memcpy( (*posNSubDomains)[(*nPos) - 1], nSubDomains, self->elGrid->nDims * sizeof(unsigned) );
-		}
-	}
-	else {
-		unsigned	p_i;
-
-		/* Loop over all remaining */
-		for( p_i = 0; p_i < max; p_i++ ) {
-			/* Don't try and decompose more than this dimension allows. */
-			if( p_i >= self->elGrid->sizes[dim] || 
-			    (self->maxDecomp[dim] && p_i >= self->maxDecomp[dim]) )
-			{
-				break;
-			}
-
-			/* If we have a minimum decomp, skip until we reach it. */
-			if( self->minDecomp[dim] && p_i < self->minDecomp[dim] - 1 )
-				continue;
-
-			/* Set the number of sub-domains. */
-			nSubDomains[dim] = p_i + 1;
-
-			/* Try this combination. */
-			CartesianGenerator_RecurseDecomps( self, dim + 1, max - nSDs + 1, nSubDomains, 
-							   nPos, posNSubDomains );
-		}
-	}
-}
-
-void CartesianGenerator_GenTopo( CartesianGenerator* self, IGraph* topo ) {
-	Grid***		grids;
-	const Comm* comm;
-	int	d_i, d_j;
-
-	assert( self );
-	assert( topo );
-
-	MeshTopology_SetNumDims( topo, self->elGrid->nDims );
-
-	/* Build additional grids for use in numbering. */
-	grids = Memory_Alloc_2DArray_Unnamed( Grid*, topo->nTDims, topo->nTDims );
-	for( d_i = 0; d_i < topo->nTDims; d_i++ )
-		memset( grids[d_i], 0, topo->nTDims * sizeof(Grid*) );
-
-	grids[topo->nDims][0] = self->elGrid;
-	grids[0][0] = self->vertGrid;
-
-	if( topo->nDims >= 2 ) {
-		grids[1][0] = Grid_New();
-		Grid_SetNumDims( grids[1][0], topo->nDims );
-		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-			if( d_i == 0 ) continue;
-			grids[topo->nDims][0]->sizes[d_i]++;
-		}
-		Grid_SetSizes( grids[1][0], grids[topo->nDims][0]->sizes );
-		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-			if( d_i == 0 ) continue;
-			grids[topo->nDims][0]->sizes[d_i]--;
-		}
-
-		grids[1][1] = Grid_New();
-		Grid_SetNumDims( grids[1][1], topo->nDims );
-		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-			if( d_i == 1 ) continue;
-			grids[topo->nDims][0]->sizes[d_i]++;
-		}
-		Grid_SetSizes( grids[1][1], grids[topo->nDims][0]->sizes );
-		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-			if( d_i == 1 ) continue;
-			grids[topo->nDims][0]->sizes[d_i]--;
-		}
-
-		if( topo->nDims >= 3 ) {
-			grids[1][2] = Grid_New();
-			Grid_SetNumDims( grids[1][2], topo->nDims );
-			for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-				if( d_i == 2 ) continue;
-				grids[topo->nDims][0]->sizes[d_i]++;
-			}
-			Grid_SetSizes( grids[1][2], grids[topo->nDims][0]->sizes );
-			for( d_i = 0; d_i < topo->nDims; d_i++ ) {
-				if( d_i == 2 ) continue;
-				grids[topo->nDims][0]->sizes[d_i]--;
-			}
-
-			grids[2][0] = Grid_New();
-			Grid_SetNumDims( grids[2][0], topo->nDims );
-			grids[topo->nDims][0]->sizes[2]++;
-			Grid_SetSizes( grids[2][0], grids[topo->nDims][0]->sizes );
-			grids[topo->nDims][0]->sizes[2]--;
-
-			grids[2][1] = Grid_New();
-			Grid_SetNumDims( grids[2][1], topo->nDims );
-			grids[topo->nDims][0]->sizes[1]++;
-			Grid_SetSizes( grids[2][1], grids[topo->nDims][0]->sizes );
-			grids[topo->nDims][0]->sizes[1]--;
-
-			grids[2][2] = Grid_New();
-			Grid_SetNumDims( grids[2][2], topo->nDims );
-			grids[topo->nDims][0]->sizes[0]++;
-			Grid_SetSizes( grids[2][2], grids[topo->nDims][0]->sizes );
-			grids[topo->nDims][0]->sizes[0]--;
-		}
-	}
-
-	/* Generate topological elements. */
-	if( self->enabledDims[0] )
-		CartesianGenerator_GenVertices( self, topo, grids );
-	if( self->enabledDims[self->nDims] )
-		CartesianGenerator_GenElements( self, topo, grids );
-	if( topo->nDims >= 2 ) {
-		if( self->enabledDims[1] )
-			CartesianGenerator_GenEdges( self, topo, grids );
-		if( topo->nDims >= 3 ) {
-			if( self->enabledDims[2] )
-				CartesianGenerator_GenFaces( self, topo, grids );
-		}
-	}
-
-	/* Generate topological incidence. */
-	if( self->enabledInc[self->nDims][0] )
-		CartesianGenerator_GenElementVertexInc( self, topo, grids );
-	if( topo->nDims >= 2 ) {
-		if( self->enabledInc[2][1] )
-			CartesianGenerator_GenFaceEdgeInc( self, topo, grids );
-		if( self->enabledInc[1][0] )
-			CartesianGenerator_GenEdgeVertexInc( self, topo, grids );
-		if( topo->nDims >= 3 ) {
-			if( self->enabledInc[2][0] )
-				CartesianGenerator_GenFaceVertexInc( self, topo, grids );
-			if( self->enabledInc[3][1] )
-				CartesianGenerator_GenVolumeEdgeInc( self, topo, grids );
-			if( self->enabledInc[3][2] )
-				CartesianGenerator_GenVolumeFaceInc( self, topo, grids );
-		}
-	}
-
-	/* Set the shadow depth and correct incidence. */
-	comm = MeshTopology_GetComm( topo );
-	if( self->shadowDepth && Comm_GetNumNeighbours( comm ) > 0 ) {
-		/* Build enough incidence to set shadow depth. */
-		IGraph_InvertIncidence( topo, MT_VERTEX, topo->nDims );
-		IGraph_ExpandIncidence( topo, topo->nDims );
-
-		/* Set the shadow depth. */
-		MeshTopology_SetShadowDepth( topo, self->shadowDepth );
-
-		/* Kill up relations and neighbours. */
-		IGraph_RemoveIncidence( topo, topo->nDims, topo->nDims );
-		IGraph_RemoveIncidence( topo, 0, topo->nDims );
-	}
-
-	/* Complete all required relations. */
-	for( d_i = 0; d_i < (int)(self->nDims); d_i++ ) {
-          for( d_j = d_i + 1; d_j <= (int)(self->nDims); d_j++ ) {
-            if( !self->enabledInc[d_i][d_j] )
-              continue;
-
-            IGraph_InvertIncidence( topo, d_i, d_j );
-          }
-	}
-	for( d_i = 0; d_i <= (int)(self->nDims); d_i++ ) {
-		if( self->enabledInc[d_i][d_i] ) {
-			if( d_i == 0 )
-				CartesianGenerator_CompleteVertexNeighbours( self, topo, grids );
-			else {
-				IGraph_ExpandIncidence( topo, d_i );
-			}
-		}
-	}
-
-	/* Generate any boundary elements required. */
-	CartesianGenerator_GenBndVerts( self, topo, grids );
-
-	/* Free allocated grids. */
-	grids[topo->nDims][0] = NULL;
-	for( d_i = 1; d_i < topo->nDims; d_i++ ) {
-		int	d_j;
-
-		for( d_j = 0; d_j < (topo->nTDims); d_j++ )
-			FreeObject( grids[d_i][d_j] );
-	}
-	FreeArray( grids );
-}
-
-void CartesianGenerator_GenEdges2D( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
-	Grid*		globalGrid;
-	unsigned	nGlobalEls;
-	Grid*		grid;
-	unsigned	nEls[2];
-	unsigned*	els;
-	unsigned*	dimInds;
-	unsigned	d_i, e_i;
-
-	assert( self );
-	assert( topo );
-	assert( grids );
-	assert( self->elGrid->nDims == 2 );
-
-	globalGrid = Grid_New();
-	Grid_SetNumDims( globalGrid, self->elGrid->nDims );
-	self->elGrid->sizes[1]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[1]--;
-
-	grid = Grid_New();
-	Grid_SetNumDims( grid, self->elGrid->nDims );
-	self->range[1]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[1]--;
-
-	nEls[0] = grid->sizes[0];
-	nGlobalEls = globalGrid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
-		nEls[0] *= grid->sizes[d_i];
-		nGlobalEls *= globalGrid->sizes[d_i];
-	}
-	els = Memory_Alloc_Array_Unnamed( unsigned, nEls[0] );
-
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
-
-	for( e_i = 0; e_i < nEls[0]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[e_i] = Grid_Project( globalGrid, dimInds );
-	}
-
-	self->elGrid->sizes[0]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[0]--;
-
-	self->range[0]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[0]--;
-
-	nEls[1] = grid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ )
-		nEls[1] *= grid->sizes[d_i];
-	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] );
-
-	for( e_i = 0; e_i < nEls[1]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[nEls[0] + e_i] = nGlobalEls + Grid_Project( globalGrid, dimInds );
-	}
-
-	IGraph_SetElements( topo, MT_EDGE, nEls[0] + nEls[1], (int*)els );
-
-	FreeArray( dimInds );
-	FreeArray( els );
-	FreeObject( grid );
-	FreeObject( globalGrid );
-}
-
-void CartesianGenerator_GenEdges3D( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
-	Grid*		globalGrid;
-	unsigned	nGlobalEls[2];
-	Grid*		grid;
-	unsigned	nEls[3];
-	unsigned*	els;
-	unsigned*	dimInds;
-	unsigned	d_i, e_i;
-
-	assert( self );
-	assert( topo );
-	assert( grids );
-	assert( self->elGrid->nDims == 3 );
-
-	globalGrid = Grid_New();
-	Grid_SetNumDims( globalGrid, self->elGrid->nDims );
-	self->elGrid->sizes[1]++;
-	self->elGrid->sizes[2]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[1]--;
-	self->elGrid->sizes[2]--;
-
-	grid = Grid_New();
-	Grid_SetNumDims( grid, self->elGrid->nDims );
-	self->range[1]++;
-	self->range[2]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[1]--;
-	self->range[2]--;
-
-	nEls[0] = grid->sizes[0];
-	nGlobalEls[0] = globalGrid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
-		nEls[0] *= grid->sizes[d_i];
-		nGlobalEls[0] *= globalGrid->sizes[d_i];
-	}
-	els = Memory_Alloc_Array_Unnamed( unsigned, nEls[0] );
-
-	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
-
-	for( e_i = 0; e_i < nEls[0]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[e_i] = Grid_Project( globalGrid, dimInds );
-	}
-
-	self->elGrid->sizes[0]++;
-	self->elGrid->sizes[2]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[0]--;
-	self->elGrid->sizes[2]--;
-
-	self->range[0]++;
-	self->range[2]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[0]--;
-	self->range[2]--;
-
-	nEls[1] = grid->sizes[0];
-	nGlobalEls[1] = globalGrid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
-		nEls[1] *= grid->sizes[d_i];
-		nGlobalEls[1] *= globalGrid->sizes[d_i];
-	}
-	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] );
-
-	for( e_i = 0; e_i < nEls[1]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[nEls[0] + e_i] = nGlobalEls[0] + Grid_Project( globalGrid, dimInds );
-	}
-
-	self->elGrid->sizes[0]++;
-	self->elGrid->sizes[1]++;
-	Grid_SetSizes( globalGrid, self->elGrid->sizes );
-	self->elGrid->sizes[0]--;
-	self->elGrid->sizes[1]--;
-
-	self->range[0]++;
-	self->range[1]++;
-	Grid_SetSizes( grid, self->range );
-	self->range[0]--;
-	self->range[1]--;
-
-	nEls[2] = grid->sizes[0];
-	for( d_i = 1; d_i < grid->nDims; d_i++ )
-		nEls[2] *= grid->sizes[d_i];
-	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] + nEls[2] );
-
-	for( e_i = 0; e_i < nEls[2]; e_i++ ) {
-		Grid_Lift( grid, e_i, dimInds );
-		for( d_i = 0; d_i < grid->nDims; d_i++ )
-			dimInds[d_i] += self->origin[d_i];
-		els[nEls[0] + nEls[1] + e_i] = nGlobalEls[0] + nGlobalEls[1] + Grid_Project( globalGrid, dimInds );
-	}
-
-	IGraph_SetElements( topo, MT_EDGE, nEls[0] + nEls[1] + nEls[2],(int*)els);
-
-	FreeArray( dimInds );
-	FreeArray( els );
-	FreeObject( grid );
-	FreeObject( globalGrid );
-}
-
-void CartesianGenerator_GenBndVerts( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
-	IArray bndElsObj, *bndEls = &bndElsObj;
-	int nDims, nVerts, nBndEls;
-	const int* ptr;
-	int global;
-	int* inds;
-	const Sync* sync;
-	int v_i, d_i;
-
-	assert( self );
-	assert( topo );
-	assert( grids );
-
-	nDims = MeshTopology_GetNumDims( topo );
-	inds = Class_Array( self, int, nDims );
-	IArray_Construct( bndEls );
-	sync = IGraph_GetDomain( topo, 0 );
-	nVerts = Sync_GetNumDomains( sync );
-	for( v_i = 0; v_i < nVerts; v_i++ ) {
-		global = Sync_DomainToGlobal( sync, v_i );
-		Grid_Lift( grids[0][0], global, (unsigned*)inds );
-		for( d_i = 0; d_i < nDims; d_i++ ) {
-                  if( inds[d_i] == 0 || (unsigned)(inds[d_i]) == grids[0][0]->sizes[d_i] - 1 )
-				break;
-		}
-		if( d_i < nDims )
-			IArray_Append( bndEls, v_i );
-	}
-	Class_Free( self, inds );
-
-	IArray_GetArray( bndEls, &nBndEls, &ptr );
-	IGraph_SetBoundaryElements( topo, 0, nBndEls, ptr );
-	IArray_Destruct( bndEls );
-}
-
-void CartesianGenerator_CompleteVertexNeighbours( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
-   Stream*		stream = Journal_Register( Info_Type, (Name)self->type  );
-   const Sync* sync;
-   unsigned	nDims;
-   unsigned	nVerts;
-   unsigned*	inds;
-   unsigned	*nNbrs, **nbrs;
-   unsigned	domain, global;
-   unsigned	v_i;
-
-	assert( self );
-	assert( topo );
-	assert( grids );
-
-	Journal_Printf( stream, "Generating vertex neighbours...\n" );
-	Stream_Indent( stream );
-
-	nDims = topo->nDims;
-	sync = IGraph_GetDomain( topo, MT_VERTEX );
-	nVerts = Sync_GetNumDomains( sync );
-	inds = AllocArray( unsigned, nDims );
-	nNbrs = AllocArray( unsigned, nVerts );
-	nbrs = AllocArray2D( unsigned, nVerts, (nDims == 3) ? 6 : (nDims == 2) ? 4 : 2 );
-	for( v_i = 0; v_i < nVerts; v_i++ ) {
-		nNbrs[v_i] = 0;
-		global = Sync_DomainToGlobal( sync, v_i );
-		Grid_Lift( grids[0][0], global, inds );
-
-		if( inds[0] > 0 ) {
-			inds[0]--;
-			domain = Grid_Project( grids[0][0], inds );
-			if(Sync_TryGlobalToDomain(sync,domain,(int*)(&domain))) {
-				nbrs[v_i][nNbrs[v_i]] = domain;
-				nNbrs[v_i]++;
-			}
-			inds[0]++;
-		}
-
-		if( inds[0] < grids[0][0]->sizes[0] - 1 ) {
-			inds[0]++;
-			domain = Grid_Project( grids[0][0], inds );
-			if(Sync_TryGlobalToDomain(sync,domain,(int*)(&domain))) {
-				nbrs[v_i][nNbrs[v_i]] = domain;
-				nNbrs[v_i]++;
-			}
-			inds[0]--;
-		}
-
-		if( nDims >= 2 ) {
-			if( inds[1] > 0 ) {
-				inds[1]--;
-				domain = Grid_Project( grids[0][0], inds );
-				if(Sync_TryGlobalToDomain(sync,domain,
-                                                          (int*)(&domain))) {
-					nbrs[v_i][nNbrs[v_i]] = domain;
-					nNbrs[v_i]++;
-				}
-				inds[1]++;
-			}
-
-			if( inds[1] < grids[0][0]->sizes[1] - 1 ) {
-				inds[1]++;
-				domain = Grid_Project( grids[0][0], inds );
-				if(Sync_TryGlobalToDomain(sync,domain,
-                                                          (int*)(&domain))) {
-					nbrs[v_i][nNbrs[v_i]] = domain;
-					nNbrs[v_i]++;
-				}
-				inds[1]--;
-			}
-
-			if( nDims == 3 ) {
-				if( inds[2] > 0 ) {
-					inds[2]--;
-					domain = Grid_Project( grids[0][0], inds );
-					if(Sync_TryGlobalToDomain(sync,domain,
-                                                                  (int*)(&domain))) {
-						nbrs[v_i][nNbrs[v_i]] = domain;
-						nNbrs[v_i]++;
-					}
-					inds[2]++;
-				}
-
-				if( inds[2] < grids[0][0]->sizes[2] - 1 ) {
-					inds[2]++;
-					domain = Grid_Project( grids[0][0], inds );
-					if(Sync_TryGlobalToDomain(sync,domain,
-                                                                  (int*)(&domain))) {
-						nbrs[v_i][nNbrs[v_i]] = domain;
-						nNbrs[v_i]++;
-					}
-					inds[2]--;
-				}
-			}
-		}
-
-		IGraph_SetIncidence(topo,MT_VERTEX,v_i,MT_VERTEX,nNbrs[v_i],
-                                    (int*)(nbrs[v_i]));
-	}
-
-	FreeArray( nNbrs );
-	FreeArray( nbrs );
-	FreeArray( inds );
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void CartesianGenerator_MapToDomain( CartesianGenerator* self,
-                                     const Sync* sync, 
-				     unsigned nIncEls, unsigned* incEls )
-{
-	unsigned	inc_i;
-
-	assert( self );
-	assert( sync );
-	assert( nIncEls );
-	assert( incEls );
-
-	for( inc_i = 0; inc_i < nIncEls; inc_i++ )
-		incEls[inc_i] = Sync_GlobalToDomain( sync, incEls[inc_i] );
-}
-
-#define MAX_LINE_LENGTH 1024
-void CartesianGenerator_GenGeom( CartesianGenerator* self, Mesh* mesh, void* data ) {
-	Stream*			   stream = Journal_Register( Info_Type, (Name)self->type );
-	Sync*			      sync;
-	AbstractContext* 	context = (AbstractContext*)data;
-	
-	assert( self );
-	assert( mesh  );
-
-	Journal_Printf( stream, "Generating geometry...\n" );
-	Stream_Indent( stream );
-
-	/* Allocate for coordinates. */
-	sync = (Sync*)IGraph_GetDomain( (IGraph*)mesh->topo, 0 );
-	mesh->verts = AllocNamedArray2D( double, Sync_GetNumDomains( sync ), 
-					 mesh->topo->nDims, 
-					 "Mesh::verts" );
-
-	if( context && context->restartTimestep && context->timeStep == context->restartTimestep && self->readFromFile) {
-      char*  meshReadFileName;
-      char*  meshReadFileNamePart;   
-
-      meshReadFileNamePart = Context_GetCheckPointReadPrefixString( context );
-#ifdef READ_HDF5
-      Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.h5", meshReadFileNamePart, self->meshes[0]->name, context->restartTimestep );
-      Journal_Printf( stream, "... loading from file %s.\n", meshReadFileName );
-      CartesianGenerator_ReadFromHDF5( self, mesh, meshReadFileName );
-#else
-      Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.dat", meshReadFileNamePart, self->meshes[0]->name, context->restartTimestep );
-      Journal_Printf( stream, "... loading from file %s.\n", meshReadFileName );
-      CartesianGenerator_ReadFromASCII( self, mesh, meshReadFileName);      
-#endif
-      Memory_Free( meshReadFileName );
-      Memory_Free( meshReadFileNamePart );
-      Mesh_Sync( mesh );
-      
-	} else { 
-      Grid*			      grid;
-      unsigned*		   inds;
-      double*			   steps;
-      int          d_i;
-
-      /* Build grid and space for indices. */
-      grid = self->vertGrid;
-      inds = Memory_Alloc_Array_Unnamed( unsigned, mesh->topo->nDims );
-
-      /* Calculate steps. */
-      steps = Memory_Alloc_Array_Unnamed( double, mesh->topo->nDims );
-      for( d_i = 0; d_i < mesh->topo->nDims; d_i++ )
-         steps[d_i] = self->crdMax[d_i] - self->crdMin[d_i];
-   
-      CartesianGenerator_CalcGeom( self, mesh, sync, grid, inds, steps );
-      
-      /* Free resources. */
-      FreeArray( inds );
-      FreeArray( steps );
-	}
-
-
-	MPI_Barrier( self->mpiComm );
-	Journal_Printf( stream, "... done.\n" );
-	Stream_UnIndent( stream );
-}
-
-void CartesianGenerator_CalcGeom( CartesianGenerator* self, Mesh* mesh, Sync* sync, Grid* grid, unsigned* inds, double* steps ) {	
-	unsigned		n_i, d_i;
-	double*         	vert;
-	unsigned        	gNode;
-
-	/* Loop over domain nodes. */
-	for( n_i = 0; n_i < (unsigned)Sync_GetNumDomains( sync ); n_i++ ) {
-		gNode = Sync_DomainToGlobal( sync, n_i );
-		Grid_Lift( grid, gNode, inds );
-		vert = Mesh_GetVertex( mesh, n_i );
-
-		/* Calculate coordinate. */
-		for( d_i = 0; d_i < (unsigned)(mesh->topo->nDims); d_i++ ) {
-                  if( inds[d_i] <= (unsigned)(self->contactDepth[d_i][0]) ) {
-                      mesh->verts[n_i][d_i] = self->crdMin[d_i];
-                      if( self->contactDepth[d_i][0] ) {
-                         mesh->verts[n_i][d_i] +=
-                            ((double)inds[d_i] / (double)self->contactDepth[d_i][0]) *
-                            self->contactGeom[d_i];
-                      }
-                   }
-                   else if( inds[d_i] >= grid->sizes[d_i] - self->contactDepth[d_i][1] - 1 ) {
-                      mesh->verts[n_i][d_i] = self->crdMax[d_i];
-                      if( self->contactDepth[d_i][1] ) {
-                         mesh->verts[n_i][d_i] -=
-                            ((double)(grid->sizes[d_i] - 1 - inds[d_i]) /
-                             (double)self->contactDepth[d_i][1]) *
-                            self->contactGeom[d_i];
-                      }
-                   }
-                   else {
-                      vert[d_i] = self->crdMin[d_i] + (self->contactDepth[d_i][0] ? self->contactGeom[d_i] : 0.0) +
-                         ((double)(inds[d_i] - self->contactDepth[d_i][0]) / 
-                          (double)(grid->sizes[d_i] - (self->contactDepth[d_i][0] + self->contactDepth[d_i][1]) - 1)) *
-                         (steps[d_i] - ((self->contactDepth[d_i][1] ? 1.0 : 0.0) + (self->contactDepth[d_i][0] ? 1.0 : 0.0)) * self->contactGeom[d_i]);
-                   }
-		}
-	}
-}
-
-void CartesianGenerator_Destruct( CartesianGenerator* self ) {
-	assert( self );
-
-	CartesianGenerator_DestructTopology( self );
-	CartesianGenerator_DestructGeometry( self );
-	KillArray( self->minDecomp );
-	KillArray( self->maxDecomp );
-	NewClass_RemoveRef( self->comm );
-}
-
-void CartesianGenerator_DestructTopology( CartesianGenerator* self ) {
-	assert( self );
-
-	self->maxDecompDims = 0;
-	memset( self->minDecomp, 0, self->nDims * sizeof(unsigned) );
-	memset( self->maxDecomp, 0, self->nDims * sizeof(unsigned) );
-	FreeObject( self->vertGrid );
-	FreeObject( self->elGrid );
-	FreeObject( self->procGrid );
-	KillArray( self->origin );
-	KillArray( self->range );
-	KillArray( self->vertOrigin );
-	KillArray( self->vertRange );
-}
-
-void CartesianGenerator_DestructGeometry( CartesianGenerator* self ) {
-	assert( self );
-
-	FreeArray( self->crdMin );
-	FreeArray( self->crdMax );
-}
-
-#ifdef READ_HDF5
-void CartesianGenerator_ReadFromHDF5(  CartesianGenerator* self, Mesh* mesh, Name filename ){
-	hid_t             file, fileSpace, fileData;
-	hsize_t           start[2], count[2], size[2], maxSize[2];   
-	hid_t             memSpace, error;
-	double            buf[4];
-   Node_LocalIndex   lNode_I = 0;
-	Node_GlobalIndex  gNode_I = 0;
-   int               totalVerts, ii;
-   unsigned int		noffset;
-   MeshCheckpointFileVersion ver;
-   hid_t					attrib_id, group_id;
-   herr_t				status;
-   char*					verticeName;
-	Stream*			   errorStream = Journal_Register( Error_Type, (Name)self->type  );   
-
-   /* Open the file and data set. */
-   file = H5Fopen( filename, H5F_ACC_RDONLY, H5P_DEFAULT );
-
-   /** get the file attributes to sanity and version checks */
-   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-      group_id  = H5Gopen(file, "/");
-      attrib_id = H5Aopen_name(group_id, "checkpoint file version");
-   #else
-      group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
-      attrib_id = H5Aopen(group_id, "checkpoint file version", H5P_DEFAULT);
-   #endif
-   /** if this attribute does not exist (attrib_id < 0) then we assume MeshCHECKPOINT_V1 and continue without checking attributes */
-   if(attrib_id < 0)
-      ver = MeshCHECKPOINT_V1;
-   else {
-      int checkVer;
-      int ndims;
-      int res[self->nDims];
-      unsigned*  sizes;
-
-      /** check for known checkpointing version type */
-
-      status = H5Aread(attrib_id, H5T_NATIVE_INT, &checkVer);
-      H5Aclose(attrib_id);
-      if(checkVer == 2)
-         ver = MeshCHECKPOINT_V2;
-      else
-         Journal_Firewall( (0), errorStream,
-            "\n\nError in %s for %s '%s'\n"
-            "Unknown checkpoint version (%u) for checkpoint file (%s).\n", 
-            __func__, self->type, self->name, (unsigned int) checkVer, filename);
-
-      /** check for correct number of dimensions */
-
-      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-         attrib_id = H5Aopen_name(group_id, "dimensions");
-      #else
-         attrib_id = H5Aopen(group_id, "dimensions", H5P_DEFAULT);
-      #endif
-      status = H5Aread(attrib_id, H5T_NATIVE_INT, &ndims);
-      H5Aclose(attrib_id);      
-      Journal_Firewall( (ndims == (int)(self->nDims)), errorStream,
-         "\n\nError in %s for %s '%s'\n"
-         "Number of dimensions (%u) for checkpoint file (%s) does not correspond to simulation dimensions (%u).\n", 
-         __func__, self->type, self->name, (unsigned int) ndims, filename,
-         self->nDims);
-
-      /** check for correct mesh size */
-      
-      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-         attrib_id = H5Aopen_name(group_id, "mesh resolution");
-      #else
-         attrib_id = H5Aopen(group_id, "mesh resolution", H5P_DEFAULT);
-      #endif
-      status = H5Aread(attrib_id, H5T_NATIVE_INT, &res);
-      H5Aclose(attrib_id);
-
-      sizes = Grid_GetSizes( self->elGrid ); /** global no. of elements in each dim */
-      if(self->nDims == 2)
-         Journal_Firewall(((sizes[0] == (unsigned)(res[0]))
-                           && (sizes[1] == (unsigned)(res[1])) ), 
-            errorStream,
-            "\n\nError in %s for %s '%s'\n"
-            "Size of mesh (%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u, %u).\n", 
-            __func__, self->type, self->name, 
-            (unsigned int) res[0], (unsigned int) res[1],
-            filename,
-            (unsigned int) sizes[0], (unsigned int) sizes[1]);
-      else
-         Journal_Firewall( 
-                          ( (sizes[0] == (unsigned)(res[0]))
-                            && (sizes[1] == (unsigned)(res[1]))
-                            && (sizes[2] == (unsigned)(res[2])) ), 
-            errorStream,
-            "\n\nError in %s for %s '%s'\n"
-            "Size of mesh (%u,%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u,%u,%u).\n", 
-            __func__, self->type, self->name, 
-            (unsigned int) res[0], (unsigned int) res[1], (unsigned int) res[2],
-            filename,
-            (unsigned int) sizes[0], (unsigned int) sizes[1], (unsigned int) sizes[2]);
-   }
-   H5Gclose(group_id);
-   
-   /** account for different versions of checkpointing */
-   switch ( ver ) {
-      case MeshCHECKPOINT_V1:
-         noffset = 1;
-         Stg_asprintf( &verticeName, "/data" );
-         break;
-      case MeshCHECKPOINT_V2:
-         noffset = 0;
-         Stg_asprintf( &verticeName, "/vertices" );
-         break;
-      default:
-         Journal_Firewall( 0, errorStream,
-            "Error: in %s: unknown checkpoint file version.\n",
-            __func__ ); 
-   }
-   
-   /* Prepare to read vertices from file */		
-   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-   fileData = H5Dopen( file, verticeName );
-   #else
-   fileData = H5Dopen2( file, verticeName, H5P_DEFAULT );
-   #endif
-   fileSpace = H5Dget_space( fileData );
-   Memory_Free( verticeName );
-   start[1] = 0;
-   count[0] = 1;
-   count[1] = mesh->topo->nDims + noffset;
-   memSpace = H5Screate_simple( 2, count, NULL );
-   totalVerts = Mesh_GetGlobalSize( mesh, (MeshTopology_Dim)0 );
-
-   /* Get size of dataspace to check consistency */
-   H5Sget_simple_extent_dims( fileSpace, size, maxSize ); 
-
-   Journal_Firewall( 
-                    (maxSize[0] == (unsigned)totalVerts), 
-      errorStream,
-      "\n\nError in %s for %s '%s'\n"
-      "Number of mesh vertices (%u) stored in %s does not correspond to total number of requested mesh vertices (%u).\n", 
-      __func__, 
-      self->type, 
-      self->name, 
-      (unsigned int)maxSize[0],
-      filename,
-      totalVerts);
-
-   for( ii=0; ii<totalVerts; ii++ ) {   
-      start[0] = ii;
-            
-      H5Sselect_hyperslab( fileSpace, H5S_SELECT_SET, start, NULL, count, NULL );
-      H5Sselect_all( memSpace );
-      
-      error = H5Dread( fileData, H5T_NATIVE_DOUBLE, memSpace, fileSpace, H5P_DEFAULT, buf );
-      gNode_I = ii;
-
-      Journal_Firewall( 
-         error >= 0, 
-         errorStream,
-         "\n\nError in %s for %s '%s' - Cannot read data in %s.\n", 
-         __func__, 
-         self->type, 
-         self->name, 
-         filename );
-      
-      if( Mesh_GlobalToDomain( mesh, MT_VERTEX, gNode_I, &lNode_I ) && 
-          lNode_I < Mesh_GetLocalSize( mesh, MT_VERTEX ) )
-      {
-         double *vert;
-
-         vert = Mesh_GetVertex( mesh, lNode_I );
-         vert[0] = buf[0 + noffset];
-         vert[1] = buf[1 + noffset];
-         if( mesh->topo->nDims ==3 )
-            vert[2] = buf[2 + noffset];
-      }
-   }
-         
-   /* Close handles */
-   H5Sclose( memSpace );
-   H5Sclose( fileSpace );
-   H5Dclose( fileData );
-   H5Fclose( file );
-   
-}
-#endif
-
-void CartesianGenerator_ReadFromASCII( CartesianGenerator* self, Mesh* mesh, Name filename ){
-   int               proc_I;
-	Node_LocalIndex   lNode_I = 0;
-	Node_GlobalIndex  gNode_I = 0;
-	FILE*             inputFile;
-	char              lineString[MAX_LINE_LENGTH];
-	int			      rank, nRanks;
-
-   MPI_Comm_rank( self->mpiComm, &rank );
-   MPI_Comm_size( self->mpiComm, &nRanks );
-
-   /* This loop used to stop 2 processors trying to open the file at the same time, which
-   * seems to cause problems */
-   for ( proc_I = 0; proc_I < nRanks; proc_I++ ) {
-      MPI_Barrier( self->mpiComm );
-      if ( proc_I == rank ) {
-         /* Do the following since in parallel on some systems, the file
-          * doesn't get re-opened at the start automatically. */
-         inputFile = fopen( filename, "r" );
-
-         rewind( inputFile );
-      }
-   }
-   
-   fgets( lineString, MAX_LINE_LENGTH, inputFile );
-   fgets( lineString, MAX_LINE_LENGTH, inputFile );
-
-   while ( !feof(inputFile) ) {
-      fscanf( inputFile, "%u ", &gNode_I );
-      if( Mesh_GlobalToDomain( mesh, MT_VERTEX, gNode_I, &lNode_I ) && 
-          lNode_I < Mesh_GetLocalSize( mesh, MT_VERTEX ) )
-      {
-         double crds[3];
-         double *vert;
-
-         fscanf( inputFile, "%lg %lg %lg ", crds, crds + 1, crds + 2 );
-         vert = Mesh_GetVertex( mesh, lNode_I );
-         vert[0] = crds[0];
-         if( self->nDims >= 2 )
-            vert[1] = crds[1];
-         if( self->nDims >=3 )
-            vert[2] = crds[2];
-      }
-      else {
-         fgets( lineString, MAX_LINE_LENGTH, inputFile );
-      }
-   }
-
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/CartesianGenerator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/CartesianGenerator.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,2487 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: CartesianGenerator.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#ifdef READ_HDF5
+#include <hdf5.h>
+#endif
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Grid.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "IGraph.h"
+#include "Mesh_ElementType.h"
+#include "Mesh_HexType.h"
+#include "MeshClass.h"
+#include "MeshGenerator.h"
+#include "Mesh_Algorithms.h"
+#include "Mesh_RegularAlgorithms.h"
+#include "CartesianGenerator.h"
+
+#define OFFSET_TAG 6
+
+/* Textual name of this class */
+const Type CartesianGenerator_Type = "CartesianGenerator";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+CartesianGenerator* CartesianGenerator_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                                    _sizeOfSelf = sizeof(CartesianGenerator);
+	Type                                                            type = CartesianGenerator_Type;
+	Stg_Class_DeleteFunction*                                    _delete = _CartesianGenerator_Delete;
+	Stg_Class_PrintFunction*                                      _print = _CartesianGenerator_Print;
+	Stg_Class_CopyFunction*                                        _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*        _defaultConstructor = (void* (*)(Name))_CartesianGenerator_New;
+	Stg_Component_ConstructFunction*                          _construct = _CartesianGenerator_AssignFromXML;
+	Stg_Component_BuildFunction*                                  _build = _CartesianGenerator_Build;
+	Stg_Component_InitialiseFunction*                        _initialise = _CartesianGenerator_Initialise;
+	Stg_Component_ExecuteFunction*                              _execute = _CartesianGenerator_Execute;
+	Stg_Component_DestroyFunction*                              _destroy = _CartesianGenerator_Destroy;
+	AllocationType                                    nameAllocationType = NON_GLOBAL;
+	MeshGenerator_SetDimSizeFunc*                         setDimSizeFunc = CartesianGenerator_SetDimSize;
+	MeshGenerator_GenerateFunc*                             generateFunc = CartesianGenerator_Generate;
+	CartesianGenerator_SetTopologyParamsFunc*      setTopologyParamsFunc = _CartesianGenerator_SetTopologyParams;
+	CartesianGenerator_GenElementsFunc*                  genElementsFunc = _CartesianGenerator_GenElements;
+	CartesianGenerator_GenFacesFunc*                        genFacesFunc = _CartesianGenerator_GenFaces;
+	CartesianGenerator_GenEdgesFunc*                        genEdgesFunc = _CartesianGenerator_GenEdges;
+	CartesianGenerator_GenVerticesFunc*                  genVerticesFunc = _CartesianGenerator_GenVertices;
+	CartesianGenerator_GenElementVertexIncFunc*  genElementVertexIncFunc = _CartesianGenerator_GenElementVertexInc;
+	CartesianGenerator_GenVolumeEdgeIncFunc*        genVolumeEdgeIncFunc = _CartesianGenerator_GenVolumeEdgeInc;
+	CartesianGenerator_GenVolumeFaceIncFunc*        genVolumeFaceIncFunc = _CartesianGenerator_GenVolumeFaceInc;
+	CartesianGenerator_GenFaceVertexIncFunc*        genFaceVertexIncFunc = _CartesianGenerator_GenFaceVertexInc;
+	CartesianGenerator_GenFaceEdgeIncFunc*            genFaceEdgeIncFunc = _CartesianGenerator_GenFaceEdgeInc;
+	CartesianGenerator_GenEdgeVertexIncFunc*        genEdgeVertexIncFunc = _CartesianGenerator_GenEdgeVertexInc;
+	CartesianGenerator_GenElementTypesFunc*          genElementTypesFunc = _CartesianGenerator_GenElementTypes;
+
+	CartesianGenerator* self = _CartesianGenerator_New(  CARTESIANGENERATOR_PASSARGS  );
+	/* CartesianGenerator info */
+   _MeshGenerator_Init( (MeshGenerator*)self, context );
+	_CartesianGenerator_Init( self );
+   return self;
+}
+
+CartesianGenerator* _CartesianGenerator_New(  CARTESIANGENERATOR_DEFARGS  ) {
+	CartesianGenerator* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(CartesianGenerator) );
+	self = (CartesianGenerator*)_MeshGenerator_New(  MESHGENERATOR_PASSARGS  );
+
+	/* Virtual info */
+	self->setTopologyParamsFunc = setTopologyParamsFunc;
+	self->genElementsFunc = genElementsFunc;
+	self->genFacesFunc = genFacesFunc;
+	self->genEdgesFunc = genEdgesFunc;
+	self->genVerticesFunc = genVerticesFunc;
+	self->genElementVertexIncFunc = genElementVertexIncFunc;
+	self->genVolumeEdgeIncFunc = genVolumeEdgeIncFunc;
+	self->genVolumeFaceIncFunc = genVolumeFaceIncFunc;
+	self->genFaceVertexIncFunc = genFaceVertexIncFunc;
+	self->genFaceEdgeIncFunc = genFaceEdgeIncFunc;
+	self->genEdgeVertexIncFunc = genEdgeVertexIncFunc;
+	self->genElementTypesFunc = genElementTypesFunc;
+
+
+	return self;
+}
+
+void _CartesianGenerator_Init( CartesianGenerator* self ) {
+	Stream*	stream;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+
+	stream = Journal_Register( Info_Type, (Name)self->type  );
+	Stream_SetPrintingRank( stream, 0 );
+
+	self->comm = NULL;
+	self->regular = True;
+	memset( self->periodic, 0, 3 * sizeof(Bool) );
+	self->maxDecompDims = 0;
+	self->minDecomp = NULL;
+	self->maxDecomp = NULL;
+	self->shadowDepth = 1;
+	self->crdMin = NULL;
+	self->crdMax = NULL;
+
+	self->vertGrid = NULL;
+	self->elGrid = NULL;
+	self->procGrid = NULL;
+	self->origin = NULL;
+	self->range = NULL;
+	self->vertOrigin = NULL;
+	self->vertRange = NULL;
+   
+   /* set load from checkpoint to false by default */
+   self->readFromFile = False;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _CartesianGenerator_Delete( void* meshGenerator ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	/* Delete the parent. */
+	_MeshGenerator_Delete( self );
+}
+
+void _CartesianGenerator_Print( void* meshGenerator, Stream* stream ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	
+	/* Set the Journal for printing informations */
+	Stream* meshGeneratorStream;
+	meshGeneratorStream = Journal_Register( InfoStream_Type, (Name)"CartesianGeneratorStream"  );
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+
+	/* Print parent */
+	Journal_Printf( stream, "CartesianGenerator (ptr): (%p)\n", self );
+	_MeshGenerator_Print( self, stream );
+}
+
+void _CartesianGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
+	CartesianGenerator*		self = (CartesianGenerator*)meshGenerator;
+	Dictionary*					dict;
+	Dictionary_Entry_Value*	tmp;
+	char*							rootKey;
+	Dictionary_Entry_Value*	sizeList;
+	Dictionary_Entry_Value	*minList, *maxList;
+	unsigned						maxDecompDims;
+	unsigned						*minDecomp, *maxDecomp;
+	double						*crdMin, *crdMax;
+	unsigned*					size;
+	unsigned						shadowDepth;
+	Stream*						stream;
+	Stream*						errorStream = Journal_Register( Error_Type, (Name)self->type  );
+	unsigned						d_i;
+	unsigned						restartTimestep;
+   AbstractContext*        context;	
+#ifdef READ_HDF5
+	hid_t file, fileData;
+#endif
+	
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( cf );
+
+   /* get the context which is required for filename determination */
+   context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ) ;
+
+	/* Call parent construct. */
+	_MeshGenerator_AssignFromXML( self, cf, data );
+
+	/* Rip out the components structure as a dictionary. */
+	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
+
+	/* Read the sizes. */
+	sizeList = Dictionary_Get( dict, (Dictionary_Entry_Key)"size" );
+	assert( sizeList );
+	assert( Dictionary_Entry_Value_GetCount( sizeList ) >= self->nDims  );
+	size = Memory_Alloc_Array_Unnamed( unsigned, self->nDims );
+	for( d_i = 0; d_i < self->nDims; d_i++ ) {
+		tmp = Dictionary_Entry_Value_GetElement( sizeList, d_i );
+		rootKey = Dictionary_Entry_Value_AsString( tmp );
+
+		if( !Stg_StringIsNumeric( (char *)rootKey )  )
+			tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
+		size[d_i] = Dictionary_Entry_Value_AsUnsignedInt( tmp  );
+	}
+
+	/* Read decomposition restrictions. */
+	maxDecompDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxDecomposedDims", 0  );
+
+	minList = Dictionary_Get( dict, (Dictionary_Entry_Key)"minDecompositions" );
+	if( minList  ) {
+		minDecomp = AllocArray( unsigned, self->nDims );
+		for( d_i = 0; d_i < self->nDims; d_i++ ) {
+			tmp = Dictionary_Entry_Value_GetElement( minList, d_i );
+			rootKey = Dictionary_Entry_Value_AsString( tmp );
+
+			if( !Stg_StringIsNumeric( (char *)rootKey )  )
+				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
+			minDecomp[d_i] = Dictionary_Entry_Value_AsUnsignedInt( tmp  );
+		}
+	}
+	else
+		minDecomp = NULL;
+
+	maxList = Dictionary_Get( dict, (Dictionary_Entry_Key)"maxDecompositions" );
+	if( maxList  ) {
+		maxDecomp = AllocArray( unsigned, self->nDims );
+		for( d_i = 0; d_i < self->nDims; d_i++ ) {
+			tmp = Dictionary_Entry_Value_GetElement( maxList, d_i );
+			rootKey = Dictionary_Entry_Value_AsString( tmp );
+
+			if( !Stg_StringIsNumeric( (char *)rootKey )  )
+				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
+			maxDecomp[d_i] = Dictionary_Entry_Value_AsUnsignedInt( tmp  );
+		}
+	}
+	else
+		maxDecomp = NULL;
+
+	/* Initial setup. */
+	CartesianGenerator_SetTopologyParams( self, size, maxDecompDims, minDecomp, maxDecomp );
+
+        /* Contact stuff. */
+        self->contactDepth[0][0] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-left", 0  );
+        self->contactDepth[0][1] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-right", 0  );
+        self->contactDepth[1][0] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-bottom", 0  );
+        self->contactDepth[1][1] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-top", 0  );
+        self->contactDepth[2][0] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-back", 0  );
+        self->contactDepth[2][1] = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth-front", 0  );
+        self->contactGeom[0] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactGeometry-x", 0.0  );
+        self->contactGeom[1] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactGeometry-y", 0.0  );
+        self->contactGeom[2] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactGeometry-z", 0.0  );
+
+	/* Read geometry. */
+	minList = Dictionary_Get( dict, (Dictionary_Entry_Key)"minCoord"  );
+	maxList = Dictionary_Get( dict, (Dictionary_Entry_Key)"maxCoord" );
+	if( minList && maxList ) {
+		assert( Dictionary_Entry_Value_GetCount( minList ) >= self->nDims );
+		assert( Dictionary_Entry_Value_GetCount( maxList ) >= self->nDims  );
+		crdMin = Memory_Alloc_Array_Unnamed( double, 3 );
+		crdMax = Memory_Alloc_Array_Unnamed( double, 3 );
+		for( d_i = 0; d_i < self->nDims; d_i++ ) {
+		   double maxVal;
+			tmp = Dictionary_Entry_Value_GetElement( minList, d_i );
+			rootKey = Dictionary_Entry_Value_AsString( tmp );
+
+			if( !Stg_StringIsNumeric( (char *)rootKey )  )
+				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
+			crdMin[d_i] = Dictionary_Entry_Value_AsDouble( tmp  );
+
+			tmp = Dictionary_Entry_Value_GetElement( maxList, d_i );
+			rootKey = Dictionary_Entry_Value_AsString( tmp );
+
+			if( !Stg_StringIsNumeric( (char *)rootKey )  )
+				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
+			crdMax[d_i] = Dictionary_Entry_Value_AsDouble( tmp );
+			/* test to ensure provided domain is valid */
+			maxVal =  (abs(crdMax[d_i]) > abs(crdMin[d_i])) ? abs(crdMax[d_i]) : abs(crdMin[d_i]);
+			if( maxVal == 0  ) maxVal = 1;  /* if maxVal is zero, then both numbers must be zero, set to one as next test will fail */
+         Journal_Firewall( ( ( (crdMax[d_i] - crdMin[d_i])/maxVal) > 1E-10 || d_i==J_AXIS), errorStream,
+                     "\n\nError in %s for %s '%s'\n\n"
+                     "Dimension of domain (min = %f, max = %f) for component number %u is not valid.\n\n",
+                     __func__, self->type, self->name,
+                     crdMin[d_i], crdMax[d_i], d_i);
+		}
+
+		restartTimestep = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"restartTimestep", 0 );	
+		if( restartTimestep  ) {
+         char*   meshReadFileName;
+         char*   meshReadFileNamePart;
+         self->readFromFile = True;
+#ifdef READ_HDF5
+         hid_t   attrib_id, group_id;
+         herr_t  status;
+
+         meshReadFileNamePart = Context_GetCheckPointReadPrefixString( context );
+
+         /** assumption: that the generator only generates one mesh, or that the information in that mesh's checkpoint
+         file is valid for all meshes being generated TODO: generalise **/
+         Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.h5", meshReadFileNamePart, self->meshes[0]->name, restartTimestep );
+	      
+	      /** Read in minimum coord. */
+	      file = H5Fopen( meshReadFileName, H5F_ACC_RDONLY, H5P_DEFAULT );
+	      
+	      if( !file ) {
+            /** file not found, so don't load from checkpoint */
+            self->readFromFile = False;
+				Journal_Printf( errorStream, 
+					"Warning - Couldn't find checkpoint mesh file with filename \"%s\".\n", 
+					meshReadFileName );
+			}
+			else {
+         int res[self->nDims];
+
+         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+	         fileData = H5Dopen( file, "/min" );
+         #else
+	         fileData = H5Dopen2( file, "/min", H5P_DEFAULT );
+         #endif
+	         H5Dread( fileData, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, crdMin );
+	         H5Dclose( fileData );
+	         
+	         /** Read in maximum coord. */
+         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+	         fileData = H5Dopen( file, "/max" );
+         #else
+	         fileData = H5Dopen2( file, "/max", H5P_DEFAULT );
+         #endif
+	         H5Dread( fileData, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, crdMax );
+	         H5Dclose( fileData );
+
+            /** get the file attributes  */
+         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+            group_id  = H5Gopen(file, "/");
+            attrib_id = H5Aopen_name(group_id, "checkpoint file version");
+         #else
+            group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
+            attrib_id = H5Aopen(group_id, "checkpoint file version", H5P_DEFAULT);
+         #endif
+
+         /** check for correct mesh size */
+      
+         #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+            attrib_id = H5Aopen_name(group_id, "mesh resolution");
+         #else
+            attrib_id = H5Aopen(group_id, "mesh resolution", H5P_DEFAULT);
+         #endif
+         status = H5Aread(attrib_id, H5T_NATIVE_INT, &res);
+         H5Aclose(attrib_id);
+   
+         if(self->nDims == 2){
+           if(!((size[0]==(unsigned)(res[0])) && (size[1]==(unsigned)(res[1])))){
+               if (context->interpolateRestart)
+                  self->readFromFile = False;
+               else
+                  Journal_Firewall( 
+                     0, 
+                     errorStream,
+                     "\n\nError in %s for %s '%s'\n"
+                     "Size of mesh (%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u,%u).\n\n"
+                     "If you would like to interpolate checkpoint data to simulation mesh size\n"
+                     "    please re-launch using '--interpolateRestart=1' flag\n\n", 
+                     __func__, self->type, self->name, 
+                     (unsigned int) res[0], (unsigned int) res[1],
+                     meshReadFileName,
+                     (unsigned int) size[0], (unsigned int) size[1]);
+            }
+         } else {
+           if(!((size[0]==(unsigned)(res[0])) && (size[1]==(unsigned)(res[1]))
+                && (size[2]==(unsigned)(res[2])))){
+               if (context->interpolateRestart)
+                  self->readFromFile = False;
+               else
+                  Journal_Firewall( 
+                     0, 
+                     errorStream,
+                     "\n\nError in %s for %s '%s'\n"
+                     "Size of mesh (%u,%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u,%u,%u).\n\n"
+                     "If you would like to interpolate checkpoint data to simulation mesh size\n"
+                     "    please re-launch using '--interpolateRestart=1' flag\n\n", 
+                     __func__, self->type, self->name, 
+                     (unsigned int) res[0], (unsigned int) res[1], (unsigned int) res[2],
+                     meshReadFileName,
+                     (unsigned int) size[0], (unsigned int) size[1], (unsigned int) size[2]);
+               }
+            }
+
+         H5Gclose(group_id);
+         H5Fclose( file );
+
+         }
+
+#else
+         Journal_Firewall(!context->interpolateRestart,  
+                     errorStream,"\n\n Interpolation restart not supported for ASCII checkpoint files \n\n");
+
+         meshReadFileNamePart = Context_GetCheckPointReadPrefixString( context );
+
+         Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.dat", meshReadFileNamePart, self->meshes[0]->name, restartTimestep );
+	        
+			FILE* meshFile = fopen( meshReadFileName, "r" );	
+			/*Journal_Firewall( 
+				meshFile != 0, 
+				errorStream, 
+				"Error in %s - Couldn't find checkpoint mesh file with filename \"%s\" - aborting.\n", 
+				__func__,  
+				meshReadFileName );*/
+
+			if( meshFile == 0 ) {
+            /* file not found, so don't load from checkpoint */
+            self->readFromFile = False;            
+				Journal_Printf( errorStream, 
+					"Warning - Couldn't find checkpoint mesh file with filename \"%s\".\n", 
+					meshReadFileName );
+			}
+			else {
+				/* Read min and max coords from file */
+		      if(self->nDims==2)
+                  fscanf( meshFile, "Min: %lg %lg 0\n", &crdMin[0], &crdMin[1] );
+            else
+                  fscanf( meshFile, "Min: %lg %lg %lg\n", &crdMin[0], &crdMin[1], &crdMin[2] );
+		      if(self->nDims==2)
+                  fscanf( meshFile, "Max: %lg %lg 0\n", &crdMax[0], &crdMax[1] );
+            else
+                  fscanf( meshFile, "Max: %lg %lg %lg\n", &crdMax[0], &crdMax[1], &crdMax[2] );
+            
+				fclose( meshFile );
+			}
+#endif
+				
+			Memory_Free( meshReadFileName );
+			Memory_Free( meshReadFileNamePart );
+
+		}	
+		   
+		/* Initial setup. */
+		CartesianGenerator_SetGeometryParams( self, crdMin, crdMax );
+
+		/* Free coordinate arrays. */
+		FreeArray( crdMin );
+		FreeArray( crdMax );
+	}
+
+	/* Read and set shadow depth. */
+	shadowDepth = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"shadowDepth", 1  );
+	CartesianGenerator_SetShadowDepth( self, shadowDepth );
+
+	/* Read regular flag. */
+	self->regular = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"regular", True  );
+
+	/* Read periodic flags. */
+	self->periodic[0] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"periodic_x", False  );
+	self->periodic[1] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"periodic_y", False  );
+	self->periodic[2] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"periodic_z", False  );
+
+	/* Read a general dictionary flag for which processor to watch. */
+	stream = Journal_Register( Info_Type, (Name)self->type  );
+	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( cf->rootDict, "rankToWatch", 0 ) );
+
+	/* Free stuff. */
+	FreeArray( size );
+	FreeArray( minDecomp );
+	FreeArray( maxDecomp );
+}
+
+void _CartesianGenerator_Build( void* meshGenerator, void* data ) {
+	_MeshGenerator_Build( meshGenerator, data );
+}
+
+void _CartesianGenerator_Initialise( void* meshGenerator, void* data ) {
+}
+
+void _CartesianGenerator_Execute( void* meshGenerator, void* data ) {
+}
+
+void _CartesianGenerator_Destroy( void* meshGenerator, void* data ) {
+   CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+   CartesianGenerator_Destruct( self );
+
+   /* Destroy Parent */
+   _MeshGenerator_Destroy( self, data );
+}
+
+void CartesianGenerator_SetDimSize( void* meshGenerator, unsigned nDims ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+
+	_MeshGenerator_SetDimSize( self, nDims );
+
+	self->minDecomp = MemRearray( self->minDecomp, unsigned, self->nDims, CartesianGenerator_Type );
+	memset( self->minDecomp, 0, nDims * sizeof(unsigned) );
+	self->maxDecomp = MemRearray( self->maxDecomp, unsigned, self->nDims, CartesianGenerator_Type );
+	memset( self->maxDecomp, 0, nDims * sizeof(unsigned) );
+}
+
+void CartesianGenerator_Generate( void* meshGenerator, void* _mesh, void* data ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type );
+	Mesh*			mesh = (Mesh* )_mesh;
+	Grid**			grid;
+	unsigned		*localRange, *localOrigin;
+	Bool			*periodic;
+	
+	/* Sanity check. */
+	assert( self );
+	assert( !self->elGrid || mesh );
+
+	Journal_Printf( stream, "Cartesian generator: '%s'\n", self->name );
+	Stream_Indent( stream );
+
+	/* If we havn't been given anything, don't do anything. */
+	if( self->elGrid ) {
+		unsigned	d_i;
+
+		Journal_Printf( stream, "Target mesh: '%s'\n", mesh->name );
+		Journal_Printf( stream, "Global element size: %d", self->elGrid->sizes[0] );
+		for( d_i = 1; d_i < (unsigned)(self->elGrid->nDims); d_i++ )
+			Journal_Printf( stream, "x%d", self->elGrid->sizes[d_i] );
+		Journal_Printf( stream, "\n" );
+		Journal_Printf( stream, "Local offset of rank %d: %d", stream->_printingRank, self->origin[0] );
+		for( d_i = 1; d_i < (unsigned)(self->elGrid->nDims); d_i++ )
+			Journal_Printf( stream, "x%d", self->origin[d_i] );
+		Journal_Printf( stream, "\n" );
+		Journal_Printf( stream, "Local range of rank %d: %d", stream->_printingRank, self->range[0] );
+		for( d_i = 1; d_i < (unsigned)(self->elGrid->nDims); d_i++ )
+			Journal_Printf( stream, "x%d", self->range[d_i] );
+		Journal_Printf( stream, "\n" );
+
+		/* Fill topological values. */
+		MeshTopology_SetComm( mesh->topo, self->comm );
+		MeshTopology_SetNumDims( mesh->topo, self->elGrid->nDims );
+		CartesianGenerator_GenTopo( self, (IGraph*)mesh->topo );
+
+		/* Fill geometric values. */
+		CartesianGenerator_GenGeom( self, mesh, data );
+
+		/* Fill element types. */
+		CartesianGenerator_GenElementTypes( self, mesh );
+	}
+	else {
+          MeshTopology_SetNumDims( mesh->topo, 0 );
+	}
+
+	/* Add extensions to the mesh and fill with cartesian information. */
+	ExtensionManager_Add( mesh->info, (Name)"vertexGrid", sizeof(Grid*) );
+	grid = (Grid** )ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+	*grid = Grid_New( );
+	Grid_SetNumDims( *grid, self->vertGrid->nDims );
+	Grid_SetSizes( *grid, self->vertGrid->sizes );
+
+	ExtensionManager_Add( mesh->info, (Name)"elementGrid", sizeof(Grid*) );
+	grid = (Grid** )ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" ) );
+	*grid = Grid_New( );
+	Grid_SetNumDims( *grid, self->elGrid->nDims );
+	Grid_SetSizes( *grid, self->elGrid->sizes );
+
+	ExtensionManager_AddArray( mesh->info, "localOrigin", sizeof(unsigned), Mesh_GetDimSize( mesh ) );
+	localOrigin = (unsigned*)ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"localOrigin" )  );
+	memcpy( localOrigin, self->origin, Mesh_GetDimSize( mesh ) * sizeof(unsigned) );
+
+	ExtensionManager_AddArray( mesh->info, "localRange", sizeof(unsigned), Mesh_GetDimSize( mesh ) );
+	localRange = (unsigned*)ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"localRange" )  );
+	memcpy( localRange, self->range, Mesh_GetDimSize( mesh ) * sizeof(unsigned) );
+
+	ExtensionManager_AddArray( mesh->info, "periodic", sizeof(Bool), 3 );
+	periodic = (Bool*)ExtensionManager_Get( mesh->info, mesh, ExtensionManager_GetHandle( mesh->info, (Name)"periodic" ) );
+	memcpy( periodic, self->periodic, 3 * sizeof(Bool) );
+
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_SetTopologyParams( void* meshGenerator, unsigned* sizes, unsigned maxDecompDims, unsigned* minDecomp, unsigned* maxDecomp ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	unsigned		d_i;
+
+	/* Sanity check. */
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( !self->nDims || sizes );
+	assert( self->nDims <= 3 );
+
+	/* Kill everything we have, topologically. */
+	CartesianGenerator_DestructTopology( self );
+
+	/* Don't continue if we have nothing. */
+	if( !self->nDims )
+		return;
+
+	/* Set the parameters. */
+	self->elGrid = Grid_New();
+	Grid_SetNumDims( self->elGrid, self->nDims );
+	Grid_SetSizes( self->elGrid, sizes );
+
+	self->vertGrid = Grid_New();
+	Grid_SetNumDims( self->vertGrid, self->nDims );
+	for( d_i = 0; d_i < self->nDims; d_i++ )
+		sizes[d_i]++;
+	Grid_SetSizes( self->vertGrid, sizes );
+	for( d_i = 0; d_i < self->nDims; d_i++ )
+		sizes[d_i]--;
+
+	if( minDecomp )
+		memcpy( self->minDecomp, minDecomp, self->nDims * sizeof(unsigned) );
+	else
+		memset( self->minDecomp, 0, self->nDims * sizeof(unsigned) );
+	if( maxDecomp )
+		memcpy( self->maxDecomp, maxDecomp, self->nDims * sizeof(unsigned) );
+	else
+		memset( self->maxDecomp, 0, self->nDims * sizeof(unsigned) );
+	self->maxDecompDims = maxDecompDims;
+
+	/* As soon as we know the topology, we can decompose. */
+	CartesianGenerator_BuildDecomp( self );
+}
+
+void _CartesianGenerator_GenElements( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	Grid*			grid;
+	unsigned		nEls;
+	unsigned*		els;
+	unsigned*		dimInds;
+	unsigned	d_i, e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+
+	Journal_Printf( stream, "Generating elements...\n" );
+	Stream_Indent( stream );
+
+	grid = Grid_New();
+	Grid_SetNumDims( grid, self->elGrid->nDims );
+	Grid_SetSizes( grid, self->range );
+
+	nEls = grid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ )
+		nEls *= grid->sizes[d_i];
+	els = Memory_Alloc_Array_Unnamed( unsigned, nEls );
+
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
+
+	for( e_i = 0; e_i < nEls; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[e_i] = Grid_Project( self->elGrid, dimInds );
+	}
+
+	IGraph_SetLocalElements( topo, grid->nDims, nEls, (int*)els );
+	FreeArray( els );
+	FreeArray( dimInds );
+	FreeObject( grid );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenVertices( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	unsigned		rank;
+	Grid*			globalGrid;
+	Grid*			grid;
+	unsigned		nEls;
+	unsigned		nLocals, *locals;
+	unsigned		nRemotes/*, *remotes*/;
+	unsigned		*dstArray, *dstCount;
+	unsigned		*dimInds, *rankInds;
+	unsigned	d_i, e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+
+	Journal_Printf( stream, "Generating vertices...\n" );
+	Stream_Indent( stream );
+
+	MPI_Comm_rank( Comm_GetMPIComm( self->comm ), (int*)&rank );
+
+	globalGrid = self->vertGrid;
+
+	grid = Grid_New();
+	Grid_SetNumDims( grid, self->elGrid->nDims );
+	Grid_SetSizes( grid, self->vertRange );
+
+	nEls = grid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ )
+		nEls *= grid->sizes[d_i];
+	locals = Memory_Alloc_Array_Unnamed( unsigned, nEls );
+/*
+	remotes = Memory_Alloc_Array_Unnamed( unsigned, nEls );
+*/
+
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
+	rankInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
+	Grid_Lift( self->procGrid, rank, rankInds );
+
+	nLocals = 0;
+	nRemotes = 0;
+	for( e_i = 0; e_i < nEls; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+/*
+		for( d_i = 0; d_i < grid->nDims; d_i++ ) {
+			if( dimInds[d_i] == 0 && rankInds[d_i] > 0 )
+				break;
+		}
+		if( d_i < grid->nDims ) {
+			dstArray = remotes;
+			dstCount = &nRemotes;
+		}
+		else {
+*/
+			dstArray = locals;
+			dstCount = &nLocals;
+/*
+		}
+*/
+
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->vertOrigin[d_i];
+
+		dstArray[(*dstCount)++] = Grid_Project( globalGrid, dimInds );
+	}
+
+/*
+	MeshTopology_SetLocalElements( topo, 0, nLocals, locals );
+	MeshTopology_SetRemoteElements( topo, 0, nRemotes, remotes );
+*/
+	IGraph_SetElements( topo, 0, nLocals, (int*)locals );
+	FreeArray( locals );
+/*
+	FreeArray( remotes );
+*/
+	FreeArray( dimInds );
+	FreeArray( rankInds );
+	FreeObject( grid );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenEdges( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( self->elGrid->nDims >= 2 );
+	assert( self->elGrid->nDims <= 3 );
+
+	Journal_Printf( stream, "Generating edges...\n" );
+	Stream_Indent( stream );
+
+	if( self->elGrid->nDims == 2 )
+		CartesianGenerator_GenEdges2D( self, topo, grids );
+	else
+		CartesianGenerator_GenEdges3D( self, topo, grids );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenFaces( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	Grid*			globalGrid;
+	unsigned		nGlobalEls[2];
+	Grid*			grid;
+	unsigned		nEls[3];
+	unsigned*		els;
+	unsigned*		dimInds;
+	unsigned		d_i, e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+	assert( self->elGrid->nDims == 3 );
+
+	Journal_Printf( stream, "Generating faces...\n" );
+	Stream_Indent( stream );
+
+	globalGrid = Grid_New();
+	Grid_SetNumDims( globalGrid, self->elGrid->nDims );
+	self->elGrid->sizes[2]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[2]--;
+
+	grid = Grid_New();
+	Grid_SetNumDims( grid, self->elGrid->nDims );
+	self->range[2]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[2]--;
+
+	nEls[0] = grid->sizes[0];
+	nGlobalEls[0] = globalGrid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
+		nEls[0] *= grid->sizes[d_i];
+		nGlobalEls[0] *= globalGrid->sizes[d_i];
+	}
+	els = Memory_Alloc_Array_Unnamed( unsigned, nEls[0] );
+
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
+
+	for( e_i = 0; e_i < nEls[0]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[e_i] = Grid_Project( globalGrid, dimInds );
+	}
+
+	self->elGrid->sizes[1]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[1]--;
+
+	self->range[1]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[1]--;
+
+	nEls[1] = grid->sizes[0];
+	nGlobalEls[1] = globalGrid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
+		nEls[1] *= grid->sizes[d_i];
+		nGlobalEls[1] *= globalGrid->sizes[d_i];
+	}
+	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] );
+
+	for( e_i = 0; e_i < nEls[1]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[nEls[0] + e_i] = nGlobalEls[0] + Grid_Project( globalGrid, dimInds );
+	}
+
+	self->elGrid->sizes[0]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[0]--;
+
+	self->range[0]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[0]--;
+
+	nEls[2] = grid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ )
+		nEls[2] *= grid->sizes[d_i];
+	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] + nEls[2] );
+
+	for( e_i = 0; e_i < nEls[2]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[nEls[0] + nEls[1] + e_i] = nGlobalEls[0] + nGlobalEls[1] + Grid_Project( globalGrid, dimInds );
+	}
+
+	IGraph_SetElements(topo,MT_FACE, nEls[0] + nEls[1] + nEls[2],(int*)els);
+
+	FreeArray( dimInds );
+	FreeArray( els );
+	FreeObject( grid );
+	FreeObject( globalGrid );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenElementVertexInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	int			nDomainEls;
+	unsigned*		incEls;
+	unsigned*		dimInds;
+	unsigned		vertsPerEl;
+	const Sync*		sync;
+	unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+
+	Journal_Printf( stream, "Generating element-vertex incidence...\n" );
+	Stream_Indent( stream );
+
+	vertsPerEl = (topo->nDims == 1) ? 2 : (topo->nDims == 2) ? 4 : 8;
+
+	sync = IGraph_GetDomain( topo, topo->nDims );
+	nDomainEls = Sync_GetNumDomains( sync );
+	incEls = Memory_Alloc_Array_Unnamed( unsigned, vertsPerEl );
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
+	for( e_i = 0; e_i < (unsigned)nDomainEls; e_i++ ) {
+		unsigned	gInd = Sync_DomainToGlobal( sync, e_i );
+		unsigned	curNode = 0;
+
+		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
+
+		incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+
+		dimInds[0]++;
+		incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+		dimInds[0]--;
+
+		if( topo->nDims >= 2 ) {
+			dimInds[1]++;
+			incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+			dimInds[1]--;
+
+			if( topo->nDims >= 3 ) {
+				dimInds[2]++;
+				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+
+				dimInds[0]++;
+				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+				dimInds[0]--;
+
+				dimInds[1]++;
+				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+
+				dimInds[0]++;
+				incEls[curNode++] = Grid_Project( grids[0][0], dimInds );
+				dimInds[0]--;
+				dimInds[1]--;
+				dimInds[2]--;
+			}
+		}
+
+		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 0 ), 
+						vertsPerEl, incEls );
+		IGraph_SetIncidence( topo, topo->nDims, e_i, MT_VERTEX,
+                                     vertsPerEl, (int*)incEls );
+	}
+
+	FreeArray( incEls );
+	FreeArray( dimInds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenVolumeEdgeInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	unsigned		nIncEls;
+	unsigned*		incEls;
+	unsigned*		dimInds;
+	unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+	assert( topo->nDims >= 3 );
+
+	Journal_Printf( stream, "Generating volume-edge incidence...\n" );
+	Stream_Indent( stream );
+
+	incEls = Memory_Alloc_Array_Unnamed( unsigned, 12 );
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
+	for( e_i = 0; e_i < (unsigned)(topo->remotes[3]->nDomains); e_i++ ) {
+		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[3], e_i );
+
+		nIncEls = 12;
+		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
+
+		incEls[0] = Grid_Project( grids[1][0], dimInds );
+
+		dimInds[1]++;
+		incEls[1] = Grid_Project( grids[1][0], dimInds );
+		dimInds[1]--;
+
+		incEls[2] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+
+		dimInds[0]++;
+		incEls[3] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+		dimInds[0]--;
+
+		dimInds[2]++;
+		incEls[4] = Grid_Project( grids[1][0], dimInds );
+
+		dimInds[1]++;
+		incEls[5] = Grid_Project( grids[1][0], dimInds );
+		dimInds[1]--;
+
+		incEls[6] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+
+		dimInds[0]++;
+		incEls[7] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+		dimInds[0]--;
+		dimInds[2]--;
+
+		incEls[8] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+
+		dimInds[0]++;
+		incEls[9] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+		dimInds[0]--;
+
+		dimInds[1]++;
+		incEls[10] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+
+		dimInds[0]++;
+		incEls[11] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+		dimInds[0]--;
+		dimInds[1]--;
+
+		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 1 ), 
+						nIncEls, incEls );
+		IGraph_SetIncidence(topo,topo->nDims,e_i,1,nIncEls,(int*)incEls);
+	}
+
+	FreeArray( incEls );
+	FreeArray( dimInds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenVolumeFaceInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	unsigned		nIncEls;
+	unsigned*		incEls;
+	unsigned*		dimInds;
+	unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+	assert( topo->nDims >= 3 );
+
+	Journal_Printf( stream, "Generating volume-face incidence...\n" );
+	Stream_Indent( stream );
+
+	incEls = Memory_Alloc_Array_Unnamed( unsigned, 6 );
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
+	for(e_i=0;e_i<(unsigned)(topo->remotes[MT_VOLUME]->nDomains);e_i++) {
+		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[MT_VOLUME], e_i );
+
+		nIncEls = 6;
+		Grid_Lift( grids[topo->nDims][0], gInd, dimInds );
+
+		incEls[0] = Grid_Project( grids[2][0], dimInds );
+
+		dimInds[2]++;
+		incEls[1] = Grid_Project( grids[2][0], dimInds );
+		dimInds[2]--;
+
+		incEls[2] = Grid_Project( grids[2][1], dimInds ) + grids[2][0]->nPoints;
+
+		dimInds[1]++;
+		incEls[3] = Grid_Project( grids[2][1], dimInds ) + grids[2][0]->nPoints;
+		dimInds[1]--;
+
+		incEls[4] = Grid_Project( grids[2][2], dimInds ) + grids[2][0]->nPoints + grids[2][1]->nPoints;
+
+		dimInds[0]++;
+		incEls[5] = Grid_Project( grids[2][2], dimInds ) + grids[2][0]->nPoints + grids[2][1]->nPoints;
+		dimInds[0]--;
+
+		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 2 ), 
+						nIncEls, incEls );
+		IGraph_SetIncidence(topo,topo->nDims,e_i,2,nIncEls,(int*)incEls);
+	}
+
+	FreeArray( incEls );
+	FreeArray( dimInds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenFaceVertexInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	unsigned		nIncEls;
+	unsigned*		incEls;
+	unsigned*		dimInds;
+	unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+	assert( topo->nDims >= 2 );
+
+	Journal_Printf( stream, "Generating face-vertex incidence...\n" );
+	Stream_Indent( stream );
+
+	incEls = Memory_Alloc_Array_Unnamed( unsigned, 4 );
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
+	for(e_i=0;e_i<(unsigned)(topo->remotes[MT_FACE]->nDomains);e_i++) {
+		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[MT_FACE], e_i );
+
+		nIncEls = 4;
+
+		if( gInd < grids[2][0]->nPoints ) {
+			Grid_Lift( grids[2][0], gInd, dimInds );
+
+			incEls[0] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[1] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+
+			dimInds[1]++;
+			incEls[2] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[3] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+			dimInds[1]--;
+		}
+		else if( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints ) {
+			assert( topo->nDims >= 3 );
+
+			Grid_Lift( grids[2][1], gInd - grids[2][0]->nPoints, dimInds );
+
+			incEls[0] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[1] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+
+			dimInds[2]++;
+			incEls[2] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[3] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+			dimInds[2]--;
+		}
+		else {
+			assert( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints + grids[2][2]->nPoints );
+			assert( topo->nDims >= 3 );
+
+			Grid_Lift( grids[2][2], gInd - grids[2][0]->nPoints - grids[2][1]->nPoints, dimInds );
+
+			incEls[0] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[1]++;
+			incEls[1] = Grid_Project( grids[0][0], dimInds );
+			dimInds[1]--;
+
+			dimInds[2]++;
+			incEls[2] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[1]++;
+			incEls[3] = Grid_Project( grids[0][0], dimInds );
+			dimInds[1]--;
+			dimInds[2]--;
+		}
+
+		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 0 ), 
+						nIncEls, incEls );
+		IGraph_SetIncidence( topo, 2, e_i, 0, nIncEls, (int*)incEls );
+	}
+
+	FreeArray( incEls );
+	FreeArray( dimInds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenFaceEdgeInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+	unsigned		nIncEls;
+	unsigned*		incEls;
+	unsigned*		dimInds;
+	unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+	assert( topo->nDims >= 2 );
+
+	Journal_Printf( stream, "Generating face-edge incidence...\n" );
+	Stream_Indent( stream );
+
+	incEls = Memory_Alloc_Array_Unnamed( unsigned, 4 );
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, topo->nDims );
+	for( e_i = 0; e_i < (unsigned)(topo->remotes[MT_FACE]->nDomains);e_i++ ) {
+		unsigned	gInd = Sync_DomainToGlobal( topo->remotes[MT_FACE], e_i );
+
+		nIncEls = 4;
+
+		if( gInd < grids[2][0]->nPoints ) {
+			Grid_Lift( grids[2][0], gInd, dimInds );
+
+			incEls[0] = Grid_Project( grids[1][0], dimInds );
+
+			dimInds[1]++;
+			incEls[1] = Grid_Project( grids[1][0], dimInds );
+			dimInds[1]--;
+
+			incEls[2] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+
+			dimInds[0]++;
+			incEls[3] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+			dimInds[0]--;
+		}
+		else if( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints ) {
+			assert( topo->nDims >= 3 );
+
+			Grid_Lift( grids[2][1], gInd - grids[2][0]->nPoints, dimInds );
+
+			incEls[0] = Grid_Project( grids[1][0], dimInds );
+
+			dimInds[2]++;
+			incEls[1] = Grid_Project( grids[1][0], dimInds );
+			dimInds[2]--;
+
+			incEls[2] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+
+			dimInds[0]++;
+			incEls[3] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+			dimInds[0]--;
+		}
+		else {
+			assert( gInd < grids[2][0]->nPoints + grids[2][1]->nPoints + grids[2][2]->nPoints );
+			assert( topo->nDims >= 3 );
+
+			Grid_Lift( grids[2][2], gInd - grids[2][0]->nPoints - grids[2][1]->nPoints, dimInds );
+
+			incEls[0] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+
+			dimInds[2]++;
+			incEls[1] = Grid_Project( grids[1][1], dimInds ) + grids[1][0]->nPoints;
+			dimInds[2]--;
+
+			incEls[2] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+
+			dimInds[1]++;
+			incEls[3] = Grid_Project( grids[1][2], dimInds ) + grids[1][0]->nPoints + grids[1][1]->nPoints;
+			dimInds[1]--;
+		}
+
+		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 1 ), 
+						nIncEls, incEls );
+		IGraph_SetIncidence( topo, 2, e_i, 1, nIncEls, (int*)incEls );
+	}
+
+	FreeArray( incEls );
+	FreeArray( dimInds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenEdgeVertexInc( void* meshGenerator, IGraph* topo, Grid*** grids ) {
+   CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+   Stream*			stream = Journal_Register( Info_Type, (Name)self->type  );
+   unsigned		nIncEls;
+   unsigned*		incEls;
+   unsigned*		dimInds;
+   const Sync* sync;
+   unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+	assert( topo );
+	assert( grids );
+
+	Journal_Printf( stream, "Generating edge-vertex incidence...\n" );
+	Stream_Indent( stream );
+
+	sync = IGraph_GetDomain( topo, 1 );
+	incEls = MemArray( unsigned, 2, CartesianGenerator_Type );
+	dimInds = MemArray( unsigned, topo->nDims, CartesianGenerator_Type );
+	for( e_i = 0; e_i < (unsigned)Sync_GetNumDomains( sync ); e_i++ ) {
+		unsigned	gInd = Sync_DomainToGlobal( sync, e_i );
+
+		nIncEls = 2;
+
+		if( gInd < grids[1][0]->nPoints ) {
+			Grid_Lift( grids[1][0], gInd, dimInds );
+
+			incEls[0] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[0]++;
+			incEls[1] = Grid_Project( grids[0][0], dimInds );
+			dimInds[0]--;
+		}
+		else if( gInd < grids[1][0]->nPoints + grids[1][1]->nPoints ) {
+			assert( topo->nDims >= 2 );
+
+			Grid_Lift( grids[1][1], gInd - grids[1][0]->nPoints, dimInds );
+
+			incEls[0] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[1]++;
+			incEls[1] = Grid_Project( grids[0][0], dimInds );
+			dimInds[1]--;
+		}
+		else {
+			assert( gInd < grids[1][0]->nPoints + grids[1][1]->nPoints + grids[1][2]->nPoints );
+			assert( topo->nDims >= 3 );
+
+			Grid_Lift( grids[1][2], gInd - grids[1][0]->nPoints - grids[1][1]->nPoints, dimInds );
+
+			incEls[0] = Grid_Project( grids[0][0], dimInds );
+
+			dimInds[2]++;
+			incEls[1] = Grid_Project( grids[0][0], dimInds );
+			dimInds[2]--;
+		}
+
+		CartesianGenerator_MapToDomain( self, (Sync*)IGraph_GetDomain( topo, 0 ), 
+						nIncEls, incEls );
+		IGraph_SetIncidence( topo, MT_EDGE, e_i, MT_VERTEX, nIncEls,
+                                     (int*)incEls );
+	}
+
+	FreeArray( incEls );
+	FreeArray( dimInds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void _CartesianGenerator_GenElementTypes( void* meshGenerator, Mesh* mesh ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+	Stream*			stream;
+	unsigned		nDomainEls;
+	unsigned		e_i;
+
+	assert( self && Stg_CheckType( self, CartesianGenerator ) );
+
+	stream = Journal_Register( Info_Type, (Name)self->type  );
+	Journal_Printf( stream, "Generating element types...\n" );
+	Stream_Indent( stream );
+
+	mesh->nElTypes = 1;
+	mesh->elTypes = Memory_Alloc_Array( Mesh_ElementType*, mesh->nElTypes, "Mesh::elTypes" );
+	mesh->elTypes[0] = (Mesh_ElementType*)Mesh_HexType_New();
+	Mesh_ElementType_SetMesh( mesh->elTypes[0], mesh );
+	nDomainEls = Mesh_GetDomainSize(mesh,Mesh_GetDimSize(mesh));
+	mesh->elTypeMap = Memory_Alloc_Array( unsigned, nDomainEls, "Mesh::elTypeMap" );
+	for( e_i = 0; e_i < nDomainEls; e_i++ )
+		mesh->elTypeMap[e_i] = 0;
+
+	if( self->regular )
+		Mesh_SetAlgorithms( mesh, Mesh_RegularAlgorithms_New( "", NULL ) );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... element types are '%s',\n", mesh->elTypes[0]->type );
+	Journal_Printf( stream, "... mesh algorithm type is '%s',\n", mesh->algorithms->type );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void CartesianGenerator_SetGeometryParams( void* meshGenerator, double* min, double* max ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+
+	/* Sanity check. */
+	assert( self );
+	assert( !self->elGrid->nDims || (min && max) );
+
+	/* Kill everything we have, geometrically. */
+	KillArray( self->crdMin );
+	KillArray( self->crdMax );
+
+	/* Set the parameters. */
+	if( self->elGrid->nDims ) {
+		self->crdMin = Memory_Alloc_Array( double, self->elGrid->nDims, "CartesianGenerator::min" );
+		self->crdMax = Memory_Alloc_Array( double, self->elGrid->nDims, "CartesianGenerator::max" );
+		memcpy( self->crdMin, min, self->elGrid->nDims * sizeof(double) );
+		memcpy( self->crdMax, max, self->elGrid->nDims * sizeof(double) );
+	}
+}
+
+void CartesianGenerator_SetShadowDepth( void* meshGenerator, unsigned depth ) {
+	CartesianGenerator*	self = (CartesianGenerator*)meshGenerator;
+
+	/* Sanity check. */
+	assert( self );
+
+	self->shadowDepth = depth;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void CartesianGenerator_BuildDecomp( CartesianGenerator* self ) {
+	unsigned	nProcs, rank;
+	unsigned	nPos = 0;
+	unsigned**	posNSubDomains = NULL;
+	unsigned*	tmpSubDomains;
+	double		bestRatio;
+	unsigned	bestPos;
+	unsigned	*myRankInds, *rankInds;
+	unsigned	nNbrs, *nbrs;
+	unsigned	p_i, d_i, r_i;
+
+	/* Sanity check. */
+	assert( self );
+
+	/* Collect information regarding parallel configuration. */
+	MPI_Comm_size( self->mpiComm, (int*)&nProcs );
+	MPI_Comm_rank( self->mpiComm, (int*)&rank );
+
+	/* Allocate for possible sub-domains. */
+	tmpSubDomains = Memory_Alloc_Array( unsigned, self->elGrid->nDims, "" );
+
+	/* Build a list of all acceptable decompositions. */
+	CartesianGenerator_RecurseDecomps( self, 0, nProcs, 
+					   tmpSubDomains, &nPos, &posNSubDomains );
+	assert( nPos );
+
+	/* Free unneeded memory. */
+	FreeArray( tmpSubDomains );
+
+	/* Now check for the best ratio. */
+	bestRatio = HUGE_VAL;
+	bestPos = -1;
+	for( p_i = 0; p_i < nPos; p_i++ ) {
+		double		curRatio = 0.0;
+		unsigned	decompDims = 0;
+
+		/* If decomposed in more dimensions than allowed, skip. */
+		for( d_i = 0; d_i < self->elGrid->nDims; d_i++ )
+			decompDims += (posNSubDomains[p_i][d_i] > 1) ? 1 : 0;
+		if( self->maxDecompDims && decompDims > self->maxDecompDims )
+			continue;
+
+		/* Evaluate ratios. */
+		for( d_i = 0; d_i < self->elGrid->nDims; d_i++ ) {
+			double		nI = (double)self->elGrid->sizes[d_i] / (double)posNSubDomains[p_i][d_i];
+			unsigned	d_j;
+
+			for( d_j = d_i + 1; d_j < self->elGrid->nDims; d_j++ ) {
+				double	nJ = (double)self->elGrid->sizes[d_j] / (double)posNSubDomains[p_i][d_j];
+
+				curRatio += (nI > nJ) ? nI / nJ : nJ / nI;
+			}
+		}
+
+		/* Better than best? */
+		if( curRatio < bestRatio ) {
+			bestRatio = curRatio;
+			bestPos = p_i;
+		}
+	}
+	assert( bestPos != (unsigned)(-1) );
+
+	/* Allocate for results. */
+	self->origin = Memory_Alloc_Array( unsigned, self->elGrid->nDims, "CartesianGenerator::origin" );
+	self->range = Memory_Alloc_Array( unsigned, self->elGrid->nDims, "CartesianGenerator::range" );
+
+	/* Build a sub-domain grid. */
+	self->procGrid = Grid_New();
+	Grid_SetNumDims( self->procGrid, self->elGrid->nDims );
+	Grid_SetSizes( self->procGrid, posNSubDomains[bestPos] );
+
+	/* Free unneeded space. */
+	FreeArray( posNSubDomains );
+
+	/* Lift the rank to a parameterised offset. */
+	Grid_Lift( self->procGrid, rank, self->origin );
+	for( d_i = 0; d_i < self->elGrid->nDims; d_i++ ) {
+		unsigned	base = self->elGrid->sizes[d_i] / self->procGrid->sizes[d_i];
+		unsigned	mod = self->elGrid->sizes[d_i] % self->procGrid->sizes[d_i];
+		unsigned	origin = self->origin[d_i];
+
+		self->origin[d_i] *= base;
+		self->range[d_i] = base;
+		if( origin < mod ) {
+			self->origin[d_i] += origin;
+			self->range[d_i]++;
+		}
+		else
+			self->origin[d_i] += mod;
+	}
+
+	/* Copy to the vertex equivalents. */
+	self->vertOrigin = AllocArray( unsigned, self->elGrid->nDims );
+	self->vertRange = AllocArray( unsigned, self->elGrid->nDims );
+	for( d_i = 0; d_i < self->elGrid->nDims; d_i++ ) {
+		self->vertOrigin[d_i] = self->origin[d_i];
+		self->vertRange[d_i] = self->range[d_i] + 1;
+	}
+
+	/* Build the comm topology. */
+	myRankInds = AllocArray( unsigned, Grid_GetNumDims( self->procGrid ) );
+	rankInds = AllocArray( unsigned, Grid_GetNumDims( self->procGrid ) );
+	Grid_Lift( self->procGrid, rank, myRankInds );
+	nNbrs = 0;
+	nbrs = NULL;
+	for( r_i = 0; r_i < Grid_GetNumPoints( self->procGrid ); r_i++ ) {
+		if( r_i == rank )
+			continue;
+
+		Grid_Lift( self->procGrid, r_i, rankInds );
+		for( d_i = 0; d_i < Grid_GetNumDims( self->procGrid ); d_i++ ) {
+			if( (myRankInds[d_i] > 0 && rankInds[d_i] < myRankInds[d_i] - 1) || 
+			    (myRankInds[d_i] < self->procGrid->sizes[d_i] - 1 && rankInds[d_i] > myRankInds[d_i] + 1) )
+			{
+				break;
+			}
+		}
+		if( d_i == Grid_GetNumDims( self->procGrid ) ) {
+			nbrs = ReallocArray( nbrs, unsigned, nNbrs + 1 );
+			nbrs[nNbrs++] = r_i;
+		}
+	}
+
+	FreeArray( myRankInds );
+	FreeArray( rankInds );
+
+	NewClass_RemoveRef( self->comm );
+	self->comm = Comm_New();
+	NewClass_AddRef( self->comm );
+	Comm_SetMPIComm( self->comm, self->mpiComm );
+	Comm_SetNeighbours( self->comm, nNbrs, (int*)nbrs );
+	FreeArray( nbrs );
+}
+
+void CartesianGenerator_RecurseDecomps( CartesianGenerator* self, 
+					unsigned dim, unsigned max, 
+					unsigned* nSubDomains, 
+					unsigned* nPos, unsigned*** posNSubDomains )
+{
+	unsigned	nProcs;
+	unsigned	nSDs = 1;
+	unsigned	d_i;
+
+	MPI_Comm_size( self->mpiComm, (int*)&nProcs );
+
+	/* If we're over the limit, return immediately. */
+	for( d_i = 0; d_i < dim; d_i++ )
+		nSDs *= nSubDomains[d_i];
+	if( nSDs > nProcs )
+		return;
+
+	/* Where are we up to? */
+	if( dim == self->elGrid->nDims ) {
+		/* If this covers all processors, store it. */
+		if( nSDs == nProcs ) {
+			/* If we havn't already allocated do it now. */
+			if( !*posNSubDomains ) {
+				*nPos = 1;
+				*posNSubDomains = Memory_Alloc_2DArray_Unnamed( unsigned, 2, self->elGrid->nDims );
+			}
+			else {
+				/* Reallocate the arrays. */
+				(*nPos)++;
+				if( *nPos != 2 ) {
+					*posNSubDomains = Memory_Realloc_2DArray( *posNSubDomains, unsigned, 
+										  *nPos, self->elGrid->nDims );
+				}
+			}
+
+			/* Store status. */
+			memcpy( (*posNSubDomains)[(*nPos) - 1], nSubDomains, self->elGrid->nDims * sizeof(unsigned) );
+		}
+	}
+	else {
+		unsigned	p_i;
+
+		/* Loop over all remaining */
+		for( p_i = 0; p_i < max; p_i++ ) {
+			/* Don't try and decompose more than this dimension allows. */
+			if( p_i >= self->elGrid->sizes[dim] || 
+			    (self->maxDecomp[dim] && p_i >= self->maxDecomp[dim]) )
+			{
+				break;
+			}
+
+			/* If we have a minimum decomp, skip until we reach it. */
+			if( self->minDecomp[dim] && p_i < self->minDecomp[dim] - 1 )
+				continue;
+
+			/* Set the number of sub-domains. */
+			nSubDomains[dim] = p_i + 1;
+
+			/* Try this combination. */
+			CartesianGenerator_RecurseDecomps( self, dim + 1, max - nSDs + 1, nSubDomains, 
+							   nPos, posNSubDomains );
+		}
+	}
+}
+
+void CartesianGenerator_GenTopo( CartesianGenerator* self, IGraph* topo ) {
+	Grid***		grids;
+	const Comm* comm;
+	int	d_i, d_j;
+
+	assert( self );
+	assert( topo );
+
+	MeshTopology_SetNumDims( topo, self->elGrid->nDims );
+
+	/* Build additional grids for use in numbering. */
+	grids = Memory_Alloc_2DArray_Unnamed( Grid*, topo->nTDims, topo->nTDims );
+	for( d_i = 0; d_i < topo->nTDims; d_i++ )
+		memset( grids[d_i], 0, topo->nTDims * sizeof(Grid*) );
+
+	grids[topo->nDims][0] = self->elGrid;
+	grids[0][0] = self->vertGrid;
+
+	if( topo->nDims >= 2 ) {
+		grids[1][0] = Grid_New();
+		Grid_SetNumDims( grids[1][0], topo->nDims );
+		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+			if( d_i == 0 ) continue;
+			grids[topo->nDims][0]->sizes[d_i]++;
+		}
+		Grid_SetSizes( grids[1][0], grids[topo->nDims][0]->sizes );
+		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+			if( d_i == 0 ) continue;
+			grids[topo->nDims][0]->sizes[d_i]--;
+		}
+
+		grids[1][1] = Grid_New();
+		Grid_SetNumDims( grids[1][1], topo->nDims );
+		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+			if( d_i == 1 ) continue;
+			grids[topo->nDims][0]->sizes[d_i]++;
+		}
+		Grid_SetSizes( grids[1][1], grids[topo->nDims][0]->sizes );
+		for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+			if( d_i == 1 ) continue;
+			grids[topo->nDims][0]->sizes[d_i]--;
+		}
+
+		if( topo->nDims >= 3 ) {
+			grids[1][2] = Grid_New();
+			Grid_SetNumDims( grids[1][2], topo->nDims );
+			for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+				if( d_i == 2 ) continue;
+				grids[topo->nDims][0]->sizes[d_i]++;
+			}
+			Grid_SetSizes( grids[1][2], grids[topo->nDims][0]->sizes );
+			for( d_i = 0; d_i < topo->nDims; d_i++ ) {
+				if( d_i == 2 ) continue;
+				grids[topo->nDims][0]->sizes[d_i]--;
+			}
+
+			grids[2][0] = Grid_New();
+			Grid_SetNumDims( grids[2][0], topo->nDims );
+			grids[topo->nDims][0]->sizes[2]++;
+			Grid_SetSizes( grids[2][0], grids[topo->nDims][0]->sizes );
+			grids[topo->nDims][0]->sizes[2]--;
+
+			grids[2][1] = Grid_New();
+			Grid_SetNumDims( grids[2][1], topo->nDims );
+			grids[topo->nDims][0]->sizes[1]++;
+			Grid_SetSizes( grids[2][1], grids[topo->nDims][0]->sizes );
+			grids[topo->nDims][0]->sizes[1]--;
+
+			grids[2][2] = Grid_New();
+			Grid_SetNumDims( grids[2][2], topo->nDims );
+			grids[topo->nDims][0]->sizes[0]++;
+			Grid_SetSizes( grids[2][2], grids[topo->nDims][0]->sizes );
+			grids[topo->nDims][0]->sizes[0]--;
+		}
+	}
+
+	/* Generate topological elements. */
+	if( self->enabledDims[0] )
+		CartesianGenerator_GenVertices( self, topo, grids );
+	if( self->enabledDims[self->nDims] )
+		CartesianGenerator_GenElements( self, topo, grids );
+	if( topo->nDims >= 2 ) {
+		if( self->enabledDims[1] )
+			CartesianGenerator_GenEdges( self, topo, grids );
+		if( topo->nDims >= 3 ) {
+			if( self->enabledDims[2] )
+				CartesianGenerator_GenFaces( self, topo, grids );
+		}
+	}
+
+	/* Generate topological incidence. */
+	if( self->enabledInc[self->nDims][0] )
+		CartesianGenerator_GenElementVertexInc( self, topo, grids );
+	if( topo->nDims >= 2 ) {
+		if( self->enabledInc[2][1] )
+			CartesianGenerator_GenFaceEdgeInc( self, topo, grids );
+		if( self->enabledInc[1][0] )
+			CartesianGenerator_GenEdgeVertexInc( self, topo, grids );
+		if( topo->nDims >= 3 ) {
+			if( self->enabledInc[2][0] )
+				CartesianGenerator_GenFaceVertexInc( self, topo, grids );
+			if( self->enabledInc[3][1] )
+				CartesianGenerator_GenVolumeEdgeInc( self, topo, grids );
+			if( self->enabledInc[3][2] )
+				CartesianGenerator_GenVolumeFaceInc( self, topo, grids );
+		}
+	}
+
+	/* Set the shadow depth and correct incidence. */
+	comm = MeshTopology_GetComm( topo );
+	if( self->shadowDepth && Comm_GetNumNeighbours( comm ) > 0 ) {
+		/* Build enough incidence to set shadow depth. */
+		IGraph_InvertIncidence( topo, MT_VERTEX, topo->nDims );
+		IGraph_ExpandIncidence( topo, topo->nDims );
+
+		/* Set the shadow depth. */
+		MeshTopology_SetShadowDepth( topo, self->shadowDepth );
+
+		/* Kill up relations and neighbours. */
+		IGraph_RemoveIncidence( topo, topo->nDims, topo->nDims );
+		IGraph_RemoveIncidence( topo, 0, topo->nDims );
+	}
+
+	/* Complete all required relations. */
+	for( d_i = 0; d_i < (int)(self->nDims); d_i++ ) {
+          for( d_j = d_i + 1; d_j <= (int)(self->nDims); d_j++ ) {
+            if( !self->enabledInc[d_i][d_j] )
+              continue;
+
+            IGraph_InvertIncidence( topo, d_i, d_j );
+          }
+	}
+	for( d_i = 0; d_i <= (int)(self->nDims); d_i++ ) {
+		if( self->enabledInc[d_i][d_i] ) {
+			if( d_i == 0 )
+				CartesianGenerator_CompleteVertexNeighbours( self, topo, grids );
+			else {
+				IGraph_ExpandIncidence( topo, d_i );
+			}
+		}
+	}
+
+	/* Generate any boundary elements required. */
+	CartesianGenerator_GenBndVerts( self, topo, grids );
+
+	/* Free allocated grids. */
+	grids[topo->nDims][0] = NULL;
+	for( d_i = 1; d_i < topo->nDims; d_i++ ) {
+		int	d_j;
+
+		for( d_j = 0; d_j < (topo->nTDims); d_j++ )
+			FreeObject( grids[d_i][d_j] );
+	}
+	FreeArray( grids );
+}
+
+void CartesianGenerator_GenEdges2D( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
+	Grid*		globalGrid;
+	unsigned	nGlobalEls;
+	Grid*		grid;
+	unsigned	nEls[2];
+	unsigned*	els;
+	unsigned*	dimInds;
+	unsigned	d_i, e_i;
+
+	assert( self );
+	assert( topo );
+	assert( grids );
+	assert( self->elGrid->nDims == 2 );
+
+	globalGrid = Grid_New();
+	Grid_SetNumDims( globalGrid, self->elGrid->nDims );
+	self->elGrid->sizes[1]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[1]--;
+
+	grid = Grid_New();
+	Grid_SetNumDims( grid, self->elGrid->nDims );
+	self->range[1]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[1]--;
+
+	nEls[0] = grid->sizes[0];
+	nGlobalEls = globalGrid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
+		nEls[0] *= grid->sizes[d_i];
+		nGlobalEls *= globalGrid->sizes[d_i];
+	}
+	els = Memory_Alloc_Array_Unnamed( unsigned, nEls[0] );
+
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
+
+	for( e_i = 0; e_i < nEls[0]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[e_i] = Grid_Project( globalGrid, dimInds );
+	}
+
+	self->elGrid->sizes[0]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[0]--;
+
+	self->range[0]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[0]--;
+
+	nEls[1] = grid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ )
+		nEls[1] *= grid->sizes[d_i];
+	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] );
+
+	for( e_i = 0; e_i < nEls[1]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[nEls[0] + e_i] = nGlobalEls + Grid_Project( globalGrid, dimInds );
+	}
+
+	IGraph_SetElements( topo, MT_EDGE, nEls[0] + nEls[1], (int*)els );
+
+	FreeArray( dimInds );
+	FreeArray( els );
+	FreeObject( grid );
+	FreeObject( globalGrid );
+}
+
+void CartesianGenerator_GenEdges3D( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
+	Grid*		globalGrid;
+	unsigned	nGlobalEls[2];
+	Grid*		grid;
+	unsigned	nEls[3];
+	unsigned*	els;
+	unsigned*	dimInds;
+	unsigned	d_i, e_i;
+
+	assert( self );
+	assert( topo );
+	assert( grids );
+	assert( self->elGrid->nDims == 3 );
+
+	globalGrid = Grid_New();
+	Grid_SetNumDims( globalGrid, self->elGrid->nDims );
+	self->elGrid->sizes[1]++;
+	self->elGrid->sizes[2]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[1]--;
+	self->elGrid->sizes[2]--;
+
+	grid = Grid_New();
+	Grid_SetNumDims( grid, self->elGrid->nDims );
+	self->range[1]++;
+	self->range[2]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[1]--;
+	self->range[2]--;
+
+	nEls[0] = grid->sizes[0];
+	nGlobalEls[0] = globalGrid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
+		nEls[0] *= grid->sizes[d_i];
+		nGlobalEls[0] *= globalGrid->sizes[d_i];
+	}
+	els = Memory_Alloc_Array_Unnamed( unsigned, nEls[0] );
+
+	dimInds = Memory_Alloc_Array_Unnamed( unsigned, self->elGrid->nDims );
+
+	for( e_i = 0; e_i < nEls[0]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[e_i] = Grid_Project( globalGrid, dimInds );
+	}
+
+	self->elGrid->sizes[0]++;
+	self->elGrid->sizes[2]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[0]--;
+	self->elGrid->sizes[2]--;
+
+	self->range[0]++;
+	self->range[2]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[0]--;
+	self->range[2]--;
+
+	nEls[1] = grid->sizes[0];
+	nGlobalEls[1] = globalGrid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ ) {
+		nEls[1] *= grid->sizes[d_i];
+		nGlobalEls[1] *= globalGrid->sizes[d_i];
+	}
+	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] );
+
+	for( e_i = 0; e_i < nEls[1]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[nEls[0] + e_i] = nGlobalEls[0] + Grid_Project( globalGrid, dimInds );
+	}
+
+	self->elGrid->sizes[0]++;
+	self->elGrid->sizes[1]++;
+	Grid_SetSizes( globalGrid, self->elGrid->sizes );
+	self->elGrid->sizes[0]--;
+	self->elGrid->sizes[1]--;
+
+	self->range[0]++;
+	self->range[1]++;
+	Grid_SetSizes( grid, self->range );
+	self->range[0]--;
+	self->range[1]--;
+
+	nEls[2] = grid->sizes[0];
+	for( d_i = 1; d_i < grid->nDims; d_i++ )
+		nEls[2] *= grid->sizes[d_i];
+	els = Memory_Realloc_Array( els, unsigned, nEls[0] + nEls[1] + nEls[2] );
+
+	for( e_i = 0; e_i < nEls[2]; e_i++ ) {
+		Grid_Lift( grid, e_i, dimInds );
+		for( d_i = 0; d_i < grid->nDims; d_i++ )
+			dimInds[d_i] += self->origin[d_i];
+		els[nEls[0] + nEls[1] + e_i] = nGlobalEls[0] + nGlobalEls[1] + Grid_Project( globalGrid, dimInds );
+	}
+
+	IGraph_SetElements( topo, MT_EDGE, nEls[0] + nEls[1] + nEls[2],(int*)els);
+
+	FreeArray( dimInds );
+	FreeArray( els );
+	FreeObject( grid );
+	FreeObject( globalGrid );
+}
+
+void CartesianGenerator_GenBndVerts( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
+	IArray bndElsObj, *bndEls = &bndElsObj;
+	int nDims, nVerts, nBndEls;
+	const int* ptr;
+	int global;
+	int* inds;
+	const Sync* sync;
+	int v_i, d_i;
+
+	assert( self );
+	assert( topo );
+	assert( grids );
+
+	nDims = MeshTopology_GetNumDims( topo );
+	inds = Class_Array( self, int, nDims );
+	IArray_Construct( bndEls );
+	sync = IGraph_GetDomain( topo, 0 );
+	nVerts = Sync_GetNumDomains( sync );
+	for( v_i = 0; v_i < nVerts; v_i++ ) {
+		global = Sync_DomainToGlobal( sync, v_i );
+		Grid_Lift( grids[0][0], global, (unsigned*)inds );
+		for( d_i = 0; d_i < nDims; d_i++ ) {
+                  if( inds[d_i] == 0 || (unsigned)(inds[d_i]) == grids[0][0]->sizes[d_i] - 1 )
+				break;
+		}
+		if( d_i < nDims )
+			IArray_Append( bndEls, v_i );
+	}
+	Class_Free( self, inds );
+
+	IArray_GetArray( bndEls, &nBndEls, &ptr );
+	IGraph_SetBoundaryElements( topo, 0, nBndEls, ptr );
+	IArray_Destruct( bndEls );
+}
+
+void CartesianGenerator_CompleteVertexNeighbours( CartesianGenerator* self, IGraph* topo, Grid*** grids ) {
+   Stream*		stream = Journal_Register( Info_Type, (Name)self->type  );
+   const Sync* sync;
+   unsigned	nDims;
+   unsigned	nVerts;
+   unsigned*	inds;
+   unsigned	*nNbrs, **nbrs;
+   unsigned	domain, global;
+   unsigned	v_i;
+
+	assert( self );
+	assert( topo );
+	assert( grids );
+
+	Journal_Printf( stream, "Generating vertex neighbours...\n" );
+	Stream_Indent( stream );
+
+	nDims = topo->nDims;
+	sync = IGraph_GetDomain( topo, MT_VERTEX );
+	nVerts = Sync_GetNumDomains( sync );
+	inds = AllocArray( unsigned, nDims );
+	nNbrs = AllocArray( unsigned, nVerts );
+	nbrs = AllocArray2D( unsigned, nVerts, (nDims == 3) ? 6 : (nDims == 2) ? 4 : 2 );
+	for( v_i = 0; v_i < nVerts; v_i++ ) {
+		nNbrs[v_i] = 0;
+		global = Sync_DomainToGlobal( sync, v_i );
+		Grid_Lift( grids[0][0], global, inds );
+
+		if( inds[0] > 0 ) {
+			inds[0]--;
+			domain = Grid_Project( grids[0][0], inds );
+			if(Sync_TryGlobalToDomain(sync,domain,(int*)(&domain))) {
+				nbrs[v_i][nNbrs[v_i]] = domain;
+				nNbrs[v_i]++;
+			}
+			inds[0]++;
+		}
+
+		if( inds[0] < grids[0][0]->sizes[0] - 1 ) {
+			inds[0]++;
+			domain = Grid_Project( grids[0][0], inds );
+			if(Sync_TryGlobalToDomain(sync,domain,(int*)(&domain))) {
+				nbrs[v_i][nNbrs[v_i]] = domain;
+				nNbrs[v_i]++;
+			}
+			inds[0]--;
+		}
+
+		if( nDims >= 2 ) {
+			if( inds[1] > 0 ) {
+				inds[1]--;
+				domain = Grid_Project( grids[0][0], inds );
+				if(Sync_TryGlobalToDomain(sync,domain,
+                                                          (int*)(&domain))) {
+					nbrs[v_i][nNbrs[v_i]] = domain;
+					nNbrs[v_i]++;
+				}
+				inds[1]++;
+			}
+
+			if( inds[1] < grids[0][0]->sizes[1] - 1 ) {
+				inds[1]++;
+				domain = Grid_Project( grids[0][0], inds );
+				if(Sync_TryGlobalToDomain(sync,domain,
+                                                          (int*)(&domain))) {
+					nbrs[v_i][nNbrs[v_i]] = domain;
+					nNbrs[v_i]++;
+				}
+				inds[1]--;
+			}
+
+			if( nDims == 3 ) {
+				if( inds[2] > 0 ) {
+					inds[2]--;
+					domain = Grid_Project( grids[0][0], inds );
+					if(Sync_TryGlobalToDomain(sync,domain,
+                                                                  (int*)(&domain))) {
+						nbrs[v_i][nNbrs[v_i]] = domain;
+						nNbrs[v_i]++;
+					}
+					inds[2]++;
+				}
+
+				if( inds[2] < grids[0][0]->sizes[2] - 1 ) {
+					inds[2]++;
+					domain = Grid_Project( grids[0][0], inds );
+					if(Sync_TryGlobalToDomain(sync,domain,
+                                                                  (int*)(&domain))) {
+						nbrs[v_i][nNbrs[v_i]] = domain;
+						nNbrs[v_i]++;
+					}
+					inds[2]--;
+				}
+			}
+		}
+
+		IGraph_SetIncidence(topo,MT_VERTEX,v_i,MT_VERTEX,nNbrs[v_i],
+                                    (int*)(nbrs[v_i]));
+	}
+
+	FreeArray( nNbrs );
+	FreeArray( nbrs );
+	FreeArray( inds );
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void CartesianGenerator_MapToDomain( CartesianGenerator* self,
+                                     const Sync* sync, 
+				     unsigned nIncEls, unsigned* incEls )
+{
+	unsigned	inc_i;
+
+	assert( self );
+	assert( sync );
+	assert( nIncEls );
+	assert( incEls );
+
+	for( inc_i = 0; inc_i < nIncEls; inc_i++ )
+		incEls[inc_i] = Sync_GlobalToDomain( sync, incEls[inc_i] );
+}
+
+#define MAX_LINE_LENGTH 1024
+void CartesianGenerator_GenGeom( CartesianGenerator* self, Mesh* mesh, void* data ) {
+	Stream*			   stream = Journal_Register( Info_Type, (Name)self->type );
+	Sync*			      sync;
+	AbstractContext* 	context = (AbstractContext*)data;
+	
+	assert( self );
+	assert( mesh  );
+
+	Journal_Printf( stream, "Generating geometry...\n" );
+	Stream_Indent( stream );
+
+	/* Allocate for coordinates. */
+	sync = (Sync*)IGraph_GetDomain( (IGraph*)mesh->topo, 0 );
+	mesh->verts = AllocNamedArray2D( double, Sync_GetNumDomains( sync ), 
+					 mesh->topo->nDims, 
+					 "Mesh::verts" );
+
+	if( context && context->restartTimestep && context->timeStep == context->restartTimestep && self->readFromFile) {
+      char*  meshReadFileName;
+      char*  meshReadFileNamePart;   
+
+      meshReadFileNamePart = Context_GetCheckPointReadPrefixString( context );
+#ifdef READ_HDF5
+      Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.h5", meshReadFileNamePart, self->meshes[0]->name, context->restartTimestep );
+      Journal_Printf( stream, "... loading from file %s.\n", meshReadFileName );
+      CartesianGenerator_ReadFromHDF5( self, mesh, meshReadFileName );
+#else
+      Stg_asprintf( &meshReadFileName, "%sMesh.%s.%.5u.dat", meshReadFileNamePart, self->meshes[0]->name, context->restartTimestep );
+      Journal_Printf( stream, "... loading from file %s.\n", meshReadFileName );
+      CartesianGenerator_ReadFromASCII( self, mesh, meshReadFileName);      
+#endif
+      Memory_Free( meshReadFileName );
+      Memory_Free( meshReadFileNamePart );
+      Mesh_Sync( mesh );
+      
+	} else { 
+      Grid*			      grid;
+      unsigned*		   inds;
+      double*			   steps;
+      int          d_i;
+
+      /* Build grid and space for indices. */
+      grid = self->vertGrid;
+      inds = Memory_Alloc_Array_Unnamed( unsigned, mesh->topo->nDims );
+
+      /* Calculate steps. */
+      steps = Memory_Alloc_Array_Unnamed( double, mesh->topo->nDims );
+      for( d_i = 0; d_i < mesh->topo->nDims; d_i++ )
+         steps[d_i] = self->crdMax[d_i] - self->crdMin[d_i];
+   
+      CartesianGenerator_CalcGeom( self, mesh, sync, grid, inds, steps );
+      
+      /* Free resources. */
+      FreeArray( inds );
+      FreeArray( steps );
+	}
+
+
+	MPI_Barrier( self->mpiComm );
+	Journal_Printf( stream, "... done.\n" );
+	Stream_UnIndent( stream );
+}
+
+void CartesianGenerator_CalcGeom( CartesianGenerator* self, Mesh* mesh, Sync* sync, Grid* grid, unsigned* inds, double* steps ) {	
+	unsigned		n_i, d_i;
+	double*         	vert;
+	unsigned        	gNode;
+
+	/* Loop over domain nodes. */
+	for( n_i = 0; n_i < (unsigned)Sync_GetNumDomains( sync ); n_i++ ) {
+		gNode = Sync_DomainToGlobal( sync, n_i );
+		Grid_Lift( grid, gNode, inds );
+		vert = Mesh_GetVertex( mesh, n_i );
+
+		/* Calculate coordinate. */
+		for( d_i = 0; d_i < (unsigned)(mesh->topo->nDims); d_i++ ) {
+                  if( inds[d_i] <= (unsigned)(self->contactDepth[d_i][0]) ) {
+                      mesh->verts[n_i][d_i] = self->crdMin[d_i];
+                      if( self->contactDepth[d_i][0] ) {
+                         mesh->verts[n_i][d_i] +=
+                            ((double)inds[d_i] / (double)self->contactDepth[d_i][0]) *
+                            self->contactGeom[d_i];
+                      }
+                   }
+                   else if( inds[d_i] >= grid->sizes[d_i] - self->contactDepth[d_i][1] - 1 ) {
+                      mesh->verts[n_i][d_i] = self->crdMax[d_i];
+                      if( self->contactDepth[d_i][1] ) {
+                         mesh->verts[n_i][d_i] -=
+                            ((double)(grid->sizes[d_i] - 1 - inds[d_i]) /
+                             (double)self->contactDepth[d_i][1]) *
+                            self->contactGeom[d_i];
+                      }
+                   }
+                   else {
+                      vert[d_i] = self->crdMin[d_i] + (self->contactDepth[d_i][0] ? self->contactGeom[d_i] : 0.0) +
+                         ((double)(inds[d_i] - self->contactDepth[d_i][0]) / 
+                          (double)(grid->sizes[d_i] - (self->contactDepth[d_i][0] + self->contactDepth[d_i][1]) - 1)) *
+                         (steps[d_i] - ((self->contactDepth[d_i][1] ? 1.0 : 0.0) + (self->contactDepth[d_i][0] ? 1.0 : 0.0)) * self->contactGeom[d_i]);
+                   }
+		}
+	}
+}
+
+void CartesianGenerator_Destruct( CartesianGenerator* self ) {
+	assert( self );
+
+	CartesianGenerator_DestructTopology( self );
+	CartesianGenerator_DestructGeometry( self );
+	KillArray( self->minDecomp );
+	KillArray( self->maxDecomp );
+	NewClass_RemoveRef( self->comm );
+}
+
+void CartesianGenerator_DestructTopology( CartesianGenerator* self ) {
+	assert( self );
+
+	self->maxDecompDims = 0;
+	memset( self->minDecomp, 0, self->nDims * sizeof(unsigned) );
+	memset( self->maxDecomp, 0, self->nDims * sizeof(unsigned) );
+	FreeObject( self->vertGrid );
+	FreeObject( self->elGrid );
+	FreeObject( self->procGrid );
+	KillArray( self->origin );
+	KillArray( self->range );
+	KillArray( self->vertOrigin );
+	KillArray( self->vertRange );
+}
+
+void CartesianGenerator_DestructGeometry( CartesianGenerator* self ) {
+	assert( self );
+
+	FreeArray( self->crdMin );
+	FreeArray( self->crdMax );
+}
+
+#ifdef READ_HDF5
+void CartesianGenerator_ReadFromHDF5(  CartesianGenerator* self, Mesh* mesh, Name filename ){
+	hid_t             file, fileSpace, fileData;
+	hsize_t           start[2], count[2], size[2], maxSize[2];   
+	hid_t             memSpace, error;
+	double            buf[4];
+   Node_LocalIndex   lNode_I = 0;
+	Node_GlobalIndex  gNode_I = 0;
+   int               totalVerts, ii;
+   unsigned int		noffset;
+   MeshCheckpointFileVersion ver;
+   hid_t					attrib_id, group_id;
+   herr_t				status;
+   char*					verticeName;
+	Stream*			   errorStream = Journal_Register( Error_Type, (Name)self->type  );   
+
+   /* Open the file and data set. */
+   file = H5Fopen( filename, H5F_ACC_RDONLY, H5P_DEFAULT );
+
+   /** get the file attributes to sanity and version checks */
+   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+      group_id  = H5Gopen(file, "/");
+      attrib_id = H5Aopen_name(group_id, "checkpoint file version");
+   #else
+      group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
+      attrib_id = H5Aopen(group_id, "checkpoint file version", H5P_DEFAULT);
+   #endif
+   /** if this attribute does not exist (attrib_id < 0) then we assume MeshCHECKPOINT_V1 and continue without checking attributes */
+   if(attrib_id < 0)
+      ver = MeshCHECKPOINT_V1;
+   else {
+      int checkVer;
+      int ndims;
+      int res[self->nDims];
+      unsigned*  sizes;
+
+      /** check for known checkpointing version type */
+
+      status = H5Aread(attrib_id, H5T_NATIVE_INT, &checkVer);
+      H5Aclose(attrib_id);
+      if(checkVer == 2)
+         ver = MeshCHECKPOINT_V2;
+      else
+         Journal_Firewall( (0), errorStream,
+            "\n\nError in %s for %s '%s'\n"
+            "Unknown checkpoint version (%u) for checkpoint file (%s).\n", 
+            __func__, self->type, self->name, (unsigned int) checkVer, filename);
+
+      /** check for correct number of dimensions */
+
+      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+         attrib_id = H5Aopen_name(group_id, "dimensions");
+      #else
+         attrib_id = H5Aopen(group_id, "dimensions", H5P_DEFAULT);
+      #endif
+      status = H5Aread(attrib_id, H5T_NATIVE_INT, &ndims);
+      H5Aclose(attrib_id);      
+      Journal_Firewall( (ndims == (int)(self->nDims)), errorStream,
+         "\n\nError in %s for %s '%s'\n"
+         "Number of dimensions (%u) for checkpoint file (%s) does not correspond to simulation dimensions (%u).\n", 
+         __func__, self->type, self->name, (unsigned int) ndims, filename,
+         self->nDims);
+
+      /** check for correct mesh size */
+      
+      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+         attrib_id = H5Aopen_name(group_id, "mesh resolution");
+      #else
+         attrib_id = H5Aopen(group_id, "mesh resolution", H5P_DEFAULT);
+      #endif
+      status = H5Aread(attrib_id, H5T_NATIVE_INT, &res);
+      H5Aclose(attrib_id);
+
+      sizes = Grid_GetSizes( self->elGrid ); /** global no. of elements in each dim */
+      if(self->nDims == 2)
+         Journal_Firewall(((sizes[0] == (unsigned)(res[0]))
+                           && (sizes[1] == (unsigned)(res[1])) ), 
+            errorStream,
+            "\n\nError in %s for %s '%s'\n"
+            "Size of mesh (%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u, %u).\n", 
+            __func__, self->type, self->name, 
+            (unsigned int) res[0], (unsigned int) res[1],
+            filename,
+            (unsigned int) sizes[0], (unsigned int) sizes[1]);
+      else
+         Journal_Firewall( 
+                          ( (sizes[0] == (unsigned)(res[0]))
+                            && (sizes[1] == (unsigned)(res[1]))
+                            && (sizes[2] == (unsigned)(res[2])) ), 
+            errorStream,
+            "\n\nError in %s for %s '%s'\n"
+            "Size of mesh (%u,%u,%u) for checkpoint file (%s) does not correspond to simulation mesh size (%u,%u,%u).\n", 
+            __func__, self->type, self->name, 
+            (unsigned int) res[0], (unsigned int) res[1], (unsigned int) res[2],
+            filename,
+            (unsigned int) sizes[0], (unsigned int) sizes[1], (unsigned int) sizes[2]);
+   }
+   H5Gclose(group_id);
+   
+   /** account for different versions of checkpointing */
+   switch ( ver ) {
+      case MeshCHECKPOINT_V1:
+         noffset = 1;
+         Stg_asprintf( &verticeName, "/data" );
+         break;
+      case MeshCHECKPOINT_V2:
+         noffset = 0;
+         Stg_asprintf( &verticeName, "/vertices" );
+         break;
+      default:
+         Journal_Firewall( 0, errorStream,
+            "Error: in %s: unknown checkpoint file version.\n",
+            __func__ ); 
+   }
+   
+   /* Prepare to read vertices from file */		
+   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+   fileData = H5Dopen( file, verticeName );
+   #else
+   fileData = H5Dopen2( file, verticeName, H5P_DEFAULT );
+   #endif
+   fileSpace = H5Dget_space( fileData );
+   Memory_Free( verticeName );
+   start[1] = 0;
+   count[0] = 1;
+   count[1] = mesh->topo->nDims + noffset;
+   memSpace = H5Screate_simple( 2, count, NULL );
+   totalVerts = Mesh_GetGlobalSize( mesh, (MeshTopology_Dim)0 );
+
+   /* Get size of dataspace to check consistency */
+   H5Sget_simple_extent_dims( fileSpace, size, maxSize ); 
+
+   Journal_Firewall( 
+                    (maxSize[0] == (unsigned)totalVerts), 
+      errorStream,
+      "\n\nError in %s for %s '%s'\n"
+      "Number of mesh vertices (%u) stored in %s does not correspond to total number of requested mesh vertices (%u).\n", 
+      __func__, 
+      self->type, 
+      self->name, 
+      (unsigned int)maxSize[0],
+      filename,
+      totalVerts);
+
+   for( ii=0; ii<totalVerts; ii++ ) {   
+      start[0] = ii;
+            
+      H5Sselect_hyperslab( fileSpace, H5S_SELECT_SET, start, NULL, count, NULL );
+      H5Sselect_all( memSpace );
+      
+      error = H5Dread( fileData, H5T_NATIVE_DOUBLE, memSpace, fileSpace, H5P_DEFAULT, buf );
+      gNode_I = ii;
+
+      Journal_Firewall( 
+         error >= 0, 
+         errorStream,
+         "\n\nError in %s for %s '%s' - Cannot read data in %s.\n", 
+         __func__, 
+         self->type, 
+         self->name, 
+         filename );
+      
+      if( Mesh_GlobalToDomain( mesh, MT_VERTEX, gNode_I, &lNode_I ) && 
+          lNode_I < Mesh_GetLocalSize( mesh, MT_VERTEX ) )
+      {
+         double *vert;
+
+         vert = Mesh_GetVertex( mesh, lNode_I );
+         vert[0] = buf[0 + noffset];
+         vert[1] = buf[1 + noffset];
+         if( mesh->topo->nDims ==3 )
+            vert[2] = buf[2 + noffset];
+      }
+   }
+         
+   /* Close handles */
+   H5Sclose( memSpace );
+   H5Sclose( fileSpace );
+   H5Dclose( fileData );
+   H5Fclose( file );
+   
+}
+#endif
+
+void CartesianGenerator_ReadFromASCII( CartesianGenerator* self, Mesh* mesh, Name filename ){
+   int               proc_I;
+	Node_LocalIndex   lNode_I = 0;
+	Node_GlobalIndex  gNode_I = 0;
+	FILE*             inputFile;
+	char              lineString[MAX_LINE_LENGTH];
+	int			      rank, nRanks;
+
+   MPI_Comm_rank( self->mpiComm, &rank );
+   MPI_Comm_size( self->mpiComm, &nRanks );
+
+   /* This loop used to stop 2 processors trying to open the file at the same time, which
+   * seems to cause problems */
+   for ( proc_I = 0; proc_I < nRanks; proc_I++ ) {
+      MPI_Barrier( self->mpiComm );
+      if ( proc_I == rank ) {
+         /* Do the following since in parallel on some systems, the file
+          * doesn't get re-opened at the start automatically. */
+         inputFile = fopen( filename, "r" );
+
+         rewind( inputFile );
+      }
+   }
+   
+   fgets( lineString, MAX_LINE_LENGTH, inputFile );
+   fgets( lineString, MAX_LINE_LENGTH, inputFile );
+
+   while ( !feof(inputFile) ) {
+      fscanf( inputFile, "%u ", &gNode_I );
+      if( Mesh_GlobalToDomain( mesh, MT_VERTEX, gNode_I, &lNode_I ) && 
+          lNode_I < Mesh_GetLocalSize( mesh, MT_VERTEX ) )
+      {
+         double crds[3];
+         double *vert;
+
+         fscanf( inputFile, "%lg %lg %lg ", crds, crds + 1, crds + 2 );
+         vert = Mesh_GetVertex( mesh, lNode_I );
+         vert[0] = crds[0];
+         if( self->nDims >= 2 )
+            vert[1] = crds[1];
+         if( self->nDims >=3 )
+            vert[2] = crds[2];
+      }
+      else {
+         fgets( lineString, MAX_LINE_LENGTH, inputFile );
+      }
+   }
+
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/CompressionAdaptor.c
--- a/Mesh/src/CompressionAdaptor.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,223 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: CompressionAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Grid.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "IGraph.h"
-#include "MeshClass.h"
-#include "MeshGenerator.h"
-#include "MeshAdaptor.h"
-#include "CompressionAdaptor.h"
-
-
-typedef double (CompressionAdaptor_DeformFunc)( CompressionAdaptor* self, Mesh* mesh, 
-					    unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
-
-
-/* Textual name of this class */
-const Type CompressionAdaptor_Type = "CompressionAdaptor";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-CompressionAdaptor* CompressionAdaptor_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(CompressionAdaptor);
-	Type                                                      type = CompressionAdaptor_Type;
-	Stg_Class_DeleteFunction*                              _delete = _CompressionAdaptor_Delete;
-	Stg_Class_PrintFunction*                                _print = _CompressionAdaptor_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_CompressionAdaptor_New;
-	Stg_Component_ConstructFunction*                    _construct = _CompressionAdaptor_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _CompressionAdaptor_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _CompressionAdaptor_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _CompressionAdaptor_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _CompressionAdaptor_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	MeshGenerator_SetDimSizeFunc*                   setDimSizeFunc = _MeshGenerator_SetDimSize;
-	MeshGenerator_GenerateFunc*                       generateFunc = CompressionAdaptor_Generate;
-
-	CompressionAdaptor* self = _CompressionAdaptor_New(  COMPRESSIONADAPTOR_PASSARGS  );
-   
-   _MeshGenerator_Init( (MeshGenerator*)self, context );
-   _MeshAdaptor_Init( (MeshAdaptor*)self );
-	/* CompressionAdaptor info */
-	_CompressionAdaptor_Init( self );
-
-   return self;
-}
-
-CompressionAdaptor* _CompressionAdaptor_New(  COMPRESSIONADAPTOR_DEFARGS  ) {
-	CompressionAdaptor* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(CompressionAdaptor) );
-	self = (CompressionAdaptor*)_MeshAdaptor_New(  MESHADAPTOR_PASSARGS  );
-
-	/* Virtual info */
-	return self;
-}
-
-void _CompressionAdaptor_Init( CompressionAdaptor* self ) {
-	self->compressionfactor  = 0.0;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _CompressionAdaptor_Delete( void* adaptor ) {
-	CompressionAdaptor*	self = (CompressionAdaptor*)adaptor;
-
-	/* Delete the parent. */
-	_MeshAdaptor_Delete( self );
-}
-
-void _CompressionAdaptor_Print( void* adaptor, Stream* stream ) {
-	CompressionAdaptor*	self = (CompressionAdaptor*)adaptor;
-	
-	/* Set the Journal for printing informations */
-	Stream* adaptorStream;
-	adaptorStream = Journal_Register( InfoStream_Type, (Name)"CompressionAdaptorStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "CompressionAdaptor (ptr): (%p)\n", self );
-	_MeshAdaptor_Print( self, stream );
-}
-
-void _CompressionAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
-	CompressionAdaptor*	self = (CompressionAdaptor*)adaptor;
-
-	assert( self );
-	assert( cf );
-
-	/* Call parent construct. */
-	_MeshAdaptor_AssignFromXML( self, cf, data );
-
-	self->compressionfactor = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"compressionfactor", 0.0 );
-	if(self->compressionfactor == 0.0){
-		printf("cannot have a zero compression factor exiting program\n");
-		abort( );
-	}
-}
-
-void _CompressionAdaptor_Build( void* adaptor, void* data ) {
-	_MeshAdaptor_Build( adaptor, data );
-}
-
-void _CompressionAdaptor_Initialise( void* adaptor, void* data ) {
-	_MeshAdaptor_Initialise( adaptor, data );
-}
-
-void _CompressionAdaptor_Execute( void* adaptor, void* data ) {
-	_MeshAdaptor_Execute( adaptor, data );
-}
-
-void _CompressionAdaptor_Destroy( void* adaptor, void* data ) {
-	_MeshAdaptor_Destroy( adaptor, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void CompressionAdaptor_Generate( void* adaptor, void* _mesh, void* data ) {
-	CompressionAdaptor*		self = (CompressionAdaptor*)adaptor;
-	Mesh*				mesh = (Mesh*)_mesh;
-	const Sync*			sync;
-	Grid				*grid;
-	unsigned*			inds;
-	double				min,max[3],min2[3];
-	unsigned			gNode;
-	double				x,b;
-	unsigned			d_i, n_i;
-
-	/* Build base mesh, which is assumed to be cartesian. */
-	MeshGenerator_Generate( self->generator, mesh, data );
-
-	/* If we're not 2D or 3D, forget about it. */
-	if( mesh->topo->nDims != 2 && mesh->topo->nDims != 3 )
-		return;
-
-	/* Extract the cartesian information. */
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-	inds = AllocArray( unsigned, Mesh_GetDimSize( mesh ) );
-        
-	//get factor b so that there is always a 1 to 1 relationship with the top position normally and top position when compressed
-	Mesh_GetGlobalCoordRange( mesh, min2, max);
-	b = (max[1] - min2[1])/(pow((max[1] - min2[1]), (1.0/self->compressionfactor)));
-	for( d_i = 0; d_i < Mesh_GetDimSize( mesh ); d_i++ )
-		inds[d_i] = 0;
-	gNode = Grid_Project( grid, inds );
-	insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, gNode, &gNode ), == True );
-	min = mesh->verts[gNode][1];
-
-	/* Loop over domain nodes. */
-	sync = IGraph_GetDomain( mesh->topo, MT_VERTEX );
-	for( n_i = 0; n_i < (unsigned)Sync_GetNumDomains( sync ); n_i++ ) {
-		gNode = Sync_DomainToGlobal( sync, n_i );
-		Grid_Lift( grid, gNode, inds );
-
-		/* Deform this node. */
-		x = mesh->verts[n_i][1] - min;
-		//a compressionfactor function, eg if compression factor = 3 then would be a cubed root function
-		mesh->verts[n_i][1] = b*(pow(x, (1.0/self->compressionfactor)));
-	}
-
-	/* Free resources. */
-	FreeArray( inds );
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/CompressionAdaptor.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/CompressionAdaptor.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,223 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: CompressionAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Grid.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "IGraph.h"
+#include "MeshClass.h"
+#include "MeshGenerator.h"
+#include "MeshAdaptor.h"
+#include "CompressionAdaptor.h"
+
+
+typedef double (CompressionAdaptor_DeformFunc)( CompressionAdaptor* self, Mesh* mesh, 
+					    unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
+
+
+/* Textual name of this class */
+const Type CompressionAdaptor_Type = "CompressionAdaptor";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+CompressionAdaptor* CompressionAdaptor_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(CompressionAdaptor);
+	Type                                                      type = CompressionAdaptor_Type;
+	Stg_Class_DeleteFunction*                              _delete = _CompressionAdaptor_Delete;
+	Stg_Class_PrintFunction*                                _print = _CompressionAdaptor_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_CompressionAdaptor_New;
+	Stg_Component_ConstructFunction*                    _construct = _CompressionAdaptor_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _CompressionAdaptor_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _CompressionAdaptor_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _CompressionAdaptor_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _CompressionAdaptor_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	MeshGenerator_SetDimSizeFunc*                   setDimSizeFunc = _MeshGenerator_SetDimSize;
+	MeshGenerator_GenerateFunc*                       generateFunc = CompressionAdaptor_Generate;
+
+	CompressionAdaptor* self = _CompressionAdaptor_New(  COMPRESSIONADAPTOR_PASSARGS  );
+   
+   _MeshGenerator_Init( (MeshGenerator*)self, context );
+   _MeshAdaptor_Init( (MeshAdaptor*)self );
+	/* CompressionAdaptor info */
+	_CompressionAdaptor_Init( self );
+
+   return self;
+}
+
+CompressionAdaptor* _CompressionAdaptor_New(  COMPRESSIONADAPTOR_DEFARGS  ) {
+	CompressionAdaptor* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(CompressionAdaptor) );
+	self = (CompressionAdaptor*)_MeshAdaptor_New(  MESHADAPTOR_PASSARGS  );
+
+	/* Virtual info */
+	return self;
+}
+
+void _CompressionAdaptor_Init( CompressionAdaptor* self ) {
+	self->compressionfactor  = 0.0;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _CompressionAdaptor_Delete( void* adaptor ) {
+	CompressionAdaptor*	self = (CompressionAdaptor*)adaptor;
+
+	/* Delete the parent. */
+	_MeshAdaptor_Delete( self );
+}
+
+void _CompressionAdaptor_Print( void* adaptor, Stream* stream ) {
+	CompressionAdaptor*	self = (CompressionAdaptor*)adaptor;
+	
+	/* Set the Journal for printing informations */
+	Stream* adaptorStream;
+	adaptorStream = Journal_Register( InfoStream_Type, (Name)"CompressionAdaptorStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "CompressionAdaptor (ptr): (%p)\n", self );
+	_MeshAdaptor_Print( self, stream );
+}
+
+void _CompressionAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
+	CompressionAdaptor*	self = (CompressionAdaptor*)adaptor;
+
+	assert( self );
+	assert( cf );
+
+	/* Call parent construct. */
+	_MeshAdaptor_AssignFromXML( self, cf, data );
+
+	self->compressionfactor = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"compressionfactor", 0.0 );
+	if(self->compressionfactor == 0.0){
+		printf("cannot have a zero compression factor exiting program\n");
+		abort( );
+	}
+}
+
+void _CompressionAdaptor_Build( void* adaptor, void* data ) {
+	_MeshAdaptor_Build( adaptor, data );
+}
+
+void _CompressionAdaptor_Initialise( void* adaptor, void* data ) {
+	_MeshAdaptor_Initialise( adaptor, data );
+}
+
+void _CompressionAdaptor_Execute( void* adaptor, void* data ) {
+	_MeshAdaptor_Execute( adaptor, data );
+}
+
+void _CompressionAdaptor_Destroy( void* adaptor, void* data ) {
+	_MeshAdaptor_Destroy( adaptor, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void CompressionAdaptor_Generate( void* adaptor, void* _mesh, void* data ) {
+	CompressionAdaptor*		self = (CompressionAdaptor*)adaptor;
+	Mesh*				mesh = (Mesh*)_mesh;
+	const Sync*			sync;
+	Grid				*grid;
+	unsigned*			inds;
+	double				min,max[3],min2[3];
+	unsigned			gNode;
+	double				x,b;
+	unsigned			d_i, n_i;
+
+	/* Build base mesh, which is assumed to be cartesian. */
+	MeshGenerator_Generate( self->generator, mesh, data );
+
+	/* If we're not 2D or 3D, forget about it. */
+	if( mesh->topo->nDims != 2 && mesh->topo->nDims != 3 )
+		return;
+
+	/* Extract the cartesian information. */
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+	inds = AllocArray( unsigned, Mesh_GetDimSize( mesh ) );
+        
+	//get factor b so that there is always a 1 to 1 relationship with the top position normally and top position when compressed
+	Mesh_GetGlobalCoordRange( mesh, min2, max);
+	b = (max[1] - min2[1])/(pow((max[1] - min2[1]), (1.0/self->compressionfactor)));
+	for( d_i = 0; d_i < Mesh_GetDimSize( mesh ); d_i++ )
+		inds[d_i] = 0;
+	gNode = Grid_Project( grid, inds );
+	insist( Mesh_GlobalToDomain( mesh, MT_VERTEX, gNode, &gNode ), == True );
+	min = mesh->verts[gNode][1];
+
+	/* Loop over domain nodes. */
+	sync = IGraph_GetDomain( mesh->topo, MT_VERTEX );
+	for( n_i = 0; n_i < (unsigned)Sync_GetNumDomains( sync ); n_i++ ) {
+		gNode = Sync_DomainToGlobal( sync, n_i );
+		Grid_Lift( grid, gNode, inds );
+
+		/* Deform this node. */
+		x = mesh->verts[n_i][1] - min;
+		//a compressionfactor function, eg if compression factor = 3 then would be a cubed root function
+		mesh->verts[n_i][1] = b*(pow(x, (1.0/self->compressionfactor)));
+	}
+
+	/* Free resources. */
+	FreeArray( inds );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Decomp.c
--- a/Mesh/src/Decomp.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,404 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Decomp.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <mpi.h>
-#include "StGermain/StGermain.h"
-#include "types.h"
-#include "Decomp.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-void Decomp_Update( Decomp* self );
-void Decomp_UpdateOwnerMap( Decomp* self );
-
-
-int stgCmpIntNE( const void* l, const void* r ) {
-   assert( *(int*)l != *(int*)r );
-   return (*(int*)l < *(int*)r) ? -1 : 1;
-}
-
-
-void _Decomp_Init( void* _self ) {
-   Decomp* self = (Decomp*)_self;
-
-   _NewClass_Init( self );
-   self->mpiComm = MPI_COMM_WORLD;
-   self->nGlobals = 0;
-   self->locals = &self->localsObj;
-   IArray_Construct( self->locals );
-   self->inv = &self->invObj;
-   IMap_Construct( self->inv );
-   self->rngBegin = 0;
-   self->rngEnd = 0;
-   self->owners = &self->ownersObj;
-   IMap_Construct( self->owners );
-}
-
-void _Decomp_Destruct( void* _self ) {
-   Decomp* self = (Decomp*)_self;
-
-   Decomp_Clear( self );
-   IArray_Destruct( self->locals );
-   IMap_Destruct( self->inv );
-   IMap_Destruct( self->owners );
-   _NewClass_Destruct( self );
-}
-
-void _Decomp_Copy( void* _self, const void* _op ) {
-   Decomp* self = (Decomp*)_self;
-   const Decomp* op = (const Decomp*)_op;
-
-   assert( self && op );
-   self->mpiComm = op->mpiComm;
-   self->nGlobals = op->nGlobals;
-   IArray_Copy( self->locals, op->locals );
-   IMap_Copy( self->inv, op->inv );
-}
-
-SizeT _Decomp_CalcMem( const void* _self, PtrMap* ptrs ) {
-   const Decomp* self = (const Decomp*)_self;
-   SizeT mem;
-
-   if( PtrMap_Find( ptrs, (void*)self ) )
-      return 0;
-   mem = _NewClass_CalcMem( self, ptrs );
-   mem += NewClass_CalcMem( self->locals, ptrs );
-   mem += NewClass_CalcMem( self->inv, ptrs );
-   return mem;
-}
-
-void Decomp_SetMPIComm( void* _self, MPI_Comm mpiComm ) {
-   Decomp* self = (Decomp*)_self;
-
-   assert( self );
-   self->mpiComm = mpiComm;
-}
-
-void Decomp_SetLocals( void* _self, int nLocals, const int* locals ) {
-   Decomp* self = (Decomp*)_self;
-   int l_i;
-
-   assert( self && (!nLocals || locals) );
-   IArray_Set( self->locals, nLocals, locals );
-   Decomp_Update( self );
-   IMap_Clear( self->inv );
-   IMap_SetMaxSize( self->inv, nLocals );
-   for( l_i = 0; l_i < nLocals; l_i++ )
-      IMap_Insert( self->inv, locals[l_i], l_i );
-}
-
-void Decomp_AddLocals( void* _self, int nLocals, const int* locals ) {
-   Decomp* self = (Decomp*)_self;
-   int l_i;
-
-   assert( self && (!nLocals || locals) );
-   IMap_SetMaxSize( self->inv, IArray_GetSize( self->locals ) + nLocals );
-   IArray_Add( self->locals, nLocals, locals );
-   Decomp_Update( self );
-   for( l_i = 0; l_i < nLocals; l_i++ )
-      IMap_Insert( self->inv, locals[l_i], l_i );
-}
-
-void Decomp_RemoveLocals( void* _self, int nLocals, const int* locals, IMap* map ) {
-   Decomp* self = (Decomp*)_self;
-   int oldSize;
-   int l_i;
-
-   assert( self && (!nLocals || locals) );
-   oldSize = IArray_GetSize( self->locals );
-   IArray_Remove( self->locals, nLocals, locals, map );
-   Decomp_Update( self );
-   for( l_i = 0; l_i < nLocals; l_i++ )
-      IMap_Remove( self->inv, locals[l_i] );
-   IMap_SetMaxSize( self->inv, oldSize - nLocals );
-}
-
-void Decomp_Clear( void* _self ) {
-   Decomp* self = (Decomp*)_self;
-
-   Decomp_ClearLocals( self );
-   self->mpiComm = MPI_COMM_WORLD;
-   self->nGlobals = 0;
-}
-
-void Decomp_ClearLocals( void* _self ) {
-   Decomp* self = (Decomp*)_self;
-
-   assert( self );
-   IArray_Clear( self->locals );
-   IMap_Clear( self->inv );
-   self->rngBegin = 0;
-   self->rngEnd = 0;
-   IMap_Clear( self->owners );
-}
-
-MPI_Comm Decomp_GetComm( const void* self ) {
-   assert( self );
-   return ((Decomp*)self)->mpiComm;
-}
-
-MPI_Comm Decomp_GetMPIComm( const void* self ) {
-   assert( Class_IsSuper( self, Decomp ) );
-   return ((Decomp*)self)->mpiComm;
-}
-
-int Decomp_GetNumGlobals( const void* self ) {
-   assert( self );
-   return ((Decomp*)self)->nGlobals;
-}
-
-int Decomp_GetNumLocals( const void* self ) {
-   assert( self );
-   return IArray_GetSize( ((Decomp*)self)->locals );
-}
-
-void Decomp_GetLocals( const void* self, int* nLocals, const int** locals ) {
-   assert( self );
-   *nLocals = IArray_GetSize( ((Decomp*)self)->locals );
-   *locals = IArray_GetPtr( ((Decomp*)self)->locals );
-}
-
-int Decomp_LocalToGlobal( const void* self, int local ) {
-   assert( self && local < IArray_GetSize( ((Decomp*)self)->locals ) );
-   return IArray_GetPtr( ((Decomp*)self)->locals )[local];
-}
-
-int Decomp_GlobalToLocal( const void* self, int global ) {
-   assert( self && global < ((Decomp*)self)->nGlobals );
-   return IMap_Map( ((Decomp*)self)->inv, global );
-}
-
-Bool Decomp_TryGlobalToLocal( const void* self, int global, int* local ) {
-   assert( self && global < ((Decomp*)self)->nGlobals );
-   return IMap_TryMap( ((Decomp*)self)->inv, global, local );
-}
-
-void Decomp_FindOwners( const void* _self, int nGlobals, const int* globals, 
-		       int* ranks )
-{
-   const Decomp* self = Class_Cast( _self, Decomp );
-   IMap ordMapObj, *ordMap = &ordMapObj;
-   int rangeSize;
-   int *ord;
-   int **ptrs, *sizes;
-   int begin, end, len, pos, ind;
-   int *recvSizes, **recvArrays;
-   int *remSizes, **remRanks;
-   int nRanks, rank;
-   int g_i, r_i, i_i;
-
-   assert( !nGlobals || globals );
-   assert( !nGlobals || ranks );
-
-   insist( MPI_Comm_size( self->mpiComm, &nRanks ), == MPI_SUCCESS );
-   insist( MPI_Comm_rank( self->mpiComm, &rank ), == MPI_SUCCESS );
-
-   IMap_Construct( ordMap );
-   IMap_SetMaxSize( ordMap, nGlobals );
-   for( g_i = 0; g_i < nGlobals; g_i++ )
-      IMap_Insert( ordMap, globals[g_i], g_i );
-   ord = Class_Array( self, int, nGlobals );
-   memcpy( ord, globals, nGlobals * sizeof(int) );
-   qsort( ord, nGlobals, sizeof(int), stgCmpIntNE );
-
-   ptrs = Class_Array( self, int*, nRanks );
-   sizes = Class_Array( self, int, nRanks );
-
-   rangeSize = self->nGlobals / nRanks;
-   if( rank < self->nGlobals % nRanks )
-      rangeSize++;
-
-   pos = 0;
-   begin = end = 0;
-   for( r_i = 0; r_i < nRanks; r_i++ ) {
-      end += self->nGlobals / nRanks;
-      if( r_i < self->nGlobals % nRanks )
-	 end++;
-
-      if( pos < nGlobals && ord[pos] >= begin && ord[pos] < end ) {
-	 len = 0;
-	 while( pos + len < nGlobals && ord[pos + len] < end ) {
-	    if( r_i == rank ) {
-	       ind = IMap_Map( ordMap, ord[pos + len] );
-	       ranks[ind] = IMap_Map( self->owners, ord[pos + len] );
-	    }
-	    len++;
-	 }
-	 if( r_i != rank ) {
-	    ptrs[r_i] = ord + pos;
-	    sizes[r_i] = len;
-	 }
-	 else {
-	    ptrs[r_i] = NULL;
-	    sizes[r_i] = 0;
-	 }
-	 pos += len;
-      }
-      else {
-	 ptrs[r_i] = NULL;
-	 sizes[r_i] = 0;
-      }
-
-      begin = end;
-   }
-
-   MPIArray_Alltoall( (unsigned*)sizes, (void**)ptrs, 
-		      (unsigned**)&recvSizes, (void***)&recvArrays, 
-		      sizeof(int), self->mpiComm );
-
-   for( r_i = 0; r_i < nRanks; r_i++ ) {
-      for( i_i = 0; i_i < recvSizes[r_i]; i_i++ )
-	 recvArrays[r_i][i_i] = IMap_Map( self->owners, recvArrays[r_i][i_i] );
-   }
-
-   MPIArray_Alltoall( (unsigned*)recvSizes, (void**)recvArrays, 
-		      (unsigned**)&remSizes, (void***)&remRanks, 
-		      sizeof(int), self->mpiComm );
-   MemFree( recvSizes );
-   for( r_i = 0; r_i < nRanks; r_i++ )
-      MemFree( recvArrays[r_i] );
-   MemFree( recvArrays );
-
-   for( r_i = 0; r_i < nRanks; r_i++ ) {
-      for( i_i = 0; i_i < remSizes[r_i]; i_i++ ) {
-	 ind = IMap_Map( ordMap, ptrs[r_i][i_i] );
-	 ranks[ind] = remRanks[r_i][i_i];
-      }
-      MemFree( remRanks[r_i] );
-   }
-   IMap_Destruct( ordMap );
-   MemFree( remRanks );
-   MemFree( remSizes );
-   Class_Free( self, sizes );
-   Class_Free( self, ptrs );
-   Class_Free( self, ord );
-}
-
-void Decomp_Update( Decomp* self ) {
-   int nLocals;
-
-   assert( self );
-   if( self->mpiComm ) {
-      nLocals = IArray_GetSize( self->locals );
-      insist( MPI_Allreduce( &nLocals, &self->nGlobals, 1, MPI_INT, MPI_SUM, 
-			     self->mpiComm ), == MPI_SUCCESS );
-   }
-   else
-      self->nGlobals = 0;
-
-   Decomp_UpdateOwnerMap( self );
-}
-
-void Decomp_UpdateOwnerMap( Decomp* self ) {
-   int rangeSize;
-   int nLocals;
-   const int *locals;
-   int *ord;
-   int **ptrs, *sizes;
-   int begin, end, len, pos;
-   int *recvSizes, **recvArrays;
-   int nRanks, rank;
-   int r_i, i_i;
-
-   assert( Class_IsSuper( self, Decomp ) );
-
-   insist( MPI_Comm_size( self->mpiComm, &nRanks ), == MPI_SUCCESS );
-   insist( MPI_Comm_rank( self->mpiComm, &rank ), == MPI_SUCCESS );
-
-   IArray_GetArray( self->locals, &nLocals, &locals );
-   ord = Class_Array( self, int, nLocals );
-   memcpy( ord, locals, nLocals * sizeof(int) );
-   qsort( ord, nLocals, sizeof(int), stgCmpIntNE );
-
-   ptrs = Class_Array( self, int*, nRanks );
-   sizes = Class_Array( self, int, nRanks );
-
-   rangeSize = self->nGlobals / nRanks;
-   if( rank < self->nGlobals % nRanks )
-      rangeSize++;
-   IMap_Clear( self->owners );
-   IMap_SetMaxSize( self->owners, rangeSize );
-
-   pos = 0;
-   begin = end = 0;
-   for( r_i = 0; r_i < nRanks; r_i++ ) {
-      end += self->nGlobals / nRanks;
-      if( r_i < self->nGlobals % nRanks )
-	 end++;
-      if( r_i == rank ) {
-	 self->rngBegin = begin;
-	 self->rngEnd = end;
-      }
-
-      if( pos < nLocals && ord[pos] >= begin && ord[pos] < end ) {
-	 len = 0;
-	 while( pos + len < nLocals && ord[pos + len] < end ) {
-	    if( r_i == rank )
-	       IMap_Insert( self->owners, ord[pos + len], r_i );
-	    len++;
-	 }
-	 if( r_i != rank ) {
-	    ptrs[r_i] = ord + pos;
-	    sizes[r_i] = len;
-	 }
-	 else {
-	    ptrs[r_i] = NULL;
-	    sizes[r_i] = 0;
-	 }
-	 pos += len;
-      }
-      else {
-	 ptrs[r_i] = NULL;
-	 sizes[r_i] = 0;
-      }
-
-      begin = end;
-   }
-
-   MPIArray_Alltoall( (unsigned*)sizes, (void**)ptrs, 
-		      (unsigned**)&recvSizes, (void***)&recvArrays, 
-		      sizeof(int), self->mpiComm );
-   Class_Free( self, sizes );
-   Class_Free( self, ptrs );
-   Class_Free( self, ord );
-
-   for( r_i = 0; r_i < nRanks; r_i++ ) {
-      for( i_i = 0; i_i < recvSizes[r_i]; i_i++ )
-	 IMap_Insert( self->owners, recvArrays[r_i][i_i], r_i );
-      MemFree( recvArrays[r_i] );
-   }
-   MemFree( recvSizes );
-   MemFree( recvArrays );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Decomp.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Decomp.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,404 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Decomp.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <mpi.h>
+#include "StGermain/StGermain.h"
+#include "types.h"
+#include "Decomp.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+void Decomp_Update( Decomp* self );
+void Decomp_UpdateOwnerMap( Decomp* self );
+
+
+int stgCmpIntNE( const void* l, const void* r ) {
+   assert( *(int*)l != *(int*)r );
+   return (*(int*)l < *(int*)r) ? -1 : 1;
+}
+
+
+void _Decomp_Init( void* _self ) {
+   Decomp* self = (Decomp*)_self;
+
+   _NewClass_Init( self );
+   self->mpiComm = MPI_COMM_WORLD;
+   self->nGlobals = 0;
+   self->locals = &self->localsObj;
+   IArray_Construct( self->locals );
+   self->inv = &self->invObj;
+   IMap_Construct( self->inv );
+   self->rngBegin = 0;
+   self->rngEnd = 0;
+   self->owners = &self->ownersObj;
+   IMap_Construct( self->owners );
+}
+
+void _Decomp_Destruct( void* _self ) {
+   Decomp* self = (Decomp*)_self;
+
+   Decomp_Clear( self );
+   IArray_Destruct( self->locals );
+   IMap_Destruct( self->inv );
+   IMap_Destruct( self->owners );
+   _NewClass_Destruct( self );
+}
+
+void _Decomp_Copy( void* _self, const void* _op ) {
+   Decomp* self = (Decomp*)_self;
+   const Decomp* op = (const Decomp*)_op;
+
+   assert( self && op );
+   self->mpiComm = op->mpiComm;
+   self->nGlobals = op->nGlobals;
+   IArray_Copy( self->locals, op->locals );
+   IMap_Copy( self->inv, op->inv );
+}
+
+SizeT _Decomp_CalcMem( const void* _self, PtrMap* ptrs ) {
+   const Decomp* self = (const Decomp*)_self;
+   SizeT mem;
+
+   if( PtrMap_Find( ptrs, (void*)self ) )
+      return 0;
+   mem = _NewClass_CalcMem( self, ptrs );
+   mem += NewClass_CalcMem( self->locals, ptrs );
+   mem += NewClass_CalcMem( self->inv, ptrs );
+   return mem;
+}
+
+void Decomp_SetMPIComm( void* _self, MPI_Comm mpiComm ) {
+   Decomp* self = (Decomp*)_self;
+
+   assert( self );
+   self->mpiComm = mpiComm;
+}
+
+void Decomp_SetLocals( void* _self, int nLocals, const int* locals ) {
+   Decomp* self = (Decomp*)_self;
+   int l_i;
+
+   assert( self && (!nLocals || locals) );
+   IArray_Set( self->locals, nLocals, locals );
+   Decomp_Update( self );
+   IMap_Clear( self->inv );
+   IMap_SetMaxSize( self->inv, nLocals );
+   for( l_i = 0; l_i < nLocals; l_i++ )
+      IMap_Insert( self->inv, locals[l_i], l_i );
+}
+
+void Decomp_AddLocals( void* _self, int nLocals, const int* locals ) {
+   Decomp* self = (Decomp*)_self;
+   int l_i;
+
+   assert( self && (!nLocals || locals) );
+   IMap_SetMaxSize( self->inv, IArray_GetSize( self->locals ) + nLocals );
+   IArray_Add( self->locals, nLocals, locals );
+   Decomp_Update( self );
+   for( l_i = 0; l_i < nLocals; l_i++ )
+      IMap_Insert( self->inv, locals[l_i], l_i );
+}
+
+void Decomp_RemoveLocals( void* _self, int nLocals, const int* locals, IMap* map ) {
+   Decomp* self = (Decomp*)_self;
+   int oldSize;
+   int l_i;
+
+   assert( self && (!nLocals || locals) );
+   oldSize = IArray_GetSize( self->locals );
+   IArray_Remove( self->locals, nLocals, locals, map );
+   Decomp_Update( self );
+   for( l_i = 0; l_i < nLocals; l_i++ )
+      IMap_Remove( self->inv, locals[l_i] );
+   IMap_SetMaxSize( self->inv, oldSize - nLocals );
+}
+
+void Decomp_Clear( void* _self ) {
+   Decomp* self = (Decomp*)_self;
+
+   Decomp_ClearLocals( self );
+   self->mpiComm = MPI_COMM_WORLD;
+   self->nGlobals = 0;
+}
+
+void Decomp_ClearLocals( void* _self ) {
+   Decomp* self = (Decomp*)_self;
+
+   assert( self );
+   IArray_Clear( self->locals );
+   IMap_Clear( self->inv );
+   self->rngBegin = 0;
+   self->rngEnd = 0;
+   IMap_Clear( self->owners );
+}
+
+MPI_Comm Decomp_GetComm( const void* self ) {
+   assert( self );
+   return ((Decomp*)self)->mpiComm;
+}
+
+MPI_Comm Decomp_GetMPIComm( const void* self ) {
+   assert( Class_IsSuper( self, Decomp ) );
+   return ((Decomp*)self)->mpiComm;
+}
+
+int Decomp_GetNumGlobals( const void* self ) {
+   assert( self );
+   return ((Decomp*)self)->nGlobals;
+}
+
+int Decomp_GetNumLocals( const void* self ) {
+   assert( self );
+   return IArray_GetSize( ((Decomp*)self)->locals );
+}
+
+void Decomp_GetLocals( const void* self, int* nLocals, const int** locals ) {
+   assert( self );
+   *nLocals = IArray_GetSize( ((Decomp*)self)->locals );
+   *locals = IArray_GetPtr( ((Decomp*)self)->locals );
+}
+
+int Decomp_LocalToGlobal( const void* self, int local ) {
+   assert( self && local < IArray_GetSize( ((Decomp*)self)->locals ) );
+   return IArray_GetPtr( ((Decomp*)self)->locals )[local];
+}
+
+int Decomp_GlobalToLocal( const void* self, int global ) {
+   assert( self && global < ((Decomp*)self)->nGlobals );
+   return IMap_Map( ((Decomp*)self)->inv, global );
+}
+
+Bool Decomp_TryGlobalToLocal( const void* self, int global, int* local ) {
+   assert( self && global < ((Decomp*)self)->nGlobals );
+   return IMap_TryMap( ((Decomp*)self)->inv, global, local );
+}
+
+void Decomp_FindOwners( const void* _self, int nGlobals, const int* globals, 
+		       int* ranks )
+{
+   const Decomp* self = Class_Cast( _self, Decomp );
+   IMap ordMapObj, *ordMap = &ordMapObj;
+   int rangeSize;
+   int *ord;
+   int **ptrs, *sizes;
+   int begin, end, len, pos, ind;
+   int *recvSizes, **recvArrays;
+   int *remSizes, **remRanks;
+   int nRanks, rank;
+   int g_i, r_i, i_i;
+
+   assert( !nGlobals || globals );
+   assert( !nGlobals || ranks );
+
+   insist( MPI_Comm_size( self->mpiComm, &nRanks ), == MPI_SUCCESS );
+   insist( MPI_Comm_rank( self->mpiComm, &rank ), == MPI_SUCCESS );
+
+   IMap_Construct( ordMap );
+   IMap_SetMaxSize( ordMap, nGlobals );
+   for( g_i = 0; g_i < nGlobals; g_i++ )
+      IMap_Insert( ordMap, globals[g_i], g_i );
+   ord = Class_Array( self, int, nGlobals );
+   memcpy( ord, globals, nGlobals * sizeof(int) );
+   qsort( ord, nGlobals, sizeof(int), stgCmpIntNE );
+
+   ptrs = Class_Array( self, int*, nRanks );
+   sizes = Class_Array( self, int, nRanks );
+
+   rangeSize = self->nGlobals / nRanks;
+   if( rank < self->nGlobals % nRanks )
+      rangeSize++;
+
+   pos = 0;
+   begin = end = 0;
+   for( r_i = 0; r_i < nRanks; r_i++ ) {
+      end += self->nGlobals / nRanks;
+      if( r_i < self->nGlobals % nRanks )
+	 end++;
+
+      if( pos < nGlobals && ord[pos] >= begin && ord[pos] < end ) {
+	 len = 0;
+	 while( pos + len < nGlobals && ord[pos + len] < end ) {
+	    if( r_i == rank ) {
+	       ind = IMap_Map( ordMap, ord[pos + len] );
+	       ranks[ind] = IMap_Map( self->owners, ord[pos + len] );
+	    }
+	    len++;
+	 }
+	 if( r_i != rank ) {
+	    ptrs[r_i] = ord + pos;
+	    sizes[r_i] = len;
+	 }
+	 else {
+	    ptrs[r_i] = NULL;
+	    sizes[r_i] = 0;
+	 }
+	 pos += len;
+      }
+      else {
+	 ptrs[r_i] = NULL;
+	 sizes[r_i] = 0;
+      }
+
+      begin = end;
+   }
+
+   MPIArray_Alltoall( (unsigned*)sizes, (void**)ptrs, 
+		      (unsigned**)&recvSizes, (void***)&recvArrays, 
+		      sizeof(int), self->mpiComm );
+
+   for( r_i = 0; r_i < nRanks; r_i++ ) {
+      for( i_i = 0; i_i < recvSizes[r_i]; i_i++ )
+	 recvArrays[r_i][i_i] = IMap_Map( self->owners, recvArrays[r_i][i_i] );
+   }
+
+   MPIArray_Alltoall( (unsigned*)recvSizes, (void**)recvArrays, 
+		      (unsigned**)&remSizes, (void***)&remRanks, 
+		      sizeof(int), self->mpiComm );
+   MemFree( recvSizes );
+   for( r_i = 0; r_i < nRanks; r_i++ )
+      MemFree( recvArrays[r_i] );
+   MemFree( recvArrays );
+
+   for( r_i = 0; r_i < nRanks; r_i++ ) {
+      for( i_i = 0; i_i < remSizes[r_i]; i_i++ ) {
+	 ind = IMap_Map( ordMap, ptrs[r_i][i_i] );
+	 ranks[ind] = remRanks[r_i][i_i];
+      }
+      MemFree( remRanks[r_i] );
+   }
+   IMap_Destruct( ordMap );
+   MemFree( remRanks );
+   MemFree( remSizes );
+   Class_Free( self, sizes );
+   Class_Free( self, ptrs );
+   Class_Free( self, ord );
+}
+
+void Decomp_Update( Decomp* self ) {
+   int nLocals;
+
+   assert( self );
+   if( self->mpiComm ) {
+      nLocals = IArray_GetSize( self->locals );
+      insist( MPI_Allreduce( &nLocals, &self->nGlobals, 1, MPI_INT, MPI_SUM, 
+			     self->mpiComm ), == MPI_SUCCESS );
+   }
+   else
+      self->nGlobals = 0;
+
+   Decomp_UpdateOwnerMap( self );
+}
+
+void Decomp_UpdateOwnerMap( Decomp* self ) {
+   int rangeSize;
+   int nLocals;
+   const int *locals;
+   int *ord;
+   int **ptrs, *sizes;
+   int begin, end, len, pos;
+   int *recvSizes, **recvArrays;
+   int nRanks, rank;
+   int r_i, i_i;
+
+   assert( Class_IsSuper( self, Decomp ) );
+
+   insist( MPI_Comm_size( self->mpiComm, &nRanks ), == MPI_SUCCESS );
+   insist( MPI_Comm_rank( self->mpiComm, &rank ), == MPI_SUCCESS );
+
+   IArray_GetArray( self->locals, &nLocals, &locals );
+   ord = Class_Array( self, int, nLocals );
+   memcpy( ord, locals, nLocals * sizeof(int) );
+   qsort( ord, nLocals, sizeof(int), stgCmpIntNE );
+
+   ptrs = Class_Array( self, int*, nRanks );
+   sizes = Class_Array( self, int, nRanks );
+
+   rangeSize = self->nGlobals / nRanks;
+   if( rank < self->nGlobals % nRanks )
+      rangeSize++;
+   IMap_Clear( self->owners );
+   IMap_SetMaxSize( self->owners, rangeSize );
+
+   pos = 0;
+   begin = end = 0;
+   for( r_i = 0; r_i < nRanks; r_i++ ) {
+      end += self->nGlobals / nRanks;
+      if( r_i < self->nGlobals % nRanks )
+	 end++;
+      if( r_i == rank ) {
+	 self->rngBegin = begin;
+	 self->rngEnd = end;
+      }
+
+      if( pos < nLocals && ord[pos] >= begin && ord[pos] < end ) {
+	 len = 0;
+	 while( pos + len < nLocals && ord[pos + len] < end ) {
+	    if( r_i == rank )
+	       IMap_Insert( self->owners, ord[pos + len], r_i );
+	    len++;
+	 }
+	 if( r_i != rank ) {
+	    ptrs[r_i] = ord + pos;
+	    sizes[r_i] = len;
+	 }
+	 else {
+	    ptrs[r_i] = NULL;
+	    sizes[r_i] = 0;
+	 }
+	 pos += len;
+      }
+      else {
+	 ptrs[r_i] = NULL;
+	 sizes[r_i] = 0;
+      }
+
+      begin = end;
+   }
+
+   MPIArray_Alltoall( (unsigned*)sizes, (void**)ptrs, 
+		      (unsigned**)&recvSizes, (void***)&recvArrays, 
+		      sizeof(int), self->mpiComm );
+   Class_Free( self, sizes );
+   Class_Free( self, ptrs );
+   Class_Free( self, ord );
+
+   for( r_i = 0; r_i < nRanks; r_i++ ) {
+      for( i_i = 0; i_i < recvSizes[r_i]; i_i++ )
+	 IMap_Insert( self->owners, recvArrays[r_i][i_i], r_i );
+      MemFree( recvArrays[r_i] );
+   }
+   MemFree( recvSizes );
+   MemFree( recvArrays );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Finalise.c
--- a/Mesh/src/Finalise.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool StgDomainMesh_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Finalise.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,49 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool StgDomainMesh_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Grid.c
--- a/Mesh/src/Grid.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,296 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Grid.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Grid.h"
-
-
-/* Textual name of this class */
-const Type Grid_Type = "Grid";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Grid* Grid_New() {
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(Grid);
-	Type                              type = Grid_Type;
-	Stg_Class_DeleteFunction*      _delete = _Grid_Delete;
-	Stg_Class_PrintFunction*        _print = _Grid_Print;
-	Stg_Class_CopyFunction*          _copy = NULL;
-
-	return _Grid_New(  GRID_PASSARGS  );
-}
-
-Grid* _Grid_New(  GRID_DEFARGS  ) {
-	Grid*	self;
-
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Grid) );
-	self = (Grid*)_Stg_Class_New(  STG_CLASS_PASSARGS  );
-
-	/* Virtual info */
-
-	/* Grid info */
-	_Grid_Init( self );
-
-	return self;
-}
-
-void _Grid_Init( Grid* self ) {
-	self->nDims = 0;
-	self->sizes = NULL;
-	self->basis = NULL;
-	self->nPoints = 0;
-
-	self->map = NULL;
-	self->invMap = NULL;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Grid_Delete( void* grid ) {
-	Grid*	self = (Grid*)grid;
-
-	FreeArray( self->sizes );
-	FreeArray( self->basis );
-
-	/* Delete the parent. */
-	_Stg_Class_Delete( self );
-}
-
-void _Grid_Print( void* grid, Stream* stream ) {
-	Grid*	self = (Grid*)grid;
-
-	/* Set the Journal for printing informations */
-	Stream* gridStream;
-	gridStream = Journal_Register( InfoStream_Type, (Name)"GridStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Grid (ptr): (%p)\n", self );
-	_Stg_Class_Print( self, stream );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void Grid_SetNumDims( void* grid, unsigned nDims ) {
-	Grid*	self = (Grid*)grid;
-
-	/* Sanity check. */
-	assert( self );
-
-	/* If we're changing dimensions, kill everything and begin again. */
-	KillArray( self->sizes );
-	KillArray( self->basis );
-
-	/* Set dimensions. */
-	self->nDims = nDims;
-}
-
-void Grid_SetSizes( void* grid, unsigned* sizes ) {
-	Grid*	self = (Grid*)grid;
-
-	/* Sanity check. */
-	assert( self );
-	assert( !self->nDims || sizes );
-#ifndef NDEBUG
-	{
-		unsigned	d_i;
-
-		for( d_i = 0; d_i < self->nDims; d_i++ )
-			assert( sizes[d_i] );
-	}
-#endif
-
-	KillArray( self->sizes );
-	KillArray( self->basis );
-
-	/* Copy the sizes, allocate arrays and build basis. */
-	if( self->nDims ) {
-		unsigned	d_i;
-
-      if(self->sizes) FreeArray( self->sizes );
-      if(self->basis) FreeArray( self->basis );
-		   
-		self->sizes = Memory_Alloc_Array( unsigned, self->nDims, "Grid::sizes" );
-		self->basis = Memory_Alloc_Array( unsigned, self->nDims, "Grid::basis" );
-		memcpy( self->sizes, sizes, self->nDims * sizeof(unsigned) );
-
-		/* Build basis. */
-		self->basis[0] = 1;
-		self->nPoints = sizes[0];
-		for( d_i = 1; d_i < self->nDims; d_i++ ) {
-			self->basis[d_i] = self->basis[d_i - 1] * self->sizes[d_i - 1];
-			self->nPoints *= sizes[d_i];
-		}
-	}
-}
-
-void Grid_SetMapping( void* grid, HashTable* mapping, HashTable* inverse ) {
-	Grid*	self = (Grid*)grid;
-
-	assert( self );
-
-	self->map = mapping;
-	self->invMap = inverse;
-}
-
-unsigned Grid_GetNumDims( void* grid ) {
-	Grid*	self = (Grid*)grid;
-
-	assert( self );
-
-	return self->nDims;
-}
-
-unsigned* Grid_GetSizes( void* grid ) {
-	Grid*	self = (Grid*)grid;
-
-	assert( self );
-
-	return self->sizes;
-}
-
-unsigned Grid_GetNumPoints( void* grid ) {
-	Grid*	self = (Grid*)grid;
-
-	assert( self );
-
-	return self->nPoints;
-}
-
-void Grid_GetMapping( void* grid, HashTable** mapping, HashTable** inverse ) {
-	Grid*	self = (Grid*)grid;
-
-	assert( self );
-
-	*mapping = self->map;
-	*inverse = self->invMap;
-}
-
-void Grid_Lift( void* grid, unsigned ind, unsigned* params ) {
-	Grid*		self = (Grid*)grid;
-	unsigned	rem;
-	unsigned	d_i;
-
-	/* Sanity check. */
-	assert( self );
-	assert( self->nDims );
-	assert( self->sizes && self->basis );
-	assert( params );
-
-	/*
-	** Take a one dimensional array index and lift it into a regular mesh topological
-	** space.
-	*/
-
-	if( self->map ) {
-#ifndef NDEBUG
-		unsigned*	remPtr;
-
-		assert( remPtr = HashTable_FindEntry( self->map, &ind, sizeof(unsigned), unsigned ) );
-		rem = *remPtr;
-#else
-		rem = *HashTable_FindEntry( self->map, &ind, sizeof(unsigned), unsigned );
-#endif
-	}
-	else
-		rem = ind;
-
-	for( d_i = self->nDims; d_i > 0; d_i-- ) {
-		unsigned	dimInd = d_i - 1;
-		div_t		divRes;
-
-		divRes = div( rem, self->basis[dimInd] );
-		params[dimInd] = divRes.quot;
-		rem = divRes.rem;
-
-		/* Ensure this is a valid lifting. */
-		assert( params[dimInd] < self->sizes[dimInd] );
-	}
-}
-
-unsigned Grid_Project( void* grid, unsigned* params ) {
-	Grid*		self = (Grid*)grid;
-	unsigned	ind = 0;
-	unsigned	d_i;
-
-	/* Sanity check. */
-	assert( self );
-	assert( self->nDims );
-	assert( self->sizes && self->basis );
-	assert( params );
-
-	/*
-	** Project an n-dimensional set of topological indices into a one-dimensional, unique space.
-	*/
-
-	for( d_i = 0; d_i < self->nDims; d_i++ ) {
-		assert( params[d_i] < self->sizes[d_i] );
-		ind += params[d_i] * self->basis[d_i];
-	}
-
-	if( self->invMap ) {
-#ifndef NDEBUG
-		unsigned*	indPtr;
-
-		assert( indPtr = HashTable_FindEntry( self->invMap, &ind, sizeof(unsigned), unsigned ) );
-		ind = *indPtr;
-#else
-		ind = *HashTable_FindEntry( self->invMap, &ind, sizeof(unsigned), unsigned );
-#endif
-	}
-
-	return ind;
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Grid.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Grid.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,296 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Grid.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Grid.h"
+
+
+/* Textual name of this class */
+const Type Grid_Type = "Grid";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Grid* Grid_New() {
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(Grid);
+	Type                              type = Grid_Type;
+	Stg_Class_DeleteFunction*      _delete = _Grid_Delete;
+	Stg_Class_PrintFunction*        _print = _Grid_Print;
+	Stg_Class_CopyFunction*          _copy = NULL;
+
+	return _Grid_New(  GRID_PASSARGS  );
+}
+
+Grid* _Grid_New(  GRID_DEFARGS  ) {
+	Grid*	self;
+
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Grid) );
+	self = (Grid*)_Stg_Class_New(  STG_CLASS_PASSARGS  );
+
+	/* Virtual info */
+
+	/* Grid info */
+	_Grid_Init( self );
+
+	return self;
+}
+
+void _Grid_Init( Grid* self ) {
+	self->nDims = 0;
+	self->sizes = NULL;
+	self->basis = NULL;
+	self->nPoints = 0;
+
+	self->map = NULL;
+	self->invMap = NULL;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Grid_Delete( void* grid ) {
+	Grid*	self = (Grid*)grid;
+
+	FreeArray( self->sizes );
+	FreeArray( self->basis );
+
+	/* Delete the parent. */
+	_Stg_Class_Delete( self );
+}
+
+void _Grid_Print( void* grid, Stream* stream ) {
+	Grid*	self = (Grid*)grid;
+
+	/* Set the Journal for printing informations */
+	Stream* gridStream;
+	gridStream = Journal_Register( InfoStream_Type, (Name)"GridStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Grid (ptr): (%p)\n", self );
+	_Stg_Class_Print( self, stream );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Grid_SetNumDims( void* grid, unsigned nDims ) {
+	Grid*	self = (Grid*)grid;
+
+	/* Sanity check. */
+	assert( self );
+
+	/* If we're changing dimensions, kill everything and begin again. */
+	KillArray( self->sizes );
+	KillArray( self->basis );
+
+	/* Set dimensions. */
+	self->nDims = nDims;
+}
+
+void Grid_SetSizes( void* grid, unsigned* sizes ) {
+	Grid*	self = (Grid*)grid;
+
+	/* Sanity check. */
+	assert( self );
+	assert( !self->nDims || sizes );
+#ifndef NDEBUG
+	{
+		unsigned	d_i;
+
+		for( d_i = 0; d_i < self->nDims; d_i++ )
+			assert( sizes[d_i] );
+	}
+#endif
+
+	KillArray( self->sizes );
+	KillArray( self->basis );
+
+	/* Copy the sizes, allocate arrays and build basis. */
+	if( self->nDims ) {
+		unsigned	d_i;
+
+      if(self->sizes) FreeArray( self->sizes );
+      if(self->basis) FreeArray( self->basis );
+		   
+		self->sizes = Memory_Alloc_Array( unsigned, self->nDims, "Grid::sizes" );
+		self->basis = Memory_Alloc_Array( unsigned, self->nDims, "Grid::basis" );
+		memcpy( self->sizes, sizes, self->nDims * sizeof(unsigned) );
+
+		/* Build basis. */
+		self->basis[0] = 1;
+		self->nPoints = sizes[0];
+		for( d_i = 1; d_i < self->nDims; d_i++ ) {
+			self->basis[d_i] = self->basis[d_i - 1] * self->sizes[d_i - 1];
+			self->nPoints *= sizes[d_i];
+		}
+	}
+}
+
+void Grid_SetMapping( void* grid, HashTable* mapping, HashTable* inverse ) {
+	Grid*	self = (Grid*)grid;
+
+	assert( self );
+
+	self->map = mapping;
+	self->invMap = inverse;
+}
+
+unsigned Grid_GetNumDims( void* grid ) {
+	Grid*	self = (Grid*)grid;
+
+	assert( self );
+
+	return self->nDims;
+}
+
+unsigned* Grid_GetSizes( void* grid ) {
+	Grid*	self = (Grid*)grid;
+
+	assert( self );
+
+	return self->sizes;
+}
+
+unsigned Grid_GetNumPoints( void* grid ) {
+	Grid*	self = (Grid*)grid;
+
+	assert( self );
+
+	return self->nPoints;
+}
+
+void Grid_GetMapping( void* grid, HashTable** mapping, HashTable** inverse ) {
+	Grid*	self = (Grid*)grid;
+
+	assert( self );
+
+	*mapping = self->map;
+	*inverse = self->invMap;
+}
+
+void Grid_Lift( void* grid, unsigned ind, unsigned* params ) {
+	Grid*		self = (Grid*)grid;
+	unsigned	rem;
+	unsigned	d_i;
+
+	/* Sanity check. */
+	assert( self );
+	assert( self->nDims );
+	assert( self->sizes && self->basis );
+	assert( params );
+
+	/*
+	** Take a one dimensional array index and lift it into a regular mesh topological
+	** space.
+	*/
+
+	if( self->map ) {
+#ifndef NDEBUG
+		unsigned*	remPtr;
+
+		assert( remPtr = HashTable_FindEntry( self->map, &ind, sizeof(unsigned), unsigned ) );
+		rem = *remPtr;
+#else
+		rem = *HashTable_FindEntry( self->map, &ind, sizeof(unsigned), unsigned );
+#endif
+	}
+	else
+		rem = ind;
+
+	for( d_i = self->nDims; d_i > 0; d_i-- ) {
+		unsigned	dimInd = d_i - 1;
+		div_t		divRes;
+
+		divRes = div( rem, self->basis[dimInd] );
+		params[dimInd] = divRes.quot;
+		rem = divRes.rem;
+
+		/* Ensure this is a valid lifting. */
+		assert( params[dimInd] < self->sizes[dimInd] );
+	}
+}
+
+unsigned Grid_Project( void* grid, unsigned* params ) {
+	Grid*		self = (Grid*)grid;
+	unsigned	ind = 0;
+	unsigned	d_i;
+
+	/* Sanity check. */
+	assert( self );
+	assert( self->nDims );
+	assert( self->sizes && self->basis );
+	assert( params );
+
+	/*
+	** Project an n-dimensional set of topological indices into a one-dimensional, unique space.
+	*/
+
+	for( d_i = 0; d_i < self->nDims; d_i++ ) {
+		assert( params[d_i] < self->sizes[d_i] );
+		ind += params[d_i] * self->basis[d_i];
+	}
+
+	if( self->invMap ) {
+#ifndef NDEBUG
+		unsigned*	indPtr;
+
+		assert( indPtr = HashTable_FindEntry( self->invMap, &ind, sizeof(unsigned), unsigned ) );
+		ind = *indPtr;
+#else
+		ind = *HashTable_FindEntry( self->invMap, &ind, sizeof(unsigned), unsigned );
+#endif
+	}
+
+	return ind;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/IGraph.c
--- a/Mesh/src/IGraph.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1018 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: IGraph.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include "StGermain/StGermain.h"
-#include "types.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "IGraph.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-void IGraph_PickleIncidenceInit( IGraph* self, int dim, int nEls, int* els, int* nBytes );
-void IGraph_PickleIncidence( IGraph* self, int dim, int nEls, int* els, stgByte* bytes );
-void IGraph_UnpickleIncidence( IGraph* self, int dim, int nBytes, stgByte* bytes );
-int IGraph_Cmp( const void* l, const void* r );
-
-
-void _IGraph_Init( void* _self ) {
-   IGraph* self = (IGraph*)_self;
-
-   _MeshTopology_Init( self );
-   self->nDims = (MeshTopology_Dim)0;
-   self->nTDims = 0;
-   self->shadDepth = 0;
-   self->comm = NULL;
-   self->locals = NULL;
-   self->remotes = NULL;
-   self->nBndEls = NULL;
-   self->bndEls = NULL;
-   self->nIncEls = NULL;
-   self->incEls = NULL;
-}
-
-void _IGraph_Destruct( void* _self ) {
-   IGraph* self = (IGraph*)_self;
-
-   IGraph_Clear( self );
-   _MeshTopology_Destruct( self );
-}
-
-void _IGraph_Copy( void* _self, const void* op ) {
-   /*IGraph* self = (IGraph*)_self;*/
-
-   assert( 0 );
-   /* TODO */
-}
-
-SizeT _IGraph_CalcMem( const void* _self, PtrMap* ptrs ) {
-   IGraph* self = (IGraph*)_self;
-   SizeT mem;
-   int d_i;
-
-   if( PtrMap_Find( ptrs, (void*)self ) )
-      return 0;
-   mem = _MeshTopology_CalcMem( self, ptrs );
-
-	for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-      if( self->locals )
-			mem += NewClass_CalcMem( self->locals[d_i], ptrs );
-		if( self->remotes )
-			mem += NewClass_CalcMem( self->remotes[d_i], ptrs );
-   }
-   return mem;
-}
-
-void _IGraph_SetNumDims( void* _self, int nDims ) {
-   IGraph* self = (IGraph*)_self;
-   int d_i;
-
-   IGraph_ClearDims( self );
-   _MeshTopology_SetNumDims( self, nDims );
-
-   self->locals = Class_Array( self, Decomp*, self->nTDims );
-   self->remotes = Class_Array( self, Sync*, self->nTDims );
-   self->nIncEls = Class_Array2D( self, int*, self->nTDims, self->nTDims );
-   self->incEls = Class_Array2D( self, int**, self->nTDims, self->nTDims );
-
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-		self->locals[d_i] = Decomp_New();
-      NewClass_AddRef( self->locals[d_i] );
-      self->remotes[d_i] = Sync_New();
-		NewClass_AddRef( self->remotes[d_i] );
-
-		if( self->comm )
-			Decomp_SetMPIComm( self->locals[d_i], Comm_GetMPIComm( self->comm ) );
-		Sync_SetDecomp( self->remotes[d_i], self->locals[d_i] );
-
-      if( self->comm )
-			Sync_SetComm( self->remotes[d_i], self->comm );
-
-		memset( self->nIncEls[d_i], 0, sizeof(int**) * self->nTDims );
-		memset( self->incEls[d_i], 0, sizeof(int***) * self->nTDims );
-   }
-}
-
-void IGraph_SetComm( void* _self, const Comm* comm ) {
-   IGraph* self = (IGraph*)_self;
-   const Comm* curComm;
-   int d_i;
-
-   assert( self );
-
-   IGraph_ClearElements( self );
-   _MeshTopology_SetComm( self, comm );
-
-   if( comm ) {
-      for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-			curComm = Sync_GetComm( self->remotes[d_i] );
-
-			if( curComm != comm ) {
-				Sync_SetComm( self->remotes[d_i], self->comm );
-				Decomp_SetMPIComm( self->locals[d_i], Comm_GetMPIComm( self->comm ) );
-			}
-      }
-   }
-}
-
-void IGraph_SetDomain( void* _self, int dim, Sync* sync ) {
-   IGraph* self = (IGraph*)_self;
-
-   assert( self && dim < self->nTDims );
-   NewClass_RemoveRef( self->locals[dim] );
-   NewClass_RemoveRef( self->remotes[dim] );
-   self->remotes[dim] = sync;
-   NewClass_AddRef( sync );
-
-   if( sync ) {
-      self->locals[dim] = (Decomp*)Sync_GetDecomp( sync );
-      NewClass_AddRef( self->locals[dim] );
-   }
-}
-
-void IGraph_SetElements( void* _self, int dim, int nEls, const int* globals ) {
-   IGraph* self = (IGraph*)_self;
-   int rank;
-   int nNbrs;
-   const int *nbrs;
-   int nSubEls;
-   const int *subEls;
-   int rem, netRem;
-   int *nNbrEls, **nbrEls;
-   IArray** isects;
-   ISet localsObj, *locals = &localsObj;
-   ISet remotesObj, *remotes = &remotesObj;
-   int nCurEls, *curEls;
-   MPI_Comm mpiComm;
-   int n_i, e_i;
-
-   assert( self && dim < self->nTDims );
-   assert( !nEls || globals );
-   assert( self->comm );
-
-   Comm_GetNeighbours( self->comm, &nNbrs, &nbrs );
-   if( !nNbrs ) {
-      IGraph_SetLocalElements( self, dim, nEls, globals );
-      return;
-   }
-
-   ISet_Construct( locals );
-   mpiComm = Comm_GetMPIComm( self->comm );
-   insist( MPI_Comm_rank( mpiComm, &rank ), == MPI_SUCCESS );
-   isects = Class_Array( self, IArray*, nNbrs );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      isects[n_i] = IArray_New();
-
-   ISet_UseArray( locals, nEls, globals );
-   nSubEls = (nEls < 1000) ? nEls : 1000;
-   rem = nEls;
-   subEls = globals;
-   nNbrEls = Class_Array( self, int, nNbrs );
-   nbrEls = Class_Array( self, int*, nNbrs );
-
-	do {
-		Comm_AllgatherInit( self->comm, nSubEls, nNbrEls, sizeof(int) );
-
-      for( n_i = 0; n_i < nNbrs; n_i++ )
-			nbrEls[n_i] = Class_Array( self, int, nNbrEls[n_i] );
-
-		Comm_AllgatherBegin( self->comm, subEls, (void**)nbrEls );
-      Comm_AllgatherEnd( self->comm );
-
-		for( n_i = 0; n_i < nNbrs; n_i++ ) {
-			for( e_i = 0; e_i < nNbrEls[n_i]; e_i++ ) {
-				if( ISet_Has( locals, nbrEls[n_i][e_i] ) )
-					IArray_Append( isects[n_i], nbrEls[n_i][e_i] );
-			}
-			Class_Free( self, nbrEls[n_i] );
-		}
-
-      subEls += nSubEls;
-      rem -= nSubEls;
-      nSubEls = (rem < 1000) ? rem : 1000;
-      insist( MPI_Allreduce( &rem, &netRem, 1, MPI_INT, MPI_SUM, mpiComm ), == MPI_SUCCESS );
-   } while( netRem );
-   Class_Free( self, nNbrEls );
-   Class_Free( self, nbrEls );
-
-   ISet_Construct( remotes );
-   ISet_SetMaxSize( remotes, nEls );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      IArray_GetArray( isects[n_i], &nCurEls, (const int**)&curEls );
-      if( nbrs[n_i] < rank ) {
-			for( e_i = 0; e_i < nCurEls; e_i++ ) {
-				ISet_TryRemove( locals, curEls[e_i] );
-				ISet_TryInsert( remotes, curEls[e_i] );
-			}
-      }
-      NewClass_Delete( isects[n_i] );
-   }
-   Class_Free( self, isects );
-
-   nCurEls = ISet_GetSize( locals );
-   curEls = Class_Array( self, int, nCurEls );
-   ISet_GetArray( locals, curEls );
-   ISet_Destruct( locals );
-   qsort( curEls, nCurEls, sizeof(int), IGraph_Cmp );
-   IGraph_SetLocalElements( self, dim, nCurEls, curEls );
-   Class_Free( self, curEls );
-   nCurEls = ISet_GetSize( remotes );
-   curEls = Class_Array( self, int, nCurEls );
-   ISet_GetArray( remotes, curEls );
-   ISet_Destruct( remotes );
-   qsort( curEls, nCurEls, sizeof(int), IGraph_Cmp );
-   IGraph_SetRemoteElements( self, dim, nCurEls, curEls );
-   Class_Free( self, curEls );
-}
-
-void IGraph_SetLocalElements( void* _self, int dim, int nEls, const int* globals ) {
-   IGraph* self = (IGraph*)_self;
-   int d_i, e_i;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( !nEls || globals );
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-      for( e_i = 0; e_i < Sync_GetNumDomains( self->remotes[dim] ); d_i++ )
-			Class_Free( self, self->incEls[dim][d_i][e_i] );
-		Class_Free( self, self->incEls[dim][d_i] );
-      Class_Free( self, self->nIncEls[dim][d_i] );
-      self->incEls[dim][d_i] = NULL;
-      self->nIncEls[dim][d_i] = NULL;
-   }
-   Decomp_SetLocals( self->locals[dim], nEls, globals );
-   Sync_SetDecomp( self->remotes[dim], self->locals[dim] );
-}
-
-void IGraph_AddLocalElements( void* _self, int dim, int nEls, const int* globals ) {
-   IGraph* self = (IGraph*)_self;
-
-   assert( 0 );
-   /* TODO */
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( !nEls || globals );
-   Decomp_AddLocals( self->locals[dim], nEls, globals );
-   /* TODO: Expand this dimensions incidence if some incidence already set. */
-}
-
-void IGraph_RemoveLocalElements( void* _self, int dim, int nEls, const int* globals, IMap* map ) {
-   /*IGraph* self = (IGraph*)_self;*/
-
-   assert( 0 );
-   /* TODO: Method body goes here */
-}
-
-void IGraph_SetRemoteElements( void* _self, int dim, int nEls, const int* globals ) {
-   IGraph* self = (IGraph*)_self;
-   int nDoms;
-   int d_i, e_i;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( !nEls || globals );
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-		if( self->nIncEls[dim][d_i] ) {
-			for( e_i = Decomp_GetNumLocals( self->locals[dim] ); e_i < Sync_GetNumDomains( self->remotes[dim] ); e_i++ ) {
-				Class_Free( self, self->incEls[dim][d_i][e_i] );
-			}
-      }
-   }
-
-   Sync_SetRemotes( self->remotes[dim], nEls, globals );
-
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-      if( self->nIncEls[dim][d_i] ) {
-			nDoms = Sync_GetNumDomains( self->remotes[dim] );
-			self->nIncEls[dim][d_i] = Class_Rearray( self, self->incEls[dim][d_i], int, nDoms );
-			self->incEls[dim][d_i] = Class_Rearray( self, self->incEls[dim][d_i], int*, nDoms );
-
-			for( e_i = Decomp_GetNumLocals( self->locals[dim] ); e_i < nDoms; e_i++ ) {
-				self->nIncEls[dim][d_i][e_i] = 0;
-				self->incEls[dim][d_i][e_i] = NULL;
-			}
-      }
-   }
-}
-
-void IGraph_AddRemoteElements( void* _self, int dim, int nEls, const int* globals ) {
-   IGraph* self = (IGraph*)_self;
-   int nOldDoms, nDoms;
-   int d_i, e_i;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( !nEls || globals );
-   nOldDoms = Sync_GetNumDomains( self->remotes[dim] );
-   Sync_AddRemotes( self->remotes[dim], nEls, globals );
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-      if( self->nIncEls[dim][d_i] ) {
-			nDoms = Sync_GetNumDomains( self->remotes[dim] );
-			self->nIncEls[dim][d_i] = Class_Rearray( self, self->nIncEls[dim][d_i], int, nDoms );
-			self->incEls[dim][d_i] = Class_Rearray( self, self->incEls[dim][d_i], int*, nDoms );
-
-			for( e_i = nOldDoms; e_i < nDoms; e_i++ ) {
-				self->nIncEls[dim][d_i][e_i] = 0;
-				self->incEls[dim][d_i][e_i] = NULL;
-			}
-      }
-   }
-}
-
-void IGraph_RemoveRemoteElements( void* _self, int dim, int nEls, const int* globals, IMap* map ) {
-   /*IGraph* self = (IGraph*)_self;*/
-
-   assert( 0 );
-   /* TODO: Method body goes here */
-}
-
-void IGraph_SetBoundaryElements( void* _self, int dim, int nEls, const int* els ) {
-   IGraph* self = Class_Cast( _self, IGraph );
-
-   assert( !nEls || els );
-   assert( dim < self->nTDims );
-
-   if( !self->nBndEls ) {
-      self->nBndEls = Class_Array( self, int, self->nTDims );
-      memset( self->nBndEls, 0, sizeof(int) * self->nTDims );
-   }
-   if( !self->bndEls ) {
-      self->bndEls = Class_Array( self, int*, self->nTDims );
-      memset( self->bndEls, 0, sizeof(int*) * self->nTDims );
-   }
-   self->nBndEls[dim] = nEls;
-   self->bndEls[dim] = Class_Rearray( self, self->bndEls[dim], int, nEls );
-   memcpy( self->bndEls[dim], els, sizeof(int) * nEls );
-}
-
-void IGraph_SetIncidence( void* _self, int fromDim, int fromEl, int toDim, int nIncEls, const int* incEls  ) {
-   IGraph* self = (IGraph*)_self;
-   int nDoms;
-
-   assert( self );
-   assert( fromDim < self->nTDims && toDim < self->nTDims );
-   assert( self->locals[fromDim] );
-   if( !self->nIncEls[fromDim][toDim] ) {
-      nDoms = Sync_GetNumDomains( self->remotes[fromDim] );
-      self->nIncEls[fromDim][toDim] = Class_Array( self, int, nDoms );
-      self->incEls[fromDim][toDim] = Class_Array( self, int*, nDoms );
-      memset( self->incEls[fromDim][toDim], 0, sizeof(int*) * nDoms );
-   }
-
-   self->nIncEls[fromDim][toDim][fromEl] = nIncEls;
-   self->incEls[fromDim][toDim][fromEl] = Class_Rearray( self, self->incEls[fromDim][toDim][fromEl], int, nIncEls );
-   memcpy( self->incEls[fromDim][toDim][fromEl], incEls, nIncEls * sizeof(int) );
-}
-
-void IGraph_RemoveIncidence( void* _self, int fromDim, int toDim ) {
-   IGraph* self = (IGraph*)_self;
-   int nEls;
-   int e_i;
-
-   assert( self );
-   assert( fromDim < self->nTDims );
-   assert( toDim < self->nTDims );
-
-   nEls = Sync_GetNumDomains( self->remotes[fromDim] );
-   for( e_i = 0; e_i < nEls; e_i++ )
-      Class_Free( self, self->incEls[fromDim][toDim][e_i] );
-   Class_Free( self, self->incEls[fromDim][toDim] );
-   Class_Free( self, self->nIncEls[fromDim][toDim] );
-   self->incEls[fromDim][toDim] = NULL;
-   self->nIncEls[fromDim][toDim] = NULL;
-}
-
-void IGraph_InvertIncidence( void* _self, int fromDim, int toDim ) {
-   IGraph* self = (IGraph*)_self;
-   int fromSize, toSize;
-   int *nInvIncEls, **invIncEls;
-   int *nIncEls, **incEls;
-   int elInd;
-   int e_i, inc_i;
-
-   assert( self );
-   fromSize = Sync_GetNumDomains( self->remotes[fromDim] );
-   toSize = Sync_GetNumDomains( self->remotes[toDim] );
-   nInvIncEls = self->nIncEls[toDim][fromDim];
-   invIncEls = self->incEls[toDim][fromDim];
-   nIncEls = Class_Array( self, int, fromSize );
-   memset( nIncEls, 0, fromSize * sizeof(int) );
-   for( e_i = 0; e_i < toSize; e_i++ ) {
-      for( inc_i = 0; inc_i < nInvIncEls[e_i]; inc_i++ )
-			nIncEls[invIncEls[e_i][inc_i]]++;
-   }
-
-   incEls = Class_Array( self, int*, fromSize );
-   for( e_i = 0; e_i < fromSize; e_i++ )
-      incEls[e_i] = Class_Array( self, int, nIncEls[e_i] );
-   memset( nIncEls, 0, fromSize * sizeof(unsigned) );
-   for( e_i = 0; e_i < toSize; e_i++ ) {
-		for( inc_i = 0; inc_i < nInvIncEls[e_i]; inc_i++ ) {
-			elInd = invIncEls[e_i][inc_i];
-			incEls[elInd][nIncEls[elInd]++] = e_i;
-      }
-   }
-
-   for( e_i = 0; e_i < fromSize; e_i++ ) {
-      IGraph_SetIncidence( self, fromDim, e_i, toDim, nIncEls[e_i], incEls[e_i] );
-      Class_Free( self, incEls[e_i] );
-   }
-   Class_Free( self, nIncEls );
-   Class_Free( self, incEls );
-}
-
-void IGraph_ExpandIncidence( void* _self, int dim ) {
-   IGraph* self = (IGraph*)_self;
-   ISet nbrSetObj, *nbrSet = &nbrSetObj;
-   int nEls;
-   int nCurNbrs, maxNbrs;
-   int nIncEls, *incEls;
-   int nUpEls, *upEls;
-   int e_i, inc_i, inc_j;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( dim > 0 );
-   assert( self->nIncEls[dim][0] );
-
-   nEls = Sync_GetNumDomains( self->remotes[dim] );
-   maxNbrs = 0;
-   for( e_i = 0; e_i < nEls; e_i++ ) {
-      nCurNbrs = 0;
-      nIncEls = self->nIncEls[dim][0][e_i];
-      incEls = self->incEls[dim][0][e_i];
-      for( inc_i = 0; inc_i < nIncEls; inc_i++ )
-			nCurNbrs += self->nIncEls[0][dim][incEls[inc_i]];
-			if( nCurNbrs > maxNbrs )
-				maxNbrs = nCurNbrs;
-	}
-
-   ISet_Construct( nbrSet );
-   ISet_SetMaxSize( nbrSet, maxNbrs );
-   if( !self->nIncEls[dim][dim] ) {
-      self->nIncEls[dim][dim] = Class_Array( self, int, nEls );
-      memset( self->nIncEls[dim][dim], 0, nEls * sizeof(int) );
-   }
-   if( !self->incEls[dim][dim] ) {
-      self->incEls[dim][dim] = Class_Array( self, int*, nEls );
-      memset( self->incEls[dim][dim], 0, nEls * sizeof(int*) );
-   }
-   for( e_i = 0; e_i < nEls; e_i++ ) {
-      nIncEls = self->nIncEls[dim][0][e_i];
-      incEls = self->incEls[dim][0][e_i];
-      for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
-			nUpEls = self->nIncEls[0][dim][incEls[inc_i]];
-			upEls = self->incEls[0][dim][incEls[inc_i]];
-			for( inc_j = 0; inc_j < nUpEls; inc_j++ ) {
-				if( upEls[inc_j] == e_i )
-					continue;
-				ISet_TryInsert( nbrSet, upEls[inc_j] );
-			}
-      }
-      self->nIncEls[dim][dim][e_i] = ISet_GetSize( nbrSet );
-      self->incEls[dim][dim][e_i] = Class_Rearray( self, self->incEls[dim][dim][e_i], int, self->nIncEls[dim][dim][e_i] );
-      ISet_GetArray( nbrSet, self->incEls[dim][dim][e_i] );
-      ISet_Clear( nbrSet );
-   }
-   ISet_Destruct( nbrSet );
-}
-
-void _IGraph_SetShadowDepth( void* _self, int depth ) {
-   IGraph* self = (IGraph*)_self;
-   int nNbrs, nDims;
-   Sync* vertSync;
-   ISet ghostSetObj, *ghostSet = &ghostSetObj;
-   ISet mySetObj, *mySet = &mySetObj;
-   IArray* isects;
-   int nGhosts, *ghosts;
-   int nLocals, nRemotes;
-   const int* locals, *remotes;
-   int *nNbrGhosts, **nbrGhosts;
-   int *nBytes, *nRecvBytes;
-   stgByte **bytes, **recvBytes;
-   int nIncEls, *incEls;
-   int **nLowEls, ***lowEls;
-   int *nShdEls, **shdEls;
-   int el, dom;
-   int n_i, s_i, l_i, inc_i;
-   int v_i, g_i, e_i, d_i;
-
-   assert( self && depth >= 0 );
-   assert( self->comm && self->nTDims );
-
-   _MeshTopology_SetShadowDepth( self, depth );
-
-   /* Build ghost set. */
-   nDims = self->nDims;
-   nNbrs = Comm_GetNumNeighbours( self->comm );
-   vertSync = self->remotes[0];
-   nGhosts = 0;
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      nGhosts += vertSync->nSnks[n_i] + vertSync->nSrcs[n_i];
-   ISet_Construct( ghostSet );
-   ISet_SetMaxSize( ghostSet, nGhosts );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < vertSync->nSnks[n_i]; s_i++ ) {
-			el = Decomp_LocalToGlobal( self->locals[0], vertSync->snks[n_i][s_i] );
-			ISet_TryInsert( ghostSet, el );
-      }
-      for( s_i = 0; s_i < vertSync->nSrcs[n_i]; s_i++ ) {
-			el = Sync_RemoteToGlobal( vertSync, vertSync->srcs[n_i][s_i] );
-			ISet_TryInsert( ghostSet, el );
-      }
-   }
-   nGhosts = ISet_GetSize( ghostSet );
-   ghosts = Class_Array( self, int, nGhosts );
-   ISet_GetArray( ghostSet, ghosts );
-   ISet_Destruct( ghostSet );
-
-   /* Gather neighbouring ghost sets. */
-   nNbrGhosts = Class_Array( self, int, nNbrs );
-   nbrGhosts = Class_Array( self, int*, nNbrs );
-   Comm_AllgatherInit( self->comm, nGhosts, nNbrGhosts, sizeof(int) );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      nbrGhosts[n_i] = Class_Array( self, int, nNbrGhosts[n_i] );
-   Comm_AllgatherBegin( self->comm, ghosts, (void**)nbrGhosts );
-   Comm_AllgatherEnd( self->comm );
-   Class_Free( self, ghosts );
-
-   /* Build intersections. */
-   ISet_Construct( mySet );
-   ISet_SetMaxSize( mySet, Sync_GetNumDomains( vertSync ) );
-   Decomp_GetLocals( self->locals[0], &nLocals, &locals );
-   for( l_i = 0; l_i < nLocals; l_i++ )
-      ISet_Insert( mySet, locals[l_i] );
-   Sync_GetRemotes( self->remotes[0], &nRemotes, &remotes );
-   for( l_i = 0; l_i < nRemotes; l_i++ )
-      ISet_Insert( mySet, remotes[l_i] );
-   isects = Class_Array( self, IArray, nNbrs );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      IArray_Construct( isects + n_i );
-      for( g_i = 0; g_i < nNbrGhosts[n_i]; g_i++ ) {
-			if( ISet_Has( mySet, nbrGhosts[n_i][g_i] ) )
-				IArray_Append( isects + n_i, nbrGhosts[n_i][g_i] );
-		}
-      Class_Free( self, nbrGhosts[n_i] );
-   }
-
-   /* Convert vertices to shadowed elements. */
-   ISet_Clear( mySet );
-   ISet_SetMaxSize( mySet, Decomp_GetNumLocals( self->locals[self->nDims] ) );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      IArray_GetArray( isects + n_i, nNbrGhosts + n_i, (const int**)(nbrGhosts + n_i) );
-
-      for( v_i = 0; v_i < nNbrGhosts[n_i]; v_i++ ) {
-			dom = Sync_GlobalToDomain( vertSync, nbrGhosts[n_i][v_i] );
-
-			for( inc_i = 0; inc_i < self->nIncEls[0][nDims][dom]; inc_i++ ) {
-				el = self->incEls[0][nDims][dom][inc_i];
-
-				if( el < Decomp_GetNumLocals( self->locals[nDims] ) ) {
-					el = Decomp_LocalToGlobal( self->locals[nDims], el );
-					ISet_TryInsert( mySet, el );
-				}
-			}
-      }
-      IArray_Destruct( isects + n_i );
-      nNbrGhosts[n_i] = ISet_GetSize( mySet );
-      nbrGhosts[n_i] = Class_Array( self, int, nNbrGhosts[n_i] );
-      ISet_GetArray( mySet, nbrGhosts[n_i] );
-      ISet_Clear( mySet );
-   }
-   Class_Free( self, isects );
-   ISet_SetMaxSize( mySet, 0 );
-
-   /* Transfer elements. */
-   nShdEls = Class_Array( self, int, nNbrs );
-   shdEls = Class_Array( self, int*, nNbrs );
-   Comm_AlltoallInit( self->comm, nNbrGhosts, nShdEls, sizeof(int) );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      shdEls[n_i] = Class_Array( self, int, nShdEls[n_i] );
-   Comm_AlltoallBegin( self->comm, (const void**)nbrGhosts, (void**)shdEls );
-   Comm_AlltoallEnd( self->comm );
-   dom = 0;
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      dom += nShdEls[n_i];
-   ISet_SetMaxSize( mySet, dom );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( e_i = 0; e_i < nShdEls[n_i]; e_i++ )
-			ISet_Insert( mySet, shdEls[n_i][e_i] );
-			Class_Free( self, shdEls[n_i] );
-   }
-   nShdEls[0] = ISet_GetSize( mySet );
-   shdEls[0] = Class_Array( self, int, nShdEls[0] );
-   ISet_GetArray( mySet, shdEls[0] );
-   ISet_Clear( mySet );
-   ISet_SetMaxSize( mySet, 0 );
-   qsort( shdEls[0], nShdEls[0], sizeof(int), IGraph_Cmp );
-   IGraph_AddRemoteElements( self, nDims, nShdEls[0], shdEls[0] );
-   Class_Free( self, shdEls[0] );
-
-   /* Transfer lower level shadowed elements. */
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( e_i = 0; e_i < nNbrGhosts[n_i]; e_i++ ) {
-			nbrGhosts[n_i][e_i] = Decomp_GlobalToLocal( self->locals[nDims], nbrGhosts[n_i][e_i] );
-      }
-   }
-   nLowEls = Class_Array( self, int*, self->nTDims );
-   lowEls = Class_Array( self, int**, self->nTDims );
-	for( d_i = nDims - 1; d_i >= 0; d_i-- ) {
-      if( !self->nIncEls[nDims][d_i] ) {
-			nLowEls[d_i] = NULL;
-			lowEls[d_i] = NULL;
-			continue;
-		}
-      nLowEls[d_i] = Class_Array( self, int, nNbrs );
-      lowEls[d_i] = Class_Array( self, int*, nNbrs );
-      ISet_SetMaxSize( mySet, Decomp_GetNumLocals( self->locals[d_i] ) );
-
-      for( n_i = 0; n_i < nNbrs; n_i++ ) {
-			for( e_i = 0; e_i < nNbrGhosts[n_i]; e_i++ ) {
-				nIncEls = self->nIncEls[nDims][d_i][nbrGhosts[n_i][e_i]];
-				incEls = self->incEls[nDims][d_i][nbrGhosts[n_i][e_i]];
-
-				for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
-					if( incEls[inc_i] >= Decomp_GetNumLocals( self->locals[d_i] ) )
-						continue;
-					el = Decomp_LocalToGlobal( self->locals[d_i], incEls[inc_i] );
-					ISet_TryInsert( mySet, el );
-				}
-			}
-			nLowEls[d_i][n_i] = ISet_GetSize( mySet );
-			lowEls[d_i][n_i] = Class_Array( self, int, nLowEls[d_i][n_i] );
-			ISet_GetArray( mySet, lowEls[d_i][n_i] );
-			ISet_Clear( mySet );
-		}
-
-      Comm_AlltoallInit( self->comm, nLowEls[d_i], nShdEls, sizeof(int) );
-		for( n_i = 0; n_i < nNbrs; n_i++ )
-			shdEls[n_i] = Class_Array( self, int, nShdEls[n_i] );
-      Comm_AlltoallBegin( self->comm, (const void**)lowEls[d_i], (void**)shdEls );
-      Comm_AlltoallEnd( self->comm );
-
-      dom = 0;
-      for( n_i = 0; n_i < nNbrs; n_i++ )
-			dom += nShdEls[n_i];
-      ISet_SetMaxSize( mySet, dom );
-		for( n_i = 0; n_i < nNbrs; n_i++ ) {
-			for( s_i = 0; s_i < nShdEls[n_i]; s_i++ ) {
-				if( !Sync_TryGlobalToDomain( self->remotes[d_i], shdEls[n_i][s_i], &el ) ) {
-					ISet_Insert( mySet, shdEls[n_i][s_i] );
-				}
-			}
-			Class_Free( self, shdEls[n_i] );
-      }
-      nShdEls[0] = ISet_GetSize( mySet );
-      shdEls[0] = Class_Array( self, int, nShdEls[0] );
-      ISet_GetArray( mySet, shdEls[0] );
-      ISet_Clear( mySet );
-      qsort( shdEls[0], nShdEls[0], sizeof(int), IGraph_Cmp );
-      IGraph_AddRemoteElements( self, d_i, nShdEls[0], shdEls[0] );
-      Class_Free( self, shdEls[0] );
-   }
-   ISet_Destruct( mySet );
-   Class_Free( self, shdEls );
-   Class_Free( self, nShdEls );
-
-   /* Transfer shadowed incidence. */
-   nBytes = Class_Array( self, int, nNbrs );
-   bytes = Class_Array( self, stgByte*, nNbrs );
-   nRecvBytes = Class_Array( self, int, nNbrs );
-   recvBytes = Class_Array( self, stgByte*, nNbrs );
-   nLowEls[nDims] = nNbrGhosts;
-   lowEls[nDims] = nbrGhosts;
-   for( d_i = 0; d_i < nDims; d_i++ ) {
-		if( !nLowEls[d_i] )
-			continue;
-		for( n_i = 0; n_i < nNbrs; n_i++ ) {
-			for( e_i = 0; e_i < nLowEls[d_i][n_i]; e_i++ ) {
-				lowEls[d_i][n_i][e_i] = Decomp_GlobalToLocal( self->locals[d_i], lowEls[d_i][n_i][e_i] );
-			}
-		}
-   }
-   for( d_i = nDims; d_i >= 0; d_i-- ) {
-		if( !nLowEls[d_i] )
-			continue;
-		if( d_i == 0 ) {
-			for( n_i = 0; n_i < nNbrs; n_i++ )
-				Class_Free( self, lowEls[0][n_i] );
-			Class_Free( self, lowEls[0] );
-			Class_Free( self, nLowEls[0] );
-			continue;
-		}
-
-		for( n_i = 0; n_i < nNbrs; n_i++ ) {
-			IGraph_PickleIncidenceInit( self, d_i, nLowEls[d_i][n_i], lowEls[d_i][n_i], nBytes + n_i );
-			bytes[n_i] = Class_Array( self, stgByte, nBytes[n_i] );
-			IGraph_PickleIncidence( self, d_i, nLowEls[d_i][n_i], lowEls[d_i][n_i], bytes[n_i] );
-			Class_Free( self, lowEls[d_i][n_i] );
-		}
-      Class_Free( self, nLowEls[d_i] );
-      Class_Free( self, lowEls[d_i] );
-
-      Comm_AlltoallInit( self->comm, nBytes, nRecvBytes, sizeof(stgByte) );
-		for( n_i = 0; n_i < nNbrs; n_i++ )
-			recvBytes[n_i] = Class_Array( self, stgByte, nRecvBytes[n_i] );
-		Comm_AlltoallBegin( self->comm, (const void**)bytes, (void**)recvBytes );
-		Comm_AlltoallEnd( self->comm );
-      for( n_i = 0; n_i < nNbrs; n_i++ )
-			Class_Free( self, bytes[n_i] );
-
-      for( n_i = 0; n_i < nNbrs; n_i++ ) {
-			IGraph_UnpickleIncidence( self, d_i, nRecvBytes[n_i], recvBytes[n_i] );
-			Class_Free( self, recvBytes[n_i] );
-      }
-   }
-   Class_Free( self, nBytes );
-   Class_Free( self, bytes );
-   Class_Free( self, lowEls );
-   Class_Free( self, nLowEls );
-   Class_Free( self, recvBytes );
-   Class_Free( self, nRecvBytes );
-}
-
-void IGraph_Clear( void* self ) {
-   IGraph_ClearDims( self );
-   if( ((IGraph*)self)->comm )
-      NewClass_RemoveRef( ((IGraph*)self)->comm );
-   ((IGraph*)self)->comm = NULL;
-	((NewClass*)self)->curAllocd = 0;
-}
-
-void IGraph_ClearDims( void* _self ) {
-   IGraph* self = (IGraph*)_self;
-   int d_i;
-
-   IGraph_ClearElements( self );
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-      if( self->locals && self->locals[d_i] )
-			NewClass_RemoveRef( self->locals[d_i] );
-      if( self->remotes && self->remotes[d_i] )
-			NewClass_RemoveRef( self->remotes[d_i] );
-   }
-   Class_Free( self, self->locals );
-   Class_Free( self, self->remotes );
-   Class_Free( self, self->nIncEls );
-   Class_Free( self, self->incEls );
-
-   self->nDims = (MeshTopology_Dim)0;
-   self->nTDims = 0;
-   self->shadDepth = 0;
-   self->locals = NULL;
-   self->remotes = NULL;
-   self->nIncEls = NULL;
-   self->incEls = NULL;
-}
-
-void IGraph_ClearElements( void* _self ) {
-   IGraph* self = (IGraph*)_self;
-   int d_i;
-
-   IGraph_ClearIncidence( self );
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-      if( self->locals )
-			Decomp_ClearLocals( self->locals[d_i] );
-      if( self->remotes && self->remotes[d_i] )
-			Sync_ClearRemotes( self->remotes[d_i] );
-      if( self->bndEls )
-			Class_Free( self, self->bndEls[d_i] );
-   }
-   Class_Free( self, self->bndEls );
-   Class_Free( self, self->nBndEls );
-   self->bndEls = NULL;
-   self->nBndEls = NULL;
-}
-
-void IGraph_ClearIncidence( void* _self ) {
-   IGraph* self = (IGraph*)_self;
-   int d_i, d_j, e_i;
-
-   assert( self );
-   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
-		for( d_j = 0; d_j < self->nTDims; d_j++ ) {
-			if( self->nIncEls[d_i][d_j] ) {
-				for( e_i = 0; e_i < Sync_GetNumDomains( self->remotes[d_i] ); e_i++ )
-					Class_Free( self, self->incEls[d_i][d_j][e_i] );
-				Class_Free( self, self->incEls[d_i][d_j] );
-				Class_Free( self, self->nIncEls[d_i][d_j] );
-				self->nIncEls[d_i][d_j] = NULL;
-				self->incEls[d_i][d_j] = NULL;
-			}
-      }
-   }
-}
-
-int IGraph_GetNumDims( const void* self ) {
-   assert( self );
-   return ((IGraph*)self)->nDims;
-}
-
-const Comm* IGraph_GetComm( const void* self ) {
-   assert( self );
-   return ((IGraph*)self)->comm;
-}
-
-Bool IGraph_HasDomain( const void* self, int dim ) {
-   assert( self && dim < ((IGraph*)self)->nTDims );
-   return Sync_GetNumDomains( ((IGraph*)self)->remotes[dim] ) ? 
-      True : False;
-}
-
-const Sync* IGraph_GetDomain( const void* self, int dim ) {
-   assert( self && dim < ((IGraph*)self)->nTDims );
-   return ((IGraph*)self)->remotes[dim];
-}
-
-void IGraph_GetBoundaryElements( const void* self, int dim, int* nEls, const int** els ) {
-   assert( Class_IsSuper( self, IGraph ) );
-   assert( dim < ((IGraph*)self)->nTDims );
-   assert( nEls );
-   assert( els );
-
-   *nEls = ((IGraph*)self)->nBndEls ? ((IGraph*)self)->nBndEls[dim] : 0;
-   *els = ((IGraph*)self)->bndEls ? ((IGraph*)self)->bndEls[dim] : NULL;
-}
-
-Bool IGraph_HasIncidence( const void* self, int fromDim, int toDim ) {
-   assert( self );
-   assert( fromDim < ((IGraph*)self)->nTDims );
-   assert( toDim < ((IGraph*)self)->nTDims );
-   return ((IGraph*)self)->nIncEls[fromDim][toDim] ? True : False;
-}
-
-int IGraph_GetIncidenceSize( const void* self, int fromDim, int fromEl, int toDim ) {
-   assert( self );
-   assert( fromDim < ((IGraph*)self)->nTDims );
-   assert( toDim < ((IGraph*)self)->nTDims );
-   assert( fromEl < Sync_GetNumDomains( ((IGraph*)self)->remotes[fromDim] ) );
-   return ((IGraph*)self)->nIncEls[fromDim][toDim][fromEl];
-}
-
-void _IGraph_GetIncidence( void* self, int fromDim, int fromEl, int toDim, IArray* inc ) {
-   assert( self );
-   assert( fromDim < ((IGraph*)self)->nTDims );
-   assert( toDim < ((IGraph*)self)->nTDims );
-   assert( fromEl < Sync_GetNumDomains( ((IGraph*)self)->remotes[fromDim] ) );
-   assert( inc );
-
-   IArray_SoftResize( inc, ((IGraph*)self)->nIncEls[fromDim][toDim][fromEl] );
-   memcpy( inc->ptr, ((IGraph*)self)->incEls[fromDim][toDim][fromEl], IArray_GetSize( inc ) * sizeof(int) );
-}
-
-void IGraph_PrintIncidence( const void* _self, int fromDim, int toDim ) {
-   IGraph* self = (IGraph*)_self;
-   int nEls, global;
-   int nIncEls, *incEls;
-   int e_i, inc_i;
-
-   assert( self );
-   assert( toDim < self->nTDims );
-   assert( fromDim < self->nTDims );
-
-   nEls = Sync_GetNumDomains( self->remotes[fromDim] );
-   printf( "Printing incidence for %d elements:\n", nEls );
-   for( e_i = 0; e_i < nEls; e_i++ ) {
-      global = Sync_DomainToGlobal( self->remotes[fromDim], e_i );
-      nIncEls = self->nIncEls[fromDim][toDim][e_i];
-      incEls = self->incEls[fromDim][toDim][e_i];
-      printf( "   %d, %d incident elements:\n", global, nIncEls );
-      for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
-			printf( "      %d\n", incEls[inc_i] );
-      }
-   }
-}
-
-void IGraph_PickleIncidenceInit( IGraph* self, int dim, int nEls, int* els, int* nBytes ) {
-   int size;
-   int d_i, e_i;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( !nEls || els );
-   assert( nBytes );
-
-   size = 1;
-   for( e_i = 0; e_i < nEls; e_i++ ) {
-      size += 1;
-      for( d_i = 0; d_i < dim; d_i++ ) {
-			size += 1;
-			if( self->nIncEls[dim][d_i] )
-				size += self->nIncEls[dim][d_i][els[e_i]];
-		}
-	}
-   *nBytes = size * sizeof(int);
-}
-
-void IGraph_PickleIncidence( IGraph* self, int dim, int nEls, int* els, stgByte* bytes ) {
-   Sync* sync;
-   int curEntry, *entries;
-   int nIncEls, *incEls;
-   int inc_i, d_i, e_i;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( !nEls || els );
-   assert( bytes );
-
-   sync = self->remotes[dim];
-   entries = (int*)bytes;
-   entries[0] = nEls;
-   curEntry = 1;
-   for( e_i = 0; e_i < nEls; e_i++ ) {
-      entries[curEntry++] = Sync_DomainToGlobal( sync, els[e_i] );
-      for( d_i = 0; d_i < dim; d_i++ ) {
-			if( !self->nIncEls[dim][d_i] ) {
-				entries[curEntry++] = 0;
-				continue;
-			}
-			nIncEls = self->nIncEls[dim][d_i][els[e_i]];
-			entries[curEntry++] = nIncEls;
-			incEls = self->incEls[dim][d_i][els[e_i]];
-			for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
-				entries[curEntry++] = Sync_DomainToGlobal( self->remotes[d_i], incEls[inc_i] );
-			}
-      }
-   }
-}
-
-void IGraph_UnpickleIncidence( IGraph* self, int dim, int nBytes, stgByte* bytes ) {
-   Sync* sync;
-   int nEls, el;
-   int nIncEls, **incEls;
-   int curEntry, *entries;
-   int inc_i, e_i, d_i;
-
-   assert( self );
-   assert( dim < self->nTDims );
-   assert( nBytes && bytes );
-
-   sync = self->remotes[dim];
-   entries = (int*)bytes;
-   nEls = entries[0];
-   curEntry = 1;
-   for( e_i = 0; e_i < nEls; e_i++ ) {
-      el = Sync_GlobalToDomain( sync, entries[curEntry++] );
-      for( d_i = 0; d_i < dim; d_i++ ) {
-			nIncEls = entries[curEntry++];
-			if( !self->nIncEls[dim][d_i] ) {
-				if( !nIncEls )
-					continue;
-				self->nIncEls[dim][d_i] = Class_Array( self, int, Sync_GetNumDomains( sync ) );
-				memset( self->nIncEls[dim][d_i], 0, sizeof(int) * Sync_GetNumDomains( sync ) );
-			}
-			self->nIncEls[dim][d_i][el] = nIncEls;
-			if( !nIncEls ) {
-				if( self->incEls[dim][d_i] )
-					Class_Free( self, self->incEls[dim][d_i][el] );
-				continue;
-			}
-			if( !self->incEls[dim][d_i] ) {
-				self->incEls[dim][d_i] = Class_Array( self, int*, Sync_GetNumDomains( sync ) );
-				memset( self->incEls[dim][d_i], 0, 
-				Sync_GetNumDomains( sync ) * sizeof(int*) );
-			}
-			incEls = self->incEls[dim][d_i];
-			incEls[el] = Class_Rearray( self, incEls[el], int, nIncEls );
-			for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
-				incEls[el][inc_i] = Sync_GlobalToDomain( self->remotes[d_i], entries[curEntry++] );
-			}
-      }
-   }
-}
-
-int IGraph_Cmp( const void* l, const void* r ) {
-   assert( *(int*)l != *(int*)r );
-   return (*(int*)l < *(int*)r) ? -1 : 1;
-}
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/IGraph.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/IGraph.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1018 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: IGraph.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "StGermain/StGermain.h"
+#include "types.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "IGraph.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+void IGraph_PickleIncidenceInit( IGraph* self, int dim, int nEls, int* els, int* nBytes );
+void IGraph_PickleIncidence( IGraph* self, int dim, int nEls, int* els, stgByte* bytes );
+void IGraph_UnpickleIncidence( IGraph* self, int dim, int nBytes, stgByte* bytes );
+int IGraph_Cmp( const void* l, const void* r );
+
+
+void _IGraph_Init( void* _self ) {
+   IGraph* self = (IGraph*)_self;
+
+   _MeshTopology_Init( self );
+   self->nDims = (MeshTopology_Dim)0;
+   self->nTDims = 0;
+   self->shadDepth = 0;
+   self->comm = NULL;
+   self->locals = NULL;
+   self->remotes = NULL;
+   self->nBndEls = NULL;
+   self->bndEls = NULL;
+   self->nIncEls = NULL;
+   self->incEls = NULL;
+}
+
+void _IGraph_Destruct( void* _self ) {
+   IGraph* self = (IGraph*)_self;
+
+   IGraph_Clear( self );
+   _MeshTopology_Destruct( self );
+}
+
+void _IGraph_Copy( void* _self, const void* op ) {
+   /*IGraph* self = (IGraph*)_self;*/
+
+   assert( 0 );
+   /* TODO */
+}
+
+SizeT _IGraph_CalcMem( const void* _self, PtrMap* ptrs ) {
+   IGraph* self = (IGraph*)_self;
+   SizeT mem;
+   int d_i;
+
+   if( PtrMap_Find( ptrs, (void*)self ) )
+      return 0;
+   mem = _MeshTopology_CalcMem( self, ptrs );
+
+	for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+      if( self->locals )
+			mem += NewClass_CalcMem( self->locals[d_i], ptrs );
+		if( self->remotes )
+			mem += NewClass_CalcMem( self->remotes[d_i], ptrs );
+   }
+   return mem;
+}
+
+void _IGraph_SetNumDims( void* _self, int nDims ) {
+   IGraph* self = (IGraph*)_self;
+   int d_i;
+
+   IGraph_ClearDims( self );
+   _MeshTopology_SetNumDims( self, nDims );
+
+   self->locals = Class_Array( self, Decomp*, self->nTDims );
+   self->remotes = Class_Array( self, Sync*, self->nTDims );
+   self->nIncEls = Class_Array2D( self, int*, self->nTDims, self->nTDims );
+   self->incEls = Class_Array2D( self, int**, self->nTDims, self->nTDims );
+
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+		self->locals[d_i] = Decomp_New();
+      NewClass_AddRef( self->locals[d_i] );
+      self->remotes[d_i] = Sync_New();
+		NewClass_AddRef( self->remotes[d_i] );
+
+		if( self->comm )
+			Decomp_SetMPIComm( self->locals[d_i], Comm_GetMPIComm( self->comm ) );
+		Sync_SetDecomp( self->remotes[d_i], self->locals[d_i] );
+
+      if( self->comm )
+			Sync_SetComm( self->remotes[d_i], self->comm );
+
+		memset( self->nIncEls[d_i], 0, sizeof(int**) * self->nTDims );
+		memset( self->incEls[d_i], 0, sizeof(int***) * self->nTDims );
+   }
+}
+
+void IGraph_SetComm( void* _self, const Comm* comm ) {
+   IGraph* self = (IGraph*)_self;
+   const Comm* curComm;
+   int d_i;
+
+   assert( self );
+
+   IGraph_ClearElements( self );
+   _MeshTopology_SetComm( self, comm );
+
+   if( comm ) {
+      for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+			curComm = Sync_GetComm( self->remotes[d_i] );
+
+			if( curComm != comm ) {
+				Sync_SetComm( self->remotes[d_i], self->comm );
+				Decomp_SetMPIComm( self->locals[d_i], Comm_GetMPIComm( self->comm ) );
+			}
+      }
+   }
+}
+
+void IGraph_SetDomain( void* _self, int dim, Sync* sync ) {
+   IGraph* self = (IGraph*)_self;
+
+   assert( self && dim < self->nTDims );
+   NewClass_RemoveRef( self->locals[dim] );
+   NewClass_RemoveRef( self->remotes[dim] );
+   self->remotes[dim] = sync;
+   NewClass_AddRef( sync );
+
+   if( sync ) {
+      self->locals[dim] = (Decomp*)Sync_GetDecomp( sync );
+      NewClass_AddRef( self->locals[dim] );
+   }
+}
+
+void IGraph_SetElements( void* _self, int dim, int nEls, const int* globals ) {
+   IGraph* self = (IGraph*)_self;
+   int rank;
+   int nNbrs;
+   const int *nbrs;
+   int nSubEls;
+   const int *subEls;
+   int rem, netRem;
+   int *nNbrEls, **nbrEls;
+   IArray** isects;
+   ISet localsObj, *locals = &localsObj;
+   ISet remotesObj, *remotes = &remotesObj;
+   int nCurEls, *curEls;
+   MPI_Comm mpiComm;
+   int n_i, e_i;
+
+   assert( self && dim < self->nTDims );
+   assert( !nEls || globals );
+   assert( self->comm );
+
+   Comm_GetNeighbours( self->comm, &nNbrs, &nbrs );
+   if( !nNbrs ) {
+      IGraph_SetLocalElements( self, dim, nEls, globals );
+      return;
+   }
+
+   ISet_Construct( locals );
+   mpiComm = Comm_GetMPIComm( self->comm );
+   insist( MPI_Comm_rank( mpiComm, &rank ), == MPI_SUCCESS );
+   isects = Class_Array( self, IArray*, nNbrs );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      isects[n_i] = IArray_New();
+
+   ISet_UseArray( locals, nEls, globals );
+   nSubEls = (nEls < 1000) ? nEls : 1000;
+   rem = nEls;
+   subEls = globals;
+   nNbrEls = Class_Array( self, int, nNbrs );
+   nbrEls = Class_Array( self, int*, nNbrs );
+
+	do {
+		Comm_AllgatherInit( self->comm, nSubEls, nNbrEls, sizeof(int) );
+
+      for( n_i = 0; n_i < nNbrs; n_i++ )
+			nbrEls[n_i] = Class_Array( self, int, nNbrEls[n_i] );
+
+		Comm_AllgatherBegin( self->comm, subEls, (void**)nbrEls );
+      Comm_AllgatherEnd( self->comm );
+
+		for( n_i = 0; n_i < nNbrs; n_i++ ) {
+			for( e_i = 0; e_i < nNbrEls[n_i]; e_i++ ) {
+				if( ISet_Has( locals, nbrEls[n_i][e_i] ) )
+					IArray_Append( isects[n_i], nbrEls[n_i][e_i] );
+			}
+			Class_Free( self, nbrEls[n_i] );
+		}
+
+      subEls += nSubEls;
+      rem -= nSubEls;
+      nSubEls = (rem < 1000) ? rem : 1000;
+      insist( MPI_Allreduce( &rem, &netRem, 1, MPI_INT, MPI_SUM, mpiComm ), == MPI_SUCCESS );
+   } while( netRem );
+   Class_Free( self, nNbrEls );
+   Class_Free( self, nbrEls );
+
+   ISet_Construct( remotes );
+   ISet_SetMaxSize( remotes, nEls );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      IArray_GetArray( isects[n_i], &nCurEls, (const int**)&curEls );
+      if( nbrs[n_i] < rank ) {
+			for( e_i = 0; e_i < nCurEls; e_i++ ) {
+				ISet_TryRemove( locals, curEls[e_i] );
+				ISet_TryInsert( remotes, curEls[e_i] );
+			}
+      }
+      NewClass_Delete( isects[n_i] );
+   }
+   Class_Free( self, isects );
+
+   nCurEls = ISet_GetSize( locals );
+   curEls = Class_Array( self, int, nCurEls );
+   ISet_GetArray( locals, curEls );
+   ISet_Destruct( locals );
+   qsort( curEls, nCurEls, sizeof(int), IGraph_Cmp );
+   IGraph_SetLocalElements( self, dim, nCurEls, curEls );
+   Class_Free( self, curEls );
+   nCurEls = ISet_GetSize( remotes );
+   curEls = Class_Array( self, int, nCurEls );
+   ISet_GetArray( remotes, curEls );
+   ISet_Destruct( remotes );
+   qsort( curEls, nCurEls, sizeof(int), IGraph_Cmp );
+   IGraph_SetRemoteElements( self, dim, nCurEls, curEls );
+   Class_Free( self, curEls );
+}
+
+void IGraph_SetLocalElements( void* _self, int dim, int nEls, const int* globals ) {
+   IGraph* self = (IGraph*)_self;
+   int d_i, e_i;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( !nEls || globals );
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+      for( e_i = 0; e_i < Sync_GetNumDomains( self->remotes[dim] ); d_i++ )
+			Class_Free( self, self->incEls[dim][d_i][e_i] );
+		Class_Free( self, self->incEls[dim][d_i] );
+      Class_Free( self, self->nIncEls[dim][d_i] );
+      self->incEls[dim][d_i] = NULL;
+      self->nIncEls[dim][d_i] = NULL;
+   }
+   Decomp_SetLocals( self->locals[dim], nEls, globals );
+   Sync_SetDecomp( self->remotes[dim], self->locals[dim] );
+}
+
+void IGraph_AddLocalElements( void* _self, int dim, int nEls, const int* globals ) {
+   IGraph* self = (IGraph*)_self;
+
+   assert( 0 );
+   /* TODO */
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( !nEls || globals );
+   Decomp_AddLocals( self->locals[dim], nEls, globals );
+   /* TODO: Expand this dimensions incidence if some incidence already set. */
+}
+
+void IGraph_RemoveLocalElements( void* _self, int dim, int nEls, const int* globals, IMap* map ) {
+   /*IGraph* self = (IGraph*)_self;*/
+
+   assert( 0 );
+   /* TODO: Method body goes here */
+}
+
+void IGraph_SetRemoteElements( void* _self, int dim, int nEls, const int* globals ) {
+   IGraph* self = (IGraph*)_self;
+   int nDoms;
+   int d_i, e_i;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( !nEls || globals );
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+		if( self->nIncEls[dim][d_i] ) {
+			for( e_i = Decomp_GetNumLocals( self->locals[dim] ); e_i < Sync_GetNumDomains( self->remotes[dim] ); e_i++ ) {
+				Class_Free( self, self->incEls[dim][d_i][e_i] );
+			}
+      }
+   }
+
+   Sync_SetRemotes( self->remotes[dim], nEls, globals );
+
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+      if( self->nIncEls[dim][d_i] ) {
+			nDoms = Sync_GetNumDomains( self->remotes[dim] );
+			self->nIncEls[dim][d_i] = Class_Rearray( self, self->incEls[dim][d_i], int, nDoms );
+			self->incEls[dim][d_i] = Class_Rearray( self, self->incEls[dim][d_i], int*, nDoms );
+
+			for( e_i = Decomp_GetNumLocals( self->locals[dim] ); e_i < nDoms; e_i++ ) {
+				self->nIncEls[dim][d_i][e_i] = 0;
+				self->incEls[dim][d_i][e_i] = NULL;
+			}
+      }
+   }
+}
+
+void IGraph_AddRemoteElements( void* _self, int dim, int nEls, const int* globals ) {
+   IGraph* self = (IGraph*)_self;
+   int nOldDoms, nDoms;
+   int d_i, e_i;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( !nEls || globals );
+   nOldDoms = Sync_GetNumDomains( self->remotes[dim] );
+   Sync_AddRemotes( self->remotes[dim], nEls, globals );
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+      if( self->nIncEls[dim][d_i] ) {
+			nDoms = Sync_GetNumDomains( self->remotes[dim] );
+			self->nIncEls[dim][d_i] = Class_Rearray( self, self->nIncEls[dim][d_i], int, nDoms );
+			self->incEls[dim][d_i] = Class_Rearray( self, self->incEls[dim][d_i], int*, nDoms );
+
+			for( e_i = nOldDoms; e_i < nDoms; e_i++ ) {
+				self->nIncEls[dim][d_i][e_i] = 0;
+				self->incEls[dim][d_i][e_i] = NULL;
+			}
+      }
+   }
+}
+
+void IGraph_RemoveRemoteElements( void* _self, int dim, int nEls, const int* globals, IMap* map ) {
+   /*IGraph* self = (IGraph*)_self;*/
+
+   assert( 0 );
+   /* TODO: Method body goes here */
+}
+
+void IGraph_SetBoundaryElements( void* _self, int dim, int nEls, const int* els ) {
+   IGraph* self = Class_Cast( _self, IGraph );
+
+   assert( !nEls || els );
+   assert( dim < self->nTDims );
+
+   if( !self->nBndEls ) {
+      self->nBndEls = Class_Array( self, int, self->nTDims );
+      memset( self->nBndEls, 0, sizeof(int) * self->nTDims );
+   }
+   if( !self->bndEls ) {
+      self->bndEls = Class_Array( self, int*, self->nTDims );
+      memset( self->bndEls, 0, sizeof(int*) * self->nTDims );
+   }
+   self->nBndEls[dim] = nEls;
+   self->bndEls[dim] = Class_Rearray( self, self->bndEls[dim], int, nEls );
+   memcpy( self->bndEls[dim], els, sizeof(int) * nEls );
+}
+
+void IGraph_SetIncidence( void* _self, int fromDim, int fromEl, int toDim, int nIncEls, const int* incEls  ) {
+   IGraph* self = (IGraph*)_self;
+   int nDoms;
+
+   assert( self );
+   assert( fromDim < self->nTDims && toDim < self->nTDims );
+   assert( self->locals[fromDim] );
+   if( !self->nIncEls[fromDim][toDim] ) {
+      nDoms = Sync_GetNumDomains( self->remotes[fromDim] );
+      self->nIncEls[fromDim][toDim] = Class_Array( self, int, nDoms );
+      self->incEls[fromDim][toDim] = Class_Array( self, int*, nDoms );
+      memset( self->incEls[fromDim][toDim], 0, sizeof(int*) * nDoms );
+   }
+
+   self->nIncEls[fromDim][toDim][fromEl] = nIncEls;
+   self->incEls[fromDim][toDim][fromEl] = Class_Rearray( self, self->incEls[fromDim][toDim][fromEl], int, nIncEls );
+   memcpy( self->incEls[fromDim][toDim][fromEl], incEls, nIncEls * sizeof(int) );
+}
+
+void IGraph_RemoveIncidence( void* _self, int fromDim, int toDim ) {
+   IGraph* self = (IGraph*)_self;
+   int nEls;
+   int e_i;
+
+   assert( self );
+   assert( fromDim < self->nTDims );
+   assert( toDim < self->nTDims );
+
+   nEls = Sync_GetNumDomains( self->remotes[fromDim] );
+   for( e_i = 0; e_i < nEls; e_i++ )
+      Class_Free( self, self->incEls[fromDim][toDim][e_i] );
+   Class_Free( self, self->incEls[fromDim][toDim] );
+   Class_Free( self, self->nIncEls[fromDim][toDim] );
+   self->incEls[fromDim][toDim] = NULL;
+   self->nIncEls[fromDim][toDim] = NULL;
+}
+
+void IGraph_InvertIncidence( void* _self, int fromDim, int toDim ) {
+   IGraph* self = (IGraph*)_self;
+   int fromSize, toSize;
+   int *nInvIncEls, **invIncEls;
+   int *nIncEls, **incEls;
+   int elInd;
+   int e_i, inc_i;
+
+   assert( self );
+   fromSize = Sync_GetNumDomains( self->remotes[fromDim] );
+   toSize = Sync_GetNumDomains( self->remotes[toDim] );
+   nInvIncEls = self->nIncEls[toDim][fromDim];
+   invIncEls = self->incEls[toDim][fromDim];
+   nIncEls = Class_Array( self, int, fromSize );
+   memset( nIncEls, 0, fromSize * sizeof(int) );
+   for( e_i = 0; e_i < toSize; e_i++ ) {
+      for( inc_i = 0; inc_i < nInvIncEls[e_i]; inc_i++ )
+			nIncEls[invIncEls[e_i][inc_i]]++;
+   }
+
+   incEls = Class_Array( self, int*, fromSize );
+   for( e_i = 0; e_i < fromSize; e_i++ )
+      incEls[e_i] = Class_Array( self, int, nIncEls[e_i] );
+   memset( nIncEls, 0, fromSize * sizeof(unsigned) );
+   for( e_i = 0; e_i < toSize; e_i++ ) {
+		for( inc_i = 0; inc_i < nInvIncEls[e_i]; inc_i++ ) {
+			elInd = invIncEls[e_i][inc_i];
+			incEls[elInd][nIncEls[elInd]++] = e_i;
+      }
+   }
+
+   for( e_i = 0; e_i < fromSize; e_i++ ) {
+      IGraph_SetIncidence( self, fromDim, e_i, toDim, nIncEls[e_i], incEls[e_i] );
+      Class_Free( self, incEls[e_i] );
+   }
+   Class_Free( self, nIncEls );
+   Class_Free( self, incEls );
+}
+
+void IGraph_ExpandIncidence( void* _self, int dim ) {
+   IGraph* self = (IGraph*)_self;
+   ISet nbrSetObj, *nbrSet = &nbrSetObj;
+   int nEls;
+   int nCurNbrs, maxNbrs;
+   int nIncEls, *incEls;
+   int nUpEls, *upEls;
+   int e_i, inc_i, inc_j;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( dim > 0 );
+   assert( self->nIncEls[dim][0] );
+
+   nEls = Sync_GetNumDomains( self->remotes[dim] );
+   maxNbrs = 0;
+   for( e_i = 0; e_i < nEls; e_i++ ) {
+      nCurNbrs = 0;
+      nIncEls = self->nIncEls[dim][0][e_i];
+      incEls = self->incEls[dim][0][e_i];
+      for( inc_i = 0; inc_i < nIncEls; inc_i++ )
+			nCurNbrs += self->nIncEls[0][dim][incEls[inc_i]];
+			if( nCurNbrs > maxNbrs )
+				maxNbrs = nCurNbrs;
+	}
+
+   ISet_Construct( nbrSet );
+   ISet_SetMaxSize( nbrSet, maxNbrs );
+   if( !self->nIncEls[dim][dim] ) {
+      self->nIncEls[dim][dim] = Class_Array( self, int, nEls );
+      memset( self->nIncEls[dim][dim], 0, nEls * sizeof(int) );
+   }
+   if( !self->incEls[dim][dim] ) {
+      self->incEls[dim][dim] = Class_Array( self, int*, nEls );
+      memset( self->incEls[dim][dim], 0, nEls * sizeof(int*) );
+   }
+   for( e_i = 0; e_i < nEls; e_i++ ) {
+      nIncEls = self->nIncEls[dim][0][e_i];
+      incEls = self->incEls[dim][0][e_i];
+      for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
+			nUpEls = self->nIncEls[0][dim][incEls[inc_i]];
+			upEls = self->incEls[0][dim][incEls[inc_i]];
+			for( inc_j = 0; inc_j < nUpEls; inc_j++ ) {
+				if( upEls[inc_j] == e_i )
+					continue;
+				ISet_TryInsert( nbrSet, upEls[inc_j] );
+			}
+      }
+      self->nIncEls[dim][dim][e_i] = ISet_GetSize( nbrSet );
+      self->incEls[dim][dim][e_i] = Class_Rearray( self, self->incEls[dim][dim][e_i], int, self->nIncEls[dim][dim][e_i] );
+      ISet_GetArray( nbrSet, self->incEls[dim][dim][e_i] );
+      ISet_Clear( nbrSet );
+   }
+   ISet_Destruct( nbrSet );
+}
+
+void _IGraph_SetShadowDepth( void* _self, int depth ) {
+   IGraph* self = (IGraph*)_self;
+   int nNbrs, nDims;
+   Sync* vertSync;
+   ISet ghostSetObj, *ghostSet = &ghostSetObj;
+   ISet mySetObj, *mySet = &mySetObj;
+   IArray* isects;
+   int nGhosts, *ghosts;
+   int nLocals, nRemotes;
+   const int* locals, *remotes;
+   int *nNbrGhosts, **nbrGhosts;
+   int *nBytes, *nRecvBytes;
+   stgByte **bytes, **recvBytes;
+   int nIncEls, *incEls;
+   int **nLowEls, ***lowEls;
+   int *nShdEls, **shdEls;
+   int el, dom;
+   int n_i, s_i, l_i, inc_i;
+   int v_i, g_i, e_i, d_i;
+
+   assert( self && depth >= 0 );
+   assert( self->comm && self->nTDims );
+
+   _MeshTopology_SetShadowDepth( self, depth );
+
+   /* Build ghost set. */
+   nDims = self->nDims;
+   nNbrs = Comm_GetNumNeighbours( self->comm );
+   vertSync = self->remotes[0];
+   nGhosts = 0;
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      nGhosts += vertSync->nSnks[n_i] + vertSync->nSrcs[n_i];
+   ISet_Construct( ghostSet );
+   ISet_SetMaxSize( ghostSet, nGhosts );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < vertSync->nSnks[n_i]; s_i++ ) {
+			el = Decomp_LocalToGlobal( self->locals[0], vertSync->snks[n_i][s_i] );
+			ISet_TryInsert( ghostSet, el );
+      }
+      for( s_i = 0; s_i < vertSync->nSrcs[n_i]; s_i++ ) {
+			el = Sync_RemoteToGlobal( vertSync, vertSync->srcs[n_i][s_i] );
+			ISet_TryInsert( ghostSet, el );
+      }
+   }
+   nGhosts = ISet_GetSize( ghostSet );
+   ghosts = Class_Array( self, int, nGhosts );
+   ISet_GetArray( ghostSet, ghosts );
+   ISet_Destruct( ghostSet );
+
+   /* Gather neighbouring ghost sets. */
+   nNbrGhosts = Class_Array( self, int, nNbrs );
+   nbrGhosts = Class_Array( self, int*, nNbrs );
+   Comm_AllgatherInit( self->comm, nGhosts, nNbrGhosts, sizeof(int) );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      nbrGhosts[n_i] = Class_Array( self, int, nNbrGhosts[n_i] );
+   Comm_AllgatherBegin( self->comm, ghosts, (void**)nbrGhosts );
+   Comm_AllgatherEnd( self->comm );
+   Class_Free( self, ghosts );
+
+   /* Build intersections. */
+   ISet_Construct( mySet );
+   ISet_SetMaxSize( mySet, Sync_GetNumDomains( vertSync ) );
+   Decomp_GetLocals( self->locals[0], &nLocals, &locals );
+   for( l_i = 0; l_i < nLocals; l_i++ )
+      ISet_Insert( mySet, locals[l_i] );
+   Sync_GetRemotes( self->remotes[0], &nRemotes, &remotes );
+   for( l_i = 0; l_i < nRemotes; l_i++ )
+      ISet_Insert( mySet, remotes[l_i] );
+   isects = Class_Array( self, IArray, nNbrs );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      IArray_Construct( isects + n_i );
+      for( g_i = 0; g_i < nNbrGhosts[n_i]; g_i++ ) {
+			if( ISet_Has( mySet, nbrGhosts[n_i][g_i] ) )
+				IArray_Append( isects + n_i, nbrGhosts[n_i][g_i] );
+		}
+      Class_Free( self, nbrGhosts[n_i] );
+   }
+
+   /* Convert vertices to shadowed elements. */
+   ISet_Clear( mySet );
+   ISet_SetMaxSize( mySet, Decomp_GetNumLocals( self->locals[self->nDims] ) );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      IArray_GetArray( isects + n_i, nNbrGhosts + n_i, (const int**)(nbrGhosts + n_i) );
+
+      for( v_i = 0; v_i < nNbrGhosts[n_i]; v_i++ ) {
+			dom = Sync_GlobalToDomain( vertSync, nbrGhosts[n_i][v_i] );
+
+			for( inc_i = 0; inc_i < self->nIncEls[0][nDims][dom]; inc_i++ ) {
+				el = self->incEls[0][nDims][dom][inc_i];
+
+				if( el < Decomp_GetNumLocals( self->locals[nDims] ) ) {
+					el = Decomp_LocalToGlobal( self->locals[nDims], el );
+					ISet_TryInsert( mySet, el );
+				}
+			}
+      }
+      IArray_Destruct( isects + n_i );
+      nNbrGhosts[n_i] = ISet_GetSize( mySet );
+      nbrGhosts[n_i] = Class_Array( self, int, nNbrGhosts[n_i] );
+      ISet_GetArray( mySet, nbrGhosts[n_i] );
+      ISet_Clear( mySet );
+   }
+   Class_Free( self, isects );
+   ISet_SetMaxSize( mySet, 0 );
+
+   /* Transfer elements. */
+   nShdEls = Class_Array( self, int, nNbrs );
+   shdEls = Class_Array( self, int*, nNbrs );
+   Comm_AlltoallInit( self->comm, nNbrGhosts, nShdEls, sizeof(int) );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      shdEls[n_i] = Class_Array( self, int, nShdEls[n_i] );
+   Comm_AlltoallBegin( self->comm, (const void**)nbrGhosts, (void**)shdEls );
+   Comm_AlltoallEnd( self->comm );
+   dom = 0;
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      dom += nShdEls[n_i];
+   ISet_SetMaxSize( mySet, dom );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( e_i = 0; e_i < nShdEls[n_i]; e_i++ )
+			ISet_Insert( mySet, shdEls[n_i][e_i] );
+			Class_Free( self, shdEls[n_i] );
+   }
+   nShdEls[0] = ISet_GetSize( mySet );
+   shdEls[0] = Class_Array( self, int, nShdEls[0] );
+   ISet_GetArray( mySet, shdEls[0] );
+   ISet_Clear( mySet );
+   ISet_SetMaxSize( mySet, 0 );
+   qsort( shdEls[0], nShdEls[0], sizeof(int), IGraph_Cmp );
+   IGraph_AddRemoteElements( self, nDims, nShdEls[0], shdEls[0] );
+   Class_Free( self, shdEls[0] );
+
+   /* Transfer lower level shadowed elements. */
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( e_i = 0; e_i < nNbrGhosts[n_i]; e_i++ ) {
+			nbrGhosts[n_i][e_i] = Decomp_GlobalToLocal( self->locals[nDims], nbrGhosts[n_i][e_i] );
+      }
+   }
+   nLowEls = Class_Array( self, int*, self->nTDims );
+   lowEls = Class_Array( self, int**, self->nTDims );
+	for( d_i = nDims - 1; d_i >= 0; d_i-- ) {
+      if( !self->nIncEls[nDims][d_i] ) {
+			nLowEls[d_i] = NULL;
+			lowEls[d_i] = NULL;
+			continue;
+		}
+      nLowEls[d_i] = Class_Array( self, int, nNbrs );
+      lowEls[d_i] = Class_Array( self, int*, nNbrs );
+      ISet_SetMaxSize( mySet, Decomp_GetNumLocals( self->locals[d_i] ) );
+
+      for( n_i = 0; n_i < nNbrs; n_i++ ) {
+			for( e_i = 0; e_i < nNbrGhosts[n_i]; e_i++ ) {
+				nIncEls = self->nIncEls[nDims][d_i][nbrGhosts[n_i][e_i]];
+				incEls = self->incEls[nDims][d_i][nbrGhosts[n_i][e_i]];
+
+				for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
+					if( incEls[inc_i] >= Decomp_GetNumLocals( self->locals[d_i] ) )
+						continue;
+					el = Decomp_LocalToGlobal( self->locals[d_i], incEls[inc_i] );
+					ISet_TryInsert( mySet, el );
+				}
+			}
+			nLowEls[d_i][n_i] = ISet_GetSize( mySet );
+			lowEls[d_i][n_i] = Class_Array( self, int, nLowEls[d_i][n_i] );
+			ISet_GetArray( mySet, lowEls[d_i][n_i] );
+			ISet_Clear( mySet );
+		}
+
+      Comm_AlltoallInit( self->comm, nLowEls[d_i], nShdEls, sizeof(int) );
+		for( n_i = 0; n_i < nNbrs; n_i++ )
+			shdEls[n_i] = Class_Array( self, int, nShdEls[n_i] );
+      Comm_AlltoallBegin( self->comm, (const void**)lowEls[d_i], (void**)shdEls );
+      Comm_AlltoallEnd( self->comm );
+
+      dom = 0;
+      for( n_i = 0; n_i < nNbrs; n_i++ )
+			dom += nShdEls[n_i];
+      ISet_SetMaxSize( mySet, dom );
+		for( n_i = 0; n_i < nNbrs; n_i++ ) {
+			for( s_i = 0; s_i < nShdEls[n_i]; s_i++ ) {
+				if( !Sync_TryGlobalToDomain( self->remotes[d_i], shdEls[n_i][s_i], &el ) ) {
+					ISet_Insert( mySet, shdEls[n_i][s_i] );
+				}
+			}
+			Class_Free( self, shdEls[n_i] );
+      }
+      nShdEls[0] = ISet_GetSize( mySet );
+      shdEls[0] = Class_Array( self, int, nShdEls[0] );
+      ISet_GetArray( mySet, shdEls[0] );
+      ISet_Clear( mySet );
+      qsort( shdEls[0], nShdEls[0], sizeof(int), IGraph_Cmp );
+      IGraph_AddRemoteElements( self, d_i, nShdEls[0], shdEls[0] );
+      Class_Free( self, shdEls[0] );
+   }
+   ISet_Destruct( mySet );
+   Class_Free( self, shdEls );
+   Class_Free( self, nShdEls );
+
+   /* Transfer shadowed incidence. */
+   nBytes = Class_Array( self, int, nNbrs );
+   bytes = Class_Array( self, stgByte*, nNbrs );
+   nRecvBytes = Class_Array( self, int, nNbrs );
+   recvBytes = Class_Array( self, stgByte*, nNbrs );
+   nLowEls[nDims] = nNbrGhosts;
+   lowEls[nDims] = nbrGhosts;
+   for( d_i = 0; d_i < nDims; d_i++ ) {
+		if( !nLowEls[d_i] )
+			continue;
+		for( n_i = 0; n_i < nNbrs; n_i++ ) {
+			for( e_i = 0; e_i < nLowEls[d_i][n_i]; e_i++ ) {
+				lowEls[d_i][n_i][e_i] = Decomp_GlobalToLocal( self->locals[d_i], lowEls[d_i][n_i][e_i] );
+			}
+		}
+   }
+   for( d_i = nDims; d_i >= 0; d_i-- ) {
+		if( !nLowEls[d_i] )
+			continue;
+		if( d_i == 0 ) {
+			for( n_i = 0; n_i < nNbrs; n_i++ )
+				Class_Free( self, lowEls[0][n_i] );
+			Class_Free( self, lowEls[0] );
+			Class_Free( self, nLowEls[0] );
+			continue;
+		}
+
+		for( n_i = 0; n_i < nNbrs; n_i++ ) {
+			IGraph_PickleIncidenceInit( self, d_i, nLowEls[d_i][n_i], lowEls[d_i][n_i], nBytes + n_i );
+			bytes[n_i] = Class_Array( self, stgByte, nBytes[n_i] );
+			IGraph_PickleIncidence( self, d_i, nLowEls[d_i][n_i], lowEls[d_i][n_i], bytes[n_i] );
+			Class_Free( self, lowEls[d_i][n_i] );
+		}
+      Class_Free( self, nLowEls[d_i] );
+      Class_Free( self, lowEls[d_i] );
+
+      Comm_AlltoallInit( self->comm, nBytes, nRecvBytes, sizeof(stgByte) );
+		for( n_i = 0; n_i < nNbrs; n_i++ )
+			recvBytes[n_i] = Class_Array( self, stgByte, nRecvBytes[n_i] );
+		Comm_AlltoallBegin( self->comm, (const void**)bytes, (void**)recvBytes );
+		Comm_AlltoallEnd( self->comm );
+      for( n_i = 0; n_i < nNbrs; n_i++ )
+			Class_Free( self, bytes[n_i] );
+
+      for( n_i = 0; n_i < nNbrs; n_i++ ) {
+			IGraph_UnpickleIncidence( self, d_i, nRecvBytes[n_i], recvBytes[n_i] );
+			Class_Free( self, recvBytes[n_i] );
+      }
+   }
+   Class_Free( self, nBytes );
+   Class_Free( self, bytes );
+   Class_Free( self, lowEls );
+   Class_Free( self, nLowEls );
+   Class_Free( self, recvBytes );
+   Class_Free( self, nRecvBytes );
+}
+
+void IGraph_Clear( void* self ) {
+   IGraph_ClearDims( self );
+   if( ((IGraph*)self)->comm )
+      NewClass_RemoveRef( ((IGraph*)self)->comm );
+   ((IGraph*)self)->comm = NULL;
+	((NewClass*)self)->curAllocd = 0;
+}
+
+void IGraph_ClearDims( void* _self ) {
+   IGraph* self = (IGraph*)_self;
+   int d_i;
+
+   IGraph_ClearElements( self );
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+      if( self->locals && self->locals[d_i] )
+			NewClass_RemoveRef( self->locals[d_i] );
+      if( self->remotes && self->remotes[d_i] )
+			NewClass_RemoveRef( self->remotes[d_i] );
+   }
+   Class_Free( self, self->locals );
+   Class_Free( self, self->remotes );
+   Class_Free( self, self->nIncEls );
+   Class_Free( self, self->incEls );
+
+   self->nDims = (MeshTopology_Dim)0;
+   self->nTDims = 0;
+   self->shadDepth = 0;
+   self->locals = NULL;
+   self->remotes = NULL;
+   self->nIncEls = NULL;
+   self->incEls = NULL;
+}
+
+void IGraph_ClearElements( void* _self ) {
+   IGraph* self = (IGraph*)_self;
+   int d_i;
+
+   IGraph_ClearIncidence( self );
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+      if( self->locals )
+			Decomp_ClearLocals( self->locals[d_i] );
+      if( self->remotes && self->remotes[d_i] )
+			Sync_ClearRemotes( self->remotes[d_i] );
+      if( self->bndEls )
+			Class_Free( self, self->bndEls[d_i] );
+   }
+   Class_Free( self, self->bndEls );
+   Class_Free( self, self->nBndEls );
+   self->bndEls = NULL;
+   self->nBndEls = NULL;
+}
+
+void IGraph_ClearIncidence( void* _self ) {
+   IGraph* self = (IGraph*)_self;
+   int d_i, d_j, e_i;
+
+   assert( self );
+   for( d_i = 0; d_i < self->nTDims; d_i++ ) {
+		for( d_j = 0; d_j < self->nTDims; d_j++ ) {
+			if( self->nIncEls[d_i][d_j] ) {
+				for( e_i = 0; e_i < Sync_GetNumDomains( self->remotes[d_i] ); e_i++ )
+					Class_Free( self, self->incEls[d_i][d_j][e_i] );
+				Class_Free( self, self->incEls[d_i][d_j] );
+				Class_Free( self, self->nIncEls[d_i][d_j] );
+				self->nIncEls[d_i][d_j] = NULL;
+				self->incEls[d_i][d_j] = NULL;
+			}
+      }
+   }
+}
+
+int IGraph_GetNumDims( const void* self ) {
+   assert( self );
+   return ((IGraph*)self)->nDims;
+}
+
+const Comm* IGraph_GetComm( const void* self ) {
+   assert( self );
+   return ((IGraph*)self)->comm;
+}
+
+Bool IGraph_HasDomain( const void* self, int dim ) {
+   assert( self && dim < ((IGraph*)self)->nTDims );
+   return Sync_GetNumDomains( ((IGraph*)self)->remotes[dim] ) ? 
+      True : False;
+}
+
+const Sync* IGraph_GetDomain( const void* self, int dim ) {
+   assert( self && dim < ((IGraph*)self)->nTDims );
+   return ((IGraph*)self)->remotes[dim];
+}
+
+void IGraph_GetBoundaryElements( const void* self, int dim, int* nEls, const int** els ) {
+   assert( Class_IsSuper( self, IGraph ) );
+   assert( dim < ((IGraph*)self)->nTDims );
+   assert( nEls );
+   assert( els );
+
+   *nEls = ((IGraph*)self)->nBndEls ? ((IGraph*)self)->nBndEls[dim] : 0;
+   *els = ((IGraph*)self)->bndEls ? ((IGraph*)self)->bndEls[dim] : NULL;
+}
+
+Bool IGraph_HasIncidence( const void* self, int fromDim, int toDim ) {
+   assert( self );
+   assert( fromDim < ((IGraph*)self)->nTDims );
+   assert( toDim < ((IGraph*)self)->nTDims );
+   return ((IGraph*)self)->nIncEls[fromDim][toDim] ? True : False;
+}
+
+int IGraph_GetIncidenceSize( const void* self, int fromDim, int fromEl, int toDim ) {
+   assert( self );
+   assert( fromDim < ((IGraph*)self)->nTDims );
+   assert( toDim < ((IGraph*)self)->nTDims );
+   assert( fromEl < Sync_GetNumDomains( ((IGraph*)self)->remotes[fromDim] ) );
+   return ((IGraph*)self)->nIncEls[fromDim][toDim][fromEl];
+}
+
+void _IGraph_GetIncidence( void* self, int fromDim, int fromEl, int toDim, IArray* inc ) {
+   assert( self );
+   assert( fromDim < ((IGraph*)self)->nTDims );
+   assert( toDim < ((IGraph*)self)->nTDims );
+   assert( fromEl < Sync_GetNumDomains( ((IGraph*)self)->remotes[fromDim] ) );
+   assert( inc );
+
+   IArray_SoftResize( inc, ((IGraph*)self)->nIncEls[fromDim][toDim][fromEl] );
+   memcpy( inc->ptr, ((IGraph*)self)->incEls[fromDim][toDim][fromEl], IArray_GetSize( inc ) * sizeof(int) );
+}
+
+void IGraph_PrintIncidence( const void* _self, int fromDim, int toDim ) {
+   IGraph* self = (IGraph*)_self;
+   int nEls, global;
+   int nIncEls, *incEls;
+   int e_i, inc_i;
+
+   assert( self );
+   assert( toDim < self->nTDims );
+   assert( fromDim < self->nTDims );
+
+   nEls = Sync_GetNumDomains( self->remotes[fromDim] );
+   printf( "Printing incidence for %d elements:\n", nEls );
+   for( e_i = 0; e_i < nEls; e_i++ ) {
+      global = Sync_DomainToGlobal( self->remotes[fromDim], e_i );
+      nIncEls = self->nIncEls[fromDim][toDim][e_i];
+      incEls = self->incEls[fromDim][toDim][e_i];
+      printf( "   %d, %d incident elements:\n", global, nIncEls );
+      for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
+			printf( "      %d\n", incEls[inc_i] );
+      }
+   }
+}
+
+void IGraph_PickleIncidenceInit( IGraph* self, int dim, int nEls, int* els, int* nBytes ) {
+   int size;
+   int d_i, e_i;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( !nEls || els );
+   assert( nBytes );
+
+   size = 1;
+   for( e_i = 0; e_i < nEls; e_i++ ) {
+      size += 1;
+      for( d_i = 0; d_i < dim; d_i++ ) {
+			size += 1;
+			if( self->nIncEls[dim][d_i] )
+				size += self->nIncEls[dim][d_i][els[e_i]];
+		}
+	}
+   *nBytes = size * sizeof(int);
+}
+
+void IGraph_PickleIncidence( IGraph* self, int dim, int nEls, int* els, stgByte* bytes ) {
+   Sync* sync;
+   int curEntry, *entries;
+   int nIncEls, *incEls;
+   int inc_i, d_i, e_i;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( !nEls || els );
+   assert( bytes );
+
+   sync = self->remotes[dim];
+   entries = (int*)bytes;
+   entries[0] = nEls;
+   curEntry = 1;
+   for( e_i = 0; e_i < nEls; e_i++ ) {
+      entries[curEntry++] = Sync_DomainToGlobal( sync, els[e_i] );
+      for( d_i = 0; d_i < dim; d_i++ ) {
+			if( !self->nIncEls[dim][d_i] ) {
+				entries[curEntry++] = 0;
+				continue;
+			}
+			nIncEls = self->nIncEls[dim][d_i][els[e_i]];
+			entries[curEntry++] = nIncEls;
+			incEls = self->incEls[dim][d_i][els[e_i]];
+			for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
+				entries[curEntry++] = Sync_DomainToGlobal( self->remotes[d_i], incEls[inc_i] );
+			}
+      }
+   }
+}
+
+void IGraph_UnpickleIncidence( IGraph* self, int dim, int nBytes, stgByte* bytes ) {
+   Sync* sync;
+   int nEls, el;
+   int nIncEls, **incEls;
+   int curEntry, *entries;
+   int inc_i, e_i, d_i;
+
+   assert( self );
+   assert( dim < self->nTDims );
+   assert( nBytes && bytes );
+
+   sync = self->remotes[dim];
+   entries = (int*)bytes;
+   nEls = entries[0];
+   curEntry = 1;
+   for( e_i = 0; e_i < nEls; e_i++ ) {
+      el = Sync_GlobalToDomain( sync, entries[curEntry++] );
+      for( d_i = 0; d_i < dim; d_i++ ) {
+			nIncEls = entries[curEntry++];
+			if( !self->nIncEls[dim][d_i] ) {
+				if( !nIncEls )
+					continue;
+				self->nIncEls[dim][d_i] = Class_Array( self, int, Sync_GetNumDomains( sync ) );
+				memset( self->nIncEls[dim][d_i], 0, sizeof(int) * Sync_GetNumDomains( sync ) );
+			}
+			self->nIncEls[dim][d_i][el] = nIncEls;
+			if( !nIncEls ) {
+				if( self->incEls[dim][d_i] )
+					Class_Free( self, self->incEls[dim][d_i][el] );
+				continue;
+			}
+			if( !self->incEls[dim][d_i] ) {
+				self->incEls[dim][d_i] = Class_Array( self, int*, Sync_GetNumDomains( sync ) );
+				memset( self->incEls[dim][d_i], 0, 
+				Sync_GetNumDomains( sync ) * sizeof(int*) );
+			}
+			incEls = self->incEls[dim][d_i];
+			incEls[el] = Class_Rearray( self, incEls[el], int, nIncEls );
+			for( inc_i = 0; inc_i < nIncEls; inc_i++ ) {
+				incEls[el][inc_i] = Sync_GlobalToDomain( self->remotes[d_i], entries[curEntry++] );
+			}
+      }
+   }
+}
+
+int IGraph_Cmp( const void* l, const void* r ) {
+   assert( *(int*)l != *(int*)r );
+   return (*(int*)l < *(int*)r) ? -1 : 1;
+}
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Init.c
--- a/Mesh/src/Init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Init.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include "Mesh.h"
-
-
-Stream* Mesh_VerboseConfig = NULL;
-Stream* Mesh_Debug = NULL;
-Stream* Mesh_Warning = NULL;
-Stream* Mesh_Error = NULL;
-
-
-Bool StgDomainMesh_Init( int* argc, char** argv[] ) {
-	Mesh_VerboseConfig = Journal_Register( Info_Type, (Name)"Mesh_VerboseConfig"  );
-	Mesh_Debug = Journal_Register( Debug_Type, (Name)"Mesh"  );
-	Mesh_Warning = Journal_Register( Error_Type, (Name)"Mesh"  );
-	Mesh_Error = Journal_Register( Error_Type, (Name)"Mesh"  );
-
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Mesh_Algorithms_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Mesh_Algorithms_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Mesh_HexAlgorithms_Type, "0", (Stg_Component_DefaultConstructorFunction*)Mesh_HexAlgorithms_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Mesh_CentroidAlgorithms_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Mesh_CentroidAlgorithms_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Mesh_RegularAlgorithms_Type, "0", (Stg_Component_DefaultConstructorFunction*)Mesh_RegularAlgorithms_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshTopology_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)MeshTopology_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), CartesianGenerator_Type, "0", (Stg_Component_DefaultConstructorFunction*)CartesianGenerator_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Mesh_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Mesh_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), SurfaceAdaptor_Type, "0", (Stg_Component_DefaultConstructorFunction*)SurfaceAdaptor_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), CompressionAdaptor_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)CompressionAdaptor_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), LinearSpaceAdaptor_Type, "0", (Stg_Component_DefaultConstructorFunction*)LinearSpaceAdaptor_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshVariable_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)MeshVariable_New );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Remesher_Type, "0", (Stg_Component_DefaultConstructorFunction*)_Remesher_DefaultNew );
-
-	RegisterParent( Mesh_ElementType_Type, Stg_Class_Type );
-	RegisterParent( Mesh_HexType_Type, Mesh_ElementType_Type );
-	RegisterParent( Mesh_CentroidType_Type, Mesh_ElementType_Type );
-	RegisterParent( Mesh_Algorithms_Type, Stg_Component_Type );
-	RegisterParent( Mesh_HexAlgorithms_Type, Mesh_Algorithms_Type );
-	RegisterParent( Mesh_CentroidAlgorithms_Type, Mesh_Algorithms_Type );
-	RegisterParent( Mesh_RegularAlgorithms_Type, Mesh_Algorithms_Type );
-	RegisterParent( MeshTopology_Type, Stg_Component_Type );
-	RegisterParent( Mesh_Type, Stg_Component_Type );
-	RegisterParent( MeshGenerator_Type, Stg_Component_Type );
-	RegisterParent( CartesianGenerator_Type, MeshGenerator_Type );
-	RegisterParent( MeshAdaptor_Type, MeshGenerator_Type );
-	RegisterParent( SurfaceAdaptor_Type, MeshAdaptor_Type );
-	RegisterParent( CompressionAdaptor_Type, MeshAdaptor_Type );
-	RegisterParent( LinearSpaceAdaptor_Type, MeshAdaptor_Type );
-	RegisterParent( MeshVariable_Type, Variable_Type );
-	RegisterParent( Remesher_Type, Stg_Component_Type );
-
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,88 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Init.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include "Mesh.h"
+
+
+Stream* Mesh_VerboseConfig = NULL;
+Stream* Mesh_Debug = NULL;
+Stream* Mesh_Warning = NULL;
+Stream* Mesh_Error = NULL;
+
+
+Bool StgDomainMesh_Init( int* argc, char** argv[] ) {
+	Mesh_VerboseConfig = Journal_Register( Info_Type, (Name)"Mesh_VerboseConfig"  );
+	Mesh_Debug = Journal_Register( Debug_Type, (Name)"Mesh"  );
+	Mesh_Warning = Journal_Register( Error_Type, (Name)"Mesh"  );
+	Mesh_Error = Journal_Register( Error_Type, (Name)"Mesh"  );
+
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Mesh_Algorithms_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Mesh_Algorithms_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Mesh_HexAlgorithms_Type, "0", (Stg_Component_DefaultConstructorFunction*)Mesh_HexAlgorithms_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Mesh_CentroidAlgorithms_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Mesh_CentroidAlgorithms_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Mesh_RegularAlgorithms_Type, "0", (Stg_Component_DefaultConstructorFunction*)Mesh_RegularAlgorithms_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshTopology_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)MeshTopology_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), CartesianGenerator_Type, "0", (Stg_Component_DefaultConstructorFunction*)CartesianGenerator_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), Mesh_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)Mesh_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), SurfaceAdaptor_Type, "0", (Stg_Component_DefaultConstructorFunction*)SurfaceAdaptor_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), CompressionAdaptor_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)CompressionAdaptor_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), LinearSpaceAdaptor_Type, "0", (Stg_Component_DefaultConstructorFunction*)LinearSpaceAdaptor_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshVariable_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)MeshVariable_New );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Remesher_Type, "0", (Stg_Component_DefaultConstructorFunction*)_Remesher_DefaultNew );
+
+	RegisterParent( Mesh_ElementType_Type, Stg_Class_Type );
+	RegisterParent( Mesh_HexType_Type, Mesh_ElementType_Type );
+	RegisterParent( Mesh_CentroidType_Type, Mesh_ElementType_Type );
+	RegisterParent( Mesh_Algorithms_Type, Stg_Component_Type );
+	RegisterParent( Mesh_HexAlgorithms_Type, Mesh_Algorithms_Type );
+	RegisterParent( Mesh_CentroidAlgorithms_Type, Mesh_Algorithms_Type );
+	RegisterParent( Mesh_RegularAlgorithms_Type, Mesh_Algorithms_Type );
+	RegisterParent( MeshTopology_Type, Stg_Component_Type );
+	RegisterParent( Mesh_Type, Stg_Component_Type );
+	RegisterParent( MeshGenerator_Type, Stg_Component_Type );
+	RegisterParent( CartesianGenerator_Type, MeshGenerator_Type );
+	RegisterParent( MeshAdaptor_Type, MeshGenerator_Type );
+	RegisterParent( SurfaceAdaptor_Type, MeshAdaptor_Type );
+	RegisterParent( CompressionAdaptor_Type, MeshAdaptor_Type );
+	RegisterParent( LinearSpaceAdaptor_Type, MeshAdaptor_Type );
+	RegisterParent( MeshVariable_Type, Variable_Type );
+	RegisterParent( Remesher_Type, Stg_Component_Type );
+
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshAdaptor.c
--- a/Mesh/src/MeshAdaptor.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Decomp.h"
-#include "MeshTopology.h"
-#include "MeshClass.h"
-#include "MeshGenerator.h"
-#include "MeshAdaptor.h"
-
-
-/* Textual name of this class */
-const Type MeshAdaptor_Type = "MeshAdaptor";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-MeshAdaptor* _MeshAdaptor_New(  MESHADAPTOR_DEFARGS  ) {
-	MeshAdaptor* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MeshAdaptor) );
-	self = (MeshAdaptor*)_MeshGenerator_New(  MESHGENERATOR_PASSARGS  );
-
-	/* Virtual info */
-
-	return self;
-}
-
-void _MeshAdaptor_Init( MeshAdaptor* self ) {
-	self->generator = NULL;
-	self->srcMesh = NULL;
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _MeshAdaptor_Delete( void* adaptor ) {
-	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
-
-	/* Delete the parent. */
-	_MeshGenerator_Delete( self );
-}
-
-void _MeshAdaptor_Print( void* adaptor, Stream* stream ) {
-	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
-	
-	/* Set the Journal for printing informations */
-	Stream* adaptorStream;
-	adaptorStream = Journal_Register( InfoStream_Type, (Name)"MeshAdaptorStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "MeshAdaptor (ptr): (%p)\n", self );
-	_Stg_Component_Print( self, stream );
-}
-
-void _MeshAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
-	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
-
-	_MeshGenerator_AssignFromXML( self, cf, data );
-
-	/* There could be either a generator or a mesh to use as a template.  Prefer the mesh. */
-	self->srcMesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"sourceMesh", Mesh, False, data );
-	if( !self->srcMesh  ) {
-		/* Read the source generator. */
-		self->generator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"sourceGenerator", MeshGenerator, True, data  );
-	}
-}
-
-void _MeshAdaptor_Build( void* _adaptor, void* data ) {
-   MeshAdaptor*      self = (MeshAdaptor*)_adaptor;
-   if(self->generator)
-     Stg_Component_Build( self->generator, data, False );
-   if(self->srcMesh)
-     Stg_Component_Build( self->srcMesh, data, False );
-   _MeshGenerator_Build( self, data );
-}
-
-void _MeshAdaptor_Initialise( void* _adaptor, void* data ) {
-   MeshAdaptor*      self = (MeshAdaptor*)_adaptor;
-   if(self->generator)
-     Stg_Component_Initialise( self->generator, data, False );
-   if(self->srcMesh)
-     Stg_Component_Initialise( self->srcMesh, data, False );
-   _MeshGenerator_Initialise( self, data );
-   
-}
-
-void _MeshAdaptor_Execute( void* adaptor, void* data ) {
-    _MeshGenerator_Execute( adaptor, data );
-}
-
-void _MeshAdaptor_Destroy( void* _adaptor, void* data ) {
-   MeshAdaptor*      self = (MeshAdaptor*)_adaptor;
-   if(self->generator)
-     Stg_Component_Destroy( self->generator, data, False );
-   if(self->srcMesh)
-     Stg_Component_Destroy( self->srcMesh, data, False );
-   _MeshGenerator_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void MeshAdaptor_SetGenerator( void* adaptor, void* generator ) {
-	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
-
-	self->generator = (MeshGenerator*)generator;
-	if( self->generator )
-		self->srcMesh = NULL;
-}
-
-void MeshAdaptor_SetSourceMesh( void* adaptor, void* mesh ) {
-	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
-
-	self->srcMesh = (Mesh*)mesh;
-	if( self->srcMesh )
-		self->generator = NULL;
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshAdaptor.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/MeshAdaptor.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,167 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Decomp.h"
+#include "MeshTopology.h"
+#include "MeshClass.h"
+#include "MeshGenerator.h"
+#include "MeshAdaptor.h"
+
+
+/* Textual name of this class */
+const Type MeshAdaptor_Type = "MeshAdaptor";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+MeshAdaptor* _MeshAdaptor_New(  MESHADAPTOR_DEFARGS  ) {
+	MeshAdaptor* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MeshAdaptor) );
+	self = (MeshAdaptor*)_MeshGenerator_New(  MESHGENERATOR_PASSARGS  );
+
+	/* Virtual info */
+
+	return self;
+}
+
+void _MeshAdaptor_Init( MeshAdaptor* self ) {
+	self->generator = NULL;
+	self->srcMesh = NULL;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _MeshAdaptor_Delete( void* adaptor ) {
+	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
+
+	/* Delete the parent. */
+	_MeshGenerator_Delete( self );
+}
+
+void _MeshAdaptor_Print( void* adaptor, Stream* stream ) {
+	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
+	
+	/* Set the Journal for printing informations */
+	Stream* adaptorStream;
+	adaptorStream = Journal_Register( InfoStream_Type, (Name)"MeshAdaptorStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "MeshAdaptor (ptr): (%p)\n", self );
+	_Stg_Component_Print( self, stream );
+}
+
+void _MeshAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
+	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
+
+	_MeshGenerator_AssignFromXML( self, cf, data );
+
+	/* There could be either a generator or a mesh to use as a template.  Prefer the mesh. */
+	self->srcMesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"sourceMesh", Mesh, False, data );
+	if( !self->srcMesh  ) {
+		/* Read the source generator. */
+		self->generator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"sourceGenerator", MeshGenerator, True, data  );
+	}
+}
+
+void _MeshAdaptor_Build( void* _adaptor, void* data ) {
+   MeshAdaptor*      self = (MeshAdaptor*)_adaptor;
+   if(self->generator)
+     Stg_Component_Build( self->generator, data, False );
+   if(self->srcMesh)
+     Stg_Component_Build( self->srcMesh, data, False );
+   _MeshGenerator_Build( self, data );
+}
+
+void _MeshAdaptor_Initialise( void* _adaptor, void* data ) {
+   MeshAdaptor*      self = (MeshAdaptor*)_adaptor;
+   if(self->generator)
+     Stg_Component_Initialise( self->generator, data, False );
+   if(self->srcMesh)
+     Stg_Component_Initialise( self->srcMesh, data, False );
+   _MeshGenerator_Initialise( self, data );
+   
+}
+
+void _MeshAdaptor_Execute( void* adaptor, void* data ) {
+    _MeshGenerator_Execute( adaptor, data );
+}
+
+void _MeshAdaptor_Destroy( void* _adaptor, void* data ) {
+   MeshAdaptor*      self = (MeshAdaptor*)_adaptor;
+   if(self->generator)
+     Stg_Component_Destroy( self->generator, data, False );
+   if(self->srcMesh)
+     Stg_Component_Destroy( self->srcMesh, data, False );
+   _MeshGenerator_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void MeshAdaptor_SetGenerator( void* adaptor, void* generator ) {
+	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
+
+	self->generator = (MeshGenerator*)generator;
+	if( self->generator )
+		self->srcMesh = NULL;
+}
+
+void MeshAdaptor_SetSourceMesh( void* adaptor, void* mesh ) {
+	MeshAdaptor*	self = (MeshAdaptor*)adaptor;
+
+	self->srcMesh = (Mesh*)mesh;
+	if( self->srcMesh )
+		self->generator = NULL;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshClass.c
--- a/Mesh/src/MeshClass.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,663 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshClass.c 4184 2007-09-25 07:54:17Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type Mesh_Type = "Mesh";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh* Mesh_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Mesh);
-	Type                                                      type = Mesh_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Mesh_Delete;
-	Stg_Class_PrintFunction*                                _print = _Mesh_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_Mesh_New;
-	Stg_Component_ConstructFunction*                    _construct = _Mesh_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Mesh_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Mesh_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Mesh_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Mesh_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-
-	Mesh* self = _Mesh_New(  MESH_PASSARGS  );
-
-	_Mesh_Init( self, context );
-   return self;
-}
-
-Mesh* _Mesh_New(  MESH_DEFARGS  ) {
-	Mesh* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh) );
-	self = (Mesh*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	return self;
-}
-
-void _Mesh_Init( Mesh* self, AbstractContext* context ) {
-   self->context = context;
-	self->topo = (MeshTopology*)IGraph_New();
-	self->verts = NULL;
-
-	self->vars = List_New();
-	List_SetItemSize( self->vars, sizeof(MeshVariable*) );
-
-	self->minSep = 0.0;
-	self->minAxialSep = NULL;
-	self->minLocalCrd = NULL;
-	self->maxLocalCrd = NULL;
-	self->minDomainCrd = NULL;
-	self->maxDomainCrd = NULL;
-	self->minGlobalCrd = NULL;
-	self->maxGlobalCrd = NULL;
-
-	self->algorithms = Mesh_Algorithms_New( "", NULL );
-	Mesh_Algorithms_SetMesh( self->algorithms, self );
-	self->nElTypes = 0;
-	self->elTypes = NULL;
-	self->elTypeMap = NULL;
-
-	self->topoDataSizes = UIntMap_New();
-	self->topoDataInfos = NULL;
-	self->topoDatas = NULL;
-	self->info = ExtensionManager_New_OfExistingObject( "mesh_info", self );
-
-	self->generator = NULL;
-	self->emReg = NULL;
-
-	self->isCheckpointedAndReloaded = False;
-	self->requiresCheckpointing     = False;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_Delete( void* mesh ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	/* Delete the parent. */
-	_Stg_Component_Delete( self );
-}
-
-void _Mesh_Print( void* mesh, Stream* stream ) {
-	Mesh*	self = (Mesh*)mesh;
-	
-	/* Set the Journal for printing informations */
-	Stream* meshStream;
-	meshStream = Journal_Register( InfoStream_Type, (Name)"MeshStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh (ptr): (%p)\n", self );
-	_Stg_Component_Print( self, stream );
-}
-
-void _Mesh_AssignFromXML( void* mesh, Stg_ComponentFactory* cf, void* data ) {
-	Mesh*			self = (Mesh*)mesh;
-   AbstractContext* context = NULL;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	_Mesh_Init( self, context );
-}
-
-void _Mesh_Build( void* mesh, void* data ) {
-	Mesh*			self = (Mesh*)mesh;
-	unsigned		nDims;
-	unsigned		d_i;
-
-	assert( self );
-
-	if( self->generator ) {
-	   Stg_Component_Build( self->generator, data, False );
-	   MeshGenerator_Generate( self->generator, self, data );
-	}
-
-	nDims = Mesh_GetDimSize( self );
-	if( !nDims )
-		return;
-
-	self->topoDataInfos = Memory_Alloc_Array( ExtensionManager*, nDims, "mesh::topoDataInfos" );
-	self->topoDatas = Memory_Alloc_Array( void*, nDims, "mesh::topoDatas" );
-
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		char		name[20];
-		unsigned	size;
-
-		if( !UIntMap_Map( self->topoDataSizes, d_i, &size ) || !size ||
-		    !Mesh_GetDomainSize( self, (MeshTopology_Dim)d_i ) )
-		{
-			self->topoDataInfos[d_i] = NULL;
-			self->topoDatas[d_i] = NULL;
-			continue;
-		}
-
-		sprintf( name, "topoData(%d)", d_i );
-		self->topoDataInfos[d_i] = ExtensionManager_New_OfStruct( name, size );
-		self->topoDatas[d_i] = (void*)ExtensionManager_Malloc( self->topoDataInfos[d_i], Mesh_GetDomainSize( self, (MeshTopology_Dim)d_i ) );
-	}
-
-	/*
-	** Set up the geometric information.
-	*/
-
-	self->minAxialSep = Memory_Alloc_Array( double, nDims, "Mesh::minAxialSep" );
-	self->minLocalCrd = Memory_Alloc_Array( double, nDims, "Mesh::minLocalCrd" );
-	self->maxLocalCrd = Memory_Alloc_Array( double, nDims, "Mesh::maxLocalCrd" );
-	self->minDomainCrd = Memory_Alloc_Array( double, nDims, "Mesh::minLocalCrd" );
-	self->maxDomainCrd = Memory_Alloc_Array( double, nDims, "Mesh::maxLocalCrd" );
-	self->minGlobalCrd = Memory_Alloc_Array( double, nDims, "Mesh::minGlobalCrd" );
-	self->maxGlobalCrd = Memory_Alloc_Array( double, nDims, "Mesh::maxGlobalCrd" );
-
-	Mesh_DeformationUpdate( self );
-}
-
-void _Mesh_Initialise( void* mesh, void* data ) {
-}
-
-void _Mesh_Execute( void* mesh, void* data ) {
-}
-
-void _Mesh_Destroy( void* mesh, void* data ) {
-   Mesh*		self = (Mesh*)mesh;
-   unsigned	d_i;
-
-   Mesh_Destruct( self );
-   Stg_Component_Destroy( self->algorithms, NULL, False );
-   Stg_Class_Delete( self->info );
-   Stg_Class_Delete( self->vars );
-   Stg_Class_Delete( self->topoDataSizes );
-
-   for( d_i = 0; d_i < (unsigned)Mesh_GetDimSize( self ); d_i++ ) {
-     if( self->topoDataInfos[d_i] )	
-       Stg_Class_Delete( self->topoDataInfos[d_i] );
-     if( self->topoDatas[d_i] )
-       Memory_Free( self->topoDatas[d_i] );
-   }
-   Memory_Free( self->topoDataInfos );
-   Memory_Free( self->topoDatas );
-
-   NewClass_Delete( self->topo );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void Mesh_SetExtensionManagerRegister( void* mesh, void* extMgrReg ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	self->emReg = (ExtensionManager_Register*)extMgrReg;
-	if( extMgrReg )
-		ExtensionManager_Register_Add( extMgrReg, self->info );
-}
-
-void Mesh_SetTopologyDataSize( void* mesh, MeshTopology_Dim dim, unsigned size ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	UIntMap_Insert( self->topoDataSizes, dim, size );
-}
-
-void Mesh_SetGenerator( void* mesh, void* generator ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	Mesh_Destruct( self );
-	self->generator = (MeshGenerator*)generator;
-}
-
-void Mesh_SetAlgorithms( void* mesh, void* algorithms ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self && Stg_CheckType( self, Mesh ) );
-
-   /* TODO: This is a hack, because the FreeObject below will try and
-      remove the mesh. This is normally ok but as the code is not
-      in a Destroy or Delete phase it's problematic. Problems like
-      this should be fixed with reference counters */
-	if( self->algorithms ) 
-   	self->algorithms->mesh = NULL;
-
-	FreeObject( self->algorithms );
-	if( algorithms ) {
-		assert( Stg_CheckType( algorithms, Mesh_Algorithms ) );
-		self->algorithms = (Mesh_Algorithms*)algorithms;
-	}
-	else
-		self->algorithms = Mesh_Algorithms_New( "", NULL );
-
-	Mesh_Algorithms_SetMesh( self->algorithms, self );
-}
-
-MeshTopology_Dim Mesh_GetDimSize( void* mesh ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return (MeshTopology_Dim)(self->topo->nDims);
-}
-
-unsigned Mesh_GetGlobalSize( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Decomp_GetNumGlobals( Sync_GetDecomp( IGraph_GetDomain( self->topo, dim ) ) );
-}
-
-unsigned Mesh_GetLocalSize( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	if( Class_IsSuper( self->topo, IGraph ) )
-		return Decomp_GetNumLocals( Sync_GetDecomp( IGraph_GetDomain( self->topo, dim ) ) );
-	else
-		return MeshTopology_GetNumCells( self->topo, dim );
-}
-
-unsigned Mesh_GetRemoteSize( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Sync_GetNumRemotes( IGraph_GetDomain( self->topo, dim ) );
-}
-
-unsigned Mesh_GetDomainSize( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	if( Class_IsSuper( self->topo, IGraph ) )
-		return Sync_GetNumDomains( IGraph_GetDomain( self->topo, dim ) );
-	else
-		return MeshTopology_GetNumCells( self->topo, dim );
-}
-
-unsigned Mesh_GetSharedSize( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Sync_GetNumShared( IGraph_GetDomain( self->topo, dim ) );
-}
-
-MeshTopology* Mesh_GetTopology( void* mesh ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	return self->topo;
-}
-
-Sync* Mesh_GetSync( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	return (Sync*)IGraph_GetDomain( self->topo, dim );
-}
-
-Bool Mesh_GlobalToDomain( void* mesh, MeshTopology_Dim dim, unsigned global, unsigned* domain ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Sync_TryGlobalToDomain( IGraph_GetDomain( self->topo, dim ), global, (int*)domain );
-}
-
-unsigned Mesh_DomainToGlobal( void* mesh, MeshTopology_Dim dim, unsigned domain ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Sync_DomainToGlobal( IGraph_GetDomain( self->topo, dim ), domain );
-}
-
-Bool Mesh_LocalToShared( void* mesh, MeshTopology_Dim dim, unsigned domain, unsigned* shared ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Sync_TryLocalToShared( IGraph_GetDomain( self->topo, dim ), domain, (int*)shared );
-}
-
-unsigned Mesh_SharedToLocal( void* mesh, MeshTopology_Dim dim, unsigned shared ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return Sync_SharedToLocal( IGraph_GetDomain( self->topo, dim ), shared );
-}
-
-unsigned Mesh_GetOwner( void* mesh, MeshTopology_Dim dim, unsigned remote ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	return Sync_GetOwner( IGraph_GetDomain( self->topo, dim ), remote );
-}
-
-void Mesh_GetSharers(
-	void*					mesh,
-	MeshTopology_Dim	dim,
-	int				shared, 
-	int*			nSharers,
-	const int**			sharers )
-{
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	Sync_GetSharers( IGraph_GetDomain( self->topo, dim ), shared, nSharers, sharers );
-}
-
-Bool Mesh_HasIncidence( void* mesh, MeshTopology_Dim fromDim, MeshTopology_Dim toDim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	return IGraph_HasIncidence( self->topo, fromDim, toDim );
-}
-
-unsigned Mesh_GetIncidenceSize( void* mesh, MeshTopology_Dim fromDim, unsigned fromInd, MeshTopology_Dim toDim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	return IGraph_GetIncidenceSize( self->topo, fromDim, fromInd, toDim );
-}
-
-void Mesh_GetIncidence( void* mesh, MeshTopology_Dim fromDim, unsigned fromInd, MeshTopology_Dim toDim, IArray* inc ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topo );
-
-	MeshTopology_GetIncidence( self->topo, fromDim, fromInd, toDim, inc );
-}
-
-unsigned Mesh_NearestVertex( void* mesh, double* point ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	return Mesh_Algorithms_NearestVertex( self->algorithms, point );
-}
-
-Bool Mesh_Search( void* mesh, double* point, MeshTopology_Dim* dim, unsigned* ind ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self && Stg_CheckType( self, Mesh ) );
-
-	return Mesh_Algorithms_Search( self->algorithms, point, dim, ind );
-}
-
-/* Mesh_SearchElements (
- * mesh -- is a mesh
- * point -- is a global coordinate
- * elInd -- will be filled in by a local elementID
- * )
- * returns:
- * False if the point is not in the DOMAIN space of the proc 
- * True if the point is in the DOMAIN space
- */
-Bool Mesh_SearchElements( void* mesh, double* point, unsigned* elInd ) {
-	Mesh*	self = (Mesh*)mesh;
-
-/* 	assert( self && Stg_CheckType( self, Mesh ) ); */
-
-	return Mesh_Algorithms_SearchElements( self->algorithms, point, elInd );
-}
-
-Bool Mesh_ElementHasPoint( void* mesh, unsigned element, double* point, 
-			   MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( element < Mesh_GetDomainSize( self, Mesh_GetDimSize( self ) ) );
-	assert( self->elTypeMap );
-	assert( self->elTypeMap[element] < self->nElTypes );
-	assert( self->elTypes[self->elTypeMap[element]] );
-
-	return Mesh_ElementType_ElementHasPoint( self->elTypes[self->elTypeMap[element]], element, point, 
-						 dim, ind );
-}
-
-Mesh_ElementType* Mesh_GetElementType( void* mesh, unsigned element ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( element < Mesh_GetDomainSize( self, Mesh_GetDimSize( self ) ) );
-	assert( self->elTypeMap );
-	assert( self->elTypeMap[element] < self->nElTypes );
-	assert( self->elTypes );
-
-	return self->elTypes[self->elTypeMap[element]];
-}
-
-Comm* Mesh_GetCommTopology( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	return (Comm*)MeshTopology_GetComm( self->topo );
-}
-
-double* Mesh_GetVertex( void* mesh, unsigned domain ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( domain < Mesh_GetDomainSize( self, MT_VERTEX ) );
-	assert( self->verts );
-
-	return self->verts[domain];
-}
-
-Bool Mesh_HasExtension( void* mesh, const Name name ) {
-	Mesh* self = (Mesh*)mesh;
-
-	assert( self );
-
-	return (ExtensionManager_GetHandle( self->info, (Name)name ) != (unsigned)(-1) ) ?  True : False;
-}
-
-void* _Mesh_GetExtension( void* mesh, const Name name ) {
-	Mesh* self = (Mesh*)mesh;
-
-	assert( self );
-	assert( ExtensionManager_GetHandle( self->info, (Name)name ) != (unsigned)(-1)  );
-
-	return ExtensionManager_Get( self->info, self, ExtensionManager_GetHandle( self->info, (Name)name )  );
-}
-
-void* Mesh_GetTopologyData( void* mesh, MeshTopology_Dim dim ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( self->topoDatas );
-	assert( dim < Mesh_GetDimSize( self ) );
-
-	return self->topoDatas[dim];
-}
-
-void Mesh_GetMinimumSeparation( void* mesh, double* minSep, double* axial ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( minSep );
-
-	*minSep = self->minSep;
-	if( axial )
-		memcpy( axial, self->minAxialSep, Mesh_GetDimSize( self ) * sizeof(double) );
-}
-
-void Mesh_GetLocalCoordRange( void* mesh, double* min, double* max ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( min );
-	assert( max );
-
-	memcpy( min, self->minLocalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
-	memcpy( max, self->maxLocalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
-}
-
-void Mesh_GetDomainCoordRange( void* mesh, double* min, double* max ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-	assert( min );
-	assert( max );
-
-	memcpy( min, self->minDomainCrd, Mesh_GetDimSize( self ) * sizeof(double) );
-	memcpy( max, self->maxDomainCrd, Mesh_GetDimSize( self ) * sizeof(double) );
-}
-
-void Mesh_GetGlobalCoordRange( void* mesh, double* min, double* max ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	memcpy( min, self->minGlobalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
-	memcpy( max, self->maxGlobalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
-}
-
-void Mesh_DeformationUpdate( void* mesh ) {
-	Mesh*	self = (Mesh*)mesh;
-
-	assert( self );
-
-	if( Mesh_GetDomainSize( self, (MeshTopology_Dim)0 ) ) {
-		self->minSep = Mesh_Algorithms_GetMinimumSeparation( self->algorithms, self->minAxialSep );
-		Mesh_Algorithms_GetLocalCoordRange( self->algorithms, self->minLocalCrd, self->maxLocalCrd );
-		Mesh_Algorithms_GetDomainCoordRange( self->algorithms, self->minDomainCrd, self->maxDomainCrd );
-		Mesh_Algorithms_GetGlobalCoordRange( self->algorithms, self->minGlobalCrd, self->maxGlobalCrd );
-
-		Mesh_Algorithms_Update( self->algorithms );
-	}
-}
-
-void Mesh_Sync( void* mesh ) {
-	Mesh*	self = (Mesh*)mesh;
-	const Sync* sync;
-	int nDims, nLocals;
-
-	assert( self );
-
-	sync = Mesh_GetSync( self, (MeshTopology_Dim)0 );
-	nDims = Mesh_GetDimSize( self );
-	nLocals = Mesh_GetLocalSize( self, (MeshTopology_Dim)0 );
-	Sync_SyncArray( sync, self->verts[0], nDims * sizeof(double), self->verts[nLocals], nDims * sizeof(double), nDims * sizeof(double) );
-
-	/* TODO
-	if( self->dataSyncArrays ) {
-		unsigned	d_i;
-
-		for( d_i = 0; d_i < Mesh_GetDimSize( self ); d_i++ ) {
-			if( self->dataSyncArrays[d_i] )
-				Decomp_Sync_Array_Sync( self->dataSyncArrays[d_i] );
-		}
-	}
-	*/
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-void Mesh_Destruct( Mesh* self ) {
-	unsigned	et_i/*, v_i*/;
-
-	for( et_i = 0; et_i < self->nElTypes; et_i++ )
-		Stg_Class_Delete( self->elTypes[et_i] );
-	KillArray( self->elTypes );
-	KillArray( self->elTypeMap );
-	self->nElTypes = 0;
-
-	KillArray( self->verts );
-
-	self->generator = NULL;
-	self->emReg = NULL;
-
-	/*
-	for( v_i = 0; v_i < List_GetSize( self->vars ); v_i++ ) {
-		MeshVariable*	var;
-
-		var = *(MeshVariable**)List_GetItem( self->vars, v_i );
-		MeshVariable_SetMesh( var, NULL );
-	}
-	List_Clear( self->vars );
-	*/
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshClass.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/MeshClass.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,663 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshClass.c 4184 2007-09-25 07:54:17Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type Mesh_Type = "Mesh";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh* Mesh_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Mesh);
+	Type                                                      type = Mesh_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Mesh_Delete;
+	Stg_Class_PrintFunction*                                _print = _Mesh_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_Mesh_New;
+	Stg_Component_ConstructFunction*                    _construct = _Mesh_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Mesh_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Mesh_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Mesh_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Mesh_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+
+	Mesh* self = _Mesh_New(  MESH_PASSARGS  );
+
+	_Mesh_Init( self, context );
+   return self;
+}
+
+Mesh* _Mesh_New(  MESH_DEFARGS  ) {
+	Mesh* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh) );
+	self = (Mesh*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	return self;
+}
+
+void _Mesh_Init( Mesh* self, AbstractContext* context ) {
+   self->context = context;
+	self->topo = (MeshTopology*)IGraph_New();
+	self->verts = NULL;
+
+	self->vars = List_New();
+	List_SetItemSize( self->vars, sizeof(MeshVariable*) );
+
+	self->minSep = 0.0;
+	self->minAxialSep = NULL;
+	self->minLocalCrd = NULL;
+	self->maxLocalCrd = NULL;
+	self->minDomainCrd = NULL;
+	self->maxDomainCrd = NULL;
+	self->minGlobalCrd = NULL;
+	self->maxGlobalCrd = NULL;
+
+	self->algorithms = Mesh_Algorithms_New( "", NULL );
+	Mesh_Algorithms_SetMesh( self->algorithms, self );
+	self->nElTypes = 0;
+	self->elTypes = NULL;
+	self->elTypeMap = NULL;
+
+	self->topoDataSizes = UIntMap_New();
+	self->topoDataInfos = NULL;
+	self->topoDatas = NULL;
+	self->info = ExtensionManager_New_OfExistingObject( "mesh_info", self );
+
+	self->generator = NULL;
+	self->emReg = NULL;
+
+	self->isCheckpointedAndReloaded = False;
+	self->requiresCheckpointing     = False;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_Delete( void* mesh ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	/* Delete the parent. */
+	_Stg_Component_Delete( self );
+}
+
+void _Mesh_Print( void* mesh, Stream* stream ) {
+	Mesh*	self = (Mesh*)mesh;
+	
+	/* Set the Journal for printing informations */
+	Stream* meshStream;
+	meshStream = Journal_Register( InfoStream_Type, (Name)"MeshStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh (ptr): (%p)\n", self );
+	_Stg_Component_Print( self, stream );
+}
+
+void _Mesh_AssignFromXML( void* mesh, Stg_ComponentFactory* cf, void* data ) {
+	Mesh*			self = (Mesh*)mesh;
+   AbstractContext* context = NULL;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	_Mesh_Init( self, context );
+}
+
+void _Mesh_Build( void* mesh, void* data ) {
+	Mesh*			self = (Mesh*)mesh;
+	unsigned		nDims;
+	unsigned		d_i;
+
+	assert( self );
+
+	if( self->generator ) {
+	   Stg_Component_Build( self->generator, data, False );
+	   MeshGenerator_Generate( self->generator, self, data );
+	}
+
+	nDims = Mesh_GetDimSize( self );
+	if( !nDims )
+		return;
+
+	self->topoDataInfos = Memory_Alloc_Array( ExtensionManager*, nDims, "mesh::topoDataInfos" );
+	self->topoDatas = Memory_Alloc_Array( void*, nDims, "mesh::topoDatas" );
+
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+		char		name[20];
+		unsigned	size;
+
+		if( !UIntMap_Map( self->topoDataSizes, d_i, &size ) || !size ||
+		    !Mesh_GetDomainSize( self, (MeshTopology_Dim)d_i ) )
+		{
+			self->topoDataInfos[d_i] = NULL;
+			self->topoDatas[d_i] = NULL;
+			continue;
+		}
+
+		sprintf( name, "topoData(%d)", d_i );
+		self->topoDataInfos[d_i] = ExtensionManager_New_OfStruct( name, size );
+		self->topoDatas[d_i] = (void*)ExtensionManager_Malloc( self->topoDataInfos[d_i], Mesh_GetDomainSize( self, (MeshTopology_Dim)d_i ) );
+	}
+
+	/*
+	** Set up the geometric information.
+	*/
+
+	self->minAxialSep = Memory_Alloc_Array( double, nDims, "Mesh::minAxialSep" );
+	self->minLocalCrd = Memory_Alloc_Array( double, nDims, "Mesh::minLocalCrd" );
+	self->maxLocalCrd = Memory_Alloc_Array( double, nDims, "Mesh::maxLocalCrd" );
+	self->minDomainCrd = Memory_Alloc_Array( double, nDims, "Mesh::minLocalCrd" );
+	self->maxDomainCrd = Memory_Alloc_Array( double, nDims, "Mesh::maxLocalCrd" );
+	self->minGlobalCrd = Memory_Alloc_Array( double, nDims, "Mesh::minGlobalCrd" );
+	self->maxGlobalCrd = Memory_Alloc_Array( double, nDims, "Mesh::maxGlobalCrd" );
+
+	Mesh_DeformationUpdate( self );
+}
+
+void _Mesh_Initialise( void* mesh, void* data ) {
+}
+
+void _Mesh_Execute( void* mesh, void* data ) {
+}
+
+void _Mesh_Destroy( void* mesh, void* data ) {
+   Mesh*		self = (Mesh*)mesh;
+   unsigned	d_i;
+
+   Mesh_Destruct( self );
+   Stg_Component_Destroy( self->algorithms, NULL, False );
+   Stg_Class_Delete( self->info );
+   Stg_Class_Delete( self->vars );
+   Stg_Class_Delete( self->topoDataSizes );
+
+   for( d_i = 0; d_i < (unsigned)Mesh_GetDimSize( self ); d_i++ ) {
+     if( self->topoDataInfos[d_i] )	
+       Stg_Class_Delete( self->topoDataInfos[d_i] );
+     if( self->topoDatas[d_i] )
+       Memory_Free( self->topoDatas[d_i] );
+   }
+   Memory_Free( self->topoDataInfos );
+   Memory_Free( self->topoDatas );
+
+   NewClass_Delete( self->topo );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Mesh_SetExtensionManagerRegister( void* mesh, void* extMgrReg ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	self->emReg = (ExtensionManager_Register*)extMgrReg;
+	if( extMgrReg )
+		ExtensionManager_Register_Add( extMgrReg, self->info );
+}
+
+void Mesh_SetTopologyDataSize( void* mesh, MeshTopology_Dim dim, unsigned size ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	UIntMap_Insert( self->topoDataSizes, dim, size );
+}
+
+void Mesh_SetGenerator( void* mesh, void* generator ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	Mesh_Destruct( self );
+	self->generator = (MeshGenerator*)generator;
+}
+
+void Mesh_SetAlgorithms( void* mesh, void* algorithms ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self && Stg_CheckType( self, Mesh ) );
+
+   /* TODO: This is a hack, because the FreeObject below will try and
+      remove the mesh. This is normally ok but as the code is not
+      in a Destroy or Delete phase it's problematic. Problems like
+      this should be fixed with reference counters */
+	if( self->algorithms ) 
+   	self->algorithms->mesh = NULL;
+
+	FreeObject( self->algorithms );
+	if( algorithms ) {
+		assert( Stg_CheckType( algorithms, Mesh_Algorithms ) );
+		self->algorithms = (Mesh_Algorithms*)algorithms;
+	}
+	else
+		self->algorithms = Mesh_Algorithms_New( "", NULL );
+
+	Mesh_Algorithms_SetMesh( self->algorithms, self );
+}
+
+MeshTopology_Dim Mesh_GetDimSize( void* mesh ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return (MeshTopology_Dim)(self->topo->nDims);
+}
+
+unsigned Mesh_GetGlobalSize( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Decomp_GetNumGlobals( Sync_GetDecomp( IGraph_GetDomain( self->topo, dim ) ) );
+}
+
+unsigned Mesh_GetLocalSize( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	if( Class_IsSuper( self->topo, IGraph ) )
+		return Decomp_GetNumLocals( Sync_GetDecomp( IGraph_GetDomain( self->topo, dim ) ) );
+	else
+		return MeshTopology_GetNumCells( self->topo, dim );
+}
+
+unsigned Mesh_GetRemoteSize( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Sync_GetNumRemotes( IGraph_GetDomain( self->topo, dim ) );
+}
+
+unsigned Mesh_GetDomainSize( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	if( Class_IsSuper( self->topo, IGraph ) )
+		return Sync_GetNumDomains( IGraph_GetDomain( self->topo, dim ) );
+	else
+		return MeshTopology_GetNumCells( self->topo, dim );
+}
+
+unsigned Mesh_GetSharedSize( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Sync_GetNumShared( IGraph_GetDomain( self->topo, dim ) );
+}
+
+MeshTopology* Mesh_GetTopology( void* mesh ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	return self->topo;
+}
+
+Sync* Mesh_GetSync( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	return (Sync*)IGraph_GetDomain( self->topo, dim );
+}
+
+Bool Mesh_GlobalToDomain( void* mesh, MeshTopology_Dim dim, unsigned global, unsigned* domain ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Sync_TryGlobalToDomain( IGraph_GetDomain( self->topo, dim ), global, (int*)domain );
+}
+
+unsigned Mesh_DomainToGlobal( void* mesh, MeshTopology_Dim dim, unsigned domain ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Sync_DomainToGlobal( IGraph_GetDomain( self->topo, dim ), domain );
+}
+
+Bool Mesh_LocalToShared( void* mesh, MeshTopology_Dim dim, unsigned domain, unsigned* shared ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Sync_TryLocalToShared( IGraph_GetDomain( self->topo, dim ), domain, (int*)shared );
+}
+
+unsigned Mesh_SharedToLocal( void* mesh, MeshTopology_Dim dim, unsigned shared ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return Sync_SharedToLocal( IGraph_GetDomain( self->topo, dim ), shared );
+}
+
+unsigned Mesh_GetOwner( void* mesh, MeshTopology_Dim dim, unsigned remote ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	return Sync_GetOwner( IGraph_GetDomain( self->topo, dim ), remote );
+}
+
+void Mesh_GetSharers(
+	void*					mesh,
+	MeshTopology_Dim	dim,
+	int				shared, 
+	int*			nSharers,
+	const int**			sharers )
+{
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	Sync_GetSharers( IGraph_GetDomain( self->topo, dim ), shared, nSharers, sharers );
+}
+
+Bool Mesh_HasIncidence( void* mesh, MeshTopology_Dim fromDim, MeshTopology_Dim toDim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	return IGraph_HasIncidence( self->topo, fromDim, toDim );
+}
+
+unsigned Mesh_GetIncidenceSize( void* mesh, MeshTopology_Dim fromDim, unsigned fromInd, MeshTopology_Dim toDim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	return IGraph_GetIncidenceSize( self->topo, fromDim, fromInd, toDim );
+}
+
+void Mesh_GetIncidence( void* mesh, MeshTopology_Dim fromDim, unsigned fromInd, MeshTopology_Dim toDim, IArray* inc ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topo );
+
+	MeshTopology_GetIncidence( self->topo, fromDim, fromInd, toDim, inc );
+}
+
+unsigned Mesh_NearestVertex( void* mesh, double* point ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	return Mesh_Algorithms_NearestVertex( self->algorithms, point );
+}
+
+Bool Mesh_Search( void* mesh, double* point, MeshTopology_Dim* dim, unsigned* ind ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self && Stg_CheckType( self, Mesh ) );
+
+	return Mesh_Algorithms_Search( self->algorithms, point, dim, ind );
+}
+
+/* Mesh_SearchElements (
+ * mesh -- is a mesh
+ * point -- is a global coordinate
+ * elInd -- will be filled in by a local elementID
+ * )
+ * returns:
+ * False if the point is not in the DOMAIN space of the proc 
+ * True if the point is in the DOMAIN space
+ */
+Bool Mesh_SearchElements( void* mesh, double* point, unsigned* elInd ) {
+	Mesh*	self = (Mesh*)mesh;
+
+/* 	assert( self && Stg_CheckType( self, Mesh ) ); */
+
+	return Mesh_Algorithms_SearchElements( self->algorithms, point, elInd );
+}
+
+Bool Mesh_ElementHasPoint( void* mesh, unsigned element, double* point, 
+			   MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( element < Mesh_GetDomainSize( self, Mesh_GetDimSize( self ) ) );
+	assert( self->elTypeMap );
+	assert( self->elTypeMap[element] < self->nElTypes );
+	assert( self->elTypes[self->elTypeMap[element]] );
+
+	return Mesh_ElementType_ElementHasPoint( self->elTypes[self->elTypeMap[element]], element, point, 
+						 dim, ind );
+}
+
+Mesh_ElementType* Mesh_GetElementType( void* mesh, unsigned element ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( element < Mesh_GetDomainSize( self, Mesh_GetDimSize( self ) ) );
+	assert( self->elTypeMap );
+	assert( self->elTypeMap[element] < self->nElTypes );
+	assert( self->elTypes );
+
+	return self->elTypes[self->elTypeMap[element]];
+}
+
+Comm* Mesh_GetCommTopology( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	return (Comm*)MeshTopology_GetComm( self->topo );
+}
+
+double* Mesh_GetVertex( void* mesh, unsigned domain ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( domain < Mesh_GetDomainSize( self, MT_VERTEX ) );
+	assert( self->verts );
+
+	return self->verts[domain];
+}
+
+Bool Mesh_HasExtension( void* mesh, const Name name ) {
+	Mesh* self = (Mesh*)mesh;
+
+	assert( self );
+
+	return (ExtensionManager_GetHandle( self->info, (Name)name ) != (unsigned)(-1) ) ?  True : False;
+}
+
+void* _Mesh_GetExtension( void* mesh, const Name name ) {
+	Mesh* self = (Mesh*)mesh;
+
+	assert( self );
+	assert( ExtensionManager_GetHandle( self->info, (Name)name ) != (unsigned)(-1)  );
+
+	return ExtensionManager_Get( self->info, self, ExtensionManager_GetHandle( self->info, (Name)name )  );
+}
+
+void* Mesh_GetTopologyData( void* mesh, MeshTopology_Dim dim ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( self->topoDatas );
+	assert( dim < Mesh_GetDimSize( self ) );
+
+	return self->topoDatas[dim];
+}
+
+void Mesh_GetMinimumSeparation( void* mesh, double* minSep, double* axial ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( minSep );
+
+	*minSep = self->minSep;
+	if( axial )
+		memcpy( axial, self->minAxialSep, Mesh_GetDimSize( self ) * sizeof(double) );
+}
+
+void Mesh_GetLocalCoordRange( void* mesh, double* min, double* max ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( min );
+	assert( max );
+
+	memcpy( min, self->minLocalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
+	memcpy( max, self->maxLocalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
+}
+
+void Mesh_GetDomainCoordRange( void* mesh, double* min, double* max ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+	assert( min );
+	assert( max );
+
+	memcpy( min, self->minDomainCrd, Mesh_GetDimSize( self ) * sizeof(double) );
+	memcpy( max, self->maxDomainCrd, Mesh_GetDimSize( self ) * sizeof(double) );
+}
+
+void Mesh_GetGlobalCoordRange( void* mesh, double* min, double* max ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	memcpy( min, self->minGlobalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
+	memcpy( max, self->maxGlobalCrd, Mesh_GetDimSize( self ) * sizeof(double) );
+}
+
+void Mesh_DeformationUpdate( void* mesh ) {
+	Mesh*	self = (Mesh*)mesh;
+
+	assert( self );
+
+	if( Mesh_GetDomainSize( self, (MeshTopology_Dim)0 ) ) {
+		self->minSep = Mesh_Algorithms_GetMinimumSeparation( self->algorithms, self->minAxialSep );
+		Mesh_Algorithms_GetLocalCoordRange( self->algorithms, self->minLocalCrd, self->maxLocalCrd );
+		Mesh_Algorithms_GetDomainCoordRange( self->algorithms, self->minDomainCrd, self->maxDomainCrd );
+		Mesh_Algorithms_GetGlobalCoordRange( self->algorithms, self->minGlobalCrd, self->maxGlobalCrd );
+
+		Mesh_Algorithms_Update( self->algorithms );
+	}
+}
+
+void Mesh_Sync( void* mesh ) {
+	Mesh*	self = (Mesh*)mesh;
+	const Sync* sync;
+	int nDims, nLocals;
+
+	assert( self );
+
+	sync = Mesh_GetSync( self, (MeshTopology_Dim)0 );
+	nDims = Mesh_GetDimSize( self );
+	nLocals = Mesh_GetLocalSize( self, (MeshTopology_Dim)0 );
+	Sync_SyncArray( sync, self->verts[0], nDims * sizeof(double), self->verts[nLocals], nDims * sizeof(double), nDims * sizeof(double) );
+
+	/* TODO
+	if( self->dataSyncArrays ) {
+		unsigned	d_i;
+
+		for( d_i = 0; d_i < Mesh_GetDimSize( self ); d_i++ ) {
+			if( self->dataSyncArrays[d_i] )
+				Decomp_Sync_Array_Sync( self->dataSyncArrays[d_i] );
+		}
+	}
+	*/
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void Mesh_Destruct( Mesh* self ) {
+	unsigned	et_i/*, v_i*/;
+
+	for( et_i = 0; et_i < self->nElTypes; et_i++ )
+		Stg_Class_Delete( self->elTypes[et_i] );
+	KillArray( self->elTypes );
+	KillArray( self->elTypeMap );
+	self->nElTypes = 0;
+
+	KillArray( self->verts );
+
+	self->generator = NULL;
+	self->emReg = NULL;
+
+	/*
+	for( v_i = 0; v_i < List_GetSize( self->vars ); v_i++ ) {
+		MeshVariable*	var;
+
+		var = *(MeshVariable**)List_GetItem( self->vars, v_i );
+		MeshVariable_SetMesh( var, NULL );
+	}
+	List_Clear( self->vars );
+	*/
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshGenerator.c
--- a/Mesh/src/MeshGenerator.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,347 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshGenerator.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "MeshClass.h"
-#include "MeshGenerator.h"
-
-
-/* Textual name of this class */
-const Type MeshGenerator_Type = "MeshGenerator";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-MeshGenerator* _MeshGenerator_New(  MESHGENERATOR_DEFARGS  ) {
-	MeshGenerator*	self;
-
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MeshGenerator) );
-	self = (MeshGenerator*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	/* Virtual info */
-	self->setDimSizeFunc = setDimSizeFunc;
-	self->generateFunc = generateFunc;
-
-	return self;
-}
-
-void _MeshGenerator_Init( MeshGenerator* self, AbstractContext* context ) {
-   self->context = context;
-	self->mpiComm = MPI_COMM_WORLD;
-	self->nMeshes = 0;
-	self->meshes = NULL;
-	self->nDims = 0;
-	self->enabledDims = NULL;
-	self->enabledInc = NULL;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _MeshGenerator_Delete( void* meshGenerator ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-
-	_Stg_Component_Delete( self );
-}
-
-void _MeshGenerator_Print( void* meshGenerator, Stream* stream ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-	
-	/* Set the Journal for printing informations */
-	Stream* meshGeneratorStream;
-	meshGeneratorStream = Journal_Register( InfoStream_Type, (Name)"MeshGeneratorStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "MeshGenerator (ptr): (%p)\n", self );
-	_Stg_Component_Print( self, stream );
-}
-
-void _MeshGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
-	MeshGenerator*		self = (MeshGenerator*)meshGenerator;
-	Dictionary*		dict;
-	unsigned		nDims;
-	Dictionary_Entry_Value*	meshList;
-	Dictionary_Entry_Value	*enabledDimsList, *enabledIncList;
-	Mesh*			mesh;
-
-	assert( self );
-	assert( cf );
-
-	/* Rip out the components structure as a dictionary. */
-	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
-
-	/* Set the communicator to a default. */
-	MeshGenerator_SetMPIComm( self, MPI_COMM_WORLD );
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !self->context  )
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	/* Read the individual mesh if specified. */
-	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, False, data );
-	if( mesh  )
-		MeshGenerator_AddMesh( self, mesh );
-
-	/* Read the mesh list, if it's there. */
-	meshList = Dictionary_Get( dict, (Dictionary_Entry_Key)"meshes" );
-	if( meshList ) {
-		unsigned	nMeshes;
-		char*		name;
-		unsigned	m_i;
-
-		nMeshes = Dictionary_Entry_Value_GetCount( meshList );
-		for( m_i = 0; m_i < nMeshes; m_i++  ) {
-			Mesh*	mesh;
-
-			name = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( meshList, m_i ) );
-			mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)name, Mesh, True, data  );
-			MeshGenerator_AddMesh( self, mesh );
-		}
-	}
-
-	/* Read dimensions and state. */
-	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dim", 2 );
-	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dims", nDims );
-	MeshGenerator_SetDimSize( self, nDims );
-	enabledDimsList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledDims"  );
-	enabledIncList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledIncidence"  );
-
-    /* Clear dims/incidence flags */
-    unsigned    d_i;
-    memset( self->enabledDims, 0, (nDims + 1) * sizeof(Bool) );
-    for( d_i = 0; d_i <= nDims; d_i++ )
-        memset( self->enabledInc[d_i], 0, (nDims + 1) * sizeof(Bool) );
-
-    if( enabledDimsList ) {
-        unsigned    dim;
-        unsigned    nEnabledDims;
-        nEnabledDims = Dictionary_Entry_Value_GetCount( enabledDimsList );
-        for( d_i = 0; d_i < nEnabledDims; d_i++ ) {
-            dim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledDimsList, d_i ) );
-            if (dim > nDims + 1)
-                Journal_Printf(Mesh_Warning, "Warning - in %s: *** Skipping out of range dimension: %d\n", __func__, dim);
-            else
-                MeshGenerator_SetDimState( self, dim, True );
-        }
-    }
-    else
-    {
-        /* Default to all dimensions enabled */
-        for( d_i = 0; d_i < nDims + 1; d_i++ ) 
-            MeshGenerator_SetDimState( self, d_i, True );
-    }
-
-    if( enabledIncList ) {
-        unsigned    nEnabledInc;
-        unsigned    fromDim, toDim;
-        nEnabledInc = Dictionary_Entry_Value_GetCount( enabledIncList );
-        assert( nEnabledInc % 2 == 0 );
-        for( d_i = 0; d_i < nEnabledInc; d_i += 2 ) {
-            fromDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i ) );
-            toDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i + 1 ) );
-            if (fromDim > nDims || toDim > nDims) 
-                Journal_Printf( Mesh_Warning, "Warning - in %s: *** Skipping out of range incidence: %d to %d\n", 
-                            __func__ , fromDim, toDim);
-            else
-                MeshGenerator_SetIncidenceState( self, fromDim, toDim, True );
-        }
-    }
-    else
-    {
-        /* Default incidence setup 0->1,2,3  1->0,2  2->0,1  3->0 */
-        MeshGenerator_SetIncidenceState( self, 0, 0, True );
-        for( d_i = 1; d_i <= nDims; d_i ++ ) {
-            MeshGenerator_SetIncidenceState( self, 0, d_i, True );
-            MeshGenerator_SetIncidenceState( self, d_i, 0, True );
-        }
-        if (nDims >= 2) {
-            MeshGenerator_SetIncidenceState( self, 1, 2, True );
-            MeshGenerator_SetIncidenceState( self, 2, 1, True );
-        }
-    }
-}
-
-void _MeshGenerator_Build( void* meshGenerator, void* data ) {
-}
-
-void _MeshGenerator_Initialise( void* meshGenerator, void* data ) {
-}
-
-void _MeshGenerator_Execute( void* meshGenerator, void* data ) {
-}
-
-void _MeshGenerator_Destroy( void* meshGenerator, void* data ) {
-   MeshGenerator* self = (MeshGenerator*)meshGenerator;
-
-   MeshGenerator_Destruct( self );
-}
-
-void MeshGenerator_SetFullIncidence( void* meshGenerator ) {
-	MeshGenerator* self = (MeshGenerator*)meshGenerator;
-	unsigned d_i, d_j;
-
-	assert( self );
-
-	for( d_i = 0; d_i <= self->nDims; d_i++ ) {
-		self->enabledDims[d_i] = True;
-		for( d_j = 0; d_j <= self->nDims; d_j++ )
-			self->enabledInc[d_i][d_j] = True;
-	}
-}
-
-void _MeshGenerator_SetDimSize( void* meshGenerator, unsigned nDims ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-	unsigned	d_i, d_j;
-
-	assert( self && Stg_CheckType( self, MeshGenerator ) );
-
-	self->nDims = nDims;
-	self->enabledDims = ReallocArray( self->enabledDims, Bool, nDims + 1 );
-	self->enabledInc = ReallocArray2D( self->enabledInc, Bool, nDims + 1, nDims + 1 );
-	for( d_i = 0; d_i <= nDims; d_i++ ) {
-		if( d_i == 0 || d_i == nDims )
-			self->enabledDims[d_i] = True;
-		else
-			self->enabledDims[d_i] = False;
-		for( d_j = 0; d_j <= nDims; d_j++ ) {
-			if( (d_i == 0 || d_i == nDims) && (d_j == 0 || d_j == nDims) ) {
-				if( d_i == d_j && d_j == nDims )
-					self->enabledInc[d_i][d_j] = False;
-				else
-					self->enabledInc[d_i][d_j] = True;
-			}
-			else
-				self->enabledInc[d_i][d_j] = False;
-		}
-	}
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void MeshGenerator_SetMPIComm( void* meshGenerator, MPI_Comm mpiComm ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-
-	/* Sanity check. */
-	assert( self );
-
-	/* Should probably kill some stuff when I do this. Oh well. */
-	self->mpiComm = mpiComm;
-}
-
-void MeshGenerator_AddMesh( void* meshGenerator, void* mesh ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-
-	/* Sanity check. */
-	assert( self );
-
-	/* If not already allocated, allocate now. */
-	if( !self->meshes ) {
-		self->nMeshes = 1;
-		self->meshes = Memory_Alloc_Array( Mesh*, 1, "MeshGenerator::meshes" );
-	}
-	else {
-		/* Otherwise reallocate. */
-		self->nMeshes++;
-		self->meshes = Memory_Realloc_Array( self->meshes, Mesh*, self->nMeshes );
-	}
-
-	/* Add the new mesh. */
-	self->meshes[self->nMeshes - 1] = (Mesh*)mesh;
-	((Mesh*)mesh)->generator = self;
-}
-
-void MeshGenerator_SetDimState( void* meshGenerator, unsigned dim, Bool state ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-
-	assert( self && Stg_CheckType( self, MeshGenerator ) );
-	assert( dim <= self->nDims );
-	assert( self->enabledDims );
-
-	self->enabledDims[dim] = state;
-}
-
-void MeshGenerator_ClearIncidenceStates( void* meshGenerator ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-	unsigned	d_i, d_j;
-
-	assert( self && Stg_CheckType( self, MeshGenerator ) );
-
-	for( d_i = 0; d_i <= self->nDims; d_i++ ) {
-		for( d_j = 0; d_j <= self->nDims; d_j++ )
-			self->enabledInc[d_i][d_j] = False;
-	}
-}
-
-void MeshGenerator_SetIncidenceState( void* meshGenerator, unsigned fromDim, unsigned toDim, Bool state ) {
-	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
-
-	assert( self && Stg_CheckType( self, MeshGenerator ) );
-	assert( fromDim <= self->nDims );
-	assert( toDim <= self->nDims );
-	assert( self->enabledInc );
-
-	self->enabledInc[fromDim][toDim] = state;
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-void MeshGenerator_Destruct( MeshGenerator* self ) {
-	assert( self && Stg_CheckType( self, MeshGenerator ) );
-
-	KillArray( self->enabledDims );
-	KillArray( self->enabledInc );
-	KillArray( self->meshes );
-	self->nMeshes = 0;
-	self->nDims = 0;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshGenerator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/MeshGenerator.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,347 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshGenerator.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "MeshClass.h"
+#include "MeshGenerator.h"
+
+
+/* Textual name of this class */
+const Type MeshGenerator_Type = "MeshGenerator";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+MeshGenerator* _MeshGenerator_New(  MESHGENERATOR_DEFARGS  ) {
+	MeshGenerator*	self;
+
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MeshGenerator) );
+	self = (MeshGenerator*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	/* Virtual info */
+	self->setDimSizeFunc = setDimSizeFunc;
+	self->generateFunc = generateFunc;
+
+	return self;
+}
+
+void _MeshGenerator_Init( MeshGenerator* self, AbstractContext* context ) {
+   self->context = context;
+	self->mpiComm = MPI_COMM_WORLD;
+	self->nMeshes = 0;
+	self->meshes = NULL;
+	self->nDims = 0;
+	self->enabledDims = NULL;
+	self->enabledInc = NULL;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _MeshGenerator_Delete( void* meshGenerator ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+
+	_Stg_Component_Delete( self );
+}
+
+void _MeshGenerator_Print( void* meshGenerator, Stream* stream ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+	
+	/* Set the Journal for printing informations */
+	Stream* meshGeneratorStream;
+	meshGeneratorStream = Journal_Register( InfoStream_Type, (Name)"MeshGeneratorStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "MeshGenerator (ptr): (%p)\n", self );
+	_Stg_Component_Print( self, stream );
+}
+
+void _MeshGenerator_AssignFromXML( void* meshGenerator, Stg_ComponentFactory* cf, void* data ) {
+	MeshGenerator*		self = (MeshGenerator*)meshGenerator;
+	Dictionary*		dict;
+	unsigned		nDims;
+	Dictionary_Entry_Value*	meshList;
+	Dictionary_Entry_Value	*enabledDimsList, *enabledIncList;
+	Mesh*			mesh;
+
+	assert( self );
+	assert( cf );
+
+	/* Rip out the components structure as a dictionary. */
+	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
+
+	/* Set the communicator to a default. */
+	MeshGenerator_SetMPIComm( self, MPI_COMM_WORLD );
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !self->context  )
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	/* Read the individual mesh if specified. */
+	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, False, data );
+	if( mesh  )
+		MeshGenerator_AddMesh( self, mesh );
+
+	/* Read the mesh list, if it's there. */
+	meshList = Dictionary_Get( dict, (Dictionary_Entry_Key)"meshes" );
+	if( meshList ) {
+		unsigned	nMeshes;
+		char*		name;
+		unsigned	m_i;
+
+		nMeshes = Dictionary_Entry_Value_GetCount( meshList );
+		for( m_i = 0; m_i < nMeshes; m_i++  ) {
+			Mesh*	mesh;
+
+			name = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( meshList, m_i ) );
+			mesh = Stg_ComponentFactory_ConstructByName( cf, (Name)name, Mesh, True, data  );
+			MeshGenerator_AddMesh( self, mesh );
+		}
+	}
+
+	/* Read dimensions and state. */
+	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dim", 2 );
+	nDims = Stg_ComponentFactory_GetUnsignedInt( cf, self->name,  (Dictionary_Entry_Key)"dims", nDims );
+	MeshGenerator_SetDimSize( self, nDims );
+	enabledDimsList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledDims"  );
+	enabledIncList = Dictionary_Get( dict, (Dictionary_Entry_Key)"enabledIncidence"  );
+
+    /* Clear dims/incidence flags */
+    unsigned    d_i;
+    memset( self->enabledDims, 0, (nDims + 1) * sizeof(Bool) );
+    for( d_i = 0; d_i <= nDims; d_i++ )
+        memset( self->enabledInc[d_i], 0, (nDims + 1) * sizeof(Bool) );
+
+    if( enabledDimsList ) {
+        unsigned    dim;
+        unsigned    nEnabledDims;
+        nEnabledDims = Dictionary_Entry_Value_GetCount( enabledDimsList );
+        for( d_i = 0; d_i < nEnabledDims; d_i++ ) {
+            dim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledDimsList, d_i ) );
+            if (dim > nDims + 1)
+                Journal_Printf(Mesh_Warning, "Warning - in %s: *** Skipping out of range dimension: %d\n", __func__, dim);
+            else
+                MeshGenerator_SetDimState( self, dim, True );
+        }
+    }
+    else
+    {
+        /* Default to all dimensions enabled */
+        for( d_i = 0; d_i < nDims + 1; d_i++ ) 
+            MeshGenerator_SetDimState( self, d_i, True );
+    }
+
+    if( enabledIncList ) {
+        unsigned    nEnabledInc;
+        unsigned    fromDim, toDim;
+        nEnabledInc = Dictionary_Entry_Value_GetCount( enabledIncList );
+        assert( nEnabledInc % 2 == 0 );
+        for( d_i = 0; d_i < nEnabledInc; d_i += 2 ) {
+            fromDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i ) );
+            toDim = Dictionary_Entry_Value_AsUnsignedInt( Dictionary_Entry_Value_GetElement( enabledIncList, d_i + 1 ) );
+            if (fromDim > nDims || toDim > nDims) 
+                Journal_Printf( Mesh_Warning, "Warning - in %s: *** Skipping out of range incidence: %d to %d\n", 
+                            __func__ , fromDim, toDim);
+            else
+                MeshGenerator_SetIncidenceState( self, fromDim, toDim, True );
+        }
+    }
+    else
+    {
+        /* Default incidence setup 0->1,2,3  1->0,2  2->0,1  3->0 */
+        MeshGenerator_SetIncidenceState( self, 0, 0, True );
+        for( d_i = 1; d_i <= nDims; d_i ++ ) {
+            MeshGenerator_SetIncidenceState( self, 0, d_i, True );
+            MeshGenerator_SetIncidenceState( self, d_i, 0, True );
+        }
+        if (nDims >= 2) {
+            MeshGenerator_SetIncidenceState( self, 1, 2, True );
+            MeshGenerator_SetIncidenceState( self, 2, 1, True );
+        }
+    }
+}
+
+void _MeshGenerator_Build( void* meshGenerator, void* data ) {
+}
+
+void _MeshGenerator_Initialise( void* meshGenerator, void* data ) {
+}
+
+void _MeshGenerator_Execute( void* meshGenerator, void* data ) {
+}
+
+void _MeshGenerator_Destroy( void* meshGenerator, void* data ) {
+   MeshGenerator* self = (MeshGenerator*)meshGenerator;
+
+   MeshGenerator_Destruct( self );
+}
+
+void MeshGenerator_SetFullIncidence( void* meshGenerator ) {
+	MeshGenerator* self = (MeshGenerator*)meshGenerator;
+	unsigned d_i, d_j;
+
+	assert( self );
+
+	for( d_i = 0; d_i <= self->nDims; d_i++ ) {
+		self->enabledDims[d_i] = True;
+		for( d_j = 0; d_j <= self->nDims; d_j++ )
+			self->enabledInc[d_i][d_j] = True;
+	}
+}
+
+void _MeshGenerator_SetDimSize( void* meshGenerator, unsigned nDims ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+	unsigned	d_i, d_j;
+
+	assert( self && Stg_CheckType( self, MeshGenerator ) );
+
+	self->nDims = nDims;
+	self->enabledDims = ReallocArray( self->enabledDims, Bool, nDims + 1 );
+	self->enabledInc = ReallocArray2D( self->enabledInc, Bool, nDims + 1, nDims + 1 );
+	for( d_i = 0; d_i <= nDims; d_i++ ) {
+		if( d_i == 0 || d_i == nDims )
+			self->enabledDims[d_i] = True;
+		else
+			self->enabledDims[d_i] = False;
+		for( d_j = 0; d_j <= nDims; d_j++ ) {
+			if( (d_i == 0 || d_i == nDims) && (d_j == 0 || d_j == nDims) ) {
+				if( d_i == d_j && d_j == nDims )
+					self->enabledInc[d_i][d_j] = False;
+				else
+					self->enabledInc[d_i][d_j] = True;
+			}
+			else
+				self->enabledInc[d_i][d_j] = False;
+		}
+	}
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void MeshGenerator_SetMPIComm( void* meshGenerator, MPI_Comm mpiComm ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+
+	/* Sanity check. */
+	assert( self );
+
+	/* Should probably kill some stuff when I do this. Oh well. */
+	self->mpiComm = mpiComm;
+}
+
+void MeshGenerator_AddMesh( void* meshGenerator, void* mesh ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+
+	/* Sanity check. */
+	assert( self );
+
+	/* If not already allocated, allocate now. */
+	if( !self->meshes ) {
+		self->nMeshes = 1;
+		self->meshes = Memory_Alloc_Array( Mesh*, 1, "MeshGenerator::meshes" );
+	}
+	else {
+		/* Otherwise reallocate. */
+		self->nMeshes++;
+		self->meshes = Memory_Realloc_Array( self->meshes, Mesh*, self->nMeshes );
+	}
+
+	/* Add the new mesh. */
+	self->meshes[self->nMeshes - 1] = (Mesh*)mesh;
+	((Mesh*)mesh)->generator = self;
+}
+
+void MeshGenerator_SetDimState( void* meshGenerator, unsigned dim, Bool state ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+
+	assert( self && Stg_CheckType( self, MeshGenerator ) );
+	assert( dim <= self->nDims );
+	assert( self->enabledDims );
+
+	self->enabledDims[dim] = state;
+}
+
+void MeshGenerator_ClearIncidenceStates( void* meshGenerator ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+	unsigned	d_i, d_j;
+
+	assert( self && Stg_CheckType( self, MeshGenerator ) );
+
+	for( d_i = 0; d_i <= self->nDims; d_i++ ) {
+		for( d_j = 0; d_j <= self->nDims; d_j++ )
+			self->enabledInc[d_i][d_j] = False;
+	}
+}
+
+void MeshGenerator_SetIncidenceState( void* meshGenerator, unsigned fromDim, unsigned toDim, Bool state ) {
+	MeshGenerator*	self = (MeshGenerator*)meshGenerator;
+
+	assert( self && Stg_CheckType( self, MeshGenerator ) );
+	assert( fromDim <= self->nDims );
+	assert( toDim <= self->nDims );
+	assert( self->enabledInc );
+
+	self->enabledInc[fromDim][toDim] = state;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void MeshGenerator_Destruct( MeshGenerator* self ) {
+	assert( self && Stg_CheckType( self, MeshGenerator ) );
+
+	KillArray( self->enabledDims );
+	KillArray( self->enabledInc );
+	KillArray( self->meshes );
+	self->nMeshes = 0;
+	self->nDims = 0;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshTopology.c
--- a/Mesh/src/MeshTopology.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshTopology.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include "StGermain/StGermain.h"
-#include "types.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-void _MeshTopology_Init( void* _self ) {
-   MeshTopology* self = (MeshTopology*)_self;
-
-   _NewClass_Init( self );
-   self->nDims = (MeshTopology_Dim)0;
-   self->nTDims = 0;
-   self->shadDepth = 0;
-   self->comm = NULL;
-}
-
-void _MeshTopology_Destruct( void* _self ) {
-   MeshTopology* self = (MeshTopology*)_self;
-
-   _NewClass_Destruct( self );
-}
-
-void _MeshTopology_Copy( void* _self, const void* op ) {
-   /*MeshTopology* self = (MeshTopology*)_self;*/
-
-   assert( 0 );
-   /* TODO */
-}
-
-SizeT _MeshTopology_CalcMem( const void* _self, PtrMap* ptrs ) {
-   MeshTopology* self = (MeshTopology*)_self;
-   SizeT mem;
-
-   if( PtrMap_Find( ptrs, (void*)self ) )
-      return 0;
-   mem = _NewClass_CalcMem( self, ptrs );
-   return mem;
-}
-
-void _MeshTopology_SetNumDims( void* _self, int nDims ) {
-   MeshTopology* self = (MeshTopology*)_self;
-
-   self->nDims = nDims;
-   if( self->nDims > 0 )
-      self->nTDims = nDims + 1;
-}
-
-void _MeshTopology_SetComm( void* _self, const Comm* comm ) {
-   MeshTopology* self = (MeshTopology*)_self;
-
-   NewClass_RemoveRef( self->comm );
-   self->comm = (Comm*)comm;
-   if( comm )
-      NewClass_AddRef( (Comm*)comm );
-}
-
-void _MeshTopology_SetShadowDepth( void* _self, int depth ) {
-   MeshTopology* self = (MeshTopology*)_self;
-
-   assert( self && depth >= 0 );
-   assert( self->comm && self->nTDims );
-
-   self->shadDepth = depth;
-}
-
-int MeshTopology_GetNumDims( const void* self ) {
-   assert( self );
-   return ((MeshTopology*)self)->nDims;
-}
-
-const Comm* MeshTopology_GetComm( const void* self ) {
-   assert( self );
-   return ((MeshTopology*)self)->comm;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshTopology.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/MeshTopology.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,111 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshTopology.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "StGermain/StGermain.h"
+#include "types.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+void _MeshTopology_Init( void* _self ) {
+   MeshTopology* self = (MeshTopology*)_self;
+
+   _NewClass_Init( self );
+   self->nDims = (MeshTopology_Dim)0;
+   self->nTDims = 0;
+   self->shadDepth = 0;
+   self->comm = NULL;
+}
+
+void _MeshTopology_Destruct( void* _self ) {
+   MeshTopology* self = (MeshTopology*)_self;
+
+   _NewClass_Destruct( self );
+}
+
+void _MeshTopology_Copy( void* _self, const void* op ) {
+   /*MeshTopology* self = (MeshTopology*)_self;*/
+
+   assert( 0 );
+   /* TODO */
+}
+
+SizeT _MeshTopology_CalcMem( const void* _self, PtrMap* ptrs ) {
+   MeshTopology* self = (MeshTopology*)_self;
+   SizeT mem;
+
+   if( PtrMap_Find( ptrs, (void*)self ) )
+      return 0;
+   mem = _NewClass_CalcMem( self, ptrs );
+   return mem;
+}
+
+void _MeshTopology_SetNumDims( void* _self, int nDims ) {
+   MeshTopology* self = (MeshTopology*)_self;
+
+   self->nDims = nDims;
+   if( self->nDims > 0 )
+      self->nTDims = nDims + 1;
+}
+
+void _MeshTopology_SetComm( void* _self, const Comm* comm ) {
+   MeshTopology* self = (MeshTopology*)_self;
+
+   NewClass_RemoveRef( self->comm );
+   self->comm = (Comm*)comm;
+   if( comm )
+      NewClass_AddRef( (Comm*)comm );
+}
+
+void _MeshTopology_SetShadowDepth( void* _self, int depth ) {
+   MeshTopology* self = (MeshTopology*)_self;
+
+   assert( self && depth >= 0 );
+   assert( self->comm && self->nTDims );
+
+   self->shadDepth = depth;
+}
+
+int MeshTopology_GetNumDims( const void* self ) {
+   assert( self );
+   return ((MeshTopology*)self)->nDims;
+}
+
+const Comm* MeshTopology_GetComm( const void* self ) {
+   assert( self );
+   return ((MeshTopology*)self)->comm;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshVariable.c
--- a/Mesh/src/MeshVariable.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,275 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshVariable.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type MeshVariable_Type = "MeshVariable";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-MeshVariable* MeshVariable_New( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(MeshVariable);
-	Type                                                      type = MeshVariable_Type;
-	Stg_Class_DeleteFunction*                              _delete = _MeshVariable_Delete;
-	Stg_Class_PrintFunction*                                _print = _MeshVariable_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_MeshVariable_New;
-	Stg_Component_ConstructFunction*                    _construct = _MeshVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _MeshVariable_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _MeshVariable_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _MeshVariable_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _MeshVariable_Destroy;
-	Index                                                dataCount = 0;
-	SizeT*                                             dataOffsets = NULL;
-	Variable_DataType*                                   dataTypes = NULL;
-	Index*                                          dataTypeCounts = NULL;
-	Name*                                                dataNames = NULL;
-	SizeT*                                           structSizePtr = NULL;
-	Index*                                            arraySizePtr = NULL;
-	Variable_ArraySizeFunc*                          arraySizeFunc = NULL;
-	void**                                             arrayPtrPtr = NULL;
-	Variable_Register*                                          vr = NULL;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	MeshVariable* self = _MeshVariable_New(  MESHVARIABLE_PASSARGS  );
-
-	_MeshVariable_Init( self );
-
-	return self;
-}
-
-MeshVariable* _MeshVariable_New(  MESHVARIABLE_DEFARGS  ) {
-	MeshVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MeshVariable) );
-	self = (MeshVariable*)_Variable_New(  VARIABLE_PASSARGS  );
-
-	/* Virtual info */
-
-	return self;
-}
-
-void _MeshVariable_Init( MeshVariable* self ) {
-	self->mesh = NULL;
-	self->topoDim = MT_VERTEX;
-	self->meshArraySize = 0;
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _MeshVariable_Delete( void* meshVariable ) {
-	MeshVariable*	self = (MeshVariable*)meshVariable;
-
-	/* Delete the parent. */
-	_Variable_Delete( self );
-}
-
-void _MeshVariable_Print( void* meshVariable, Stream* stream ) {
-	MeshVariable*	self = (MeshVariable*)meshVariable;
-	
-	/* Set the Journal for printing informations */
-	Stream* meshVariableStream;
-	meshVariableStream = Journal_Register( InfoStream_Type, (Name)"MeshVariableStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "MeshVariable (ptr): (%p)\n", self );
-	_Variable_Print( self, stream );
-}
-
-void _MeshVariable_AssignFromXML( void* meshVariable, Stg_ComponentFactory* cf, void* data ) {
-	MeshVariable*		self = (MeshVariable*)meshVariable;
-	SizeT					dataOffsets[] = { 0 };
-	Variable_DataType	dataTypes[] = { (Variable_DataType)0 };		/* Init value later */
-	Index					dataTypeCounts[] = { 1 };
-	Dictionary*			componentDict = NULL;
-	Dictionary*			thisComponentDict = NULL;
-	Name					dataTypeName = NULL;
-	Name					rankName = NULL;
-	void*					variableRegister = NULL;
-	void*					pointerRegister = NULL;
-	Name*					names = NULL;
-	Stream*				error = Journal_Register( Error_Type, (Name)self->type );
-	Mesh*					mesh;
-	AbstractContext*	context;
-	
-	assert( self );
-
-	componentDict = cf->componentDict;
-	assert( componentDict  );
-	thisComponentDict = Dictionary_GetDictionary( componentDict, self->name );
-	assert( thisComponentDict );
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
-	
-	/* Grab Registers */
-	variableRegister = context->variable_Register;
-	assert( variableRegister );
-	pointerRegister = context->pointer_Register;
-	assert( pointerRegister  );
-
-	/* Construct the mesh. */
-	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
-	MeshVariable_SetMesh( self, mesh );
-
-	/* Get the topological element we're intereseted in. */
-	self->topoDim = (MeshTopology_Dim)Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"topologicalDim", 0  );
-			
-	/* Get Type of Variable */
-	dataTypeName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"DataType"  );
-	if ( !strcasecmp( dataTypeName, "Double" ) )
-		dataTypes[0] = Variable_DataType_Double;
-	else if ( !strcasecmp( dataTypeName, "Float" ) )
-		dataTypes[0] = Variable_DataType_Float;
-	else if ( !strcasecmp( dataTypeName, "Int" ) )
-		dataTypes[0] = Variable_DataType_Int;
-	else if ( !strcasecmp( dataTypeName, "Char" ) )
-		dataTypes[0] = Variable_DataType_Char;
-	else if ( !strcasecmp( dataTypeName, "Short" ) )
-		dataTypes[0] = Variable_DataType_Short;
-	else 
-		Journal_Firewall( False, error, "Variable '%s' cannot understand data type '%s'\n", self->name, dataTypeName );
-
-	/* Get Rank of Variable - i.e. Scalar or Vector */
-	rankName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"Rank"  );
-	if( !strcasecmp( rankName, "Scalar" ) ){
-		dataTypeCounts[0] = 1;
-	}
-	else if ( !strcasecmp( rankName, "Vector" ) ){
-		Dictionary_Entry_Value* list;
-		Index                   nameCount = 0;
-
-		/* Get Names from list */
-		if (( list = Dictionary_Get( thisComponentDict, (Dictionary_Entry_Key)"names" ) )) {
-			Index entry_I;
-
-			nameCount = Dictionary_Entry_Value_GetCount( list  );
-			names = Memory_Alloc_Array( Name, nameCount, "Variable Names" );
-
-			for ( entry_I = 0 ; entry_I < nameCount ; entry_I++ )
-				names[ entry_I ] = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement(list, entry_I ) );
-		}
-		dataTypeCounts[0] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"VectorComponentCount", nameCount  );
-
-		Journal_Firewall( nameCount >= dataTypeCounts[0], error, "Variable '%s' has too few names in list for %d vector components.\n", self->name, dataTypeCounts[0] );
-	}
-	else
-		Journal_Firewall( False, error, "Variable '%s' cannot understand rank '%s'\n", self->name, rankName );
-
-	_Variable_Init( (Variable*)self, context, 1, dataOffsets, dataTypes, dataTypeCounts, names, 0, NULL, _MeshVariable_GetMeshArraySize, (void**)&self->arrayPtr, True, (Variable_Register*)variableRegister );
-
-	/* Clean Up */
-	if (names)
-		Memory_Free(names);
-}
-
-void _MeshVariable_Build( void* meshVariable, void* data ) {
-	MeshVariable*	self = (MeshVariable*)meshVariable;
-
-	assert( self );
-
-	/* We need to make sure the Mesh is built first, since this Variable and it's sub-components are going
-	 *  to ask for the Mesh Size etc. */	
-	Stg_Component_Build( self->mesh, data, False );
-
-	_Variable_Build( self, data );
-}
-
-void _MeshVariable_Initialise( void* meshVariable, void* data ) {
-	MeshVariable*	self = (MeshVariable*)meshVariable;
-
-    Stg_Component_Initialise( self->mesh, data, False );
-}
-
-void _MeshVariable_Execute( void* meshVariable, void* data ) {
-}
-
-void _MeshVariable_Destroy( void* meshVariable, void* data ) {
-	MeshVariable*	self = (MeshVariable*)meshVariable;
-
-	MeshVariable_Destruct( self );
-
-	Stg_Component_Destroy( self->mesh, data, False );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void MeshVariable_SetMesh( void* meshVariable, void* _mesh ) {
-	MeshVariable*	self = (MeshVariable*)meshVariable;
-	Mesh*				mesh = (Mesh*)_mesh;
-
-	assert( self );
-
-	MeshVariable_Destruct( self );
-
-	self->mesh = mesh;
-	if( mesh )
-		List_Append( mesh->vars, self );
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-void MeshVariable_Destruct( MeshVariable* self ) {
-}
-
-Index _MeshVariable_GetMeshArraySize( void* meshVariable ) {
-	MeshVariable* self = (MeshVariable*)meshVariable;
-
-	return Mesh_GetDomainSize( self->mesh, self->topoDim );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/MeshVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/MeshVariable.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,275 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshVariable.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type MeshVariable_Type = "MeshVariable";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+MeshVariable* MeshVariable_New( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(MeshVariable);
+	Type                                                      type = MeshVariable_Type;
+	Stg_Class_DeleteFunction*                              _delete = _MeshVariable_Delete;
+	Stg_Class_PrintFunction*                                _print = _MeshVariable_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_MeshVariable_New;
+	Stg_Component_ConstructFunction*                    _construct = _MeshVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _MeshVariable_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _MeshVariable_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _MeshVariable_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _MeshVariable_Destroy;
+	Index                                                dataCount = 0;
+	SizeT*                                             dataOffsets = NULL;
+	Variable_DataType*                                   dataTypes = NULL;
+	Index*                                          dataTypeCounts = NULL;
+	Name*                                                dataNames = NULL;
+	SizeT*                                           structSizePtr = NULL;
+	Index*                                            arraySizePtr = NULL;
+	Variable_ArraySizeFunc*                          arraySizeFunc = NULL;
+	void**                                             arrayPtrPtr = NULL;
+	Variable_Register*                                          vr = NULL;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	MeshVariable* self = _MeshVariable_New(  MESHVARIABLE_PASSARGS  );
+
+	_MeshVariable_Init( self );
+
+	return self;
+}
+
+MeshVariable* _MeshVariable_New(  MESHVARIABLE_DEFARGS  ) {
+	MeshVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MeshVariable) );
+	self = (MeshVariable*)_Variable_New(  VARIABLE_PASSARGS  );
+
+	/* Virtual info */
+
+	return self;
+}
+
+void _MeshVariable_Init( MeshVariable* self ) {
+	self->mesh = NULL;
+	self->topoDim = MT_VERTEX;
+	self->meshArraySize = 0;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _MeshVariable_Delete( void* meshVariable ) {
+	MeshVariable*	self = (MeshVariable*)meshVariable;
+
+	/* Delete the parent. */
+	_Variable_Delete( self );
+}
+
+void _MeshVariable_Print( void* meshVariable, Stream* stream ) {
+	MeshVariable*	self = (MeshVariable*)meshVariable;
+	
+	/* Set the Journal for printing informations */
+	Stream* meshVariableStream;
+	meshVariableStream = Journal_Register( InfoStream_Type, (Name)"MeshVariableStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "MeshVariable (ptr): (%p)\n", self );
+	_Variable_Print( self, stream );
+}
+
+void _MeshVariable_AssignFromXML( void* meshVariable, Stg_ComponentFactory* cf, void* data ) {
+	MeshVariable*		self = (MeshVariable*)meshVariable;
+	SizeT					dataOffsets[] = { 0 };
+	Variable_DataType	dataTypes[] = { (Variable_DataType)0 };		/* Init value later */
+	Index					dataTypeCounts[] = { 1 };
+	Dictionary*			componentDict = NULL;
+	Dictionary*			thisComponentDict = NULL;
+	Name					dataTypeName = NULL;
+	Name					rankName = NULL;
+	void*					variableRegister = NULL;
+	void*					pointerRegister = NULL;
+	Name*					names = NULL;
+	Stream*				error = Journal_Register( Error_Type, (Name)self->type );
+	Mesh*					mesh;
+	AbstractContext*	context;
+	
+	assert( self );
+
+	componentDict = cf->componentDict;
+	assert( componentDict  );
+	thisComponentDict = Dictionary_GetDictionary( componentDict, self->name );
+	assert( thisComponentDict );
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
+	
+	/* Grab Registers */
+	variableRegister = context->variable_Register;
+	assert( variableRegister );
+	pointerRegister = context->pointer_Register;
+	assert( pointerRegister  );
+
+	/* Construct the mesh. */
+	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
+	MeshVariable_SetMesh( self, mesh );
+
+	/* Get the topological element we're intereseted in. */
+	self->topoDim = (MeshTopology_Dim)Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"topologicalDim", 0  );
+			
+	/* Get Type of Variable */
+	dataTypeName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"DataType"  );
+	if ( !strcasecmp( dataTypeName, "Double" ) )
+		dataTypes[0] = Variable_DataType_Double;
+	else if ( !strcasecmp( dataTypeName, "Float" ) )
+		dataTypes[0] = Variable_DataType_Float;
+	else if ( !strcasecmp( dataTypeName, "Int" ) )
+		dataTypes[0] = Variable_DataType_Int;
+	else if ( !strcasecmp( dataTypeName, "Char" ) )
+		dataTypes[0] = Variable_DataType_Char;
+	else if ( !strcasecmp( dataTypeName, "Short" ) )
+		dataTypes[0] = Variable_DataType_Short;
+	else 
+		Journal_Firewall( False, error, "Variable '%s' cannot understand data type '%s'\n", self->name, dataTypeName );
+
+	/* Get Rank of Variable - i.e. Scalar or Vector */
+	rankName = Dictionary_GetString( thisComponentDict, (Dictionary_Entry_Key)"Rank"  );
+	if( !strcasecmp( rankName, "Scalar" ) ){
+		dataTypeCounts[0] = 1;
+	}
+	else if ( !strcasecmp( rankName, "Vector" ) ){
+		Dictionary_Entry_Value* list;
+		Index                   nameCount = 0;
+
+		/* Get Names from list */
+		if (( list = Dictionary_Get( thisComponentDict, (Dictionary_Entry_Key)"names" ) )) {
+			Index entry_I;
+
+			nameCount = Dictionary_Entry_Value_GetCount( list  );
+			names = Memory_Alloc_Array( Name, nameCount, "Variable Names" );
+
+			for ( entry_I = 0 ; entry_I < nameCount ; entry_I++ )
+				names[ entry_I ] = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement(list, entry_I ) );
+		}
+		dataTypeCounts[0] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"VectorComponentCount", nameCount  );
+
+		Journal_Firewall( nameCount >= dataTypeCounts[0], error, "Variable '%s' has too few names in list for %d vector components.\n", self->name, dataTypeCounts[0] );
+	}
+	else
+		Journal_Firewall( False, error, "Variable '%s' cannot understand rank '%s'\n", self->name, rankName );
+
+	_Variable_Init( (Variable*)self, context, 1, dataOffsets, dataTypes, dataTypeCounts, names, 0, NULL, _MeshVariable_GetMeshArraySize, (void**)&self->arrayPtr, True, (Variable_Register*)variableRegister );
+
+	/* Clean Up */
+	if (names)
+		Memory_Free(names);
+}
+
+void _MeshVariable_Build( void* meshVariable, void* data ) {
+	MeshVariable*	self = (MeshVariable*)meshVariable;
+
+	assert( self );
+
+	/* We need to make sure the Mesh is built first, since this Variable and it's sub-components are going
+	 *  to ask for the Mesh Size etc. */	
+	Stg_Component_Build( self->mesh, data, False );
+
+	_Variable_Build( self, data );
+}
+
+void _MeshVariable_Initialise( void* meshVariable, void* data ) {
+	MeshVariable*	self = (MeshVariable*)meshVariable;
+
+    Stg_Component_Initialise( self->mesh, data, False );
+}
+
+void _MeshVariable_Execute( void* meshVariable, void* data ) {
+}
+
+void _MeshVariable_Destroy( void* meshVariable, void* data ) {
+	MeshVariable*	self = (MeshVariable*)meshVariable;
+
+	MeshVariable_Destruct( self );
+
+	Stg_Component_Destroy( self->mesh, data, False );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void MeshVariable_SetMesh( void* meshVariable, void* _mesh ) {
+	MeshVariable*	self = (MeshVariable*)meshVariable;
+	Mesh*				mesh = (Mesh*)_mesh;
+
+	assert( self );
+
+	MeshVariable_Destruct( self );
+
+	self->mesh = mesh;
+	if( mesh )
+		List_Append( mesh->vars, self );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void MeshVariable_Destruct( MeshVariable* self ) {
+}
+
+Index _MeshVariable_GetMeshArraySize( void* meshVariable ) {
+	MeshVariable* self = (MeshVariable*)meshVariable;
+
+	return Mesh_GetDomainSize( self->mesh, self->topoDim );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_Algorithms.c
--- a/Mesh/src/Mesh_Algorithms.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,757 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_Algorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type Mesh_Algorithms_Type = "Mesh_Algorithms";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_Algorithms* Mesh_Algorithms_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                                   _sizeOfSelf = sizeof(Mesh_Algorithms);
-	Type                                                           type = Mesh_Algorithms_Type;
-	Stg_Class_DeleteFunction*                                   _delete = _Mesh_Algorithms_Delete;
-	Stg_Class_PrintFunction*                                     _print = _Mesh_Algorithms_Print;
-	Stg_Class_CopyFunction*                                       _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_Algorithms_New;
-	Stg_Component_ConstructFunction*                         _construct = _Mesh_Algorithms_AssignFromXML;
-	Stg_Component_BuildFunction*                                 _build = _Mesh_Algorithms_Build;
-	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_Algorithms_Initialise;
-	Stg_Component_ExecuteFunction*                             _execute = _Mesh_Algorithms_Execute;
-	Stg_Component_DestroyFunction*                             _destroy = _Mesh_Algorithms_Destroy;
-	AllocationType                                   nameAllocationType = NON_GLOBAL;
-	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = _Mesh_Algorithms_SetMesh;
-	Mesh_Algorithms_UpdateFunc*                              updateFunc = _Mesh_Algorithms_Update;
-	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = _Mesh_Algorithms_NearestVertex;
-	Mesh_Algorithms_SearchFunc*                              searchFunc = _Mesh_Algorithms_Search;
-	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = _Mesh_Algorithms_SearchElements;
-	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
-	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = _Mesh_Algorithms_GetLocalCoordRange;
-	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = _Mesh_Algorithms_GetDomainCoordRange;
-	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = _Mesh_Algorithms_GetGlobalCoordRange;
-
-	Mesh_Algorithms* self = _Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
-
-	_Mesh_Algorithms_Init( self, context);
-   return self;
-
-}
-
-Mesh_Algorithms* _Mesh_Algorithms_New(  MESH_ALGORITHMS_DEFARGS  ) {
-	Mesh_Algorithms* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_Algorithms) );
-	self = (Mesh_Algorithms*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	/* Virtual info */
-	self->setMeshFunc = setMeshFunc;
-	self->updateFunc = updateFunc;
-	self->nearestVertexFunc = nearestVertexFunc;
-	self->searchFunc = searchFunc;
-	self->searchElementsFunc = searchElementsFunc;
-	self->getMinimumSeparationFunc = getMinimumSeparationFunc;
-	self->getLocalCoordRangeFunc = getLocalCoordRangeFunc;
-	self->getDomainCoordRangeFunc = getDomainCoordRangeFunc;
-	self->getGlobalCoordRangeFunc = getGlobalCoordRangeFunc;
-
-	return self;
-}
-
-void _Mesh_Algorithms_Init( Mesh_Algorithms* self, AbstractContext* context ) {
-   self->context = context;
-	self->nearestVertex = NULL;
-	self->search = NULL;
-	self->mesh = NULL;
-	self->tree = NULL;
-	MPI_Comm_rank( MPI_COMM_WORLD, &self->rank );
-	self->incArray = IArray_New();
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_Algorithms_Delete( void* algorithms ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-
-	/* Delete the parent. */
-	_Stg_Component_Delete( self );
-}
-
-void _Mesh_Algorithms_Print( void* algorithms, Stream* stream ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	
-	/* Set the Journal for printing informations */
-	Stream* algorithmsStream;
-	algorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_AlgorithmsStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_Algorithms (ptr): (%p)\n", self );
-	_Stg_Component_Print( self, stream );
-}
-
-void _Mesh_Algorithms_AssignFromXML( void* algorithms, Stg_ComponentFactory* cf, void* data ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-   AbstractContext* context = NULL;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-   _Mesh_Algorithms_Init( self, context );
-}
-
-void _Mesh_Algorithms_Build( void* algorithms, void* data ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-   Stg_Component_Build( self->mesh, data, False );
-   Stg_Component_Build( self->tree, data, False );
-}
-
-void _Mesh_Algorithms_Initialise( void* algorithms, void* data ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-   Stg_Component_Initialise( self->mesh, data, False );
-   Stg_Component_Initialise( self->tree, data, False );
-}
-
-void _Mesh_Algorithms_Execute( void* algorithms, void* data ) {
-}
-
-void _Mesh_Algorithms_Destroy( void* algorithms, void* data ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	NewClass_Delete( self->incArray );
-   if(self->mesh) Stg_Component_Destroy( self->mesh, data, False );
-   if(self->tree) Stg_Component_Destroy( self->tree, data, False );
-}
-
-void _Mesh_Algorithms_SetMesh( void* algorithms, void* mesh ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-
-	assert( self );
-	assert( mesh );
-
-	self->mesh = (Mesh*)mesh;
-}
-
-void _Mesh_Algorithms_Update( void* algorithms ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	int nDims, d_i;
-
-	assert( self );
-
-#if 0
-	if( !self->mesh ) {
-	   if( self->tree )
-	      SpatialTree_Clear( self->tree );
-	   return;
-	}
-
-	if( !self->tree )
-	   self->tree = SpatialTree_New();
-	SpatialTree_SetMesh( self->tree, self->mesh );
-	SpatialTree_Rebuild( self->tree );
-	self->search = Mesh_Algorithms_SearchWithTree;
-#endif
-
-	if( !Class_IsSuper( self->mesh->topo, IGraph ) || 
-	    Mesh_HasIncidence( self->mesh, MT_VERTEX, MT_VERTEX ) )
-	{
-		self->nearestVertex = Mesh_Algorithms_NearestVertexWithNeighbours;
-	}
-	else
-		self->nearestVertex = Mesh_Algorithms_NearestVertexGeneral;
-
-	nDims = Mesh_GetDimSize( self->mesh );
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-	   if( Class_IsSuper( self->mesh->topo, IGraph ) &&
-	       (!Mesh_GetGlobalSize( self->mesh, (MeshTopology_Dim)d_i ) || !Mesh_HasIncidence( self->mesh, (MeshTopology_Dim)nDims, (MeshTopology_Dim)d_i )) )
-	   {
-			break;
-	   }
-	}
-	if( d_i == nDims )
-		self->search = Mesh_Algorithms_SearchWithFullIncidence;
-	else if( Mesh_HasIncidence( self->mesh, MT_VERTEX, Mesh_GetDimSize( self->mesh ) ) )
-		self->search = Mesh_Algorithms_SearchWithMinIncidence;
-	else
-		self->search = Mesh_Algorithms_SearchGeneral;
-}
-
-unsigned _Mesh_Algorithms_NearestVertex( void* algorithms, double* point ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-
-	assert( self );
-	assert( self->nearestVertex );
-
-	return self->nearestVertex( self, point );
-}
-
-Bool _Mesh_Algorithms_Search( void* algorithms, double* point, 
-			      MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-
-	assert( self );
-	assert( self->search );
-
-	return self->search( self, point, dim, ind );
-}
-
-Bool _Mesh_Algorithms_SearchElements( void* algorithms, double* point, 
-				      unsigned* elInd )
-{
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		dim, ind;
-
-	assert( self );
-	assert( self->mesh );
-	assert( elInd );
-
-	mesh = self->mesh;
-	if(Mesh_Algorithms_Search(self,point,(MeshTopology_Dim*)(&dim),&ind)) {
-		unsigned	nDims;
-
-		nDims = Mesh_GetDimSize( mesh );
-		if( dim != nDims ) {
-			unsigned	nInc, *inc;
-			unsigned	nLocalEls;
-			unsigned	lowest;
-			unsigned	global;
-			unsigned	inc_i;
-
-			/* Must have required incidence for this to work. */
-			assert(Mesh_HasIncidence(mesh,(MeshTopology_Dim)dim,
-                                                 (MeshTopology_Dim)nDims));
-
-			nLocalEls = Mesh_GetLocalSize(mesh,
-                                                      (MeshTopology_Dim)nDims);
-			Mesh_GetIncidence( mesh, (MeshTopology_Dim)dim,
-                                           ind, (MeshTopology_Dim)nDims,
-                                           self->incArray );
-			nInc = IArray_GetSize( self->incArray );
-			inc = (unsigned*)IArray_GetPtr( self->incArray );
-			assert( nInc );
-			lowest = Mesh_DomainToGlobal(mesh,
-                                                     (MeshTopology_Dim)nDims,
-                                                     inc[0] );
-			for( inc_i = 1; inc_i < nInc; inc_i++ ) {
-                          global=Mesh_DomainToGlobal(mesh,
-                                                     (MeshTopology_Dim)nDims,
-                                                     inc[inc_i] );
-                          if( global < lowest )
-                            lowest = global;
-			}
-
-			insist( Mesh_GlobalToDomain(mesh,
-                                                    (MeshTopology_Dim)nDims,
-                                                    lowest, elInd), == True );
-		}
-		else
-			*elInd = ind;
-
-		return True;
-	}
-
-	return False;
-}
-
-double _Mesh_Algorithms_GetMinimumSeparation( void* algorithms, double* perDim ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nDomainEls;
-	double			minSep;
-	double*			dimSep;
-	unsigned		e_i;
-
-	assert( self );
-	assert( self->mesh );
-
-	mesh = self->mesh;
-	if( perDim )
-		dimSep = Memory_Alloc_Array_Unnamed( double, Mesh_GetDimSize( mesh ) );
-	else
-		dimSep = NULL;
-
-	minSep = HUGE_VAL;
-	nDomainEls=
-          Mesh_GetDomainSize(mesh,Mesh_GetDimSize(mesh));
-	for( e_i = 0; e_i < nDomainEls; e_i++ ) {
-		Mesh_ElementType*	elType;
-		double			curSep;
-
-		elType = Mesh_GetElementType( mesh, e_i );
-		curSep = Mesh_ElementType_GetMinimumSeparation( elType, e_i, dimSep );
-		if( curSep < minSep ) {
-			minSep = curSep;
-			if( perDim )
-				memcpy( perDim, dimSep, Mesh_GetDimSize( mesh ) * sizeof(double) );
-		}
-	}
-
-   if( dimSep ) Memory_Free( dimSep );
-
-	return minSep;
-}
-
-void _Mesh_Algorithms_GetLocalCoordRange( void* algorithms, double* min, double* max ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nVerts, nEls;
-	unsigned*		verts;
-	double*			vert;
-	unsigned		nDims;
-	unsigned		v_i, e_i, d_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert( min );
-	assert( max );
-
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-	nEls = Mesh_GetLocalSize( mesh, (MeshTopology_Dim)nDims );
-	memcpy( min, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
-	memcpy( max, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
-	for( e_i = 0; e_i < nEls; e_i++ ) {
-		Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims,
-                                   e_i, (MeshTopology_Dim)0, self->incArray );
-		nVerts = IArray_GetSize( self->incArray );
-		verts = (unsigned*)IArray_GetPtr( self->incArray );
-		for( v_i = 0; v_i < nVerts; v_i++ ) {
-			vert = Mesh_GetVertex( mesh, verts[v_i] );
-			for( d_i = 0; d_i < nDims; d_i++ ) {
-				if( vert[d_i] < min[d_i] )
-					min[d_i] = vert[d_i];
-				if( vert[d_i] > max[d_i] )
-					max[d_i] = vert[d_i];
-			}
-		}
-	}
-}
-
-void _Mesh_Algorithms_GetDomainCoordRange( void* algorithms, double* min, double* max ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nVerts;
-	double*			vert;
-	unsigned		nDims;
-	unsigned		v_i, d_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert( min );
-	assert( max );
-
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-	nVerts = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	memcpy( min, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
-	memcpy( max, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
-	for( v_i = 1; v_i < nVerts; v_i++ ) {
-		vert = Mesh_GetVertex( mesh, v_i );
-		for( d_i = 0; d_i < nDims; d_i++ ) {
-			if( vert[d_i] < min[d_i] )
-				min[d_i] = vert[d_i];
-			if( vert[d_i] > max[d_i] )
-				max[d_i] = vert[d_i];
-		}
-	}
-}
-
-void _Mesh_Algorithms_GetGlobalCoordRange( void* algorithms, double* min, double* max ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nDims;
-	double			*localMin, *localMax;
-	MPI_Comm		comm;
-	unsigned		d_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert( min );
-	assert( max );
-
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-	localMin = Memory_Alloc_Array_Unnamed( double, nDims );
-	localMax = Memory_Alloc_Array_Unnamed( double, nDims );
-
-	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
-	Mesh_Algorithms_GetLocalCoordRange( self, localMin, localMax );
-	for( d_i = 0; d_i < (unsigned)Mesh_GetDimSize( mesh ); d_i++ ) {
-		MPI_Allreduce( localMin + d_i, min + d_i, 1, MPI_DOUBLE, MPI_MIN, comm );
-		MPI_Allreduce( localMax + d_i, max + d_i, 1, MPI_DOUBLE, MPI_MAX, comm );
-	}
-
-	FreeArray( localMin );
-	FreeArray( localMax );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-#define Vec_Sep( nDims, v0, v1 )									\
-	(((v0)[0] - (v1)[0]) * ((v0)[0] - (v1)[0]) +							\
-	 (((nDims) >= 2) ? (((v0)[1] - (v1)[1]) * ((v0)[1] - (v1)[1]) + 				\
-			    (((nDims) == 3) ? (((v0)[2] - (v1)[2]) * ((v0)[2] - (v1)[2])) : 0)) : 0))
-
-unsigned Mesh_Algorithms_NearestVertexWithNeighbours( void* algorithms, double* point ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nDims;
-	unsigned		curVert;
-	double*			vert;
-	double			sep;
-	Bool			done;
-	unsigned		nNbrs;
-	unsigned*		nbrs;
-	double			nbrSep;
-	unsigned		nbr_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert( Mesh_HasIncidence( self->mesh, MT_VERTEX, MT_VERTEX ) );
-
-	/* Get dimensionality. */
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-
-	/* Begin somewhere in the middle. */
-	curVert = Mesh_GetDomainSize( mesh, MT_VERTEX ) / 2;
-
-	/* Calc distance squared to current node. */
-	vert = Mesh_GetVertex( mesh, curVert );
-	sep = Vec_Sep( nDims, vert, point );
-
-	/* Loop until we've found closest local node. */
-	do {
-		/* Get neighbouring vertices. */
-		Mesh_GetIncidence( mesh, MT_VERTEX, curVert, MT_VERTEX, self->incArray );
-		nNbrs = IArray_GetSize( self->incArray );
-		nbrs = (unsigned*)IArray_GetPtr( self->incArray );
-
-		/* Assume we'll be done after this loop. */
-		done = True;
-
-		/* Compare to neighbours. */
-		for( nbr_i = 0; nbr_i < nNbrs; nbr_i++ ) {
-			/* Calculate neighbour separation. */
-			nbrSep = Vec_Sep( nDims, Mesh_GetVertex( mesh, nbrs[nbr_i] ), point );
-
-			/* Closer? */
-			if( nbrSep < sep ) {
-				curVert = nbrs[nbr_i];
-				sep = nbrSep;
-				done = False;
-			}
-		}
-	}
-	while( !done );
-
-	return curVert;
-}
-
-unsigned Mesh_Algorithms_NearestVertexGeneral( void* algorithms, double* point ) {
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nDims;
-	unsigned		nDomainVerts;
-	double*			vert;
-	unsigned		minVertInd;
-	double			curSep, minSep;
-	unsigned		v_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert( Mesh_GetDomainSize( self->mesh, MT_VERTEX ) );
-
-	/* TODO: This is going to be hella slow, need to use some kind of spatial partitioning scheme. */
-
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-	nDomainVerts = Mesh_GetDomainSize( mesh, MT_VERTEX );
-
-	vert = Mesh_GetVertex( mesh, 0 );
-	minSep = Vec_Sep( nDims, vert, point );
-	minVertInd = 0;
-
-	for( v_i = 1; v_i < nDomainVerts; v_i++ ) {
-		vert = Mesh_GetVertex( mesh, v_i );
-		curSep = Vec_Sep( nDims, vert, point );
-		if( curSep < minSep ) {
-			minSep = curSep;
-			minVertInd = v_i;
-		}
-	}
-
-	return minVertInd;
-}
-
-Bool Mesh_Algorithms_SearchWithFullIncidence( void* algorithms, double* point, 
-					      MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	double			maxCrd[3], minCrd[3];
-	unsigned		nDims;
-	unsigned		nEls;
-	unsigned		nearVert;
-	unsigned		nInc, *inc;
-	unsigned		e_i, d_i, inc_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert(Mesh_HasIncidence(self->mesh,MT_VERTEX,
-                                 Mesh_GetDimSize(self->mesh)));
-	assert( dim );
-	assert( ind );
-
-	/* Get dimensionality. */
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-
-	/* If outside local range, immediately return false. */
-	Mesh_GetDomainCoordRange( mesh, minCrd, maxCrd );
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		if( point[d_i] < minCrd[d_i] || point[d_i] > maxCrd[d_i] )
-			return False;
-	}
-
-	/* Start by locating the closest vertex. */
-	nearVert = Mesh_NearestVertex( mesh, point );
-
-	/* Get vertex/element incidence. */
-	Mesh_GetIncidence( mesh, MT_VERTEX, (MeshTopology_Dim)nearVert,
-                           (MeshTopology_Dim)nDims, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = (unsigned*)IArray_GetPtr( self->incArray );
-
-	/* Search each of these incident elements in turn. */
-	for( inc_i = 0; inc_i < nInc; inc_i++ ) {
-		if( Mesh_ElementHasPoint( mesh, inc[inc_i], point, dim, ind ) )
-			return True;
-	}
-
-/* OK 11/1/2010 Disabling this for now as it takes forever when for a point not found and seems unnecessary
- * Surely if a point is not found in incident elements it will not be found elsewhere?
- * If it is required could be enabled with a flag or in another function,
- * eg: Mesh_Algorithms_SearchBruteForce, so it doesn't do this by default
- * Plotting IsoSurface in one instance spends 30 seconds here searching for a ~1 second rendering job */
-
-/* 1-Feb-2010: Re-enabling it because with distorted elements the
-   point may not be inside the incident elements of the nearest
-   vertex.  Yes, this really happens. */
-
-	/* Brute force, search every element in turn (last resort). */
-	nEls = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims );
-	for( e_i = 0; e_i < nEls; e_i++ ) {
-		if( Mesh_ElementHasPoint( mesh, e_i, point, dim, ind ) )
-			return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_Algorithms_SearchWithMinIncidence( void* algorithms, double* point, 
-					      MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	double			maxCrd[3], minCrd[3];
-	unsigned		lowest;
-	unsigned		nDims;
-	unsigned		nEls;
-	unsigned		nearVert;
-	unsigned		nInc, *inc;
-	unsigned		e_i, d_i, inc_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert(Mesh_HasIncidence(self->mesh, MT_VERTEX,
-                                 Mesh_GetDimSize(self->mesh)));
-	assert( dim );
-	assert( ind );
-
-	/* Get dimensionality. */
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-
-	/* If outside local range, immediately return false. */
-	Mesh_GetDomainCoordRange( mesh, minCrd, maxCrd );
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		if( point[d_i] < minCrd[d_i] || point[d_i] > maxCrd[d_i] )
-			return False;
-	}
-
-	/* Start by locating the closest vertex. */
-	nearVert = Mesh_NearestVertex( mesh, point );
-
-	/* Get vertex/element incidence. */
-	Mesh_GetIncidence( mesh, MT_VERTEX, nearVert, (MeshTopology_Dim)nDims,
-                           self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = (unsigned*)IArray_GetPtr( self->incArray );
-
-	/* Search all of these elements and return the element with lowest global index. */
-	lowest = (unsigned)-1;
-	for( inc_i = 0; inc_i < nInc; inc_i++ ) {
-		if( Mesh_ElementHasPoint( mesh, inc[inc_i], point, dim, ind ) ) {
-			unsigned	global;
-
-			global=Mesh_DomainToGlobal(mesh,(MeshTopology_Dim)nDims,
-                                                   inc[inc_i]);
-			if( global < lowest )
-				lowest = global;
-		}
-	}
-	if( lowest != (unsigned)-1 ) {
-		insist(Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,
-                                           lowest, ind ), == True );
-		*dim = (MeshTopology_Dim)nDims;
-		return True;
-	}
-
-	/* Brute force, search every element in turn (last resort). */
-	lowest = (unsigned)-1;
-	nEls = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims );
-	for( e_i = 0; e_i < nEls; e_i++ ) {
-          if( Mesh_ElementHasPoint( mesh, e_i, point, dim, ind ) ) {
-            unsigned	global;
-            
-            global = Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)nDims, e_i );
-            if( global < lowest )
-              lowest = global;
-          }
-	}
-	if( lowest != (unsigned)-1 ) {
-          insist(Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,lowest,ind),
-                 ==True);
-          *dim = (MeshTopology_Dim)nDims;
-          return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_Algorithms_SearchGeneral( void* algorithms, double* point, 
-				    MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
-	Mesh*			mesh;
-	double			maxCrd[3], minCrd[3];
-	unsigned		nDims;
-	unsigned		nEls;
-	unsigned		e_i, d_i;
-
-	assert( self );
-	assert( self->mesh );
-	assert( dim );
-	assert( ind );
-
-	/* Get dimensionality. */
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-
-	/* If outside local range, immediately return false. */
-	Mesh_GetDomainCoordRange( mesh, minCrd, maxCrd );
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		if( point[d_i] < minCrd[d_i] || point[d_i] > maxCrd[d_i] )
-			return False;
-	}
-
-	/* Brute force, search every element in turn. */
-	nEls = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims );
-	for( e_i = 0; e_i < nEls; e_i++ ) {
-		if( Mesh_ElementHasPoint( mesh, e_i, point, dim, ind ) )
-			return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_Algorithms_SearchWithTree( void* _self, double* pnt, unsigned* dim, unsigned* el ) {
-   Mesh_Algorithms* self = (Mesh_Algorithms*)_self;
-   int nEls, *els;
-   unsigned curEl;
-	int curRank;
-   int nLocals, owner;
-   int ii;
-   MeshTopology_Dim curDim;
-
-   *dim = Mesh_GetDimSize( self->mesh );
-   MPI_Comm_size( MPI_COMM_WORLD, &curRank );
-   nLocals=Mesh_GetLocalSize(self->mesh,(MeshTopology_Dim)(*dim));
-   if( !SpatialTree_Search( self->tree, pnt, &nEls, &els ) )
-      return False;
-
-   *el = nLocals;
-   for( ii = 0; ii < nEls; ii++ ) {
-      if( Mesh_ElementHasPoint( self->mesh, els[ii], pnt, &curDim, &curEl ) ) {
-        if( curEl >= (unsigned)nLocals ) {
-	    owner = Mesh_GetOwner( self->mesh, curDim, curEl - nLocals );
-	    owner = Comm_RankLocalToGlobal( self->mesh->topo->comm, owner );
-	    if( owner <= curRank ) {
-	       curRank = owner;
-	       *el = curEl;
-	    }
-	 }
-	 else if( self->rank <= curRank && curEl < *el ) {
-	    curRank = self->rank;
-	    *el = curEl;
-	 }
-      }
-   }
-
-   return True;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_Algorithms.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_Algorithms.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,757 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_Algorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type Mesh_Algorithms_Type = "Mesh_Algorithms";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_Algorithms* Mesh_Algorithms_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                                   _sizeOfSelf = sizeof(Mesh_Algorithms);
+	Type                                                           type = Mesh_Algorithms_Type;
+	Stg_Class_DeleteFunction*                                   _delete = _Mesh_Algorithms_Delete;
+	Stg_Class_PrintFunction*                                     _print = _Mesh_Algorithms_Print;
+	Stg_Class_CopyFunction*                                       _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_Algorithms_New;
+	Stg_Component_ConstructFunction*                         _construct = _Mesh_Algorithms_AssignFromXML;
+	Stg_Component_BuildFunction*                                 _build = _Mesh_Algorithms_Build;
+	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_Algorithms_Initialise;
+	Stg_Component_ExecuteFunction*                             _execute = _Mesh_Algorithms_Execute;
+	Stg_Component_DestroyFunction*                             _destroy = _Mesh_Algorithms_Destroy;
+	AllocationType                                   nameAllocationType = NON_GLOBAL;
+	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = _Mesh_Algorithms_SetMesh;
+	Mesh_Algorithms_UpdateFunc*                              updateFunc = _Mesh_Algorithms_Update;
+	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = _Mesh_Algorithms_NearestVertex;
+	Mesh_Algorithms_SearchFunc*                              searchFunc = _Mesh_Algorithms_Search;
+	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = _Mesh_Algorithms_SearchElements;
+	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
+	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = _Mesh_Algorithms_GetLocalCoordRange;
+	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = _Mesh_Algorithms_GetDomainCoordRange;
+	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = _Mesh_Algorithms_GetGlobalCoordRange;
+
+	Mesh_Algorithms* self = _Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
+
+	_Mesh_Algorithms_Init( self, context);
+   return self;
+
+}
+
+Mesh_Algorithms* _Mesh_Algorithms_New(  MESH_ALGORITHMS_DEFARGS  ) {
+	Mesh_Algorithms* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_Algorithms) );
+	self = (Mesh_Algorithms*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	/* Virtual info */
+	self->setMeshFunc = setMeshFunc;
+	self->updateFunc = updateFunc;
+	self->nearestVertexFunc = nearestVertexFunc;
+	self->searchFunc = searchFunc;
+	self->searchElementsFunc = searchElementsFunc;
+	self->getMinimumSeparationFunc = getMinimumSeparationFunc;
+	self->getLocalCoordRangeFunc = getLocalCoordRangeFunc;
+	self->getDomainCoordRangeFunc = getDomainCoordRangeFunc;
+	self->getGlobalCoordRangeFunc = getGlobalCoordRangeFunc;
+
+	return self;
+}
+
+void _Mesh_Algorithms_Init( Mesh_Algorithms* self, AbstractContext* context ) {
+   self->context = context;
+	self->nearestVertex = NULL;
+	self->search = NULL;
+	self->mesh = NULL;
+	self->tree = NULL;
+	MPI_Comm_rank( MPI_COMM_WORLD, &self->rank );
+	self->incArray = IArray_New();
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_Algorithms_Delete( void* algorithms ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+
+	/* Delete the parent. */
+	_Stg_Component_Delete( self );
+}
+
+void _Mesh_Algorithms_Print( void* algorithms, Stream* stream ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	
+	/* Set the Journal for printing informations */
+	Stream* algorithmsStream;
+	algorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_AlgorithmsStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_Algorithms (ptr): (%p)\n", self );
+	_Stg_Component_Print( self, stream );
+}
+
+void _Mesh_Algorithms_AssignFromXML( void* algorithms, Stg_ComponentFactory* cf, void* data ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+   AbstractContext* context = NULL;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+   _Mesh_Algorithms_Init( self, context );
+}
+
+void _Mesh_Algorithms_Build( void* algorithms, void* data ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+   Stg_Component_Build( self->mesh, data, False );
+   Stg_Component_Build( self->tree, data, False );
+}
+
+void _Mesh_Algorithms_Initialise( void* algorithms, void* data ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+   Stg_Component_Initialise( self->mesh, data, False );
+   Stg_Component_Initialise( self->tree, data, False );
+}
+
+void _Mesh_Algorithms_Execute( void* algorithms, void* data ) {
+}
+
+void _Mesh_Algorithms_Destroy( void* algorithms, void* data ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	NewClass_Delete( self->incArray );
+   if(self->mesh) Stg_Component_Destroy( self->mesh, data, False );
+   if(self->tree) Stg_Component_Destroy( self->tree, data, False );
+}
+
+void _Mesh_Algorithms_SetMesh( void* algorithms, void* mesh ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+
+	assert( self );
+	assert( mesh );
+
+	self->mesh = (Mesh*)mesh;
+}
+
+void _Mesh_Algorithms_Update( void* algorithms ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	int nDims, d_i;
+
+	assert( self );
+
+#if 0
+	if( !self->mesh ) {
+	   if( self->tree )
+	      SpatialTree_Clear( self->tree );
+	   return;
+	}
+
+	if( !self->tree )
+	   self->tree = SpatialTree_New();
+	SpatialTree_SetMesh( self->tree, self->mesh );
+	SpatialTree_Rebuild( self->tree );
+	self->search = Mesh_Algorithms_SearchWithTree;
+#endif
+
+	if( !Class_IsSuper( self->mesh->topo, IGraph ) || 
+	    Mesh_HasIncidence( self->mesh, MT_VERTEX, MT_VERTEX ) )
+	{
+		self->nearestVertex = Mesh_Algorithms_NearestVertexWithNeighbours;
+	}
+	else
+		self->nearestVertex = Mesh_Algorithms_NearestVertexGeneral;
+
+	nDims = Mesh_GetDimSize( self->mesh );
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+	   if( Class_IsSuper( self->mesh->topo, IGraph ) &&
+	       (!Mesh_GetGlobalSize( self->mesh, (MeshTopology_Dim)d_i ) || !Mesh_HasIncidence( self->mesh, (MeshTopology_Dim)nDims, (MeshTopology_Dim)d_i )) )
+	   {
+			break;
+	   }
+	}
+	if( d_i == nDims )
+		self->search = Mesh_Algorithms_SearchWithFullIncidence;
+	else if( Mesh_HasIncidence( self->mesh, MT_VERTEX, Mesh_GetDimSize( self->mesh ) ) )
+		self->search = Mesh_Algorithms_SearchWithMinIncidence;
+	else
+		self->search = Mesh_Algorithms_SearchGeneral;
+}
+
+unsigned _Mesh_Algorithms_NearestVertex( void* algorithms, double* point ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+
+	assert( self );
+	assert( self->nearestVertex );
+
+	return self->nearestVertex( self, point );
+}
+
+Bool _Mesh_Algorithms_Search( void* algorithms, double* point, 
+			      MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+
+	assert( self );
+	assert( self->search );
+
+	return self->search( self, point, dim, ind );
+}
+
+Bool _Mesh_Algorithms_SearchElements( void* algorithms, double* point, 
+				      unsigned* elInd )
+{
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		dim, ind;
+
+	assert( self );
+	assert( self->mesh );
+	assert( elInd );
+
+	mesh = self->mesh;
+	if(Mesh_Algorithms_Search(self,point,(MeshTopology_Dim*)(&dim),&ind)) {
+		unsigned	nDims;
+
+		nDims = Mesh_GetDimSize( mesh );
+		if( dim != nDims ) {
+			unsigned	nInc, *inc;
+			unsigned	nLocalEls;
+			unsigned	lowest;
+			unsigned	global;
+			unsigned	inc_i;
+
+			/* Must have required incidence for this to work. */
+			assert(Mesh_HasIncidence(mesh,(MeshTopology_Dim)dim,
+                                                 (MeshTopology_Dim)nDims));
+
+			nLocalEls = Mesh_GetLocalSize(mesh,
+                                                      (MeshTopology_Dim)nDims);
+			Mesh_GetIncidence( mesh, (MeshTopology_Dim)dim,
+                                           ind, (MeshTopology_Dim)nDims,
+                                           self->incArray );
+			nInc = IArray_GetSize( self->incArray );
+			inc = (unsigned*)IArray_GetPtr( self->incArray );
+			assert( nInc );
+			lowest = Mesh_DomainToGlobal(mesh,
+                                                     (MeshTopology_Dim)nDims,
+                                                     inc[0] );
+			for( inc_i = 1; inc_i < nInc; inc_i++ ) {
+                          global=Mesh_DomainToGlobal(mesh,
+                                                     (MeshTopology_Dim)nDims,
+                                                     inc[inc_i] );
+                          if( global < lowest )
+                            lowest = global;
+			}
+
+			insist( Mesh_GlobalToDomain(mesh,
+                                                    (MeshTopology_Dim)nDims,
+                                                    lowest, elInd), == True );
+		}
+		else
+			*elInd = ind;
+
+		return True;
+	}
+
+	return False;
+}
+
+double _Mesh_Algorithms_GetMinimumSeparation( void* algorithms, double* perDim ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nDomainEls;
+	double			minSep;
+	double*			dimSep;
+	unsigned		e_i;
+
+	assert( self );
+	assert( self->mesh );
+
+	mesh = self->mesh;
+	if( perDim )
+		dimSep = Memory_Alloc_Array_Unnamed( double, Mesh_GetDimSize( mesh ) );
+	else
+		dimSep = NULL;
+
+	minSep = HUGE_VAL;
+	nDomainEls=
+          Mesh_GetDomainSize(mesh,Mesh_GetDimSize(mesh));
+	for( e_i = 0; e_i < nDomainEls; e_i++ ) {
+		Mesh_ElementType*	elType;
+		double			curSep;
+
+		elType = Mesh_GetElementType( mesh, e_i );
+		curSep = Mesh_ElementType_GetMinimumSeparation( elType, e_i, dimSep );
+		if( curSep < minSep ) {
+			minSep = curSep;
+			if( perDim )
+				memcpy( perDim, dimSep, Mesh_GetDimSize( mesh ) * sizeof(double) );
+		}
+	}
+
+   if( dimSep ) Memory_Free( dimSep );
+
+	return minSep;
+}
+
+void _Mesh_Algorithms_GetLocalCoordRange( void* algorithms, double* min, double* max ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nVerts, nEls;
+	unsigned*		verts;
+	double*			vert;
+	unsigned		nDims;
+	unsigned		v_i, e_i, d_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert( min );
+	assert( max );
+
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+	nEls = Mesh_GetLocalSize( mesh, (MeshTopology_Dim)nDims );
+	memcpy( min, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
+	memcpy( max, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
+	for( e_i = 0; e_i < nEls; e_i++ ) {
+		Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims,
+                                   e_i, (MeshTopology_Dim)0, self->incArray );
+		nVerts = IArray_GetSize( self->incArray );
+		verts = (unsigned*)IArray_GetPtr( self->incArray );
+		for( v_i = 0; v_i < nVerts; v_i++ ) {
+			vert = Mesh_GetVertex( mesh, verts[v_i] );
+			for( d_i = 0; d_i < nDims; d_i++ ) {
+				if( vert[d_i] < min[d_i] )
+					min[d_i] = vert[d_i];
+				if( vert[d_i] > max[d_i] )
+					max[d_i] = vert[d_i];
+			}
+		}
+	}
+}
+
+void _Mesh_Algorithms_GetDomainCoordRange( void* algorithms, double* min, double* max ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nVerts;
+	double*			vert;
+	unsigned		nDims;
+	unsigned		v_i, d_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert( min );
+	assert( max );
+
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+	nVerts = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	memcpy( min, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
+	memcpy( max, Mesh_GetVertex( mesh, 0 ), nDims * sizeof(double) );
+	for( v_i = 1; v_i < nVerts; v_i++ ) {
+		vert = Mesh_GetVertex( mesh, v_i );
+		for( d_i = 0; d_i < nDims; d_i++ ) {
+			if( vert[d_i] < min[d_i] )
+				min[d_i] = vert[d_i];
+			if( vert[d_i] > max[d_i] )
+				max[d_i] = vert[d_i];
+		}
+	}
+}
+
+void _Mesh_Algorithms_GetGlobalCoordRange( void* algorithms, double* min, double* max ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nDims;
+	double			*localMin, *localMax;
+	MPI_Comm		comm;
+	unsigned		d_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert( min );
+	assert( max );
+
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+	localMin = Memory_Alloc_Array_Unnamed( double, nDims );
+	localMax = Memory_Alloc_Array_Unnamed( double, nDims );
+
+	comm = Comm_GetMPIComm( Mesh_GetCommTopology( mesh, MT_VERTEX ) );
+	Mesh_Algorithms_GetLocalCoordRange( self, localMin, localMax );
+	for( d_i = 0; d_i < (unsigned)Mesh_GetDimSize( mesh ); d_i++ ) {
+		MPI_Allreduce( localMin + d_i, min + d_i, 1, MPI_DOUBLE, MPI_MIN, comm );
+		MPI_Allreduce( localMax + d_i, max + d_i, 1, MPI_DOUBLE, MPI_MAX, comm );
+	}
+
+	FreeArray( localMin );
+	FreeArray( localMax );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+#define Vec_Sep( nDims, v0, v1 )									\
+	(((v0)[0] - (v1)[0]) * ((v0)[0] - (v1)[0]) +							\
+	 (((nDims) >= 2) ? (((v0)[1] - (v1)[1]) * ((v0)[1] - (v1)[1]) + 				\
+			    (((nDims) == 3) ? (((v0)[2] - (v1)[2]) * ((v0)[2] - (v1)[2])) : 0)) : 0))
+
+unsigned Mesh_Algorithms_NearestVertexWithNeighbours( void* algorithms, double* point ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nDims;
+	unsigned		curVert;
+	double*			vert;
+	double			sep;
+	Bool			done;
+	unsigned		nNbrs;
+	unsigned*		nbrs;
+	double			nbrSep;
+	unsigned		nbr_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert( Mesh_HasIncidence( self->mesh, MT_VERTEX, MT_VERTEX ) );
+
+	/* Get dimensionality. */
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+
+	/* Begin somewhere in the middle. */
+	curVert = Mesh_GetDomainSize( mesh, MT_VERTEX ) / 2;
+
+	/* Calc distance squared to current node. */
+	vert = Mesh_GetVertex( mesh, curVert );
+	sep = Vec_Sep( nDims, vert, point );
+
+	/* Loop until we've found closest local node. */
+	do {
+		/* Get neighbouring vertices. */
+		Mesh_GetIncidence( mesh, MT_VERTEX, curVert, MT_VERTEX, self->incArray );
+		nNbrs = IArray_GetSize( self->incArray );
+		nbrs = (unsigned*)IArray_GetPtr( self->incArray );
+
+		/* Assume we'll be done after this loop. */
+		done = True;
+
+		/* Compare to neighbours. */
+		for( nbr_i = 0; nbr_i < nNbrs; nbr_i++ ) {
+			/* Calculate neighbour separation. */
+			nbrSep = Vec_Sep( nDims, Mesh_GetVertex( mesh, nbrs[nbr_i] ), point );
+
+			/* Closer? */
+			if( nbrSep < sep ) {
+				curVert = nbrs[nbr_i];
+				sep = nbrSep;
+				done = False;
+			}
+		}
+	}
+	while( !done );
+
+	return curVert;
+}
+
+unsigned Mesh_Algorithms_NearestVertexGeneral( void* algorithms, double* point ) {
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nDims;
+	unsigned		nDomainVerts;
+	double*			vert;
+	unsigned		minVertInd;
+	double			curSep, minSep;
+	unsigned		v_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert( Mesh_GetDomainSize( self->mesh, MT_VERTEX ) );
+
+	/* TODO: This is going to be hella slow, need to use some kind of spatial partitioning scheme. */
+
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+	nDomainVerts = Mesh_GetDomainSize( mesh, MT_VERTEX );
+
+	vert = Mesh_GetVertex( mesh, 0 );
+	minSep = Vec_Sep( nDims, vert, point );
+	minVertInd = 0;
+
+	for( v_i = 1; v_i < nDomainVerts; v_i++ ) {
+		vert = Mesh_GetVertex( mesh, v_i );
+		curSep = Vec_Sep( nDims, vert, point );
+		if( curSep < minSep ) {
+			minSep = curSep;
+			minVertInd = v_i;
+		}
+	}
+
+	return minVertInd;
+}
+
+Bool Mesh_Algorithms_SearchWithFullIncidence( void* algorithms, double* point, 
+					      MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	double			maxCrd[3], minCrd[3];
+	unsigned		nDims;
+	unsigned		nEls;
+	unsigned		nearVert;
+	unsigned		nInc, *inc;
+	unsigned		e_i, d_i, inc_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert(Mesh_HasIncidence(self->mesh,MT_VERTEX,
+                                 Mesh_GetDimSize(self->mesh)));
+	assert( dim );
+	assert( ind );
+
+	/* Get dimensionality. */
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+
+	/* If outside local range, immediately return false. */
+	Mesh_GetDomainCoordRange( mesh, minCrd, maxCrd );
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+		if( point[d_i] < minCrd[d_i] || point[d_i] > maxCrd[d_i] )
+			return False;
+	}
+
+	/* Start by locating the closest vertex. */
+	nearVert = Mesh_NearestVertex( mesh, point );
+
+	/* Get vertex/element incidence. */
+	Mesh_GetIncidence( mesh, MT_VERTEX, (MeshTopology_Dim)nearVert,
+                           (MeshTopology_Dim)nDims, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = (unsigned*)IArray_GetPtr( self->incArray );
+
+	/* Search each of these incident elements in turn. */
+	for( inc_i = 0; inc_i < nInc; inc_i++ ) {
+		if( Mesh_ElementHasPoint( mesh, inc[inc_i], point, dim, ind ) )
+			return True;
+	}
+
+/* OK 11/1/2010 Disabling this for now as it takes forever when for a point not found and seems unnecessary
+ * Surely if a point is not found in incident elements it will not be found elsewhere?
+ * If it is required could be enabled with a flag or in another function,
+ * eg: Mesh_Algorithms_SearchBruteForce, so it doesn't do this by default
+ * Plotting IsoSurface in one instance spends 30 seconds here searching for a ~1 second rendering job */
+
+/* 1-Feb-2010: Re-enabling it because with distorted elements the
+   point may not be inside the incident elements of the nearest
+   vertex.  Yes, this really happens. */
+
+	/* Brute force, search every element in turn (last resort). */
+	nEls = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims );
+	for( e_i = 0; e_i < nEls; e_i++ ) {
+		if( Mesh_ElementHasPoint( mesh, e_i, point, dim, ind ) )
+			return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_Algorithms_SearchWithMinIncidence( void* algorithms, double* point, 
+					      MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	double			maxCrd[3], minCrd[3];
+	unsigned		lowest;
+	unsigned		nDims;
+	unsigned		nEls;
+	unsigned		nearVert;
+	unsigned		nInc, *inc;
+	unsigned		e_i, d_i, inc_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert(Mesh_HasIncidence(self->mesh, MT_VERTEX,
+                                 Mesh_GetDimSize(self->mesh)));
+	assert( dim );
+	assert( ind );
+
+	/* Get dimensionality. */
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+
+	/* If outside local range, immediately return false. */
+	Mesh_GetDomainCoordRange( mesh, minCrd, maxCrd );
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+		if( point[d_i] < minCrd[d_i] || point[d_i] > maxCrd[d_i] )
+			return False;
+	}
+
+	/* Start by locating the closest vertex. */
+	nearVert = Mesh_NearestVertex( mesh, point );
+
+	/* Get vertex/element incidence. */
+	Mesh_GetIncidence( mesh, MT_VERTEX, nearVert, (MeshTopology_Dim)nDims,
+                           self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = (unsigned*)IArray_GetPtr( self->incArray );
+
+	/* Search all of these elements and return the element with lowest global index. */
+	lowest = (unsigned)-1;
+	for( inc_i = 0; inc_i < nInc; inc_i++ ) {
+		if( Mesh_ElementHasPoint( mesh, inc[inc_i], point, dim, ind ) ) {
+			unsigned	global;
+
+			global=Mesh_DomainToGlobal(mesh,(MeshTopology_Dim)nDims,
+                                                   inc[inc_i]);
+			if( global < lowest )
+				lowest = global;
+		}
+	}
+	if( lowest != (unsigned)-1 ) {
+		insist(Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,
+                                           lowest, ind ), == True );
+		*dim = (MeshTopology_Dim)nDims;
+		return True;
+	}
+
+	/* Brute force, search every element in turn (last resort). */
+	lowest = (unsigned)-1;
+	nEls = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims );
+	for( e_i = 0; e_i < nEls; e_i++ ) {
+          if( Mesh_ElementHasPoint( mesh, e_i, point, dim, ind ) ) {
+            unsigned	global;
+            
+            global = Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)nDims, e_i );
+            if( global < lowest )
+              lowest = global;
+          }
+	}
+	if( lowest != (unsigned)-1 ) {
+          insist(Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,lowest,ind),
+                 ==True);
+          *dim = (MeshTopology_Dim)nDims;
+          return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_Algorithms_SearchGeneral( void* algorithms, double* point, 
+				    MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_Algorithms*	self = (Mesh_Algorithms*)algorithms;
+	Mesh*			mesh;
+	double			maxCrd[3], minCrd[3];
+	unsigned		nDims;
+	unsigned		nEls;
+	unsigned		e_i, d_i;
+
+	assert( self );
+	assert( self->mesh );
+	assert( dim );
+	assert( ind );
+
+	/* Get dimensionality. */
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+
+	/* If outside local range, immediately return false. */
+	Mesh_GetDomainCoordRange( mesh, minCrd, maxCrd );
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+		if( point[d_i] < minCrd[d_i] || point[d_i] > maxCrd[d_i] )
+			return False;
+	}
+
+	/* Brute force, search every element in turn. */
+	nEls = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims );
+	for( e_i = 0; e_i < nEls; e_i++ ) {
+		if( Mesh_ElementHasPoint( mesh, e_i, point, dim, ind ) )
+			return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_Algorithms_SearchWithTree( void* _self, double* pnt, unsigned* dim, unsigned* el ) {
+   Mesh_Algorithms* self = (Mesh_Algorithms*)_self;
+   int nEls, *els;
+   unsigned curEl;
+	int curRank;
+   int nLocals, owner;
+   int ii;
+   MeshTopology_Dim curDim;
+
+   *dim = Mesh_GetDimSize( self->mesh );
+   MPI_Comm_size( MPI_COMM_WORLD, &curRank );
+   nLocals=Mesh_GetLocalSize(self->mesh,(MeshTopology_Dim)(*dim));
+   if( !SpatialTree_Search( self->tree, pnt, &nEls, &els ) )
+      return False;
+
+   *el = nLocals;
+   for( ii = 0; ii < nEls; ii++ ) {
+      if( Mesh_ElementHasPoint( self->mesh, els[ii], pnt, &curDim, &curEl ) ) {
+        if( curEl >= (unsigned)nLocals ) {
+	    owner = Mesh_GetOwner( self->mesh, curDim, curEl - nLocals );
+	    owner = Comm_RankLocalToGlobal( self->mesh->topo->comm, owner );
+	    if( owner <= curRank ) {
+	       curRank = owner;
+	       *el = curEl;
+	    }
+	 }
+	 else if( self->rank <= curRank && curEl < *el ) {
+	    curRank = self->rank;
+	    *el = curEl;
+	 }
+      }
+   }
+
+   return True;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_CentroidAlgorithms.c
--- a/Mesh/src/Mesh_CentroidAlgorithms.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,269 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_CentroidAlgorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type Mesh_CentroidAlgorithms_Type = "Mesh_CentroidAlgorithms";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_CentroidAlgorithms* Mesh_CentroidAlgorithms_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                                   _sizeOfSelf = sizeof(Mesh_CentroidAlgorithms);
-	Type                                                           type = Mesh_CentroidAlgorithms_Type;
-	Stg_Class_DeleteFunction*                                   _delete = _Mesh_CentroidAlgorithms_Delete;
-	Stg_Class_PrintFunction*                                     _print = _Mesh_CentroidAlgorithms_Print;
-	Stg_Class_CopyFunction*                                       _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_CentroidAlgorithms_New;
-	Stg_Component_ConstructFunction*                         _construct = _Mesh_CentroidAlgorithms_AssignFromXML;
-	Stg_Component_BuildFunction*                                 _build = _Mesh_CentroidAlgorithms_Build;
-	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_CentroidAlgorithms_Initialise;
-	Stg_Component_ExecuteFunction*                             _execute = _Mesh_CentroidAlgorithms_Execute;
-	Stg_Component_DestroyFunction*                             _destroy = _Mesh_CentroidAlgorithms_Destroy;
-	AllocationType                                   nameAllocationType = NON_GLOBAL;
-	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = _Mesh_Algorithms_SetMesh;
-	Mesh_Algorithms_UpdateFunc*                              updateFunc = Mesh_CentroidAlgorithms_Update;
-	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = Mesh_CentroidAlgorithms_NearestVertex;
-	Mesh_Algorithms_SearchFunc*                              searchFunc = Mesh_CentroidAlgorithms_Search;
-	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = Mesh_CentroidAlgorithms_SearchElements;
-	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
-	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = Mesh_CentroidAlgorithms_GetLocalCoordRange;
-	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = Mesh_CentroidAlgorithms_GetDomainCoordRange;
-	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = Mesh_CentroidAlgorithms_GetGlobalCoordRange;
-
-   Mesh_CentroidAlgorithms* self = _Mesh_CentroidAlgorithms_New(  MESH_CENTROIDALGORITHMS_PASSARGS  );
-
-	_Mesh_Algorithms_Init( (Mesh_Algorithms*)self, context );
-	_Mesh_CentroidAlgorithms_Init( self );
-   return self;
-
-}
-
-Mesh_CentroidAlgorithms* _Mesh_CentroidAlgorithms_New(  MESH_CENTROIDALGORITHMS_DEFARGS  ) {
-	Mesh_CentroidAlgorithms* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_CentroidAlgorithms) );
-	self = (Mesh_CentroidAlgorithms*)_Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
-
-	return self;
-}
-
-void _Mesh_CentroidAlgorithms_Init( void* centroidAlgorithms ) {
-	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidAlgorithms ) );
-
-	self->elMesh = NULL;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_CentroidAlgorithms_Delete( void* centroidAlgorithms ) {
-	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
-
-	/* Delete the parent. */
-	_Mesh_Algorithms_Delete( self );
-}
-
-void _Mesh_CentroidAlgorithms_Print( void* _centroidAlgorithms, Stream* stream ) {
-	Mesh_CentroidAlgorithms* self= (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
-	
-	/* Set the Journal for printing informations */
-	Stream* centroidAlgorithmsStream;
-	centroidAlgorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_CentroidAlgorithmsStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_CentroidAlgorithms (ptr): (%p)\n", self );
-	_Mesh_Algorithms_Print( self, stream );
-}
-
-void _Mesh_CentroidAlgorithms_AssignFromXML( void* _centroidAlgorithms, Stg_ComponentFactory* cf, void* data ) {
-    
-    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
-    
-    _Mesh_Algorithms_AssignFromXML( self, cf, data );
-
-    _Mesh_CentroidAlgorithms_Init( self );
-}
-
-void _Mesh_CentroidAlgorithms_Build( void* _centroidAlgorithms, void* data ) {
-    
-    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
-    
-    Stg_Component_Build( self->elMesh, data, False );  
-    _Mesh_Algorithms_Build( self, data );
-}
-
-void _Mesh_CentroidAlgorithms_Initialise( void* _centroidAlgorithms, void* data ) {
-    Mesh_CentroidAlgorithms*      self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
-    
-    Stg_Component_Initialise( self->elMesh, data, False );  
-    _Mesh_Algorithms_Initialise( self, data );
-}
-
-void _Mesh_CentroidAlgorithms_Execute( void* _centroidAlgorithms, void* data ) {
-    
-    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
-    
-    Stg_Component_Initialise( self->elMesh, data, False );  
-    _Mesh_Algorithms_Initialise( self, data );
-}
-
-void _Mesh_CentroidAlgorithms_Destroy( void* _centroidAlgorithms, void* data ) {
-    
-    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
-    
-    Stg_Component_Destroy( self->elMesh, data, False );  
-    _Mesh_Algorithms_Destroy( self, data );
-}
-
-void Mesh_CentroidAlgorithms_Update( void* centroidAlgorithms ) {
-}
-
-#define Vec_Sep( nDims, v0, v1 )									\
-	(((v0)[0] - (v1)[0]) * ((v0)[0] - (v1)[0]) +							\
-	 (((nDims) >= 2) ? (((v0)[1] - (v1)[1]) * ((v0)[1] - (v1)[1]) + 				\
-			    (((nDims) == 3) ? (((v0)[2] - (v1)[2]) * ((v0)[2] - (v1)[2])) : 0)) : 0))
-
-unsigned Mesh_CentroidAlgorithms_NearestVertex( void* centroidAlgorithms, double* point ) {
-	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
-	unsigned			elInd;
-	double dist, nearDist;
-	unsigned near;
-	unsigned nDims;
-	double* vert;
-	unsigned inc_i;
-
-	assert( self );
-
-	if( Mesh_SearchElements( self->elMesh, point, &elInd ) ) {
-          unsigned	nInc, *inc;
-          
-          nDims = Mesh_GetDimSize( self->mesh );
-          Mesh_GetIncidence(self->elMesh,
-                            Mesh_GetDimSize( self->mesh ),
-                            elInd, MT_VERTEX, 
-                            self->incArray );
-          nInc = IArray_GetSize( self->incArray );
-          inc = (unsigned*)IArray_GetPtr( self->incArray );
-          near = inc[0];
-          vert = Mesh_GetVertex( self->mesh, inc[0] );
-          nearDist = Vec_Sep( nDims, vert, point );
-          for( inc_i = 1; inc_i < nInc; inc_i++ ) {
-            vert = Mesh_GetVertex( self->mesh, inc[inc_i] );
-            dist = Vec_Sep( nDims, vert, point );
-            if( dist < nearDist ) {
-              near = inc[inc_i];
-              nearDist = dist;
-            }
-          }
-          return near;
-	}
-	else
-          return _Mesh_Algorithms_NearestVertex( self, point );
-}
-
-Bool Mesh_CentroidAlgorithms_Search( void* centroidAlgorithms, double* point, 
-				     MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
-
-	assert( self );
-
-	return Mesh_Search( self->elMesh, point, dim, ind );
-}
-
-Bool Mesh_CentroidAlgorithms_SearchElements( void* centroidAlgorithms, double* point, 
-					     unsigned* elInd )
-{
-	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
-
-	assert( self );
-
-	return Mesh_SearchElements( self->elMesh, point, elInd );
-}
-
-void Mesh_CentroidAlgorithms_GetLocalCoordRange( void* algorithms, double* min, double* max ) {
-	Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)algorithms;
-
-	assert( self );
-	Mesh_GetLocalCoordRange( self->elMesh, min, max );
-}
-
-void Mesh_CentroidAlgorithms_GetDomainCoordRange( void* algorithms, double* min, double* max ) {
-	Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)algorithms;
-
-	assert( self );
-	Mesh_GetDomainCoordRange( self->elMesh, min, max );
-}
-
-void Mesh_CentroidAlgorithms_GetGlobalCoordRange( void* algorithms, double* min, double* max ) {
-	Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)algorithms;
-
-	assert( self );
-	Mesh_GetGlobalCoordRange( self->elMesh, min, max );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void Mesh_CentroidAlgorithms_SetElementMesh( void* centroidAlgorithms, void* mesh ) {
-	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidAlgorithms ) );
-
-	self->elMesh = (Mesh*)mesh;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_CentroidAlgorithms.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_CentroidAlgorithms.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,269 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_CentroidAlgorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type Mesh_CentroidAlgorithms_Type = "Mesh_CentroidAlgorithms";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_CentroidAlgorithms* Mesh_CentroidAlgorithms_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                                   _sizeOfSelf = sizeof(Mesh_CentroidAlgorithms);
+	Type                                                           type = Mesh_CentroidAlgorithms_Type;
+	Stg_Class_DeleteFunction*                                   _delete = _Mesh_CentroidAlgorithms_Delete;
+	Stg_Class_PrintFunction*                                     _print = _Mesh_CentroidAlgorithms_Print;
+	Stg_Class_CopyFunction*                                       _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_CentroidAlgorithms_New;
+	Stg_Component_ConstructFunction*                         _construct = _Mesh_CentroidAlgorithms_AssignFromXML;
+	Stg_Component_BuildFunction*                                 _build = _Mesh_CentroidAlgorithms_Build;
+	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_CentroidAlgorithms_Initialise;
+	Stg_Component_ExecuteFunction*                             _execute = _Mesh_CentroidAlgorithms_Execute;
+	Stg_Component_DestroyFunction*                             _destroy = _Mesh_CentroidAlgorithms_Destroy;
+	AllocationType                                   nameAllocationType = NON_GLOBAL;
+	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = _Mesh_Algorithms_SetMesh;
+	Mesh_Algorithms_UpdateFunc*                              updateFunc = Mesh_CentroidAlgorithms_Update;
+	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = Mesh_CentroidAlgorithms_NearestVertex;
+	Mesh_Algorithms_SearchFunc*                              searchFunc = Mesh_CentroidAlgorithms_Search;
+	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = Mesh_CentroidAlgorithms_SearchElements;
+	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
+	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = Mesh_CentroidAlgorithms_GetLocalCoordRange;
+	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = Mesh_CentroidAlgorithms_GetDomainCoordRange;
+	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = Mesh_CentroidAlgorithms_GetGlobalCoordRange;
+
+   Mesh_CentroidAlgorithms* self = _Mesh_CentroidAlgorithms_New(  MESH_CENTROIDALGORITHMS_PASSARGS  );
+
+	_Mesh_Algorithms_Init( (Mesh_Algorithms*)self, context );
+	_Mesh_CentroidAlgorithms_Init( self );
+   return self;
+
+}
+
+Mesh_CentroidAlgorithms* _Mesh_CentroidAlgorithms_New(  MESH_CENTROIDALGORITHMS_DEFARGS  ) {
+	Mesh_CentroidAlgorithms* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_CentroidAlgorithms) );
+	self = (Mesh_CentroidAlgorithms*)_Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
+
+	return self;
+}
+
+void _Mesh_CentroidAlgorithms_Init( void* centroidAlgorithms ) {
+	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidAlgorithms ) );
+
+	self->elMesh = NULL;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_CentroidAlgorithms_Delete( void* centroidAlgorithms ) {
+	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
+
+	/* Delete the parent. */
+	_Mesh_Algorithms_Delete( self );
+}
+
+void _Mesh_CentroidAlgorithms_Print( void* _centroidAlgorithms, Stream* stream ) {
+	Mesh_CentroidAlgorithms* self= (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
+	
+	/* Set the Journal for printing informations */
+	Stream* centroidAlgorithmsStream;
+	centroidAlgorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_CentroidAlgorithmsStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_CentroidAlgorithms (ptr): (%p)\n", self );
+	_Mesh_Algorithms_Print( self, stream );
+}
+
+void _Mesh_CentroidAlgorithms_AssignFromXML( void* _centroidAlgorithms, Stg_ComponentFactory* cf, void* data ) {
+    
+    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
+    
+    _Mesh_Algorithms_AssignFromXML( self, cf, data );
+
+    _Mesh_CentroidAlgorithms_Init( self );
+}
+
+void _Mesh_CentroidAlgorithms_Build( void* _centroidAlgorithms, void* data ) {
+    
+    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
+    
+    Stg_Component_Build( self->elMesh, data, False );  
+    _Mesh_Algorithms_Build( self, data );
+}
+
+void _Mesh_CentroidAlgorithms_Initialise( void* _centroidAlgorithms, void* data ) {
+    Mesh_CentroidAlgorithms*      self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
+    
+    Stg_Component_Initialise( self->elMesh, data, False );  
+    _Mesh_Algorithms_Initialise( self, data );
+}
+
+void _Mesh_CentroidAlgorithms_Execute( void* _centroidAlgorithms, void* data ) {
+    
+    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
+    
+    Stg_Component_Initialise( self->elMesh, data, False );  
+    _Mesh_Algorithms_Initialise( self, data );
+}
+
+void _Mesh_CentroidAlgorithms_Destroy( void* _centroidAlgorithms, void* data ) {
+    
+    Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)_centroidAlgorithms;
+    
+    Stg_Component_Destroy( self->elMesh, data, False );  
+    _Mesh_Algorithms_Destroy( self, data );
+}
+
+void Mesh_CentroidAlgorithms_Update( void* centroidAlgorithms ) {
+}
+
+#define Vec_Sep( nDims, v0, v1 )									\
+	(((v0)[0] - (v1)[0]) * ((v0)[0] - (v1)[0]) +							\
+	 (((nDims) >= 2) ? (((v0)[1] - (v1)[1]) * ((v0)[1] - (v1)[1]) + 				\
+			    (((nDims) == 3) ? (((v0)[2] - (v1)[2]) * ((v0)[2] - (v1)[2])) : 0)) : 0))
+
+unsigned Mesh_CentroidAlgorithms_NearestVertex( void* centroidAlgorithms, double* point ) {
+	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
+	unsigned			elInd;
+	double dist, nearDist;
+	unsigned near;
+	unsigned nDims;
+	double* vert;
+	unsigned inc_i;
+
+	assert( self );
+
+	if( Mesh_SearchElements( self->elMesh, point, &elInd ) ) {
+          unsigned	nInc, *inc;
+          
+          nDims = Mesh_GetDimSize( self->mesh );
+          Mesh_GetIncidence(self->elMesh,
+                            Mesh_GetDimSize( self->mesh ),
+                            elInd, MT_VERTEX, 
+                            self->incArray );
+          nInc = IArray_GetSize( self->incArray );
+          inc = (unsigned*)IArray_GetPtr( self->incArray );
+          near = inc[0];
+          vert = Mesh_GetVertex( self->mesh, inc[0] );
+          nearDist = Vec_Sep( nDims, vert, point );
+          for( inc_i = 1; inc_i < nInc; inc_i++ ) {
+            vert = Mesh_GetVertex( self->mesh, inc[inc_i] );
+            dist = Vec_Sep( nDims, vert, point );
+            if( dist < nearDist ) {
+              near = inc[inc_i];
+              nearDist = dist;
+            }
+          }
+          return near;
+	}
+	else
+          return _Mesh_Algorithms_NearestVertex( self, point );
+}
+
+Bool Mesh_CentroidAlgorithms_Search( void* centroidAlgorithms, double* point, 
+				     MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
+
+	assert( self );
+
+	return Mesh_Search( self->elMesh, point, dim, ind );
+}
+
+Bool Mesh_CentroidAlgorithms_SearchElements( void* centroidAlgorithms, double* point, 
+					     unsigned* elInd )
+{
+	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
+
+	assert( self );
+
+	return Mesh_SearchElements( self->elMesh, point, elInd );
+}
+
+void Mesh_CentroidAlgorithms_GetLocalCoordRange( void* algorithms, double* min, double* max ) {
+	Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)algorithms;
+
+	assert( self );
+	Mesh_GetLocalCoordRange( self->elMesh, min, max );
+}
+
+void Mesh_CentroidAlgorithms_GetDomainCoordRange( void* algorithms, double* min, double* max ) {
+	Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)algorithms;
+
+	assert( self );
+	Mesh_GetDomainCoordRange( self->elMesh, min, max );
+}
+
+void Mesh_CentroidAlgorithms_GetGlobalCoordRange( void* algorithms, double* min, double* max ) {
+	Mesh_CentroidAlgorithms* self = (Mesh_CentroidAlgorithms*)algorithms;
+
+	assert( self );
+	Mesh_GetGlobalCoordRange( self->elMesh, min, max );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Mesh_CentroidAlgorithms_SetElementMesh( void* centroidAlgorithms, void* mesh ) {
+	Mesh_CentroidAlgorithms*	self = (Mesh_CentroidAlgorithms*)centroidAlgorithms;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidAlgorithms ) );
+
+	self->elMesh = (Mesh*)mesh;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_CentroidType.c
--- a/Mesh/src/Mesh_CentroidType.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,181 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_CentroidType.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "Mesh_ElementType.h"
-#include "MeshClass.h"
-#include "Mesh_CentroidType.h"
-
-
-/* Textual name of this class */
-const Type Mesh_CentroidType_Type = "Mesh_CentroidType";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_CentroidType* Mesh_CentroidType_New() {
-	/* Variables set in this function */
-	SizeT                                                    _sizeOfSelf = sizeof(Mesh_CentroidType);
-	Type                                                            type = Mesh_CentroidType_Type;
-	Stg_Class_DeleteFunction*                                    _delete = _Mesh_CentroidType_Delete;
-	Stg_Class_PrintFunction*                                      _print = _Mesh_CentroidType_Print;
-	Stg_Class_CopyFunction*                                        _copy = NULL;
-	Mesh_ElementType_UpdateFunc*                              updateFunc = Mesh_CentroidType_Update;
-	Mesh_ElementType_ElementHasPointFunc*            elementHasPointFunc = Mesh_CentroidType_ElementHasPoint;
-	Mesh_ElementType_GetMinimumSeparationFunc*  getMinimumSeparationFunc = Mesh_CentroidType_GetMinimumSeparation;
-	Mesh_ElementType_GetCentroidFunc*                    getCentroidFunc = Mesh_CentroidType_GetCentroid;
-
-	return _Mesh_CentroidType_New(  MESH_CENTROIDTYPE_PASSARGS  );
-}
-
-Mesh_CentroidType* _Mesh_CentroidType_New(  MESH_CENTROIDTYPE_DEFARGS  ) {
-	Mesh_CentroidType* self;
-
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_CentroidType) );
-	self = (Mesh_CentroidType*)_Mesh_ElementType_New(  MESH_ELEMENTTYPE_PASSARGS  );
-
-	/* Virtual info */
-
-	/* Mesh_CentroidType info */
-	_Mesh_CentroidType_Init( self );
-
-	return self;
-}
-
-void _Mesh_CentroidType_Init( Mesh_CentroidType* self ) {
-	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
-
-	self->elMesh = NULL;
-	self->incArray = IArray_New();
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_CentroidType_Delete( void* centroidType ) {
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-
-	NewClass_Delete( self->incArray );
-
-	/* Delete the parent. */
-	_Mesh_ElementType_Delete( self );
-}
-
-void _Mesh_CentroidType_Print( void* centroidType, Stream* stream ) {
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-	Stream*			centroidTypeStream;
-
-	centroidTypeStream = Journal_Register( InfoStream_Type, (Name)"Mesh_CentroidTypeStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_CentroidType (ptr): (%p)\n", self );
-	_Mesh_ElementType_Print( self, stream );
-}
-
-void Mesh_CentroidType_Update( void* centroidType ) {
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
-}
-
-Bool Mesh_CentroidType_ElementHasPoint( void* centroidType, unsigned elInd, double* point, 
-					MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
-
-	return Mesh_ElementHasPoint( self->elMesh, elInd, point, dim, ind );
-}
-
-double Mesh_CentroidType_GetMinimumSeparation( void* centroidType, unsigned elInd, double* perDim ) {
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-	Mesh_ElementType*	elType;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
-
-	elType = Mesh_GetElementType( self->elMesh, elInd );
-
-	return Mesh_ElementType_GetMinimumSeparation( elType, elInd, perDim );
-}
-
-void Mesh_CentroidType_GetCentroid( void* centroidType, unsigned element, double* centroid ) {
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-	const int*		inc;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
-
-	Mesh_GetIncidence( self->mesh,
-                           Mesh_GetDimSize( self->mesh ),
-                           element, MT_VERTEX, 
-			   self->incArray );
-	assert( IArray_GetSize( self->incArray ) == 1 );
-	inc = IArray_GetPtr( self->incArray );
-	memcpy( centroid, Mesh_GetVertex( self->mesh, inc[0] ), Mesh_GetDimSize( self->mesh ) * sizeof(unsigned) );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void Mesh_CentroidType_SetElementMesh( void* centroidType, void* mesh ) {
-	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
-
-	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
-	assert( !mesh || Stg_CheckType( mesh, Mesh ) );
-
-	self->elMesh = (Mesh*)mesh;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_CentroidType.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_CentroidType.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,181 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_CentroidType.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "Mesh_ElementType.h"
+#include "MeshClass.h"
+#include "Mesh_CentroidType.h"
+
+
+/* Textual name of this class */
+const Type Mesh_CentroidType_Type = "Mesh_CentroidType";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_CentroidType* Mesh_CentroidType_New() {
+	/* Variables set in this function */
+	SizeT                                                    _sizeOfSelf = sizeof(Mesh_CentroidType);
+	Type                                                            type = Mesh_CentroidType_Type;
+	Stg_Class_DeleteFunction*                                    _delete = _Mesh_CentroidType_Delete;
+	Stg_Class_PrintFunction*                                      _print = _Mesh_CentroidType_Print;
+	Stg_Class_CopyFunction*                                        _copy = NULL;
+	Mesh_ElementType_UpdateFunc*                              updateFunc = Mesh_CentroidType_Update;
+	Mesh_ElementType_ElementHasPointFunc*            elementHasPointFunc = Mesh_CentroidType_ElementHasPoint;
+	Mesh_ElementType_GetMinimumSeparationFunc*  getMinimumSeparationFunc = Mesh_CentroidType_GetMinimumSeparation;
+	Mesh_ElementType_GetCentroidFunc*                    getCentroidFunc = Mesh_CentroidType_GetCentroid;
+
+	return _Mesh_CentroidType_New(  MESH_CENTROIDTYPE_PASSARGS  );
+}
+
+Mesh_CentroidType* _Mesh_CentroidType_New(  MESH_CENTROIDTYPE_DEFARGS  ) {
+	Mesh_CentroidType* self;
+
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_CentroidType) );
+	self = (Mesh_CentroidType*)_Mesh_ElementType_New(  MESH_ELEMENTTYPE_PASSARGS  );
+
+	/* Virtual info */
+
+	/* Mesh_CentroidType info */
+	_Mesh_CentroidType_Init( self );
+
+	return self;
+}
+
+void _Mesh_CentroidType_Init( Mesh_CentroidType* self ) {
+	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
+
+	self->elMesh = NULL;
+	self->incArray = IArray_New();
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_CentroidType_Delete( void* centroidType ) {
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+
+	NewClass_Delete( self->incArray );
+
+	/* Delete the parent. */
+	_Mesh_ElementType_Delete( self );
+}
+
+void _Mesh_CentroidType_Print( void* centroidType, Stream* stream ) {
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+	Stream*			centroidTypeStream;
+
+	centroidTypeStream = Journal_Register( InfoStream_Type, (Name)"Mesh_CentroidTypeStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_CentroidType (ptr): (%p)\n", self );
+	_Mesh_ElementType_Print( self, stream );
+}
+
+void Mesh_CentroidType_Update( void* centroidType ) {
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
+}
+
+Bool Mesh_CentroidType_ElementHasPoint( void* centroidType, unsigned elInd, double* point, 
+					MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
+
+	return Mesh_ElementHasPoint( self->elMesh, elInd, point, dim, ind );
+}
+
+double Mesh_CentroidType_GetMinimumSeparation( void* centroidType, unsigned elInd, double* perDim ) {
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+	Mesh_ElementType*	elType;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
+
+	elType = Mesh_GetElementType( self->elMesh, elInd );
+
+	return Mesh_ElementType_GetMinimumSeparation( elType, elInd, perDim );
+}
+
+void Mesh_CentroidType_GetCentroid( void* centroidType, unsigned element, double* centroid ) {
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+	const int*		inc;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
+
+	Mesh_GetIncidence( self->mesh,
+                           Mesh_GetDimSize( self->mesh ),
+                           element, MT_VERTEX, 
+			   self->incArray );
+	assert( IArray_GetSize( self->incArray ) == 1 );
+	inc = IArray_GetPtr( self->incArray );
+	memcpy( centroid, Mesh_GetVertex( self->mesh, inc[0] ), Mesh_GetDimSize( self->mesh ) * sizeof(unsigned) );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Mesh_CentroidType_SetElementMesh( void* centroidType, void* mesh ) {
+	Mesh_CentroidType*	self = (Mesh_CentroidType*)centroidType;
+
+	assert( self && Stg_CheckType( self, Mesh_CentroidType ) );
+	assert( !mesh || Stg_CheckType( mesh, Mesh ) );
+
+	self->elMesh = (Mesh*)mesh;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_ElementType.c
--- a/Mesh/src/Mesh_ElementType.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_ElementType.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type Mesh_ElementType_Type = "Mesh_ElementType";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_ElementType* _Mesh_ElementType_New(  MESH_ELEMENTTYPE_DEFARGS  ) {
-	Mesh_ElementType*	self;
-
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_ElementType) );
-	self = (Mesh_ElementType*)_Stg_Class_New(  STG_CLASS_PASSARGS  );
-
-	/* Virtual info */
-	self->updateFunc = updateFunc;
-	self->elementHasPointFunc = elementHasPointFunc;
-	self->getMinimumSeparationFunc = getMinimumSeparationFunc;
-	self->getCentroidFunc = getCentroidFunc;
-
-	/* Mesh_ElementType info */
-	_Mesh_ElementType_Init( self );
-
-	return self;
-}
-
-void _Mesh_ElementType_Init( Mesh_ElementType* self ) {
-	assert( self && Stg_CheckType( self, Mesh_ElementType ) );
-
-	self->mesh = NULL;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_ElementType_Delete( void* elementType ) {
-	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
-
-	/* Delete the parent. */
-	_Stg_Class_Delete( self );
-}
-
-void _Mesh_ElementType_Print( void* elementType, Stream* stream ) {
-	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
-	Stream*			elementTypeStream;
-
-	elementTypeStream = Journal_Register( InfoStream_Type, (Name)"Mesh_ElementTypeStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_ElementType (ptr): (%p)\n", self );
-	_Stg_Class_Print( self, stream );
-}
-
-void _Mesh_ElementType_GetCentroid( void* elementType, unsigned element, double* centroid ) {
-	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
-	Mesh*			mesh;
-	IArray*			inc;
-	unsigned		nIncVerts;
-	const int		*incVerts;
-	unsigned		nDims;
-	double			denom;
-	unsigned		d_i, v_i;
-
-	assert( self );
-
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-	inc = IArray_New();
-	Mesh_GetIncidence(mesh,(MeshTopology_Dim)nDims,element,MT_VERTEX,inc);
-	nIncVerts = (unsigned)IArray_GetSize( inc );
-	incVerts = IArray_GetPtr( inc );
-
-	assert( nIncVerts );
-	denom = 1.0 / (double)nIncVerts;
-
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		centroid[d_i] = Mesh_GetVertex( mesh, incVerts[0] )[d_i];
-		for( v_i = 1; v_i < nIncVerts; v_i++ )
-			centroid[d_i] += Mesh_GetVertex( mesh, incVerts[v_i] )[d_i];
-		centroid[d_i] *= denom;
-	}
-
-	NewClass_Delete( inc );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void Mesh_ElementType_SetMesh( void* elementType, void* mesh ) {
-	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
-
-	assert( self && Stg_CheckType( self, Mesh_ElementType ) );
-	assert( !mesh || Stg_CheckType( mesh, Mesh ) );
-
-	self->mesh = (Mesh*)mesh;
-	Mesh_ElementType_Update( self );
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_ElementType.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_ElementType.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,149 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_ElementType.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type Mesh_ElementType_Type = "Mesh_ElementType";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_ElementType* _Mesh_ElementType_New(  MESH_ELEMENTTYPE_DEFARGS  ) {
+	Mesh_ElementType*	self;
+
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_ElementType) );
+	self = (Mesh_ElementType*)_Stg_Class_New(  STG_CLASS_PASSARGS  );
+
+	/* Virtual info */
+	self->updateFunc = updateFunc;
+	self->elementHasPointFunc = elementHasPointFunc;
+	self->getMinimumSeparationFunc = getMinimumSeparationFunc;
+	self->getCentroidFunc = getCentroidFunc;
+
+	/* Mesh_ElementType info */
+	_Mesh_ElementType_Init( self );
+
+	return self;
+}
+
+void _Mesh_ElementType_Init( Mesh_ElementType* self ) {
+	assert( self && Stg_CheckType( self, Mesh_ElementType ) );
+
+	self->mesh = NULL;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_ElementType_Delete( void* elementType ) {
+	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
+
+	/* Delete the parent. */
+	_Stg_Class_Delete( self );
+}
+
+void _Mesh_ElementType_Print( void* elementType, Stream* stream ) {
+	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
+	Stream*			elementTypeStream;
+
+	elementTypeStream = Journal_Register( InfoStream_Type, (Name)"Mesh_ElementTypeStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_ElementType (ptr): (%p)\n", self );
+	_Stg_Class_Print( self, stream );
+}
+
+void _Mesh_ElementType_GetCentroid( void* elementType, unsigned element, double* centroid ) {
+	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
+	Mesh*			mesh;
+	IArray*			inc;
+	unsigned		nIncVerts;
+	const int		*incVerts;
+	unsigned		nDims;
+	double			denom;
+	unsigned		d_i, v_i;
+
+	assert( self );
+
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+	inc = IArray_New();
+	Mesh_GetIncidence(mesh,(MeshTopology_Dim)nDims,element,MT_VERTEX,inc);
+	nIncVerts = (unsigned)IArray_GetSize( inc );
+	incVerts = IArray_GetPtr( inc );
+
+	assert( nIncVerts );
+	denom = 1.0 / (double)nIncVerts;
+
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+		centroid[d_i] = Mesh_GetVertex( mesh, incVerts[0] )[d_i];
+		for( v_i = 1; v_i < nIncVerts; v_i++ )
+			centroid[d_i] += Mesh_GetVertex( mesh, incVerts[v_i] )[d_i];
+		centroid[d_i] *= denom;
+	}
+
+	NewClass_Delete( inc );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Mesh_ElementType_SetMesh( void* elementType, void* mesh ) {
+	Mesh_ElementType*	self = (Mesh_ElementType*)elementType;
+
+	assert( self && Stg_CheckType( self, Mesh_ElementType ) );
+	assert( !mesh || Stg_CheckType( mesh, Mesh ) );
+
+	self->mesh = (Mesh*)mesh;
+	Mesh_ElementType_Update( self );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_HexAlgorithms.c
--- a/Mesh/src/Mesh_HexAlgorithms.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,156 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_HexAlgorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type Mesh_HexAlgorithms_Type = "Mesh_HexAlgorithms";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_HexAlgorithms* Mesh_HexAlgorithms_New( Name name, AbstractContext* context) {
-	/* Variables set in this function */
-	SizeT                                                   _sizeOfSelf = sizeof(Mesh_HexAlgorithms);
-	Type                                                           type = Mesh_HexAlgorithms_Type;
-	Stg_Class_DeleteFunction*                                   _delete = _Mesh_HexAlgorithms_Delete;
-	Stg_Class_PrintFunction*                                     _print = _Mesh_HexAlgorithms_Print;
-	Stg_Class_CopyFunction*                                       _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_HexAlgorithms_New;
-	Stg_Component_ConstructFunction*                         _construct = _Mesh_HexAlgorithms_AssignFromXML;
-	Stg_Component_BuildFunction*                                 _build = _Mesh_HexAlgorithms_Build;
-	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_HexAlgorithms_Initialise;
-	Stg_Component_ExecuteFunction*                             _execute = _Mesh_HexAlgorithms_Execute;
-	Stg_Component_DestroyFunction*                             _destroy = _Mesh_HexAlgorithms_Destroy;
-	AllocationType                                   nameAllocationType = NON_GLOBAL;
-	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = _Mesh_Algorithms_SetMesh;
-	Mesh_Algorithms_UpdateFunc*                              updateFunc = _Mesh_Algorithms_Update;
-	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = _Mesh_Algorithms_NearestVertex;
-	Mesh_Algorithms_SearchFunc*                              searchFunc = _Mesh_Algorithms_Search;
-	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = _Mesh_Algorithms_SearchElements;
-	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
-	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = _Mesh_Algorithms_GetLocalCoordRange;
-	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = _Mesh_Algorithms_GetDomainCoordRange;
-	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = _Mesh_Algorithms_GetGlobalCoordRange;
-
-   Mesh_HexAlgorithms* self = _Mesh_HexAlgorithms_New(  MESH_HEXALGORITHMS_PASSARGS  );
-	/* Mesh_HexAlgorithms info */
-	_Mesh_Algorithms_Init( (Mesh_Algorithms*)self, context );
-	_Mesh_HexAlgorithms_Init( self );
-
-   return self;
-
-}
-
-Mesh_HexAlgorithms* _Mesh_HexAlgorithms_New(  MESH_HEXALGORITHMS_DEFARGS  ) {
-	Mesh_HexAlgorithms* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_HexAlgorithms) );
-	self = (Mesh_HexAlgorithms*)_Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
-
-	return self;
-}
-
-void _Mesh_HexAlgorithms_Init( void* hexAlgorithms ) {
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_HexAlgorithms_Delete( void* hexAlgorithms ) {
-	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-
-	/* Delete the parent. */
-	_Mesh_Algorithms_Delete( self );
-}
-
-void _Mesh_HexAlgorithms_Print( void* hexAlgorithms, Stream* stream ) {
-	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-	
-	/* Set the Journal for printing informations */
-	Stream* hexAlgorithmsStream;
-	hexAlgorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_HexAlgorithmsStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_HexAlgorithms (ptr): (%p)\n", self );
-	_Mesh_Algorithms_Print( self, stream );
-}
-
-void _Mesh_HexAlgorithms_AssignFromXML( void* hexAlgorithms, Stg_ComponentFactory* cf, void* data ) {
-
-   Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-   _Mesh_Algorithms_AssignFromXML( self, cf, data );
-   _Mesh_HexAlgorithms_Init( self );
-}
-
-void _Mesh_HexAlgorithms_Build( void* hexAlgorithms, void* data ) {
-	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-	_Mesh_Algorithms_Build( self, data );
-}
-
-void _Mesh_HexAlgorithms_Initialise( void* hexAlgorithms, void* data ) {
-	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-	_Mesh_Algorithms_Initialise( self, data );
-}
-
-void _Mesh_HexAlgorithms_Execute( void* hexAlgorithms, void* data ) {
-	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-	_Mesh_Algorithms_Execute( self, data );
-}
-
-void _Mesh_HexAlgorithms_Destroy( void* hexAlgorithms, void* data ) {
-	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
-	_Mesh_Algorithms_Destroy( self, data );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_HexAlgorithms.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_HexAlgorithms.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,156 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_HexAlgorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type Mesh_HexAlgorithms_Type = "Mesh_HexAlgorithms";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_HexAlgorithms* Mesh_HexAlgorithms_New( Name name, AbstractContext* context) {
+	/* Variables set in this function */
+	SizeT                                                   _sizeOfSelf = sizeof(Mesh_HexAlgorithms);
+	Type                                                           type = Mesh_HexAlgorithms_Type;
+	Stg_Class_DeleteFunction*                                   _delete = _Mesh_HexAlgorithms_Delete;
+	Stg_Class_PrintFunction*                                     _print = _Mesh_HexAlgorithms_Print;
+	Stg_Class_CopyFunction*                                       _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_HexAlgorithms_New;
+	Stg_Component_ConstructFunction*                         _construct = _Mesh_HexAlgorithms_AssignFromXML;
+	Stg_Component_BuildFunction*                                 _build = _Mesh_HexAlgorithms_Build;
+	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_HexAlgorithms_Initialise;
+	Stg_Component_ExecuteFunction*                             _execute = _Mesh_HexAlgorithms_Execute;
+	Stg_Component_DestroyFunction*                             _destroy = _Mesh_HexAlgorithms_Destroy;
+	AllocationType                                   nameAllocationType = NON_GLOBAL;
+	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = _Mesh_Algorithms_SetMesh;
+	Mesh_Algorithms_UpdateFunc*                              updateFunc = _Mesh_Algorithms_Update;
+	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = _Mesh_Algorithms_NearestVertex;
+	Mesh_Algorithms_SearchFunc*                              searchFunc = _Mesh_Algorithms_Search;
+	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = _Mesh_Algorithms_SearchElements;
+	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
+	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = _Mesh_Algorithms_GetLocalCoordRange;
+	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = _Mesh_Algorithms_GetDomainCoordRange;
+	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = _Mesh_Algorithms_GetGlobalCoordRange;
+
+   Mesh_HexAlgorithms* self = _Mesh_HexAlgorithms_New(  MESH_HEXALGORITHMS_PASSARGS  );
+	/* Mesh_HexAlgorithms info */
+	_Mesh_Algorithms_Init( (Mesh_Algorithms*)self, context );
+	_Mesh_HexAlgorithms_Init( self );
+
+   return self;
+
+}
+
+Mesh_HexAlgorithms* _Mesh_HexAlgorithms_New(  MESH_HEXALGORITHMS_DEFARGS  ) {
+	Mesh_HexAlgorithms* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_HexAlgorithms) );
+	self = (Mesh_HexAlgorithms*)_Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
+
+	return self;
+}
+
+void _Mesh_HexAlgorithms_Init( void* hexAlgorithms ) {
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_HexAlgorithms_Delete( void* hexAlgorithms ) {
+	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+
+	/* Delete the parent. */
+	_Mesh_Algorithms_Delete( self );
+}
+
+void _Mesh_HexAlgorithms_Print( void* hexAlgorithms, Stream* stream ) {
+	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+	
+	/* Set the Journal for printing informations */
+	Stream* hexAlgorithmsStream;
+	hexAlgorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_HexAlgorithmsStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_HexAlgorithms (ptr): (%p)\n", self );
+	_Mesh_Algorithms_Print( self, stream );
+}
+
+void _Mesh_HexAlgorithms_AssignFromXML( void* hexAlgorithms, Stg_ComponentFactory* cf, void* data ) {
+
+   Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+   _Mesh_Algorithms_AssignFromXML( self, cf, data );
+   _Mesh_HexAlgorithms_Init( self );
+}
+
+void _Mesh_HexAlgorithms_Build( void* hexAlgorithms, void* data ) {
+	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+	_Mesh_Algorithms_Build( self, data );
+}
+
+void _Mesh_HexAlgorithms_Initialise( void* hexAlgorithms, void* data ) {
+	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+	_Mesh_Algorithms_Initialise( self, data );
+}
+
+void _Mesh_HexAlgorithms_Execute( void* hexAlgorithms, void* data ) {
+	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+	_Mesh_Algorithms_Execute( self, data );
+}
+
+void _Mesh_HexAlgorithms_Destroy( void* hexAlgorithms, void* data ) {
+	Mesh_HexAlgorithms*	self = (Mesh_HexAlgorithms*)hexAlgorithms;
+	_Mesh_Algorithms_Destroy( self, data );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_HexType.c
--- a/Mesh/src/Mesh_HexType.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1080 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_HexType.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "IGraph.h"
-#include "Mesh_ElementType.h"
-#include "MeshClass.h"
-#include "Mesh_HexType.h"
-
-
-/* Textual name of this class */
-const Type Mesh_HexType_Type = "Mesh_HexType";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_HexType* Mesh_HexType_New() {
-	/* Variables set in this function */
-	SizeT                                                    _sizeOfSelf = sizeof(Mesh_HexType);
-	Type                                                            type = Mesh_HexType_Type;
-	Stg_Class_DeleteFunction*                                    _delete = _Mesh_HexType_Delete;
-	Stg_Class_PrintFunction*                                      _print = _Mesh_HexType_Print;
-	Stg_Class_CopyFunction*                                        _copy = NULL;
-	Mesh_ElementType_UpdateFunc*                              updateFunc = Mesh_HexType_Update;
-	Mesh_ElementType_ElementHasPointFunc*            elementHasPointFunc = Mesh_HexType_ElementHasPoint;
-	Mesh_ElementType_GetMinimumSeparationFunc*  getMinimumSeparationFunc = Mesh_HexType_GetMinimumSeparation;
-	Mesh_ElementType_GetCentroidFunc*                    getCentroidFunc = _Mesh_ElementType_GetCentroid;
-
-	return _Mesh_HexType_New(  MESH_HEXTYPE_PASSARGS  );
-}
-
-Mesh_HexType* _Mesh_HexType_New(  MESH_HEXTYPE_DEFARGS  ) {
-	Mesh_HexType* self;
-
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_HexType) );
-	self = (Mesh_HexType*)_Mesh_ElementType_New(  MESH_ELEMENTTYPE_PASSARGS  );
-
-	/* Virtual info */
-
-	/* Mesh_HexType info */
-	_Mesh_HexType_Init( self );
-
-	return self;
-}
-
-void _Mesh_HexType_Init( Mesh_HexType* self ) {
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-
-	self->vertMap = AllocArray( unsigned, 8 );
-	self->inc = AllocArray( unsigned, 8 );
-	Mesh_HexType_SetVertexMap( self, NULL );
-
-	self->elementHasPoint = NULL;
-
-	self->triInds = AllocArray2D( unsigned, 2, 3 );
-	self->triInds[0][0] = 0; self->triInds[0][1] = 1; self->triInds[0][2] = 2;
-	self->triInds[1][0] = 1; self->triInds[1][1] = 3; self->triInds[1][2] = 2;
-
-	self->tetInds = AllocArray2D( unsigned, 10, 4 );
-	self->tetInds[0][0] = 0; self->tetInds[0][1] = 1; self->tetInds[0][2] = 2; self->tetInds[0][3] = 4;
-	self->tetInds[1][0] = 1; self->tetInds[1][1] = 2; self->tetInds[1][2] = 3; self->tetInds[1][3] = 7;
-	self->tetInds[2][0] = 1; self->tetInds[2][1] = 4; self->tetInds[2][2] = 5; self->tetInds[2][3] = 7;
-	self->tetInds[3][0] = 2; self->tetInds[3][1] = 4; self->tetInds[3][2] = 6; self->tetInds[3][3] = 7;
-	self->tetInds[4][0] = 1; self->tetInds[4][1] = 2; self->tetInds[4][2] = 4; self->tetInds[4][3] = 7;
-	self->tetInds[5][0] = 0; self->tetInds[5][1] = 1; self->tetInds[5][2] = 3; self->tetInds[5][3] = 5;
-	self->tetInds[6][0] = 0; self->tetInds[6][1] = 4; self->tetInds[6][2] = 5; self->tetInds[6][3] = 6;
-	self->tetInds[7][0] = 0; self->tetInds[7][1] = 2; self->tetInds[7][2] = 3; self->tetInds[7][3] = 6;
-	self->tetInds[8][0] = 3; self->tetInds[8][1] = 5; self->tetInds[8][2] = 6; self->tetInds[8][3] = 7;
-	self->tetInds[9][0] = 0; self->tetInds[9][1] = 3; self->tetInds[9][2] = 5; self->tetInds[9][3] = 6;
-
-	self->incArray = IArray_New();
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_HexType_Delete( void* elementType ) {
-	Mesh_HexType*	self = (Mesh_HexType*)elementType;
-
-	FreeArray( self->vertMap );
-	FreeArray( self->inc );
-	FreeArray( self->triInds );
-	FreeArray( self->tetInds );
-	NewClass_Delete( self->incArray );
-
-	/* Delete the parent. */
-	_Mesh_ElementType_Delete( self );
-}
-
-void _Mesh_HexType_Print( void* elementType, Stream* stream ) {
-	Mesh_HexType*	self = (Mesh_HexType*)elementType;
-	Stream*			elementTypeStream;
-
-	elementTypeStream = Journal_Register( InfoStream_Type, (Name)"Mesh_HexTypeStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_HexType (ptr): (%p)\n", self );
-	_Mesh_ElementType_Print( self, stream );
-}
-
-void Mesh_HexType_Update( void* hexType ) {
-	Mesh_HexType*	self = (Mesh_HexType*)hexType;
-	unsigned	nDims;
-	unsigned	d_i;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-
-	nDims = Mesh_GetDimSize( self->mesh );
-	for( d_i = 0; d_i < nDims; d_i++ ) {
-		if( Class_IsSuper( self->mesh->topo, IGraph ) && (!Mesh_GetGlobalSize( self->mesh, (MeshTopology_Dim)d_i ) || !Mesh_HasIncidence( self->mesh, (MeshTopology_Dim)nDims, (MeshTopology_Dim)d_i )) ) {
-			break;
-		}
-	}
-
-	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
-		if( d_i == nDims ) {
-			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint3DWithIncidence;
-		}
-		else {
-			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint3DGeneral;
-		}
-	}
-	else if( Mesh_GetDimSize( self->mesh ) == 2 ) {
-		if( d_i == nDims ) {
-			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint2DWithIncidence;
-		}
-		else {
-			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint2DGeneral;
-		}
-	}
-	else {
-		if( d_i == nDims ) {
-			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint1DWithIncidence;
-		}
-		else {
-			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint1DGeneral;
-		}
-	}
-}
-
-Bool Mesh_HexType_ElementHasPoint( void* hexType, unsigned elInd, double* point, MeshTopology_Dim* dim, unsigned* ind ) {
-	Mesh_HexType*	self = (Mesh_HexType*)hexType;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) <= 3 );
-	assert( self->elementHasPoint );
-
-	return self->elementHasPoint( self, elInd, point, dim, ind );
-}
-
-double Mesh_HexType_GetMinimumSeparation( void* hexType, unsigned elInd, double* perDim ) {
-	Mesh_HexType*	self = (Mesh_HexType*)hexType;
-	unsigned*		map = NULL;
-	double			curSep = 0.0;
-	double*			dimSep = NULL;
-	unsigned		e_i, nInc = 0;
-	int			*inc = NULL;
-
-	assert( self );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( Mesh_GetDimSize( self->mesh ) <= 3 );
-
-	/*
-	** We know we're a hexahedral element but we may not be regular.  This algorithm (originally from
-	** FeVariable.c) doesn't calculate the exact separation but provides an answer that's pretty
-	** close.
-	*/
-
-	dimSep = AllocArray( double, Mesh_GetDimSize( self->mesh ) );
-
-	for( e_i = 0; e_i > (unsigned)Mesh_GetDimSize( self->mesh ); e_i++ )
-		dimSep[e_i] = 0.0;
-
-	Mesh_GetIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-	map = self->vertMap;
-
-	curSep = Mesh_GetVertex( self->mesh, inc[map[1]] )[0] - Mesh_GetVertex( self->mesh, inc[map[0]] )[0];
-	dimSep[0] = curSep;	
-
-	if( Mesh_GetDimSize( self->mesh ) >= 2 ) {
-		curSep = Mesh_GetVertex( self->mesh, inc[map[3]] )[0] - Mesh_GetVertex( self->mesh, inc[map[2]] )[0];
-		if( curSep < dimSep[0] )
-			dimSep[0] = curSep;
-	}
-
-	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
-		curSep = Mesh_GetVertex( self->mesh, inc[map[5]] )[0] - Mesh_GetVertex( self->mesh, inc[map[4]] )[0];
-		if( curSep < dimSep[0] )
-			dimSep[0] = curSep;
-
-		curSep = Mesh_GetVertex( self->mesh, inc[map[7]] )[0] - Mesh_GetVertex( self->mesh, inc[map[6]] )[0];
-		if( curSep < dimSep[0] )
-			dimSep[0] = curSep;
-	}
-
-	if( Mesh_GetDimSize( self->mesh ) >= 2 ) {
-		dimSep[1] = Mesh_GetVertex( self->mesh, inc[map[2]] )[1] - Mesh_GetVertex( self->mesh, inc[map[0]] )[1];
-
-		curSep = Mesh_GetVertex( self->mesh, inc[map[3]] )[1] - Mesh_GetVertex( self->mesh, inc[map[1]] )[1];
-		if( curSep < dimSep[1] )
-			dimSep[1] = curSep;
-	}
-
-	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
-		curSep = Mesh_GetVertex( self->mesh, inc[map[6]] )[1] - Mesh_GetVertex( self->mesh, inc[map[4]] )[1];
-		if( curSep < dimSep[1] )
-			dimSep[1] = curSep;
-
-		curSep = Mesh_GetVertex( self->mesh, inc[map[7]] )[1] - Mesh_GetVertex( self->mesh, inc[map[5]] )[1];
-		if( curSep < dimSep[1] )
-			dimSep[1] = curSep;
-	}
-
-	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
-		curSep = Mesh_GetVertex( self->mesh, inc[map[4]] )[2] - Mesh_GetVertex( self->mesh, inc[map[0]] )[2];
-		dimSep[2] = curSep;
-
-		curSep = Mesh_GetVertex( self->mesh, inc[map[5]] )[2] - Mesh_GetVertex( self->mesh, inc[map[1]] )[2];
-		if( curSep < dimSep[2] )
-			dimSep[2] = curSep;
-
-		curSep = Mesh_GetVertex( self->mesh, inc[map[6]] )[2] - Mesh_GetVertex( self->mesh, inc[map[2]] )[2];
-		if ( curSep < dimSep[2] )
-			dimSep[2] = curSep;
-
-		curSep = Mesh_GetVertex( self->mesh, inc[map[7]] )[2] - Mesh_GetVertex( self->mesh, inc[map[3]] )[2];
-		if ( curSep < dimSep[2] )
-			dimSep[2] = curSep;
-	}
-
-	curSep = dimSep[0];
-	if( Mesh_GetDimSize( self->mesh ) >= 2 ) {
-		curSep = dimSep[1] < curSep ? dimSep[1] : curSep;
-		if ( Mesh_GetDimSize( self->mesh ) == 3 )
-			curSep = dimSep[2] < curSep ? dimSep[2] : curSep;
-	}
-
-	if( perDim )
-		memcpy( perDim, dimSep, Mesh_GetDimSize( self->mesh ) * sizeof(double) );
-
-	FreeArray( dimSep );
-
-	return curSep;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void Mesh_HexType_SetVertexMap( void* hexType, unsigned* map ) {
-	Mesh_HexType*	self = (Mesh_HexType*)hexType;
-	unsigned	v_i;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-
-	if( map ) {
-		self->mapSize = (Mesh_GetDimSize( self->mesh ) == 3) ? 8 : 4;
-		memcpy( self->vertMap, map, self->mapSize * sizeof(unsigned) );
-	}
-	else {
-		self->mapSize = 0;
-		for( v_i = 0; v_i < 8; v_i++ )
-			self->vertMap[v_i] = v_i;
-	}
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-Bool Mesh_HexType_ElementHasPoint3DGeneral( Mesh_HexType* self, unsigned elInd, double* point, 
-					    MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*		mesh;
-	unsigned	nInc;
-	double		bc[4];
-	unsigned	inside;
-	const int	*inc;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) == 3 );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( point );
-	assert( dim );
-	assert( ind );
-
-	/* Shortcuts. */
-	mesh = self->mesh;
-
-	/* Get element to vertex incidence. */
-	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-
-	/* Search for tetrahedra. */
-	if( self->mapSize ) {
-		unsigned	v_i;
-
-		for( v_i = 0; v_i < self->mapSize; v_i++ )
-			self->inc[v_i] = inc[self->vertMap[v_i]];
-		if( Simplex_Search3D( mesh->verts, self->inc, 10, self->tetInds, point, bc, &inside ) ) {
-			*dim = MT_VOLUME;
-			*ind = elInd;
-			return True;
-		}
-	}
-	else {
-		if( Simplex_Search3D( mesh->verts, (unsigned*)inc, 10, self->tetInds, point, bc, &inside ) ) {
-			*dim = MT_VOLUME;
-			*ind = elInd;
-			return True;
-		}
-	}
-
-	return False;
-}
-
-Bool Mesh_HexType_ElementHasPoint3DWithIncidence( Mesh_HexType* self, unsigned elInd, double* point, 
-						  MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*		mesh;
-	unsigned	nInc;
-	Bool		fnd;
-	double		bc[4];
-	IGraph*		topo;
-	unsigned	inside;
-	const int*	inc;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) == 3 );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( point );
-	assert( dim );
-	assert( ind );
-
-	/* Shortcuts. */
-	mesh = self->mesh;
-	topo = (IGraph*)mesh->topo;
-
-	/* Get element to vertex incidence. */
-	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-
-	/* Search for tetrahedra. */
-	if( self->mapSize ) {
-		unsigned	v_i;
-
-		for( v_i = 0; v_i < self->mapSize; v_i++ )
-			self->inc[v_i] = inc[self->vertMap[v_i]];
-		fnd = Simplex_Search3D( mesh->verts, self->inc, 10, self->tetInds, point, bc, &inside );
-	}
-	else
-		fnd = Simplex_Search3D( mesh->verts, (unsigned*)inc, 10, self->tetInds, point, bc, &inside );
-	if( fnd ) {
-		unsigned*	inds = self->tetInds[inside];
-
-		/* Check boundary ownership. */
-		if( bc[0] == 0.0 || bc[0] == -0.0 ) {
-			if( bc[1] == 0.0 || bc[1] == -0.0 ) {
-				if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-					*dim = MT_VERTEX;
-					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[3]];
-				}
-				else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-					*dim = MT_VERTEX;
-					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[2]];
-				}
-				else {
-					if( inside == 0 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-					}
-					else if( inside == 1 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][11];
-					}
-					else if( inside == 2 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][7];
-					}
-					else if( inside == 3 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][5];
-					}
-					else if( inside == 4 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-					}
-					else if( inside == 5 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-					}
-					else if( inside == 6 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-					}
-					else if( inside == 7 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-					}
-					else if( inside == 8 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][5];
-					}
-					else {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-					}
-				}
-			}
-			else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-				if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-					*dim = MT_VERTEX;
-					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[1]];
-				}
-				else {
-					if( inside == 0 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-					}
-					else if( inside == 1 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-					}
-					else if( inside == 2 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-					}
-					else if( inside == 3 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-					}
-					else if( inside == 4 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-					}
-					else if( inside == 5 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][9];
-					}
-					else if( inside == 6 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][6];
-					}
-					else if( inside == 7 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][10];
-					}
-					else if( inside == 8 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][7];
-					}
-					else {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-					}
-				}
-			}
-			else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-				if( inside == 0 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-				}
-				else if( inside == 1 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][1];
-				}
-				else if( inside == 2 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][4];
-				}
-				else if( inside == 3 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][6];
-				}
-				else if( inside == 4 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-				}
-				else if( inside == 5 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][3];
-				}
-				else if( inside == 6 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][4];
-				}
-				else if( inside == 7 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][1];
-				}
-				else if( inside == 8 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-				}
-				else {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-				}
-			}
-			else {
-				if( inside == 0 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 1 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-				}
-				else if( inside == 2 ) {
-					*dim = 	MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-				}
-				else if( inside == 3 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-				}
-				else if( inside == 4 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 5 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-				}
-				else if( inside == 6 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-				}
-				else if( inside == 7 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-				}
-				else if( inside == 8 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
-				}
-				else {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-			}
-		}
-		else if( bc[1] == 0.0 || bc[1] == -0.0 ) {
-			if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-				if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-					*dim = MT_VERTEX;
-					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[0]];
-				}
-				else {
-					if( inside == 0 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][8];
-					}
-					else if( inside == 1 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-					}
-					else if( inside == 2 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-					}
-					else if( inside == 3 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-					}
-					else if( inside == 4 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-					}
-					else if( inside == 5 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-					}
-					else if( inside == 6 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-					}
-					else if( inside == 7 ) {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-					}
-					else if( inside == 8 ) {
-						*dim = MT_EDGE;
-						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][7];
-					}
-					else {
-						*dim = MT_FACE;
-						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-					}
-				}
-			}
-			else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-				if( inside == 0 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][2];
-				}
-				else if( inside == 1 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][3];
-				}
-				else if( inside == 2 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][9];
-				}
-				else if( inside == 3 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][10];
-				}
-				else if( inside == 4 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-				}
-				else if( inside == 5 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-				}
-				else if( inside == 6 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-				}
-				else if( inside == 7 ) {
-					*dim = 	MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-				}
-				else if( inside == 8 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-				}
-				else {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-				}
-			}
-			else {
-				if( inside == 0 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-				}
-				else if( inside == 1 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-				}
-				else if( inside == 2 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-				}
-				else if( inside == 3 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-				}
-				else if( inside == 4 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 5 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 6 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 7 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 8 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
-				}
-				else {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-			}
-		}
-		else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-			if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-				if( inside == 0 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][0];
-				}
-				else if( inside == 1 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-				}
-				else if( inside == 2 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-				}
-				else if( inside == 3 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-				}
-				else if( inside == 4 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-				}
-				else if( inside == 5 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][0];
-				}
-				else if( inside == 6 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][8];
-				}
-				else if( inside == 7 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][2];
-				}
-				else if( inside == 8 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-				}
-				else {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-				}
-			}
-			else {
-				if( inside == 0 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-				}
-				else if( inside == 1 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 2 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 3 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 4 ) {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-				else if( inside == 5 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-				}
-				else if( inside == 6 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-				}
-				else if( inside == 7 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-				}
-				else if( inside == 8 ) {
-					*dim = MT_FACE;
-					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
-				}
-				else {
-					*dim = MT_VOLUME;
-					*ind = elInd;
-				}
-			}
-		}
-		else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
-			if( inside == 0 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-			}
-			else if( inside == 1 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-			}
-			else if( inside == 2 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-			}
-			else if( inside == 3 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
-			}
-			else if( inside == 4 ) {
-				*dim = MT_VOLUME;
-				*ind = elInd;
-			}
-			else if( inside == 5 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-			}
-			else if( inside == 6 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
-			}
-			else if( inside == 7 ) {
-				*dim = MT_FACE;
-				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
-			}
-			else if( inside == 8 ) {
-				*dim = MT_VOLUME;
-				*ind = elInd;
-			}
-			else {
-				*dim = MT_VOLUME;
-				*ind = elInd;
-			}
-		}
-		else {
-			*dim = MT_VOLUME;
-			*ind = elInd;
-		}
-
-		return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_HexType_ElementHasPoint2DGeneral( Mesh_HexType* self, unsigned elInd, double* point, 
-					    MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*		mesh;
-	unsigned	nInc;
-	Bool		fnd;
-	double		bc[3];
-	unsigned	inside;
-	const int*	inc;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) == 2 );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( point );
-	assert( dim );
-	assert( ind );
-
-	/* Shortcuts. */
-	mesh = self->mesh;
-
-	/* Get element to vertex incidence. */
-	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-
-	/* Search for triangle. */
-	if( self->mapSize ) {
-		unsigned	v_i;
-
-		for( v_i = 0; v_i < self->mapSize; v_i++ )
-			self->inc[v_i] = inc[self->vertMap[v_i]];
-		fnd = Simplex_Search2D( mesh->verts, self->inc, 2, self->triInds, point, bc, &inside );
-	}
-	else
-		fnd = Simplex_Search2D( mesh->verts, (unsigned*)inc, 2, self->triInds, point, bc, &inside );
-	if( fnd ) {
-		*dim = MT_FACE;
-		*ind = elInd;
-		return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_HexType_ElementHasPoint2DWithIncidence( Mesh_HexType* self, unsigned elInd, double* point, 
-						  MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*		mesh;
-	unsigned	nInc;
-	Bool		fnd;
-	double		bc[3];
-	IGraph*		topo;
-	unsigned	inside;
-	const int*	inc;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) == 2 );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( point );
-	assert( dim );
-	assert( ind );
-
-	/* Shortcuts. */
-	mesh = self->mesh;
-	topo = (IGraph*)mesh->topo;
-
-	/* Get element to vertex incidence. */
-	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-
-	/* Search for triangle. */
-	if( self->mapSize ) {
-		unsigned	v_i;
-
-		for( v_i = 0; v_i < self->mapSize; v_i++ )
-			self->inc[v_i] = inc[self->vertMap[v_i]];
-		fnd = Simplex_Search2D( mesh->verts, self->inc, 2, self->triInds, point, bc, &inside );
-	}
-	else
-		fnd = Simplex_Search2D( mesh->verts, (unsigned*)inc, 2, self->triInds, point, bc, &inside );
-	if( fnd ) {
-		unsigned	*inds = self->triInds[inside];
-
-		/* Check boundary ownership. */
-		if( bc[0] == 0.0 || bc[0] == -0.0 ) {
-			if( bc[1] == 0.0 || bc[1] == -0.0 ) {
-				*dim = MT_VERTEX;
-				*ind = topo->incEls[MT_FACE][MT_VERTEX][elInd][inds[2]];
-			}
-			else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-				*dim = MT_VERTEX;
-				*ind = topo->incEls[MT_FACE][MT_VERTEX][elInd][inds[1]];
-			}
-			else {
-				if( inside == 0 ) {
-					*dim = MT_FACE;
-					*ind = elInd;
-				}
-				else if( inside == 1 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][1];
-				}
-			}
-		}
-		else if( bc[1] == 0.0 || bc[1] == -0.0 ) {
-			if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-				*dim = MT_VERTEX;
-				*ind = topo->incEls[MT_FACE][MT_VERTEX][elInd][inds[0]];
-			}
-			else {
-				if( inside == 0 ) {
-					*dim = MT_EDGE;
-					*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][2];
-				}
-				else if( inside == 1 ) {
-					*dim = MT_FACE;
-					*ind = elInd;
-				}
-			}
-		}
-		else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
-			if( inside == 0 ) {
-				*dim = MT_EDGE;
-				*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][0];
-			}
-			else if( inside == 1 ) {
-				*dim = MT_EDGE;
-				*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][3];
-			}
-		}
-		else {
-			*dim = MT_FACE;
-			*ind = elInd;
-		}
-
-		return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_HexType_ElementHasPoint1DGeneral( Mesh_HexType* self, unsigned elInd, double* point, 
-					    MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*		mesh;
-	unsigned	nInc;
-	const int*	inc;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) == 1 );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( point );
-	assert( dim );
-	assert( ind );
-
-	mesh = self->mesh;
-	Mesh_GetIncidence( mesh, MT_EDGE, elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-
-	if( point[0] > *Mesh_GetVertex( mesh, inc[self->vertMap[0]] ) && 
-	    point[0] < *Mesh_GetVertex( mesh, inc[self->vertMap[1]] ) )
-	{
-		*dim = MT_EDGE;
-		*ind = elInd;
-		return True;
-	}
-
-	return False;
-}
-
-Bool Mesh_HexType_ElementHasPoint1DWithIncidence( Mesh_HexType* self, unsigned elInd, double* point, 
-						  MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh*		mesh;
-	unsigned	nInc;
-	const int*	inc;
-
-	assert( self && Stg_CheckType( self, Mesh_HexType ) );
-	assert( Mesh_GetDimSize( self->mesh ) == 1 );
-	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	assert( point );
-	assert( dim );
-	assert( ind );
-
-	mesh = self->mesh;
-	Mesh_GetIncidence( mesh, MT_EDGE, elInd, MT_VERTEX, self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = IArray_GetPtr( self->incArray );
-	assert( nInc == 2 );
-
-	if( point[0] > *Mesh_GetVertex( mesh, inc[self->vertMap[0]] ) && 
-	    point[0] < *Mesh_GetVertex( mesh, inc[self->vertMap[1]] ) )
-	{
-		*dim = MT_EDGE;
-		*ind = elInd;
-		return True;
-	}
-	else if( point[0] == *Mesh_GetVertex( mesh, inc[self->vertMap[0]] ) ) {
-		*dim = MT_VERTEX;
-		*ind = inc[0];
-		return True;
-	}
-	else if( point[0] == *Mesh_GetVertex( mesh, inc[self->vertMap[1]] ) ) {
-		*dim = MT_VERTEX;
-		*ind = inc[1];
-		return True;
-	}
-
-	return False;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_HexType.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_HexType.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1080 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_HexType.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "IGraph.h"
+#include "Mesh_ElementType.h"
+#include "MeshClass.h"
+#include "Mesh_HexType.h"
+
+
+/* Textual name of this class */
+const Type Mesh_HexType_Type = "Mesh_HexType";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_HexType* Mesh_HexType_New() {
+	/* Variables set in this function */
+	SizeT                                                    _sizeOfSelf = sizeof(Mesh_HexType);
+	Type                                                            type = Mesh_HexType_Type;
+	Stg_Class_DeleteFunction*                                    _delete = _Mesh_HexType_Delete;
+	Stg_Class_PrintFunction*                                      _print = _Mesh_HexType_Print;
+	Stg_Class_CopyFunction*                                        _copy = NULL;
+	Mesh_ElementType_UpdateFunc*                              updateFunc = Mesh_HexType_Update;
+	Mesh_ElementType_ElementHasPointFunc*            elementHasPointFunc = Mesh_HexType_ElementHasPoint;
+	Mesh_ElementType_GetMinimumSeparationFunc*  getMinimumSeparationFunc = Mesh_HexType_GetMinimumSeparation;
+	Mesh_ElementType_GetCentroidFunc*                    getCentroidFunc = _Mesh_ElementType_GetCentroid;
+
+	return _Mesh_HexType_New(  MESH_HEXTYPE_PASSARGS  );
+}
+
+Mesh_HexType* _Mesh_HexType_New(  MESH_HEXTYPE_DEFARGS  ) {
+	Mesh_HexType* self;
+
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_HexType) );
+	self = (Mesh_HexType*)_Mesh_ElementType_New(  MESH_ELEMENTTYPE_PASSARGS  );
+
+	/* Virtual info */
+
+	/* Mesh_HexType info */
+	_Mesh_HexType_Init( self );
+
+	return self;
+}
+
+void _Mesh_HexType_Init( Mesh_HexType* self ) {
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+
+	self->vertMap = AllocArray( unsigned, 8 );
+	self->inc = AllocArray( unsigned, 8 );
+	Mesh_HexType_SetVertexMap( self, NULL );
+
+	self->elementHasPoint = NULL;
+
+	self->triInds = AllocArray2D( unsigned, 2, 3 );
+	self->triInds[0][0] = 0; self->triInds[0][1] = 1; self->triInds[0][2] = 2;
+	self->triInds[1][0] = 1; self->triInds[1][1] = 3; self->triInds[1][2] = 2;
+
+	self->tetInds = AllocArray2D( unsigned, 10, 4 );
+	self->tetInds[0][0] = 0; self->tetInds[0][1] = 1; self->tetInds[0][2] = 2; self->tetInds[0][3] = 4;
+	self->tetInds[1][0] = 1; self->tetInds[1][1] = 2; self->tetInds[1][2] = 3; self->tetInds[1][3] = 7;
+	self->tetInds[2][0] = 1; self->tetInds[2][1] = 4; self->tetInds[2][2] = 5; self->tetInds[2][3] = 7;
+	self->tetInds[3][0] = 2; self->tetInds[3][1] = 4; self->tetInds[3][2] = 6; self->tetInds[3][3] = 7;
+	self->tetInds[4][0] = 1; self->tetInds[4][1] = 2; self->tetInds[4][2] = 4; self->tetInds[4][3] = 7;
+	self->tetInds[5][0] = 0; self->tetInds[5][1] = 1; self->tetInds[5][2] = 3; self->tetInds[5][3] = 5;
+	self->tetInds[6][0] = 0; self->tetInds[6][1] = 4; self->tetInds[6][2] = 5; self->tetInds[6][3] = 6;
+	self->tetInds[7][0] = 0; self->tetInds[7][1] = 2; self->tetInds[7][2] = 3; self->tetInds[7][3] = 6;
+	self->tetInds[8][0] = 3; self->tetInds[8][1] = 5; self->tetInds[8][2] = 6; self->tetInds[8][3] = 7;
+	self->tetInds[9][0] = 0; self->tetInds[9][1] = 3; self->tetInds[9][2] = 5; self->tetInds[9][3] = 6;
+
+	self->incArray = IArray_New();
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_HexType_Delete( void* elementType ) {
+	Mesh_HexType*	self = (Mesh_HexType*)elementType;
+
+	FreeArray( self->vertMap );
+	FreeArray( self->inc );
+	FreeArray( self->triInds );
+	FreeArray( self->tetInds );
+	NewClass_Delete( self->incArray );
+
+	/* Delete the parent. */
+	_Mesh_ElementType_Delete( self );
+}
+
+void _Mesh_HexType_Print( void* elementType, Stream* stream ) {
+	Mesh_HexType*	self = (Mesh_HexType*)elementType;
+	Stream*			elementTypeStream;
+
+	elementTypeStream = Journal_Register( InfoStream_Type, (Name)"Mesh_HexTypeStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_HexType (ptr): (%p)\n", self );
+	_Mesh_ElementType_Print( self, stream );
+}
+
+void Mesh_HexType_Update( void* hexType ) {
+	Mesh_HexType*	self = (Mesh_HexType*)hexType;
+	unsigned	nDims;
+	unsigned	d_i;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+
+	nDims = Mesh_GetDimSize( self->mesh );
+	for( d_i = 0; d_i < nDims; d_i++ ) {
+		if( Class_IsSuper( self->mesh->topo, IGraph ) && (!Mesh_GetGlobalSize( self->mesh, (MeshTopology_Dim)d_i ) || !Mesh_HasIncidence( self->mesh, (MeshTopology_Dim)nDims, (MeshTopology_Dim)d_i )) ) {
+			break;
+		}
+	}
+
+	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
+		if( d_i == nDims ) {
+			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint3DWithIncidence;
+		}
+		else {
+			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint3DGeneral;
+		}
+	}
+	else if( Mesh_GetDimSize( self->mesh ) == 2 ) {
+		if( d_i == nDims ) {
+			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint2DWithIncidence;
+		}
+		else {
+			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint2DGeneral;
+		}
+	}
+	else {
+		if( d_i == nDims ) {
+			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint1DWithIncidence;
+		}
+		else {
+			self->elementHasPoint = (Mesh_ElementType_ElementHasPointFunc*)Mesh_HexType_ElementHasPoint1DGeneral;
+		}
+	}
+}
+
+Bool Mesh_HexType_ElementHasPoint( void* hexType, unsigned elInd, double* point, MeshTopology_Dim* dim, unsigned* ind ) {
+	Mesh_HexType*	self = (Mesh_HexType*)hexType;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) <= 3 );
+	assert( self->elementHasPoint );
+
+	return self->elementHasPoint( self, elInd, point, dim, ind );
+}
+
+double Mesh_HexType_GetMinimumSeparation( void* hexType, unsigned elInd, double* perDim ) {
+	Mesh_HexType*	self = (Mesh_HexType*)hexType;
+	unsigned*		map = NULL;
+	double			curSep = 0.0;
+	double*			dimSep = NULL;
+	unsigned		e_i, nInc = 0;
+	int			*inc = NULL;
+
+	assert( self );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( Mesh_GetDimSize( self->mesh ) <= 3 );
+
+	/*
+	** We know we're a hexahedral element but we may not be regular.  This algorithm (originally from
+	** FeVariable.c) doesn't calculate the exact separation but provides an answer that's pretty
+	** close.
+	*/
+
+	dimSep = AllocArray( double, Mesh_GetDimSize( self->mesh ) );
+
+	for( e_i = 0; e_i > (unsigned)Mesh_GetDimSize( self->mesh ); e_i++ )
+		dimSep[e_i] = 0.0;
+
+	Mesh_GetIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+	map = self->vertMap;
+
+	curSep = Mesh_GetVertex( self->mesh, inc[map[1]] )[0] - Mesh_GetVertex( self->mesh, inc[map[0]] )[0];
+	dimSep[0] = curSep;	
+
+	if( Mesh_GetDimSize( self->mesh ) >= 2 ) {
+		curSep = Mesh_GetVertex( self->mesh, inc[map[3]] )[0] - Mesh_GetVertex( self->mesh, inc[map[2]] )[0];
+		if( curSep < dimSep[0] )
+			dimSep[0] = curSep;
+	}
+
+	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
+		curSep = Mesh_GetVertex( self->mesh, inc[map[5]] )[0] - Mesh_GetVertex( self->mesh, inc[map[4]] )[0];
+		if( curSep < dimSep[0] )
+			dimSep[0] = curSep;
+
+		curSep = Mesh_GetVertex( self->mesh, inc[map[7]] )[0] - Mesh_GetVertex( self->mesh, inc[map[6]] )[0];
+		if( curSep < dimSep[0] )
+			dimSep[0] = curSep;
+	}
+
+	if( Mesh_GetDimSize( self->mesh ) >= 2 ) {
+		dimSep[1] = Mesh_GetVertex( self->mesh, inc[map[2]] )[1] - Mesh_GetVertex( self->mesh, inc[map[0]] )[1];
+
+		curSep = Mesh_GetVertex( self->mesh, inc[map[3]] )[1] - Mesh_GetVertex( self->mesh, inc[map[1]] )[1];
+		if( curSep < dimSep[1] )
+			dimSep[1] = curSep;
+	}
+
+	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
+		curSep = Mesh_GetVertex( self->mesh, inc[map[6]] )[1] - Mesh_GetVertex( self->mesh, inc[map[4]] )[1];
+		if( curSep < dimSep[1] )
+			dimSep[1] = curSep;
+
+		curSep = Mesh_GetVertex( self->mesh, inc[map[7]] )[1] - Mesh_GetVertex( self->mesh, inc[map[5]] )[1];
+		if( curSep < dimSep[1] )
+			dimSep[1] = curSep;
+	}
+
+	if( Mesh_GetDimSize( self->mesh ) == 3 ) {
+		curSep = Mesh_GetVertex( self->mesh, inc[map[4]] )[2] - Mesh_GetVertex( self->mesh, inc[map[0]] )[2];
+		dimSep[2] = curSep;
+
+		curSep = Mesh_GetVertex( self->mesh, inc[map[5]] )[2] - Mesh_GetVertex( self->mesh, inc[map[1]] )[2];
+		if( curSep < dimSep[2] )
+			dimSep[2] = curSep;
+
+		curSep = Mesh_GetVertex( self->mesh, inc[map[6]] )[2] - Mesh_GetVertex( self->mesh, inc[map[2]] )[2];
+		if ( curSep < dimSep[2] )
+			dimSep[2] = curSep;
+
+		curSep = Mesh_GetVertex( self->mesh, inc[map[7]] )[2] - Mesh_GetVertex( self->mesh, inc[map[3]] )[2];
+		if ( curSep < dimSep[2] )
+			dimSep[2] = curSep;
+	}
+
+	curSep = dimSep[0];
+	if( Mesh_GetDimSize( self->mesh ) >= 2 ) {
+		curSep = dimSep[1] < curSep ? dimSep[1] : curSep;
+		if ( Mesh_GetDimSize( self->mesh ) == 3 )
+			curSep = dimSep[2] < curSep ? dimSep[2] : curSep;
+	}
+
+	if( perDim )
+		memcpy( perDim, dimSep, Mesh_GetDimSize( self->mesh ) * sizeof(double) );
+
+	FreeArray( dimSep );
+
+	return curSep;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Mesh_HexType_SetVertexMap( void* hexType, unsigned* map ) {
+	Mesh_HexType*	self = (Mesh_HexType*)hexType;
+	unsigned	v_i;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+
+	if( map ) {
+		self->mapSize = (Mesh_GetDimSize( self->mesh ) == 3) ? 8 : 4;
+		memcpy( self->vertMap, map, self->mapSize * sizeof(unsigned) );
+	}
+	else {
+		self->mapSize = 0;
+		for( v_i = 0; v_i < 8; v_i++ )
+			self->vertMap[v_i] = v_i;
+	}
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+Bool Mesh_HexType_ElementHasPoint3DGeneral( Mesh_HexType* self, unsigned elInd, double* point, 
+					    MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*		mesh;
+	unsigned	nInc;
+	double		bc[4];
+	unsigned	inside;
+	const int	*inc;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) == 3 );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( point );
+	assert( dim );
+	assert( ind );
+
+	/* Shortcuts. */
+	mesh = self->mesh;
+
+	/* Get element to vertex incidence. */
+	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+
+	/* Search for tetrahedra. */
+	if( self->mapSize ) {
+		unsigned	v_i;
+
+		for( v_i = 0; v_i < self->mapSize; v_i++ )
+			self->inc[v_i] = inc[self->vertMap[v_i]];
+		if( Simplex_Search3D( mesh->verts, self->inc, 10, self->tetInds, point, bc, &inside ) ) {
+			*dim = MT_VOLUME;
+			*ind = elInd;
+			return True;
+		}
+	}
+	else {
+		if( Simplex_Search3D( mesh->verts, (unsigned*)inc, 10, self->tetInds, point, bc, &inside ) ) {
+			*dim = MT_VOLUME;
+			*ind = elInd;
+			return True;
+		}
+	}
+
+	return False;
+}
+
+Bool Mesh_HexType_ElementHasPoint3DWithIncidence( Mesh_HexType* self, unsigned elInd, double* point, 
+						  MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*		mesh;
+	unsigned	nInc;
+	Bool		fnd;
+	double		bc[4];
+	IGraph*		topo;
+	unsigned	inside;
+	const int*	inc;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) == 3 );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( point );
+	assert( dim );
+	assert( ind );
+
+	/* Shortcuts. */
+	mesh = self->mesh;
+	topo = (IGraph*)mesh->topo;
+
+	/* Get element to vertex incidence. */
+	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+
+	/* Search for tetrahedra. */
+	if( self->mapSize ) {
+		unsigned	v_i;
+
+		for( v_i = 0; v_i < self->mapSize; v_i++ )
+			self->inc[v_i] = inc[self->vertMap[v_i]];
+		fnd = Simplex_Search3D( mesh->verts, self->inc, 10, self->tetInds, point, bc, &inside );
+	}
+	else
+		fnd = Simplex_Search3D( mesh->verts, (unsigned*)inc, 10, self->tetInds, point, bc, &inside );
+	if( fnd ) {
+		unsigned*	inds = self->tetInds[inside];
+
+		/* Check boundary ownership. */
+		if( bc[0] == 0.0 || bc[0] == -0.0 ) {
+			if( bc[1] == 0.0 || bc[1] == -0.0 ) {
+				if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+					*dim = MT_VERTEX;
+					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[3]];
+				}
+				else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+					*dim = MT_VERTEX;
+					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[2]];
+				}
+				else {
+					if( inside == 0 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+					}
+					else if( inside == 1 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][11];
+					}
+					else if( inside == 2 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][7];
+					}
+					else if( inside == 3 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][5];
+					}
+					else if( inside == 4 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+					}
+					else if( inside == 5 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+					}
+					else if( inside == 6 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+					}
+					else if( inside == 7 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+					}
+					else if( inside == 8 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][5];
+					}
+					else {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+					}
+				}
+			}
+			else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+				if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+					*dim = MT_VERTEX;
+					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[1]];
+				}
+				else {
+					if( inside == 0 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+					}
+					else if( inside == 1 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+					}
+					else if( inside == 2 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+					}
+					else if( inside == 3 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+					}
+					else if( inside == 4 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+					}
+					else if( inside == 5 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][9];
+					}
+					else if( inside == 6 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][6];
+					}
+					else if( inside == 7 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][10];
+					}
+					else if( inside == 8 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][7];
+					}
+					else {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+					}
+				}
+			}
+			else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+				if( inside == 0 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+				}
+				else if( inside == 1 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][1];
+				}
+				else if( inside == 2 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][4];
+				}
+				else if( inside == 3 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][6];
+				}
+				else if( inside == 4 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+				}
+				else if( inside == 5 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][3];
+				}
+				else if( inside == 6 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][4];
+				}
+				else if( inside == 7 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][1];
+				}
+				else if( inside == 8 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+				}
+				else {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+				}
+			}
+			else {
+				if( inside == 0 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 1 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+				}
+				else if( inside == 2 ) {
+					*dim = 	MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+				}
+				else if( inside == 3 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+				}
+				else if( inside == 4 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 5 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+				}
+				else if( inside == 6 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+				}
+				else if( inside == 7 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+				}
+				else if( inside == 8 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][1];
+				}
+				else {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+			}
+		}
+		else if( bc[1] == 0.0 || bc[1] == -0.0 ) {
+			if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+				if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+					*dim = MT_VERTEX;
+					*ind = topo->incEls[MT_VOLUME][MT_VERTEX][elInd][inds[0]];
+				}
+				else {
+					if( inside == 0 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][8];
+					}
+					else if( inside == 1 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+					}
+					else if( inside == 2 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+					}
+					else if( inside == 3 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+					}
+					else if( inside == 4 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+					}
+					else if( inside == 5 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+					}
+					else if( inside == 6 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+					}
+					else if( inside == 7 ) {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+					}
+					else if( inside == 8 ) {
+						*dim = MT_EDGE;
+						*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][7];
+					}
+					else {
+						*dim = MT_FACE;
+						*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+					}
+				}
+			}
+			else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+				if( inside == 0 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][2];
+				}
+				else if( inside == 1 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][3];
+				}
+				else if( inside == 2 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][9];
+				}
+				else if( inside == 3 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][10];
+				}
+				else if( inside == 4 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+				}
+				else if( inside == 5 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+				}
+				else if( inside == 6 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+				}
+				else if( inside == 7 ) {
+					*dim = 	MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+				}
+				else if( inside == 8 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+				}
+				else {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+				}
+			}
+			else {
+				if( inside == 0 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+				}
+				else if( inside == 1 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+				}
+				else if( inside == 2 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+				}
+				else if( inside == 3 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+				}
+				else if( inside == 4 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 5 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 6 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 7 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 8 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][3];
+				}
+				else {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+			}
+		}
+		else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+			if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+				if( inside == 0 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][0];
+				}
+				else if( inside == 1 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+				}
+				else if( inside == 2 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+				}
+				else if( inside == 3 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+				}
+				else if( inside == 4 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+				}
+				else if( inside == 5 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][0];
+				}
+				else if( inside == 6 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][8];
+				}
+				else if( inside == 7 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_VOLUME][MT_EDGE][elInd][2];
+				}
+				else if( inside == 8 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+				}
+				else {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+				}
+			}
+			else {
+				if( inside == 0 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+				}
+				else if( inside == 1 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 2 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 3 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 4 ) {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+				else if( inside == 5 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+				}
+				else if( inside == 6 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+				}
+				else if( inside == 7 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+				}
+				else if( inside == 8 ) {
+					*dim = MT_FACE;
+					*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][5];
+				}
+				else {
+					*dim = MT_VOLUME;
+					*ind = elInd;
+				}
+			}
+		}
+		else if( bc[3] == 0.0 || bc[3] == -0.0 ) {
+			if( inside == 0 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+			}
+			else if( inside == 1 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+			}
+			else if( inside == 2 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+			}
+			else if( inside == 3 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][4];
+			}
+			else if( inside == 4 ) {
+				*dim = MT_VOLUME;
+				*ind = elInd;
+			}
+			else if( inside == 5 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+			}
+			else if( inside == 6 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][2];
+			}
+			else if( inside == 7 ) {
+				*dim = MT_FACE;
+				*ind = topo->incEls[MT_VOLUME][MT_FACE][elInd][0];
+			}
+			else if( inside == 8 ) {
+				*dim = MT_VOLUME;
+				*ind = elInd;
+			}
+			else {
+				*dim = MT_VOLUME;
+				*ind = elInd;
+			}
+		}
+		else {
+			*dim = MT_VOLUME;
+			*ind = elInd;
+		}
+
+		return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_HexType_ElementHasPoint2DGeneral( Mesh_HexType* self, unsigned elInd, double* point, 
+					    MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*		mesh;
+	unsigned	nInc;
+	Bool		fnd;
+	double		bc[3];
+	unsigned	inside;
+	const int*	inc;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) == 2 );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( point );
+	assert( dim );
+	assert( ind );
+
+	/* Shortcuts. */
+	mesh = self->mesh;
+
+	/* Get element to vertex incidence. */
+	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+
+	/* Search for triangle. */
+	if( self->mapSize ) {
+		unsigned	v_i;
+
+		for( v_i = 0; v_i < self->mapSize; v_i++ )
+			self->inc[v_i] = inc[self->vertMap[v_i]];
+		fnd = Simplex_Search2D( mesh->verts, self->inc, 2, self->triInds, point, bc, &inside );
+	}
+	else
+		fnd = Simplex_Search2D( mesh->verts, (unsigned*)inc, 2, self->triInds, point, bc, &inside );
+	if( fnd ) {
+		*dim = MT_FACE;
+		*ind = elInd;
+		return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_HexType_ElementHasPoint2DWithIncidence( Mesh_HexType* self, unsigned elInd, double* point, 
+						  MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*		mesh;
+	unsigned	nInc;
+	Bool		fnd;
+	double		bc[3];
+	IGraph*		topo;
+	unsigned	inside;
+	const int*	inc;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) == 2 );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( point );
+	assert( dim );
+	assert( ind );
+
+	/* Shortcuts. */
+	mesh = self->mesh;
+	topo = (IGraph*)mesh->topo;
+
+	/* Get element to vertex incidence. */
+	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+
+	/* Search for triangle. */
+	if( self->mapSize ) {
+		unsigned	v_i;
+
+		for( v_i = 0; v_i < self->mapSize; v_i++ )
+			self->inc[v_i] = inc[self->vertMap[v_i]];
+		fnd = Simplex_Search2D( mesh->verts, self->inc, 2, self->triInds, point, bc, &inside );
+	}
+	else
+		fnd = Simplex_Search2D( mesh->verts, (unsigned*)inc, 2, self->triInds, point, bc, &inside );
+	if( fnd ) {
+		unsigned	*inds = self->triInds[inside];
+
+		/* Check boundary ownership. */
+		if( bc[0] == 0.0 || bc[0] == -0.0 ) {
+			if( bc[1] == 0.0 || bc[1] == -0.0 ) {
+				*dim = MT_VERTEX;
+				*ind = topo->incEls[MT_FACE][MT_VERTEX][elInd][inds[2]];
+			}
+			else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+				*dim = MT_VERTEX;
+				*ind = topo->incEls[MT_FACE][MT_VERTEX][elInd][inds[1]];
+			}
+			else {
+				if( inside == 0 ) {
+					*dim = MT_FACE;
+					*ind = elInd;
+				}
+				else if( inside == 1 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][1];
+				}
+			}
+		}
+		else if( bc[1] == 0.0 || bc[1] == -0.0 ) {
+			if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+				*dim = MT_VERTEX;
+				*ind = topo->incEls[MT_FACE][MT_VERTEX][elInd][inds[0]];
+			}
+			else {
+				if( inside == 0 ) {
+					*dim = MT_EDGE;
+					*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][2];
+				}
+				else if( inside == 1 ) {
+					*dim = MT_FACE;
+					*ind = elInd;
+				}
+			}
+		}
+		else if( bc[2] == 0.0 || bc[2] == -0.0 ) {
+			if( inside == 0 ) {
+				*dim = MT_EDGE;
+				*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][0];
+			}
+			else if( inside == 1 ) {
+				*dim = MT_EDGE;
+				*ind = topo->incEls[MT_FACE][MT_EDGE][elInd][3];
+			}
+		}
+		else {
+			*dim = MT_FACE;
+			*ind = elInd;
+		}
+
+		return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_HexType_ElementHasPoint1DGeneral( Mesh_HexType* self, unsigned elInd, double* point, 
+					    MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*		mesh;
+	unsigned	nInc;
+	const int*	inc;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) == 1 );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( point );
+	assert( dim );
+	assert( ind );
+
+	mesh = self->mesh;
+	Mesh_GetIncidence( mesh, MT_EDGE, elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+
+	if( point[0] > *Mesh_GetVertex( mesh, inc[self->vertMap[0]] ) && 
+	    point[0] < *Mesh_GetVertex( mesh, inc[self->vertMap[1]] ) )
+	{
+		*dim = MT_EDGE;
+		*ind = elInd;
+		return True;
+	}
+
+	return False;
+}
+
+Bool Mesh_HexType_ElementHasPoint1DWithIncidence( Mesh_HexType* self, unsigned elInd, double* point, 
+						  MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh*		mesh;
+	unsigned	nInc;
+	const int*	inc;
+
+	assert( self && Stg_CheckType( self, Mesh_HexType ) );
+	assert( Mesh_GetDimSize( self->mesh ) == 1 );
+	assert( elInd < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	assert( point );
+	assert( dim );
+	assert( ind );
+
+	mesh = self->mesh;
+	Mesh_GetIncidence( mesh, MT_EDGE, elInd, MT_VERTEX, self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = IArray_GetPtr( self->incArray );
+	assert( nInc == 2 );
+
+	if( point[0] > *Mesh_GetVertex( mesh, inc[self->vertMap[0]] ) && 
+	    point[0] < *Mesh_GetVertex( mesh, inc[self->vertMap[1]] ) )
+	{
+		*dim = MT_EDGE;
+		*ind = elInd;
+		return True;
+	}
+	else if( point[0] == *Mesh_GetVertex( mesh, inc[self->vertMap[0]] ) ) {
+		*dim = MT_VERTEX;
+		*ind = inc[0];
+		return True;
+	}
+	else if( point[0] == *Mesh_GetVertex( mesh, inc[self->vertMap[1]] ) ) {
+		*dim = MT_VERTEX;
+		*ind = inc[1];
+		return True;
+	}
+
+	return False;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_RegularAlgorithms.c
--- a/Mesh/src/Mesh_RegularAlgorithms.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,301 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Mesh_RegularAlgorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include "Mesh.h"
-
-
-/* Textual name of this class */
-const Type Mesh_RegularAlgorithms_Type = "Mesh_RegularAlgorithms";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Mesh_RegularAlgorithms* Mesh_RegularAlgorithms_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                                   _sizeOfSelf = sizeof(Mesh_RegularAlgorithms);
-	Type                                                           type = Mesh_RegularAlgorithms_Type;
-	Stg_Class_DeleteFunction*                                   _delete = _Mesh_RegularAlgorithms_Delete;
-	Stg_Class_PrintFunction*                                     _print = _Mesh_RegularAlgorithms_Print;
-	Stg_Class_CopyFunction*                                       _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_RegularAlgorithms_New;
-	Stg_Component_ConstructFunction*                         _construct = _Mesh_RegularAlgorithms_AssignFromXML;
-	Stg_Component_BuildFunction*                                 _build = _Mesh_RegularAlgorithms_Build;
-	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_RegularAlgorithms_Initialise;
-	Stg_Component_ExecuteFunction*                             _execute = _Mesh_RegularAlgorithms_Execute;
-	Stg_Component_DestroyFunction*                             _destroy = _Mesh_RegularAlgorithms_Destroy;
-	AllocationType                                   nameAllocationType = NON_GLOBAL;
-	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = Mesh_RegularAlgorithms_SetMesh;
-	Mesh_Algorithms_UpdateFunc*                              updateFunc = Mesh_RegularAlgorithms_Update;
-	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = _Mesh_Algorithms_NearestVertex;
-	Mesh_Algorithms_SearchFunc*                              searchFunc = _Mesh_Algorithms_Search;
-	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = Mesh_RegularAlgorithms_SearchElements;
-	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
-	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = _Mesh_Algorithms_GetLocalCoordRange;
-	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = _Mesh_Algorithms_GetDomainCoordRange;
-	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = _Mesh_Algorithms_GetGlobalCoordRange;
-
-	Mesh_RegularAlgorithms* self = _Mesh_RegularAlgorithms_New(  MESH_REGULARALGORITHMS_PASSARGS  );
-
-	/* Mesh_RegularAlgorithms info */
-	_Mesh_Algorithms_Init( (Mesh_Algorithms*)self, context );
-	_Mesh_RegularAlgorithms_Init( self );
-
-   return self;
-}
-
-Mesh_RegularAlgorithms* _Mesh_RegularAlgorithms_New(  MESH_REGULARALGORITHMS_DEFARGS  ) {
-	Mesh_RegularAlgorithms* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Mesh_RegularAlgorithms) );
-	self = (Mesh_RegularAlgorithms*)_Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
-
-	return self;
-}
-
-void _Mesh_RegularAlgorithms_Init( void* algorithms ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-
-	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
-
-	self->sep = NULL;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Mesh_RegularAlgorithms_Delete( void* algorithms ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-
-	/* Delete the parent. */
-	_Mesh_Algorithms_Delete( self );
-}
-
-void _Mesh_RegularAlgorithms_Print( void* algorithms, Stream* stream ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	
-	/* Set the Journal for printing informations */
-	Stream* algorithmsStream;
-	algorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_RegularAlgorithmsStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "Mesh_RegularAlgorithms (ptr): (%p)\n", self );
-	_Mesh_Algorithms_Print( self, stream );
-}
-
-void _Mesh_RegularAlgorithms_AssignFromXML( void* algorithms, Stg_ComponentFactory* cf, void* data ) {
-	_Mesh_Algorithms_AssignFromXML( algorithms, cf, data );
-   _Mesh_RegularAlgorithms_Init( algorithms );
-}
-
-void _Mesh_RegularAlgorithms_Build( void* algorithms, void* data ) {
-    _Mesh_Algorithms_Build( algorithms, data );
-}
-
-void _Mesh_RegularAlgorithms_Initialise( void* algorithms, void* data ) {
-    _Mesh_Algorithms_Initialise( algorithms, data );
-}
-
-void _Mesh_RegularAlgorithms_Execute( void* algorithms, void* data ) {
-    _Mesh_Algorithms_Execute( algorithms, data );
-}
-
-void _Mesh_RegularAlgorithms_Destroy( void* algorithms, void* data ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-
-	Mesh_RegularAlgorithms_Destruct( self );
-
-   _Mesh_Algorithms_Destroy( algorithms, data );
-}
-
-void Mesh_RegularAlgorithms_SetMesh( void* algorithms, void* mesh ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-
-	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
-
-	Mesh_RegularAlgorithms_Destruct( self );
-	_Mesh_Algorithms_SetMesh( self, mesh );
-}
-
-void Mesh_RegularAlgorithms_Update( void* algorithms ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	unsigned		nDims, ii;
-	Grid*			eGrid;
-
-	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
-	assert( self->mesh );
-
-	Mesh_RegularAlgorithms_Destruct( self );
-	_Mesh_Algorithms_Update( self );
-
-	nDims = Mesh_GetDimSize( self->mesh );
-	self->minCrd = AllocArray( double, nDims );
-	self->maxCrd = AllocArray( double, nDims );
-	Mesh_GetGlobalCoordRange( self->mesh, self->minCrd, self->maxCrd );
-
-	self->sep = AllocArray( double, nDims );
-	eGrid = *Mesh_GetExtension( self->mesh, Grid**, "elementGrid" );
-	for( ii = 0; ii < nDims; ii++ )
-		self->sep[ii] = (self->maxCrd[ii] - self->minCrd[ii]) / eGrid->sizes[ii];
-}
-
-Bool _Mesh_RegularAlgorithms_Search( void* algorithms, void* _mesh, double* point, 
-				     MeshTopology_Dim* dim, unsigned* ind )
-{
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	Mesh*			mesh = (Mesh*)_mesh;
-
-	assert( self );
-	assert( mesh );
-	assert( dim );
-	assert( ind );
-
-	/* TODO */
-	abort();
-
-	return False;
-}
-
-Bool Mesh_RegularAlgorithms_SearchElements( void* algorithms, double* point, unsigned* elInd ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	Mesh*			mesh;
-	unsigned		nDims;
-	unsigned		inds[3];
-	Grid			*elGrid;
-	double			out, frac, integer;
-	unsigned		d_i;
-
-	assert( self );
-	assert( Mesh_GetDimSize( self->mesh ) <= 3 );
-	assert( elInd );
-
-	mesh = self->mesh;
-	nDims = Mesh_GetDimSize( mesh );
-	elGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-						ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" ) );
-	for( d_i = 0; d_i < nDims; d_i++  ) {
-		if( Num_Approx( point[d_i] - self->maxCrd[d_i], 0.0 ) )
-			inds[d_i] = elGrid->sizes[d_i] - 1;
-		else if( point[d_i] < self->minCrd[d_i] || point[d_i] > self->maxCrd[d_i] )
-			return False;
-		else {
-			out = (point[d_i] - self->minCrd[d_i]) / self->sep[d_i];
-			frac = modf( out, &integer );
-			inds[d_i] = (unsigned)integer;
-			if( inds[d_i] > 0 && Num_Approx( frac, 0.0 ) )
-				inds[d_i]--;
-		}
-	}
-
-	*elInd = Grid_Project( elGrid, inds );
-	return Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,*elInd,elInd);
-}
-
-double _Mesh_RegularAlgorithms_GetMinimumSeparation( void* algorithms, void* _mesh, double* perDim ) {
-	Mesh* mesh;
-
-	mesh = (Mesh*)_mesh;
-
-	/* TODO */
-	abort();
-
-	return 0.0;
-}
-
-void _Mesh_RegularAlgorithms_GetLocalCoordRange( void* algorithms, void* _mesh, double* min, double* max ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	Mesh*			mesh = (Mesh*)_mesh;
-
-	assert( self );
-	assert( mesh );
-	assert( min );
-	assert( max );
-
-	/* TODO */
-	abort();
-}
-
-void _Mesh_RegularAlgorithms_GetDomainCoordRange( void* algorithms, void* _mesh, double* min, double* max ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	Mesh*			mesh = (Mesh*)_mesh;
-
-	assert( self );
-	assert( mesh );
-	assert( min );
-	assert( max );
-
-	/* TODO */
-	abort();
-}
-
-void _Mesh_RegularAlgorithms_GetGlobalCoordRange( void* algorithms, void* _mesh, double* min, double* max ) {
-	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
-	Mesh*			mesh = (Mesh*)_mesh;
-
-	assert( self );
-	assert( mesh );
-	assert( min );
-	assert( max );
-
-	/* TODO */
-	abort();
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-void Mesh_RegularAlgorithms_Destruct( Mesh_RegularAlgorithms* self ) {
-	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
-
-	KillArray( self->sep );
-	KillArray( self->minCrd );
-	KillArray( self->maxCrd );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Mesh_RegularAlgorithms.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Mesh_RegularAlgorithms.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,301 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Mesh_RegularAlgorithms.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include "Mesh.h"
+
+
+/* Textual name of this class */
+const Type Mesh_RegularAlgorithms_Type = "Mesh_RegularAlgorithms";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Mesh_RegularAlgorithms* Mesh_RegularAlgorithms_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                                   _sizeOfSelf = sizeof(Mesh_RegularAlgorithms);
+	Type                                                           type = Mesh_RegularAlgorithms_Type;
+	Stg_Class_DeleteFunction*                                   _delete = _Mesh_RegularAlgorithms_Delete;
+	Stg_Class_PrintFunction*                                     _print = _Mesh_RegularAlgorithms_Print;
+	Stg_Class_CopyFunction*                                       _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*       _defaultConstructor = (void* (*)(Name))_Mesh_RegularAlgorithms_New;
+	Stg_Component_ConstructFunction*                         _construct = _Mesh_RegularAlgorithms_AssignFromXML;
+	Stg_Component_BuildFunction*                                 _build = _Mesh_RegularAlgorithms_Build;
+	Stg_Component_InitialiseFunction*                       _initialise = _Mesh_RegularAlgorithms_Initialise;
+	Stg_Component_ExecuteFunction*                             _execute = _Mesh_RegularAlgorithms_Execute;
+	Stg_Component_DestroyFunction*                             _destroy = _Mesh_RegularAlgorithms_Destroy;
+	AllocationType                                   nameAllocationType = NON_GLOBAL;
+	Mesh_Algorithms_SetMeshFunc*                            setMeshFunc = Mesh_RegularAlgorithms_SetMesh;
+	Mesh_Algorithms_UpdateFunc*                              updateFunc = Mesh_RegularAlgorithms_Update;
+	Mesh_Algorithms_NearestVertexFunc*                nearestVertexFunc = _Mesh_Algorithms_NearestVertex;
+	Mesh_Algorithms_SearchFunc*                              searchFunc = _Mesh_Algorithms_Search;
+	Mesh_Algorithms_SearchElementsFunc*              searchElementsFunc = Mesh_RegularAlgorithms_SearchElements;
+	Mesh_Algorithms_GetMinimumSeparationFunc*  getMinimumSeparationFunc = _Mesh_Algorithms_GetMinimumSeparation;
+	Mesh_Algorithms_GetLocalCoordRangeFunc*      getLocalCoordRangeFunc = _Mesh_Algorithms_GetLocalCoordRange;
+	Mesh_Algorithms_GetDomainCoordRangeFunc*    getDomainCoordRangeFunc = _Mesh_Algorithms_GetDomainCoordRange;
+	Mesh_Algorithms_GetGlobalCoordRangeFunc*    getGlobalCoordRangeFunc = _Mesh_Algorithms_GetGlobalCoordRange;
+
+	Mesh_RegularAlgorithms* self = _Mesh_RegularAlgorithms_New(  MESH_REGULARALGORITHMS_PASSARGS  );
+
+	/* Mesh_RegularAlgorithms info */
+	_Mesh_Algorithms_Init( (Mesh_Algorithms*)self, context );
+	_Mesh_RegularAlgorithms_Init( self );
+
+   return self;
+}
+
+Mesh_RegularAlgorithms* _Mesh_RegularAlgorithms_New(  MESH_REGULARALGORITHMS_DEFARGS  ) {
+	Mesh_RegularAlgorithms* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Mesh_RegularAlgorithms) );
+	self = (Mesh_RegularAlgorithms*)_Mesh_Algorithms_New(  MESH_ALGORITHMS_PASSARGS  );
+
+	return self;
+}
+
+void _Mesh_RegularAlgorithms_Init( void* algorithms ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+
+	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
+
+	self->sep = NULL;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Mesh_RegularAlgorithms_Delete( void* algorithms ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+
+	/* Delete the parent. */
+	_Mesh_Algorithms_Delete( self );
+}
+
+void _Mesh_RegularAlgorithms_Print( void* algorithms, Stream* stream ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	
+	/* Set the Journal for printing informations */
+	Stream* algorithmsStream;
+	algorithmsStream = Journal_Register( InfoStream_Type, (Name)"Mesh_RegularAlgorithmsStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "Mesh_RegularAlgorithms (ptr): (%p)\n", self );
+	_Mesh_Algorithms_Print( self, stream );
+}
+
+void _Mesh_RegularAlgorithms_AssignFromXML( void* algorithms, Stg_ComponentFactory* cf, void* data ) {
+	_Mesh_Algorithms_AssignFromXML( algorithms, cf, data );
+   _Mesh_RegularAlgorithms_Init( algorithms );
+}
+
+void _Mesh_RegularAlgorithms_Build( void* algorithms, void* data ) {
+    _Mesh_Algorithms_Build( algorithms, data );
+}
+
+void _Mesh_RegularAlgorithms_Initialise( void* algorithms, void* data ) {
+    _Mesh_Algorithms_Initialise( algorithms, data );
+}
+
+void _Mesh_RegularAlgorithms_Execute( void* algorithms, void* data ) {
+    _Mesh_Algorithms_Execute( algorithms, data );
+}
+
+void _Mesh_RegularAlgorithms_Destroy( void* algorithms, void* data ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+
+	Mesh_RegularAlgorithms_Destruct( self );
+
+   _Mesh_Algorithms_Destroy( algorithms, data );
+}
+
+void Mesh_RegularAlgorithms_SetMesh( void* algorithms, void* mesh ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+
+	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
+
+	Mesh_RegularAlgorithms_Destruct( self );
+	_Mesh_Algorithms_SetMesh( self, mesh );
+}
+
+void Mesh_RegularAlgorithms_Update( void* algorithms ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	unsigned		nDims, ii;
+	Grid*			eGrid;
+
+	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
+	assert( self->mesh );
+
+	Mesh_RegularAlgorithms_Destruct( self );
+	_Mesh_Algorithms_Update( self );
+
+	nDims = Mesh_GetDimSize( self->mesh );
+	self->minCrd = AllocArray( double, nDims );
+	self->maxCrd = AllocArray( double, nDims );
+	Mesh_GetGlobalCoordRange( self->mesh, self->minCrd, self->maxCrd );
+
+	self->sep = AllocArray( double, nDims );
+	eGrid = *Mesh_GetExtension( self->mesh, Grid**, "elementGrid" );
+	for( ii = 0; ii < nDims; ii++ )
+		self->sep[ii] = (self->maxCrd[ii] - self->minCrd[ii]) / eGrid->sizes[ii];
+}
+
+Bool _Mesh_RegularAlgorithms_Search( void* algorithms, void* _mesh, double* point, 
+				     MeshTopology_Dim* dim, unsigned* ind )
+{
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	Mesh*			mesh = (Mesh*)_mesh;
+
+	assert( self );
+	assert( mesh );
+	assert( dim );
+	assert( ind );
+
+	/* TODO */
+	abort();
+
+	return False;
+}
+
+Bool Mesh_RegularAlgorithms_SearchElements( void* algorithms, double* point, unsigned* elInd ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	Mesh*			mesh;
+	unsigned		nDims;
+	unsigned		inds[3];
+	Grid			*elGrid;
+	double			out, frac, integer;
+	unsigned		d_i;
+
+	assert( self );
+	assert( Mesh_GetDimSize( self->mesh ) <= 3 );
+	assert( elInd );
+
+	mesh = self->mesh;
+	nDims = Mesh_GetDimSize( mesh );
+	elGrid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+						ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" ) );
+	for( d_i = 0; d_i < nDims; d_i++  ) {
+		if( Num_Approx( point[d_i] - self->maxCrd[d_i], 0.0 ) )
+			inds[d_i] = elGrid->sizes[d_i] - 1;
+		else if( point[d_i] < self->minCrd[d_i] || point[d_i] > self->maxCrd[d_i] )
+			return False;
+		else {
+			out = (point[d_i] - self->minCrd[d_i]) / self->sep[d_i];
+			frac = modf( out, &integer );
+			inds[d_i] = (unsigned)integer;
+			if( inds[d_i] > 0 && Num_Approx( frac, 0.0 ) )
+				inds[d_i]--;
+		}
+	}
+
+	*elInd = Grid_Project( elGrid, inds );
+	return Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,*elInd,elInd);
+}
+
+double _Mesh_RegularAlgorithms_GetMinimumSeparation( void* algorithms, void* _mesh, double* perDim ) {
+	Mesh* mesh;
+
+	mesh = (Mesh*)_mesh;
+
+	/* TODO */
+	abort();
+
+	return 0.0;
+}
+
+void _Mesh_RegularAlgorithms_GetLocalCoordRange( void* algorithms, void* _mesh, double* min, double* max ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	Mesh*			mesh = (Mesh*)_mesh;
+
+	assert( self );
+	assert( mesh );
+	assert( min );
+	assert( max );
+
+	/* TODO */
+	abort();
+}
+
+void _Mesh_RegularAlgorithms_GetDomainCoordRange( void* algorithms, void* _mesh, double* min, double* max ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	Mesh*			mesh = (Mesh*)_mesh;
+
+	assert( self );
+	assert( mesh );
+	assert( min );
+	assert( max );
+
+	/* TODO */
+	abort();
+}
+
+void _Mesh_RegularAlgorithms_GetGlobalCoordRange( void* algorithms, void* _mesh, double* min, double* max ) {
+	Mesh_RegularAlgorithms*	self = (Mesh_RegularAlgorithms*)algorithms;
+	Mesh*			mesh = (Mesh*)_mesh;
+
+	assert( self );
+	assert( mesh );
+	assert( min );
+	assert( max );
+
+	/* TODO */
+	abort();
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void Mesh_RegularAlgorithms_Destruct( Mesh_RegularAlgorithms* self ) {
+	assert( self && Stg_CheckType( self, Mesh_RegularAlgorithms ) );
+
+	KillArray( self->sep );
+	KillArray( self->minCrd );
+	KillArray( self->maxCrd );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Remesher.c
--- a/Mesh/src/Remesher.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd,
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Remesher.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "Remesher.h"
-
-
-/* Textual name of this class */
-const Type Remesher_Type = "Remesher";
-
-/* Constructors */
-
-Remesher* _Remesher_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Remesher);
-	Type                                                      type = Remesher_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Remesher_Delete;
-	Stg_Class_PrintFunction*                                _print = _Remesher_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void*(*)(Name))_Remesher_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Remesher_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Remesher_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Remesher_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Remesher_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Remesher_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	Remesher_RemeshFunc*                                remeshFunc = NULL;
-
-   return _Remesher_New(  REMESHER_PASSARGS  );
-}
-
-Remesher* _Remesher_New(  REMESHER_DEFARGS  ) {
-   Remesher* self;
-
-   /* Allocate memory. */
-   self = (Remesher*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-   /* Virtual functions. */
-   self->remeshFunc = remeshFunc;
-
-   return self;
-}
-
-void _Remesher_Init( void* remesher, AbstractContext* context, Mesh* mesh ) {
-   Remesher*	self = (Remesher*)remesher;
-
-   /* Remesher info */
-	self->context = context;
-   self->mesh = mesh;
-}
-
-/* Virtual functions */
-
-void _Remesher_Delete( void* remesher ) {
-   Remesher*	self = (Remesher*)remesher;
-
-   /* Delete the class itself */
-
-   /* Delete parent */
-   _Stg_Component_Delete( self );
-}
-
-void _Remesher_Print( void* remesher, Stream* stream ) {
-   Remesher*	self = (Remesher*)remesher;
-   Stream*		myStream;
-	
-   /* Set the Journal for printing informations */
-   myStream = Journal_Register( InfoStream_Type, (Name)"RemesherStream"  );
-
-   /* Print parent */
-   _Stg_Component_Print( self, stream );
-
-   /* General info */
-   Journal_Printf( myStream, "Remesher (ptr): (%p)\n", self );
-
-   /* Virtual info */
-
-   /* Remesher info */
-}
-
-void _Remesher_AssignFromXML( void* remesher, Stg_ComponentFactory* cf, void* data ) {
-   Remesher*			self = (Remesher*)remesher;
-	AbstractContext*	context;
-	Mesh*					mesh;
-
-   assert( self );
-   assert( cf );
-   assert( cf->componentDict );
-
-   context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-   if( !context  )
-      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-   mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
-
-	_Remesher_Init ( self, context, mesh );
-}
-
-void _Remesher_Build( void* remesher, void* data ) {
-   Remesher*	self = (Remesher*)remesher;
-
-   assert( self );
-   assert( self->mesh );
-
-   Stg_Component_Build( (void*)(self->remeshFunc), data, False );   
-   Stg_Component_Build( self->mesh, data, False );   
-}
-
-void _Remesher_Initialise( void* remesher, void* data ) {
-   Remesher*	self = (Remesher*)remesher;
-
-   assert( self );
-
-   Stg_Component_Initialise( (void*)(self->remeshFunc), data, False );   
-   Stg_Component_Initialise( self->mesh, data, False );   
-}
-
-void _Remesher_Execute( void* remesher, void* data ) {
-   Remesher*	self = (Remesher*)remesher;
-
-
-   assert( self );
-}
-
-void _Remesher_Destroy( void* remesher, void* data ) {
-   Remesher*	self = (Remesher*)remesher;
-
-   assert( self );
-
-   Stg_Component_Destroy( (void*)(self->remeshFunc), data, False );   
-}
-
-/* Public Functions */
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Remesher.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Remesher.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,175 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd,
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Remesher.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "Remesher.h"
+
+
+/* Textual name of this class */
+const Type Remesher_Type = "Remesher";
+
+/* Constructors */
+
+Remesher* _Remesher_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Remesher);
+	Type                                                      type = Remesher_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Remesher_Delete;
+	Stg_Class_PrintFunction*                                _print = _Remesher_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void*(*)(Name))_Remesher_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Remesher_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Remesher_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Remesher_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Remesher_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Remesher_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	Remesher_RemeshFunc*                                remeshFunc = NULL;
+
+   return _Remesher_New(  REMESHER_PASSARGS  );
+}
+
+Remesher* _Remesher_New(  REMESHER_DEFARGS  ) {
+   Remesher* self;
+
+   /* Allocate memory. */
+   self = (Remesher*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+   /* Virtual functions. */
+   self->remeshFunc = remeshFunc;
+
+   return self;
+}
+
+void _Remesher_Init( void* remesher, AbstractContext* context, Mesh* mesh ) {
+   Remesher*	self = (Remesher*)remesher;
+
+   /* Remesher info */
+	self->context = context;
+   self->mesh = mesh;
+}
+
+/* Virtual functions */
+
+void _Remesher_Delete( void* remesher ) {
+   Remesher*	self = (Remesher*)remesher;
+
+   /* Delete the class itself */
+
+   /* Delete parent */
+   _Stg_Component_Delete( self );
+}
+
+void _Remesher_Print( void* remesher, Stream* stream ) {
+   Remesher*	self = (Remesher*)remesher;
+   Stream*		myStream;
+	
+   /* Set the Journal for printing informations */
+   myStream = Journal_Register( InfoStream_Type, (Name)"RemesherStream"  );
+
+   /* Print parent */
+   _Stg_Component_Print( self, stream );
+
+   /* General info */
+   Journal_Printf( myStream, "Remesher (ptr): (%p)\n", self );
+
+   /* Virtual info */
+
+   /* Remesher info */
+}
+
+void _Remesher_AssignFromXML( void* remesher, Stg_ComponentFactory* cf, void* data ) {
+   Remesher*			self = (Remesher*)remesher;
+	AbstractContext*	context;
+	Mesh*					mesh;
+
+   assert( self );
+   assert( cf );
+   assert( cf->componentDict );
+
+   context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+   if( !context  )
+      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+   mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
+
+	_Remesher_Init ( self, context, mesh );
+}
+
+void _Remesher_Build( void* remesher, void* data ) {
+   Remesher*	self = (Remesher*)remesher;
+
+   assert( self );
+   assert( self->mesh );
+
+   Stg_Component_Build( (void*)(self->remeshFunc), data, False );   
+   Stg_Component_Build( self->mesh, data, False );   
+}
+
+void _Remesher_Initialise( void* remesher, void* data ) {
+   Remesher*	self = (Remesher*)remesher;
+
+   assert( self );
+
+   Stg_Component_Initialise( (void*)(self->remeshFunc), data, False );   
+   Stg_Component_Initialise( self->mesh, data, False );   
+}
+
+void _Remesher_Execute( void* remesher, void* data ) {
+   Remesher*	self = (Remesher*)remesher;
+
+
+   assert( self );
+}
+
+void _Remesher_Destroy( void* remesher, void* data ) {
+   Remesher*	self = (Remesher*)remesher;
+
+   assert( self );
+
+   Stg_Component_Destroy( (void*)(self->remeshFunc), data, False );   
+}
+
+/* Public Functions */
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/SpatialTree.c
--- a/Mesh/src/SpatialTree.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,353 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SpatialTree.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <StGermain/StGermain.h>
-#include "types.h"
-#include "Mesh.h"
-#include "SpatialTree.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-#define GETNODECHILDREN( tree, node )		\
-  ((void**)(node))
-
-#define GETNODEORIGIN( tree, node )		\
-   ((double*)((stgByte*)(node) +		\
-	      (tree)->nChld * sizeof(void*)))
-
-#define SETNODEVERTS( tree, node, nVerts, verts )		\
-   ((int*)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
-	   (tree)->nDims * sizeof(double)))[0] = (nVerts);	\
-   ((int**)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
-	    (tree)->nDims * sizeof(double) +			\
-	    sizeof(int)))[0] = (verts)
-
-#define GETNODEVERTARRAY( tree, node )				\
-   ((int**)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
-	    (tree)->nDims * sizeof(double) +			\
-	    sizeof(int)))[0]
-
-#define GETNODENUMVERTS( tree, node )				\
-   ((int*)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
-	   (tree)->nDims * sizeof(double)))[0]
-
-
-void SpatialTree_DestroyNode( SpatialTree* self, void* node );
-void SpatialTree_SplitSet( SpatialTree* self, double* orig,
-			   int nVerts, int* verts, 
-			   int* subSizes, int** subSets,
-			   Bool store );
-void SpatialTree_SplitNode( SpatialTree* self, void* node, void** parent,
-			    double* min, double* max,
-			    int nVerts, int* verts );
-void SpatialTree_BuildElements( SpatialTree* self, int nVerts, int* verts, 
-				int* nEls, int** els );
-void SpatialTree_SearchNode( SpatialTree* self, void* node, 
-			     const double* pnt, int* nEls, int** els );
-
-
-void _SpatialTree_Init( void* _self ) {
-   SpatialTree* self = Class_Cast( _self, SpatialTree );
-
-   _NewClass_Init( self );
-   self->mesh = NULL;
-   self->nDims = 0;
-   self->min = NULL;
-   self->max = NULL;
-   self->root = NULL;
-   self->tol = 10;
-   self->nNodes = 0;
-}
-
-void _SpatialTree_Destruct( void* _self ) {
-   SpatialTree* self = Class_Cast( _self, SpatialTree );
-
-   if( self->root )
-      SpatialTree_DestroyNode( self, self->root );
-   _NewClass_Destruct( self );
-}
-
-void _SpatialTree_Copy( void* _self, const void* _op ) {
-   /*SpatialTree* self = Class_Cast( _self, SpatialTree );*/
-   /*const SpatialTree* op = Class_ConstCast( _op, SpatialTree );*/
-
-   abort();
-}
-
-void SpatialTree_SetMesh( void* _self, void* mesh ) {
-   SpatialTree* self = Class_Cast( _self, SpatialTree );
-
-   SpatialTree_Clear( self );
-   self->mesh = (Mesh*)mesh;
-}
-
-void SpatialTree_Rebuild( void* _self ) {
-   SpatialTree* self = Class_Cast( _self, SpatialTree );
-   int nVerts, *verts;
-   int ii;
-
-   if( !self->mesh )
-      return;
-
-   SpatialTree_Clear( self );
-   self->nDims = Mesh_GetDimSize( self->mesh );
-   self->nChld = 2;
-   for( ii = 1; ii < self->nDims; ii++ )
-      self->nChld *= 2;
-
-   self->min = Class_Array( self, double, self->nDims );
-   self->max = Class_Array( self, double, self->nDims );
-
-   Mesh_GetDomainCoordRange( self->mesh, self->min, self->max );
-   nVerts = Mesh_GetDomainSize( self->mesh, (MeshTopology_Dim)0 );
-   verts = Class_Array( self, int, nVerts );
-   for( ii = 0; ii < nVerts; ii++ )
-      verts[ii] = ii;
-   self->root = Class_Array( self, stgByte, self->nChld * sizeof(void*) + 
-			     self->nDims * sizeof(double) );
-   SpatialTree_SplitNode( self, self->root, &self->root,
-			  self->min, self->max, nVerts, verts );
-}
-
-Bool SpatialTree_Search( void* _self, const double* pnt, int* nEls, int** els ) {
-   SpatialTree* self = Class_Cast( _self, SpatialTree );
-   int ii;
-
-   for( ii = 0; ii < self->nDims; ii++ ) {
-      if( pnt[ii] < self->min[ii] || pnt[ii] > self->max[ii] )
-	 return False;
-   }
-
-   SpatialTree_SearchNode( self, self->root, pnt, nEls, els );
-   return True;
-}
-
-void SpatialTree_Clear( void* _self ) {
-   SpatialTree* self = Class_Cast( _self, SpatialTree );
-
-   if( self->root ) {
-      SpatialTree_DestroyNode( self, self->root );
-      self->root = NULL;
-      self->nNodes = 0;
-   }
-
-
-   Class_Free( self, self->min ); self->min = NULL;
-   Class_Free( self, self->max ); self->max = NULL;
-}
-
-void SpatialTree_SplitNode( SpatialTree* self, void* node, void** parent,
-			    double* min, double* max,
-			    int nVerts, int* verts )
-{
-   int ii;
-
-   for( ii = 0; ii < self->nDims; ii++ )
-      GETNODEORIGIN( self, node )[ii] = min[ii] + (max[ii] - min[ii]) * 0.5;
-
-   if( nVerts <= self->tol ) {
-      int nEls, *els;
-
-      node = (void*)Class_Rearray( self, node, stgByte,
-				   self->nChld * sizeof(void*) + 
-				   self->nDims * sizeof(double) + 
-				   sizeof(int) + sizeof(int*) );
-      *parent = node;
-      memset( node, 0, self->nChld * sizeof(void*) );
-
-      SpatialTree_BuildElements( self, nVerts, verts, 
-				 &nEls, &els );
-      Class_Free( self, verts );
-      SETNODEVERTS( self, node, nEls, els );
-   }
-   else {
-      void *newNode, *newNodePtr;
-      int* subSizes;
-      int** subSets;
-      double *subMin, *subMax;
-      int jj;
-
-      for( ii = 0; ii < self->nChld; ii++ ) {
-	 newNode = Class_Array( self, stgByte, self->nChld * sizeof(void*) + 
-				self->nDims * sizeof(double) );
-	 GETNODECHILDREN( self, node )[ii] = newNode;
-      }
-
-      subSizes = Class_Array( self, int, self->nChld );
-      SpatialTree_SplitSet( self, GETNODEORIGIN( self, node ),
-			    nVerts, verts, subSizes, NULL, False );
-
-      subSets = Class_Array( self, int*, self->nChld );
-      for( ii = 0; ii < self->nChld; ii++ )
-	 subSets[ii] = Class_Array( self, int, subSizes[ii] );
-      SpatialTree_SplitSet( self, GETNODEORIGIN( self, node ),
-			    nVerts, verts, subSizes, subSets, True );
-
-      Class_Free( self, verts );
-
-      subMin = Class_Array( self, double, self->nDims );
-      subMax = Class_Array( self, double, self->nDims );
-
-      for( ii = 0; ii < self->nChld; ii++ ) {
-	 for( jj = 0; jj < self->nDims; jj++ ) {
-	    if( ii & (1 << jj) ) {
-	       subMin[jj] = GETNODEORIGIN( self, node )[jj];
-	       subMax[jj] = max[jj];
-	    }
-	    else {
-	       subMin[jj] = min[jj];
-	       subMax[jj] = GETNODEORIGIN( self, node )[jj];
-	    }
-	 }
-
-	 newNode = GETNODECHILDREN( self, node )[ii];
-	 newNodePtr = GETNODECHILDREN( self, node ) + ii;
-	 SpatialTree_SplitNode( self, newNode, (void**)newNodePtr, subMin, subMax,
-				subSizes[ii], subSets[ii] );
-      }
-
-      Class_Free( self, subMin );
-      Class_Free( self, subMax );
-   }
-}
-
-void SpatialTree_SplitSet( SpatialTree* self, double* orig,
-			   int nVerts, int* verts, 
-			   int* subSizes, int** subSets,
-			   Bool store )
-{
-   double* crd;
-   int code;
-   int ii, jj;
-
-   memset( subSizes, 0, self->nChld * sizeof(int) );
-   for( ii = 0; ii < nVerts; ii++ ) {
-      crd = Mesh_GetVertex( self->mesh, verts[ii] );
-      code = 0;
-      for( jj = 0; jj < self->nDims; jj++ ) {
-	 if( crd[jj] > orig[jj] )
-	    code |= 1 << jj;
-      }
-
-      if( store )
-	 subSets[code][subSizes[code]++] = verts[ii];
-      else
-	 subSizes[code]++;
-   }
-}
-
-void SpatialTree_BuildElements( SpatialTree* self, int nVerts, int* verts, 
-				int* nEls, int** els )
-{
-   int maxEls, *curEls;
-   IArray* inc;
-   int nIncEls, *incEls;
-   int ii, jj, kk;
-
-   maxEls = 0;
-   for( ii = 0; ii < nVerts; ii++ )
-      maxEls += Mesh_GetIncidenceSize(self->mesh,(MeshTopology_Dim)0,
-                                      verts[ii],(MeshTopology_Dim)(self->nDims));
-
-   curEls = Class_Array( self, int, maxEls );
-
-   inc = IArray_New();
-   maxEls = 0;
-   for( ii = 0; ii < nVerts; ii++ ) {
-      Mesh_GetIncidence(self->mesh,(MeshTopology_Dim)0,verts[ii],
-                        (MeshTopology_Dim)(self->nDims),inc);
-      nIncEls = IArray_GetSize( inc );
-      incEls = IArray_GetPtr( inc );
-      for( jj = 0; jj < nIncEls; jj++ ) {
-	 for( kk = 0; kk < maxEls; kk++ ) {
-	    if( curEls[kk] == incEls[jj] )
-	       break;
-	 }
-	 if( kk == maxEls )
-	    curEls[maxEls++] = incEls[jj];
-      }
-   }
-   NewClass_Delete( inc );
-
-   *nEls = maxEls;
-   *els = Class_Rearray( self, curEls, int, maxEls );
-}
-
-void SpatialTree_SearchNode( SpatialTree* self, void* node, 
-			     const double* pnt, int* nEls, int** els )
-{
-   if( GETNODECHILDREN( self, node )[0] == NULL ) {
-      *nEls = GETNODENUMVERTS( self, node );
-      *els = GETNODEVERTARRAY( self, node );
-   }
-   else {
-      double* orig;
-      int code;
-      int ii;
-
-      orig = GETNODEORIGIN( self, node );
-      code = 0;
-      for( ii = 0; ii < self->nDims; ii++ ) {
-	 if( pnt[ii] > orig[ii] )
-	    code |= 1 << ii;
-      }
-
-      SpatialTree_SearchNode( self, GETNODECHILDREN( self, node )[code], 
-			      pnt, nEls, els );
-   }
-}
-
-void SpatialTree_DestroyNode( SpatialTree* self, void* node ) {
-   Bool leaf;
-   int ii;
-
-   if( !node )
-      return;
-
-   leaf = True;
-   for( ii = 0; ii < self->nChld; ii++ ) {
-      if( GETNODECHILDREN( self, node )[ii] )
-	 leaf = False;
-      SpatialTree_DestroyNode( self, GETNODECHILDREN( self, node )[ii] );
-   }
-
-   if( leaf ) {
-      Class_Free( self, GETNODEVERTARRAY( self, node ) );
-   }
-
-   Class_Free( self, node );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/SpatialTree.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/SpatialTree.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,353 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SpatialTree.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <StGermain/StGermain.h>
+#include "types.h"
+#include "Mesh.h"
+#include "SpatialTree.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+#define GETNODECHILDREN( tree, node )		\
+  ((void**)(node))
+
+#define GETNODEORIGIN( tree, node )		\
+   ((double*)((stgByte*)(node) +		\
+	      (tree)->nChld * sizeof(void*)))
+
+#define SETNODEVERTS( tree, node, nVerts, verts )		\
+   ((int*)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
+	   (tree)->nDims * sizeof(double)))[0] = (nVerts);	\
+   ((int**)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
+	    (tree)->nDims * sizeof(double) +			\
+	    sizeof(int)))[0] = (verts)
+
+#define GETNODEVERTARRAY( tree, node )				\
+   ((int**)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
+	    (tree)->nDims * sizeof(double) +			\
+	    sizeof(int)))[0]
+
+#define GETNODENUMVERTS( tree, node )				\
+   ((int*)((stgByte*)(node) + (tree)->nChld * sizeof(void*) +	\
+	   (tree)->nDims * sizeof(double)))[0]
+
+
+void SpatialTree_DestroyNode( SpatialTree* self, void* node );
+void SpatialTree_SplitSet( SpatialTree* self, double* orig,
+			   int nVerts, int* verts, 
+			   int* subSizes, int** subSets,
+			   Bool store );
+void SpatialTree_SplitNode( SpatialTree* self, void* node, void** parent,
+			    double* min, double* max,
+			    int nVerts, int* verts );
+void SpatialTree_BuildElements( SpatialTree* self, int nVerts, int* verts, 
+				int* nEls, int** els );
+void SpatialTree_SearchNode( SpatialTree* self, void* node, 
+			     const double* pnt, int* nEls, int** els );
+
+
+void _SpatialTree_Init( void* _self ) {
+   SpatialTree* self = Class_Cast( _self, SpatialTree );
+
+   _NewClass_Init( self );
+   self->mesh = NULL;
+   self->nDims = 0;
+   self->min = NULL;
+   self->max = NULL;
+   self->root = NULL;
+   self->tol = 10;
+   self->nNodes = 0;
+}
+
+void _SpatialTree_Destruct( void* _self ) {
+   SpatialTree* self = Class_Cast( _self, SpatialTree );
+
+   if( self->root )
+      SpatialTree_DestroyNode( self, self->root );
+   _NewClass_Destruct( self );
+}
+
+void _SpatialTree_Copy( void* _self, const void* _op ) {
+   /*SpatialTree* self = Class_Cast( _self, SpatialTree );*/
+   /*const SpatialTree* op = Class_ConstCast( _op, SpatialTree );*/
+
+   abort();
+}
+
+void SpatialTree_SetMesh( void* _self, void* mesh ) {
+   SpatialTree* self = Class_Cast( _self, SpatialTree );
+
+   SpatialTree_Clear( self );
+   self->mesh = (Mesh*)mesh;
+}
+
+void SpatialTree_Rebuild( void* _self ) {
+   SpatialTree* self = Class_Cast( _self, SpatialTree );
+   int nVerts, *verts;
+   int ii;
+
+   if( !self->mesh )
+      return;
+
+   SpatialTree_Clear( self );
+   self->nDims = Mesh_GetDimSize( self->mesh );
+   self->nChld = 2;
+   for( ii = 1; ii < self->nDims; ii++ )
+      self->nChld *= 2;
+
+   self->min = Class_Array( self, double, self->nDims );
+   self->max = Class_Array( self, double, self->nDims );
+
+   Mesh_GetDomainCoordRange( self->mesh, self->min, self->max );
+   nVerts = Mesh_GetDomainSize( self->mesh, (MeshTopology_Dim)0 );
+   verts = Class_Array( self, int, nVerts );
+   for( ii = 0; ii < nVerts; ii++ )
+      verts[ii] = ii;
+   self->root = Class_Array( self, stgByte, self->nChld * sizeof(void*) + 
+			     self->nDims * sizeof(double) );
+   SpatialTree_SplitNode( self, self->root, &self->root,
+			  self->min, self->max, nVerts, verts );
+}
+
+Bool SpatialTree_Search( void* _self, const double* pnt, int* nEls, int** els ) {
+   SpatialTree* self = Class_Cast( _self, SpatialTree );
+   int ii;
+
+   for( ii = 0; ii < self->nDims; ii++ ) {
+      if( pnt[ii] < self->min[ii] || pnt[ii] > self->max[ii] )
+	 return False;
+   }
+
+   SpatialTree_SearchNode( self, self->root, pnt, nEls, els );
+   return True;
+}
+
+void SpatialTree_Clear( void* _self ) {
+   SpatialTree* self = Class_Cast( _self, SpatialTree );
+
+   if( self->root ) {
+      SpatialTree_DestroyNode( self, self->root );
+      self->root = NULL;
+      self->nNodes = 0;
+   }
+
+
+   Class_Free( self, self->min ); self->min = NULL;
+   Class_Free( self, self->max ); self->max = NULL;
+}
+
+void SpatialTree_SplitNode( SpatialTree* self, void* node, void** parent,
+			    double* min, double* max,
+			    int nVerts, int* verts )
+{
+   int ii;
+
+   for( ii = 0; ii < self->nDims; ii++ )
+      GETNODEORIGIN( self, node )[ii] = min[ii] + (max[ii] - min[ii]) * 0.5;
+
+   if( nVerts <= self->tol ) {
+      int nEls, *els;
+
+      node = (void*)Class_Rearray( self, node, stgByte,
+				   self->nChld * sizeof(void*) + 
+				   self->nDims * sizeof(double) + 
+				   sizeof(int) + sizeof(int*) );
+      *parent = node;
+      memset( node, 0, self->nChld * sizeof(void*) );
+
+      SpatialTree_BuildElements( self, nVerts, verts, 
+				 &nEls, &els );
+      Class_Free( self, verts );
+      SETNODEVERTS( self, node, nEls, els );
+   }
+   else {
+      void *newNode, *newNodePtr;
+      int* subSizes;
+      int** subSets;
+      double *subMin, *subMax;
+      int jj;
+
+      for( ii = 0; ii < self->nChld; ii++ ) {
+	 newNode = Class_Array( self, stgByte, self->nChld * sizeof(void*) + 
+				self->nDims * sizeof(double) );
+	 GETNODECHILDREN( self, node )[ii] = newNode;
+      }
+
+      subSizes = Class_Array( self, int, self->nChld );
+      SpatialTree_SplitSet( self, GETNODEORIGIN( self, node ),
+			    nVerts, verts, subSizes, NULL, False );
+
+      subSets = Class_Array( self, int*, self->nChld );
+      for( ii = 0; ii < self->nChld; ii++ )
+	 subSets[ii] = Class_Array( self, int, subSizes[ii] );
+      SpatialTree_SplitSet( self, GETNODEORIGIN( self, node ),
+			    nVerts, verts, subSizes, subSets, True );
+
+      Class_Free( self, verts );
+
+      subMin = Class_Array( self, double, self->nDims );
+      subMax = Class_Array( self, double, self->nDims );
+
+      for( ii = 0; ii < self->nChld; ii++ ) {
+	 for( jj = 0; jj < self->nDims; jj++ ) {
+	    if( ii & (1 << jj) ) {
+	       subMin[jj] = GETNODEORIGIN( self, node )[jj];
+	       subMax[jj] = max[jj];
+	    }
+	    else {
+	       subMin[jj] = min[jj];
+	       subMax[jj] = GETNODEORIGIN( self, node )[jj];
+	    }
+	 }
+
+	 newNode = GETNODECHILDREN( self, node )[ii];
+	 newNodePtr = GETNODECHILDREN( self, node ) + ii;
+	 SpatialTree_SplitNode( self, newNode, (void**)newNodePtr, subMin, subMax,
+				subSizes[ii], subSets[ii] );
+      }
+
+      Class_Free( self, subMin );
+      Class_Free( self, subMax );
+   }
+}
+
+void SpatialTree_SplitSet( SpatialTree* self, double* orig,
+			   int nVerts, int* verts, 
+			   int* subSizes, int** subSets,
+			   Bool store )
+{
+   double* crd;
+   int code;
+   int ii, jj;
+
+   memset( subSizes, 0, self->nChld * sizeof(int) );
+   for( ii = 0; ii < nVerts; ii++ ) {
+      crd = Mesh_GetVertex( self->mesh, verts[ii] );
+      code = 0;
+      for( jj = 0; jj < self->nDims; jj++ ) {
+	 if( crd[jj] > orig[jj] )
+	    code |= 1 << jj;
+      }
+
+      if( store )
+	 subSets[code][subSizes[code]++] = verts[ii];
+      else
+	 subSizes[code]++;
+   }
+}
+
+void SpatialTree_BuildElements( SpatialTree* self, int nVerts, int* verts, 
+				int* nEls, int** els )
+{
+   int maxEls, *curEls;
+   IArray* inc;
+   int nIncEls, *incEls;
+   int ii, jj, kk;
+
+   maxEls = 0;
+   for( ii = 0; ii < nVerts; ii++ )
+      maxEls += Mesh_GetIncidenceSize(self->mesh,(MeshTopology_Dim)0,
+                                      verts[ii],(MeshTopology_Dim)(self->nDims));
+
+   curEls = Class_Array( self, int, maxEls );
+
+   inc = IArray_New();
+   maxEls = 0;
+   for( ii = 0; ii < nVerts; ii++ ) {
+      Mesh_GetIncidence(self->mesh,(MeshTopology_Dim)0,verts[ii],
+                        (MeshTopology_Dim)(self->nDims),inc);
+      nIncEls = IArray_GetSize( inc );
+      incEls = IArray_GetPtr( inc );
+      for( jj = 0; jj < nIncEls; jj++ ) {
+	 for( kk = 0; kk < maxEls; kk++ ) {
+	    if( curEls[kk] == incEls[jj] )
+	       break;
+	 }
+	 if( kk == maxEls )
+	    curEls[maxEls++] = incEls[jj];
+      }
+   }
+   NewClass_Delete( inc );
+
+   *nEls = maxEls;
+   *els = Class_Rearray( self, curEls, int, maxEls );
+}
+
+void SpatialTree_SearchNode( SpatialTree* self, void* node, 
+			     const double* pnt, int* nEls, int** els )
+{
+   if( GETNODECHILDREN( self, node )[0] == NULL ) {
+      *nEls = GETNODENUMVERTS( self, node );
+      *els = GETNODEVERTARRAY( self, node );
+   }
+   else {
+      double* orig;
+      int code;
+      int ii;
+
+      orig = GETNODEORIGIN( self, node );
+      code = 0;
+      for( ii = 0; ii < self->nDims; ii++ ) {
+	 if( pnt[ii] > orig[ii] )
+	    code |= 1 << ii;
+      }
+
+      SpatialTree_SearchNode( self, GETNODECHILDREN( self, node )[code], 
+			      pnt, nEls, els );
+   }
+}
+
+void SpatialTree_DestroyNode( SpatialTree* self, void* node ) {
+   Bool leaf;
+   int ii;
+
+   if( !node )
+      return;
+
+   leaf = True;
+   for( ii = 0; ii < self->nChld; ii++ ) {
+      if( GETNODECHILDREN( self, node )[ii] )
+	 leaf = False;
+      SpatialTree_DestroyNode( self, GETNODECHILDREN( self, node )[ii] );
+   }
+
+   if( leaf ) {
+      Class_Free( self, GETNODEVERTARRAY( self, node ) );
+   }
+
+   Class_Free( self, node );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/SurfaceAdaptor.c
--- a/Mesh/src/SurfaceAdaptor.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,710 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SurfaceAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Grid.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "IGraph.h"
-#include "MeshClass.h"
-#include "MeshGenerator.h"
-#include "MeshAdaptor.h"
-#include "SurfaceAdaptor.h"
-#include "Remesher.h"
-
-/* Textual name of this class */
-const Type SurfaceAdaptor_Type = "SurfaceAdaptor";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-SurfaceAdaptor* SurfaceAdaptor_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(SurfaceAdaptor);
-	Type                                                      type = SurfaceAdaptor_Type;
-	Stg_Class_DeleteFunction*                              _delete = _SurfaceAdaptor_Delete;
-	Stg_Class_PrintFunction*                                _print = _SurfaceAdaptor_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_SurfaceAdaptor_New;
-	Stg_Component_ConstructFunction*                    _construct = _SurfaceAdaptor_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _SurfaceAdaptor_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _SurfaceAdaptor_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _SurfaceAdaptor_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _SurfaceAdaptor_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	MeshGenerator_SetDimSizeFunc*                   setDimSizeFunc = _MeshGenerator_SetDimSize;
-	MeshGenerator_GenerateFunc*                       generateFunc = SurfaceAdaptor_Generate;
-
-	SurfaceAdaptor* self = _SurfaceAdaptor_New(  SURFACEADAPTOR_PASSARGS  );
-
-   _MeshGenerator_Init( (MeshGenerator*)self, context );
-   _MeshAdaptor_Init( (MeshAdaptor*)self );
-	_SurfaceAdaptor_Init( self );
-
-   return self;
-}
-
-SurfaceAdaptor* _SurfaceAdaptor_New(  SURFACEADAPTOR_DEFARGS  ) {
-	SurfaceAdaptor* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SurfaceAdaptor) );
-	self = (SurfaceAdaptor*)_MeshAdaptor_New(  MESHADAPTOR_PASSARGS  );
-
-	/* Virtual info */
-	return self;
-}
-
-void _SurfaceAdaptor_Init( SurfaceAdaptor* self ) {
-	self->topSurfaceType = SurfaceAdaptor_SurfaceType_Invalid;
-	self->bottomSurfaceType = SurfaceAdaptor_SurfaceType_Invalid;
-	memset( &self->top_info, 0, sizeof(SurfaceAdaptor_SurfaceInfo ));
-	memset( &self->bottom_info, 0, sizeof(SurfaceAdaptor_SurfaceInfo));
-        self->topDeformFunc=self->bottomDeformFunc=NULL;
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _SurfaceAdaptor_Delete( void* adaptor ) {
-	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
-
-	/* Delete the parent. */
-	_MeshAdaptor_Delete( self );
-}
-
-void _SurfaceAdaptor_Print( void* adaptor, Stream* stream ) {
-	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
-	
-	/* Set the Journal for printing informations */
-	Stream* adaptorStream;
-	adaptorStream = Journal_Register( InfoStream_Type, (Name)"SurfaceAdaptorStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "SurfaceAdaptor (ptr): (%p)\n", self );
-	_MeshAdaptor_Print( self, stream );
-}
-
-void _SurfaceAdaptor_AssignFromXML_Surface(Stg_ComponentFactory* cf,
-                                           Name name,
-                                           SurfaceAdaptor_SurfaceType *surfaceType,
-                                           Dictionary* dict,
-                                           SurfaceAdaptor_SurfaceInfo *info,
-                                           SurfaceAdaptor_DeformFunc **deformFunc,
-                                           char *surface);
-
-void _SurfaceAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
-	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
-	Dictionary*	dict;
-
-	assert( self );
-	assert( cf );
-
-	/* Call parent construct. */
-	_MeshAdaptor_AssignFromXML( self, cf, data );
-
-	/* Rip out the components structure as a dictionary. */
-	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
-
-        self->topDeformFunc=self->bottomDeformFunc=NULL;
-        char surface[100];
-        _SurfaceAdaptor_AssignFromXML_Surface(cf,self->name,
-                                              &(self->topSurfaceType),
-                                              dict,
-                                              &(self->top_info),
-                                              &(self->topDeformFunc),
-                                              strcpy(surface,"top"));
-        _SurfaceAdaptor_AssignFromXML_Surface(cf,self->name,
-                                              &(self->bottomSurfaceType),
-                                              dict,
-                                              &(self->bottom_info),
-                                              &(self->bottomDeformFunc),
-                                              strcpy(surface,"bottom"));
-}
-
-void _SurfaceAdaptor_AssignFromXML_Surface(Stg_ComponentFactory* cf,
-                                           Name name,
-                                           SurfaceAdaptor_SurfaceType *surfaceType,
-                                           Dictionary* dict,
-                                           SurfaceAdaptor_SurfaceInfo *info,
-                                           SurfaceAdaptor_DeformFunc **deformFunc,
-                                           char *surface)
-{
-  char temp[100];
-  char *surfaceName;
-  strcpy(temp,surface);
-  /* What kind of surface do we want? */
-  surfaceName = 
-    Stg_ComponentFactory_GetString( cf, name,
-                                    (Dictionary_Entry_Key)strcat(temp,"SurfaceType"), ""  );
-  if( !strcmp( surfaceName, "wedge" ) ) {
-    *surfaceType = SurfaceAdaptor_SurfaceType_Wedge;
-    *deformFunc = SurfaceAdaptor_Wedge ;
-    strcpy(temp,surface);
-    info->wedge.offs[0] =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"BeginOffset"), 0.0  );
-    strcpy(temp,surface);
-    info->wedge.endOffs[0] =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"EndOffset"), 1.0  );
-    strcpy(temp,surface);
-    info->wedge.grad[0] = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"Gradient"), 0.5  );
-    /* get the parameters for the z-axis */
-    strcpy(temp,surface);
-    info->wedge.offs[1] = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"BeginOffsetZ"), 0.0  );
-    strcpy(temp,surface);
-    info->wedge.endOffs[1] = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"EndOffsetZ"), 1.0  );
-    strcpy(temp,surface);
-    info->wedge.grad[1] = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"GradientZ"), 0.5  );
-  }
-  else if( !strcmp( surfaceName, "plateau" ) ) {
-    *surfaceType = SurfaceAdaptor_SurfaceType_Plateau;
-    *deformFunc = SurfaceAdaptor_Plateau;
-    strcpy(temp,surface);
-    info->plateau.x1 =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"X1"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.x2 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"X2"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.x3 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"X3"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.x4 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"X4"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.z1 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"Z1"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.z2 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"Z2"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.z3 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"Z3"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.z4 = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"Z4"), 0.0 );
-    strcpy(temp,surface);
-    info->plateau.height =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"Height"), 0.0 );
-  }
-  else if( !strcmp( surfaceName, "topo_data" ) ) {
-    FILE *fp;
-    char* surfaceFileName;
-    int i,j,ii,jj;
-    *surfaceType = SurfaceAdaptor_SurfaceType_Topo_Data;
-    *deformFunc = SurfaceAdaptor_Topo_Data;
-    strcpy(temp,surface);
-    surfaceFileName =
-      Stg_ComponentFactory_GetString( cf, name,
-                                      strcat(temp,"SurfaceName"),
-                                      "ascii_topo" );
-    strcpy(temp,surface);
-    info->topo_data.nx =
-      Stg_ComponentFactory_GetInt( cf, name,
-                                   strcat(temp,"Nx"), 0 );
-    strcpy(temp,surface);
-    info->topo_data.nz = 
-      Stg_ComponentFactory_GetInt( cf, name,
-                                   strcat(temp,"Nz"), 1 );
-    strcpy(temp,surface);
-    info->topo_data.minX = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"MinX"), 0 );
-    strcpy(temp,surface);
-    info->topo_data.minZ = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"MinZ"), 0 );
-    strcpy(temp,surface);
-    info->topo_data.maxX = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"MaxX"), 0 );
-    strcpy(temp,surface);
-    info->topo_data.maxZ =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      strcat(temp,"MaxZ"), 0 );
-    info->topo_data.dx=
-      (info->topo_data.maxX-info->topo_data.minX)
-      /(info->topo_data.nx-1);
-    info->topo_data.dz=
-      (info->topo_data.maxZ-info->topo_data.minZ)
-      /(info->topo_data.nz-1);
-    info->topo_data.heights=
-      (double*)malloc(sizeof(double)*info->topo_data.nx
-                      *info->topo_data.nz);
-    fp=fopen(surfaceFileName,"r");
-    if(!fp)
-      {
-        printf("Can not open the file %s\n",surfaceFileName);
-        abort();
-      }
-    for(i=0;i<info->topo_data.nx;++i)
-      for(j=0;j<info->topo_data.nz;++j)
-        {
-          float h;
-          fscanf(fp,"%d %d %f",&ii,&jj,&h);
-          info->topo_data.heights[ii+info->topo_data.nx*jj]=h;
-        }
-    fclose(fp);
-  }
-  else if( !strcmp( surfaceName, "sine" )
-           || !strcmp( surfaceName, "cosine" ) ) {
-    Dictionary_Entry_Value*	originList;
-
-    if( !strcmp( surfaceName, "sine" ) )
-      {
-        *surfaceType = SurfaceAdaptor_SurfaceType_Sine;
-        *deformFunc = SurfaceAdaptor_Sine;
-      }
-    else
-      {
-        *surfaceType = SurfaceAdaptor_SurfaceType_Cosine;
-        *deformFunc = SurfaceAdaptor_Cosine;
-      }
-    strcpy(temp,surface);
-    originList =
-      Dictionary_Get( dict, (Dictionary_Entry_Key)strcat(temp,"Origin") );
-    if( originList ) {
-      unsigned	nDims;
-      unsigned	d_i;
-
-      nDims = Dictionary_Entry_Value_GetCount( originList );
-      for( d_i = 0; d_i < nDims; d_i++  ) {
-        Dictionary_Entry_Value*	val;
-
-        val = Dictionary_Entry_Value_GetElement( originList, d_i );
-        info->trig.origin[d_i] = Dictionary_Entry_Value_AsDouble( val );
-      }
-    }
-    else
-      memset( info->trig.origin, 0, sizeof(double) * 2 );
-
-    strcpy(temp,surface);
-    info->trig.amp =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"Amplitude"), 1.0  );
-    strcpy(temp,surface);
-    info->trig.freq =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"Frequency"), 1.0 );
-  } else if( !strcmp( surfaceName, "cylinder" ) ) {
-    *surfaceType = SurfaceAdaptor_SurfaceType_Cylinder;
-    *deformFunc = SurfaceAdaptor_Cylinder ;
-    strcpy(temp,surface);
-    info->cylinder.origin[0] =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"X0"), 0.0  );
-    strcpy(temp,surface);
-    info->cylinder.origin[1] =
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"Y0"), 0.0  );
-    strcpy(temp,surface);
-    info->cylinder.r = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"Radius"), 0.0  );
-    strcpy(temp,surface);
-    info->cylinder.minX = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"MinX"),
-                                      info->cylinder.origin[0] - info->cylinder.r);
-    strcpy(temp,surface);
-    info->cylinder.maxX = 
-      Stg_ComponentFactory_GetDouble( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"MaxX"),
-                                      info->cylinder.origin[0] + info->cylinder.r);
-    strcpy(temp,surface);
-    info->cylinder.sign = 
-      Stg_ComponentFactory_GetBool( cf, name,
-                                      (Dictionary_Entry_Key)strcat(temp,"Sign"), True  );
-  }
-  else
-    Journal_Firewall(!strcmp(surfaceName,""),Journal_Register( Error_Type, name ),
-                     "Unknown type of surface for SurfaceAdaptor: %s\n",
-                     surfaceName);
-}
-
-void _SurfaceAdaptor_Build( void* adaptor, void* data ) {
-   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
-
-   _MeshAdaptor_Build( self, data );
-}
-
-void _SurfaceAdaptor_Initialise( void* adaptor, void* data ) {
-   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
-
-   _MeshAdaptor_Initialise( self, data );
-}
-
-void _SurfaceAdaptor_Execute( void* adaptor, void* data ) {
-   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
-
-   _MeshAdaptor_Execute( self, data );
-}
-
-void _SurfaceAdaptor_Destroy( void* adaptor, void* data ) {
-   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
-
-   _MeshAdaptor_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void SurfaceAdaptor_Generate( void* adaptor, void* _mesh, void* data ) {
-	SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
-	Mesh* mesh = (Mesh*)_mesh;
-	const Sync* sync;
-	Grid *grid;
-	unsigned* inds;
-	unsigned n_i;
-
-	/* Build base mesh, which is assumed to be cartesian. */
-	MeshGenerator_Generate( self->generator, mesh, data );
-
-	/* if loading from checkpoint then forget about this step */
-	if( ((Context*)data)->loadFromCheckPoint == True )
-		return;
-	/* If we're not 2D or 3D, forget about it. */
-	if( mesh->topo->nDims != 2 && mesh->topo->nDims != 3 )
-		return;
-
-	/* Extract the cartesian information. */
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-	inds = AllocArray( unsigned, Mesh_GetDimSize( mesh ) );
-
-	/* Loop over domain nodes. */
-	sync = IGraph_GetDomain( mesh->topo, MT_VERTEX );
-	for( n_i = 0; n_i < (unsigned)Sync_GetNumDomains( sync ); n_i++ ) {
-		unsigned gNode;
-		double percentage, min_height, max_height;
-                double topDeform=0.0;
-                double bottomDeform=0.0;
-
-		gNode = Sync_DomainToGlobal( sync, n_i );
-		Grid_Lift( grid, gNode, inds );
-
-		/* Calculate a height percentage. */
-		percentage = (double)(inds[1]) / (double)(grid->sizes[1] - 1);
-
-		/* Deform this node. */
-                if(self->topDeformFunc)
-                  topDeform = self->topDeformFunc( &(self->top_info), mesh,
-                                                   grid->sizes, n_i, inds);
-                if(self->bottomDeformFunc)
-                  bottomDeform =
-                    self->bottomDeformFunc(&(self->bottom_info),mesh,
-                                           grid->sizes, n_i, inds);
-                min_height=((CartesianGenerator*)self->generator)->crdMin[1] + bottomDeform;
-                max_height=((CartesianGenerator*)self->generator)->crdMax[1] + topDeform;
-
-		mesh->verts[n_i][1] = percentage * (max_height - min_height)
-                  + min_height;
-	}
-
-	/* Free resources. */
-	FreeArray( inds );
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-double SurfaceAdaptor_Wedge( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
-                             unsigned* globalSize, unsigned vertex,
-                             unsigned* vertexInds )
-{
-  if ( mesh->topo->nDims != 3 )
-    {
-      if( mesh->verts[vertex][0] >= info->wedge.offs[0] )
-        {
-          if( mesh->verts[vertex][0] >= info->wedge.endOffs[0] )
-            return (info->wedge.endOffs[0] - info->wedge.offs[0])
-              * info->wedge.grad[0];
-          else
-            return (mesh->verts[vertex][0] - info->wedge.offs[0])
-              * info->wedge.grad[0];
-        }
-      else 
-        return 0.0;
-    }
-  else
-    {
-      if( mesh->verts[vertex][0] >= info->wedge.offs[0] )
-        {
-          if( mesh->verts[vertex][0] >= info->wedge.endOffs[0] )
-            {
-              return (info->wedge.endOffs[0] - info->wedge.offs[0])
-                * info->wedge.grad[0]
-                + (mesh->verts[vertex][2] - info->wedge.offs[1])
-                * info->wedge.grad[1];
-            }
-          else
-            {
-              return (mesh->verts[vertex][0] - info->wedge.offs[0])
-                * info->wedge.grad[0]
-                + (mesh->verts[vertex][2] - info->wedge.offs[1])
-                * info->wedge.grad[1];
-            }
-        }
-      else 
-        return 0.0;
-    }
-}
-
-double SurfaceAdaptor_Plateau( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
-                               unsigned* globalSize, unsigned vertex,
-                               unsigned* vertexInds )
-{
-  double x_factor, z_factor;
-  x_factor =1;
-  z_factor=1;
-  if( mesh->verts[vertex][0] < info->plateau.x1
-      || mesh->verts[vertex][0] > info->plateau.x4)
-    {
-      x_factor=0;
-    }
-  else if( mesh->verts[vertex][0] <= info->plateau.x2)
-    {
-      x_factor=(mesh->verts[vertex][0] - info->plateau.x1)
-        /(info->plateau.x2 - info->plateau.x1);
-    }
-  else if( mesh->verts[vertex][0] <= info->plateau.x3)
-    {
-      x_factor=1;
-    }
-  else if( mesh->verts[vertex][0] <= info->plateau.x4)
-    {
-      x_factor=(info->plateau.x4 - mesh->verts[vertex][0])
-        /(info->plateau.x4 - info->plateau.x3);
-    }
-
-  if(mesh->topo->nDims==3)
-    {
-      if( mesh->verts[vertex][2] < info->plateau.z1
-          || mesh->verts[vertex][2] > info->plateau.z4)
-        {
-          z_factor=0;
-        }
-      else if( mesh->verts[vertex][2] <= info->plateau.z2)
-        {
-          z_factor=(mesh->verts[vertex][2] - info->plateau.z1)
-            /(info->plateau.z2 - info->plateau.z1);
-        }
-      else if( mesh->verts[vertex][2] <= info->plateau.z3)
-        {
-          z_factor=1;
-        }
-      else if( mesh->verts[vertex][2] <= info->plateau.z4)
-        {
-          z_factor=(info->plateau.z4 - mesh->verts[vertex][2])
-            /(info->plateau.z4 - info->plateau.z3);
-        }
-    }
-
-  return x_factor*z_factor*info->plateau.height;
-}
-
-double SurfaceAdaptor_Topo_Data( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
-                                 unsigned* globalSize, unsigned vertex,
-                                 unsigned* vertexInds )
-{
-  int i,k,ip,kp;
-  double dx,dz;
-
-  if(mesh->topo->nDims==3)
-    {
-      i=floor((mesh->verts[vertex][0] - info->topo_data.minX)
-              /info->topo_data.dx + 0.5);
-      k=floor((mesh->verts[vertex][2] - info->topo_data.minZ)
-              /info->topo_data.dz + 0.5);
-
-      if(i<0 || i>info->topo_data.nx-1
-         || k<0 || k>info->topo_data.nz-1)
-        {
-          printf("Coordinate not covered by the topography file: %g %g\n\tminX: %g\n\tmaxX: %g\n\tminZ: %g\n\tmaxZ: %g\n\tnx: %d\n\tnz: %d\n",
-                 mesh->verts[vertex][0],
-                 mesh->verts[vertex][2],
-                 info->topo_data.minX,
-                 info->topo_data.maxX,
-                 info->topo_data.minZ,
-                 info->topo_data.maxZ,
-                 info->topo_data.nx,
-                 info->topo_data.nz);
-          abort();
-        }
-
-      /* Interpolate the height */
-      ip=i+1;
-      kp=k+1;
-      if(ip>info->topo_data.nx-1)
-        ip=i;
-      if(kp>info->topo_data.nz-1)
-        kp=k;
-
-      dx=(mesh->verts[vertex][0]
-          - (i*info->topo_data.dx+info->topo_data.minX))
-        /info->topo_data.dx;
-      dz=(mesh->verts[vertex][2]
-          - (k*info->topo_data.dz+info->topo_data.minZ))
-        /info->topo_data.dz;
-
-      return info->topo_data.heights[i+info->topo_data.nx*k]*(1-dx)*(1-dz)
-        + info->topo_data.heights[i+info->topo_data.nx*kp]*(1-dx)*dz
-        + info->topo_data.heights[ip+info->topo_data.nx*k]*dx*(1-dz)
-        + info->topo_data.heights[ip+info->topo_data.nx*kp]*dx*dz;
-    }
-  else
-    {
-      i=floor((mesh->verts[vertex][0] - info->topo_data.minX)
-              /info->topo_data.dx + 0.5);
-      if(i<0 || i>info->topo_data.nx-1)
-        {
-          printf("Coordinate not covered by the topography file: %g\n\tminX: %g\n\tmaxX: %g\n\tnx: %d\n\n",
-                 mesh->verts[vertex][0],
-                 info->topo_data.minX,
-                 info->topo_data.maxX,
-                 info->topo_data.nx);
-          abort();
-        }
-
-      /* Interpolate the height */
-      ip=i+1;
-      if(ip>info->topo_data.nx-1)
-        ip=i;
-
-      dx=(mesh->verts[vertex][0]
-          - (i*info->topo_data.dx+info->topo_data.minX))
-        /info->topo_data.dx;
-
-      return info->topo_data.heights[i]*(1-dx)
-        + info->topo_data.heights[ip]*dx;
-    }
-}
-
-double SurfaceAdaptor_Sine( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
-			    unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
-{
-	double	dx, dy;
-	double	rad;
-
-	dx = mesh->verts[vertex][0] - info->trig.origin[0];
-	rad = dx * dx;
-	if( mesh->topo->nDims == 3 ) {
-		dy = mesh->verts[vertex][1] - info->trig.origin[1];
-		rad += dy * dy;
-	}
-	rad = sqrt( rad );
-
-	return info->trig.amp * sin( info->trig.freq * rad );
-}
-
-double SurfaceAdaptor_Cosine( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
-			      unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
-{
-	double	dx, dz;
-	double	rad;
-
-	dx = mesh->verts[vertex][0] - info->trig.origin[0];
-	rad = dx * dx;
-	if( mesh->topo->nDims == 3 ) {
-		dz = mesh->verts[vertex][2] - info->trig.origin[2];
-		rad += dz * dz;
-	}
-	rad = sqrt( rad );
-
-	return info->trig.amp * cos( info->trig.freq * rad );
-}
-
-double SurfaceAdaptor_Cylinder( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
-                                unsigned* globalSize, unsigned vertex,
-                                unsigned* vertexInds )
-{
-  double x, x0, minX, maxX, y0, r;
-
-  x = mesh->verts[vertex][0];
-  x0= info->cylinder.origin[0];
-  minX=info->cylinder.minX;
-  maxX=info->cylinder.maxX;
-
-  y0= info->cylinder.origin[1];
-  r = info->cylinder.r;
-  if(x<minX)
-    {
-      x=minX;
-    }
-  else if(x>maxX)
-    {
-      x=maxX;
-    }
-  return info->cylinder.sign ? y0+sqrt(r*r-(x-x0)*(x-x0))
-    : y0-sqrt(r*r-(x-x0)*(x-x0));
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/SurfaceAdaptor.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/SurfaceAdaptor.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,710 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SurfaceAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Grid.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "IGraph.h"
+#include "MeshClass.h"
+#include "MeshGenerator.h"
+#include "MeshAdaptor.h"
+#include "SurfaceAdaptor.h"
+#include "Remesher.h"
+
+/* Textual name of this class */
+const Type SurfaceAdaptor_Type = "SurfaceAdaptor";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+SurfaceAdaptor* SurfaceAdaptor_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(SurfaceAdaptor);
+	Type                                                      type = SurfaceAdaptor_Type;
+	Stg_Class_DeleteFunction*                              _delete = _SurfaceAdaptor_Delete;
+	Stg_Class_PrintFunction*                                _print = _SurfaceAdaptor_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_SurfaceAdaptor_New;
+	Stg_Component_ConstructFunction*                    _construct = _SurfaceAdaptor_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _SurfaceAdaptor_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _SurfaceAdaptor_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _SurfaceAdaptor_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _SurfaceAdaptor_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	MeshGenerator_SetDimSizeFunc*                   setDimSizeFunc = _MeshGenerator_SetDimSize;
+	MeshGenerator_GenerateFunc*                       generateFunc = SurfaceAdaptor_Generate;
+
+	SurfaceAdaptor* self = _SurfaceAdaptor_New(  SURFACEADAPTOR_PASSARGS  );
+
+   _MeshGenerator_Init( (MeshGenerator*)self, context );
+   _MeshAdaptor_Init( (MeshAdaptor*)self );
+	_SurfaceAdaptor_Init( self );
+
+   return self;
+}
+
+SurfaceAdaptor* _SurfaceAdaptor_New(  SURFACEADAPTOR_DEFARGS  ) {
+	SurfaceAdaptor* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SurfaceAdaptor) );
+	self = (SurfaceAdaptor*)_MeshAdaptor_New(  MESHADAPTOR_PASSARGS  );
+
+	/* Virtual info */
+	return self;
+}
+
+void _SurfaceAdaptor_Init( SurfaceAdaptor* self ) {
+	self->topSurfaceType = SurfaceAdaptor_SurfaceType_Invalid;
+	self->bottomSurfaceType = SurfaceAdaptor_SurfaceType_Invalid;
+	memset( &self->top_info, 0, sizeof(SurfaceAdaptor_SurfaceInfo ));
+	memset( &self->bottom_info, 0, sizeof(SurfaceAdaptor_SurfaceInfo));
+        self->topDeformFunc=self->bottomDeformFunc=NULL;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _SurfaceAdaptor_Delete( void* adaptor ) {
+	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
+
+	/* Delete the parent. */
+	_MeshAdaptor_Delete( self );
+}
+
+void _SurfaceAdaptor_Print( void* adaptor, Stream* stream ) {
+	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
+	
+	/* Set the Journal for printing informations */
+	Stream* adaptorStream;
+	adaptorStream = Journal_Register( InfoStream_Type, (Name)"SurfaceAdaptorStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "SurfaceAdaptor (ptr): (%p)\n", self );
+	_MeshAdaptor_Print( self, stream );
+}
+
+void _SurfaceAdaptor_AssignFromXML_Surface(Stg_ComponentFactory* cf,
+                                           Name name,
+                                           SurfaceAdaptor_SurfaceType *surfaceType,
+                                           Dictionary* dict,
+                                           SurfaceAdaptor_SurfaceInfo *info,
+                                           SurfaceAdaptor_DeformFunc **deformFunc,
+                                           char *surface);
+
+void _SurfaceAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
+	SurfaceAdaptor*	self = (SurfaceAdaptor*)adaptor;
+	Dictionary*	dict;
+
+	assert( self );
+	assert( cf );
+
+	/* Call parent construct. */
+	_MeshAdaptor_AssignFromXML( self, cf, data );
+
+	/* Rip out the components structure as a dictionary. */
+	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
+
+        self->topDeformFunc=self->bottomDeformFunc=NULL;
+        char surface[100];
+        _SurfaceAdaptor_AssignFromXML_Surface(cf,self->name,
+                                              &(self->topSurfaceType),
+                                              dict,
+                                              &(self->top_info),
+                                              &(self->topDeformFunc),
+                                              strcpy(surface,"top"));
+        _SurfaceAdaptor_AssignFromXML_Surface(cf,self->name,
+                                              &(self->bottomSurfaceType),
+                                              dict,
+                                              &(self->bottom_info),
+                                              &(self->bottomDeformFunc),
+                                              strcpy(surface,"bottom"));
+}
+
+void _SurfaceAdaptor_AssignFromXML_Surface(Stg_ComponentFactory* cf,
+                                           Name name,
+                                           SurfaceAdaptor_SurfaceType *surfaceType,
+                                           Dictionary* dict,
+                                           SurfaceAdaptor_SurfaceInfo *info,
+                                           SurfaceAdaptor_DeformFunc **deformFunc,
+                                           char *surface)
+{
+  char temp[100];
+  char *surfaceName;
+  strcpy(temp,surface);
+  /* What kind of surface do we want? */
+  surfaceName = 
+    Stg_ComponentFactory_GetString( cf, name,
+                                    (Dictionary_Entry_Key)strcat(temp,"SurfaceType"), ""  );
+  if( !strcmp( surfaceName, "wedge" ) ) {
+    *surfaceType = SurfaceAdaptor_SurfaceType_Wedge;
+    *deformFunc = SurfaceAdaptor_Wedge ;
+    strcpy(temp,surface);
+    info->wedge.offs[0] =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"BeginOffset"), 0.0  );
+    strcpy(temp,surface);
+    info->wedge.endOffs[0] =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"EndOffset"), 1.0  );
+    strcpy(temp,surface);
+    info->wedge.grad[0] = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"Gradient"), 0.5  );
+    /* get the parameters for the z-axis */
+    strcpy(temp,surface);
+    info->wedge.offs[1] = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"BeginOffsetZ"), 0.0  );
+    strcpy(temp,surface);
+    info->wedge.endOffs[1] = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"EndOffsetZ"), 1.0  );
+    strcpy(temp,surface);
+    info->wedge.grad[1] = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"GradientZ"), 0.5  );
+  }
+  else if( !strcmp( surfaceName, "plateau" ) ) {
+    *surfaceType = SurfaceAdaptor_SurfaceType_Plateau;
+    *deformFunc = SurfaceAdaptor_Plateau;
+    strcpy(temp,surface);
+    info->plateau.x1 =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"X1"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.x2 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"X2"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.x3 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"X3"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.x4 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"X4"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.z1 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"Z1"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.z2 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"Z2"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.z3 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"Z3"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.z4 = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"Z4"), 0.0 );
+    strcpy(temp,surface);
+    info->plateau.height =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"Height"), 0.0 );
+  }
+  else if( !strcmp( surfaceName, "topo_data" ) ) {
+    FILE *fp;
+    char* surfaceFileName;
+    int i,j,ii,jj;
+    *surfaceType = SurfaceAdaptor_SurfaceType_Topo_Data;
+    *deformFunc = SurfaceAdaptor_Topo_Data;
+    strcpy(temp,surface);
+    surfaceFileName =
+      Stg_ComponentFactory_GetString( cf, name,
+                                      strcat(temp,"SurfaceName"),
+                                      "ascii_topo" );
+    strcpy(temp,surface);
+    info->topo_data.nx =
+      Stg_ComponentFactory_GetInt( cf, name,
+                                   strcat(temp,"Nx"), 0 );
+    strcpy(temp,surface);
+    info->topo_data.nz = 
+      Stg_ComponentFactory_GetInt( cf, name,
+                                   strcat(temp,"Nz"), 1 );
+    strcpy(temp,surface);
+    info->topo_data.minX = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"MinX"), 0 );
+    strcpy(temp,surface);
+    info->topo_data.minZ = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"MinZ"), 0 );
+    strcpy(temp,surface);
+    info->topo_data.maxX = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"MaxX"), 0 );
+    strcpy(temp,surface);
+    info->topo_data.maxZ =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      strcat(temp,"MaxZ"), 0 );
+    info->topo_data.dx=
+      (info->topo_data.maxX-info->topo_data.minX)
+      /(info->topo_data.nx-1);
+    info->topo_data.dz=
+      (info->topo_data.maxZ-info->topo_data.minZ)
+      /(info->topo_data.nz-1);
+    info->topo_data.heights=
+      (double*)malloc(sizeof(double)*info->topo_data.nx
+                      *info->topo_data.nz);
+    fp=fopen(surfaceFileName,"r");
+    if(!fp)
+      {
+        printf("Can not open the file %s\n",surfaceFileName);
+        abort();
+      }
+    for(i=0;i<info->topo_data.nx;++i)
+      for(j=0;j<info->topo_data.nz;++j)
+        {
+          float h;
+          fscanf(fp,"%d %d %f",&ii,&jj,&h);
+          info->topo_data.heights[ii+info->topo_data.nx*jj]=h;
+        }
+    fclose(fp);
+  }
+  else if( !strcmp( surfaceName, "sine" )
+           || !strcmp( surfaceName, "cosine" ) ) {
+    Dictionary_Entry_Value*	originList;
+
+    if( !strcmp( surfaceName, "sine" ) )
+      {
+        *surfaceType = SurfaceAdaptor_SurfaceType_Sine;
+        *deformFunc = SurfaceAdaptor_Sine;
+      }
+    else
+      {
+        *surfaceType = SurfaceAdaptor_SurfaceType_Cosine;
+        *deformFunc = SurfaceAdaptor_Cosine;
+      }
+    strcpy(temp,surface);
+    originList =
+      Dictionary_Get( dict, (Dictionary_Entry_Key)strcat(temp,"Origin") );
+    if( originList ) {
+      unsigned	nDims;
+      unsigned	d_i;
+
+      nDims = Dictionary_Entry_Value_GetCount( originList );
+      for( d_i = 0; d_i < nDims; d_i++  ) {
+        Dictionary_Entry_Value*	val;
+
+        val = Dictionary_Entry_Value_GetElement( originList, d_i );
+        info->trig.origin[d_i] = Dictionary_Entry_Value_AsDouble( val );
+      }
+    }
+    else
+      memset( info->trig.origin, 0, sizeof(double) * 2 );
+
+    strcpy(temp,surface);
+    info->trig.amp =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"Amplitude"), 1.0  );
+    strcpy(temp,surface);
+    info->trig.freq =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"Frequency"), 1.0 );
+  } else if( !strcmp( surfaceName, "cylinder" ) ) {
+    *surfaceType = SurfaceAdaptor_SurfaceType_Cylinder;
+    *deformFunc = SurfaceAdaptor_Cylinder ;
+    strcpy(temp,surface);
+    info->cylinder.origin[0] =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"X0"), 0.0  );
+    strcpy(temp,surface);
+    info->cylinder.origin[1] =
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"Y0"), 0.0  );
+    strcpy(temp,surface);
+    info->cylinder.r = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"Radius"), 0.0  );
+    strcpy(temp,surface);
+    info->cylinder.minX = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"MinX"),
+                                      info->cylinder.origin[0] - info->cylinder.r);
+    strcpy(temp,surface);
+    info->cylinder.maxX = 
+      Stg_ComponentFactory_GetDouble( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"MaxX"),
+                                      info->cylinder.origin[0] + info->cylinder.r);
+    strcpy(temp,surface);
+    info->cylinder.sign = 
+      Stg_ComponentFactory_GetBool( cf, name,
+                                      (Dictionary_Entry_Key)strcat(temp,"Sign"), True  );
+  }
+  else
+    Journal_Firewall(!strcmp(surfaceName,""),Journal_Register( Error_Type, name ),
+                     "Unknown type of surface for SurfaceAdaptor: %s\n",
+                     surfaceName);
+}
+
+void _SurfaceAdaptor_Build( void* adaptor, void* data ) {
+   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
+
+   _MeshAdaptor_Build( self, data );
+}
+
+void _SurfaceAdaptor_Initialise( void* adaptor, void* data ) {
+   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
+
+   _MeshAdaptor_Initialise( self, data );
+}
+
+void _SurfaceAdaptor_Execute( void* adaptor, void* data ) {
+   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
+
+   _MeshAdaptor_Execute( self, data );
+}
+
+void _SurfaceAdaptor_Destroy( void* adaptor, void* data ) {
+   SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
+
+   _MeshAdaptor_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void SurfaceAdaptor_Generate( void* adaptor, void* _mesh, void* data ) {
+	SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
+	Mesh* mesh = (Mesh*)_mesh;
+	const Sync* sync;
+	Grid *grid;
+	unsigned* inds;
+	unsigned n_i;
+
+	/* Build base mesh, which is assumed to be cartesian. */
+	MeshGenerator_Generate( self->generator, mesh, data );
+
+	/* if loading from checkpoint then forget about this step */
+	if( ((Context*)data)->loadFromCheckPoint == True )
+		return;
+	/* If we're not 2D or 3D, forget about it. */
+	if( mesh->topo->nDims != 2 && mesh->topo->nDims != 3 )
+		return;
+
+	/* Extract the cartesian information. */
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+	inds = AllocArray( unsigned, Mesh_GetDimSize( mesh ) );
+
+	/* Loop over domain nodes. */
+	sync = IGraph_GetDomain( mesh->topo, MT_VERTEX );
+	for( n_i = 0; n_i < (unsigned)Sync_GetNumDomains( sync ); n_i++ ) {
+		unsigned gNode;
+		double percentage, min_height, max_height;
+                double topDeform=0.0;
+                double bottomDeform=0.0;
+
+		gNode = Sync_DomainToGlobal( sync, n_i );
+		Grid_Lift( grid, gNode, inds );
+
+		/* Calculate a height percentage. */
+		percentage = (double)(inds[1]) / (double)(grid->sizes[1] - 1);
+
+		/* Deform this node. */
+                if(self->topDeformFunc)
+                  topDeform = self->topDeformFunc( &(self->top_info), mesh,
+                                                   grid->sizes, n_i, inds);
+                if(self->bottomDeformFunc)
+                  bottomDeform =
+                    self->bottomDeformFunc(&(self->bottom_info),mesh,
+                                           grid->sizes, n_i, inds);
+                min_height=((CartesianGenerator*)self->generator)->crdMin[1] + bottomDeform;
+                max_height=((CartesianGenerator*)self->generator)->crdMax[1] + topDeform;
+
+		mesh->verts[n_i][1] = percentage * (max_height - min_height)
+                  + min_height;
+	}
+
+	/* Free resources. */
+	FreeArray( inds );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+double SurfaceAdaptor_Wedge( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
+                             unsigned* globalSize, unsigned vertex,
+                             unsigned* vertexInds )
+{
+  if ( mesh->topo->nDims != 3 )
+    {
+      if( mesh->verts[vertex][0] >= info->wedge.offs[0] )
+        {
+          if( mesh->verts[vertex][0] >= info->wedge.endOffs[0] )
+            return (info->wedge.endOffs[0] - info->wedge.offs[0])
+              * info->wedge.grad[0];
+          else
+            return (mesh->verts[vertex][0] - info->wedge.offs[0])
+              * info->wedge.grad[0];
+        }
+      else 
+        return 0.0;
+    }
+  else
+    {
+      if( mesh->verts[vertex][0] >= info->wedge.offs[0] )
+        {
+          if( mesh->verts[vertex][0] >= info->wedge.endOffs[0] )
+            {
+              return (info->wedge.endOffs[0] - info->wedge.offs[0])
+                * info->wedge.grad[0]
+                + (mesh->verts[vertex][2] - info->wedge.offs[1])
+                * info->wedge.grad[1];
+            }
+          else
+            {
+              return (mesh->verts[vertex][0] - info->wedge.offs[0])
+                * info->wedge.grad[0]
+                + (mesh->verts[vertex][2] - info->wedge.offs[1])
+                * info->wedge.grad[1];
+            }
+        }
+      else 
+        return 0.0;
+    }
+}
+
+double SurfaceAdaptor_Plateau( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
+                               unsigned* globalSize, unsigned vertex,
+                               unsigned* vertexInds )
+{
+  double x_factor, z_factor;
+  x_factor =1;
+  z_factor=1;
+  if( mesh->verts[vertex][0] < info->plateau.x1
+      || mesh->verts[vertex][0] > info->plateau.x4)
+    {
+      x_factor=0;
+    }
+  else if( mesh->verts[vertex][0] <= info->plateau.x2)
+    {
+      x_factor=(mesh->verts[vertex][0] - info->plateau.x1)
+        /(info->plateau.x2 - info->plateau.x1);
+    }
+  else if( mesh->verts[vertex][0] <= info->plateau.x3)
+    {
+      x_factor=1;
+    }
+  else if( mesh->verts[vertex][0] <= info->plateau.x4)
+    {
+      x_factor=(info->plateau.x4 - mesh->verts[vertex][0])
+        /(info->plateau.x4 - info->plateau.x3);
+    }
+
+  if(mesh->topo->nDims==3)
+    {
+      if( mesh->verts[vertex][2] < info->plateau.z1
+          || mesh->verts[vertex][2] > info->plateau.z4)
+        {
+          z_factor=0;
+        }
+      else if( mesh->verts[vertex][2] <= info->plateau.z2)
+        {
+          z_factor=(mesh->verts[vertex][2] - info->plateau.z1)
+            /(info->plateau.z2 - info->plateau.z1);
+        }
+      else if( mesh->verts[vertex][2] <= info->plateau.z3)
+        {
+          z_factor=1;
+        }
+      else if( mesh->verts[vertex][2] <= info->plateau.z4)
+        {
+          z_factor=(info->plateau.z4 - mesh->verts[vertex][2])
+            /(info->plateau.z4 - info->plateau.z3);
+        }
+    }
+
+  return x_factor*z_factor*info->plateau.height;
+}
+
+double SurfaceAdaptor_Topo_Data( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
+                                 unsigned* globalSize, unsigned vertex,
+                                 unsigned* vertexInds )
+{
+  int i,k,ip,kp;
+  double dx,dz;
+
+  if(mesh->topo->nDims==3)
+    {
+      i=floor((mesh->verts[vertex][0] - info->topo_data.minX)
+              /info->topo_data.dx + 0.5);
+      k=floor((mesh->verts[vertex][2] - info->topo_data.minZ)
+              /info->topo_data.dz + 0.5);
+
+      if(i<0 || i>info->topo_data.nx-1
+         || k<0 || k>info->topo_data.nz-1)
+        {
+          printf("Coordinate not covered by the topography file: %g %g\n\tminX: %g\n\tmaxX: %g\n\tminZ: %g\n\tmaxZ: %g\n\tnx: %d\n\tnz: %d\n",
+                 mesh->verts[vertex][0],
+                 mesh->verts[vertex][2],
+                 info->topo_data.minX,
+                 info->topo_data.maxX,
+                 info->topo_data.minZ,
+                 info->topo_data.maxZ,
+                 info->topo_data.nx,
+                 info->topo_data.nz);
+          abort();
+        }
+
+      /* Interpolate the height */
+      ip=i+1;
+      kp=k+1;
+      if(ip>info->topo_data.nx-1)
+        ip=i;
+      if(kp>info->topo_data.nz-1)
+        kp=k;
+
+      dx=(mesh->verts[vertex][0]
+          - (i*info->topo_data.dx+info->topo_data.minX))
+        /info->topo_data.dx;
+      dz=(mesh->verts[vertex][2]
+          - (k*info->topo_data.dz+info->topo_data.minZ))
+        /info->topo_data.dz;
+
+      return info->topo_data.heights[i+info->topo_data.nx*k]*(1-dx)*(1-dz)
+        + info->topo_data.heights[i+info->topo_data.nx*kp]*(1-dx)*dz
+        + info->topo_data.heights[ip+info->topo_data.nx*k]*dx*(1-dz)
+        + info->topo_data.heights[ip+info->topo_data.nx*kp]*dx*dz;
+    }
+  else
+    {
+      i=floor((mesh->verts[vertex][0] - info->topo_data.minX)
+              /info->topo_data.dx + 0.5);
+      if(i<0 || i>info->topo_data.nx-1)
+        {
+          printf("Coordinate not covered by the topography file: %g\n\tminX: %g\n\tmaxX: %g\n\tnx: %d\n\n",
+                 mesh->verts[vertex][0],
+                 info->topo_data.minX,
+                 info->topo_data.maxX,
+                 info->topo_data.nx);
+          abort();
+        }
+
+      /* Interpolate the height */
+      ip=i+1;
+      if(ip>info->topo_data.nx-1)
+        ip=i;
+
+      dx=(mesh->verts[vertex][0]
+          - (i*info->topo_data.dx+info->topo_data.minX))
+        /info->topo_data.dx;
+
+      return info->topo_data.heights[i]*(1-dx)
+        + info->topo_data.heights[ip]*dx;
+    }
+}
+
+double SurfaceAdaptor_Sine( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
+			    unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
+{
+	double	dx, dy;
+	double	rad;
+
+	dx = mesh->verts[vertex][0] - info->trig.origin[0];
+	rad = dx * dx;
+	if( mesh->topo->nDims == 3 ) {
+		dy = mesh->verts[vertex][1] - info->trig.origin[1];
+		rad += dy * dy;
+	}
+	rad = sqrt( rad );
+
+	return info->trig.amp * sin( info->trig.freq * rad );
+}
+
+double SurfaceAdaptor_Cosine( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
+			      unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
+{
+	double	dx, dz;
+	double	rad;
+
+	dx = mesh->verts[vertex][0] - info->trig.origin[0];
+	rad = dx * dx;
+	if( mesh->topo->nDims == 3 ) {
+		dz = mesh->verts[vertex][2] - info->trig.origin[2];
+		rad += dz * dz;
+	}
+	rad = sqrt( rad );
+
+	return info->trig.amp * cos( info->trig.freq * rad );
+}
+
+double SurfaceAdaptor_Cylinder( SurfaceAdaptor_SurfaceInfo *info, Mesh* mesh, 
+                                unsigned* globalSize, unsigned vertex,
+                                unsigned* vertexInds )
+{
+  double x, x0, minX, maxX, y0, r;
+
+  x = mesh->verts[vertex][0];
+  x0= info->cylinder.origin[0];
+  minX=info->cylinder.minX;
+  maxX=info->cylinder.maxX;
+
+  y0= info->cylinder.origin[1];
+  r = info->cylinder.r;
+  if(x<minX)
+    {
+      x=minX;
+    }
+  else if(x>maxX)
+    {
+      x=maxX;
+    }
+  return info->cylinder.sign ? y0+sqrt(r*r-(x-x0)*(x-x0))
+    : y0-sqrt(r*r-(x-x0)*(x-x0));
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Sync.c
--- a/Mesh/src/Sync.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,630 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Sync.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-#include <string.h>
-#include "StGermain/StGermain.h"
-#include "types.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-void Sync_UpdateTables( Sync* self );
-void Sync_UpdateShared( Sync* self );
-void Sync_UpdateOwners( Sync* self );
-void Sync_ClearTables( Sync* self );
-void Sync_ClearShared( Sync* self );
-void Sync_ClearOwners( Sync* self );
-
-
-void _Sync_Init( void* _self ) {
-   Sync* self = (Sync*)_self;
-
-   _NewClass_Init( self );
-   self->decomp = NULL;
-   self->comm = NULL;
-   self->nDomains = 0;
-   self->remotes = &self->remotesObj;
-   IArray_Construct( self->remotes );
-   self->owners = NULL;
-   self->nShared = 0;
-   self->shared = NULL;
-   self->nSharers = NULL;
-   self->sharers = NULL;
-   self->gr = &self->grObj;
-   IMap_Construct( self->gr );
-   self->ls = &self->lsObj;
-   IMap_Construct( self->ls );
-   self->nSrcs = NULL;
-   self->srcs = NULL;
-   self->nSnks = NULL;
-   self->snks = NULL;
-}
-
-void _Sync_Destruct( void* _self ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_Clear( self );
-   IArray_Destruct( self->remotes );
-   IMap_Destruct( self->gr );
-   IMap_Destruct( self->ls );
-   _NewClass_Destruct( self );
-}
-
-void _Sync_Copy( void* _self, const void* op ) {
-   /*Sync* self = (Sync*)_self;*/
-
-   /* TODO: Method body goes here */
-   assert( 0 );
-}
-
-SizeT _Sync_CalcMem( const void* _self, PtrMap* ptrs ) {
-   const Sync* self = (const Sync*)_self;
-   SizeT mem;
-
-   if( PtrMap_Find( ptrs, (void*)self ) )
-      return 0;
-   mem = _NewClass_CalcMem( self, ptrs );
-   if( self->decomp )
-      mem += NewClass_CalcMem( self->decomp, ptrs );
-   mem += NewClass_CalcMem( self->remotes, ptrs );
-   mem += NewClass_CalcMem( self->gr, ptrs );
-   mem += NewClass_CalcMem( self->ls, ptrs );
-   return mem;
-}
-
-void Sync_SetDecomp( void* _self, const Decomp* decomp ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_ClearDecomp( self );
-   self->decomp = (Decomp*)decomp;
-   if( self->decomp ) {
-      NewClass_AddRef( self->decomp );
-      self->nDomains = Decomp_GetNumLocals( self->decomp );
-      Sync_UpdateTables( self );
-      Sync_UpdateShared( self );
-      Sync_UpdateOwners( self );
-   }
-}
-
-void Sync_FindRemotes( void* _self, int nRemotes, const int* remotes ) {
-   Sync *self = Class_Cast( _self, Sync );
-   int *owners;
-   ISet nbrSetObj, *nbrSet = &nbrSetObj;
-   Comm* comm;
-   int nNbrs, *nbrs;
-   int nRanks;
-   Bool *sendFlags, *recvFlags;
-   MPI_Comm mpiComm;
-   int r_i;
-
-   assert( !nRemotes || remotes );
-
-   mpiComm = Decomp_GetMPIComm( self->decomp );
-   insist( MPI_Comm_size( mpiComm, &nRanks ), == MPI_SUCCESS );
-
-   owners = Class_Array( self, int, nRemotes );
-   Decomp_FindOwners( self->decomp, nRemotes, remotes, owners );
-   ISet_Construct( nbrSet );
-   ISet_SetMaxSize( nbrSet, nRemotes );
-   for( r_i = 0; r_i < nRemotes; r_i++ )
-      ISet_TryInsert( nbrSet, owners[r_i] );
-   Class_Free( self, owners );
-
-   sendFlags = Class_Array( self, Bool, nRanks );
-   recvFlags = Class_Array( self, Bool, nRanks );
-   for( r_i = 0; r_i < nRanks; r_i++ )
-      sendFlags[r_i] = ISet_Has( nbrSet, r_i );
-   insist( MPI_Alltoall( sendFlags, 1, MPI_INT, 
-			 recvFlags, 1, MPI_INT, 
-			 mpiComm ), == MPI_SUCCESS );
-   Class_Free( self, sendFlags );
-   for( r_i = 0; r_i < nRanks; r_i++ ) {
-      if( recvFlags[r_i] )
-	 ISet_TryInsert( nbrSet, r_i );
-   }
-   Class_Free( self, recvFlags );
-
-   nNbrs = ISet_GetSize( nbrSet );
-   nbrs = Class_Array( self, int, nNbrs );
-   ISet_GetArray( nbrSet, nbrs );
-   ISet_Destruct( nbrSet );
-
-   comm = Comm_New();
-   Comm_SetMPIComm( comm, Decomp_GetMPIComm( self->decomp ) );
-   Comm_SetNeighbours( comm, nNbrs, nbrs );
-   Class_Free( self, nbrs );
-   Sync_SetComm( self, comm );
-
-   Sync_SetRemotes( self, nRemotes, remotes );
-}
-
-void Sync_SetComm( void* _self, const Comm* comm ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_ClearComm( self );
-   self->comm = (Comm*)comm;
-   if( self->comm ) {
-      NewClass_AddRef( self->comm );
-      Sync_UpdateTables( self );
-      Sync_UpdateShared( self );
-      Sync_UpdateOwners( self );
-   }
-}
-
-void Sync_SetRemotes( void* _self, int nRemotes, const int* remotes ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_ClearRemotes( self );
-   Sync_AddRemotes( self, nRemotes, remotes );
-}
-
-void Sync_AddRemotes( void* _self, int nRemotes, const int* remotes ) {
-   Sync* self = (Sync*)_self;
-   int nOldRems;
-   int r_i;
-
-   assert( self && self->decomp && self->comm );
-   nOldRems = IArray_GetSize( self->remotes );
-   IMap_SetMaxSize( self->gr, IArray_GetSize( self->remotes ) + nRemotes );
-   IArray_Add( self->remotes, nRemotes, remotes );
-   for( r_i = 0; r_i < nRemotes; r_i++ )
-      IMap_Insert( self->gr, remotes[r_i], nOldRems + r_i );
-   Sync_UpdateTables( self );
-   Sync_UpdateShared( self );
-   Sync_UpdateOwners( self );
-   self->nDomains += nRemotes;
-}
-
-void Sync_RemoveRemotes( void* _self, int nRemotes, const int* remotes, IMap* map ) {
-   Sync* self = (Sync*)_self;
-
-   assert( self && self->decomp && self->comm );
-   IArray_Remove( self->remotes, nRemotes, remotes, map );
-   Sync_UpdateTables( self );
-   Sync_UpdateShared( self );
-   Sync_UpdateOwners( self );
-   self->nDomains -= nRemotes;
-}
-
-void Sync_Clear( void* _self ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_ClearRemotes( self );
-   NewClass_RemoveRef( self->decomp );
-   self->decomp = NULL;
-   NewClass_RemoveRef( self->comm );
-   self->comm = NULL;
-   self->nDomains = 0;
-}
-
-void Sync_ClearDecomp( void* _self ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_ClearRemotes( self );
-   NewClass_RemoveRef( self->decomp );
-   self->decomp = NULL;
-   self->nDomains = 0;
-}
-
-void Sync_ClearComm( void* _self ) {
-   Sync* self = (Sync*)_self;
-
-   Sync_ClearRemotes( self );
-   NewClass_RemoveRef( self->comm );
-   self->comm = NULL;
-   if( self->decomp )
-      self->nDomains = Decomp_GetNumLocals( self->decomp );
-   else
-      self->nDomains = 0;
-}
-
-void Sync_ClearRemotes( void* _self ) {
-   Sync* self = (Sync*)_self;
-   int s_i;
-
-   Sync_ClearTables( self );
-   IArray_Clear( self->remotes );
-   for( s_i = 0; s_i < self->nShared; s_i++ )
-      Class_Free( self, self->sharers[s_i] );
-   Class_Free( self, self->shared );
-   Class_Free( self, self->nSharers );
-   Class_Free( self, self->sharers );
-   Class_Free( self, self->owners );
-   IMap_Clear( self->gr );
-   IMap_Clear( self->ls );
-   if( self->decomp )
-      self->nDomains = Decomp_GetNumLocals( self->decomp );
-   else
-      self->nDomains = 0;
-   self->nShared = 0;
-   self->shared = NULL;
-   self->nSharers = NULL;
-   self->sharers = NULL;
-   self->owners = NULL;
-}
-
-const Decomp* Sync_GetDecomp( const void* self ) {
-   assert( self );
-   return ((Sync*)self)->decomp;
-}
-
-const Comm* Sync_GetComm( const void* self ) {
-   assert( self );
-   return ((Sync*)self)->comm;
-}
-
-int Sync_GetNumRemotes( const void* self ) {
-   assert( self );
-   return IArray_GetSize( ((Sync*)self)->remotes );
-}
-
-int Sync_GetNumDomains( const void* self ) {
-   assert( self );
-   return ((Sync*)self)->nDomains;
-}
-
-int Sync_GetNumShared( const void* self ) {
-   assert( self );
-   return ((Sync*)self)->nShared;
-}
-
-int Sync_GetNumSharers( const void* self, int shared ) {
-   assert( self && shared < ((Sync*)self)->nShared );
-   assert( ((Sync*)self)->nSharers );
-   return ((Sync*)self)->nSharers[shared];
-}
-
-void Sync_GetRemotes( const void* self, int* nRemotes, const int** remotes ) {
-   assert( self );
-   *nRemotes = IArray_GetSize( ((Sync*)self)->remotes );
-   *remotes = IArray_GetPtr( ((Sync*)self)->remotes );
-}
-
-int Sync_GetOwner( const void* self, int remote ) {
-   assert( self && remote < IArray_GetSize( ((Sync*)self)->remotes ) );
-   assert( ((Sync*)self)->owners );
-   return ((Sync*)self)->owners[remote];
-}
-
-void Sync_GetShared( const void* self, int* nShared, const int** shared ) {
-   assert( self );
-   assert( !((Sync*)self)->nShared || shared );
-   if( nShared )
-      *nShared = ((Sync*)self)->nShared;
-   *shared = ((Sync*)self)->shared;
-}
-
-void Sync_GetSharers( const void* self, int shared, int* nSharers, const int** sharers ) {
-   assert( self && shared < ((Sync*)self)->nShared );
-   assert( ((Sync*)self)->nSharers && sharers );
-   if( nSharers )
-      *nSharers = ((Sync*)self)->nSharers[shared];
-   *sharers = ((Sync*)self)->sharers[shared];
-}
-
-int Sync_RemoteToGlobal( const void* self, int remote ) {
-   assert( self && remote < IArray_GetSize( ((Sync*)self)->remotes ) );
-   return IArray_GetPtr( ((Sync*)self)->remotes )[remote];
-}
-
-int Sync_GlobalToRemote( const void* self, int global ) {
-   assert( self && global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
-   return IMap_Map( ((Sync*)self)->gr, global );
-}
-
-Bool Sync_TryGlobalToRemote( const void* self, int global, int* remote ) {
-   assert( self && remote );
-   assert( global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
-   return IMap_TryMap( ((Sync*)self)->gr, global, remote );
-}
-
-int Sync_DomainToGlobal( const void* self, int domain ) {
-   assert( self );
-   assert( domain < Decomp_GetNumLocals( ((Sync*)self)->decomp ) + 
-	   IArray_GetSize( ((Sync*)self)->remotes ) );
-   if( domain < Decomp_GetNumLocals( ((Sync*)self)->decomp ) )
-      return Decomp_LocalToGlobal( ((Sync*)self)->decomp, domain );
-   else {
-      return IArray_GetPtr( ((Sync*)self)->remotes )
-	 [domain - Decomp_GetNumLocals( ((Sync*)self)->decomp )];
-   }
-}
-
-int Sync_GlobalToDomain( const void* self, int global ) {
-  int domain;
-
-   assert( self );
-   assert( global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
-   if( !Decomp_TryGlobalToLocal( ((Sync*)self)->decomp, global, &domain ) ) {
-      if( !IMap_Has( ((Sync*)self)->gr, global ) )
-	 abort();
-      return IMap_Map( ((Sync*)self)->gr, global ) + 
-	 Decomp_GetNumLocals( ((Sync*)self)->decomp );
-   }
-   else
-      return domain;
-}
-
-Bool Sync_TryGlobalToDomain( const void* self, int global, int* domain ) {
-   assert( self && domain );
-   assert( global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
-   if( !Decomp_TryGlobalToLocal( ((Sync*)self)->decomp, global, domain ) ) {
-      if( IMap_TryMap( ((Sync*)self)->gr, global, domain ) ) {
-	 *domain += Decomp_GetNumLocals( ((Sync*)self)->decomp );
-	 return True;
-      }
-      else
-	 return False;
-   }
-   else
-      return True;
-}
-
-int Sync_SharedToLocal( const void* self, int shared ) {
-   assert( self && shared < ((Sync*)self)->nShared );
-   return ((Sync*)self)->shared[shared];
-}
-
-int Sync_LocalToShared( const void* self, int local ) {
-   assert( self && local < Decomp_GetNumLocals( ((Sync*)self)->decomp ) );
-   return IMap_Map( ((Sync*)self)->ls, local );
-}
-
-Bool Sync_TryLocalToShared( const void* self, int local, int* shared ) {
-   assert( self && local < Decomp_GetNumLocals( ((Sync*)self)->decomp ) );
-   assert( shared );
-   return IMap_TryMap( ((Sync*)self)->ls, local, shared );
-}
-
-void Sync_SyncArray( const void* _self, 
-		     const void* local, size_t localStride, 
-		     const void* remote, size_t remoteStride, 
-		     size_t itmSize )
-{
-   Sync* self = (Sync*)_self;
-   int nNbrs;
-   int* nSrcs;
-   stgByte **srcs, **snks;
-   int n_i, s_i;
-
-   assert( self );
-   nNbrs = Comm_GetNumNeighbours( self->comm );
-   snks = Class_Array( self, stgByte*, nNbrs );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      snks[n_i] = Class_Array( self, stgByte, self->nSnks[n_i] * itmSize );
-      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
-	 memcpy( snks[n_i] + s_i * itmSize, 
-		 (stgByte*)local + self->snks[n_i][s_i] * localStride, 
-		 itmSize );
-      }
-   }
-
-   nSrcs = Class_Array( self, int, nNbrs );
-   Comm_AlltoallInit( self->comm, self->nSnks, nSrcs, itmSize );
-   srcs = Class_Array( self, stgByte*, nNbrs );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      srcs[n_i] = Class_Array( self, stgByte, nSrcs[n_i] * itmSize );
-   Comm_AlltoallBegin( self->comm, (const void**)snks, (void**)srcs );
-   Comm_AlltoallEnd( self->comm );
-   Class_Free( self, nSrcs );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      Class_Free( self, snks[n_i] );
-   Class_Free( self, snks );
-
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < self->nSrcs[n_i]; s_i++ ) {
-	 memcpy( (stgByte*)remote + self->srcs[n_i][s_i] * remoteStride, 
-		 srcs[n_i] + s_i * itmSize, 
-		 itmSize );
-      }
-      Class_Free( self, srcs[n_i] );
-   }
-   Class_Free( self, srcs );
-}
-
-void Sync_UpdateTables( Sync* self ) {
-   int nNbrs;
-   ISet theirRemsObj, *theirRems = &theirRemsObj;
-   ISet myLocsObj, *myLocs = &myLocsObj;
-   int nLocals, nRems;
-   const int *locals, *rems;
-   int* nAllRems, **allRems;
-   int* nFnds, **fnds;
-   int n_i, s_i;
-
-   Sync_ClearTables( self );
-   if( !self->comm || !self->decomp )
-      return;
-
-   nNbrs = Comm_GetNumNeighbours( self->comm );
-   ISet_Construct( theirRems );
-   ISet_Construct( myLocs );
-   Decomp_GetLocals( self->decomp, &nLocals, &locals );
-   ISet_UseArray( myLocs, nLocals, locals );
-   nRems = IArray_GetSize( self->remotes );
-   rems = IArray_GetPtr( self->remotes );
-
-   nAllRems = Class_Array( self, int, nNbrs );
-   allRems = Class_Array( self, int*, nNbrs );
-   Comm_AllgatherInit( self->comm, nRems, nAllRems, sizeof(int) );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      allRems[n_i] = Class_Array( self, int, nAllRems[n_i] );
-   Comm_AllgatherBegin( self->comm, rems, (void**)allRems );
-   Comm_AllgatherEnd( self->comm );
-
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      ISet_UseArray( theirRems, nAllRems[n_i], allRems[n_i] );
-      ISet_Isect( theirRems, myLocs );
-      nAllRems[n_i] = ISet_GetSize( theirRems );
-      allRems[n_i] = Class_Rearray( self, allRems[n_i], int, nAllRems[n_i] );
-      ISet_GetArray( theirRems, allRems[n_i] );
-   }
-   ISet_Destruct( theirRems );
-   ISet_Destruct( myLocs );
-
-   nFnds = Class_Array( self, int, nNbrs );
-   fnds = Class_Array( self, int*, nNbrs );
-   Comm_AlltoallInit( self->comm, nAllRems, nFnds, sizeof(int) );
-   for( n_i = 0; n_i < nNbrs; n_i++ )
-      fnds[n_i] = Class_Array( self, int, nFnds[n_i] );
-   Comm_AlltoallBegin( self->comm, (const void**)allRems, (void**)fnds );
-   Comm_AlltoallEnd( self->comm );
-
-   self->nSrcs = nFnds;
-   self->srcs = fnds;
-   self->nSnks = nAllRems;
-   self->snks = allRems;
-
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < self->nSrcs[n_i]; s_i++ ) {
-	 self->srcs[n_i][s_i] = Sync_GlobalToRemote( self, 
-						     self->srcs[n_i][s_i] ); 
-      }
-      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
-	 self->snks[n_i][s_i] = Decomp_GlobalToLocal( self->decomp, 
-						      self->snks[n_i][s_i] );
-      }
-   }
-}
-
-void Sync_UpdateShared( Sync* self ) {
-   ISet sharedSetObj, *sharedSet = &sharedSetObj;
-   int shared, nNbrs;
-   int n_i, s_i;
-
-   assert( self );
-   Sync_ClearShared( self );
-   if( !self->comm || !self->decomp )
-      return;
-
-   nNbrs = Comm_GetNumNeighbours( self->comm );
-   ISet_Construct( sharedSet );
-   ISet_SetMaxSize( sharedSet, Decomp_GetNumLocals( self->decomp ) );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ )
-	 ISet_TryInsert( sharedSet, self->snks[n_i][s_i] );
-   }
-   self->nShared = ISet_GetSize( sharedSet );
-   self->shared = Class_Rearray( self, self->shared, int, self->nShared );
-   ISet_GetArray( sharedSet, self->shared );
-   ISet_Destruct( sharedSet );
-
-   IMap_Clear( self->ls );
-   IMap_SetMaxSize( self->ls, self->nShared );
-   for( s_i = 0; s_i < self->nShared; s_i++ )
-      IMap_Insert( self->ls, self->shared[s_i], s_i );
-
-   self->nSharers = Class_Rearray( self, self->nSharers, int, self->nShared );
-   memset( self->nSharers, 0, self->nShared * sizeof(int) );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
-	 shared = IMap_Map( self->ls, self->snks[n_i][s_i] );
-	 self->nSharers[shared]++;
-      }
-   }
-   self->sharers = Class_Rearray( self, self->sharers, int*, self->nShared );
-   for( s_i = 0; s_i < self->nShared; s_i++ )
-      self->sharers[s_i] = Class_Array( self, int, self->nSharers[s_i] );
-   memset( self->nSharers, 0, self->nShared * sizeof(int) );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
-	 shared = IMap_Map( self->ls, self->snks[n_i][s_i] );
-	 self->sharers[shared][self->nSharers[shared]++] = n_i;
-      }
-   }
-}
-
-void Sync_UpdateOwners( Sync* self ) {
-   int nRemotes, nNbrs;
-   int n_i, s_i;
-
-   assert( self );
-   Sync_ClearOwners( self );
-   if( !self->comm || !self->decomp )
-      return;
-
-   nNbrs = Comm_GetNumNeighbours( self->comm );
-   nRemotes = IArray_GetSize( self->remotes );
-   self->owners = Class_Rearray( self, self->owners, int, nRemotes );
-   for( n_i = 0; n_i < nNbrs; n_i++ ) {
-      for( s_i = 0; s_i < self->nSrcs[n_i]; s_i++ )
-	 self->owners[self->srcs[n_i][s_i]] = n_i;
-   }
-}
-
-void Sync_ClearTables( Sync* self ) {
-   int n_i;
-
-   assert( self );
-   if( self->decomp ) {
-      if( self->comm ) {
-	 for( n_i = 0; n_i < Comm_GetNumNeighbours( self->comm ); n_i++ ) {
-	    if( self->srcs )
-	       Class_Free( self, self->srcs[n_i] );
-	    if( self->snks )
-	       Class_Free( self, self->snks[n_i] );
-	 }
-      }
-   }
-   Class_Free( self, self->nSrcs );
-   Class_Free( self, self->srcs );
-   Class_Free( self, self->nSnks );
-   Class_Free( self, self->snks );
-   self->nSrcs = NULL;
-   self->srcs = NULL;
-   self->nSnks = NULL;
-   self->snks = NULL;
-}
-
-void Sync_ClearShared( Sync* self ) {
-   int s_i;
-
-   assert( self );
-   for( s_i = 0; s_i < self->nShared; s_i++ )
-      Class_Free( self, self->sharers[s_i] );
-   Class_Free( self, self->shared );
-   Class_Free( self, self->nSharers );
-   Class_Free( self, self->sharers );
-   self->nShared = 0;
-   self->shared = NULL;
-   self->nSharers = NULL;
-   self->sharers = NULL;
-}
-
-void Sync_ClearOwners( Sync* self ) {
-   assert( self );
-   Class_Free( self, self->owners );
-   self->owners = NULL;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/Sync.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/Sync.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,630 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Sync.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "StGermain/StGermain.h"
+#include "types.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+void Sync_UpdateTables( Sync* self );
+void Sync_UpdateShared( Sync* self );
+void Sync_UpdateOwners( Sync* self );
+void Sync_ClearTables( Sync* self );
+void Sync_ClearShared( Sync* self );
+void Sync_ClearOwners( Sync* self );
+
+
+void _Sync_Init( void* _self ) {
+   Sync* self = (Sync*)_self;
+
+   _NewClass_Init( self );
+   self->decomp = NULL;
+   self->comm = NULL;
+   self->nDomains = 0;
+   self->remotes = &self->remotesObj;
+   IArray_Construct( self->remotes );
+   self->owners = NULL;
+   self->nShared = 0;
+   self->shared = NULL;
+   self->nSharers = NULL;
+   self->sharers = NULL;
+   self->gr = &self->grObj;
+   IMap_Construct( self->gr );
+   self->ls = &self->lsObj;
+   IMap_Construct( self->ls );
+   self->nSrcs = NULL;
+   self->srcs = NULL;
+   self->nSnks = NULL;
+   self->snks = NULL;
+}
+
+void _Sync_Destruct( void* _self ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_Clear( self );
+   IArray_Destruct( self->remotes );
+   IMap_Destruct( self->gr );
+   IMap_Destruct( self->ls );
+   _NewClass_Destruct( self );
+}
+
+void _Sync_Copy( void* _self, const void* op ) {
+   /*Sync* self = (Sync*)_self;*/
+
+   /* TODO: Method body goes here */
+   assert( 0 );
+}
+
+SizeT _Sync_CalcMem( const void* _self, PtrMap* ptrs ) {
+   const Sync* self = (const Sync*)_self;
+   SizeT mem;
+
+   if( PtrMap_Find( ptrs, (void*)self ) )
+      return 0;
+   mem = _NewClass_CalcMem( self, ptrs );
+   if( self->decomp )
+      mem += NewClass_CalcMem( self->decomp, ptrs );
+   mem += NewClass_CalcMem( self->remotes, ptrs );
+   mem += NewClass_CalcMem( self->gr, ptrs );
+   mem += NewClass_CalcMem( self->ls, ptrs );
+   return mem;
+}
+
+void Sync_SetDecomp( void* _self, const Decomp* decomp ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_ClearDecomp( self );
+   self->decomp = (Decomp*)decomp;
+   if( self->decomp ) {
+      NewClass_AddRef( self->decomp );
+      self->nDomains = Decomp_GetNumLocals( self->decomp );
+      Sync_UpdateTables( self );
+      Sync_UpdateShared( self );
+      Sync_UpdateOwners( self );
+   }
+}
+
+void Sync_FindRemotes( void* _self, int nRemotes, const int* remotes ) {
+   Sync *self = Class_Cast( _self, Sync );
+   int *owners;
+   ISet nbrSetObj, *nbrSet = &nbrSetObj;
+   Comm* comm;
+   int nNbrs, *nbrs;
+   int nRanks;
+   Bool *sendFlags, *recvFlags;
+   MPI_Comm mpiComm;
+   int r_i;
+
+   assert( !nRemotes || remotes );
+
+   mpiComm = Decomp_GetMPIComm( self->decomp );
+   insist( MPI_Comm_size( mpiComm, &nRanks ), == MPI_SUCCESS );
+
+   owners = Class_Array( self, int, nRemotes );
+   Decomp_FindOwners( self->decomp, nRemotes, remotes, owners );
+   ISet_Construct( nbrSet );
+   ISet_SetMaxSize( nbrSet, nRemotes );
+   for( r_i = 0; r_i < nRemotes; r_i++ )
+      ISet_TryInsert( nbrSet, owners[r_i] );
+   Class_Free( self, owners );
+
+   sendFlags = Class_Array( self, Bool, nRanks );
+   recvFlags = Class_Array( self, Bool, nRanks );
+   for( r_i = 0; r_i < nRanks; r_i++ )
+      sendFlags[r_i] = ISet_Has( nbrSet, r_i );
+   insist( MPI_Alltoall( sendFlags, 1, MPI_INT, 
+			 recvFlags, 1, MPI_INT, 
+			 mpiComm ), == MPI_SUCCESS );
+   Class_Free( self, sendFlags );
+   for( r_i = 0; r_i < nRanks; r_i++ ) {
+      if( recvFlags[r_i] )
+	 ISet_TryInsert( nbrSet, r_i );
+   }
+   Class_Free( self, recvFlags );
+
+   nNbrs = ISet_GetSize( nbrSet );
+   nbrs = Class_Array( self, int, nNbrs );
+   ISet_GetArray( nbrSet, nbrs );
+   ISet_Destruct( nbrSet );
+
+   comm = Comm_New();
+   Comm_SetMPIComm( comm, Decomp_GetMPIComm( self->decomp ) );
+   Comm_SetNeighbours( comm, nNbrs, nbrs );
+   Class_Free( self, nbrs );
+   Sync_SetComm( self, comm );
+
+   Sync_SetRemotes( self, nRemotes, remotes );
+}
+
+void Sync_SetComm( void* _self, const Comm* comm ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_ClearComm( self );
+   self->comm = (Comm*)comm;
+   if( self->comm ) {
+      NewClass_AddRef( self->comm );
+      Sync_UpdateTables( self );
+      Sync_UpdateShared( self );
+      Sync_UpdateOwners( self );
+   }
+}
+
+void Sync_SetRemotes( void* _self, int nRemotes, const int* remotes ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_ClearRemotes( self );
+   Sync_AddRemotes( self, nRemotes, remotes );
+}
+
+void Sync_AddRemotes( void* _self, int nRemotes, const int* remotes ) {
+   Sync* self = (Sync*)_self;
+   int nOldRems;
+   int r_i;
+
+   assert( self && self->decomp && self->comm );
+   nOldRems = IArray_GetSize( self->remotes );
+   IMap_SetMaxSize( self->gr, IArray_GetSize( self->remotes ) + nRemotes );
+   IArray_Add( self->remotes, nRemotes, remotes );
+   for( r_i = 0; r_i < nRemotes; r_i++ )
+      IMap_Insert( self->gr, remotes[r_i], nOldRems + r_i );
+   Sync_UpdateTables( self );
+   Sync_UpdateShared( self );
+   Sync_UpdateOwners( self );
+   self->nDomains += nRemotes;
+}
+
+void Sync_RemoveRemotes( void* _self, int nRemotes, const int* remotes, IMap* map ) {
+   Sync* self = (Sync*)_self;
+
+   assert( self && self->decomp && self->comm );
+   IArray_Remove( self->remotes, nRemotes, remotes, map );
+   Sync_UpdateTables( self );
+   Sync_UpdateShared( self );
+   Sync_UpdateOwners( self );
+   self->nDomains -= nRemotes;
+}
+
+void Sync_Clear( void* _self ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_ClearRemotes( self );
+   NewClass_RemoveRef( self->decomp );
+   self->decomp = NULL;
+   NewClass_RemoveRef( self->comm );
+   self->comm = NULL;
+   self->nDomains = 0;
+}
+
+void Sync_ClearDecomp( void* _self ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_ClearRemotes( self );
+   NewClass_RemoveRef( self->decomp );
+   self->decomp = NULL;
+   self->nDomains = 0;
+}
+
+void Sync_ClearComm( void* _self ) {
+   Sync* self = (Sync*)_self;
+
+   Sync_ClearRemotes( self );
+   NewClass_RemoveRef( self->comm );
+   self->comm = NULL;
+   if( self->decomp )
+      self->nDomains = Decomp_GetNumLocals( self->decomp );
+   else
+      self->nDomains = 0;
+}
+
+void Sync_ClearRemotes( void* _self ) {
+   Sync* self = (Sync*)_self;
+   int s_i;
+
+   Sync_ClearTables( self );
+   IArray_Clear( self->remotes );
+   for( s_i = 0; s_i < self->nShared; s_i++ )
+      Class_Free( self, self->sharers[s_i] );
+   Class_Free( self, self->shared );
+   Class_Free( self, self->nSharers );
+   Class_Free( self, self->sharers );
+   Class_Free( self, self->owners );
+   IMap_Clear( self->gr );
+   IMap_Clear( self->ls );
+   if( self->decomp )
+      self->nDomains = Decomp_GetNumLocals( self->decomp );
+   else
+      self->nDomains = 0;
+   self->nShared = 0;
+   self->shared = NULL;
+   self->nSharers = NULL;
+   self->sharers = NULL;
+   self->owners = NULL;
+}
+
+const Decomp* Sync_GetDecomp( const void* self ) {
+   assert( self );
+   return ((Sync*)self)->decomp;
+}
+
+const Comm* Sync_GetComm( const void* self ) {
+   assert( self );
+   return ((Sync*)self)->comm;
+}
+
+int Sync_GetNumRemotes( const void* self ) {
+   assert( self );
+   return IArray_GetSize( ((Sync*)self)->remotes );
+}
+
+int Sync_GetNumDomains( const void* self ) {
+   assert( self );
+   return ((Sync*)self)->nDomains;
+}
+
+int Sync_GetNumShared( const void* self ) {
+   assert( self );
+   return ((Sync*)self)->nShared;
+}
+
+int Sync_GetNumSharers( const void* self, int shared ) {
+   assert( self && shared < ((Sync*)self)->nShared );
+   assert( ((Sync*)self)->nSharers );
+   return ((Sync*)self)->nSharers[shared];
+}
+
+void Sync_GetRemotes( const void* self, int* nRemotes, const int** remotes ) {
+   assert( self );
+   *nRemotes = IArray_GetSize( ((Sync*)self)->remotes );
+   *remotes = IArray_GetPtr( ((Sync*)self)->remotes );
+}
+
+int Sync_GetOwner( const void* self, int remote ) {
+   assert( self && remote < IArray_GetSize( ((Sync*)self)->remotes ) );
+   assert( ((Sync*)self)->owners );
+   return ((Sync*)self)->owners[remote];
+}
+
+void Sync_GetShared( const void* self, int* nShared, const int** shared ) {
+   assert( self );
+   assert( !((Sync*)self)->nShared || shared );
+   if( nShared )
+      *nShared = ((Sync*)self)->nShared;
+   *shared = ((Sync*)self)->shared;
+}
+
+void Sync_GetSharers( const void* self, int shared, int* nSharers, const int** sharers ) {
+   assert( self && shared < ((Sync*)self)->nShared );
+   assert( ((Sync*)self)->nSharers && sharers );
+   if( nSharers )
+      *nSharers = ((Sync*)self)->nSharers[shared];
+   *sharers = ((Sync*)self)->sharers[shared];
+}
+
+int Sync_RemoteToGlobal( const void* self, int remote ) {
+   assert( self && remote < IArray_GetSize( ((Sync*)self)->remotes ) );
+   return IArray_GetPtr( ((Sync*)self)->remotes )[remote];
+}
+
+int Sync_GlobalToRemote( const void* self, int global ) {
+   assert( self && global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
+   return IMap_Map( ((Sync*)self)->gr, global );
+}
+
+Bool Sync_TryGlobalToRemote( const void* self, int global, int* remote ) {
+   assert( self && remote );
+   assert( global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
+   return IMap_TryMap( ((Sync*)self)->gr, global, remote );
+}
+
+int Sync_DomainToGlobal( const void* self, int domain ) {
+   assert( self );
+   assert( domain < Decomp_GetNumLocals( ((Sync*)self)->decomp ) + 
+	   IArray_GetSize( ((Sync*)self)->remotes ) );
+   if( domain < Decomp_GetNumLocals( ((Sync*)self)->decomp ) )
+      return Decomp_LocalToGlobal( ((Sync*)self)->decomp, domain );
+   else {
+      return IArray_GetPtr( ((Sync*)self)->remotes )
+	 [domain - Decomp_GetNumLocals( ((Sync*)self)->decomp )];
+   }
+}
+
+int Sync_GlobalToDomain( const void* self, int global ) {
+  int domain;
+
+   assert( self );
+   assert( global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
+   if( !Decomp_TryGlobalToLocal( ((Sync*)self)->decomp, global, &domain ) ) {
+      if( !IMap_Has( ((Sync*)self)->gr, global ) )
+	 abort();
+      return IMap_Map( ((Sync*)self)->gr, global ) + 
+	 Decomp_GetNumLocals( ((Sync*)self)->decomp );
+   }
+   else
+      return domain;
+}
+
+Bool Sync_TryGlobalToDomain( const void* self, int global, int* domain ) {
+   assert( self && domain );
+   assert( global < Decomp_GetNumGlobals( ((Sync*)self)->decomp ) );
+   if( !Decomp_TryGlobalToLocal( ((Sync*)self)->decomp, global, domain ) ) {
+      if( IMap_TryMap( ((Sync*)self)->gr, global, domain ) ) {
+	 *domain += Decomp_GetNumLocals( ((Sync*)self)->decomp );
+	 return True;
+      }
+      else
+	 return False;
+   }
+   else
+      return True;
+}
+
+int Sync_SharedToLocal( const void* self, int shared ) {
+   assert( self && shared < ((Sync*)self)->nShared );
+   return ((Sync*)self)->shared[shared];
+}
+
+int Sync_LocalToShared( const void* self, int local ) {
+   assert( self && local < Decomp_GetNumLocals( ((Sync*)self)->decomp ) );
+   return IMap_Map( ((Sync*)self)->ls, local );
+}
+
+Bool Sync_TryLocalToShared( const void* self, int local, int* shared ) {
+   assert( self && local < Decomp_GetNumLocals( ((Sync*)self)->decomp ) );
+   assert( shared );
+   return IMap_TryMap( ((Sync*)self)->ls, local, shared );
+}
+
+void Sync_SyncArray( const void* _self, 
+		     const void* local, size_t localStride, 
+		     const void* remote, size_t remoteStride, 
+		     size_t itmSize )
+{
+   Sync* self = (Sync*)_self;
+   int nNbrs;
+   int* nSrcs;
+   stgByte **srcs, **snks;
+   int n_i, s_i;
+
+   assert( self );
+   nNbrs = Comm_GetNumNeighbours( self->comm );
+   snks = Class_Array( self, stgByte*, nNbrs );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      snks[n_i] = Class_Array( self, stgByte, self->nSnks[n_i] * itmSize );
+      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
+	 memcpy( snks[n_i] + s_i * itmSize, 
+		 (stgByte*)local + self->snks[n_i][s_i] * localStride, 
+		 itmSize );
+      }
+   }
+
+   nSrcs = Class_Array( self, int, nNbrs );
+   Comm_AlltoallInit( self->comm, self->nSnks, nSrcs, itmSize );
+   srcs = Class_Array( self, stgByte*, nNbrs );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      srcs[n_i] = Class_Array( self, stgByte, nSrcs[n_i] * itmSize );
+   Comm_AlltoallBegin( self->comm, (const void**)snks, (void**)srcs );
+   Comm_AlltoallEnd( self->comm );
+   Class_Free( self, nSrcs );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      Class_Free( self, snks[n_i] );
+   Class_Free( self, snks );
+
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < self->nSrcs[n_i]; s_i++ ) {
+	 memcpy( (stgByte*)remote + self->srcs[n_i][s_i] * remoteStride, 
+		 srcs[n_i] + s_i * itmSize, 
+		 itmSize );
+      }
+      Class_Free( self, srcs[n_i] );
+   }
+   Class_Free( self, srcs );
+}
+
+void Sync_UpdateTables( Sync* self ) {
+   int nNbrs;
+   ISet theirRemsObj, *theirRems = &theirRemsObj;
+   ISet myLocsObj, *myLocs = &myLocsObj;
+   int nLocals, nRems;
+   const int *locals, *rems;
+   int* nAllRems, **allRems;
+   int* nFnds, **fnds;
+   int n_i, s_i;
+
+   Sync_ClearTables( self );
+   if( !self->comm || !self->decomp )
+      return;
+
+   nNbrs = Comm_GetNumNeighbours( self->comm );
+   ISet_Construct( theirRems );
+   ISet_Construct( myLocs );
+   Decomp_GetLocals( self->decomp, &nLocals, &locals );
+   ISet_UseArray( myLocs, nLocals, locals );
+   nRems = IArray_GetSize( self->remotes );
+   rems = IArray_GetPtr( self->remotes );
+
+   nAllRems = Class_Array( self, int, nNbrs );
+   allRems = Class_Array( self, int*, nNbrs );
+   Comm_AllgatherInit( self->comm, nRems, nAllRems, sizeof(int) );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      allRems[n_i] = Class_Array( self, int, nAllRems[n_i] );
+   Comm_AllgatherBegin( self->comm, rems, (void**)allRems );
+   Comm_AllgatherEnd( self->comm );
+
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      ISet_UseArray( theirRems, nAllRems[n_i], allRems[n_i] );
+      ISet_Isect( theirRems, myLocs );
+      nAllRems[n_i] = ISet_GetSize( theirRems );
+      allRems[n_i] = Class_Rearray( self, allRems[n_i], int, nAllRems[n_i] );
+      ISet_GetArray( theirRems, allRems[n_i] );
+   }
+   ISet_Destruct( theirRems );
+   ISet_Destruct( myLocs );
+
+   nFnds = Class_Array( self, int, nNbrs );
+   fnds = Class_Array( self, int*, nNbrs );
+   Comm_AlltoallInit( self->comm, nAllRems, nFnds, sizeof(int) );
+   for( n_i = 0; n_i < nNbrs; n_i++ )
+      fnds[n_i] = Class_Array( self, int, nFnds[n_i] );
+   Comm_AlltoallBegin( self->comm, (const void**)allRems, (void**)fnds );
+   Comm_AlltoallEnd( self->comm );
+
+   self->nSrcs = nFnds;
+   self->srcs = fnds;
+   self->nSnks = nAllRems;
+   self->snks = allRems;
+
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < self->nSrcs[n_i]; s_i++ ) {
+	 self->srcs[n_i][s_i] = Sync_GlobalToRemote( self, 
+						     self->srcs[n_i][s_i] ); 
+      }
+      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
+	 self->snks[n_i][s_i] = Decomp_GlobalToLocal( self->decomp, 
+						      self->snks[n_i][s_i] );
+      }
+   }
+}
+
+void Sync_UpdateShared( Sync* self ) {
+   ISet sharedSetObj, *sharedSet = &sharedSetObj;
+   int shared, nNbrs;
+   int n_i, s_i;
+
+   assert( self );
+   Sync_ClearShared( self );
+   if( !self->comm || !self->decomp )
+      return;
+
+   nNbrs = Comm_GetNumNeighbours( self->comm );
+   ISet_Construct( sharedSet );
+   ISet_SetMaxSize( sharedSet, Decomp_GetNumLocals( self->decomp ) );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ )
+	 ISet_TryInsert( sharedSet, self->snks[n_i][s_i] );
+   }
+   self->nShared = ISet_GetSize( sharedSet );
+   self->shared = Class_Rearray( self, self->shared, int, self->nShared );
+   ISet_GetArray( sharedSet, self->shared );
+   ISet_Destruct( sharedSet );
+
+   IMap_Clear( self->ls );
+   IMap_SetMaxSize( self->ls, self->nShared );
+   for( s_i = 0; s_i < self->nShared; s_i++ )
+      IMap_Insert( self->ls, self->shared[s_i], s_i );
+
+   self->nSharers = Class_Rearray( self, self->nSharers, int, self->nShared );
+   memset( self->nSharers, 0, self->nShared * sizeof(int) );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
+	 shared = IMap_Map( self->ls, self->snks[n_i][s_i] );
+	 self->nSharers[shared]++;
+      }
+   }
+   self->sharers = Class_Rearray( self, self->sharers, int*, self->nShared );
+   for( s_i = 0; s_i < self->nShared; s_i++ )
+      self->sharers[s_i] = Class_Array( self, int, self->nSharers[s_i] );
+   memset( self->nSharers, 0, self->nShared * sizeof(int) );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < self->nSnks[n_i]; s_i++ ) {
+	 shared = IMap_Map( self->ls, self->snks[n_i][s_i] );
+	 self->sharers[shared][self->nSharers[shared]++] = n_i;
+      }
+   }
+}
+
+void Sync_UpdateOwners( Sync* self ) {
+   int nRemotes, nNbrs;
+   int n_i, s_i;
+
+   assert( self );
+   Sync_ClearOwners( self );
+   if( !self->comm || !self->decomp )
+      return;
+
+   nNbrs = Comm_GetNumNeighbours( self->comm );
+   nRemotes = IArray_GetSize( self->remotes );
+   self->owners = Class_Rearray( self, self->owners, int, nRemotes );
+   for( n_i = 0; n_i < nNbrs; n_i++ ) {
+      for( s_i = 0; s_i < self->nSrcs[n_i]; s_i++ )
+	 self->owners[self->srcs[n_i][s_i]] = n_i;
+   }
+}
+
+void Sync_ClearTables( Sync* self ) {
+   int n_i;
+
+   assert( self );
+   if( self->decomp ) {
+      if( self->comm ) {
+	 for( n_i = 0; n_i < Comm_GetNumNeighbours( self->comm ); n_i++ ) {
+	    if( self->srcs )
+	       Class_Free( self, self->srcs[n_i] );
+	    if( self->snks )
+	       Class_Free( self, self->snks[n_i] );
+	 }
+      }
+   }
+   Class_Free( self, self->nSrcs );
+   Class_Free( self, self->srcs );
+   Class_Free( self, self->nSnks );
+   Class_Free( self, self->snks );
+   self->nSrcs = NULL;
+   self->srcs = NULL;
+   self->nSnks = NULL;
+   self->snks = NULL;
+}
+
+void Sync_ClearShared( Sync* self ) {
+   int s_i;
+
+   assert( self );
+   for( s_i = 0; s_i < self->nShared; s_i++ )
+      Class_Free( self, self->sharers[s_i] );
+   Class_Free( self, self->shared );
+   Class_Free( self, self->nSharers );
+   Class_Free( self, self->sharers );
+   self->nShared = 0;
+   self->shared = NULL;
+   self->nSharers = NULL;
+   self->sharers = NULL;
+}
+
+void Sync_ClearOwners( Sync* self ) {
+   assert( self );
+   Class_Free( self, self->owners );
+   self->owners = NULL;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/linearSpaceAdaptor.c
--- a/Mesh/src/linearSpaceAdaptor.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,371 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: LinearSpaceAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <string.h>
-#include <assert.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Grid.h"
-#include "Decomp.h"
-#include "Sync.h"
-#include "MeshTopology.h"
-#include "IGraph.h"
-#include "MeshClass.h"
-#include "MeshGenerator.h"
-#include "MeshAdaptor.h"
-#include "linearSpaceAdaptor.h"
-
-
-typedef double (LinearSpaceAdaptor_DeformFunc)( LinearSpaceAdaptor* self, Mesh* mesh, 
-					    unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
-
-
-/* Textual name of this class */
-const Type LinearSpaceAdaptor_Type = "LinearSpaceAdaptor";
-
-
-
-/* My private functions */
-void   LinearSpaceAdaptor_FillTable( segment* table, unsigned size  );
-double LinearSpaceAdaptor_MapPoint( segment* table, unsigned size, double x );
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-LinearSpaceAdaptor* LinearSpaceAdaptor_New( Name name, AbstractContext* context ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(LinearSpaceAdaptor);
-	Type                                                      type = LinearSpaceAdaptor_Type;
-	Stg_Class_DeleteFunction*                              _delete = _LinearSpaceAdaptor_Delete;
-	Stg_Class_PrintFunction*                                _print = _LinearSpaceAdaptor_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_LinearSpaceAdaptor_New;
-	Stg_Component_ConstructFunction*                    _construct = _LinearSpaceAdaptor_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _LinearSpaceAdaptor_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _LinearSpaceAdaptor_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _LinearSpaceAdaptor_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _LinearSpaceAdaptor_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	MeshGenerator_SetDimSizeFunc*                   setDimSizeFunc = _MeshGenerator_SetDimSize;
-	MeshGenerator_GenerateFunc*                       generateFunc = LinearSpaceAdaptor_Generate;
-
-   LinearSpaceAdaptor* self = _LinearSpaceAdaptor_New(  LINEARSPACEADAPTOR_PASSARGS  );
-
-   _MeshGenerator_Init( (MeshGenerator*)self, context );
-   _MeshAdaptor_Init( (MeshAdaptor*)self );
-	_LinearSpaceAdaptor_Init( self );
-
-   return self;
-}
-
-LinearSpaceAdaptor* _LinearSpaceAdaptor_New(  LINEARSPACEADAPTOR_DEFARGS  ) {
-	LinearSpaceAdaptor* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(LinearSpaceAdaptor) );
-	self = (LinearSpaceAdaptor*)_MeshAdaptor_New(  MESHADAPTOR_PASSARGS  );
-
-	/* Virtual info */
-	return self;
-}
-
-void _LinearSpaceAdaptor_Init( LinearSpaceAdaptor* self ) {}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _LinearSpaceAdaptor_Delete( void* adaptor ) {
-	LinearSpaceAdaptor*	self = (LinearSpaceAdaptor*)adaptor;
-
-	/* Delete the parent. */
-	_MeshAdaptor_Delete( self );
-}
-
-void _LinearSpaceAdaptor_Print( void* adaptor, Stream* stream ) {
-	LinearSpaceAdaptor*	self = (LinearSpaceAdaptor*)adaptor;
-	
-	/* Set the Journal for printing informations */
-	Stream* adaptorStream;
-	adaptorStream = Journal_Register( InfoStream_Type, (Name)"LinearSpaceAdaptorStream"  );
-
-	/* Print parent */
-	Journal_Printf( stream, "LinearSpaceAdaptor (ptr): (%p)\n", self );
-	_MeshAdaptor_Print( self, stream );
-}
-
-void _LinearSpaceAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
-	LinearSpaceAdaptor*	self = (LinearSpaceAdaptor*)adaptor;
-	Dictionary_Entry_Value* optionsList;
-	Dictionary_Entry_Value* optionSet;
-	Index                   segmentCount;
-	Index                   segment_I;
-	segment*                seg;
-	Dictionary*             dictionary  = Dictionary_GetDictionary( cf->componentDict, self->name );
-	AbstractContext*        context;
-
-	assert( self );
-	assert( cf );
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, True, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
-	self->loadFromCheckPoint = context->loadFromCheckPoint;
-
-	if( self->loadFromCheckPoint  )
-	  return;
-
-	/* Call parent construct. */
-	_MeshAdaptor_AssignFromXML( self, cf, data );
-
-	self->minX = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minX" )  );
-	self->maxX = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxX" )  );
-	self->minY = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minY" )  );
-	self->maxY = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxY" )  );
-	self->minZ = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minZ" )  );
-	self->maxZ = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxZ" )  );
-
-	/* Read maping functions - X axis*/
-        optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionX" );
-
-	if( optionsList ) {
-	  segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
-	  self->nSegmentsx = segmentCount;
-
-	  self->tablex = Memory_Alloc_Array( segment , segmentCount, "mapping table x" );
-	  memset( self->tablex, 0, segmentCount * sizeof(segment) );
-
-	  for ( segment_I = 0 ; segment_I < segmentCount ; segment_I++) { 
-	    optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
-	    seg = &(self->tablex[segment_I]);
-	    seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" )  );
-	    seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" )  );
-	  }
-	  LinearSpaceAdaptor_FillTable( self->tablex, segmentCount );
-	} else {
-	  self->nSegmentsx = 0;
-	}
-
-
-	/* Read maping functions - Y axis*/
-        optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionY" );
-	
-	if( optionsList ) {
-	  segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
-	  self->nSegmentsy = segmentCount;
-
-	  self->tabley = Memory_Alloc_Array( segment , segmentCount, "mapping table y" );
-	  memset( self->tabley, 0, segmentCount * sizeof(segment) );
-
-	  for ( segment_I = 0; segment_I < segmentCount; segment_I++) { 
-	    optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
-	    seg = &(self->tabley[segment_I]);
-	    seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" )  );
-	    seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" )  );
-	  }
-	  LinearSpaceAdaptor_FillTable( self->tabley, segmentCount );
-	} else {
- 	  self->nSegmentsy = 0;
-	}
-
-
-	/* Read maping functions - Z axis*/
-        optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionZ" );
-	
-	if( optionsList ) {
-	  segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
-	  self->nSegmentsz = segmentCount;
-
-	  self->tablez = Memory_Alloc_Array( segment , segmentCount, "mapping table x" );
-	  memset( self->tablez, 0, segmentCount * sizeof(segment) );
-
-	  for ( segment_I = 0 ; segment_I < segmentCount ; segment_I++) { 
-	    optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
-	    seg = &(self->tablez[segment_I]);
-	    seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" )  );
-	    seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" )  );
-	  }
-	  LinearSpaceAdaptor_FillTable( self->tablez, segmentCount );
-	} else {
- 	  self->nSegmentsz = 0;
-	}
-
-	_LinearSpaceAdaptor_Init( self );
-}
-
-void _LinearSpaceAdaptor_Build( void* adaptor, void* data ) {
-	_MeshAdaptor_Build( adaptor, data );
-}
-
-void _LinearSpaceAdaptor_Initialise( void* adaptor, void* data ) {
-	_MeshAdaptor_Initialise( adaptor, data );
-}
-
-void _LinearSpaceAdaptor_Execute( void* adaptor, void* data ) {
-}
-
-void _LinearSpaceAdaptor_Destroy( void* adaptor, void* data ) {
-   LinearSpaceAdaptor*		self = (LinearSpaceAdaptor*)adaptor;
-
-   Memory_Free( self->tablex );
-   Memory_Free( self->tabley );
-   Memory_Free( self->tablez );
-
-   _MeshAdaptor_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void LinearSpaceAdaptor_Generate( void* adaptor, void* _mesh, void* data ) {
-
-  LinearSpaceAdaptor*		self = (LinearSpaceAdaptor*)adaptor;
-  Mesh*				mesh = (Mesh*)_mesh;
-  const Sync*			sync;
-  double			x;
-  int   			n_i;
-
-  /* Build base mesh, which is assumed to be cartesian. */
-  MeshGenerator_Generate( self->generator, mesh, data );
-
-  if( self->loadFromCheckPoint )
-    return;
-
-  /* Loop over domain nodes. */
-  sync = IGraph_GetDomain( mesh->topo, MT_VERTEX );
-  
-  if( self->nSegmentsx > 0 ) {
-    for( n_i = 0; n_i < Sync_GetNumDomains( sync ); n_i++ ) {
-      /* get the x coord */
-      x = mesh->verts[n_i][I_AXIS];      
-
-      if( x != self->minX && x != self->maxX ) {	      
-	/* normalize the x coord*/
-	x = (x - self->minX) / (self->maxX - self->minX);
-	/* map the normalized point */
-	x = LinearSpaceAdaptor_MapPoint( self->tablex, self->nSegmentsx, x  );
-	/* denormalize mapped point */
-	x = (self->maxX - self->minX)*x + self->minX;
-	/* move the node */
-	mesh->verts[n_i][I_AXIS] = x;
-      }
-    }
-  }
-
-  if( self->nSegmentsy > 0 ) {
-    for( n_i = 0; n_i < Sync_GetNumDomains( sync ); n_i++ ) {
-      /* get the y coord */
-      x = mesh->verts[n_i][J_AXIS];      
-
-      if( x != self->minY && x != self->maxY ) {
-	/* normalize the y coord*/
-	x = (x - self->minY) / (self->maxY - self->minY);
-	/* map the normalized point */
-	x = LinearSpaceAdaptor_MapPoint( self->tabley, self->nSegmentsy, x  );
-	/* denormalize mapped point */
-	x = (self->maxY - self->minY)*x + self->minY;
-	/* move the node */
-	mesh->verts[n_i][J_AXIS] = x;
-      }
-    }
-  }  
-
-  if( self->nSegmentsz > 0 ) {
-    for( n_i = 0; n_i < Sync_GetNumDomains( sync ); n_i++ ) {
-      /* get the x coord */
-      x = mesh->verts[n_i][K_AXIS];
-
-      if( x != self->minZ && x != self->maxZ ) {	      
-	/* normalize the z coord*/
-	x = (x - self->minZ) / (self->maxZ - self->minZ);
-	/* map the normalized point */
-	x = LinearSpaceAdaptor_MapPoint( self->tablez, self->nSegmentsz, x  );
-	/* denormalize mapped point */
-	x = (self->maxZ - self->minZ)*x + self->minZ;
-	/* move the node */
-	mesh->verts[n_i][K_AXIS] = x;
-      }
-      /*	    
-	FILE* fh;
-	fh = fopen( "coords.txt", "a+");
-	if( fh != NULL )
-	fprintf( fh, "%g\t%g\n", mesh->verts[n_i][I_AXIS], mesh->verts[n_i][J_AXIS] );		
-	fclose( fh );*/
-    }
-  }
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-void LinearSpaceAdaptor_FillTable( segment* table, unsigned size  ) {
-
-  Index i;
-
-  table[0].p  = table[0].y / table[0].x;
-  table[0].y0 = 0; 
-  for( i = 1; i < size; i++ ){
-    table[i].p  = (table[i].y - table[i-1].y) / (table[i].x - table[i-1].x);
-    table[i].y0 = table[i-1].y;
-  }
-}
-
-double LinearSpaceAdaptor_MapPoint( segment* table, unsigned size, double x  ) {
-
-  Index i;
-
-  if( x < table[0].x )
-    return x * table[0].p + table[0].y0;
-
-  for( i = 1; i < size; i++ ){
-    if( x < table[i].x )
-      return (x - table[i-1].x) * table[i].p + table[i].y0;
-  }
-  return 0;
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/src/linearSpaceAdaptor.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/src/linearSpaceAdaptor.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,371 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: LinearSpaceAdaptor.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Grid.h"
+#include "Decomp.h"
+#include "Sync.h"
+#include "MeshTopology.h"
+#include "IGraph.h"
+#include "MeshClass.h"
+#include "MeshGenerator.h"
+#include "MeshAdaptor.h"
+#include "linearSpaceAdaptor.h"
+
+
+typedef double (LinearSpaceAdaptor_DeformFunc)( LinearSpaceAdaptor* self, Mesh* mesh, 
+					    unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
+
+
+/* Textual name of this class */
+const Type LinearSpaceAdaptor_Type = "LinearSpaceAdaptor";
+
+
+
+/* My private functions */
+void   LinearSpaceAdaptor_FillTable( segment* table, unsigned size  );
+double LinearSpaceAdaptor_MapPoint( segment* table, unsigned size, double x );
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+LinearSpaceAdaptor* LinearSpaceAdaptor_New( Name name, AbstractContext* context ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(LinearSpaceAdaptor);
+	Type                                                      type = LinearSpaceAdaptor_Type;
+	Stg_Class_DeleteFunction*                              _delete = _LinearSpaceAdaptor_Delete;
+	Stg_Class_PrintFunction*                                _print = _LinearSpaceAdaptor_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void* (*)(Name))_LinearSpaceAdaptor_New;
+	Stg_Component_ConstructFunction*                    _construct = _LinearSpaceAdaptor_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _LinearSpaceAdaptor_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _LinearSpaceAdaptor_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _LinearSpaceAdaptor_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _LinearSpaceAdaptor_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	MeshGenerator_SetDimSizeFunc*                   setDimSizeFunc = _MeshGenerator_SetDimSize;
+	MeshGenerator_GenerateFunc*                       generateFunc = LinearSpaceAdaptor_Generate;
+
+   LinearSpaceAdaptor* self = _LinearSpaceAdaptor_New(  LINEARSPACEADAPTOR_PASSARGS  );
+
+   _MeshGenerator_Init( (MeshGenerator*)self, context );
+   _MeshAdaptor_Init( (MeshAdaptor*)self );
+	_LinearSpaceAdaptor_Init( self );
+
+   return self;
+}
+
+LinearSpaceAdaptor* _LinearSpaceAdaptor_New(  LINEARSPACEADAPTOR_DEFARGS  ) {
+	LinearSpaceAdaptor* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(LinearSpaceAdaptor) );
+	self = (LinearSpaceAdaptor*)_MeshAdaptor_New(  MESHADAPTOR_PASSARGS  );
+
+	/* Virtual info */
+	return self;
+}
+
+void _LinearSpaceAdaptor_Init( LinearSpaceAdaptor* self ) {}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _LinearSpaceAdaptor_Delete( void* adaptor ) {
+	LinearSpaceAdaptor*	self = (LinearSpaceAdaptor*)adaptor;
+
+	/* Delete the parent. */
+	_MeshAdaptor_Delete( self );
+}
+
+void _LinearSpaceAdaptor_Print( void* adaptor, Stream* stream ) {
+	LinearSpaceAdaptor*	self = (LinearSpaceAdaptor*)adaptor;
+	
+	/* Set the Journal for printing informations */
+	Stream* adaptorStream;
+	adaptorStream = Journal_Register( InfoStream_Type, (Name)"LinearSpaceAdaptorStream"  );
+
+	/* Print parent */
+	Journal_Printf( stream, "LinearSpaceAdaptor (ptr): (%p)\n", self );
+	_MeshAdaptor_Print( self, stream );
+}
+
+void _LinearSpaceAdaptor_AssignFromXML( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
+	LinearSpaceAdaptor*	self = (LinearSpaceAdaptor*)adaptor;
+	Dictionary_Entry_Value* optionsList;
+	Dictionary_Entry_Value* optionSet;
+	Index                   segmentCount;
+	Index                   segment_I;
+	segment*                seg;
+	Dictionary*             dictionary  = Dictionary_GetDictionary( cf->componentDict, self->name );
+	AbstractContext*        context;
+
+	assert( self );
+	assert( cf );
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, True, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
+	self->loadFromCheckPoint = context->loadFromCheckPoint;
+
+	if( self->loadFromCheckPoint  )
+	  return;
+
+	/* Call parent construct. */
+	_MeshAdaptor_AssignFromXML( self, cf, data );
+
+	self->minX = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minX" )  );
+	self->maxX = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxX" )  );
+	self->minY = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minY" )  );
+	self->maxY = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxY" )  );
+	self->minZ = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"minZ" )  );
+	self->maxZ = Dictionary_Entry_Value_AsDouble( Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"maxZ" )  );
+
+	/* Read maping functions - X axis*/
+        optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionX" );
+
+	if( optionsList ) {
+	  segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
+	  self->nSegmentsx = segmentCount;
+
+	  self->tablex = Memory_Alloc_Array( segment , segmentCount, "mapping table x" );
+	  memset( self->tablex, 0, segmentCount * sizeof(segment) );
+
+	  for ( segment_I = 0 ; segment_I < segmentCount ; segment_I++) { 
+	    optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
+	    seg = &(self->tablex[segment_I]);
+	    seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" )  );
+	    seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" )  );
+	  }
+	  LinearSpaceAdaptor_FillTable( self->tablex, segmentCount );
+	} else {
+	  self->nSegmentsx = 0;
+	}
+
+
+	/* Read maping functions - Y axis*/
+        optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionY" );
+	
+	if( optionsList ) {
+	  segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
+	  self->nSegmentsy = segmentCount;
+
+	  self->tabley = Memory_Alloc_Array( segment , segmentCount, "mapping table y" );
+	  memset( self->tabley, 0, segmentCount * sizeof(segment) );
+
+	  for ( segment_I = 0; segment_I < segmentCount; segment_I++) { 
+	    optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
+	    seg = &(self->tabley[segment_I]);
+	    seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" )  );
+	    seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" )  );
+	  }
+	  LinearSpaceAdaptor_FillTable( self->tabley, segmentCount );
+	} else {
+ 	  self->nSegmentsy = 0;
+	}
+
+
+	/* Read maping functions - Z axis*/
+        optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"mappingFunctionZ" );
+	
+	if( optionsList ) {
+	  segmentCount = Dictionary_Entry_Value_GetCount(optionsList );
+	  self->nSegmentsz = segmentCount;
+
+	  self->tablez = Memory_Alloc_Array( segment , segmentCount, "mapping table x" );
+	  memset( self->tablez, 0, segmentCount * sizeof(segment) );
+
+	  for ( segment_I = 0 ; segment_I < segmentCount ; segment_I++) { 
+	    optionSet = Dictionary_Entry_Value_GetElement(optionsList, segment_I );
+	    seg = &(self->tablez[segment_I]);
+	    seg->x = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"point" )  );
+	    seg->y = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"mappedTo" )  );
+	  }
+	  LinearSpaceAdaptor_FillTable( self->tablez, segmentCount );
+	} else {
+ 	  self->nSegmentsz = 0;
+	}
+
+	_LinearSpaceAdaptor_Init( self );
+}
+
+void _LinearSpaceAdaptor_Build( void* adaptor, void* data ) {
+	_MeshAdaptor_Build( adaptor, data );
+}
+
+void _LinearSpaceAdaptor_Initialise( void* adaptor, void* data ) {
+	_MeshAdaptor_Initialise( adaptor, data );
+}
+
+void _LinearSpaceAdaptor_Execute( void* adaptor, void* data ) {
+}
+
+void _LinearSpaceAdaptor_Destroy( void* adaptor, void* data ) {
+   LinearSpaceAdaptor*		self = (LinearSpaceAdaptor*)adaptor;
+
+   Memory_Free( self->tablex );
+   Memory_Free( self->tabley );
+   Memory_Free( self->tablez );
+
+   _MeshAdaptor_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void LinearSpaceAdaptor_Generate( void* adaptor, void* _mesh, void* data ) {
+
+  LinearSpaceAdaptor*		self = (LinearSpaceAdaptor*)adaptor;
+  Mesh*				mesh = (Mesh*)_mesh;
+  const Sync*			sync;
+  double			x;
+  int   			n_i;
+
+  /* Build base mesh, which is assumed to be cartesian. */
+  MeshGenerator_Generate( self->generator, mesh, data );
+
+  if( self->loadFromCheckPoint )
+    return;
+
+  /* Loop over domain nodes. */
+  sync = IGraph_GetDomain( mesh->topo, MT_VERTEX );
+  
+  if( self->nSegmentsx > 0 ) {
+    for( n_i = 0; n_i < Sync_GetNumDomains( sync ); n_i++ ) {
+      /* get the x coord */
+      x = mesh->verts[n_i][I_AXIS];      
+
+      if( x != self->minX && x != self->maxX ) {	      
+	/* normalize the x coord*/
+	x = (x - self->minX) / (self->maxX - self->minX);
+	/* map the normalized point */
+	x = LinearSpaceAdaptor_MapPoint( self->tablex, self->nSegmentsx, x  );
+	/* denormalize mapped point */
+	x = (self->maxX - self->minX)*x + self->minX;
+	/* move the node */
+	mesh->verts[n_i][I_AXIS] = x;
+      }
+    }
+  }
+
+  if( self->nSegmentsy > 0 ) {
+    for( n_i = 0; n_i < Sync_GetNumDomains( sync ); n_i++ ) {
+      /* get the y coord */
+      x = mesh->verts[n_i][J_AXIS];      
+
+      if( x != self->minY && x != self->maxY ) {
+	/* normalize the y coord*/
+	x = (x - self->minY) / (self->maxY - self->minY);
+	/* map the normalized point */
+	x = LinearSpaceAdaptor_MapPoint( self->tabley, self->nSegmentsy, x  );
+	/* denormalize mapped point */
+	x = (self->maxY - self->minY)*x + self->minY;
+	/* move the node */
+	mesh->verts[n_i][J_AXIS] = x;
+      }
+    }
+  }  
+
+  if( self->nSegmentsz > 0 ) {
+    for( n_i = 0; n_i < Sync_GetNumDomains( sync ); n_i++ ) {
+      /* get the x coord */
+      x = mesh->verts[n_i][K_AXIS];
+
+      if( x != self->minZ && x != self->maxZ ) {	      
+	/* normalize the z coord*/
+	x = (x - self->minZ) / (self->maxZ - self->minZ);
+	/* map the normalized point */
+	x = LinearSpaceAdaptor_MapPoint( self->tablez, self->nSegmentsz, x  );
+	/* denormalize mapped point */
+	x = (self->maxZ - self->minZ)*x + self->minZ;
+	/* move the node */
+	mesh->verts[n_i][K_AXIS] = x;
+      }
+      /*	    
+	FILE* fh;
+	fh = fopen( "coords.txt", "a+");
+	if( fh != NULL )
+	fprintf( fh, "%g\t%g\n", mesh->verts[n_i][I_AXIS], mesh->verts[n_i][J_AXIS] );		
+	fclose( fh );*/
+    }
+  }
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+void LinearSpaceAdaptor_FillTable( segment* table, unsigned size  ) {
+
+  Index i;
+
+  table[0].p  = table[0].y / table[0].x;
+  table[0].y0 = 0; 
+  for( i = 1; i < size; i++ ){
+    table[i].p  = (table[i].y - table[i-1].y) / (table[i].x - table[i-1].x);
+    table[i].y0 = table[i-1].y;
+  }
+}
+
+double LinearSpaceAdaptor_MapPoint( segment* table, unsigned size, double x  ) {
+
+  Index i;
+
+  if( x < table[0].x )
+    return x * table[0].p + table[0].y0;
+
+  for( i = 1; i < size; i++ ){
+    if( x < table[i].x )
+      return (x - table[i-1].x) * table[i].p + table[i].y0;
+  }
+  return 0;
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/tests/CartesianGeneratorSuite.c
--- a/Mesh/tests/CartesianGeneratorSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,413 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the CartesianGeneratorSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include "CartesianGeneratorSuite.h"
-
-typedef struct {
-	Mesh*	mesh;
-} CartesianGeneratorSuiteData;
-
-void CartesianGeneratorSuite_Setup( CartesianGeneratorSuiteData* data ) {
-	CartesianGenerator* gen;
-	int nRanks;
-	unsigned sizes[3];
-	double minCrd[3];
-	double maxCrd[3];
-
-	Journal_Enable_AllTypedStream( False );
-
-	insist( MPI_Comm_size( MPI_COMM_WORLD, &nRanks ), == MPI_SUCCESS );
-	sizes[0] = sizes[1] = sizes[2] = nRanks * 4;
-	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
-	maxCrd[0] = minCrd[1] = minCrd[2] = (double)nRanks;
-
-	gen = CartesianGenerator_New( "", NULL );
-	MeshGenerator_SetDimSize( gen, 3 );
-	CartesianGenerator_SetShadowDepth( gen, 1 );
-	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
-
-	data->mesh = Mesh_New( "", NULL );
-	CartesianGenerator_Generate( gen, data->mesh, NULL );
-   Stg_Component_Build(data->mesh, NULL, False);
-   Stg_Component_Initialise(data->mesh, NULL, False);
-}
-
-void CartesianGeneratorSuite_Teardown( CartesianGeneratorSuiteData* data ) {
-	Stg_Component_Destroy( data->mesh, NULL, True );
-
-	Journal_Enable_AllTypedStream( True );
-}
-
-void CartesianGeneratorSuite_TestElementVertexInc( CartesianGeneratorSuiteData* data ) {
-	unsigned	dim = Mesh_GetDimSize( data->mesh );
-	Sync*		elSync		= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, dim );
-	Sync*		vertSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_VERTEX );
-	Grid*		elGrid		= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "elementGrid" );
-	Grid*		vertGrid	= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "vertexGrid" );
-	IArray*		inc		= IArray_New();
-	int*	incVerts;
-	unsigned	nIncVerts;
-	unsigned	el_i;
-	unsigned	gEl;
-	unsigned	dimInds[3];
-	unsigned	gNode0, gNode1, gNode2;
-	int		checkNodes;
-
-	for(el_i=0;el_i<Mesh_GetLocalSize(data->mesh,(MeshTopology_Dim)dim);
-            el_i++ ) {
-		gEl = Sync_DomainToGlobal( elSync, el_i );
-		Grid_Lift( elGrid, gEl, dimInds );	
-
-		MeshTopology_GetIncidence( (IGraph*)data->mesh->topo, dim, el_i, MT_VERTEX, inc );
-		nIncVerts = IArray_GetSize( inc );
-		incVerts = IArray_GetPtr( inc );
-
-		pcu_check_true( nIncVerts == 8 );
-
-		gNode0 = Grid_Project( vertGrid, dimInds );
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]++;
-		gNode0++;
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]--; dimInds[1]++;
-		gNode0--; gNode0 += vertGrid->sizes[0];
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]++;
-		gNode0++;
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]--; dimInds[1]--; dimInds[2]++;
-		gNode0--; gNode0 -= vertGrid->sizes[0]; gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[4] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]++;
-		gNode0++;
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[5] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]--; dimInds[1]++;
-		gNode0--; gNode0 += vertGrid->sizes[0];
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[6] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-
-		dimInds[0]++;
-		gNode0++;
-		gNode1 = Grid_Project( vertGrid, dimInds );
-		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[7] );
-		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-		pcu_check_true( checkNodes );
-	}
-
-	NewClass_Delete( inc );
-}
-
-void CartesianGeneratorSuite_TestEdgeVertexInc( CartesianGeneratorSuiteData* data ) {
-	Grid*		elGrid		= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "elementGrid" );
-	Grid*		vertGrid	= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "vertexGrid" );
-	Grid*		edgeGrid_0	= Grid_New();
-	Grid*		edgeGrid_1	= Grid_New();
-	Grid*		edgeGrid_2	= Grid_New();
-	Sync*		vertSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_VERTEX );
-	Sync*		edgeSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_EDGE );
-	IArray*		inc		= IArray_New();
-	int*	incVerts;
-	unsigned	nIncVerts;
-	unsigned	dim		= ((IGraph*)data->mesh->topo)->nDims;
-	unsigned	sizes[3];
-	unsigned	edge_i;
-	unsigned	gEdge;
-	unsigned	dimInds[3];
-	unsigned	gNode0, gNode1, gNode2;
-	int		checkNodes;
-
-	sizes[0] = elGrid->sizes[0];
-	sizes[1] = elGrid->sizes[1] + 1;
-	sizes[2] = elGrid->sizes[2] + 1;
-	Grid_SetNumDims( edgeGrid_0, dim );
-	Grid_SetSizes( edgeGrid_0, sizes );
-	sizes[0] = elGrid->sizes[0] + 1;
-	sizes[1] = elGrid->sizes[1];
-	sizes[2] = elGrid->sizes[2] + 1;
-	Grid_SetNumDims( edgeGrid_1, dim );
-	Grid_SetSizes( edgeGrid_1, sizes );
-	sizes[0] = elGrid->sizes[0] + 1;
-	sizes[1] = elGrid->sizes[1] + 1;
-	sizes[2] = elGrid->sizes[2];
-	Grid_SetNumDims( edgeGrid_2, dim );
-	Grid_SetSizes( edgeGrid_2, sizes );
-
-	for(edge_i=0;edge_i<(unsigned)Sync_GetNumDomains(edgeSync);edge_i++) {
-		gEdge = Sync_DomainToGlobal( edgeSync, edge_i );
-
-		MeshTopology_GetIncidence( (IGraph*)data->mesh->topo, MT_EDGE, edge_i, MT_VERTEX, inc );
-		nIncVerts = IArray_GetSize( inc );
-		incVerts = IArray_GetPtr( inc );
-
-		pcu_check_true( nIncVerts == 2 );
-
-		if( gEdge < edgeGrid_0->nPoints ) {
-			Grid_Lift( edgeGrid_0, gEdge, dimInds );
-			gNode0 = Grid_Project( vertGrid, dimInds );
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0++;
-			dimInds[0]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-		}
-		else if( gEdge < edgeGrid_0->nPoints + edgeGrid_1->nPoints ) {
-			Grid_Lift( edgeGrid_1, gEdge - edgeGrid_0->nPoints, dimInds );
-			gNode0 = Grid_Project( vertGrid, dimInds );
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0 += vertGrid->sizes[0];
-			dimInds[1]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-		}
-		else if( gEdge < edgeGrid_0->nPoints + edgeGrid_1->nPoints + edgeGrid_2->nPoints ) {
-			Grid_Lift( edgeGrid_2, gEdge - edgeGrid_0->nPoints - edgeGrid_1->nPoints, dimInds );
-			gNode0 = Grid_Project( vertGrid, dimInds );
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
-			dimInds[2]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-		}
-	}
-
-	FreeObject( edgeGrid_0 );
-	FreeObject( edgeGrid_1 );
-	FreeObject( edgeGrid_2 );
-
-	NewClass_Delete( inc );
-}
-
-void CartesianGeneratorSuite_TestFaceVertexInc( CartesianGeneratorSuiteData* data ) {
-	Grid*		elGrid		= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "elementGrid" );
-	Grid*		vertGrid	= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "vertexGrid" );
-	Grid*		faceGrid_0	= Grid_New();
-	Grid*		faceGrid_1	= Grid_New();
-	Grid*		faceGrid_2	= Grid_New();
-	Sync*		vertSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_VERTEX );
-	Sync*		faceSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_FACE );
-	IArray*		inc		= IArray_New();
-	int*	incVerts;
-	unsigned	nIncVerts;
-	unsigned	dim		= ((IGraph*)data->mesh->topo)->nDims;
-	unsigned	sizes[3];
-	unsigned	face_i;
-	unsigned	gFace;
-	unsigned	dimInds[3];
-	unsigned	gNode0, gNode1, gNode2;
-	int		checkNodes;
-
-	sizes[0] = elGrid->sizes[0];
-	sizes[1] = elGrid->sizes[1];
-	sizes[2] = elGrid->sizes[2] + 1;
-	Grid_SetNumDims( faceGrid_0, dim );
-	Grid_SetSizes( faceGrid_0, sizes );
-	sizes[0] = elGrid->sizes[0];
-	sizes[1] = elGrid->sizes[1] + 1;
-	sizes[2] = elGrid->sizes[2];
-	Grid_SetNumDims( faceGrid_1, dim );
-	Grid_SetSizes( faceGrid_1, sizes );
-	sizes[0] = elGrid->sizes[0] + 1;
-	sizes[1] = elGrid->sizes[1];
-	sizes[2] = elGrid->sizes[2];
-	Grid_SetNumDims( faceGrid_2, dim );
-	Grid_SetSizes( faceGrid_2, sizes );
-
-	for(face_i = 0;
-            face_i<(unsigned)(((IGraph*)data->mesh->topo)->remotes[MT_FACE]->nDomains);
-            face_i++ ) {
-		gFace = Sync_DomainToGlobal( faceSync, face_i );
-
-		MeshTopology_GetIncidence( (IGraph*)data->mesh->topo, MT_FACE, face_i, MT_VERTEX, inc );
-		nIncVerts = IArray_GetSize( inc );
-		incVerts = IArray_GetPtr( inc );
-
-		pcu_check_true( nIncVerts == 4 );
-
-		if( gFace < faceGrid_0->nPoints ) {
-			Grid_Lift( faceGrid_0, gFace, dimInds );
-
-			gNode0 = Grid_Project( vertGrid, dimInds );
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0++;
-			dimInds[0]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0--; gNode0 += vertGrid->sizes[0];
-			dimInds[0]--; dimInds[1]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0++;
-			dimInds[0]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-		}
-		else if( gFace < faceGrid_0->nPoints + faceGrid_1->nPoints ) {
-			Grid_Lift( faceGrid_1, gFace - faceGrid_0->nPoints, dimInds );
-
-			gNode0 = Grid_Project( vertGrid, dimInds );
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0++;
-			dimInds[0]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0--; gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
-			dimInds[0]--; dimInds[2]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0++;
-			dimInds[0]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-		}
-		else if( gFace < faceGrid_0->nPoints + faceGrid_1->nPoints + faceGrid_2->nPoints ) {
-			Grid_Lift( faceGrid_2, gFace - faceGrid_0->nPoints - faceGrid_1->nPoints, dimInds );
-
-			gNode0 = Grid_Project( vertGrid, dimInds );
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0 += vertGrid->sizes[0];
-			dimInds[1]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0 -= vertGrid->sizes[0]; gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
-			dimInds[1]--; dimInds[2]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-
-			gNode0 += vertGrid->sizes[0];
-			dimInds[1]++;
-			gNode1 = Grid_Project( vertGrid, dimInds );
-			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
-			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
-			pcu_check_true( checkNodes );
-		}
-	}
-
-	FreeObject( faceGrid_0 );
-	FreeObject( faceGrid_1 );
-	FreeObject( faceGrid_2 );
-
-	NewClass_Delete( inc );
-}
-void CartesianGeneratorSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, CartesianGeneratorSuiteData );
-   pcu_suite_setFixtures( suite, CartesianGeneratorSuite_Setup, CartesianGeneratorSuite_Teardown );
-   pcu_suite_addTest( suite, CartesianGeneratorSuite_TestElementVertexInc );
-   pcu_suite_addTest( suite, CartesianGeneratorSuite_TestEdgeVertexInc );
-   pcu_suite_addTest( suite, CartesianGeneratorSuite_TestFaceVertexInc );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/tests/CartesianGeneratorSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/tests/CartesianGeneratorSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,413 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the CartesianGeneratorSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include "CartesianGeneratorSuite.h"
+
+typedef struct {
+	Mesh*	mesh;
+} CartesianGeneratorSuiteData;
+
+void CartesianGeneratorSuite_Setup( CartesianGeneratorSuiteData* data ) {
+	CartesianGenerator* gen;
+	int nRanks;
+	unsigned sizes[3];
+	double minCrd[3];
+	double maxCrd[3];
+
+	Journal_Enable_AllTypedStream( False );
+
+	insist( MPI_Comm_size( MPI_COMM_WORLD, &nRanks ), == MPI_SUCCESS );
+	sizes[0] = sizes[1] = sizes[2] = nRanks * 4;
+	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
+	maxCrd[0] = minCrd[1] = minCrd[2] = (double)nRanks;
+
+	gen = CartesianGenerator_New( "", NULL );
+	MeshGenerator_SetDimSize( gen, 3 );
+	CartesianGenerator_SetShadowDepth( gen, 1 );
+	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
+
+	data->mesh = Mesh_New( "", NULL );
+	CartesianGenerator_Generate( gen, data->mesh, NULL );
+   Stg_Component_Build(data->mesh, NULL, False);
+   Stg_Component_Initialise(data->mesh, NULL, False);
+}
+
+void CartesianGeneratorSuite_Teardown( CartesianGeneratorSuiteData* data ) {
+	Stg_Component_Destroy( data->mesh, NULL, True );
+
+	Journal_Enable_AllTypedStream( True );
+}
+
+void CartesianGeneratorSuite_TestElementVertexInc( CartesianGeneratorSuiteData* data ) {
+	unsigned	dim = Mesh_GetDimSize( data->mesh );
+	Sync*		elSync		= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, dim );
+	Sync*		vertSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_VERTEX );
+	Grid*		elGrid		= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "elementGrid" );
+	Grid*		vertGrid	= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "vertexGrid" );
+	IArray*		inc		= IArray_New();
+	int*	incVerts;
+	unsigned	nIncVerts;
+	unsigned	el_i;
+	unsigned	gEl;
+	unsigned	dimInds[3];
+	unsigned	gNode0, gNode1, gNode2;
+	int		checkNodes;
+
+	for(el_i=0;el_i<Mesh_GetLocalSize(data->mesh,(MeshTopology_Dim)dim);
+            el_i++ ) {
+		gEl = Sync_DomainToGlobal( elSync, el_i );
+		Grid_Lift( elGrid, gEl, dimInds );	
+
+		MeshTopology_GetIncidence( (IGraph*)data->mesh->topo, dim, el_i, MT_VERTEX, inc );
+		nIncVerts = IArray_GetSize( inc );
+		incVerts = IArray_GetPtr( inc );
+
+		pcu_check_true( nIncVerts == 8 );
+
+		gNode0 = Grid_Project( vertGrid, dimInds );
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]++;
+		gNode0++;
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]--; dimInds[1]++;
+		gNode0--; gNode0 += vertGrid->sizes[0];
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]++;
+		gNode0++;
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]--; dimInds[1]--; dimInds[2]++;
+		gNode0--; gNode0 -= vertGrid->sizes[0]; gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[4] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]++;
+		gNode0++;
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[5] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]--; dimInds[1]++;
+		gNode0--; gNode0 += vertGrid->sizes[0];
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[6] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+
+		dimInds[0]++;
+		gNode0++;
+		gNode1 = Grid_Project( vertGrid, dimInds );
+		gNode2 = Sync_DomainToGlobal( vertSync, incVerts[7] );
+		checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+		pcu_check_true( checkNodes );
+	}
+
+	NewClass_Delete( inc );
+}
+
+void CartesianGeneratorSuite_TestEdgeVertexInc( CartesianGeneratorSuiteData* data ) {
+	Grid*		elGrid		= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "elementGrid" );
+	Grid*		vertGrid	= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "vertexGrid" );
+	Grid*		edgeGrid_0	= Grid_New();
+	Grid*		edgeGrid_1	= Grid_New();
+	Grid*		edgeGrid_2	= Grid_New();
+	Sync*		vertSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_VERTEX );
+	Sync*		edgeSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_EDGE );
+	IArray*		inc		= IArray_New();
+	int*	incVerts;
+	unsigned	nIncVerts;
+	unsigned	dim		= ((IGraph*)data->mesh->topo)->nDims;
+	unsigned	sizes[3];
+	unsigned	edge_i;
+	unsigned	gEdge;
+	unsigned	dimInds[3];
+	unsigned	gNode0, gNode1, gNode2;
+	int		checkNodes;
+
+	sizes[0] = elGrid->sizes[0];
+	sizes[1] = elGrid->sizes[1] + 1;
+	sizes[2] = elGrid->sizes[2] + 1;
+	Grid_SetNumDims( edgeGrid_0, dim );
+	Grid_SetSizes( edgeGrid_0, sizes );
+	sizes[0] = elGrid->sizes[0] + 1;
+	sizes[1] = elGrid->sizes[1];
+	sizes[2] = elGrid->sizes[2] + 1;
+	Grid_SetNumDims( edgeGrid_1, dim );
+	Grid_SetSizes( edgeGrid_1, sizes );
+	sizes[0] = elGrid->sizes[0] + 1;
+	sizes[1] = elGrid->sizes[1] + 1;
+	sizes[2] = elGrid->sizes[2];
+	Grid_SetNumDims( edgeGrid_2, dim );
+	Grid_SetSizes( edgeGrid_2, sizes );
+
+	for(edge_i=0;edge_i<(unsigned)Sync_GetNumDomains(edgeSync);edge_i++) {
+		gEdge = Sync_DomainToGlobal( edgeSync, edge_i );
+
+		MeshTopology_GetIncidence( (IGraph*)data->mesh->topo, MT_EDGE, edge_i, MT_VERTEX, inc );
+		nIncVerts = IArray_GetSize( inc );
+		incVerts = IArray_GetPtr( inc );
+
+		pcu_check_true( nIncVerts == 2 );
+
+		if( gEdge < edgeGrid_0->nPoints ) {
+			Grid_Lift( edgeGrid_0, gEdge, dimInds );
+			gNode0 = Grid_Project( vertGrid, dimInds );
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0++;
+			dimInds[0]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+		}
+		else if( gEdge < edgeGrid_0->nPoints + edgeGrid_1->nPoints ) {
+			Grid_Lift( edgeGrid_1, gEdge - edgeGrid_0->nPoints, dimInds );
+			gNode0 = Grid_Project( vertGrid, dimInds );
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0 += vertGrid->sizes[0];
+			dimInds[1]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+		}
+		else if( gEdge < edgeGrid_0->nPoints + edgeGrid_1->nPoints + edgeGrid_2->nPoints ) {
+			Grid_Lift( edgeGrid_2, gEdge - edgeGrid_0->nPoints - edgeGrid_1->nPoints, dimInds );
+			gNode0 = Grid_Project( vertGrid, dimInds );
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
+			dimInds[2]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+		}
+	}
+
+	FreeObject( edgeGrid_0 );
+	FreeObject( edgeGrid_1 );
+	FreeObject( edgeGrid_2 );
+
+	NewClass_Delete( inc );
+}
+
+void CartesianGeneratorSuite_TestFaceVertexInc( CartesianGeneratorSuiteData* data ) {
+	Grid*		elGrid		= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "elementGrid" );
+	Grid*		vertGrid	= *(Grid**)Mesh_GetExtension( data->mesh, Grid**, "vertexGrid" );
+	Grid*		faceGrid_0	= Grid_New();
+	Grid*		faceGrid_1	= Grid_New();
+	Grid*		faceGrid_2	= Grid_New();
+	Sync*		vertSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_VERTEX );
+	Sync*		faceSync	= (Sync*)IGraph_GetDomain( (IGraph*)data->mesh->topo, MT_FACE );
+	IArray*		inc		= IArray_New();
+	int*	incVerts;
+	unsigned	nIncVerts;
+	unsigned	dim		= ((IGraph*)data->mesh->topo)->nDims;
+	unsigned	sizes[3];
+	unsigned	face_i;
+	unsigned	gFace;
+	unsigned	dimInds[3];
+	unsigned	gNode0, gNode1, gNode2;
+	int		checkNodes;
+
+	sizes[0] = elGrid->sizes[0];
+	sizes[1] = elGrid->sizes[1];
+	sizes[2] = elGrid->sizes[2] + 1;
+	Grid_SetNumDims( faceGrid_0, dim );
+	Grid_SetSizes( faceGrid_0, sizes );
+	sizes[0] = elGrid->sizes[0];
+	sizes[1] = elGrid->sizes[1] + 1;
+	sizes[2] = elGrid->sizes[2];
+	Grid_SetNumDims( faceGrid_1, dim );
+	Grid_SetSizes( faceGrid_1, sizes );
+	sizes[0] = elGrid->sizes[0] + 1;
+	sizes[1] = elGrid->sizes[1];
+	sizes[2] = elGrid->sizes[2];
+	Grid_SetNumDims( faceGrid_2, dim );
+	Grid_SetSizes( faceGrid_2, sizes );
+
+	for(face_i = 0;
+            face_i<(unsigned)(((IGraph*)data->mesh->topo)->remotes[MT_FACE]->nDomains);
+            face_i++ ) {
+		gFace = Sync_DomainToGlobal( faceSync, face_i );
+
+		MeshTopology_GetIncidence( (IGraph*)data->mesh->topo, MT_FACE, face_i, MT_VERTEX, inc );
+		nIncVerts = IArray_GetSize( inc );
+		incVerts = IArray_GetPtr( inc );
+
+		pcu_check_true( nIncVerts == 4 );
+
+		if( gFace < faceGrid_0->nPoints ) {
+			Grid_Lift( faceGrid_0, gFace, dimInds );
+
+			gNode0 = Grid_Project( vertGrid, dimInds );
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0++;
+			dimInds[0]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0--; gNode0 += vertGrid->sizes[0];
+			dimInds[0]--; dimInds[1]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0++;
+			dimInds[0]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+		}
+		else if( gFace < faceGrid_0->nPoints + faceGrid_1->nPoints ) {
+			Grid_Lift( faceGrid_1, gFace - faceGrid_0->nPoints, dimInds );
+
+			gNode0 = Grid_Project( vertGrid, dimInds );
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0++;
+			dimInds[0]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0--; gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
+			dimInds[0]--; dimInds[2]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0++;
+			dimInds[0]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+		}
+		else if( gFace < faceGrid_0->nPoints + faceGrid_1->nPoints + faceGrid_2->nPoints ) {
+			Grid_Lift( faceGrid_2, gFace - faceGrid_0->nPoints - faceGrid_1->nPoints, dimInds );
+
+			gNode0 = Grid_Project( vertGrid, dimInds );
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[0] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0 += vertGrid->sizes[0];
+			dimInds[1]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[1] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0 -= vertGrid->sizes[0]; gNode0 += vertGrid->sizes[0] * vertGrid->sizes[1];
+			dimInds[1]--; dimInds[2]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[2] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+
+			gNode0 += vertGrid->sizes[0];
+			dimInds[1]++;
+			gNode1 = Grid_Project( vertGrid, dimInds );
+			gNode2 = Sync_DomainToGlobal( vertSync, incVerts[3] );
+			checkNodes = (gNode0 == gNode1) && (gNode1 == gNode2);
+			pcu_check_true( checkNodes );
+		}
+	}
+
+	FreeObject( faceGrid_0 );
+	FreeObject( faceGrid_1 );
+	FreeObject( faceGrid_2 );
+
+	NewClass_Delete( inc );
+}
+void CartesianGeneratorSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, CartesianGeneratorSuiteData );
+   pcu_suite_setFixtures( suite, CartesianGeneratorSuite_Setup, CartesianGeneratorSuite_Teardown );
+   pcu_suite_addTest( suite, CartesianGeneratorSuite_TestElementVertexInc );
+   pcu_suite_addTest( suite, CartesianGeneratorSuite_TestEdgeVertexInc );
+   pcu_suite_addTest( suite, CartesianGeneratorSuite_TestFaceVertexInc );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/tests/DecompSuite.c
--- a/Mesh/tests/DecompSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,124 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the DecompSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "DecompSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} DecompSuiteData;
-
-void DecompSuite_Setup( DecompSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void DecompSuite_Teardown( DecompSuiteData* data ) {
-}
-
-void DecompSuite_TestDecomp( DecompSuiteData* data ) {
-	Decomp*	decomp;
-	int		nLocs, *locs, *ranks;
-   int		l_i, g_i;
-
-	nLocs = 10;
-	locs = MemArray( int, nLocs, "testDecomp" );
-
-	decomp = Decomp_New();
-   for( l_i = 0; l_i < nLocs; l_i++ )
-		locs[l_i] = data->rank * nLocs + l_i;
-	pcu_check_noassert( Decomp_SetLocals( decomp, nLocs, locs ) );
-	for( g_i = 0; g_i < data->nProcs * nLocs; g_i++ ) {
-		if( g_i >= data->rank * nLocs && g_i < (data->rank + 1) * nLocs ) {
-			pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->rank );
-		}
-		else {
-			pcu_check_true( !IMap_Has( decomp->owners, g_i ) );
-		}
-	}
-
-	for( l_i = 0; l_i < nLocs; l_i++ ) {
-		locs[l_i] = (data->rank * nLocs + nLocs / 2 + l_i) % (data->nProcs * nLocs);
-   }
-	pcu_check_noassert( Decomp_SetLocals( decomp, nLocs, locs ) );
-	for( g_i = 0; g_i < data->nProcs * nLocs; g_i++ ) {
-		if( g_i >= data->rank * nLocs && g_i < (data->rank + 1) * nLocs ) {
-			if( g_i < data->rank * nLocs + nLocs / 2 ) {
-				if( data->rank > 0 ) {
-					pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->rank - 1 );
-				}
-				else {
-					pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->nProcs - 1 );
-				}
-			}
-			else {
-				pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->rank );
-			}
-		}
-		else {
-			pcu_check_true( !IMap_Has( decomp->owners, g_i ) );
-		}
-	}
-
-	locs = MemRearray( locs, int, data->nProcs * nLocs, "testDecomp" );
-	ranks = MemArray( int, data->nProcs * nLocs, "testDecomp" );
-	for( g_i = 0; g_i < data->nProcs * nLocs; g_i++ )
-		locs[g_i] = g_i;
-	pcu_check_noassert( Decomp_FindOwners( decomp, data->nProcs * nLocs, locs, ranks ) );
-
-	NewClass_Delete( decomp );
-	MemFree( locs );
-	MemFree( ranks );
-}
-
-void DecompSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, DecompSuiteData );
-   pcu_suite_setFixtures( suite, DecompSuite_Setup, DecompSuite_Teardown );
-   pcu_suite_addTest( suite, DecompSuite_TestDecomp );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/tests/DecompSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/tests/DecompSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,124 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the DecompSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "DecompSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} DecompSuiteData;
+
+void DecompSuite_Setup( DecompSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void DecompSuite_Teardown( DecompSuiteData* data ) {
+}
+
+void DecompSuite_TestDecomp( DecompSuiteData* data ) {
+	Decomp*	decomp;
+	int		nLocs, *locs, *ranks;
+   int		l_i, g_i;
+
+	nLocs = 10;
+	locs = MemArray( int, nLocs, "testDecomp" );
+
+	decomp = Decomp_New();
+   for( l_i = 0; l_i < nLocs; l_i++ )
+		locs[l_i] = data->rank * nLocs + l_i;
+	pcu_check_noassert( Decomp_SetLocals( decomp, nLocs, locs ) );
+	for( g_i = 0; g_i < data->nProcs * nLocs; g_i++ ) {
+		if( g_i >= data->rank * nLocs && g_i < (data->rank + 1) * nLocs ) {
+			pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->rank );
+		}
+		else {
+			pcu_check_true( !IMap_Has( decomp->owners, g_i ) );
+		}
+	}
+
+	for( l_i = 0; l_i < nLocs; l_i++ ) {
+		locs[l_i] = (data->rank * nLocs + nLocs / 2 + l_i) % (data->nProcs * nLocs);
+   }
+	pcu_check_noassert( Decomp_SetLocals( decomp, nLocs, locs ) );
+	for( g_i = 0; g_i < data->nProcs * nLocs; g_i++ ) {
+		if( g_i >= data->rank * nLocs && g_i < (data->rank + 1) * nLocs ) {
+			if( g_i < data->rank * nLocs + nLocs / 2 ) {
+				if( data->rank > 0 ) {
+					pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->rank - 1 );
+				}
+				else {
+					pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->nProcs - 1 );
+				}
+			}
+			else {
+				pcu_check_true( IMap_Map( decomp->owners, g_i ) == data->rank );
+			}
+		}
+		else {
+			pcu_check_true( !IMap_Has( decomp->owners, g_i ) );
+		}
+	}
+
+	locs = MemRearray( locs, int, data->nProcs * nLocs, "testDecomp" );
+	ranks = MemArray( int, data->nProcs * nLocs, "testDecomp" );
+	for( g_i = 0; g_i < data->nProcs * nLocs; g_i++ )
+		locs[g_i] = g_i;
+	pcu_check_noassert( Decomp_FindOwners( decomp, data->nProcs * nLocs, locs, ranks ) );
+
+	NewClass_Delete( decomp );
+	MemFree( locs );
+	MemFree( ranks );
+}
+
+void DecompSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, DecompSuiteData );
+   pcu_suite_setFixtures( suite, DecompSuite_Setup, DecompSuite_Teardown );
+   pcu_suite_addTest( suite, DecompSuite_TestDecomp );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/tests/MeshSuite.c
--- a/Mesh/tests/MeshSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,269 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the MeshSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "MeshSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} MeshSuiteData;
-
-int MeshSuite_findOwner( Mesh* mesh, int vert ) {
-	IArray*	inc;
-	int		lowest, cur;
-	int		nDims;
-	int		ii;
-
-	inc = IArray_New();
-
-	nDims = Mesh_GetDimSize( mesh );
-	Mesh_GetIncidence(mesh,(MeshTopology_Dim)0,vert,(MeshTopology_Dim)nDims,
-                          inc);
-	lowest = Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)nDims,
-                                      IArray_GetPtr( inc )[0] );
-	for( ii = 1; ii < IArray_GetSize( inc ); ii++ ) {
-		cur = Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)nDims,
-                                           IArray_GetPtr( inc )[ii] );
-		if( cur < lowest )
-			lowest = cur;
-	}
-   NewClass_Delete( inc );
-   Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,lowest,(unsigned*)(&lowest));
-
-   return lowest;
-}
-
-void MeshSuite_Setup( MeshSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void MeshSuite_Teardown( MeshSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void MeshSuite_TestMeshNearVert1D( MeshSuiteData* data ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	int						nDims;
-	unsigned					sizes[3];
-	double					minCrd[3];
-	double					maxCrd[3];
-	int						nInc, *inc;
-	IArray*					incArray;
-	double*					vert;
-	int						e_i, inc_i;
-
-	sizes[0] = sizes[1] = sizes[2] = 4 * data->nProcs;
-	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
-	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
-
-	nDims = 1;
-	gen = CartesianGenerator_New( "", NULL );
-	MeshGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetShadowDepth( gen, 1 );
-	CartesianGenerator_SetTopologyParams(gen,sizes,0,NULL,NULL);
-	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetGenerator( mesh, gen );
-	Stg_Component_Build( mesh, NULL, False );
-	incArray = IArray_New();
-
-	for(e_i=0;e_i<(int)Mesh_GetDomainSize(mesh,(MeshTopology_Dim)nDims);e_i++) {
-          Mesh_GetIncidence(mesh,(MeshTopology_Dim)nDims,e_i,MT_VERTEX,incArray);
-          nInc = IArray_GetSize( incArray );
-          inc = IArray_GetPtr( incArray );
-          for( inc_i = 0; inc_i < nInc; inc_i++ ) {
-            vert = Mesh_GetVertex( mesh, inc[inc_i] );
-            if( !Mesh_NearestVertex( mesh, vert ) == inc[inc_i] ) break;
-          }
-	}
-        pcu_check_true(e_i==(int)Mesh_GetDomainSize(mesh,(MeshTopology_Dim)nDims));
-
-	NewClass_Delete( incArray );
-
-	FreeObject( gen );
-	FreeObject( mesh );
-}
-
-void MeshSuite_TestMeshNearVert2D( MeshSuiteData* data ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	int						nDims;
-	unsigned					sizes[3];
-	double					minCrd[3];
-	double					maxCrd[3];
-	int						nInc, *inc;
-	IArray*					incArray;
-	double*					vert;
-	int						e_i, inc_i;
-
-	sizes[0] = sizes[1] = sizes[2] = 4 * data->nProcs;
-	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
-	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
-
-	nDims = 2;
-	gen = CartesianGenerator_New( "", NULL );
-	MeshGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetShadowDepth( gen, 1 );
-	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetGenerator( mesh, gen );
-	Stg_Component_Build( mesh, NULL, False );
-	incArray = IArray_New();
-
-	for( e_i = 0; e_i < (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ); e_i++ ) {
-		Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims, e_i, MT_VERTEX, incArray );
- 		nInc = IArray_GetSize( incArray );
-		inc = IArray_GetPtr( incArray );
-		for( inc_i = 0; inc_i < nInc; inc_i++ ) {
-			vert = Mesh_GetVertex( mesh, inc[inc_i] );
-			if( !Mesh_NearestVertex( mesh, vert ) == inc[inc_i] ) break;
-		}
-	}
-	pcu_check_true( e_i == (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ) );
-
-	NewClass_Delete( incArray );
-
-	FreeObject( gen );
-	FreeObject( mesh );
-}
-
-void MeshSuite_TestMeshNearVert3D( MeshSuiteData* data ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	int						nDims;
-	unsigned					sizes[3];
-	double					minCrd[3];
-	double					maxCrd[3];
-	int						nInc, *inc;
-	IArray*					incArray;
-	double*					vert;
-	int						e_i, inc_i;
-
-	sizes[0] = sizes[1] = sizes[2] = 4 * data->nProcs;
-	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
-	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
-
-	nDims = 3;
-	gen = CartesianGenerator_New( "", NULL );
-	MeshGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetShadowDepth( gen, 1 );
-	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
-	
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetGenerator( mesh, gen );
-	Stg_Component_Build( mesh, NULL, False );
-	incArray = IArray_New();
-
-	for( e_i = 0; e_i < (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ); e_i++ ) {
-		Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims, e_i, MT_VERTEX, incArray );
-		nInc = IArray_GetSize( incArray );
-		inc = IArray_GetPtr( incArray );
-		for( inc_i = 0; inc_i < nInc; inc_i++ ) {
-			vert = Mesh_GetVertex( mesh, inc[inc_i] );
-			if( !Mesh_NearestVertex( mesh, vert ) == inc[inc_i] ) break;
-		}
-	}
-	pcu_check_true( e_i == (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ) );
-
-	NewClass_Delete( incArray );
-
-	FreeObject( gen );
-	FreeObject( mesh );
-}
-
-void MeshSuite_TestMeshSearch( MeshSuiteData* data ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	int						nDims;
-	unsigned					sizes[3];
-	double					minCrd[3];
-	double					maxCrd[3];
-	int						el;
-	int						ii;
-
-	sizes[0] = sizes[1] = sizes[2] = 2 * data->nProcs;
-	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
-	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
-
-	nDims = 3;
-	gen = CartesianGenerator_New( "", NULL );
-	MeshGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetShadowDepth( gen, 1 );
-	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetGenerator( mesh, gen );
-	Stg_Component_Build( mesh, NULL, False );
-
-	for( ii = 0; ii < (int)Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 ); ii++ ) {
-		if( !Mesh_SearchElements( mesh, Mesh_GetVertex( mesh, ii ),
-                                          (unsigned*)(&el) ) )
-			break;
-		if( el != MeshSuite_findOwner( mesh, ii ) )
-			break;
-	}
-	pcu_check_true(ii==(int)Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 ) );
-}
-
-void MeshSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, MeshSuiteData );
-   pcu_suite_setFixtures( suite, MeshSuite_Setup, MeshSuite_Teardown );
-   pcu_suite_addTest( suite, MeshSuite_TestMeshNearVert1D );
-   pcu_suite_addTest( suite, MeshSuite_TestMeshNearVert2D );
-   pcu_suite_addTest( suite, MeshSuite_TestMeshNearVert3D );
-   pcu_suite_addTest( suite, MeshSuite_TestMeshSearch );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Mesh/tests/MeshSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Mesh/tests/MeshSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,269 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the MeshSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "MeshSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} MeshSuiteData;
+
+int MeshSuite_findOwner( Mesh* mesh, int vert ) {
+	IArray*	inc;
+	int		lowest, cur;
+	int		nDims;
+	int		ii;
+
+	inc = IArray_New();
+
+	nDims = Mesh_GetDimSize( mesh );
+	Mesh_GetIncidence(mesh,(MeshTopology_Dim)0,vert,(MeshTopology_Dim)nDims,
+                          inc);
+	lowest = Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)nDims,
+                                      IArray_GetPtr( inc )[0] );
+	for( ii = 1; ii < IArray_GetSize( inc ); ii++ ) {
+		cur = Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)nDims,
+                                           IArray_GetPtr( inc )[ii] );
+		if( cur < lowest )
+			lowest = cur;
+	}
+   NewClass_Delete( inc );
+   Mesh_GlobalToDomain(mesh,(MeshTopology_Dim)nDims,lowest,(unsigned*)(&lowest));
+
+   return lowest;
+}
+
+void MeshSuite_Setup( MeshSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void MeshSuite_Teardown( MeshSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void MeshSuite_TestMeshNearVert1D( MeshSuiteData* data ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	int						nDims;
+	unsigned					sizes[3];
+	double					minCrd[3];
+	double					maxCrd[3];
+	int						nInc, *inc;
+	IArray*					incArray;
+	double*					vert;
+	int						e_i, inc_i;
+
+	sizes[0] = sizes[1] = sizes[2] = 4 * data->nProcs;
+	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
+	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
+
+	nDims = 1;
+	gen = CartesianGenerator_New( "", NULL );
+	MeshGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetShadowDepth( gen, 1 );
+	CartesianGenerator_SetTopologyParams(gen,sizes,0,NULL,NULL);
+	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetGenerator( mesh, gen );
+	Stg_Component_Build( mesh, NULL, False );
+	incArray = IArray_New();
+
+	for(e_i=0;e_i<(int)Mesh_GetDomainSize(mesh,(MeshTopology_Dim)nDims);e_i++) {
+          Mesh_GetIncidence(mesh,(MeshTopology_Dim)nDims,e_i,MT_VERTEX,incArray);
+          nInc = IArray_GetSize( incArray );
+          inc = IArray_GetPtr( incArray );
+          for( inc_i = 0; inc_i < nInc; inc_i++ ) {
+            vert = Mesh_GetVertex( mesh, inc[inc_i] );
+            if( !Mesh_NearestVertex( mesh, vert ) == inc[inc_i] ) break;
+          }
+	}
+        pcu_check_true(e_i==(int)Mesh_GetDomainSize(mesh,(MeshTopology_Dim)nDims));
+
+	NewClass_Delete( incArray );
+
+	FreeObject( gen );
+	FreeObject( mesh );
+}
+
+void MeshSuite_TestMeshNearVert2D( MeshSuiteData* data ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	int						nDims;
+	unsigned					sizes[3];
+	double					minCrd[3];
+	double					maxCrd[3];
+	int						nInc, *inc;
+	IArray*					incArray;
+	double*					vert;
+	int						e_i, inc_i;
+
+	sizes[0] = sizes[1] = sizes[2] = 4 * data->nProcs;
+	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
+	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
+
+	nDims = 2;
+	gen = CartesianGenerator_New( "", NULL );
+	MeshGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetShadowDepth( gen, 1 );
+	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetGenerator( mesh, gen );
+	Stg_Component_Build( mesh, NULL, False );
+	incArray = IArray_New();
+
+	for( e_i = 0; e_i < (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ); e_i++ ) {
+		Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims, e_i, MT_VERTEX, incArray );
+ 		nInc = IArray_GetSize( incArray );
+		inc = IArray_GetPtr( incArray );
+		for( inc_i = 0; inc_i < nInc; inc_i++ ) {
+			vert = Mesh_GetVertex( mesh, inc[inc_i] );
+			if( !Mesh_NearestVertex( mesh, vert ) == inc[inc_i] ) break;
+		}
+	}
+	pcu_check_true( e_i == (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ) );
+
+	NewClass_Delete( incArray );
+
+	FreeObject( gen );
+	FreeObject( mesh );
+}
+
+void MeshSuite_TestMeshNearVert3D( MeshSuiteData* data ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	int						nDims;
+	unsigned					sizes[3];
+	double					minCrd[3];
+	double					maxCrd[3];
+	int						nInc, *inc;
+	IArray*					incArray;
+	double*					vert;
+	int						e_i, inc_i;
+
+	sizes[0] = sizes[1] = sizes[2] = 4 * data->nProcs;
+	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
+	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
+
+	nDims = 3;
+	gen = CartesianGenerator_New( "", NULL );
+	MeshGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetShadowDepth( gen, 1 );
+	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
+	
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetGenerator( mesh, gen );
+	Stg_Component_Build( mesh, NULL, False );
+	incArray = IArray_New();
+
+	for( e_i = 0; e_i < (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ); e_i++ ) {
+		Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims, e_i, MT_VERTEX, incArray );
+		nInc = IArray_GetSize( incArray );
+		inc = IArray_GetPtr( incArray );
+		for( inc_i = 0; inc_i < nInc; inc_i++ ) {
+			vert = Mesh_GetVertex( mesh, inc[inc_i] );
+			if( !Mesh_NearestVertex( mesh, vert ) == inc[inc_i] ) break;
+		}
+	}
+	pcu_check_true( e_i == (int)Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ) );
+
+	NewClass_Delete( incArray );
+
+	FreeObject( gen );
+	FreeObject( mesh );
+}
+
+void MeshSuite_TestMeshSearch( MeshSuiteData* data ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	int						nDims;
+	unsigned					sizes[3];
+	double					minCrd[3];
+	double					maxCrd[3];
+	int						el;
+	int						ii;
+
+	sizes[0] = sizes[1] = sizes[2] = 2 * data->nProcs;
+	minCrd[0] = minCrd[1] = minCrd[2] = 0.0;
+	maxCrd[0] = maxCrd[1] = maxCrd[2] = (double)data->nProcs;
+
+	nDims = 3;
+	gen = CartesianGenerator_New( "", NULL );
+	MeshGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetShadowDepth( gen, 1 );
+	CartesianGenerator_SetTopologyParams( gen, sizes, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrd, maxCrd );
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetGenerator( mesh, gen );
+	Stg_Component_Build( mesh, NULL, False );
+
+	for( ii = 0; ii < (int)Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 ); ii++ ) {
+		if( !Mesh_SearchElements( mesh, Mesh_GetVertex( mesh, ii ),
+                                          (unsigned*)(&el) ) )
+			break;
+		if( el != MeshSuite_findOwner( mesh, ii ) )
+			break;
+	}
+	pcu_check_true(ii==(int)Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 ) );
+}
+
+void MeshSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, MeshSuiteData );
+   pcu_suite_setFixtures( suite, MeshSuite_Setup, MeshSuite_Teardown );
+   pcu_suite_addTest( suite, MeshSuite_TestMeshNearVert1D );
+   pcu_suite_addTest( suite, MeshSuite_TestMeshNearVert2D );
+   pcu_suite_addTest( suite, MeshSuite_TestMeshNearVert3D );
+   pcu_suite_addTest( suite, MeshSuite_TestMeshSearch );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Python/Bindings/Mesh/bindings.c
--- a/Python/Bindings/Mesh/bindings.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: bindings.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <Python.h>
-
-#include <mpi.h>
-#include "StGermain/StGermain/StGermain.h"
-#include "StGermain/Discretisation/Discretisation.h"
-#include <limits.h>
-#include "bindings.h"
-#include "misc.h"
-
-struct PyMethodDef Mesh_Python_Methods[] = {
-	{ Mesh_Python_copyright__name__,	Mesh_Python_copyright,		METH_VARARGS, Mesh_Python_copyright__doc__	},
-#if 0
-	{ Mesh_Python_New__name__,		Mesh_Python_New,		METH_VARARGS, Mesh_Python_New__doc__		},
-#endif
-	{ Mesh_Python_Print__name__,		Mesh_Python_Print,		METH_VARARGS, Mesh_Python_Print__doc__		},
-	{ Mesh_Python_Delete__name__,		Mesh_Python_Delete,		METH_VARARGS, Mesh_Python_Delete__doc__		},
-	{ Mesh_Python_GetDictionary__name__,	Mesh_Python_GetDictionary,	METH_VARARGS, Mesh_Python_GetDictionary__doc__	},
-	{ 0, 0, 0, 0 }
-};
-
-
-#if 0
-/* "New" member */
-char Mesh_Python_New__doc__[] = "Create a new Mesh";
-char Mesh_Python_New__name__[] = "New";
-PyObject* Mesh_Python_New( PyObject* self, PyObject* args ) {
-	return PyCObject_FromVoidPtr( Mesh_New(), 0 );
-}
-#endif
-
-/* "Print" member */
-char Mesh_Python_Print__doc__[] = "Print the Mesh";
-char Mesh_Python_Print__name__[] = "Print";
-PyObject* Mesh_Python_Print( PyObject* self, PyObject* args ) {
-	PyObject*	pyMesh;
-	Mesh*		mesh;
-	Stream*		stream = Journal_Register( Info_Type, (Name)"myStream" );
-	
-	/* Obtain arguements */
-	if( !PyArg_ParseTuple( args, "O:", &pyMesh ) ) {
-		return NULL;
-	}
-	mesh = (Mesh*)( PyCObject_AsVoidPtr( pyMesh ) );
-	
-	/* Run function */
-	Print( mesh, stream );
-	
-	/* Return */
-	Py_INCREF( Py_None );
-	return Py_None;
-}
-
-/* "Stg_Class_Delete" member */
-char Mesh_Python_Delete__doc__[] = "Stg_Class_Delete/destroy the Mesh";
-char Mesh_Python_Delete__name__[] = "Stg_Class_Delete";
-PyObject* Mesh_Python_Delete( PyObject* self, PyObject* args ) {
-	PyObject*	pyMesh;
-	Mesh*		mesh;
-	
-	/* Obtain arguements */
-	if( !PyArg_ParseTuple( args, "O:", &pyMesh ) ) {
-		return NULL;
-	}
-	mesh = (Mesh*)( PyCObject_AsVoidPtr( pyMesh ) );
-	
-	/* Run function */
-	Stg_Class_Delete( mesh );
-	
-	/* Return */
-	Py_INCREF( Py_None );
-	return Py_None;
-}
-
-/* "GetDictionary" member */
-char Mesh_Python_GetDictionary__doc__[] = "Get the Dictionary of the Mesh";
-char Mesh_Python_GetDictionary__name__[] = "GetDictionary";
-PyObject* Mesh_Python_GetDictionary( PyObject* self, PyObject* args ) {
-	PyObject*	pyMesh;
-	Mesh*		mesh;
-	
-	/* Obtain arguements */
-	if( !PyArg_ParseTuple( args, "O:", &pyMesh ) ) {
-		return NULL;
-	}
-	mesh = (Mesh*)( PyCObject_AsVoidPtr( pyMesh ) );
-	
-	return PyCObject_FromVoidPtr( mesh->dictionary, 0 );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Python/Bindings/Mesh/bindings.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Python/Bindings/Mesh/bindings.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,120 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: bindings.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <Python.h>
+
+#include <mpi.h>
+#include "StGermain/StGermain/StGermain.h"
+#include "StGermain/Discretisation/Discretisation.h"
+#include <limits.h>
+#include "bindings.h"
+#include "misc.h"
+
+struct PyMethodDef Mesh_Python_Methods[] = {
+	{ Mesh_Python_copyright__name__,	Mesh_Python_copyright,		METH_VARARGS, Mesh_Python_copyright__doc__	},
+#if 0
+	{ Mesh_Python_New__name__,		Mesh_Python_New,		METH_VARARGS, Mesh_Python_New__doc__		},
+#endif
+	{ Mesh_Python_Print__name__,		Mesh_Python_Print,		METH_VARARGS, Mesh_Python_Print__doc__		},
+	{ Mesh_Python_Delete__name__,		Mesh_Python_Delete,		METH_VARARGS, Mesh_Python_Delete__doc__		},
+	{ Mesh_Python_GetDictionary__name__,	Mesh_Python_GetDictionary,	METH_VARARGS, Mesh_Python_GetDictionary__doc__	},
+	{ 0, 0, 0, 0 }
+};
+
+
+#if 0
+/* "New" member */
+char Mesh_Python_New__doc__[] = "Create a new Mesh";
+char Mesh_Python_New__name__[] = "New";
+PyObject* Mesh_Python_New( PyObject* self, PyObject* args ) {
+	return PyCObject_FromVoidPtr( Mesh_New(), 0 );
+}
+#endif
+
+/* "Print" member */
+char Mesh_Python_Print__doc__[] = "Print the Mesh";
+char Mesh_Python_Print__name__[] = "Print";
+PyObject* Mesh_Python_Print( PyObject* self, PyObject* args ) {
+	PyObject*	pyMesh;
+	Mesh*		mesh;
+	Stream*		stream = Journal_Register( Info_Type, (Name)"myStream" );
+	
+	/* Obtain arguements */
+	if( !PyArg_ParseTuple( args, "O:", &pyMesh ) ) {
+		return NULL;
+	}
+	mesh = (Mesh*)( PyCObject_AsVoidPtr( pyMesh ) );
+	
+	/* Run function */
+	Print( mesh, stream );
+	
+	/* Return */
+	Py_INCREF( Py_None );
+	return Py_None;
+}
+
+/* "Stg_Class_Delete" member */
+char Mesh_Python_Delete__doc__[] = "Stg_Class_Delete/destroy the Mesh";
+char Mesh_Python_Delete__name__[] = "Stg_Class_Delete";
+PyObject* Mesh_Python_Delete( PyObject* self, PyObject* args ) {
+	PyObject*	pyMesh;
+	Mesh*		mesh;
+	
+	/* Obtain arguements */
+	if( !PyArg_ParseTuple( args, "O:", &pyMesh ) ) {
+		return NULL;
+	}
+	mesh = (Mesh*)( PyCObject_AsVoidPtr( pyMesh ) );
+	
+	/* Run function */
+	Stg_Class_Delete( mesh );
+	
+	/* Return */
+	Py_INCREF( Py_None );
+	return Py_None;
+}
+
+/* "GetDictionary" member */
+char Mesh_Python_GetDictionary__doc__[] = "Get the Dictionary of the Mesh";
+char Mesh_Python_GetDictionary__name__[] = "GetDictionary";
+PyObject* Mesh_Python_GetDictionary( PyObject* self, PyObject* args ) {
+	PyObject*	pyMesh;
+	Mesh*		mesh;
+	
+	/* Obtain arguements */
+	if( !PyArg_ParseTuple( args, "O:", &pyMesh ) ) {
+		return NULL;
+	}
+	mesh = (Mesh*)( PyCObject_AsVoidPtr( pyMesh ) );
+	
+	return PyCObject_FromVoidPtr( mesh->dictionary, 0 );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Python/Bindings/Mesh/init.c
--- a/Python/Bindings/Mesh/init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: init.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <Python.h>
-#include "bindings.h"
-#include "misc.h"
-
-char Mesh_Python__doc__[] = "Mesh maintains the state of the discretised information in terms of nodes and elements. ";
-
-void initMesh() {
-	Py_InitModule4( "Mesh", Mesh_Python_Methods, Mesh_Python__doc__, 0, PYTHON_API_VERSION );
-	if( PyErr_Occurred() ) {
-		Py_FatalError( "Can't initialize module Mesh" );
-	}
-	return;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Python/Bindings/Mesh/init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Python/Bindings/Mesh/init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,45 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: init.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <Python.h>
+#include "bindings.h"
+#include "misc.h"
+
+char Mesh_Python__doc__[] = "Mesh maintains the state of the discretised information in terms of nodes and elements. ";
+
+void initMesh() {
+	Py_InitModule4( "Mesh", Mesh_Python_Methods, Mesh_Python__doc__, 0, PYTHON_API_VERSION );
+	if( PyErr_Occurred() ) {
+		Py_FatalError( "Can't initialize module Mesh" );
+	}
+	return;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Python/Bindings/Mesh/misc.c
--- a/Python/Bindings/Mesh/misc.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: misc.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <Python.h>
-#include "misc.h"
-
-
-char Mesh_Python_copyright__doc__[] = "";
-char Mesh_Python_copyright__name__[] = "copyright";
-
-PyObject* Mesh_Python_copyright( PyObject* self, PyObject* args ) {
-	return Py_BuildValue( "s", "StGermain.Discretisation.Bindings.Mesh Python module: Copyright (c) 2003 Victorian Partnership for Advanced Computing (VPAC) Ltd. Australia." );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Python/Bindings/Mesh/misc.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Python/Bindings/Mesh/misc.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,42 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: misc.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <Python.h>
+#include "misc.h"
+
+
+char Mesh_Python_copyright__doc__[] = "";
+char Mesh_Python_copyright__name__[] = "copyright";
+
+PyObject* Mesh_Python_copyright( PyObject* self, PyObject* args ) {
+	return Py_BuildValue( "s", "StGermain.Discretisation.Bindings.Mesh Python module: Copyright (c) 2003 Victorian Partnership for Advanced Computing (VPAC) Ltd. Australia." );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 SConscript
--- a/SConscript	Wed May 11 13:27:02 2011 -0700
+++ b/SConscript	Thu May 12 11:18:48 2011 -0700
@@ -57,8 +57,8 @@ for d in dirs:
     defs = env.Install(inc_dir, Glob(src_dir + '/*.def'))
 
     # Build our source files.
-    srcs = Glob(src_dir + '/*.c')
-    srcs = [s for s in srcs if s.path.find('-meta.c') == -1]
+    srcs = Glob(src_dir + '/*.cxx')
+    srcs = [s for s in srcs if s.path.find('-meta.cxx') == -1]
     objs += env.SharedObject(srcs, CPPDEFINES=cpp_defs)
 
     # Build any meta files.
@@ -70,7 +70,7 @@ for d in dirs:
         env.Depends(hdrs + objs, defs)
 
     # Build any test suites we might find.
-    suites += env.Object(Glob(tst_dir + '/*Suite.c'))
+    suites += env.Object(Glob(tst_dir + '/*Suite.cxx'))
 
     # Install any test expected and input files
     tst_exp += env.Install(tst_install_dir + '/expected', Glob(tst_exp_dir + '/*'))
@@ -94,8 +94,8 @@ for d in dirs:
 
     env.Install('include/StgDomain/' + d.split('/')[-1], Glob(d + '/*.h'))
 
-    srcs = Glob(d + '/*.c')
-    srcs = [s for s in srcs if s.path.find('-meta.c') == -1]
+    srcs = Glob(d + '/*.cxx')
+    srcs = [s for s in srcs if s.path.find('-meta.cxx') == -1]
     cur_objs = env.SharedObject(srcs, CPPDEFINES=cpp_defs)
     cur_objs += env.stgSharedMeta(Glob(d + '/*.meta'), CPPDEFINES=cpp_defs)
 
@@ -196,7 +196,7 @@ if env['static_libs']:
     reg_c += '\n   stg_num_modules += %d;\n'%len(pl_regs)
     reg_c += '}\n'
 
-    reg_filename = os.path.join(env['build_dir'], 'StgDomain', 'stgdomain_static_modules.c')
+    reg_filename = os.path.join(env['build_dir'], 'StgDomain', 'stgdomain_static_modules.cxx')
     if not os.path.exists(os.path.dirname(reg_filename)):
         os.makedirs(os.path.dirname(reg_filename))
     reg_file = open(reg_filename, 'w')
@@ -205,12 +205,12 @@ if env['static_libs']:
     reg_obj = env.Object(reg_filename)
 
     # Add our register function to the StGermain module file.
-    f = open(File(env['build_dir'] + '/StGermain/stg_static_modules.c').abspath, 'r')
+    f = open(File(env['build_dir'] + '/StGermain/stg_static_modules.cxx').abspath, 'r')
     txt = f.readlines()
     f.close()
     txt.insert(-2, '   stgdomain_register_static_modules();\n')
     txt.insert(0, 'void stgdomain_register_static_modules();\n')
-    f = open(File(env['build_dir'] + '/StGermain/stg_static_modules.c').abspath, 'w')
+    f = open(File(env['build_dir'] + '/StGermain/stg_static_modules.cxx').abspath, 'w')
     f.writelines(txt)
     f.close()
 
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/BelowCosinePlane.c
--- a/Shape/src/BelowCosinePlane.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,242 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: BelowCosinePlane.c 3523 2006-04-11 06:42:09Z AlanLo $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "BelowPlane.h"
-#include "BelowCosinePlane.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type BelowCosinePlane_Type = "BelowCosinePlane";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-BelowCosinePlane* BelowCosinePlane_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		double                                offset,
-		XYZ                                   width,
-		XYZ                                   minValue,
-		XYZ                                   maxValue,
-		double                                amplitude,
-		double                                wavelength,
-		double                                phase )
-{
-	BelowCosinePlane* self = (BelowCosinePlane*) _BelowCosinePlane_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-   _BelowPlane_Init( self, offset, width, minValue, maxValue );
-   _BelowCosinePlane_Init( self, width, amplitude, wavelength, phase );
-
-	return self;
-}
-
-BelowCosinePlane* _BelowCosinePlane_New(  BELOWCOSINEPLANE_DEFARGS  )
-{
-	BelowCosinePlane* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(BelowCosinePlane) );
-	self = (BelowCosinePlane*)_BelowPlane_New(  BELOWPLANE_PASSARGS  );
-	
-	/* General info */
-	return self;
-}
-
-void _BelowCosinePlane_Init( void* belowPlane, XYZ width, double amplitude, double wavelength, double phase ) {
-	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
-
-	self->amplitude = amplitude;
-	self->wavelength = wavelength;
-	self->phase = phase;
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _BelowCosinePlane_Delete( void* belowPlane ) {
-	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
-	
-	/* Delete parent */
-	_BelowPlane_Delete( self );
-}
-
-
-void _BelowCosinePlane_Print( void* belowPlane, Stream* stream ) {
-	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _BelowCosinePlane_Copy( const void* belowPlane, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
-	BelowCosinePlane*	newBelowCosinePlane;
-	
-	newBelowCosinePlane = (BelowCosinePlane*)_BelowPlane_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newBelowCosinePlane->amplitude = self->amplitude;
-	newBelowCosinePlane->wavelength = self->wavelength;
-	newBelowCosinePlane->phase = self->phase;
-	
-	return (void*)newBelowCosinePlane;
-}
-
-void* _BelowCosinePlane_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(BelowCosinePlane);
-	Type                                                          type = BelowCosinePlane_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _BelowCosinePlane_Delete;
-	Stg_Class_PrintFunction*                                    _print = _BelowCosinePlane_Print;
-	Stg_Class_CopyFunction*                                      _copy = _BelowCosinePlane_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _BelowCosinePlane_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _BelowCosinePlane_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _BelowCosinePlane_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _BelowCosinePlane_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _BelowCosinePlane_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _BelowCosinePlane_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _BelowCosinePlane_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _BelowCosinePlane_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _BelowCosinePlane_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _BelowCosinePlane_New(  BELOWCOSINEPLANE_PASSARGS  );
-}
-
-
-void _BelowCosinePlane_AssignFromXML( void* belowPlane, Stg_ComponentFactory* cf, void* data ) {
-	BelowCosinePlane*            self          = (BelowCosinePlane*) belowPlane;
-	double                       amplitude;
-	double                       wavelength;
-	double                       phase;
-
-	_BelowPlane_AssignFromXML( self, cf, data );
-
-	amplitude = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"amplitude", 0.1  );
-	wavelength = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"wavelength", 2*M_PI  );
-	phase = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"phase", 0.0  );
-
-	_BelowCosinePlane_Init( self, self->width, amplitude, wavelength, phase );
-}
-
-void _BelowCosinePlane_Build( void* belowPlane, void* data ) {
-	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
-
-	_BelowPlane_Build( self, data );
-}
-void _BelowCosinePlane_Initialise( void* belowPlane, void* data ) {
-	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
-	
-	_BelowPlane_Initialise( self, data );
-}
-void _BelowCosinePlane_Execute( void* belowPlane, void* data ) {
-	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
-	
-	_BelowPlane_Execute( self, data );
-}
-void _BelowCosinePlane_Destroy( void* belowPlane, void* data ) {
-	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
-    
-	_BelowPlane_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _BelowCosinePlane_IsCoordInside( void* belowPlane, Coord coord ) {
-	BelowCosinePlane*            self       = (BelowCosinePlane*)belowPlane;
-	Coord                        newCoord;
-
-	double                       x, y;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-
-	x = newCoord[ I_AXIS ];
-
-	y =  self->offset + self->amplitude * cos( (2*M_PI * x /self->wavelength)  + self->phase );
-
-	if ( fabs( newCoord[ J_AXIS ] < y) ) {
-		return True;
-	}
-	return False;
-}
-
-double _BelowCosinePlane_CalculateVolume( void* belowPlane ) {
-	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
-	double volume;
-	double wavelength = self->wavelength;
-	double dx = self->width[ I_AXIS ];
-
-	/* using the identity sin(u)-sin(v) = 2 * cos( (u+v)/2 ) * sin( (u-v)/2 ) */
-
-	volume = self->offset*dx + 2 * self->amplitude * wavelength / (2*M_PI) *
-				 (
-				 cos( (M_PI/wavelength) * (self->maxValue[I_AXIS] - self->minValue[I_AXIS] ) + self->phase) *
-				 sin( (M_PI/wavelength) * (self->maxValue[I_AXIS] - self->minValue[I_AXIS]) )
-				 );
-
-	if ( self->dim == 3 ) 
-		volume = self->width[ K_AXIS ] * volume;
-	
-	return volume;
-}
-void _BelowCosinePlane_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/BelowCosinePlane.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/BelowCosinePlane.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,242 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: BelowCosinePlane.c 3523 2006-04-11 06:42:09Z AlanLo $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "BelowPlane.h"
+#include "BelowCosinePlane.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type BelowCosinePlane_Type = "BelowCosinePlane";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+BelowCosinePlane* BelowCosinePlane_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		double                                offset,
+		XYZ                                   width,
+		XYZ                                   minValue,
+		XYZ                                   maxValue,
+		double                                amplitude,
+		double                                wavelength,
+		double                                phase )
+{
+	BelowCosinePlane* self = (BelowCosinePlane*) _BelowCosinePlane_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+   _BelowPlane_Init( self, offset, width, minValue, maxValue );
+   _BelowCosinePlane_Init( self, width, amplitude, wavelength, phase );
+
+	return self;
+}
+
+BelowCosinePlane* _BelowCosinePlane_New(  BELOWCOSINEPLANE_DEFARGS  )
+{
+	BelowCosinePlane* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(BelowCosinePlane) );
+	self = (BelowCosinePlane*)_BelowPlane_New(  BELOWPLANE_PASSARGS  );
+	
+	/* General info */
+	return self;
+}
+
+void _BelowCosinePlane_Init( void* belowPlane, XYZ width, double amplitude, double wavelength, double phase ) {
+	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
+
+	self->amplitude = amplitude;
+	self->wavelength = wavelength;
+	self->phase = phase;
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _BelowCosinePlane_Delete( void* belowPlane ) {
+	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
+	
+	/* Delete parent */
+	_BelowPlane_Delete( self );
+}
+
+
+void _BelowCosinePlane_Print( void* belowPlane, Stream* stream ) {
+	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _BelowCosinePlane_Copy( const void* belowPlane, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
+	BelowCosinePlane*	newBelowCosinePlane;
+	
+	newBelowCosinePlane = (BelowCosinePlane*)_BelowPlane_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newBelowCosinePlane->amplitude = self->amplitude;
+	newBelowCosinePlane->wavelength = self->wavelength;
+	newBelowCosinePlane->phase = self->phase;
+	
+	return (void*)newBelowCosinePlane;
+}
+
+void* _BelowCosinePlane_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(BelowCosinePlane);
+	Type                                                          type = BelowCosinePlane_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _BelowCosinePlane_Delete;
+	Stg_Class_PrintFunction*                                    _print = _BelowCosinePlane_Print;
+	Stg_Class_CopyFunction*                                      _copy = _BelowCosinePlane_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _BelowCosinePlane_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _BelowCosinePlane_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _BelowCosinePlane_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _BelowCosinePlane_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _BelowCosinePlane_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _BelowCosinePlane_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _BelowCosinePlane_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _BelowCosinePlane_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _BelowCosinePlane_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _BelowCosinePlane_New(  BELOWCOSINEPLANE_PASSARGS  );
+}
+
+
+void _BelowCosinePlane_AssignFromXML( void* belowPlane, Stg_ComponentFactory* cf, void* data ) {
+	BelowCosinePlane*            self          = (BelowCosinePlane*) belowPlane;
+	double                       amplitude;
+	double                       wavelength;
+	double                       phase;
+
+	_BelowPlane_AssignFromXML( self, cf, data );
+
+	amplitude = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"amplitude", 0.1  );
+	wavelength = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"wavelength", 2*M_PI  );
+	phase = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"phase", 0.0  );
+
+	_BelowCosinePlane_Init( self, self->width, amplitude, wavelength, phase );
+}
+
+void _BelowCosinePlane_Build( void* belowPlane, void* data ) {
+	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
+
+	_BelowPlane_Build( self, data );
+}
+void _BelowCosinePlane_Initialise( void* belowPlane, void* data ) {
+	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
+	
+	_BelowPlane_Initialise( self, data );
+}
+void _BelowCosinePlane_Execute( void* belowPlane, void* data ) {
+	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
+	
+	_BelowPlane_Execute( self, data );
+}
+void _BelowCosinePlane_Destroy( void* belowPlane, void* data ) {
+	BelowCosinePlane*	self = (BelowCosinePlane*)belowPlane;
+    
+	_BelowPlane_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _BelowCosinePlane_IsCoordInside( void* belowPlane, Coord coord ) {
+	BelowCosinePlane*            self       = (BelowCosinePlane*)belowPlane;
+	Coord                        newCoord;
+
+	double                       x, y;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+
+	x = newCoord[ I_AXIS ];
+
+	y =  self->offset + self->amplitude * cos( (2*M_PI * x /self->wavelength)  + self->phase );
+
+	if ( fabs( newCoord[ J_AXIS ] < y) ) {
+		return True;
+	}
+	return False;
+}
+
+double _BelowCosinePlane_CalculateVolume( void* belowPlane ) {
+	BelowCosinePlane* self = (BelowCosinePlane*)belowPlane;
+	double volume;
+	double wavelength = self->wavelength;
+	double dx = self->width[ I_AXIS ];
+
+	/* using the identity sin(u)-sin(v) = 2 * cos( (u+v)/2 ) * sin( (u-v)/2 ) */
+
+	volume = self->offset*dx + 2 * self->amplitude * wavelength / (2*M_PI) *
+				 (
+				 cos( (M_PI/wavelength) * (self->maxValue[I_AXIS] - self->minValue[I_AXIS] ) + self->phase) *
+				 sin( (M_PI/wavelength) * (self->maxValue[I_AXIS] - self->minValue[I_AXIS]) )
+				 );
+
+	if ( self->dim == 3 ) 
+		volume = self->width[ K_AXIS ] * volume;
+	
+	return volume;
+}
+void _BelowCosinePlane_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/BelowPlane.c
--- a/Shape/src/BelowPlane.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,234 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: BelowPlane.c 3523 2006-04-11 06:42:09Z AlanLo $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "BelowPlane.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type BelowPlane_Type = "BelowPlane";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-BelowPlane* BelowPlane_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		double                                offset,
-		XYZ                                   width,
-		XYZ                                   minValue,
-		XYZ                                   maxValue )
-{
-	BelowPlane* self = (BelowPlane*) _BelowPlane_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-	_BelowPlane_Init( self, offset, width, minValue, maxValue );
-
-	return self;
-}
-
-BelowPlane* _BelowPlane_New(  BELOWPLANE_DEFARGS  )
-{
-	BelowPlane* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(BelowPlane) );
-	self = (BelowPlane*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-	return self;
-}
-
-void _BelowPlane_Init( void* belowPlane, double offset, XYZ width, XYZ minValue, XYZ maxValue ) {
-	BelowPlane* self = (BelowPlane*)belowPlane;
-
-	self->offset = offset;
-
-	memcpy( self->width, width, sizeof(XYZ) );
-	memcpy( self->minValue, maxValue, sizeof(XYZ) );
-	memcpy( self->maxValue, maxValue, sizeof(XYZ) );
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-void _BelowPlane_Delete( void* belowPlane ) {
-	BelowPlane* self = (BelowPlane*)belowPlane;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-void _BelowPlane_Print( void* belowPlane, Stream* stream ) {
-	BelowPlane* self = (BelowPlane*)belowPlane;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _BelowPlane_Copy( const void* belowPlane, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	BelowPlane*	self = (BelowPlane*)belowPlane;
-	BelowPlane*	newBelowPlane;
-	
-	newBelowPlane = (BelowPlane*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newBelowPlane->offset = self->offset;
-	
-	return (void*)newBelowPlane;
-}
-
-void* _BelowPlane_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(BelowPlane);
-	Type                                                          type = BelowPlane_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _BelowPlane_Delete;
-	Stg_Class_PrintFunction*                                    _print = _BelowPlane_Print;
-	Stg_Class_CopyFunction*                                      _copy = _BelowPlane_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _BelowPlane_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _BelowPlane_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _BelowPlane_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _BelowPlane_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _BelowPlane_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _BelowPlane_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _BelowPlane_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _BelowPlane_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _BelowPlane_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _BelowPlane_New(  BELOWPLANE_PASSARGS  );
-}
-
-
-void _BelowPlane_AssignFromXML( void* belowPlane, Stg_ComponentFactory* cf, void* data ) {
-	BelowPlane*	             self          = (BelowPlane*) belowPlane;
-	double                       offset;
-	XYZ                          minValue;
-	XYZ                          maxValue;
-	XYZ                          width;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	offset = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"offset", 0.5  );
-
-	minValue[ I_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minX", 0.0  );
-	minValue[ J_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minY", 0.0  );
-	minValue[ K_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minZ", 0.0  );
-
-	maxValue[ I_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxX", 1.0  );
-	maxValue[ J_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxY", 1.0  );
-	maxValue[ K_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxZ", 1.0  );
-
-	width[ I_AXIS ] = maxValue[ I_AXIS ] - minValue[ I_AXIS ] ;
-	width[ J_AXIS ] = maxValue[ J_AXIS ] - minValue[ J_AXIS ] ;
-	width[ K_AXIS ] = maxValue[ K_AXIS ] - minValue[ K_AXIS ] ;
-
-	_BelowPlane_Init( self, offset, width, minValue, maxValue );
-}
-
-void _BelowPlane_Build( void* belowPlane, void* data ) {
-	BelowPlane*	self = (BelowPlane*)belowPlane;
-
-	_Stg_Shape_Build( self, data );
-}
-void _BelowPlane_Initialise( void* belowPlane, void* data ) {
-	BelowPlane*	self = (BelowPlane*)belowPlane;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _BelowPlane_Execute( void* belowPlane, void* data ) {
-	BelowPlane*	self = (BelowPlane*)belowPlane;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _BelowPlane_Destroy( void* belowPlane, void* data ) {
-	BelowPlane*	self = (BelowPlane*)belowPlane;
-	
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _BelowPlane_IsCoordInside( void* belowPlane, Coord coord ) {
-	BelowPlane*            self       = (BelowPlane*)belowPlane;
-	Coord           newCoord;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-
-	if ( fabs( newCoord[ J_AXIS ] < self->offset ) ) {
-		return True;
-	}
-	return False;
-}
-
-double _BelowPlane_CalculateVolume( void* belowPlane ) {
-	BelowPlane* self = (BelowPlane*)belowPlane;
-	double volume;
-
-	if ( self->dim == 2 ) {
-		volume = self->width[ I_AXIS ] * self->offset;
-	}
-	else {
-		volume = self->width[ I_AXIS ] * self->width[ K_AXIS ] * self->offset;
-	}
-
-	return volume;
-}
-
-void _BelowPlane_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/BelowPlane.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/BelowPlane.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,234 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: BelowPlane.c 3523 2006-04-11 06:42:09Z AlanLo $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "BelowPlane.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type BelowPlane_Type = "BelowPlane";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+BelowPlane* BelowPlane_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		double                                offset,
+		XYZ                                   width,
+		XYZ                                   minValue,
+		XYZ                                   maxValue )
+{
+	BelowPlane* self = (BelowPlane*) _BelowPlane_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+	_BelowPlane_Init( self, offset, width, minValue, maxValue );
+
+	return self;
+}
+
+BelowPlane* _BelowPlane_New(  BELOWPLANE_DEFARGS  )
+{
+	BelowPlane* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(BelowPlane) );
+	self = (BelowPlane*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+	return self;
+}
+
+void _BelowPlane_Init( void* belowPlane, double offset, XYZ width, XYZ minValue, XYZ maxValue ) {
+	BelowPlane* self = (BelowPlane*)belowPlane;
+
+	self->offset = offset;
+
+	memcpy( self->width, width, sizeof(XYZ) );
+	memcpy( self->minValue, maxValue, sizeof(XYZ) );
+	memcpy( self->maxValue, maxValue, sizeof(XYZ) );
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+void _BelowPlane_Delete( void* belowPlane ) {
+	BelowPlane* self = (BelowPlane*)belowPlane;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+void _BelowPlane_Print( void* belowPlane, Stream* stream ) {
+	BelowPlane* self = (BelowPlane*)belowPlane;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _BelowPlane_Copy( const void* belowPlane, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	BelowPlane*	self = (BelowPlane*)belowPlane;
+	BelowPlane*	newBelowPlane;
+	
+	newBelowPlane = (BelowPlane*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newBelowPlane->offset = self->offset;
+	
+	return (void*)newBelowPlane;
+}
+
+void* _BelowPlane_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(BelowPlane);
+	Type                                                          type = BelowPlane_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _BelowPlane_Delete;
+	Stg_Class_PrintFunction*                                    _print = _BelowPlane_Print;
+	Stg_Class_CopyFunction*                                      _copy = _BelowPlane_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _BelowPlane_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _BelowPlane_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _BelowPlane_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _BelowPlane_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _BelowPlane_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _BelowPlane_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _BelowPlane_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _BelowPlane_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _BelowPlane_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _BelowPlane_New(  BELOWPLANE_PASSARGS  );
+}
+
+
+void _BelowPlane_AssignFromXML( void* belowPlane, Stg_ComponentFactory* cf, void* data ) {
+	BelowPlane*	             self          = (BelowPlane*) belowPlane;
+	double                       offset;
+	XYZ                          minValue;
+	XYZ                          maxValue;
+	XYZ                          width;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	offset = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"offset", 0.5  );
+
+	minValue[ I_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minX", 0.0  );
+	minValue[ J_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minY", 0.0  );
+	minValue[ K_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minZ", 0.0  );
+
+	maxValue[ I_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxX", 1.0  );
+	maxValue[ J_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxY", 1.0  );
+	maxValue[ K_AXIS ] = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxZ", 1.0  );
+
+	width[ I_AXIS ] = maxValue[ I_AXIS ] - minValue[ I_AXIS ] ;
+	width[ J_AXIS ] = maxValue[ J_AXIS ] - minValue[ J_AXIS ] ;
+	width[ K_AXIS ] = maxValue[ K_AXIS ] - minValue[ K_AXIS ] ;
+
+	_BelowPlane_Init( self, offset, width, minValue, maxValue );
+}
+
+void _BelowPlane_Build( void* belowPlane, void* data ) {
+	BelowPlane*	self = (BelowPlane*)belowPlane;
+
+	_Stg_Shape_Build( self, data );
+}
+void _BelowPlane_Initialise( void* belowPlane, void* data ) {
+	BelowPlane*	self = (BelowPlane*)belowPlane;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _BelowPlane_Execute( void* belowPlane, void* data ) {
+	BelowPlane*	self = (BelowPlane*)belowPlane;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _BelowPlane_Destroy( void* belowPlane, void* data ) {
+	BelowPlane*	self = (BelowPlane*)belowPlane;
+	
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _BelowPlane_IsCoordInside( void* belowPlane, Coord coord ) {
+	BelowPlane*            self       = (BelowPlane*)belowPlane;
+	Coord           newCoord;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+
+	if ( fabs( newCoord[ J_AXIS ] < self->offset ) ) {
+		return True;
+	}
+	return False;
+}
+
+double _BelowPlane_CalculateVolume( void* belowPlane ) {
+	BelowPlane* self = (BelowPlane*)belowPlane;
+	double volume;
+
+	if ( self->dim == 2 ) {
+		volume = self->width[ I_AXIS ] * self->offset;
+	}
+	else {
+		volume = self->width[ I_AXIS ] * self->width[ K_AXIS ] * self->offset;
+	}
+
+	return volume;
+}
+
+void _BelowPlane_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Box.c
--- a/Shape/src/Box.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,244 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Box.c 3869 2006-10-16 13:42:59Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Box.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type Box_Type = "Box";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-Box* Box_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		XYZ                                   width )
-{
-	Box* self = (Box*) _Box_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-	_Box_Init( self, width );
-	return self;
-}
-
-Box* _Box_New(  BOX_DEFARGS  )
-{
-	Box* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Box) );
-	self = (Box*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	return self;
-}
-
-void _Box_Init( void* shape, XYZ width ) {
-	Box* self = (Box*)shape;
-	
-	memcpy( self->width, width, sizeof(XYZ));
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Box_Delete( void* shape ) {
-	Box* self = (Box*)shape;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _Box_Print( void* shape, Stream* stream ) {
-	Box* self = (Box*)shape;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _Box_Copy( const void* shape, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Box*	self = (Box*)shape;
-	Box*	newBox;
-	
-	newBox = (Box*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	memcpy( newBox->width, self->width, sizeof(XYZ));
-	
-	return (void*)newBox;
-}
-
-void* _Box_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Box);
-	Type                                                          type = Box_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Box_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Box_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Box_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Box_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Box_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Box_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Box_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Box_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Box_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Box_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Box_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Box_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Box_New(  BOX_PASSARGS  );
-}
-
-
-void _Box_AssignFromXML( void* shape, Stg_ComponentFactory* cf, void* data ) {
-	Box*	             self          = (Box*) shape;
-	Dictionary*          dictionary    = Dictionary_GetDictionary( cf->componentDict, self->name );
-	XYZ                  width;
-	double               start, end;
-	char* startKey      = StG_Strdup("startX");
-	char* endKey        = StG_Strdup("endX");
-	char* widthKey      = StG_Strdup("widthX");
-	char*                startCharPtr  = (char*)strchr( startKey, 'X' );
-	char*                endCharPtr    = (char*)strchr( endKey, 'X' );
-	char*                widthCharPtr  = (char*)strchr( widthKey, 'X' );
-	char                 axisLetters[] = {'X','Y','Z'};
-	Dimension_Index      dim_I;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	for ( dim_I = 0 ; dim_I < 3 ; dim_I++ ) {
-		*startCharPtr = axisLetters[ dim_I ];
-		*endCharPtr   = axisLetters[ dim_I ];
-		*widthCharPtr = axisLetters[ dim_I ];
-
-		/* Check to see whether the user wants to specify the start and end explicitly */
-		if ( Dictionary_Get( dictionary, (Dictionary_Entry_Key)startKey  ) && Dictionary_Get( dictionary, (Dictionary_Entry_Key)endKey )  ) {
-			start = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)startKey, 0.0  );
-			end   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)endKey, 0.0  );
-
-			width[ dim_I ] = end - start;
-			self->centre[ dim_I ] = start + 0.5 * width[dim_I];
-		}
-		else 
-			width[ dim_I ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)widthKey, 0.0 );
-	}
-
-	Memory_Free( startKey );
-	Memory_Free( endKey );
-	Memory_Free( widthKey  );
-
-	_Box_Init( self, width );
-}
-
-void _Box_Build( void* shape, void* data ) {
-	Box*	self = (Box*)shape;
-
-	_Stg_Shape_Build( self, data );
-}
-void _Box_Initialise( void* shape, void* data ) {
-	Box*	self = (Box*)shape;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _Box_Execute( void* shape, void* data ) {
-	Box*	self = (Box*)shape;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _Box_Destroy( void* shape, void* data ) {
-	Box*	self = (Box*)shape;
-    
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _Box_IsCoordInside( void* shape, Coord coord ) {
-	Box*            self       = (Box*)shape;
-	Coord           newCoord;
-	Dimension_Index dim_I;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-	
-	for ( dim_I = 0 ; dim_I < self->dim ; dim_I++ ) {
-		if ( fabs( newCoord[ dim_I ] ) > 0.5 * self->width[ dim_I ] ) 
-			return False;
-	}
-	return True;
-}
-
-double _Box_CalculateVolume( void* shape ) {
-	Box* self = (Box*)shape;
-	Dimension_Index dim_I;
-	double result;
-	result = 1.0;
-	for ( dim_I = 0; dim_I < self->dim; dim_I++ ) {
-		result *= self->width[dim_I];
-	}
-	return result;
-}
-
-void _Box_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
-	/* To be implemented */
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Box.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Box.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,244 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) )
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Box.c 3869 2006-10-16 13:42:59Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Box.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type Box_Type = "Box";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+Box* Box_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		XYZ                                   width )
+{
+	Box* self = (Box*) _Box_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+	_Box_Init( self, width );
+	return self;
+}
+
+Box* _Box_New(  BOX_DEFARGS  )
+{
+	Box* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Box) );
+	self = (Box*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	return self;
+}
+
+void _Box_Init( void* shape, XYZ width ) {
+	Box* self = (Box*)shape;
+	
+	memcpy( self->width, width, sizeof(XYZ));
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Box_Delete( void* shape ) {
+	Box* self = (Box*)shape;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _Box_Print( void* shape, Stream* stream ) {
+	Box* self = (Box*)shape;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _Box_Copy( const void* shape, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Box*	self = (Box*)shape;
+	Box*	newBox;
+	
+	newBox = (Box*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	memcpy( newBox->width, self->width, sizeof(XYZ));
+	
+	return (void*)newBox;
+}
+
+void* _Box_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Box);
+	Type                                                          type = Box_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Box_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Box_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Box_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Box_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Box_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Box_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Box_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Box_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Box_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Box_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Box_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Box_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Box_New(  BOX_PASSARGS  );
+}
+
+
+void _Box_AssignFromXML( void* shape, Stg_ComponentFactory* cf, void* data ) {
+	Box*	             self          = (Box*) shape;
+	Dictionary*          dictionary    = Dictionary_GetDictionary( cf->componentDict, self->name );
+	XYZ                  width;
+	double               start, end;
+	char* startKey      = StG_Strdup("startX");
+	char* endKey        = StG_Strdup("endX");
+	char* widthKey      = StG_Strdup("widthX");
+	char*                startCharPtr  = (char*)strchr( startKey, 'X' );
+	char*                endCharPtr    = (char*)strchr( endKey, 'X' );
+	char*                widthCharPtr  = (char*)strchr( widthKey, 'X' );
+	char                 axisLetters[] = {'X','Y','Z'};
+	Dimension_Index      dim_I;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	for ( dim_I = 0 ; dim_I < 3 ; dim_I++ ) {
+		*startCharPtr = axisLetters[ dim_I ];
+		*endCharPtr   = axisLetters[ dim_I ];
+		*widthCharPtr = axisLetters[ dim_I ];
+
+		/* Check to see whether the user wants to specify the start and end explicitly */
+		if ( Dictionary_Get( dictionary, (Dictionary_Entry_Key)startKey  ) && Dictionary_Get( dictionary, (Dictionary_Entry_Key)endKey )  ) {
+			start = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)startKey, 0.0  );
+			end   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)endKey, 0.0  );
+
+			width[ dim_I ] = end - start;
+			self->centre[ dim_I ] = start + 0.5 * width[dim_I];
+		}
+		else 
+			width[ dim_I ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)widthKey, 0.0 );
+	}
+
+	Memory_Free( startKey );
+	Memory_Free( endKey );
+	Memory_Free( widthKey  );
+
+	_Box_Init( self, width );
+}
+
+void _Box_Build( void* shape, void* data ) {
+	Box*	self = (Box*)shape;
+
+	_Stg_Shape_Build( self, data );
+}
+void _Box_Initialise( void* shape, void* data ) {
+	Box*	self = (Box*)shape;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _Box_Execute( void* shape, void* data ) {
+	Box*	self = (Box*)shape;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _Box_Destroy( void* shape, void* data ) {
+	Box*	self = (Box*)shape;
+    
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _Box_IsCoordInside( void* shape, Coord coord ) {
+	Box*            self       = (Box*)shape;
+	Coord           newCoord;
+	Dimension_Index dim_I;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+	
+	for ( dim_I = 0 ; dim_I < self->dim ; dim_I++ ) {
+		if ( fabs( newCoord[ dim_I ] ) > 0.5 * self->width[ dim_I ] ) 
+			return False;
+	}
+	return True;
+}
+
+double _Box_CalculateVolume( void* shape ) {
+	Box* self = (Box*)shape;
+	Dimension_Index dim_I;
+	double result;
+	result = 1.0;
+	for ( dim_I = 0; dim_I < self->dim; dim_I++ ) {
+		result *= self->width[dim_I];
+	}
+	return result;
+}
+
+void _Box_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
+	/* To be implemented */
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/ConvexHull.c
--- a/Shape/src/ConvexHull.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,310 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ConvexHull.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "ConvexHull.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type ConvexHull_Type = "ConvexHull";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-ConvexHull* ConvexHull_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		Coord_List                            vertexList,
-		Index                                 vertexCount
-		)
-{
-	ConvexHull* self = (ConvexHull*)_ConvexHull_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
-   _ConvexHull_Init( self, vertexList, vertexCount);
-
-	return self;
-}
-
-ConvexHull* _ConvexHull_New(  CONVEXHULL_DEFARGS  )
-{
-	ConvexHull* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(ConvexHull) );
-	self = (ConvexHull*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	return self;
-}
-
-void _ConvexHull_Init( void* convexHull, Coord_List vertexList, Index vertexCount) {
-	ConvexHull* self = (ConvexHull*)convexHull;
-	Index       numberOfFaces;
-	Index       dimensions; /* this probably doesn't need to be here */
-	Index       vertex_I;
-	
-	double        tmpVector1[3];
-	double        tmpVector2[3];
-	double        tmpVector3[3];
-	
-	dimensions = 3;
-	/* Copy vertexCount */
-	self->vertexCount = vertexCount;
-	/* Copy vertexList */
-	self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
-	memcpy( self->vertexList , vertexList, sizeof(Coord) * vertexCount );
-	
-	/* Now Construct normal and store them in self->facesList */
-	
-	/* 1st allocate memory	 */
-	if(vertexCount == 3) numberOfFaces = 3; 
-	else                 numberOfFaces = 4; 
-	
-	self->facesList = Memory_Alloc_Array( XYZ, numberOfFaces, "facesList" );
-
-	/* 2nd Calculate Normals on faces */
-	/* in 2-D */
-	if( numberOfFaces == 3 ) {
-		for( vertex_I = 0; vertex_I < vertexCount ; vertex_I++ ) {
-			
-			StGermain_VectorSubtraction(tmpVector1, vertexList[ vertex_I % 3 ], vertexList[ (vertex_I+1) % 3 ], dimensions);
-			StGermain_VectorSubtraction(tmpVector2, vertexList[ vertex_I % 3 ], vertexList[ (vertex_I+2) % 3 ], dimensions);
-				
-			tmpVector3[0] = tmpVector1[1];
-			tmpVector3[1] = -1 * tmpVector1[0];
-			tmpVector3[2] = 0;
-                        /*			Now Vec3 is possibly normal vector */
-				if( StGermain_VectorDotProduct(tmpVector3, tmpVector2, dimensions) < 0 )
-				{ tmpVector3[0] = -1*tmpVector3[0]; tmpVector3[1] = -1 * tmpVector3[1]; }
-			
-			memcpy( self->facesList[ vertex_I ], tmpVector3, sizeof(XYZ) );
-		}
-	}
-	else {
-		for( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++ ) {
-			StGermain_NormalToPlane( tmpVector3, vertexList[ vertex_I % 4], vertexList[ (vertex_I+1) % 4], vertexList[ (vertex_I+2) % 4]);
-			StGermain_VectorSubtraction( tmpVector2, vertexList[ vertex_I % 4 ], vertexList[ (vertex_I+3) % 4 ], dimensions);
-
-			if( StGermain_VectorDotProduct(tmpVector3, tmpVector2, dimensions) < 0 ) 
-				{ Vec_Div3D( tmpVector3, tmpVector3, -1.0 ); }
-			memcpy( self->facesList[ vertex_I ], tmpVector3, sizeof(XYZ) );
-
-		}
-	}
-}
-	
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _ConvexHull_Delete( void* convexHull ) {
-	ConvexHull*       self       = (ConvexHull*)convexHull;
-
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _ConvexHull_Print( void* convexHull, Stream* stream ) {
-	ConvexHull* self = (ConvexHull*)convexHull;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _ConvexHull_Copy( const void* convexHull, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ConvexHull*	self = (ConvexHull*)convexHull;
-	ConvexHull*	newConvexHull;
-	
-	newConvexHull = (ConvexHull*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newConvexHull->vertexList = Memory_Alloc_Array( Coord, self->vertexCount, "vertexList" );
-	memcpy( newConvexHull->vertexList , self->vertexList, sizeof(Coord) * self->vertexCount );
-
-	newConvexHull->facesList = Memory_Alloc_Array( XYZ, self->vertexCount, "facesList" );
-	memcpy( newConvexHull->facesList, self->facesList, sizeof(XYZ) * self->vertexCount );
-
-	newConvexHull->vertexList  = self->vertexList;
-	newConvexHull->vertexCount = self->vertexCount;
-	newConvexHull->facesList   = self->facesList;
-	
-	return (void*)newConvexHull;
-}
-
-void* _ConvexHull_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(ConvexHull);
-	Type                                                          type = ConvexHull_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _ConvexHull_Delete;
-	Stg_Class_PrintFunction*                                    _print = _ConvexHull_Print;
-	Stg_Class_CopyFunction*                                      _copy = _ConvexHull_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _ConvexHull_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _ConvexHull_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _ConvexHull_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _ConvexHull_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _ConvexHull_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _ConvexHull_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _ConvexHull_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _ConvexHull_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _ConvecHull_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _ConvexHull_New(  CONVEXHULL_PASSARGS  );
-}
-
-
-void _ConvexHull_AssignFromXML( void* convexHull, Stg_ComponentFactory* cf, void* data ) {
-	ConvexHull*             self       = (ConvexHull*)convexHull;
-	Index                   vertexCount;
-	Index                   vertex_I;
-	Coord_List              vertexList;
-	double*                 coord;
-	Dictionary_Entry_Value* optionSet;
-	Dictionary_Entry_Value* optionsList;
-	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	Stream*                 stream     = cf->infoStream;
-
-	
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices"  );
-	Journal_Firewall( optionsList != NULL, 
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"In func %s: The list 'vertices' specifying the convexHull is NULL.\n", __func__);
-
-	vertexCount = Dictionary_Entry_Value_GetCount(optionsList);
-	Journal_Firewall( ( self->dim == 2 && vertexCount < 4 ) || ( self->dim == 3 && vertexCount < 5 ),
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"In func %s: Sorry, but we got lazy, you can only specify 3 (2D) or 4 (3D) points. " 
-		"Please feel free to hassle developers for this feature.\n", __func__);
-
-	/* Allocate space */
-	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
-	memset( vertexList, 0, vertexCount * sizeof(Coord) );
-	
-	Stream_Indent( stream );
-	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
-		optionSet = Dictionary_Entry_Value_GetElement(optionsList, vertex_I );
-		coord = vertexList[vertex_I];
-
-		/* Read Vertex */
-		coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"x") );
-		coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"y") );
-		
-		coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"z"));
-		optionSet = optionSet->next;
-	}
-	Stream_UnIndent( stream  );
-
-
-	_ConvexHull_Init( self, vertexList, vertexCount);
-}
-
-void _ConvexHull_Build( void* convexHull, void* data ) {
-	ConvexHull*	self = (ConvexHull*)convexHull;
-
-	_Stg_Shape_Build( self, data );
-}
-void _ConvexHull_Initialise( void* convexHull, void* data ) {
-	ConvexHull*	self = (ConvexHull*)convexHull;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _ConvexHull_Execute( void* convexHull, void* data ) {
-	ConvexHull*	self = (ConvexHull*)convexHull;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _ConvexHull_Destroy( void* convexHull, void* data ) {
-	ConvexHull*	self = (ConvexHull*)convexHull;
-   Coord_List        vertexList = self->vertexList;
-	XYZ*              facesList  = self->facesList;
-
-	Memory_Free( vertexList );
-	Memory_Free( facesList );
-	 
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-Bool _ConvexHull_IsCoordInside( void* convexHull, Coord point ) {
-	ConvexHull*     self                 = (ConvexHull*)convexHull;
-	Index           vertex_I;
-	XYZ             tmpVector;
-	/*Stream*                 stream     = cf->infoStream; */
-
-
-	/* for the particle to be inside the shape, the dot product of its position vector with the shape face normal's must be non-positive */
-	for( vertex_I = 0 ; vertex_I < self->vertexCount ; vertex_I++ ) {
-		StGermain_VectorSubtraction(tmpVector, point, self->vertexList[ vertex_I ], self->dim );
-		if( StGermain_VectorDotProduct(self->facesList[ vertex_I ], tmpVector, self->dim ) > 0 ) {
-			return False;
-		}
-	}
-	return True;
-}
-
-double _ConvexHull_CalculateVolume( void* convexHull ) {
-	assert( 0 );
-	return 0.0;
-}
-void _ConvecHull_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/ConvexHull.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/ConvexHull.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,310 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ConvexHull.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "ConvexHull.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type ConvexHull_Type = "ConvexHull";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+ConvexHull* ConvexHull_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		Coord_List                            vertexList,
+		Index                                 vertexCount
+		)
+{
+	ConvexHull* self = (ConvexHull*)_ConvexHull_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
+   _ConvexHull_Init( self, vertexList, vertexCount);
+
+	return self;
+}
+
+ConvexHull* _ConvexHull_New(  CONVEXHULL_DEFARGS  )
+{
+	ConvexHull* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(ConvexHull) );
+	self = (ConvexHull*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	return self;
+}
+
+void _ConvexHull_Init( void* convexHull, Coord_List vertexList, Index vertexCount) {
+	ConvexHull* self = (ConvexHull*)convexHull;
+	Index       numberOfFaces;
+	Index       dimensions; /* this probably doesn't need to be here */
+	Index       vertex_I;
+	
+	double        tmpVector1[3];
+	double        tmpVector2[3];
+	double        tmpVector3[3];
+	
+	dimensions = 3;
+	/* Copy vertexCount */
+	self->vertexCount = vertexCount;
+	/* Copy vertexList */
+	self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
+	memcpy( self->vertexList , vertexList, sizeof(Coord) * vertexCount );
+	
+	/* Now Construct normal and store them in self->facesList */
+	
+	/* 1st allocate memory	 */
+	if(vertexCount == 3) numberOfFaces = 3; 
+	else                 numberOfFaces = 4; 
+	
+	self->facesList = Memory_Alloc_Array( XYZ, numberOfFaces, "facesList" );
+
+	/* 2nd Calculate Normals on faces */
+	/* in 2-D */
+	if( numberOfFaces == 3 ) {
+		for( vertex_I = 0; vertex_I < vertexCount ; vertex_I++ ) {
+			
+			StGermain_VectorSubtraction(tmpVector1, vertexList[ vertex_I % 3 ], vertexList[ (vertex_I+1) % 3 ], dimensions);
+			StGermain_VectorSubtraction(tmpVector2, vertexList[ vertex_I % 3 ], vertexList[ (vertex_I+2) % 3 ], dimensions);
+				
+			tmpVector3[0] = tmpVector1[1];
+			tmpVector3[1] = -1 * tmpVector1[0];
+			tmpVector3[2] = 0;
+                        /*			Now Vec3 is possibly normal vector */
+				if( StGermain_VectorDotProduct(tmpVector3, tmpVector2, dimensions) < 0 )
+				{ tmpVector3[0] = -1*tmpVector3[0]; tmpVector3[1] = -1 * tmpVector3[1]; }
+			
+			memcpy( self->facesList[ vertex_I ], tmpVector3, sizeof(XYZ) );
+		}
+	}
+	else {
+		for( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++ ) {
+			StGermain_NormalToPlane( tmpVector3, vertexList[ vertex_I % 4], vertexList[ (vertex_I+1) % 4], vertexList[ (vertex_I+2) % 4]);
+			StGermain_VectorSubtraction( tmpVector2, vertexList[ vertex_I % 4 ], vertexList[ (vertex_I+3) % 4 ], dimensions);
+
+			if( StGermain_VectorDotProduct(tmpVector3, tmpVector2, dimensions) < 0 ) 
+				{ Vec_Div3D( tmpVector3, tmpVector3, -1.0 ); }
+			memcpy( self->facesList[ vertex_I ], tmpVector3, sizeof(XYZ) );
+
+		}
+	}
+}
+	
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _ConvexHull_Delete( void* convexHull ) {
+	ConvexHull*       self       = (ConvexHull*)convexHull;
+
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _ConvexHull_Print( void* convexHull, Stream* stream ) {
+	ConvexHull* self = (ConvexHull*)convexHull;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _ConvexHull_Copy( const void* convexHull, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ConvexHull*	self = (ConvexHull*)convexHull;
+	ConvexHull*	newConvexHull;
+	
+	newConvexHull = (ConvexHull*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newConvexHull->vertexList = Memory_Alloc_Array( Coord, self->vertexCount, "vertexList" );
+	memcpy( newConvexHull->vertexList , self->vertexList, sizeof(Coord) * self->vertexCount );
+
+	newConvexHull->facesList = Memory_Alloc_Array( XYZ, self->vertexCount, "facesList" );
+	memcpy( newConvexHull->facesList, self->facesList, sizeof(XYZ) * self->vertexCount );
+
+	newConvexHull->vertexList  = self->vertexList;
+	newConvexHull->vertexCount = self->vertexCount;
+	newConvexHull->facesList   = self->facesList;
+	
+	return (void*)newConvexHull;
+}
+
+void* _ConvexHull_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(ConvexHull);
+	Type                                                          type = ConvexHull_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _ConvexHull_Delete;
+	Stg_Class_PrintFunction*                                    _print = _ConvexHull_Print;
+	Stg_Class_CopyFunction*                                      _copy = _ConvexHull_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _ConvexHull_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _ConvexHull_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _ConvexHull_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _ConvexHull_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _ConvexHull_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _ConvexHull_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _ConvexHull_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _ConvexHull_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _ConvecHull_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _ConvexHull_New(  CONVEXHULL_PASSARGS  );
+}
+
+
+void _ConvexHull_AssignFromXML( void* convexHull, Stg_ComponentFactory* cf, void* data ) {
+	ConvexHull*             self       = (ConvexHull*)convexHull;
+	Index                   vertexCount;
+	Index                   vertex_I;
+	Coord_List              vertexList;
+	double*                 coord;
+	Dictionary_Entry_Value* optionSet;
+	Dictionary_Entry_Value* optionsList;
+	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	Stream*                 stream     = cf->infoStream;
+
+	
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices"  );
+	Journal_Firewall( optionsList != NULL, 
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"In func %s: The list 'vertices' specifying the convexHull is NULL.\n", __func__);
+
+	vertexCount = Dictionary_Entry_Value_GetCount(optionsList);
+	Journal_Firewall( ( self->dim == 2 && vertexCount < 4 ) || ( self->dim == 3 && vertexCount < 5 ),
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"In func %s: Sorry, but we got lazy, you can only specify 3 (2D) or 4 (3D) points. " 
+		"Please feel free to hassle developers for this feature.\n", __func__);
+
+	/* Allocate space */
+	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
+	memset( vertexList, 0, vertexCount * sizeof(Coord) );
+	
+	Stream_Indent( stream );
+	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
+		optionSet = Dictionary_Entry_Value_GetElement(optionsList, vertex_I );
+		coord = vertexList[vertex_I];
+
+		/* Read Vertex */
+		coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"x") );
+		coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"y") );
+		
+		coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"z"));
+		optionSet = optionSet->next;
+	}
+	Stream_UnIndent( stream  );
+
+
+	_ConvexHull_Init( self, vertexList, vertexCount);
+}
+
+void _ConvexHull_Build( void* convexHull, void* data ) {
+	ConvexHull*	self = (ConvexHull*)convexHull;
+
+	_Stg_Shape_Build( self, data );
+}
+void _ConvexHull_Initialise( void* convexHull, void* data ) {
+	ConvexHull*	self = (ConvexHull*)convexHull;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _ConvexHull_Execute( void* convexHull, void* data ) {
+	ConvexHull*	self = (ConvexHull*)convexHull;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _ConvexHull_Destroy( void* convexHull, void* data ) {
+	ConvexHull*	self = (ConvexHull*)convexHull;
+   Coord_List        vertexList = self->vertexList;
+	XYZ*              facesList  = self->facesList;
+
+	Memory_Free( vertexList );
+	Memory_Free( facesList );
+	 
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+Bool _ConvexHull_IsCoordInside( void* convexHull, Coord point ) {
+	ConvexHull*     self                 = (ConvexHull*)convexHull;
+	Index           vertex_I;
+	XYZ             tmpVector;
+	/*Stream*                 stream     = cf->infoStream; */
+
+
+	/* for the particle to be inside the shape, the dot product of its position vector with the shape face normal's must be non-positive */
+	for( vertex_I = 0 ; vertex_I < self->vertexCount ; vertex_I++ ) {
+		StGermain_VectorSubtraction(tmpVector, point, self->vertexList[ vertex_I ], self->dim );
+		if( StGermain_VectorDotProduct(self->facesList[ vertex_I ], tmpVector, self->dim ) > 0 ) {
+			return False;
+		}
+	}
+	return True;
+}
+
+double _ConvexHull_CalculateVolume( void* convexHull ) {
+	assert( 0 );
+	return 0.0;
+}
+void _ConvecHull_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Cylinder.c
--- a/Shape/src/Cylinder.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,274 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Cylinder.c 3869 2006-10-16 13:42:59Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Cylinder.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type Cylinder_Type = "Cylinder";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-Cylinder* Cylinder_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		double                                radius, 
-		XYZ                                   start, 
-		XYZ                                   end, 
-		Axis                                  alongAxis )
-{
-	Cylinder* self = (Cylinder*) _Cylinder_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-	_Cylinder_Init( self, radius, start, end, alongAxis );
-
-	return self;
-}
-
-Cylinder* _Cylinder_New(  CYLINDER_DEFARGS  )
-{
-	Cylinder* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Cylinder) );
-	self = (Cylinder*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	
-	return self;
-}
-
-void _Cylinder_Init( Cylinder* self, double radius, XYZ start, XYZ end, Axis alongAxis ) {
-	memcpy( self->start, start, sizeof(XYZ));
-	memcpy( self->end, end, sizeof(XYZ));
-	self->alongAxis = alongAxis;
-	self->radius = radius;
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Cylinder_Delete( void* cylinder ) {
-	Cylinder* self = (Cylinder*)cylinder;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-void _Cylinder_Print( void* cylinder, Stream* stream ) {
-	Cylinder* self = (Cylinder*)cylinder;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _Cylinder_Copy( const void* cylinder, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Cylinder*	self = (Cylinder*)cylinder;
-	Cylinder*	newCylinder;
-	
-	newCylinder = (Cylinder*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	memcpy( newCylinder->start, self->start, sizeof(XYZ));
-	memcpy( newCylinder->end, self->end, sizeof(XYZ));
-
-	newCylinder->radius = self->radius;
-	newCylinder->alongAxis = self->alongAxis;
-	
-	return (void*)newCylinder;
-}
-
-void* _Cylinder_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Cylinder);
-	Type                                                          type = Cylinder_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Cylinder_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Cylinder_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Cylinder_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Cylinder_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Cylinder_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Cylinder_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Cylinder_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Cylinder_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Cylinder_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Cylinder_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Cylinder_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Cylinder_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Cylinder_New(  CYLINDER_PASSARGS  );
-}
-
-#define BIG 1.0e99
-
-void _Cylinder_AssignFromXML( void* cylinder, Stg_ComponentFactory* cf, void* data ) {
-	Cylinder*            self                     = (Cylinder*) cylinder;
-	XYZ                  start                    = { -BIG, -BIG, -BIG }; 
-	XYZ                  end                      = {  BIG,  BIG,  BIG };
-	double               radius                   = 0.0;
-	Axis                 alongAxis        = I_AXIS;
-	char*                perpendicularAxisName    = NULL;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-	
-	radius = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radius", 0.0  );
-
-	start[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startX", -BIG  );
-	start[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startY", -BIG  );
-	start[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startZ", -BIG  );
-	end[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endX", BIG  );
-	end[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endY", BIG  );
-	end[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endZ", BIG  );
-
-	perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"perpendicularAxis", "x" );
-	perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"alongAxis", perpendicularAxisName );
-	switch ( perpendicularAxisName[0] ) {
-		case 'x': case 'X': case 'i': case 'I': case '0':
-			alongAxis = I_AXIS; break;
-		case 'y': case 'Y': case 'j': case 'J': case '1':
-			alongAxis = J_AXIS; break;
-		case 'z': case 'Z': case 'k': case 'K': case '2':
-			alongAxis = K_AXIS; break;
-		default:
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-					"Cannot understand alongAxis '%s'\n", perpendicularAxisName );
-	}
-	
-	_Cylinder_Init( self, radius, start, end, alongAxis );
-}
-
-void _Cylinder_Build( void* cylinder, void* data ) {
-	Cylinder*	self = (Cylinder*)cylinder;
-
-	_Stg_Shape_Build( self, data );
-}
-void _Cylinder_Initialise( void* cylinder, void* data ) {
-	Cylinder*	self = (Cylinder*)cylinder;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _Cylinder_Execute( void* cylinder, void* data ) {
-	Cylinder*	self = (Cylinder*)cylinder;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _Cylinder_Destroy( void* cylinder, void* data ) {
-	Cylinder*	self = (Cylinder*)cylinder;
-
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _Cylinder_IsCoordInside( void* cylinder, Coord coord ) {
-	Cylinder*       self       = (Cylinder*)cylinder;
-	Coord           newCoord;
-	double          insideOutsideValue;
-	double          x, y, z;
-	unsigned        axis_I;
-
-	/* Check whether coord is within min and max values */
-	for ( axis_I = 0 ; axis_I < self->dim ; axis_I++ ) {
-		if ( coord[ axis_I ] < self->start[ axis_I ] || coord[ axis_I ] > self->end[ axis_I ] )
-			return False;
-	}
-	
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-	
-	newCoord[ self->alongAxis ] = 0.0;
-
-	/* Check if coord is within radius */
-	x = newCoord[ I_AXIS ];
-	y = newCoord[ J_AXIS ];
-	if(self->dim == 2)
-		insideOutsideValue = x*x + y*y;
-	else {
-		z = newCoord[ K_AXIS ];
-		insideOutsideValue = x*x + y*y + z*z;
-	}
-	if ( insideOutsideValue > (self->radius * self->radius) )
-		return False;
-
-
-	return True;
-}
-
-void _Cylinder_DistanceFromCenterAxis( void* cylinder, Coord coord, double* disVec ) {
-	Cylinder*       self       = (Cylinder*)cylinder;
-	Coord           newCoord;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-	
-	newCoord[ self->alongAxis ] = 0.0;
-
-	/* Check if coord is within radius */
-	disVec[0] = newCoord[ I_AXIS ];
-	disVec[1] = newCoord[ J_AXIS ];
-	if(self->dim == 3)
-		disVec[2] = newCoord[ K_AXIS ];
-
-	return;
-}
-
-
-double _Cylinder_CalculateVolume( void* cylinder ) {
-	assert( 0 /* unsure how this cylinder is setup...but shouldn't be hard to implement -- Alan */ );
-	return 0.0;
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Cylinder.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Cylinder.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,274 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Cylinder.c 3869 2006-10-16 13:42:59Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Cylinder.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type Cylinder_Type = "Cylinder";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+Cylinder* Cylinder_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		double                                radius, 
+		XYZ                                   start, 
+		XYZ                                   end, 
+		Axis                                  alongAxis )
+{
+	Cylinder* self = (Cylinder*) _Cylinder_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+	_Cylinder_Init( self, radius, start, end, alongAxis );
+
+	return self;
+}
+
+Cylinder* _Cylinder_New(  CYLINDER_DEFARGS  )
+{
+	Cylinder* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Cylinder) );
+	self = (Cylinder*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	
+	return self;
+}
+
+void _Cylinder_Init( Cylinder* self, double radius, XYZ start, XYZ end, Axis alongAxis ) {
+	memcpy( self->start, start, sizeof(XYZ));
+	memcpy( self->end, end, sizeof(XYZ));
+	self->alongAxis = alongAxis;
+	self->radius = radius;
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Cylinder_Delete( void* cylinder ) {
+	Cylinder* self = (Cylinder*)cylinder;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+void _Cylinder_Print( void* cylinder, Stream* stream ) {
+	Cylinder* self = (Cylinder*)cylinder;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _Cylinder_Copy( const void* cylinder, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Cylinder*	self = (Cylinder*)cylinder;
+	Cylinder*	newCylinder;
+	
+	newCylinder = (Cylinder*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	memcpy( newCylinder->start, self->start, sizeof(XYZ));
+	memcpy( newCylinder->end, self->end, sizeof(XYZ));
+
+	newCylinder->radius = self->radius;
+	newCylinder->alongAxis = self->alongAxis;
+	
+	return (void*)newCylinder;
+}
+
+void* _Cylinder_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Cylinder);
+	Type                                                          type = Cylinder_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Cylinder_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Cylinder_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Cylinder_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Cylinder_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Cylinder_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Cylinder_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Cylinder_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Cylinder_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Cylinder_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Cylinder_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Cylinder_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Cylinder_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Cylinder_New(  CYLINDER_PASSARGS  );
+}
+
+#define BIG 1.0e99
+
+void _Cylinder_AssignFromXML( void* cylinder, Stg_ComponentFactory* cf, void* data ) {
+	Cylinder*            self                     = (Cylinder*) cylinder;
+	XYZ                  start                    = { -BIG, -BIG, -BIG }; 
+	XYZ                  end                      = {  BIG,  BIG,  BIG };
+	double               radius                   = 0.0;
+	Axis                 alongAxis        = I_AXIS;
+	char*                perpendicularAxisName    = NULL;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+	
+	radius = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radius", 0.0  );
+
+	start[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startX", -BIG  );
+	start[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startY", -BIG  );
+	start[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startZ", -BIG  );
+	end[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endX", BIG  );
+	end[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endY", BIG  );
+	end[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endZ", BIG  );
+
+	perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"perpendicularAxis", "x" );
+	perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"alongAxis", perpendicularAxisName );
+	switch ( perpendicularAxisName[0] ) {
+		case 'x': case 'X': case 'i': case 'I': case '0':
+			alongAxis = I_AXIS; break;
+		case 'y': case 'Y': case 'j': case 'J': case '1':
+			alongAxis = J_AXIS; break;
+		case 'z': case 'Z': case 'k': case 'K': case '2':
+			alongAxis = K_AXIS; break;
+		default:
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+					"Cannot understand alongAxis '%s'\n", perpendicularAxisName );
+	}
+	
+	_Cylinder_Init( self, radius, start, end, alongAxis );
+}
+
+void _Cylinder_Build( void* cylinder, void* data ) {
+	Cylinder*	self = (Cylinder*)cylinder;
+
+	_Stg_Shape_Build( self, data );
+}
+void _Cylinder_Initialise( void* cylinder, void* data ) {
+	Cylinder*	self = (Cylinder*)cylinder;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _Cylinder_Execute( void* cylinder, void* data ) {
+	Cylinder*	self = (Cylinder*)cylinder;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _Cylinder_Destroy( void* cylinder, void* data ) {
+	Cylinder*	self = (Cylinder*)cylinder;
+
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _Cylinder_IsCoordInside( void* cylinder, Coord coord ) {
+	Cylinder*       self       = (Cylinder*)cylinder;
+	Coord           newCoord;
+	double          insideOutsideValue;
+	double          x, y, z;
+	unsigned        axis_I;
+
+	/* Check whether coord is within min and max values */
+	for ( axis_I = 0 ; axis_I < self->dim ; axis_I++ ) {
+		if ( coord[ axis_I ] < self->start[ axis_I ] || coord[ axis_I ] > self->end[ axis_I ] )
+			return False;
+	}
+	
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+	
+	newCoord[ self->alongAxis ] = 0.0;
+
+	/* Check if coord is within radius */
+	x = newCoord[ I_AXIS ];
+	y = newCoord[ J_AXIS ];
+	if(self->dim == 2)
+		insideOutsideValue = x*x + y*y;
+	else {
+		z = newCoord[ K_AXIS ];
+		insideOutsideValue = x*x + y*y + z*z;
+	}
+	if ( insideOutsideValue > (self->radius * self->radius) )
+		return False;
+
+
+	return True;
+}
+
+void _Cylinder_DistanceFromCenterAxis( void* cylinder, Coord coord, double* disVec ) {
+	Cylinder*       self       = (Cylinder*)cylinder;
+	Coord           newCoord;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+	
+	newCoord[ self->alongAxis ] = 0.0;
+
+	/* Check if coord is within radius */
+	disVec[0] = newCoord[ I_AXIS ];
+	disVec[1] = newCoord[ J_AXIS ];
+	if(self->dim == 3)
+		disVec[2] = newCoord[ K_AXIS ];
+
+	return;
+}
+
+
+double _Cylinder_CalculateVolume( void* cylinder ) {
+	assert( 0 /* unsure how this cylinder is setup...but shouldn't be hard to implement -- Alan */ );
+	return 0.0;
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Everywhere.c
--- a/Shape/src/Everywhere.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) {
-	IrregTopology* self = (IrregTopology*)ir
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Everywhere.c 3869 2006-10-16 13:42:59Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Everywhere.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type Everywhere_Type = "Everywhere";
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-Everywhere* Everywhere_New(
-		Name                                  name,
-		Dimension_Index                       dim )
-{
-	Everywhere* self = (Everywhere*) _Everywhere_DefaultNew( name );
-	XYZ         centre = { 0.0,0.0,0.0 };
-
-	_Stg_Shape_Init( self, dim, centre, False, 0.0, 0.0, 0.0 );
-	_Everywhere_Init( self );
-
-	return self;
-}
-
-Everywhere* _Everywhere_New(  EVERYWHERE_DEFARGS  )
-{
-	Everywhere* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Everywhere) );
-	self = (Everywhere*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	return self;
-}
-
-void _Everywhere_Init( void* everywhere ) {
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Everywhere_Delete( void* everywhere ) {
-	Everywhere* self = (Everywhere*)everywhere;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-void _Everywhere_Print( void* everywhere, Stream* stream ) {
-	Everywhere* self = (Everywhere*)everywhere;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _Everywhere_Copy( const void* everywhere, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Everywhere*	self = (Everywhere*)everywhere;
-	Everywhere*	newEverywhere;
-	
-	newEverywhere = (Everywhere*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	return (void*)newEverywhere;
-}
-
-void* _Everywhere_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Everywhere);
-	Type                                                          type = Everywhere_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Everywhere_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Everywhere_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Everywhere_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Everywhere_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Everywhere_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Everywhere_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Everywhere_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Everywhere_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Everywhere_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Everywhere_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Everywhere_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Everywhere_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Everywhere_New(  EVERYWHERE_PASSARGS  );
-}
-
-
-void _Everywhere_AssignFromXML( void* everywhere, Stg_ComponentFactory* cf, void* data ) {
-	Everywhere*	self          = (Everywhere*) everywhere;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-	_Everywhere_Init( self );
-}
-
-void _Everywhere_Build( void* everywhere, void* data ) {
-	Everywhere*	self = (Everywhere*)everywhere;
-	_Stg_Shape_Build( self, data );
-}
-void _Everywhere_Initialise( void* everywhere, void* data ) {
-	Everywhere*	self = (Everywhere*)everywhere;
-	_Stg_Shape_Initialise( self, data );
-}
-void _Everywhere_Execute( void* everywhere, void* data ) {
-	Everywhere*	self = (Everywhere*)everywhere;
-	_Stg_Shape_Execute( self, data );
-}
-void _Everywhere_Destroy( void* everywhere, void* data ) {
-	Everywhere*	self = (Everywhere*)everywhere;
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _Everywhere_IsCoordInside( void* everywhere, Coord coord ) {
-	return True;
-}
-
-double _Everywhere_CalculateVolume( void* everywhere ) {
-	return 1.0;
-}	
-void _Everywhere_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Everywhere.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Everywhere.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,182 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) {
+	IrregTopology* self = (IrregTopology*)ir
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Everywhere.c 3869 2006-10-16 13:42:59Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Everywhere.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type Everywhere_Type = "Everywhere";
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+Everywhere* Everywhere_New(
+		Name                                  name,
+		Dimension_Index                       dim )
+{
+	Everywhere* self = (Everywhere*) _Everywhere_DefaultNew( name );
+	XYZ         centre = { 0.0,0.0,0.0 };
+
+	_Stg_Shape_Init( self, dim, centre, False, 0.0, 0.0, 0.0 );
+	_Everywhere_Init( self );
+
+	return self;
+}
+
+Everywhere* _Everywhere_New(  EVERYWHERE_DEFARGS  )
+{
+	Everywhere* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Everywhere) );
+	self = (Everywhere*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	return self;
+}
+
+void _Everywhere_Init( void* everywhere ) {
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Everywhere_Delete( void* everywhere ) {
+	Everywhere* self = (Everywhere*)everywhere;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+void _Everywhere_Print( void* everywhere, Stream* stream ) {
+	Everywhere* self = (Everywhere*)everywhere;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _Everywhere_Copy( const void* everywhere, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Everywhere*	self = (Everywhere*)everywhere;
+	Everywhere*	newEverywhere;
+	
+	newEverywhere = (Everywhere*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	return (void*)newEverywhere;
+}
+
+void* _Everywhere_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Everywhere);
+	Type                                                          type = Everywhere_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Everywhere_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Everywhere_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Everywhere_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Everywhere_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Everywhere_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Everywhere_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Everywhere_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Everywhere_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Everywhere_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Everywhere_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Everywhere_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Everywhere_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Everywhere_New(  EVERYWHERE_PASSARGS  );
+}
+
+
+void _Everywhere_AssignFromXML( void* everywhere, Stg_ComponentFactory* cf, void* data ) {
+	Everywhere*	self          = (Everywhere*) everywhere;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+	_Everywhere_Init( self );
+}
+
+void _Everywhere_Build( void* everywhere, void* data ) {
+	Everywhere*	self = (Everywhere*)everywhere;
+	_Stg_Shape_Build( self, data );
+}
+void _Everywhere_Initialise( void* everywhere, void* data ) {
+	Everywhere*	self = (Everywhere*)everywhere;
+	_Stg_Shape_Initialise( self, data );
+}
+void _Everywhere_Execute( void* everywhere, void* data ) {
+	Everywhere*	self = (Everywhere*)everywhere;
+	_Stg_Shape_Execute( self, data );
+}
+void _Everywhere_Destroy( void* everywhere, void* data ) {
+	Everywhere*	self = (Everywhere*)everywhere;
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _Everywhere_IsCoordInside( void* everywhere, Coord coord ) {
+	return True;
+}
+
+double _Everywhere_CalculateVolume( void* everywhere ) {
+	return 1.0;
+}	
+void _Everywhere_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Finalise.c
--- a/Shape/src/Finalise.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool StgDomainShape_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Finalise.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,47 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool StgDomainShape_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Init.c
--- a/Shape/src/Init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Init.c 3599 2006-05-22 00:25:46Z AlanLo $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-
-#include "Shape.h"
-
-#include <stdio.h>
-
-Bool StgDomainShape_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-	Stg_ComponentRegister_Add( componentRegister, Superellipsoid_Type, (Name)"0", _Superellipsoid_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Box_Type, (Name)"0", _Box_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Everywhere_Type, (Name)"0", _Everywhere_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, ConvexHull_Type, (Name)"0", _ConvexHull_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Sphere_Type, (Name)"0", _Sphere_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, PolygonShape_Type, (Name)"0", _PolygonShape_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Union_Type, (Name)"0", _Union_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Intersection_Type, (Name)"0", _Intersection_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, Cylinder_Type, (Name)"0", _Cylinder_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentRegister, BelowPlane_Type, (Name)"0", _BelowPlane_DefaultNew  );
-	Stg_ComponentRegister_Add( componentRegister, BelowCosinePlane_Type, (Name)"0", _BelowCosinePlane_DefaultNew );
-	
-	#ifdef HAVE_PYTHON
-		Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), PythonShape_Type, "0", _PythonShape_DefaultNew );
-		RegisterParent( PythonShape_Type, Stg_Shape_Type);
-	#endif
-
-	RegisterParent( Stg_Shape_Type,                 Stg_Component_Type );
-	RegisterParent( Superellipsoid_Type,            Stg_Shape_Type );
-	RegisterParent( Box_Type,                       Stg_Shape_Type );
-	RegisterParent( Everywhere_Type,                Stg_Shape_Type );
-	RegisterParent( ConvexHull_Type,                Stg_Shape_Type );
-	RegisterParent( Sphere_Type,                    Stg_Shape_Type );
-	RegisterParent( PolygonShape_Type,                   Stg_Shape_Type );
-	RegisterParent( Union_Type,                     Stg_Shape_Type );
-	RegisterParent( Intersection_Type,              Stg_Shape_Type );
-	RegisterParent( Cylinder_Type,                  Stg_Shape_Type );
-	
-	RegisterParent( BelowPlane_Type,                  Stg_Shape_Type );
-	RegisterParent( BelowCosinePlane_Type,            BelowPlane_Type );
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,80 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Init.c 3599 2006-05-22 00:25:46Z AlanLo $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+
+#include "Shape.h"
+
+#include <stdio.h>
+
+Bool StgDomainShape_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+	Stg_ComponentRegister_Add( componentRegister, Superellipsoid_Type, (Name)"0", _Superellipsoid_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Box_Type, (Name)"0", _Box_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Everywhere_Type, (Name)"0", _Everywhere_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, ConvexHull_Type, (Name)"0", _ConvexHull_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Sphere_Type, (Name)"0", _Sphere_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, PolygonShape_Type, (Name)"0", _PolygonShape_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Union_Type, (Name)"0", _Union_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Intersection_Type, (Name)"0", _Intersection_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, Cylinder_Type, (Name)"0", _Cylinder_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentRegister, BelowPlane_Type, (Name)"0", _BelowPlane_DefaultNew  );
+	Stg_ComponentRegister_Add( componentRegister, BelowCosinePlane_Type, (Name)"0", _BelowCosinePlane_DefaultNew );
+	
+	#ifdef HAVE_PYTHON
+		Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), PythonShape_Type, "0", _PythonShape_DefaultNew );
+		RegisterParent( PythonShape_Type, Stg_Shape_Type);
+	#endif
+
+	RegisterParent( Stg_Shape_Type,                 Stg_Component_Type );
+	RegisterParent( Superellipsoid_Type,            Stg_Shape_Type );
+	RegisterParent( Box_Type,                       Stg_Shape_Type );
+	RegisterParent( Everywhere_Type,                Stg_Shape_Type );
+	RegisterParent( ConvexHull_Type,                Stg_Shape_Type );
+	RegisterParent( Sphere_Type,                    Stg_Shape_Type );
+	RegisterParent( PolygonShape_Type,                   Stg_Shape_Type );
+	RegisterParent( Union_Type,                     Stg_Shape_Type );
+	RegisterParent( Intersection_Type,              Stg_Shape_Type );
+	RegisterParent( Cylinder_Type,                  Stg_Shape_Type );
+	
+	RegisterParent( BelowPlane_Type,                  Stg_Shape_Type );
+	RegisterParent( BelowCosinePlane_Type,            BelowPlane_Type );
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Intersection.c
--- a/Shape/src/Intersection.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,292 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Intersection.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Intersection.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type Intersection_Type = "Intersection";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Intersection* Intersection_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		Stg_Shape**                           shapeList,
-		Index                                 shapeCount,
-		Bool*                                 isComplement
-		)
-{
-	Intersection* self = (Intersection*)_Intersection_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
-	_Intersection_Init( self, shapeList, shapeCount, isComplement );
-	return self;
-}
-
-Intersection* _Intersection_New(  INTERSECTION_DEFARGS  )
-{
-	Intersection* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Intersection) );
-	self = (Intersection*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	return self;
-}
-
-void _Intersection_Init( void* intersection,  Stg_Shape** shapeList, Index shapeCount, Bool* isComplement ) {
-	Intersection* self = (Intersection*)intersection;
-	
-	self->shapeList    = Memory_Alloc_Array( Stg_Shape* , shapeCount , "shapeList" );
-	self->isComplement = Memory_Alloc_Array( Bool,        shapeCount , "isComplement" );
-
-	memcpy( self->shapeList , shapeList, sizeof(Stg_Shape*) * shapeCount );
-	memcpy( self->isComplement , isComplement, sizeof(Bool) * shapeCount );
-	self->shapeCount = shapeCount;
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Intersection_Delete( void* intersection ) {
-	Intersection*       self = (Intersection*)intersection;
-
-	Memory_Free( self->shapeList );
-
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _Intersection_Print( void* intersection, Stream* stream ) {
-	Intersection* self = (Intersection*)intersection;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-
-
-void* _Intersection_Copy( const void* intersection, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Intersection*	self = (Intersection*)intersection;
-	Intersection*	newIntersection;
-	
-	newIntersection = (Intersection*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newIntersection->shapeList = Memory_Alloc_Array( Stg_Shape*, self->shapeCount, "shapeList" );
-	memcpy( newIntersection->shapeList , self->shapeList, sizeof(Stg_Shape*) * self->shapeCount );
-	
-	newIntersection->isComplement = Memory_Alloc_Array( Bool , self->shapeCount, "isComplement" );
-	memcpy( newIntersection->isComplement , self->isComplement, sizeof(Bool) * self->shapeCount );
-
-	newIntersection->isComplement = self->isComplement;
-	newIntersection->shapeList = self->shapeList;
-	newIntersection->shapeCount = self->shapeCount;
-	
-	return (void*)newIntersection;
-}
-
-void* _Intersection_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Intersection);
-	Type                                                          type = Intersection_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Intersection_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Intersection_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Intersection_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Intersection_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Intersection_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Intersection_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Intersection_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Intersection_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Intersection_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Intersection_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Intersection_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Intersection_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Intersection_New(  INTERSECTION_PASSARGS  );
-}
-
-
-void _Intersection_AssignFromXML( void* intersection, Stg_ComponentFactory* cf, void* data ) {
-	Intersection*	        self       = (Intersection*)intersection;
-	Index                   shapeCount;
-	Stg_Shape**             shapeList;
-	Bool*                   isComplement;
-	Index                   shape_I;
-	Dictionary_Entry_Value* optionsList;
-	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	char*                   nameShape;
-	Stream*                 stream     = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
-	
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"shapes"  );
-/*	Journal_Firewall( vertexList != NULL, 
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"In func %s: vertexList specifying the intersection is NULL.\n",
-		__func__);
-
-*/	shapeCount = Dictionary_Entry_Value_GetCount(optionsList);
-
-	/* Allocate space */
-	shapeList     = Memory_Alloc_Array( Stg_Shape* , shapeCount, "Shape Array" );
-	isComplement  = Memory_Alloc_Array( Bool, shapeCount, "Complement Array" );
-	memset( shapeList,     0, shapeCount * sizeof(Stg_Shape*) );
-	memset( isComplement,  0, shapeCount * sizeof(Bool) );
-	
-	/* TALK ABOUT WITH ROB, will there be some Flag for Union or Intersection type in the XML file. */
-	/* If so do we need another variable on the intersection class which is this flag, and then use that flag  */
-	/* to determine the method of test if a particle is inside or outside the shape */
-
-
-	
-	Stream_Indent( stream );
-	for ( shape_I = 0 ; shape_I < shapeCount ; shape_I++) { 
-          /* gets the textual name corresponding to the shape elements	 */
-		nameShape = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( optionsList, shape_I));
-
-		if ( nameShape[0] == '!' ) {
-			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)&nameShape[1], Stg_Shape, True, data  ) ;
-			isComplement[ shape_I ] = True;
-		}
-		else {
-			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)nameShape, Stg_Shape, True, data ) ;
-			isComplement[ shape_I ] = False;
-		}
-		
-	}
-	Stream_UnIndent( stream  );
-
-	_Intersection_Init( self, shapeList, shapeCount, isComplement );
-
-	Memory_Free( shapeList );
-	Memory_Free( isComplement );
-}
-
-void _Intersection_Build( void* intersection, void* data ) {
-	Intersection*	self = (Intersection*)intersection;
-   unsigned shape_I = 0;
- 
-   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
-      Stg_Component_Build( self->shapeList[shape_I], data, False );
-   }
-	_Stg_Shape_Build( self, data );
-}
-void _Intersection_Initialise( void* intersection, void* data ) {
-	Intersection*	self = (Intersection*)intersection;
-   unsigned shape_I = 0;
-
-   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
-      Stg_Component_Initialise( self->shapeList[shape_I], data, False );
-   }	
-	_Stg_Shape_Initialise( self, data );
-}
-void _Intersection_Execute( void* intersection, void* data ) {
-	Intersection*	self = (Intersection*)intersection;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _Intersection_Destroy( void* intersection, void* data ) {
-	Intersection*	self = (Intersection*)intersection;
-   unsigned shape_I = 0;
-    
-   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
-      Stg_Component_Destroy( self->shapeList[shape_I], data, False );
-   }
-	Memory_Free( self->isComplement );
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-Bool _Intersection_IsCoordInside( void* intersection, Coord coord ) {
-	Intersection*   self           = (Intersection*)intersection;
-	Index           shapeCount     = self->shapeCount;
-	Index           shape_I;
-	Bool            value;
-
-	for( shape_I = 0 ; shape_I < shapeCount ; shape_I++ ) {
-		value = Stg_Shape_IsCoordInside( self->shapeList[ shape_I ], coord );
-
-		
-		if ( self->isComplement[ shape_I ] )
-                  value = (!value) ? True : False;
-			
-		if ( ! value )
-			return False;
-	}
-	return True;
-}	
-
-double _Intersection_CalculateVolume( void* intersection ) {
-	assert( 0 /* not impossible as long as you have other shapes with volum */ );
-	return 0.0;
-}
-void _Intersection_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-	
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Intersection.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Intersection.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,292 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Intersection.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Intersection.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type Intersection_Type = "Intersection";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Intersection* Intersection_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		Stg_Shape**                           shapeList,
+		Index                                 shapeCount,
+		Bool*                                 isComplement
+		)
+{
+	Intersection* self = (Intersection*)_Intersection_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
+	_Intersection_Init( self, shapeList, shapeCount, isComplement );
+	return self;
+}
+
+Intersection* _Intersection_New(  INTERSECTION_DEFARGS  )
+{
+	Intersection* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Intersection) );
+	self = (Intersection*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	return self;
+}
+
+void _Intersection_Init( void* intersection,  Stg_Shape** shapeList, Index shapeCount, Bool* isComplement ) {
+	Intersection* self = (Intersection*)intersection;
+	
+	self->shapeList    = Memory_Alloc_Array( Stg_Shape* , shapeCount , "shapeList" );
+	self->isComplement = Memory_Alloc_Array( Bool,        shapeCount , "isComplement" );
+
+	memcpy( self->shapeList , shapeList, sizeof(Stg_Shape*) * shapeCount );
+	memcpy( self->isComplement , isComplement, sizeof(Bool) * shapeCount );
+	self->shapeCount = shapeCount;
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Intersection_Delete( void* intersection ) {
+	Intersection*       self = (Intersection*)intersection;
+
+	Memory_Free( self->shapeList );
+
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _Intersection_Print( void* intersection, Stream* stream ) {
+	Intersection* self = (Intersection*)intersection;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _Intersection_Copy( const void* intersection, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Intersection*	self = (Intersection*)intersection;
+	Intersection*	newIntersection;
+	
+	newIntersection = (Intersection*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newIntersection->shapeList = Memory_Alloc_Array( Stg_Shape*, self->shapeCount, "shapeList" );
+	memcpy( newIntersection->shapeList , self->shapeList, sizeof(Stg_Shape*) * self->shapeCount );
+	
+	newIntersection->isComplement = Memory_Alloc_Array( Bool , self->shapeCount, "isComplement" );
+	memcpy( newIntersection->isComplement , self->isComplement, sizeof(Bool) * self->shapeCount );
+
+	newIntersection->isComplement = self->isComplement;
+	newIntersection->shapeList = self->shapeList;
+	newIntersection->shapeCount = self->shapeCount;
+	
+	return (void*)newIntersection;
+}
+
+void* _Intersection_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Intersection);
+	Type                                                          type = Intersection_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Intersection_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Intersection_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Intersection_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Intersection_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Intersection_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Intersection_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Intersection_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Intersection_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Intersection_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Intersection_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Intersection_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Intersection_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Intersection_New(  INTERSECTION_PASSARGS  );
+}
+
+
+void _Intersection_AssignFromXML( void* intersection, Stg_ComponentFactory* cf, void* data ) {
+	Intersection*	        self       = (Intersection*)intersection;
+	Index                   shapeCount;
+	Stg_Shape**             shapeList;
+	Bool*                   isComplement;
+	Index                   shape_I;
+	Dictionary_Entry_Value* optionsList;
+	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	char*                   nameShape;
+	Stream*                 stream     = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
+	
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"shapes"  );
+/*	Journal_Firewall( vertexList != NULL, 
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"In func %s: vertexList specifying the intersection is NULL.\n",
+		__func__);
+
+*/	shapeCount = Dictionary_Entry_Value_GetCount(optionsList);
+
+	/* Allocate space */
+	shapeList     = Memory_Alloc_Array( Stg_Shape* , shapeCount, "Shape Array" );
+	isComplement  = Memory_Alloc_Array( Bool, shapeCount, "Complement Array" );
+	memset( shapeList,     0, shapeCount * sizeof(Stg_Shape*) );
+	memset( isComplement,  0, shapeCount * sizeof(Bool) );
+	
+	/* TALK ABOUT WITH ROB, will there be some Flag for Union or Intersection type in the XML file. */
+	/* If so do we need another variable on the intersection class which is this flag, and then use that flag  */
+	/* to determine the method of test if a particle is inside or outside the shape */
+
+
+	
+	Stream_Indent( stream );
+	for ( shape_I = 0 ; shape_I < shapeCount ; shape_I++) { 
+          /* gets the textual name corresponding to the shape elements	 */
+		nameShape = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( optionsList, shape_I));
+
+		if ( nameShape[0] == '!' ) {
+			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)&nameShape[1], Stg_Shape, True, data  ) ;
+			isComplement[ shape_I ] = True;
+		}
+		else {
+			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)nameShape, Stg_Shape, True, data ) ;
+			isComplement[ shape_I ] = False;
+		}
+		
+	}
+	Stream_UnIndent( stream  );
+
+	_Intersection_Init( self, shapeList, shapeCount, isComplement );
+
+	Memory_Free( shapeList );
+	Memory_Free( isComplement );
+}
+
+void _Intersection_Build( void* intersection, void* data ) {
+	Intersection*	self = (Intersection*)intersection;
+   unsigned shape_I = 0;
+ 
+   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
+      Stg_Component_Build( self->shapeList[shape_I], data, False );
+   }
+	_Stg_Shape_Build( self, data );
+}
+void _Intersection_Initialise( void* intersection, void* data ) {
+	Intersection*	self = (Intersection*)intersection;
+   unsigned shape_I = 0;
+
+   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
+      Stg_Component_Initialise( self->shapeList[shape_I], data, False );
+   }	
+	_Stg_Shape_Initialise( self, data );
+}
+void _Intersection_Execute( void* intersection, void* data ) {
+	Intersection*	self = (Intersection*)intersection;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _Intersection_Destroy( void* intersection, void* data ) {
+	Intersection*	self = (Intersection*)intersection;
+   unsigned shape_I = 0;
+    
+   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
+      Stg_Component_Destroy( self->shapeList[shape_I], data, False );
+   }
+	Memory_Free( self->isComplement );
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+Bool _Intersection_IsCoordInside( void* intersection, Coord coord ) {
+	Intersection*   self           = (Intersection*)intersection;
+	Index           shapeCount     = self->shapeCount;
+	Index           shape_I;
+	Bool            value;
+
+	for( shape_I = 0 ; shape_I < shapeCount ; shape_I++ ) {
+		value = Stg_Shape_IsCoordInside( self->shapeList[ shape_I ], coord );
+
+		
+		if ( self->isComplement[ shape_I ] )
+                  value = (!value) ? True : False;
+			
+		if ( ! value )
+			return False;
+	}
+	return True;
+}	
+
+double _Intersection_CalculateVolume( void* intersection ) {
+	assert( 0 /* not impossible as long as you have other shapes with volum */ );
+	return 0.0;
+}
+void _Intersection_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+	
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/PolygonShape.c
--- a/Shape/src/PolygonShape.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,336 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: PolygonShape.c 4056 2007-03-29 04:55:51Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "PolygonShape.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type PolygonShape_Type = "PolygonShape";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-PolygonShape* PolygonShape_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		Coord_List                            vertexList,
-		Index                                 vertexCount,
-		XYZ                                   start,
-		XYZ                                   end,
-	   Axis                                  perpendicularAxis	)
-{ 
-	PolygonShape* self = (PolygonShape*)_PolygonShape_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
-   _PolygonShape_Init( self, vertexList, vertexCount, start, end, perpendicularAxis );
-	return self;
-}
-
-PolygonShape* _PolygonShape_New(  POLYGONSHAPE_DEFARGS  )
-{
-	PolygonShape* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(PolygonShape) );
-	self = (PolygonShape*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-	return self;
-}
-
-void _PolygonShape_Init( void* polygon, Coord_List vertexList, Index vertexCount, XYZ start, XYZ end, Axis perpendicularAxis ) {
-	PolygonShape* self = (PolygonShape*)polygon;
-	
-	self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
-	memcpy( self->vertexList , vertexList, sizeof(Coord) * vertexCount );
-	self->vertexCount = vertexCount;
-	memcpy( self->start , start, sizeof(XYZ) );
-	memcpy( self->end , end, sizeof(XYZ) );
-	self->perpendicularAxis = perpendicularAxis;
-}
-	
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _PolygonShape_Delete( void* polygon ) {
-	PolygonShape*       self = (PolygonShape*)polygon;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _PolygonShape_Print( void* polygon, Stream* stream ) {
-	PolygonShape* self = (PolygonShape*)polygon;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-
-
-void* _PolygonShape_Copy( const void* polygon, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	PolygonShape*	self = (PolygonShape*)polygon;
-	PolygonShape*	newPolygonShape;
-	
-	newPolygonShape = (PolygonShape*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newPolygonShape->vertexList = Memory_Alloc_Array( Coord, self->vertexCount, "vertexList" );
-	memcpy( newPolygonShape->vertexList , self->vertexList, sizeof(Coord) * self->vertexCount );
-
-	newPolygonShape->vertexList  = self->vertexList;
-	newPolygonShape->vertexCount = self->vertexCount;
-	memcpy( newPolygonShape->start, self->start, sizeof(XYZ) );
-	memcpy( newPolygonShape->end, self->end, sizeof(XYZ) );
-	
-	return (void*)newPolygonShape;
-}
-
-void* _PolygonShape_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(PolygonShape);
-	Type                                                          type = PolygonShape_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _PolygonShape_Delete;
-	Stg_Class_PrintFunction*                                    _print = _PolygonShape_Print;
-	Stg_Class_CopyFunction*                                      _copy = _PolygonShape_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _PolygonShape_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _PolygonShape_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _PolygonShape_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _PolygonShape_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _PolygonShape_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _PolygonShape_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _PolygonShape_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _PolygonShape_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _PolygonShape_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _PolygonShape_New(  POLYGONSHAPE_PASSARGS  );
-}
-
-
-void _PolygonShape_AssignFromXML( void* polygon, Stg_ComponentFactory* cf, void* data ) {
-	PolygonShape*           self       = (PolygonShape*)polygon;
-	Index                   vertexCount;
-	Index                   vertex_I;
-	Coord_List              vertexList;
-	XYZ                     start;
-	XYZ                     end;
-	Axis                    perpendicularAxis;
-	char*                   perpendicularAxisName;
-	double*                 coord;
-	Dictionary_Entry_Value* optionSet;
-	Dictionary_Entry_Value* optionsList;
-	Dictionary*             dictionary  = Dictionary_GetDictionary( cf->componentDict, self->name );
-	Stream*                 stream      = cf->infoStream;
-	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
-	
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	start[I_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startX", 0.0  );
-	end[I_AXIS]   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endX", 0.0  );
-	start[J_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startY", 0.0  );
-	end[J_AXIS]   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endY", 0.0  );
-	start[K_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startZ", 0.0  );
-	end[K_AXIS]   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endZ", 0.0  );
-
-	perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"perpendicularAxis", "z" );
-	switch ( perpendicularAxisName[0]  ) {
-		case 'x': case 'X': case 'i': case 'I': case '0':
-			perpendicularAxis = I_AXIS; break;
-		case 'y': case 'Y': case 'j': case 'J': case '1':
-			perpendicularAxis = J_AXIS; break;
-		case 'z': case 'Z': case 'k': case 'K': case '2':
-			perpendicularAxis = K_AXIS; break;
-		default:
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-					"Cannot understand perpendicularAxis '%s'\n", perpendicularAxisName );
-	}
-	if( self->dim == 3 && ( start[perpendicularAxis] == 0 && end[perpendicularAxis] == 0 ) ) {
-		Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-		"Problem with %s.\n"
-		"You've set the perpendicular axis to be %s, but you've not given the polygon any depth in that axis\n",
-	        self->name, perpendicularAxisName );
-	}	
-
-	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices" );
-	
-	vertexCount = Dictionary_Entry_Value_GetCount(optionsList );
-	Journal_Firewall( vertexCount >= 3, errorStream, 
-			"Too few vertices given in trying to build shape '%s' named '%s'.\n"
-			"A polygon needs at least three vertices.\n",
-			self->type, self->name );
-
-	/* Allocate space */
-	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
-	memset( vertexList, 0, vertexCount * sizeof(Coord) );
-
-	Stream_Indent( stream );
-	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
-		optionSet = Dictionary_Entry_Value_GetElement(optionsList, vertex_I );
-		coord = vertexList[vertex_I];
-		/* Read Vertex */
-		if( perpendicularAxis != I_AXIS )
-			coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"x"));
-		if( perpendicularAxis != J_AXIS  )
-			coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"y"));
-		if( perpendicularAxis != K_AXIS  )
-			coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"z") );
-
-		/* Print Position */
-		Journal_PrintfL( stream, 2, "(%0.3g, %0.3g, %0.3g)\n", coord[I_AXIS], coord[J_AXIS], coord[K_AXIS] );
-	}
-	Stream_UnIndent( stream );
-
-	_PolygonShape_Init( self, vertexList, vertexCount, start, end, perpendicularAxis );
-
-	Memory_Free( vertexList );
-}
-
-void _PolygonShape_Build( void* polygon, void* data ) {
-	PolygonShape*	self = (PolygonShape*)polygon;
-
-	_Stg_Shape_Build( self, data );
-}
-void _PolygonShape_Initialise( void* polygon, void* data ) {
-	PolygonShape*	self = (PolygonShape*)polygon;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _PolygonShape_Execute( void* polygon, void* data ) {
-	PolygonShape*	self = (PolygonShape*)polygon;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _PolygonShape_Destroy( void* polygon, void* data ) {
-	PolygonShape*	self = (PolygonShape*)polygon;
-
-	Coord_List     vertexList = self->vertexList;
-	Memory_Free( vertexList );
-
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-/* Algorithm describe Paul Bourke's page http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/ (see solution 2)
- *
- * Algorithm works by summing the angles between the test coordinate and each pair of vertices that make up an edge 
- * in the polygon. An inside point will give an angle of 2pi and and outside point will give an angle of 0 */
-
-Bool _PolygonShape_IsCoordInside( void* polygon, Coord coord ) {
-	PolygonShape*        self                = (PolygonShape*) polygon;
-	Index           vertexCount         = self->vertexCount;
-	Coord_List      vertexList          = self->vertexList;
-	Axis            perpendicularAxis   = self->perpendicularAxis;
-	XYZ             vectorToStartVertex = { 0.0, 0.0, 0.0 };
-	XYZ             vectorToEndVertex   = { 0.0, 0.0, 0.0 };
-	XYZ             crossproduct        = { 0.0, 0.0, 0.0 };
-	double          currAngle;
-	double          totalAngle          = 0.0;
-	Index           vertex_I;
-	double*         startVertex;
-	double*         endVertex;
-       Coord           newCoord;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-
-	/* Check to make sure that the coordinate is within startZ and endZ in 3D */
-	if ( self->dim == 3 && ( newCoord[ perpendicularAxis ] < self->start[perpendicularAxis] || newCoord[ perpendicularAxis ] > self->end[perpendicularAxis] ))
-		return False;	
-
-	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++ ) {
-		/* Get vertices of current edge */
-		startVertex = vertexList[ vertex_I ];
-		endVertex   = vertexList[ (vertex_I + 1) % vertexCount ];
-
-		/* Work out vectors */
-		StGermain_VectorSubtraction( vectorToStartVertex, newCoord, startVertex, 3 );
-		StGermain_VectorSubtraction( vectorToEndVertex,   newCoord, endVertex,  3 );
-
-		vectorToStartVertex[ perpendicularAxis ] = 0;
-		vectorToEndVertex[ perpendicularAxis ] = 0;
-
-		/* Work out angle - just by doing dot product - will always be positive */
-		currAngle = StGermain_AngleBetweenVectors( vectorToStartVertex, vectorToEndVertex, 3 );
-
-		/* Work out 'sign' of angle but working out cross product */
-		StGermain_VectorCrossProduct( crossproduct, vectorToEndVertex, vectorToStartVertex );
-
-		if ( crossproduct[ perpendicularAxis ] > 0.0 )
-			totalAngle += currAngle;
-		else
-			totalAngle -= currAngle;
-	}
-
-
-	/* work out whether the coord is within the polygon */
-	if ( fabs( totalAngle ) < M_PI )
-		return False;
-	else  
-		return True;
-}
-
-
-double _PolygonShape_CalculateVolume( void* polygon ) {
-	assert( 0 );
-	return 0.0;
-}
-
-void _PolygonShape_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/PolygonShape.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/PolygonShape.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,336 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: PolygonShape.c 4056 2007-03-29 04:55:51Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "PolygonShape.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type PolygonShape_Type = "PolygonShape";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+PolygonShape* PolygonShape_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		Coord_List                            vertexList,
+		Index                                 vertexCount,
+		XYZ                                   start,
+		XYZ                                   end,
+	   Axis                                  perpendicularAxis	)
+{ 
+	PolygonShape* self = (PolygonShape*)_PolygonShape_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
+   _PolygonShape_Init( self, vertexList, vertexCount, start, end, perpendicularAxis );
+	return self;
+}
+
+PolygonShape* _PolygonShape_New(  POLYGONSHAPE_DEFARGS  )
+{
+	PolygonShape* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(PolygonShape) );
+	self = (PolygonShape*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+	return self;
+}
+
+void _PolygonShape_Init( void* polygon, Coord_List vertexList, Index vertexCount, XYZ start, XYZ end, Axis perpendicularAxis ) {
+	PolygonShape* self = (PolygonShape*)polygon;
+	
+	self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
+	memcpy( self->vertexList , vertexList, sizeof(Coord) * vertexCount );
+	self->vertexCount = vertexCount;
+	memcpy( self->start , start, sizeof(XYZ) );
+	memcpy( self->end , end, sizeof(XYZ) );
+	self->perpendicularAxis = perpendicularAxis;
+}
+	
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _PolygonShape_Delete( void* polygon ) {
+	PolygonShape*       self = (PolygonShape*)polygon;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _PolygonShape_Print( void* polygon, Stream* stream ) {
+	PolygonShape* self = (PolygonShape*)polygon;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _PolygonShape_Copy( const void* polygon, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	PolygonShape*	self = (PolygonShape*)polygon;
+	PolygonShape*	newPolygonShape;
+	
+	newPolygonShape = (PolygonShape*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newPolygonShape->vertexList = Memory_Alloc_Array( Coord, self->vertexCount, "vertexList" );
+	memcpy( newPolygonShape->vertexList , self->vertexList, sizeof(Coord) * self->vertexCount );
+
+	newPolygonShape->vertexList  = self->vertexList;
+	newPolygonShape->vertexCount = self->vertexCount;
+	memcpy( newPolygonShape->start, self->start, sizeof(XYZ) );
+	memcpy( newPolygonShape->end, self->end, sizeof(XYZ) );
+	
+	return (void*)newPolygonShape;
+}
+
+void* _PolygonShape_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(PolygonShape);
+	Type                                                          type = PolygonShape_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _PolygonShape_Delete;
+	Stg_Class_PrintFunction*                                    _print = _PolygonShape_Print;
+	Stg_Class_CopyFunction*                                      _copy = _PolygonShape_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _PolygonShape_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _PolygonShape_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _PolygonShape_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _PolygonShape_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _PolygonShape_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _PolygonShape_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _PolygonShape_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _PolygonShape_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _PolygonShape_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _PolygonShape_New(  POLYGONSHAPE_PASSARGS  );
+}
+
+
+void _PolygonShape_AssignFromXML( void* polygon, Stg_ComponentFactory* cf, void* data ) {
+	PolygonShape*           self       = (PolygonShape*)polygon;
+	Index                   vertexCount;
+	Index                   vertex_I;
+	Coord_List              vertexList;
+	XYZ                     start;
+	XYZ                     end;
+	Axis                    perpendicularAxis;
+	char*                   perpendicularAxisName;
+	double*                 coord;
+	Dictionary_Entry_Value* optionSet;
+	Dictionary_Entry_Value* optionsList;
+	Dictionary*             dictionary  = Dictionary_GetDictionary( cf->componentDict, self->name );
+	Stream*                 stream      = cf->infoStream;
+	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
+	
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	start[I_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startX", 0.0  );
+	end[I_AXIS]   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endX", 0.0  );
+	start[J_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startY", 0.0  );
+	end[J_AXIS]   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endY", 0.0  );
+	start[K_AXIS] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"startZ", 0.0  );
+	end[K_AXIS]   = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"endZ", 0.0  );
+
+	perpendicularAxisName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"perpendicularAxis", "z" );
+	switch ( perpendicularAxisName[0]  ) {
+		case 'x': case 'X': case 'i': case 'I': case '0':
+			perpendicularAxis = I_AXIS; break;
+		case 'y': case 'Y': case 'j': case 'J': case '1':
+			perpendicularAxis = J_AXIS; break;
+		case 'z': case 'Z': case 'k': case 'K': case '2':
+			perpendicularAxis = K_AXIS; break;
+		default:
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+					"Cannot understand perpendicularAxis '%s'\n", perpendicularAxisName );
+	}
+	if( self->dim == 3 && ( start[perpendicularAxis] == 0 && end[perpendicularAxis] == 0 ) ) {
+		Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+		"Problem with %s.\n"
+		"You've set the perpendicular axis to be %s, but you've not given the polygon any depth in that axis\n",
+	        self->name, perpendicularAxisName );
+	}	
+
+	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices" );
+	
+	vertexCount = Dictionary_Entry_Value_GetCount(optionsList );
+	Journal_Firewall( vertexCount >= 3, errorStream, 
+			"Too few vertices given in trying to build shape '%s' named '%s'.\n"
+			"A polygon needs at least three vertices.\n",
+			self->type, self->name );
+
+	/* Allocate space */
+	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
+	memset( vertexList, 0, vertexCount * sizeof(Coord) );
+
+	Stream_Indent( stream );
+	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
+		optionSet = Dictionary_Entry_Value_GetElement(optionsList, vertex_I );
+		coord = vertexList[vertex_I];
+		/* Read Vertex */
+		if( perpendicularAxis != I_AXIS )
+			coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"x"));
+		if( perpendicularAxis != J_AXIS  )
+			coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"y"));
+		if( perpendicularAxis != K_AXIS  )
+			coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( optionSet, (Dictionary_Entry_Key)"z") );
+
+		/* Print Position */
+		Journal_PrintfL( stream, 2, "(%0.3g, %0.3g, %0.3g)\n", coord[I_AXIS], coord[J_AXIS], coord[K_AXIS] );
+	}
+	Stream_UnIndent( stream );
+
+	_PolygonShape_Init( self, vertexList, vertexCount, start, end, perpendicularAxis );
+
+	Memory_Free( vertexList );
+}
+
+void _PolygonShape_Build( void* polygon, void* data ) {
+	PolygonShape*	self = (PolygonShape*)polygon;
+
+	_Stg_Shape_Build( self, data );
+}
+void _PolygonShape_Initialise( void* polygon, void* data ) {
+	PolygonShape*	self = (PolygonShape*)polygon;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _PolygonShape_Execute( void* polygon, void* data ) {
+	PolygonShape*	self = (PolygonShape*)polygon;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _PolygonShape_Destroy( void* polygon, void* data ) {
+	PolygonShape*	self = (PolygonShape*)polygon;
+
+	Coord_List     vertexList = self->vertexList;
+	Memory_Free( vertexList );
+
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+/* Algorithm describe Paul Bourke's page http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/ (see solution 2)
+ *
+ * Algorithm works by summing the angles between the test coordinate and each pair of vertices that make up an edge 
+ * in the polygon. An inside point will give an angle of 2pi and and outside point will give an angle of 0 */
+
+Bool _PolygonShape_IsCoordInside( void* polygon, Coord coord ) {
+	PolygonShape*        self                = (PolygonShape*) polygon;
+	Index           vertexCount         = self->vertexCount;
+	Coord_List      vertexList          = self->vertexList;
+	Axis            perpendicularAxis   = self->perpendicularAxis;
+	XYZ             vectorToStartVertex = { 0.0, 0.0, 0.0 };
+	XYZ             vectorToEndVertex   = { 0.0, 0.0, 0.0 };
+	XYZ             crossproduct        = { 0.0, 0.0, 0.0 };
+	double          currAngle;
+	double          totalAngle          = 0.0;
+	Index           vertex_I;
+	double*         startVertex;
+	double*         endVertex;
+       Coord           newCoord;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+
+	/* Check to make sure that the coordinate is within startZ and endZ in 3D */
+	if ( self->dim == 3 && ( newCoord[ perpendicularAxis ] < self->start[perpendicularAxis] || newCoord[ perpendicularAxis ] > self->end[perpendicularAxis] ))
+		return False;	
+
+	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++ ) {
+		/* Get vertices of current edge */
+		startVertex = vertexList[ vertex_I ];
+		endVertex   = vertexList[ (vertex_I + 1) % vertexCount ];
+
+		/* Work out vectors */
+		StGermain_VectorSubtraction( vectorToStartVertex, newCoord, startVertex, 3 );
+		StGermain_VectorSubtraction( vectorToEndVertex,   newCoord, endVertex,  3 );
+
+		vectorToStartVertex[ perpendicularAxis ] = 0;
+		vectorToEndVertex[ perpendicularAxis ] = 0;
+
+		/* Work out angle - just by doing dot product - will always be positive */
+		currAngle = StGermain_AngleBetweenVectors( vectorToStartVertex, vectorToEndVertex, 3 );
+
+		/* Work out 'sign' of angle but working out cross product */
+		StGermain_VectorCrossProduct( crossproduct, vectorToEndVertex, vectorToStartVertex );
+
+		if ( crossproduct[ perpendicularAxis ] > 0.0 )
+			totalAngle += currAngle;
+		else
+			totalAngle -= currAngle;
+	}
+
+
+	/* work out whether the coord is within the polygon */
+	if ( fabs( totalAngle ) < M_PI )
+		return False;
+	else  
+		return True;
+}
+
+
+double _PolygonShape_CalculateVolume( void* polygon ) {
+	assert( 0 );
+	return 0.0;
+}
+
+void _PolygonShape_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/PythonShape.c
--- a/Shape/src/PythonShape.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,263 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: PythonShape.c 3869 2006-10-16 13:42:59Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#ifdef HAVE_PYTHON
-#include <Python.h>
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "PythonShape.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type PythonShape_Type = "PythonShape";
-
-char* PYTHONSHAPE_TEST_CONDITION_NAME = "testCondition";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-PythonShape* PythonShape_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		char*                                 conditionFunction )
-{
-	PythonShape* self = (PythonShape*) _PythonShape_DefaultNew( name );
-
-	PythonShape_InitAll( 
-		self, 
-		dim,
-		centre,
-		alpha,
-		beta,
-		gamma,
-		conditionFunction );
-	return self;
-}
-
-PythonShape* _PythonShape_New(  PYTHONSHAPE_DEFARGS  )
-{
-	PythonShape* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(PythonShape) );
-	self = (PythonShape*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	
-	return self;
-}
-
-void _PythonShape_Init( void* pythonShape, Name conditionFunction ) {
-	PythonShape* self = (PythonShape*)pythonShape;
-	
-	Stg_asprintf( &self->testCondition, "%s = %s", PYTHONSHAPE_TEST_CONDITION_NAME, conditionFunction );
-	
-	/* Python Stuff */
-	self->pythonDictionary = PyModule_GetDict(PyImport_AddModule("__main__"));
-	PyRun_SimpleString( "from math import *" );
-}
-
-
-void PythonShape_InitAll( 
-		void*                                 pythonShape, 
-		Dimension_Index                       dim, 
-		Coord                                 centre,
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		char*                                 conditionFunction )
-{
-	PythonShape* self = (PythonShape*)pythonShape;
-
-	Stg_Shape_InitAll( self, dim, centre, alpha, beta, gamma );
-	_PythonShape_Init( self, conditionFunction );
-}
-	
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _PythonShape_Delete( void* pythonShape ) {
-	PythonShape* self = (PythonShape*)pythonShape;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-
-}
-
-
-void _PythonShape_Print( void* pythonShape, Stream* stream ) {
-	PythonShape* self = (PythonShape*)pythonShape;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-
-
-void* _PythonShape_Copy( const void* pythonShape, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	PythonShape*	self = (PythonShape*)pythonShape;
-	PythonShape*	newPythonShape;
-	
-	newPythonShape = (PythonShape*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-	abort();
-	
-	return (void*)newPythonShape;
-}
-
-void* _PythonShape_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(PythonShape);
-	Type                                                          type = PythonShape_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _PythonShape_Delete;
-	Stg_Class_PrintFunction*                                    _print = _PythonShape_Print;
-	Stg_Class_CopyFunction*                                      _copy = _PythonShape_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _PythonShape_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _PythonShape_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _PythonShape_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _PythonShape_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _PythonShape_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _PythonShape_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _PythonShape_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _PythonShape_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _PythonShape_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _PythonShape_New(  PYTHONSHAPE_PASSARGS  );
-}
-
-
-void _PythonShape_AssignFromXML( void* pythonShape, Stg_ComponentFactory* cf, void* data ) {
-	PythonShape*	self      = (PythonShape*) pythonShape;
-	char*           conditionFunction;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	conditionFunction = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Function", "0"  );
-
-	_PythonShape_Init( self, conditionFunction );
-}
-
-void _PythonShape_Build( void* pythonShape, void* data ) {
-	PythonShape*	self = (PythonShape*)pythonShape;
-
-	_Stg_Shape_Build( self, data );
-}
-void _PythonShape_Initialise( void* pythonShape, void* data ) {
-	PythonShape*	self = (PythonShape*)pythonShape;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _PythonShape_Execute( void* pythonShape, void* data ) {
-	PythonShape*	self = (PythonShape*)pythonShape;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _PythonShape_Destroy( void* pythonShape, void* data ) {
-	PythonShape*	self = (PythonShape*)pythonShape;
-
-   Memory_Free( self->testCondition );
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _PythonShape_IsCoordInside( void* pythonShape, Coord coord ) {
-	PythonShape*          self                   = (PythonShape*)pythonShape;
-	Coord                 newCoord;
-	PyObject*             xCoord;
-	PyObject*             yCoord;
-	PyObject*             zCoord;
-	PyObject*             testConditionValue;
-    PyObject*             pythonDictionary       = (PyObject*) self->pythonDictionary;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-	
-	/* Add values to dictionary */
-	xCoord = PyFloat_FromDouble( newCoord[ I_AXIS ] );
-	PyMapping_SetItemString( self->pythonDictionary, "x", xCoord );
-	yCoord = PyFloat_FromDouble( newCoord[ J_AXIS ] );
-	PyMapping_SetItemString( self->pythonDictionary, "y", yCoord );
-	zCoord = PyFloat_FromDouble( newCoord[ K_AXIS ] );
-	PyMapping_SetItemString( self->pythonDictionary, "z", zCoord );
-
-	/* Evaluate Test Condition Using Python */
-	PyRun_SimpleString(self->testCondition);
-
-	/* Get Value Out of Python */
-	testConditionValue = PyMapping_GetItemString(pythonDictionary, PYTHONSHAPE_TEST_CONDITION_NAME);
-	Journal_Firewall( 
-			testConditionValue != NULL, 
-			Journal_Register( Error_Type, (Name)self->type ), 
-			"In func %s: Cannot Evalutate Function '%s'.\n", __func__, self->testCondition );
-
-	return PyObject_IsTrue( testConditionValue );
-}
-
-double _PythonShape_CalculateVolume( void* pythonShape ) {
-	assert( 0 );
-	return 0.0;
-}
-void _PythonShape_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-
-#endif /* HAVE_PYTHON */
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/PythonShape.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/PythonShape.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,263 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: PythonShape.c 3869 2006-10-16 13:42:59Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifdef HAVE_PYTHON
+#include <Python.h>
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "PythonShape.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type PythonShape_Type = "PythonShape";
+
+char* PYTHONSHAPE_TEST_CONDITION_NAME = "testCondition";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+PythonShape* PythonShape_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		char*                                 conditionFunction )
+{
+	PythonShape* self = (PythonShape*) _PythonShape_DefaultNew( name );
+
+	PythonShape_InitAll( 
+		self, 
+		dim,
+		centre,
+		alpha,
+		beta,
+		gamma,
+		conditionFunction );
+	return self;
+}
+
+PythonShape* _PythonShape_New(  PYTHONSHAPE_DEFARGS  )
+{
+	PythonShape* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(PythonShape) );
+	self = (PythonShape*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	
+	return self;
+}
+
+void _PythonShape_Init( void* pythonShape, Name conditionFunction ) {
+	PythonShape* self = (PythonShape*)pythonShape;
+	
+	Stg_asprintf( &self->testCondition, "%s = %s", PYTHONSHAPE_TEST_CONDITION_NAME, conditionFunction );
+	
+	/* Python Stuff */
+	self->pythonDictionary = PyModule_GetDict(PyImport_AddModule("__main__"));
+	PyRun_SimpleString( "from math import *" );
+}
+
+
+void PythonShape_InitAll( 
+		void*                                 pythonShape, 
+		Dimension_Index                       dim, 
+		Coord                                 centre,
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		char*                                 conditionFunction )
+{
+	PythonShape* self = (PythonShape*)pythonShape;
+
+	Stg_Shape_InitAll( self, dim, centre, alpha, beta, gamma );
+	_PythonShape_Init( self, conditionFunction );
+}
+	
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _PythonShape_Delete( void* pythonShape ) {
+	PythonShape* self = (PythonShape*)pythonShape;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+
+}
+
+
+void _PythonShape_Print( void* pythonShape, Stream* stream ) {
+	PythonShape* self = (PythonShape*)pythonShape;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _PythonShape_Copy( const void* pythonShape, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	PythonShape*	self = (PythonShape*)pythonShape;
+	PythonShape*	newPythonShape;
+	
+	newPythonShape = (PythonShape*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+	abort();
+	
+	return (void*)newPythonShape;
+}
+
+void* _PythonShape_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(PythonShape);
+	Type                                                          type = PythonShape_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _PythonShape_Delete;
+	Stg_Class_PrintFunction*                                    _print = _PythonShape_Print;
+	Stg_Class_CopyFunction*                                      _copy = _PythonShape_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _PythonShape_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _PythonShape_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _PythonShape_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _PythonShape_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _PythonShape_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _PythonShape_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _PythonShape_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _PythonShape_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _PythonShape_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _PythonShape_New(  PYTHONSHAPE_PASSARGS  );
+}
+
+
+void _PythonShape_AssignFromXML( void* pythonShape, Stg_ComponentFactory* cf, void* data ) {
+	PythonShape*	self      = (PythonShape*) pythonShape;
+	char*           conditionFunction;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	conditionFunction = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Function", "0"  );
+
+	_PythonShape_Init( self, conditionFunction );
+}
+
+void _PythonShape_Build( void* pythonShape, void* data ) {
+	PythonShape*	self = (PythonShape*)pythonShape;
+
+	_Stg_Shape_Build( self, data );
+}
+void _PythonShape_Initialise( void* pythonShape, void* data ) {
+	PythonShape*	self = (PythonShape*)pythonShape;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _PythonShape_Execute( void* pythonShape, void* data ) {
+	PythonShape*	self = (PythonShape*)pythonShape;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _PythonShape_Destroy( void* pythonShape, void* data ) {
+	PythonShape*	self = (PythonShape*)pythonShape;
+
+   Memory_Free( self->testCondition );
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _PythonShape_IsCoordInside( void* pythonShape, Coord coord ) {
+	PythonShape*          self                   = (PythonShape*)pythonShape;
+	Coord                 newCoord;
+	PyObject*             xCoord;
+	PyObject*             yCoord;
+	PyObject*             zCoord;
+	PyObject*             testConditionValue;
+    PyObject*             pythonDictionary       = (PyObject*) self->pythonDictionary;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+	
+	/* Add values to dictionary */
+	xCoord = PyFloat_FromDouble( newCoord[ I_AXIS ] );
+	PyMapping_SetItemString( self->pythonDictionary, "x", xCoord );
+	yCoord = PyFloat_FromDouble( newCoord[ J_AXIS ] );
+	PyMapping_SetItemString( self->pythonDictionary, "y", yCoord );
+	zCoord = PyFloat_FromDouble( newCoord[ K_AXIS ] );
+	PyMapping_SetItemString( self->pythonDictionary, "z", zCoord );
+
+	/* Evaluate Test Condition Using Python */
+	PyRun_SimpleString(self->testCondition);
+
+	/* Get Value Out of Python */
+	testConditionValue = PyMapping_GetItemString(pythonDictionary, PYTHONSHAPE_TEST_CONDITION_NAME);
+	Journal_Firewall( 
+			testConditionValue != NULL, 
+			Journal_Register( Error_Type, (Name)self->type ), 
+			"In func %s: Cannot Evalutate Function '%s'.\n", __func__, self->testCondition );
+
+	return PyObject_IsTrue( testConditionValue );
+}
+
+double _PythonShape_CalculateVolume( void* pythonShape ) {
+	assert( 0 );
+	return 0.0;
+}
+void _PythonShape_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+
+#endif /* HAVE_PYTHON */
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/ShapeClass.c
--- a/Shape/src/ShapeClass.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,278 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ShapeClass.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type Stg_Shape_Type = "Stg_Shape";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Stg_Shape* _Stg_Shape_New(  STG_SHAPE_DEFARGS  )
-{
-	Stg_Shape* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Stg_Shape) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (Stg_Shape*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-		
-	/* General info */
-
-	/* Virtual Info */
-	self->_isCoordInside = _isCoordInside;
-	self->_calculateVolume = _calculateVolume;
-	self->_distanceFromCenterAxis = _distanceFromCenterAxis,
-
-	self->invert = False;
-	
-	return self;
-}
-	
-void _Stg_Shape_Init( void* shape, Dimension_Index dim, Coord centre, Bool invert, double alpha, double beta, double gamma ) {
-	Stg_Shape* self = (Stg_Shape*) shape;
-
-	self->isConstructed = True;
-
-	self->dim = dim;
-	memcpy( self->centre, centre, sizeof(Coord) );
-
-	self->invert = invert;
-
-	self->rotationMatrix[I_AXIS][0] = cos(alpha) * cos(beta) * cos(gamma) - sin(alpha) * sin(gamma);
-	self->rotationMatrix[I_AXIS][1] = sin(alpha) * cos(beta) * cos(gamma) + cos(alpha) * sin(gamma);
-	self->rotationMatrix[I_AXIS][2] = - sin(beta) * cos(gamma);
-
-	self->rotationMatrix[J_AXIS][0] = -cos(alpha) * cos(beta) * sin(gamma) - sin(alpha) * cos(gamma);
-	self->rotationMatrix[J_AXIS][1] = -sin(alpha) * cos(beta) * sin(gamma) + cos(alpha) * cos(gamma);
-	self->rotationMatrix[J_AXIS][2] = sin(beta) * sin(gamma);
-
-	self->rotationMatrix[K_AXIS][0] = cos(alpha) * sin(beta);
-	self->rotationMatrix[K_AXIS][1] = sin(alpha) * sin(beta);
-	self->rotationMatrix[K_AXIS][2] = cos(beta);
-}
-
-
-void Stg_Shape_InitAll( void* shape, Dimension_Index dim, Coord centre, double alpha, double beta, double gamma ) {
-	Stg_Shape* self = (Stg_Shape*) shape;
-	
-	_Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-}
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Stg_Shape_Delete( void* shape ) {
-	Stg_Shape* self = (Stg_Shape*) shape;
-	
-	/* Stg_Class_Delete parent */
-	_Stg_Component_Delete( self );
-}
-
-
-void _Stg_Shape_Print( void* superellipsoid, Stream* stream ) {
-	Stg_Shape* self = (Stg_Shape*)superellipsoid;
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-	
-	/* General info */
-	Journal_Printf( stream, "Stg_Shape (ptr): (%p)\n", self );
-
-	Journal_PrintPointer( stream, self->_isCoordInside );
-	
-
-}
-
-void* _Stg_Shape_Copy( const void* shape, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Stg_Shape*	self = (Stg_Shape*) shape;
-	Stg_Shape*	newStg_Shape;
-	
-	newStg_Shape = (Stg_Shape*)_Stg_Class_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newStg_Shape->_isCoordInside = self->_isCoordInside;
-	newStg_Shape->dim = self->dim;
-
-	memcpy( newStg_Shape->centre, self->centre, sizeof(XYZ));
-
-	return (void*)newStg_Shape;
-}
-
-void _Stg_Shape_AssignFromXML( void* shape, Stg_ComponentFactory* cf, void* data ) {
-	Stg_Shape*	    self      = (Stg_Shape*) shape;
-	Dimension_Index dim;
-	Coord           centre;
-	Bool            invert        = False;
-	double          alpha, beta, gamma;
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !self->context  )
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-	
-	centre[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentreX", 0.0  );
-	centre[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentreY", 0.0  );
-	centre[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentreZ", 0.0  );
-
-	invert = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"invert", False  );
-
-	alpha = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"alpha", 0.0  );
-	beta  = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"beta", 0.0  );
-	gamma = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"gamma", 0.0  );
-
-	_Stg_Shape_Init( self, dim, centre, invert, alpha, beta, gamma );
-}
-
-
-void StGermain_GetEulerAngles( 
-		XYZ     newYDirection,
-		XYZ     oldYDirection,
-		XYZ     newXDirection,
-		XYZ     oldXDirection, 
-		double* alpha,
-		double* beta,
-		double* gamma ) 
-{
-	/* TODO */
-	*alpha = 0.0;
-	*beta  = 0.0;
-	*gamma = 0.0;
-}
-
-void _Stg_Shape_Build( void* shape, void* data ) {
-}
-
-void _Stg_Shape_Initialise( void* shape, void* data ) {
-}
-
-void _Stg_Shape_Execute( void* shape, void* data ) {
-}
-
-void _Stg_Shape_Destroy( void* shape, void* data ) {
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual Functions
-*/
-Bool Stg_Shape_IsCoordInside( void* shape, Coord coord ) {
-	Stg_Shape* self              = (Stg_Shape*)shape;
-
-	/* XOR the output */
-	/* Truth table:
-	 * | invert | isCoordInside | output | 
-	 * | 0      | 0             | 0      | With invert off, leave the result as it is
-	 * | 0      | 1             | 1      |
-	 * | 1      | 0             | 1      | With invert on, flip the result
-	 * | 1      | 1             | 0      |
-	 *
-	 * bitwise xor is used because ^^ (logical) is not ansi-c
-	 */
-	return ((self->invert != 0) ^ (self->_isCoordInside( self, coord ) != 0))
-          ? True : False;
-}	
-
-double Stg_Shape_CalculateVolume( void* shape ) {
-	Stg_Shape* self = (Stg_Shape*)shape;
-	if ( self->invert ) {
-		return 1.0 - self->_calculateVolume( self );
-	}
-	else {
-		return self->_calculateVolume( self );
-	}
-}
-
-void Stg_Shape_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
-	Stg_Shape* self = (Stg_Shape*)shape;
-
-	self->_distanceFromCenterAxis( self, coord, disVec );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-void Stg_Shape_TransformCoord( void* shape, Coord coord, Coord transformedCoord ) {
-	Stg_Shape* self              = (Stg_Shape*)shape;
-	Coord      rotatedCoord;
-
-	Stg_Shape_TranslateCoord( self, coord, transformedCoord );
-
-	/* Rotate Using Rotation Matrix */
-	rotatedCoord[ I_AXIS ] = 
-		  self->rotationMatrix[I_AXIS][0] * transformedCoord[0] 
-		+ self->rotationMatrix[I_AXIS][1] * transformedCoord[1];
-	
-	rotatedCoord[ J_AXIS ] = 
-		  self->rotationMatrix[J_AXIS][0] * transformedCoord[0] 
-		+ self->rotationMatrix[J_AXIS][1] * transformedCoord[1];
-	
-	rotatedCoord[ K_AXIS ] = 
-		  self->rotationMatrix[K_AXIS][0] * transformedCoord[0] 
-		+ self->rotationMatrix[K_AXIS][1] * transformedCoord[1];
-
-	if ( self->dim > 2 ) {
-		rotatedCoord[ I_AXIS ] += self->rotationMatrix[I_AXIS][2] * transformedCoord[2];
-		rotatedCoord[ J_AXIS ] += self->rotationMatrix[J_AXIS][2] * transformedCoord[2];
-		rotatedCoord[ K_AXIS ] += self->rotationMatrix[K_AXIS][2] * transformedCoord[2];
-	}
-
-	memcpy( transformedCoord, rotatedCoord, sizeof(Coord));
-
-}
-
-void Stg_Shape_TranslateCoord( void* shape, Coord coord, Coord translatedCoord ) {
-	Stg_Shape* self              = (Stg_Shape*)shape;
-
-   self->dim == 2 ? 
-     Vec_Sub2D( translatedCoord, coord, self->centre ) :
-     Vec_Sub3D( translatedCoord, coord, self->centre ) ;
-}
-
-
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/ShapeClass.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/ShapeClass.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,278 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ShapeClass.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type Stg_Shape_Type = "Stg_Shape";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Stg_Shape* _Stg_Shape_New(  STG_SHAPE_DEFARGS  )
+{
+	Stg_Shape* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Stg_Shape) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (Stg_Shape*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+		
+	/* General info */
+
+	/* Virtual Info */
+	self->_isCoordInside = _isCoordInside;
+	self->_calculateVolume = _calculateVolume;
+	self->_distanceFromCenterAxis = _distanceFromCenterAxis,
+
+	self->invert = False;
+	
+	return self;
+}
+	
+void _Stg_Shape_Init( void* shape, Dimension_Index dim, Coord centre, Bool invert, double alpha, double beta, double gamma ) {
+	Stg_Shape* self = (Stg_Shape*) shape;
+
+	self->isConstructed = True;
+
+	self->dim = dim;
+	memcpy( self->centre, centre, sizeof(Coord) );
+
+	self->invert = invert;
+
+	self->rotationMatrix[I_AXIS][0] = cos(alpha) * cos(beta) * cos(gamma) - sin(alpha) * sin(gamma);
+	self->rotationMatrix[I_AXIS][1] = sin(alpha) * cos(beta) * cos(gamma) + cos(alpha) * sin(gamma);
+	self->rotationMatrix[I_AXIS][2] = - sin(beta) * cos(gamma);
+
+	self->rotationMatrix[J_AXIS][0] = -cos(alpha) * cos(beta) * sin(gamma) - sin(alpha) * cos(gamma);
+	self->rotationMatrix[J_AXIS][1] = -sin(alpha) * cos(beta) * sin(gamma) + cos(alpha) * cos(gamma);
+	self->rotationMatrix[J_AXIS][2] = sin(beta) * sin(gamma);
+
+	self->rotationMatrix[K_AXIS][0] = cos(alpha) * sin(beta);
+	self->rotationMatrix[K_AXIS][1] = sin(alpha) * sin(beta);
+	self->rotationMatrix[K_AXIS][2] = cos(beta);
+}
+
+
+void Stg_Shape_InitAll( void* shape, Dimension_Index dim, Coord centre, double alpha, double beta, double gamma ) {
+	Stg_Shape* self = (Stg_Shape*) shape;
+	
+	_Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+}
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Stg_Shape_Delete( void* shape ) {
+	Stg_Shape* self = (Stg_Shape*) shape;
+	
+	/* Stg_Class_Delete parent */
+	_Stg_Component_Delete( self );
+}
+
+
+void _Stg_Shape_Print( void* superellipsoid, Stream* stream ) {
+	Stg_Shape* self = (Stg_Shape*)superellipsoid;
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+	
+	/* General info */
+	Journal_Printf( stream, "Stg_Shape (ptr): (%p)\n", self );
+
+	Journal_PrintPointer( stream, self->_isCoordInside );
+	
+
+}
+
+void* _Stg_Shape_Copy( const void* shape, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Stg_Shape*	self = (Stg_Shape*) shape;
+	Stg_Shape*	newStg_Shape;
+	
+	newStg_Shape = (Stg_Shape*)_Stg_Class_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newStg_Shape->_isCoordInside = self->_isCoordInside;
+	newStg_Shape->dim = self->dim;
+
+	memcpy( newStg_Shape->centre, self->centre, sizeof(XYZ));
+
+	return (void*)newStg_Shape;
+}
+
+void _Stg_Shape_AssignFromXML( void* shape, Stg_ComponentFactory* cf, void* data ) {
+	Stg_Shape*	    self      = (Stg_Shape*) shape;
+	Dimension_Index dim;
+	Coord           centre;
+	Bool            invert        = False;
+	double          alpha, beta, gamma;
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !self->context  )
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+	
+	centre[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentreX", 0.0  );
+	centre[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentreY", 0.0  );
+	centre[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentreZ", 0.0  );
+
+	invert = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"invert", False  );
+
+	alpha = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"alpha", 0.0  );
+	beta  = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"beta", 0.0  );
+	gamma = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"gamma", 0.0  );
+
+	_Stg_Shape_Init( self, dim, centre, invert, alpha, beta, gamma );
+}
+
+
+void StGermain_GetEulerAngles( 
+		XYZ     newYDirection,
+		XYZ     oldYDirection,
+		XYZ     newXDirection,
+		XYZ     oldXDirection, 
+		double* alpha,
+		double* beta,
+		double* gamma ) 
+{
+	/* TODO */
+	*alpha = 0.0;
+	*beta  = 0.0;
+	*gamma = 0.0;
+}
+
+void _Stg_Shape_Build( void* shape, void* data ) {
+}
+
+void _Stg_Shape_Initialise( void* shape, void* data ) {
+}
+
+void _Stg_Shape_Execute( void* shape, void* data ) {
+}
+
+void _Stg_Shape_Destroy( void* shape, void* data ) {
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual Functions
+*/
+Bool Stg_Shape_IsCoordInside( void* shape, Coord coord ) {
+	Stg_Shape* self              = (Stg_Shape*)shape;
+
+	/* XOR the output */
+	/* Truth table:
+	 * | invert | isCoordInside | output | 
+	 * | 0      | 0             | 0      | With invert off, leave the result as it is
+	 * | 0      | 1             | 1      |
+	 * | 1      | 0             | 1      | With invert on, flip the result
+	 * | 1      | 1             | 0      |
+	 *
+	 * bitwise xor is used because ^^ (logical) is not ansi-c
+	 */
+	return ((self->invert != 0) ^ (self->_isCoordInside( self, coord ) != 0))
+          ? True : False;
+}	
+
+double Stg_Shape_CalculateVolume( void* shape ) {
+	Stg_Shape* self = (Stg_Shape*)shape;
+	if ( self->invert ) {
+		return 1.0 - self->_calculateVolume( self );
+	}
+	else {
+		return self->_calculateVolume( self );
+	}
+}
+
+void Stg_Shape_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
+	Stg_Shape* self = (Stg_Shape*)shape;
+
+	self->_distanceFromCenterAxis( self, coord, disVec );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+void Stg_Shape_TransformCoord( void* shape, Coord coord, Coord transformedCoord ) {
+	Stg_Shape* self              = (Stg_Shape*)shape;
+	Coord      rotatedCoord;
+
+	Stg_Shape_TranslateCoord( self, coord, transformedCoord );
+
+	/* Rotate Using Rotation Matrix */
+	rotatedCoord[ I_AXIS ] = 
+		  self->rotationMatrix[I_AXIS][0] * transformedCoord[0] 
+		+ self->rotationMatrix[I_AXIS][1] * transformedCoord[1];
+	
+	rotatedCoord[ J_AXIS ] = 
+		  self->rotationMatrix[J_AXIS][0] * transformedCoord[0] 
+		+ self->rotationMatrix[J_AXIS][1] * transformedCoord[1];
+	
+	rotatedCoord[ K_AXIS ] = 
+		  self->rotationMatrix[K_AXIS][0] * transformedCoord[0] 
+		+ self->rotationMatrix[K_AXIS][1] * transformedCoord[1];
+
+	if ( self->dim > 2 ) {
+		rotatedCoord[ I_AXIS ] += self->rotationMatrix[I_AXIS][2] * transformedCoord[2];
+		rotatedCoord[ J_AXIS ] += self->rotationMatrix[J_AXIS][2] * transformedCoord[2];
+		rotatedCoord[ K_AXIS ] += self->rotationMatrix[K_AXIS][2] * transformedCoord[2];
+	}
+
+	memcpy( transformedCoord, rotatedCoord, sizeof(Coord));
+
+}
+
+void Stg_Shape_TranslateCoord( void* shape, Coord coord, Coord translatedCoord ) {
+	Stg_Shape* self              = (Stg_Shape*)shape;
+
+   self->dim == 2 ? 
+     Vec_Sub2D( translatedCoord, coord, self->centre ) :
+     Vec_Sub3D( translatedCoord, coord, self->centre ) ;
+}
+
+
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Sphere.c
--- a/Shape/src/Sphere.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,236 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Sphere.c 3869 2006-10-16 13:42:59Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Sphere.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type Sphere_Type = "Sphere";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Sphere* Sphere_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		double                                radius )
-{
-	Sphere* self = (Sphere*) _Sphere_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-	_Sphere_Init( self, radius );
-
-	return self;
-}
-
-Sphere* _Sphere_New(  SPHERE_DEFARGS  )
-{
-	Sphere* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Sphere) );
-	self = (Sphere*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	self->_isCoordInside = _isCoordInside;
-	self->_calculateVolume = _calculateVolume;
-	self->_distanceFromCenterAxis = _distanceFromCenterAxis;
-	
-	return self;
-}
-
-void _Sphere_Init( void* sphere, double radius ) {
-	Sphere* self = (Sphere*)sphere;
-	self->radius        = radius;
-	self->radiusSquared = radius * radius;
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Sphere_Delete( void* sphere ) {
-	Sphere* self = (Sphere*)sphere;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _Sphere_Print( void* sphere, Stream* stream ) {
-	Sphere* self = (Sphere*)sphere;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-
-
-void* _Sphere_Copy( const void* sphere, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Sphere*	self = (Sphere*)sphere;
-	Sphere*	newSphere;
-	
-	newSphere = (Sphere*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newSphere->radiusSquared = self->radiusSquared;
-	
-	return (void*)newSphere;
-}
-
-void* _Sphere_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Sphere);
-	Type                                                          type = Sphere_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Sphere_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Sphere_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Sphere_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Sphere_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Sphere_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Sphere_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Sphere_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Sphere_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Sphere_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Sphere_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Sphere_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Sphere_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Sphere_New(  SPHERE_PASSARGS  );
-}
-
-
-void _Sphere_AssignFromXML( void* sphere, Stg_ComponentFactory* cf, void* data ) {
-	Sphere*	self      = (Sphere*) sphere;
-	double             radius;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	radius = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radius", 0.0  );
-
-	_Sphere_Init( self, radius );
-}
-
-void _Sphere_Build( void* sphere, void* data ) {
-	Sphere*	self = (Sphere*)sphere;
-
-	_Stg_Shape_Build( self, data );
-}
-void _Sphere_Initialise( void* sphere, void* data ) {
-	Sphere*	self = (Sphere*)sphere;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _Sphere_Execute( void* sphere, void* data ) {
-	Sphere*	self = (Sphere*)sphere;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _Sphere_Destroy( void* sphere, void* data ) {
-	Sphere*	self = (Sphere*)sphere;
-	
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _Sphere_IsCoordInside( void* sphere, Coord coord ) {
-	Sphere*         self              = (Sphere*)sphere;
-	Coord           newCoord;
-	double          insideOutsideValue;
-	double          x, y, z;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-
-	x = newCoord[ I_AXIS ];
-	y = newCoord[ J_AXIS ];
-	if(self->dim == 2)
-		insideOutsideValue = x*x + y*y;
-	else {
-		z = newCoord[ K_AXIS ];
-		insideOutsideValue = x*x + y*y + z*z;
-	}
-
-	return (insideOutsideValue <= self->radiusSquared) ? True : False;
-	
-}
-
-void _Sphere_DistanceFromCenterAxis( void* sphere, Coord coord, double* disVec ) {
-	Sphere*         self              = (Sphere*)sphere;
-	Coord           newCoord;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-
-	disVec[0] = newCoord[ I_AXIS ];
-	disVec[1] = newCoord[ J_AXIS ];
-	if( self->dim == 3 )
-		disVec[2] = newCoord[ K_AXIS ];
-}
-	
-
-double _Sphere_CalculateVolume( void* sphere ) {
-  Sphere* self = (Sphere*)sphere;
-	if ( self->dim == 2 ) {
-		return M_PI * self->radiusSquared;
-	}
-	else {
-		return (4.0/3.0) * M_PI * self->radiusSquared * self->radius;
-	}
-}
-	
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Sphere.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Sphere.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,236 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Sphere.c 3869 2006-10-16 13:42:59Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Sphere.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type Sphere_Type = "Sphere";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Sphere* Sphere_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		double                                radius )
+{
+	Sphere* self = (Sphere*) _Sphere_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+	_Sphere_Init( self, radius );
+
+	return self;
+}
+
+Sphere* _Sphere_New(  SPHERE_DEFARGS  )
+{
+	Sphere* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Sphere) );
+	self = (Sphere*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	self->_isCoordInside = _isCoordInside;
+	self->_calculateVolume = _calculateVolume;
+	self->_distanceFromCenterAxis = _distanceFromCenterAxis;
+	
+	return self;
+}
+
+void _Sphere_Init( void* sphere, double radius ) {
+	Sphere* self = (Sphere*)sphere;
+	self->radius        = radius;
+	self->radiusSquared = radius * radius;
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Sphere_Delete( void* sphere ) {
+	Sphere* self = (Sphere*)sphere;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _Sphere_Print( void* sphere, Stream* stream ) {
+	Sphere* self = (Sphere*)sphere;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _Sphere_Copy( const void* sphere, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Sphere*	self = (Sphere*)sphere;
+	Sphere*	newSphere;
+	
+	newSphere = (Sphere*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newSphere->radiusSquared = self->radiusSquared;
+	
+	return (void*)newSphere;
+}
+
+void* _Sphere_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Sphere);
+	Type                                                          type = Sphere_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Sphere_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Sphere_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Sphere_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Sphere_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Sphere_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Sphere_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Sphere_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Sphere_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Sphere_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Sphere_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Sphere_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Sphere_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Sphere_New(  SPHERE_PASSARGS  );
+}
+
+
+void _Sphere_AssignFromXML( void* sphere, Stg_ComponentFactory* cf, void* data ) {
+	Sphere*	self      = (Sphere*) sphere;
+	double             radius;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	radius = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radius", 0.0  );
+
+	_Sphere_Init( self, radius );
+}
+
+void _Sphere_Build( void* sphere, void* data ) {
+	Sphere*	self = (Sphere*)sphere;
+
+	_Stg_Shape_Build( self, data );
+}
+void _Sphere_Initialise( void* sphere, void* data ) {
+	Sphere*	self = (Sphere*)sphere;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _Sphere_Execute( void* sphere, void* data ) {
+	Sphere*	self = (Sphere*)sphere;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _Sphere_Destroy( void* sphere, void* data ) {
+	Sphere*	self = (Sphere*)sphere;
+	
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _Sphere_IsCoordInside( void* sphere, Coord coord ) {
+	Sphere*         self              = (Sphere*)sphere;
+	Coord           newCoord;
+	double          insideOutsideValue;
+	double          x, y, z;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+
+	x = newCoord[ I_AXIS ];
+	y = newCoord[ J_AXIS ];
+	if(self->dim == 2)
+		insideOutsideValue = x*x + y*y;
+	else {
+		z = newCoord[ K_AXIS ];
+		insideOutsideValue = x*x + y*y + z*z;
+	}
+
+	return (insideOutsideValue <= self->radiusSquared) ? True : False;
+	
+}
+
+void _Sphere_DistanceFromCenterAxis( void* sphere, Coord coord, double* disVec ) {
+	Sphere*         self              = (Sphere*)sphere;
+	Coord           newCoord;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+
+	disVec[0] = newCoord[ I_AXIS ];
+	disVec[1] = newCoord[ J_AXIS ];
+	if( self->dim == 3 )
+		disVec[2] = newCoord[ K_AXIS ];
+}
+	
+
+double _Sphere_CalculateVolume( void* sphere ) {
+  Sphere* self = (Sphere*)sphere;
+	if ( self->dim == 2 ) {
+		return M_PI * self->radiusSquared;
+	}
+	else {
+		return (4.0/3.0) * M_PI * self->radiusSquared * self->radius;
+	}
+}
+	
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Superellipsoid.c
--- a/Shape/src/Superellipsoid.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,238 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Superellipsoid.c 3869 2006-10-16 13:42:59Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Superellipsoid.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type Superellipsoid_Type = "Superellipsoid";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Superellipsoid* Superellipsoid_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		double                                epsilon1,
-		double                                epsilon2,   
-		XYZ                                   radius )
-{
-	Superellipsoid* self = (Superellipsoid*) _Superellipsoid_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
-   _Superellipsoid_Init( self, epsilon1, epsilon2, radius );
-
-	return self;
-}
-
-Superellipsoid* _Superellipsoid_New(  SUPERELLIPSOID_DEFARGS  )
-{
-	Superellipsoid* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Superellipsoid) );
-	self = (Superellipsoid*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-
-	return self;
-}
-
-void _Superellipsoid_Init( void* superellipsoid, double epsilon1, double epsilon2, XYZ radius ) {
-	Superellipsoid* self = (Superellipsoid*)superellipsoid;
-	
-	self->epsilon1 = epsilon1;
-	self->epsilon2 = epsilon2;
-
-	memcpy( self->radius, radius, sizeof(XYZ));
-}
-
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Superellipsoid_Delete( void* superellipsoid ) {
-	Superellipsoid* self = (Superellipsoid*)superellipsoid;
-	
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _Superellipsoid_Print( void* superellipsoid, Stream* stream ) {
-	Superellipsoid* self = (Superellipsoid*)superellipsoid;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-
-
-void* _Superellipsoid_Copy( const void* superellipsoid, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
-	Superellipsoid*	newSuperellipsoid;
-	
-	newSuperellipsoid = (Superellipsoid*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newSuperellipsoid->epsilon1 = self->epsilon1;
-	newSuperellipsoid->epsilon2 = self->epsilon2;
-	
-	memcpy( newSuperellipsoid->radius, self->radius, sizeof(XYZ));
-	
-	return (void*)newSuperellipsoid;
-}
-
-void* _Superellipsoid_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Superellipsoid);
-	Type                                                          type = Superellipsoid_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Superellipsoid_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Superellipsoid_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Superellipsoid_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Superellipsoid_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Superellipsoid_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Superellipsoid_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Superellipsoid_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Superellipsoid_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Superellipsoid_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Superellipsoid_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Superellipsoid_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Superellipsoid_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Superellipsoid_New(  SUPERELLIPSOID_PASSARGS  );
-}
-
-
-void _Superellipsoid_AssignFromXML( void* superellipsoid, Stg_ComponentFactory* cf, void* data ) {
-	Superellipsoid*	self      = (Superellipsoid*) superellipsoid;
-	XYZ             radius;
-	double          epsilon1;
-	double          epsilon2;
-
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	radius[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radiusX", 1.0  );
-	radius[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radiusY", 1.0  );
-	radius[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radiusZ", 1.0  );
-
-	epsilon1 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"epsilon1", 1.0  );
-	epsilon2 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"epsilon2", 1.0  );
-
-	_Superellipsoid_Init( self, epsilon1, epsilon2, radius );
-}
-
-void _Superellipsoid_Build( void* superellipsoid, void* data ) {
-	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
-
-	_Stg_Shape_Build( self, data );
-}
-void _Superellipsoid_Initialise( void* superellipsoid, void* data ) {
-	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
-	
-	_Stg_Shape_Initialise( self, data );
-}
-void _Superellipsoid_Execute( void* superellipsoid, void* data ) {
-	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _Superellipsoid_Destroy( void* superellipsoid, void* data ) {
-	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
-	
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-
-Bool _Superellipsoid_IsCoordInside( void* superellipsoid, Coord coord ) {
-	Superellipsoid* self              = (Superellipsoid*)superellipsoid;
-	Coord           newCoord;
-	double          insideOutsideValue;
-	double          epsilon1          = self->epsilon1;
-	double          epsilon2          = self->epsilon2;
-	double          x, y, z;
-
-	/* Transform coordinate into canonical reference frame */
-	Stg_Shape_TransformCoord( self, coord, newCoord );
-	
-	x = newCoord[ I_AXIS ]/self->radius[ I_AXIS ];
-	y = newCoord[ J_AXIS ]/self->radius[ J_AXIS ];
-	z = newCoord[ K_AXIS ]/self->radius[ K_AXIS ];
-
-	/* Evaluate Inside-Outside Function */
-	if (self->dim == 2)
-		insideOutsideValue = pow( x*x, 1.0/epsilon1 ) + pow( y*y, 1.0/epsilon1 );
-	else 
-		insideOutsideValue = pow( pow( x*x, 1.0/epsilon2 ) + pow( y*y, 1.0/epsilon2 ) , epsilon2/epsilon1 )
-			+ pow( z*z, 1.0/epsilon1 );
-
-	/* Return True if coord is inside and False otherwise */
-	return ( insideOutsideValue <= 1.0 ) ? True : False;
-}
-
-double _Superellipsoid_CalculateVolume( void* superellipsoid ) {
-	assert( 0  );
-	return 0.0;
-}
-
-void _Superellipsoid_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}	
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Superellipsoid.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Superellipsoid.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,238 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Superellipsoid.c 3869 2006-10-16 13:42:59Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Superellipsoid.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type Superellipsoid_Type = "Superellipsoid";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Superellipsoid* Superellipsoid_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		double                                epsilon1,
+		double                                epsilon2,   
+		XYZ                                   radius )
+{
+	Superellipsoid* self = (Superellipsoid*) _Superellipsoid_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma );
+   _Superellipsoid_Init( self, epsilon1, epsilon2, radius );
+
+	return self;
+}
+
+Superellipsoid* _Superellipsoid_New(  SUPERELLIPSOID_DEFARGS  )
+{
+	Superellipsoid* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Superellipsoid) );
+	self = (Superellipsoid*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+
+	return self;
+}
+
+void _Superellipsoid_Init( void* superellipsoid, double epsilon1, double epsilon2, XYZ radius ) {
+	Superellipsoid* self = (Superellipsoid*)superellipsoid;
+	
+	self->epsilon1 = epsilon1;
+	self->epsilon2 = epsilon2;
+
+	memcpy( self->radius, radius, sizeof(XYZ));
+}
+
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Superellipsoid_Delete( void* superellipsoid ) {
+	Superellipsoid* self = (Superellipsoid*)superellipsoid;
+	
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _Superellipsoid_Print( void* superellipsoid, Stream* stream ) {
+	Superellipsoid* self = (Superellipsoid*)superellipsoid;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+
+
+void* _Superellipsoid_Copy( const void* superellipsoid, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
+	Superellipsoid*	newSuperellipsoid;
+	
+	newSuperellipsoid = (Superellipsoid*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newSuperellipsoid->epsilon1 = self->epsilon1;
+	newSuperellipsoid->epsilon2 = self->epsilon2;
+	
+	memcpy( newSuperellipsoid->radius, self->radius, sizeof(XYZ));
+	
+	return (void*)newSuperellipsoid;
+}
+
+void* _Superellipsoid_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Superellipsoid);
+	Type                                                          type = Superellipsoid_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Superellipsoid_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Superellipsoid_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Superellipsoid_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Superellipsoid_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Superellipsoid_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Superellipsoid_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Superellipsoid_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Superellipsoid_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Superellipsoid_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Superellipsoid_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Superellipsoid_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Superellipsoid_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Superellipsoid_New(  SUPERELLIPSOID_PASSARGS  );
+}
+
+
+void _Superellipsoid_AssignFromXML( void* superellipsoid, Stg_ComponentFactory* cf, void* data ) {
+	Superellipsoid*	self      = (Superellipsoid*) superellipsoid;
+	XYZ             radius;
+	double          epsilon1;
+	double          epsilon2;
+
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	radius[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radiusX", 1.0  );
+	radius[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radiusY", 1.0  );
+	radius[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"radiusZ", 1.0  );
+
+	epsilon1 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"epsilon1", 1.0  );
+	epsilon2 = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"epsilon2", 1.0  );
+
+	_Superellipsoid_Init( self, epsilon1, epsilon2, radius );
+}
+
+void _Superellipsoid_Build( void* superellipsoid, void* data ) {
+	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
+
+	_Stg_Shape_Build( self, data );
+}
+void _Superellipsoid_Initialise( void* superellipsoid, void* data ) {
+	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
+	
+	_Stg_Shape_Initialise( self, data );
+}
+void _Superellipsoid_Execute( void* superellipsoid, void* data ) {
+	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _Superellipsoid_Destroy( void* superellipsoid, void* data ) {
+	Superellipsoid*	self = (Superellipsoid*)superellipsoid;
+	
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+
+Bool _Superellipsoid_IsCoordInside( void* superellipsoid, Coord coord ) {
+	Superellipsoid* self              = (Superellipsoid*)superellipsoid;
+	Coord           newCoord;
+	double          insideOutsideValue;
+	double          epsilon1          = self->epsilon1;
+	double          epsilon2          = self->epsilon2;
+	double          x, y, z;
+
+	/* Transform coordinate into canonical reference frame */
+	Stg_Shape_TransformCoord( self, coord, newCoord );
+	
+	x = newCoord[ I_AXIS ]/self->radius[ I_AXIS ];
+	y = newCoord[ J_AXIS ]/self->radius[ J_AXIS ];
+	z = newCoord[ K_AXIS ]/self->radius[ K_AXIS ];
+
+	/* Evaluate Inside-Outside Function */
+	if (self->dim == 2)
+		insideOutsideValue = pow( x*x, 1.0/epsilon1 ) + pow( y*y, 1.0/epsilon1 );
+	else 
+		insideOutsideValue = pow( pow( x*x, 1.0/epsilon2 ) + pow( y*y, 1.0/epsilon2 ) , epsilon2/epsilon1 )
+			+ pow( z*z, 1.0/epsilon1 );
+
+	/* Return True if coord is inside and False otherwise */
+	return ( insideOutsideValue <= 1.0 ) ? True : False;
+}
+
+double _Superellipsoid_CalculateVolume( void* superellipsoid ) {
+	assert( 0  );
+	return 0.0;
+}
+
+void _Superellipsoid_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ){
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}	
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Union.c
--- a/Shape/src/Union.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,280 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Union.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-
-#include "types.h"
-#include "ShapeClass.h"
-#include "Union.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type Union_Type = "Union";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-Union* Union_New(
-		Name                                  name,
-		Dimension_Index                       dim,
-		XYZ                                   centre, 
-		double                                alpha,
-		double                                beta,
-		double                                gamma,
-		Stg_Shape**                           shapeList,
-		Index                                 shapeCount,
-		Bool*                                 isComplement
-		)
-{
-	Union* self = (Union*)_Union_DefaultNew( name );
-
-   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
-	_Union_Init( self, shapeList, shapeCount, isComplement );
-	return self;
-}
-
-Union* _Union_New(  UNION_DEFARGS  )
-{
-	Union* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(Union) );
-	self = (Union*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-	
-	/* General info */
-	
-	return self;
-}
-
-void _Union_Init( void* combination,  Stg_Shape** shapeList, Index shapeCount, Bool* isComplement ) {
-	Union* self = (Union*)combination;
-	
-	self->shapeList    = Memory_Alloc_Array( Stg_Shape* , shapeCount , "shapeList" );
-	self->isComplement = Memory_Alloc_Array( Bool,        shapeCount , "isComplement" );
-
-	memcpy( self->shapeList , shapeList, sizeof(Stg_Shape*) * shapeCount );
-	memcpy( self->isComplement , isComplement, sizeof(Bool) * shapeCount );
-	self->shapeCount = shapeCount;
-}
-
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Union_Delete( void* combination ) {
-	Union*       self = (Union*)combination;
-
-	Memory_Free( self->shapeList );
-	/* Delete parent */
-	_Stg_Shape_Delete( self );
-}
-
-
-void _Union_Print( void* combination, Stream* stream ) {
-	Union* self = (Union*)combination;
-	
-	/* Print parent */
-	_Stg_Shape_Print( self, stream );
-}
-
-void* _Union_Copy( const void* combination, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Union*	self = (Union*)combination;
-	Union*	newUnion;
-	
-	newUnion = (Union*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newUnion->shapeList = Memory_Alloc_Array( Stg_Shape*, self->shapeCount, "shapeList" );
-	memcpy( newUnion->shapeList , self->shapeList, sizeof(Stg_Shape*) * self->shapeCount );
-	
-	newUnion->isComplement = Memory_Alloc_Array( Bool , self->shapeCount, "isComplement" );
-	memcpy( newUnion->isComplement , self->isComplement, sizeof(Bool) * self->shapeCount );
-
-	newUnion->isComplement = self->isComplement;
-	newUnion->shapeList = self->shapeList;
-	newUnion->shapeCount = self->shapeCount;
-	
-	return (void*)newUnion;
-}
-
-void* _Union_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(Union);
-	Type                                                          type = Union_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _Union_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Union_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Union_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Union_DefaultNew;
-	Stg_Component_ConstructFunction*                        _construct = _Union_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _Union_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _Union_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Union_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Union_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Union_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Union_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Union_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _Union_New(  UNION_PASSARGS  );
-}
-
-
-void _Union_AssignFromXML( void* combination, Stg_ComponentFactory* cf, void* data ) {
-	Union*                  self       = (Union*)combination;
-	Index                   shapeCount;
-	Stg_Shape**             shapeList;
-	Bool*                   isComplement;
-	Index                   shape_I;
-	Dictionary_Entry_Value* optionsList;
-	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	char*                   nameShape;
-	Stream*                 stream     = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
-	
-	_Stg_Shape_AssignFromXML( self, cf, data );
-
-	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"shapes" );
-
-	shapeCount = Dictionary_Entry_Value_GetCount(optionsList );
-
-	/* Allocate space */
-	shapeList     = Memory_Alloc_Array( Stg_Shape* , shapeCount, "Shape Array" );
-	isComplement  = Memory_Alloc_Array( Bool, shapeCount, "Complement Array" );
-	memset( shapeList,     0, shapeCount * sizeof(Stg_Shape*) );
-	memset( isComplement,  0, shapeCount * sizeof(Bool) );
-	
-	Stream_Indent( stream );
-	for ( shape_I = 0 ; shape_I < shapeCount ; shape_I++) { 
-          /* gets the textual name corresponding to the shape elements	 */
-		nameShape = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( optionsList, shape_I));
-
-		if ( nameShape[0] == '!' ) {
-			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)&nameShape[1], Stg_Shape, True, data  ) ;
-			isComplement[ shape_I ] = True;
-		}
-		else {
-			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)nameShape, Stg_Shape, True, data ) ;
-			isComplement[ shape_I ] = False;
-		}
-		
-	}
-	Stream_UnIndent( stream  );
-
-	_Union_Init( self, shapeList, shapeCount, isComplement );
-
-	Memory_Free( shapeList );
-	Memory_Free( isComplement );
-}
-
-void _Union_Build( void* combination, void* data ) {
-	Union*	self = (Union*)combination;
-   unsigned shape_I = 0;
-    
-   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
-      Stg_Component_Build( self->shapeList[shape_I], data, False );
-   }
-
-	_Stg_Shape_Build( self, data );
-}
-void _Union_Initialise( void* combination, void* data ) {
-	Union*	self = (Union*)combination;
-	unsigned shape_I = 0;
-    
-   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
-      Stg_Component_Initialise( self->shapeList[shape_I], data, False );
-   }
-	_Stg_Shape_Initialise( self, data );
-}
-void _Union_Execute( void* combination, void* data ) {
-	Union*	self = (Union*)combination;
-	
-	_Stg_Shape_Execute( self, data );
-}
-void _Union_Destroy( void* combination, void* data ) {
-	Union*	self = (Union*)combination;
-	unsigned shape_I = 0;
-    
-   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
-      Stg_Component_Destroy( self->shapeList[shape_I], data, False );
-   }
-	Memory_Free( self->isComplement );
-
-	_Stg_Shape_Destroy( self, data );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-	
-/*---------------------------------------------------------------------------------------------------------------------
-** Private Member functions
-*/
-Bool _Union_IsCoordInside( void* combination, Coord coord ) {
-	Union*    self           = (Union*)combination;
-	Index           shapeCount     = self->shapeCount;
-	Index           shape_I;
-	Bool            value;
-
-	for( shape_I = 0 ; shape_I < shapeCount ; shape_I++ ) {
-		value = Stg_Shape_IsCoordInside( self->shapeList[ shape_I ], coord );
-
-		
-		if ( self->isComplement[ shape_I ] )
-                  value = (!value) ? True : False;
-			
-		if ( value )
-			return True;
-	}
-	return False;
-}	
-
-
-double _Union_CalculateVolume( void* combination ) {
-	assert ( 0 );
-	return 0.0;
-}
-
-void _Union_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
-	Stg_Shape* self = (Stg_Shape*)shape;
-	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-	"Error in function %s: This functions hasn't been implemented.", 
-	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
-}
-	
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/src/Union.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/src/Union.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,280 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) 
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Union.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+
+#include "types.h"
+#include "ShapeClass.h"
+#include "Union.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type Union_Type = "Union";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Union* Union_New(
+		Name                                  name,
+		Dimension_Index                       dim,
+		XYZ                                   centre, 
+		double                                alpha,
+		double                                beta,
+		double                                gamma,
+		Stg_Shape**                           shapeList,
+		Index                                 shapeCount,
+		Bool*                                 isComplement
+		)
+{
+	Union* self = (Union*)_Union_DefaultNew( name );
+
+   _Stg_Shape_Init( self, dim, centre, False, alpha, beta, gamma);
+	_Union_Init( self, shapeList, shapeCount, isComplement );
+	return self;
+}
+
+Union* _Union_New(  UNION_DEFARGS  )
+{
+	Union* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(Union) );
+	self = (Union*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+	
+	/* General info */
+	
+	return self;
+}
+
+void _Union_Init( void* combination,  Stg_Shape** shapeList, Index shapeCount, Bool* isComplement ) {
+	Union* self = (Union*)combination;
+	
+	self->shapeList    = Memory_Alloc_Array( Stg_Shape* , shapeCount , "shapeList" );
+	self->isComplement = Memory_Alloc_Array( Bool,        shapeCount , "isComplement" );
+
+	memcpy( self->shapeList , shapeList, sizeof(Stg_Shape*) * shapeCount );
+	memcpy( self->isComplement , isComplement, sizeof(Bool) * shapeCount );
+	self->shapeCount = shapeCount;
+}
+
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Union_Delete( void* combination ) {
+	Union*       self = (Union*)combination;
+
+	Memory_Free( self->shapeList );
+	/* Delete parent */
+	_Stg_Shape_Delete( self );
+}
+
+
+void _Union_Print( void* combination, Stream* stream ) {
+	Union* self = (Union*)combination;
+	
+	/* Print parent */
+	_Stg_Shape_Print( self, stream );
+}
+
+void* _Union_Copy( const void* combination, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Union*	self = (Union*)combination;
+	Union*	newUnion;
+	
+	newUnion = (Union*)_Stg_Shape_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newUnion->shapeList = Memory_Alloc_Array( Stg_Shape*, self->shapeCount, "shapeList" );
+	memcpy( newUnion->shapeList , self->shapeList, sizeof(Stg_Shape*) * self->shapeCount );
+	
+	newUnion->isComplement = Memory_Alloc_Array( Bool , self->shapeCount, "isComplement" );
+	memcpy( newUnion->isComplement , self->isComplement, sizeof(Bool) * self->shapeCount );
+
+	newUnion->isComplement = self->isComplement;
+	newUnion->shapeList = self->shapeList;
+	newUnion->shapeCount = self->shapeCount;
+	
+	return (void*)newUnion;
+}
+
+void* _Union_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(Union);
+	Type                                                          type = Union_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _Union_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Union_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Union_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = _Union_DefaultNew;
+	Stg_Component_ConstructFunction*                        _construct = _Union_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _Union_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _Union_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Union_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Union_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _Union_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _Union_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _Union_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _Union_New(  UNION_PASSARGS  );
+}
+
+
+void _Union_AssignFromXML( void* combination, Stg_ComponentFactory* cf, void* data ) {
+	Union*                  self       = (Union*)combination;
+	Index                   shapeCount;
+	Stg_Shape**             shapeList;
+	Bool*                   isComplement;
+	Index                   shape_I;
+	Dictionary_Entry_Value* optionsList;
+	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	char*                   nameShape;
+	Stream*                 stream     = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
+	
+	_Stg_Shape_AssignFromXML( self, cf, data );
+
+	optionsList = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"shapes" );
+
+	shapeCount = Dictionary_Entry_Value_GetCount(optionsList );
+
+	/* Allocate space */
+	shapeList     = Memory_Alloc_Array( Stg_Shape* , shapeCount, "Shape Array" );
+	isComplement  = Memory_Alloc_Array( Bool, shapeCount, "Complement Array" );
+	memset( shapeList,     0, shapeCount * sizeof(Stg_Shape*) );
+	memset( isComplement,  0, shapeCount * sizeof(Bool) );
+	
+	Stream_Indent( stream );
+	for ( shape_I = 0 ; shape_I < shapeCount ; shape_I++) { 
+          /* gets the textual name corresponding to the shape elements	 */
+		nameShape = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( optionsList, shape_I));
+
+		if ( nameShape[0] == '!' ) {
+			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)&nameShape[1], Stg_Shape, True, data  ) ;
+			isComplement[ shape_I ] = True;
+		}
+		else {
+			shapeList[ shape_I ] =  Stg_ComponentFactory_ConstructByName( cf, (Name)nameShape, Stg_Shape, True, data ) ;
+			isComplement[ shape_I ] = False;
+		}
+		
+	}
+	Stream_UnIndent( stream  );
+
+	_Union_Init( self, shapeList, shapeCount, isComplement );
+
+	Memory_Free( shapeList );
+	Memory_Free( isComplement );
+}
+
+void _Union_Build( void* combination, void* data ) {
+	Union*	self = (Union*)combination;
+   unsigned shape_I = 0;
+    
+   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
+      Stg_Component_Build( self->shapeList[shape_I], data, False );
+   }
+
+	_Stg_Shape_Build( self, data );
+}
+void _Union_Initialise( void* combination, void* data ) {
+	Union*	self = (Union*)combination;
+	unsigned shape_I = 0;
+    
+   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
+      Stg_Component_Initialise( self->shapeList[shape_I], data, False );
+   }
+	_Stg_Shape_Initialise( self, data );
+}
+void _Union_Execute( void* combination, void* data ) {
+	Union*	self = (Union*)combination;
+	
+	_Stg_Shape_Execute( self, data );
+}
+void _Union_Destroy( void* combination, void* data ) {
+	Union*	self = (Union*)combination;
+	unsigned shape_I = 0;
+    
+   for( shape_I = 0 ; shape_I < self->shapeCount ; shape_I++ ) {
+      Stg_Component_Destroy( self->shapeList[shape_I], data, False );
+   }
+	Memory_Free( self->isComplement );
+
+	_Stg_Shape_Destroy( self, data );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+	
+/*---------------------------------------------------------------------------------------------------------------------
+** Private Member functions
+*/
+Bool _Union_IsCoordInside( void* combination, Coord coord ) {
+	Union*    self           = (Union*)combination;
+	Index           shapeCount     = self->shapeCount;
+	Index           shape_I;
+	Bool            value;
+
+	for( shape_I = 0 ; shape_I < shapeCount ; shape_I++ ) {
+		value = Stg_Shape_IsCoordInside( self->shapeList[ shape_I ], coord );
+
+		
+		if ( self->isComplement[ shape_I ] )
+                  value = (!value) ? True : False;
+			
+		if ( value )
+			return True;
+	}
+	return False;
+}	
+
+
+double _Union_CalculateVolume( void* combination ) {
+	assert ( 0 );
+	return 0.0;
+}
+
+void _Union_DistanceFromCenterAxis( void* shape, Coord coord, double* disVec ) {
+	Stg_Shape* self = (Stg_Shape*)shape;
+	Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+	"Error in function %s: This functions hasn't been implemented.", 
+	"Please inform underworld-dev at vpac.org you've received this error.\n", __func__ );
+}
+	
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/tests/ShapeSuite.c
--- a/Shape/tests/ShapeSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,257 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/StgDomain.h"
-
-typedef struct {
-	Stg_ComponentFactory* cf;
-} ShapeSuiteData;
-
-void ShapeSuite_Setup( ShapeSuiteData* data ) { 
-}
-
-void ShapeSuite_Teardown( ShapeSuiteData* data ) {
-   stgMainDestroy( data->cf );
-}
-
-void ShapeSuite_GeneratePoints( ShapeSuiteData* data, Dimension_Index dim, Name inputFileName ) {
-/** Test Definition: */
-	Stg_ComponentFactory*	cf;
-	DomainContext*				context = NULL;
-	Dictionary*					dictionary;
-	Stg_Shape*					shape;
-	unsigned						testCoordCount, index;
-	Name							outputPath;
-	Coord							coord;
-	Stream*						stream = Journal_Register( Info_Type, (Name)inputFileName );
-	char							xml_input[PCU_PATH_MAX];
-
-	Journal_Enable_AllTypedStream( False  );
-
-	/* read in the xml input file */
-	pcu_filename_input( inputFileName, xml_input );
-	data->cf = cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
-	stgMainBuildAndInitialise( cf );
-	context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  ); 
-
-	dictionary = context->dictionary;
-	outputPath = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"outputPath"  );
-
-	Stream_RedirectFile_WithPrependedPath( stream, outputPath, "test.dat" );
-	shape = (Stg_Shape*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"shape" );
-	assert( shape  );
-
-	testCoordCount = Dictionary_GetUnsignedInt_WithDefault( dictionary, "testCoordCount", 10000 );
-
-	Journal_Enable_TypedStream( InfoStream_Type, True );
-
-	/* Test to see if random points are in shape */
-	srand48(0);
-	for (index = 0 ; index < testCoordCount ; index++ ) {
-		coord[ I_AXIS ] = drand48() - 1.0;
-		coord[ J_AXIS ] = drand48() - 1.0;
-		if ( dim == 3 ) 
-			coord[ K_AXIS ] = drand48() - 1.0;
-
-		if ( Stg_Shape_IsCoordInside( shape, coord ) ) 
-			Journal_Printf( stream, "%u\n", index );
-	}
-	Stream_CloseAndFreeFile( stream );
-}
-
-void ShapeSuite_TestBox2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testBox2D.xml" );
-	
-	pcu_filename_expected( "testBox2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestBox3D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testBox3D.xml" );
-
-	pcu_filename_expected( "testBox3D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestSphere2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testSphere2D.xml" );
-
-	pcu_filename_expected( "testSphere2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestSphere2D_Invert( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testSphere-invert.xml" );
-
-	pcu_filename_expected( "testSphere2D-invert.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestSphere3D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testSphere3D.xml" );
-
-	pcu_filename_expected( "testSphere3D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestConvexHull2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testConvexHull2D.xml" );
-
-	pcu_filename_expected( "testConvexHull2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestConvexHull3D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testConvexHull3D.xml" );
-
-	pcu_filename_expected( "testConvexHull3D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestUnion2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testUnion2D.xml" );
-
-	pcu_filename_expected( "testUnion2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestUnion3D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testUnion3D.xml" );
-
-	pcu_filename_expected( "testUnion3D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestUnion2DSingleNOT( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testUnion2DSingleNot.xml" );
-
-	pcu_filename_expected( "testUnion2DSingleNot.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestUnion3DSingleNOT( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testUnion3DSingleNot.xml" );
-
-	pcu_filename_expected( "testUnion3DSingleNot.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestIntersection2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testIntersection2D.xml" );
-
-	pcu_filename_expected( "testIntersection2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestIntersection3D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testIntersection3D.xml" );
-
-	pcu_filename_expected( "testIntersection3D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestCylinder( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testCylinder.xml" );
-
-	pcu_filename_expected( "testCylinder.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestPolygonShape2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testPolygonShape.xml" );
-
-	pcu_filename_expected( "testPolygonShape2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestSuperellipsoid2D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 2;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testSuperellipsoid2D.xml" );
-
-	pcu_filename_expected( "testSuperellipsoid2D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite_TestSuperellipsoid3D( ShapeSuiteData* data ) {
-	Dimension_Index  dim = 3;
-	char expected_file[PCU_PATH_MAX];
-	ShapeSuite_GeneratePoints( data, dim, "testSuperellipsoid3D.xml" );
-
-	pcu_filename_expected( "testSuperellipsoid3D.expected", expected_file );
-	pcu_check_fileEq( "output/test.dat", expected_file );
-	remove("output/test.dat");
-}
-
-void ShapeSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, ShapeSuiteData );
-   pcu_suite_setFixtures( suite, ShapeSuite_Setup, ShapeSuite_Teardown );
-   pcu_suite_addTest( suite, ShapeSuite_TestBox2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestBox3D );
-   pcu_suite_addTest( suite, ShapeSuite_TestSphere2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestSphere2D_Invert );
-   pcu_suite_addTest( suite, ShapeSuite_TestSphere3D );
-   pcu_suite_addTest( suite, ShapeSuite_TestConvexHull2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestConvexHull3D );
-   pcu_suite_addTest( suite, ShapeSuite_TestUnion2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestUnion3D );
-   pcu_suite_addTest( suite, ShapeSuite_TestUnion2DSingleNOT );
-   pcu_suite_addTest( suite, ShapeSuite_TestUnion3DSingleNOT );
-   pcu_suite_addTest( suite, ShapeSuite_TestIntersection2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestIntersection3D );
-   pcu_suite_addTest( suite, ShapeSuite_TestCylinder );
-   pcu_suite_addTest( suite, ShapeSuite_TestPolygonShape2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestSuperellipsoid2D );
-   pcu_suite_addTest( suite, ShapeSuite_TestSuperellipsoid3D );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Shape/tests/ShapeSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shape/tests/ShapeSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,257 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/StgDomain.h"
+
+typedef struct {
+	Stg_ComponentFactory* cf;
+} ShapeSuiteData;
+
+void ShapeSuite_Setup( ShapeSuiteData* data ) { 
+}
+
+void ShapeSuite_Teardown( ShapeSuiteData* data ) {
+   stgMainDestroy( data->cf );
+}
+
+void ShapeSuite_GeneratePoints( ShapeSuiteData* data, Dimension_Index dim, Name inputFileName ) {
+/** Test Definition: */
+	Stg_ComponentFactory*	cf;
+	DomainContext*				context = NULL;
+	Dictionary*					dictionary;
+	Stg_Shape*					shape;
+	unsigned						testCoordCount, index;
+	Name							outputPath;
+	Coord							coord;
+	Stream*						stream = Journal_Register( Info_Type, (Name)inputFileName );
+	char							xml_input[PCU_PATH_MAX];
+
+	Journal_Enable_AllTypedStream( False  );
+
+	/* read in the xml input file */
+	pcu_filename_input( inputFileName, xml_input );
+	data->cf = cf = stgMainInitFromXML( xml_input, MPI_COMM_WORLD, NULL );
+	stgMainBuildAndInitialise( cf );
+	context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  ); 
+
+	dictionary = context->dictionary;
+	outputPath = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"outputPath"  );
+
+	Stream_RedirectFile_WithPrependedPath( stream, outputPath, "test.dat" );
+	shape = (Stg_Shape*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"shape" );
+	assert( shape  );
+
+	testCoordCount = Dictionary_GetUnsignedInt_WithDefault( dictionary, "testCoordCount", 10000 );
+
+	Journal_Enable_TypedStream( InfoStream_Type, True );
+
+	/* Test to see if random points are in shape */
+	srand48(0);
+	for (index = 0 ; index < testCoordCount ; index++ ) {
+		coord[ I_AXIS ] = drand48() - 1.0;
+		coord[ J_AXIS ] = drand48() - 1.0;
+		if ( dim == 3 ) 
+			coord[ K_AXIS ] = drand48() - 1.0;
+
+		if ( Stg_Shape_IsCoordInside( shape, coord ) ) 
+			Journal_Printf( stream, "%u\n", index );
+	}
+	Stream_CloseAndFreeFile( stream );
+}
+
+void ShapeSuite_TestBox2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testBox2D.xml" );
+	
+	pcu_filename_expected( "testBox2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestBox3D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testBox3D.xml" );
+
+	pcu_filename_expected( "testBox3D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestSphere2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testSphere2D.xml" );
+
+	pcu_filename_expected( "testSphere2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestSphere2D_Invert( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testSphere-invert.xml" );
+
+	pcu_filename_expected( "testSphere2D-invert.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestSphere3D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testSphere3D.xml" );
+
+	pcu_filename_expected( "testSphere3D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestConvexHull2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testConvexHull2D.xml" );
+
+	pcu_filename_expected( "testConvexHull2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestConvexHull3D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testConvexHull3D.xml" );
+
+	pcu_filename_expected( "testConvexHull3D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestUnion2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testUnion2D.xml" );
+
+	pcu_filename_expected( "testUnion2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestUnion3D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testUnion3D.xml" );
+
+	pcu_filename_expected( "testUnion3D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestUnion2DSingleNOT( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testUnion2DSingleNot.xml" );
+
+	pcu_filename_expected( "testUnion2DSingleNot.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestUnion3DSingleNOT( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testUnion3DSingleNot.xml" );
+
+	pcu_filename_expected( "testUnion3DSingleNot.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestIntersection2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testIntersection2D.xml" );
+
+	pcu_filename_expected( "testIntersection2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestIntersection3D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testIntersection3D.xml" );
+
+	pcu_filename_expected( "testIntersection3D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestCylinder( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testCylinder.xml" );
+
+	pcu_filename_expected( "testCylinder.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestPolygonShape2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testPolygonShape.xml" );
+
+	pcu_filename_expected( "testPolygonShape2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestSuperellipsoid2D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 2;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testSuperellipsoid2D.xml" );
+
+	pcu_filename_expected( "testSuperellipsoid2D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite_TestSuperellipsoid3D( ShapeSuiteData* data ) {
+	Dimension_Index  dim = 3;
+	char expected_file[PCU_PATH_MAX];
+	ShapeSuite_GeneratePoints( data, dim, "testSuperellipsoid3D.xml" );
+
+	pcu_filename_expected( "testSuperellipsoid3D.expected", expected_file );
+	pcu_check_fileEq( "output/test.dat", expected_file );
+	remove("output/test.dat");
+}
+
+void ShapeSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, ShapeSuiteData );
+   pcu_suite_setFixtures( suite, ShapeSuite_Setup, ShapeSuite_Teardown );
+   pcu_suite_addTest( suite, ShapeSuite_TestBox2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestBox3D );
+   pcu_suite_addTest( suite, ShapeSuite_TestSphere2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestSphere2D_Invert );
+   pcu_suite_addTest( suite, ShapeSuite_TestSphere3D );
+   pcu_suite_addTest( suite, ShapeSuite_TestConvexHull2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestConvexHull3D );
+   pcu_suite_addTest( suite, ShapeSuite_TestUnion2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestUnion3D );
+   pcu_suite_addTest( suite, ShapeSuite_TestUnion2DSingleNOT );
+   pcu_suite_addTest( suite, ShapeSuite_TestUnion3DSingleNOT );
+   pcu_suite_addTest( suite, ShapeSuite_TestIntersection2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestIntersection3D );
+   pcu_suite_addTest( suite, ShapeSuite_TestCylinder );
+   pcu_suite_addTest( suite, ShapeSuite_TestPolygonShape2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestSuperellipsoid2D );
+   pcu_suite_addTest( suite, ShapeSuite_TestSuperellipsoid3D );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/CellLayout.c
--- a/Swarm/src/CellLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,201 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: CellLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "CellLayout.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type CellLayout_Type = "CellLayout";
-
-CellLayout* _CellLayout_New(  CELLLAYOUT_DEFARGS  ) {
-	CellLayout* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(CellLayout) );
-	self = (CellLayout*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* General info */
-	
-	/* Virtual functions */
-	self->_cellLocalCount = _cellLocalCount;
-	self->_cellShadowCount = _cellShadowCount;
-	self->_pointCount = _pointCount;
-	self->_initialisePoints = _initialisePoints;
-	self->_mapElementIdToCellId = _mapElementIdToCellId;
-	self->_isInCell = _isInCell;
-	self->_cellOf = _cellOf;
-	self->_getShadowInfo = _getShadowInfo;
-	
-	return self;
-}
-
-void _CellLayout_Init( CellLayout* self, AbstractContext* context ) {
-	/* General and Virtual info should already be set */
-
-	self->context = context;	
-}
-
-void _CellLayout_Delete( void* cellLayout ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	/* _Stg_Component_Delete parent*/
-	_Stg_Component_Delete( self );
-}
-
-void _CellLayout_Print( void* cellLayout, Stream* stream ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	/* Set the Journal for printing informations */
-	Stream* cellLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( cellLayoutStream, "CellLayout (ptr): %p\n", self );
-	
-	/* Print parent */
-	_Stg_Component_Print( self, cellLayoutStream );
-	
-	/* Virtual info */
-	Journal_Printf( cellLayoutStream, "\t_cellLocalCount (func ptr): %p\n", self->_cellLocalCount );
-	Journal_Printf( cellLayoutStream, "\t_cellShadowCount (func ptr): %p\n", self->_cellShadowCount );
-	Journal_Printf( cellLayoutStream, "\t_pointCount (func ptr): %p\n", self->_pointCount );
-	Journal_Printf( cellLayoutStream, "\t_initialisePoints (func ptr): %p\n", self->_initialisePoints );
-	Journal_Printf( cellLayoutStream, "\t_mapElementIdToCellId (func ptr): %p\n", self->_mapElementIdToCellId );
-	Journal_Printf( cellLayoutStream, "\t_isInCell (func ptr): %p\n", self->_isInCell );
-	Journal_Printf( cellLayoutStream, "\t_cellOf (func ptr): %p\n", self->_cellOf );
-	Journal_Printf( cellLayoutStream, "\t_getShadowInfo (func ptr): %p\n", self->_getShadowInfo );
-	
-	/* CellLayout info */
-}
-
-void _CellLayout_Destroy( void* cellLayout, void* data ) {
-}
-
-void* _CellLayout_Copy( const void* cellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	CellLayout*	self = (CellLayout*)cellLayout;
-	CellLayout*	newCellLayout;
-	
-	newCellLayout = (CellLayout*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	/* Virtual methods */
-	newCellLayout->_cellLocalCount = self->_cellLocalCount;
-	newCellLayout->_cellShadowCount = self->_cellShadowCount;
-	newCellLayout->_pointCount = self->_pointCount;
-	newCellLayout->_initialisePoints = self->_initialisePoints;
-	newCellLayout->_mapElementIdToCellId = self->_mapElementIdToCellId;
-	newCellLayout->_isInCell = self->_isInCell;
-	newCellLayout->_cellOf = self->_cellOf;
-	newCellLayout->_getShadowInfo = self->_getShadowInfo;
-	
-	return (void*)newCellLayout;
-}
-
-void _CellLayout_AssignFromXML( void* cellLayout, Stg_ComponentFactory *cf, void* data ) {
-	CellLayout*			self = (CellLayout*)cellLayout;
-	AbstractContext*	context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-   if( !context  )
-      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	_CellLayout_Init( self, context );
-}
-
-Cell_Index CellLayout_CellDomainCount( void* cellLayout ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_cellLocalCount( self ) + self->_cellShadowCount( self );
-}
-
-Cell_Index CellLayout_CellLocalCount( void* cellLayout ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_cellLocalCount( self );
-}
-
-Cell_Index CellLayout_CellShadowCount( void* cellLayout ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_cellShadowCount( self );
-}
-
-Cell_PointIndex CellLayout_PointCount( void* cellLayout, Cell_Index cell_I ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_pointCount( self, cell_I );
-}
-
-void CellLayout_InitialiseCellPoints( void* cellLayout, Cell_Index cell_I, Cell_PointIndex pointCount, Cell_Points points ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	self->_initialisePoints( self, cell_I, pointCount, points );
-}
-
-
-Cell_Index CellLayout_MapElementIdToCellId( void* cellLayout, unsigned element_dI ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_mapElementIdToCellId( self, element_dI );
-}
-
-
-Bool CellLayout_IsInCell( void* cellLayout, Cell_Index cellIndex, void* particle ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_isInCell( self, cellIndex, particle );
-}
-
-	
-Cell_Index CellLayout_CellOf( void* cellLayout, void* particle ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_cellOf( self, particle );
-}
-
-
-ShadowInfo* CellLayout_GetShadowInfo( void* cellLayout ) {
-	CellLayout* self = (CellLayout*)cellLayout;
-	
-	return self->_getShadowInfo( self );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/CellLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/CellLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,201 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: CellLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "CellLayout.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type CellLayout_Type = "CellLayout";
+
+CellLayout* _CellLayout_New(  CELLLAYOUT_DEFARGS  ) {
+	CellLayout* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(CellLayout) );
+	self = (CellLayout*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* General info */
+	
+	/* Virtual functions */
+	self->_cellLocalCount = _cellLocalCount;
+	self->_cellShadowCount = _cellShadowCount;
+	self->_pointCount = _pointCount;
+	self->_initialisePoints = _initialisePoints;
+	self->_mapElementIdToCellId = _mapElementIdToCellId;
+	self->_isInCell = _isInCell;
+	self->_cellOf = _cellOf;
+	self->_getShadowInfo = _getShadowInfo;
+	
+	return self;
+}
+
+void _CellLayout_Init( CellLayout* self, AbstractContext* context ) {
+	/* General and Virtual info should already be set */
+
+	self->context = context;	
+}
+
+void _CellLayout_Delete( void* cellLayout ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	/* _Stg_Component_Delete parent*/
+	_Stg_Component_Delete( self );
+}
+
+void _CellLayout_Print( void* cellLayout, Stream* stream ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	/* Set the Journal for printing informations */
+	Stream* cellLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( cellLayoutStream, "CellLayout (ptr): %p\n", self );
+	
+	/* Print parent */
+	_Stg_Component_Print( self, cellLayoutStream );
+	
+	/* Virtual info */
+	Journal_Printf( cellLayoutStream, "\t_cellLocalCount (func ptr): %p\n", self->_cellLocalCount );
+	Journal_Printf( cellLayoutStream, "\t_cellShadowCount (func ptr): %p\n", self->_cellShadowCount );
+	Journal_Printf( cellLayoutStream, "\t_pointCount (func ptr): %p\n", self->_pointCount );
+	Journal_Printf( cellLayoutStream, "\t_initialisePoints (func ptr): %p\n", self->_initialisePoints );
+	Journal_Printf( cellLayoutStream, "\t_mapElementIdToCellId (func ptr): %p\n", self->_mapElementIdToCellId );
+	Journal_Printf( cellLayoutStream, "\t_isInCell (func ptr): %p\n", self->_isInCell );
+	Journal_Printf( cellLayoutStream, "\t_cellOf (func ptr): %p\n", self->_cellOf );
+	Journal_Printf( cellLayoutStream, "\t_getShadowInfo (func ptr): %p\n", self->_getShadowInfo );
+	
+	/* CellLayout info */
+}
+
+void _CellLayout_Destroy( void* cellLayout, void* data ) {
+}
+
+void* _CellLayout_Copy( const void* cellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	CellLayout*	self = (CellLayout*)cellLayout;
+	CellLayout*	newCellLayout;
+	
+	newCellLayout = (CellLayout*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	/* Virtual methods */
+	newCellLayout->_cellLocalCount = self->_cellLocalCount;
+	newCellLayout->_cellShadowCount = self->_cellShadowCount;
+	newCellLayout->_pointCount = self->_pointCount;
+	newCellLayout->_initialisePoints = self->_initialisePoints;
+	newCellLayout->_mapElementIdToCellId = self->_mapElementIdToCellId;
+	newCellLayout->_isInCell = self->_isInCell;
+	newCellLayout->_cellOf = self->_cellOf;
+	newCellLayout->_getShadowInfo = self->_getShadowInfo;
+	
+	return (void*)newCellLayout;
+}
+
+void _CellLayout_AssignFromXML( void* cellLayout, Stg_ComponentFactory *cf, void* data ) {
+	CellLayout*			self = (CellLayout*)cellLayout;
+	AbstractContext*	context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+   if( !context  )
+      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	_CellLayout_Init( self, context );
+}
+
+Cell_Index CellLayout_CellDomainCount( void* cellLayout ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_cellLocalCount( self ) + self->_cellShadowCount( self );
+}
+
+Cell_Index CellLayout_CellLocalCount( void* cellLayout ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_cellLocalCount( self );
+}
+
+Cell_Index CellLayout_CellShadowCount( void* cellLayout ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_cellShadowCount( self );
+}
+
+Cell_PointIndex CellLayout_PointCount( void* cellLayout, Cell_Index cell_I ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_pointCount( self, cell_I );
+}
+
+void CellLayout_InitialiseCellPoints( void* cellLayout, Cell_Index cell_I, Cell_PointIndex pointCount, Cell_Points points ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	self->_initialisePoints( self, cell_I, pointCount, points );
+}
+
+
+Cell_Index CellLayout_MapElementIdToCellId( void* cellLayout, unsigned element_dI ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_mapElementIdToCellId( self, element_dI );
+}
+
+
+Bool CellLayout_IsInCell( void* cellLayout, Cell_Index cellIndex, void* particle ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_isInCell( self, cellIndex, particle );
+}
+
+	
+Cell_Index CellLayout_CellOf( void* cellLayout, void* particle ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_cellOf( self, particle );
+}
+
+
+ShadowInfo* CellLayout_GetShadowInfo( void* cellLayout ) {
+	CellLayout* self = (CellLayout*)cellLayout;
+	
+	return self->_getShadowInfo( self );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ElementCellLayout.c
--- a/Swarm/src/ElementCellLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,378 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ElementCellLayout.c 4184 2007-09-25 07:54:17Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include "StandardParticle.h"
-
-const Type ElementCellLayout_Type = "ElementCellLayout";
-
-ElementCellLayout* ElementCellLayout_New( Name name, AbstractContext* context, void* mesh ) { 
-  ElementCellLayout* self = (ElementCellLayout*)_ElementCellLayout_DefaultNew( name );
-
-	self->isConstructed = True;
-	_CellLayout_Init( (CellLayout*)self, context );
-	_ElementCellLayout_Init( self, mesh );
-
-	return self;
-}
-
-void* _ElementCellLayout_DefaultNew( Name name ){
-	/* Variables set in this function */
-	SizeT                                                _sizeOfSelf = sizeof(ElementCellLayout);
-	Type                                                        type = ElementCellLayout_Type;
-	Stg_Class_DeleteFunction*                                _delete = _ElementCellLayout_Delete;
-	Stg_Class_PrintFunction*                                  _print = _ElementCellLayout_Print;
-	Stg_Class_CopyFunction*                                    _copy = _ElementCellLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = _ElementCellLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                      _construct = _ElementCellLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                              _build = _ElementCellLayout_Build;
-	Stg_Component_InitialiseFunction*                    _initialise = _ElementCellLayout_Initialise;
-	Stg_Component_ExecuteFunction*                          _execute = _ElementCellLayout_Execute;
-	Stg_Component_DestroyFunction*                          _destroy = _ElementCellLayout_Destroy;
-	AllocationType                                nameAllocationType = NON_GLOBAL;
-	CellLayout_CellCountFunction*                    _cellLocalCount = _ElementCellLayout_CellLocalCount;
-	CellLayout_CellCountFunction*                   _cellShadowCount = _ElementCellLayout_CellShadowCount;
-	CellLayout_PointCountFunction*                       _pointCount = _ElementCellLayout_PointCount;
-	CellLayout_InitialisePointsFunction*           _initialisePoints = _ElementCellLayout_InitialisePoints;
-	CellLayout_MapElementIdToCellIdFunction*   _mapElementIdToCellId = _ElementCellLayout_MapElementIdToCellId;
-	CellLayout_IsInCellFunction*                           _isInCell = _ElementCellLayout_IsInCell;
-	CellLayout_CellOfFunction*                               _cellOf = _ElementCellLayout_CellOf;
-	CellLayout_GetShadowInfoFunction*                 _getShadowInfo = _ElementCellLayout_GetShadowInfo;
-
-	return (void*) _ElementCellLayout_New(  ELEMENTCELLLAYOUT_PASSARGS  );
-}
-
-ElementCellLayout* _ElementCellLayout_New(  ELEMENTCELLLAYOUT_DEFARGS  ) {
-	ElementCellLayout* self;
-	
-	/* Allocate memory */
-	self = (ElementCellLayout*)_CellLayout_New(  CELLLAYOUT_PASSARGS  );
-	
-	/* General info */
-	
-	/* Virtual info */
-	
-	/* ElementCellLayout info */
-	
-	return self;
-}
-
-
-void _ElementCellLayout_Init( ElementCellLayout* self, void* mesh ) { 
-	/* General and Virtual info should already be set */
-	
-	/* ElementCellInfo info */
-	self->mesh = (Mesh*)mesh;
-	self->incArray = IArray_New();
-}
-
-void _ElementCellLayout_Delete( void* elementCellLayout ) {
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-
-	/* Stg_Class_Delete parent class */
-	_CellLayout_Delete( self );
-}
-
-void _ElementCellLayout_Print( void* elementCellLayout, Stream* stream ) {
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-
-	/* Set the Journal for printing informations */
-	Stream* elementCellLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( elementCellLayoutStream, "ElementCellLayout (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_CellLayout_Print( self, elementCellLayoutStream );
-	
-	/* Virtual info */
-	
-	/* ElementCellLayout info */
-	Journal_Printf( elementCellLayoutStream, "\tmesh (ptr): %p\n", self->mesh );
-}
-
-
-void* _ElementCellLayout_Copy( const void* elementCellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ElementCellLayout*	self = (ElementCellLayout*)elementCellLayout;
-	ElementCellLayout*	newElementCellLayout;
-	PtrMap*			map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newElementCellLayout = (ElementCellLayout*)_CellLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	if( deep ) {
-		newElementCellLayout->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
-	}
-	else {
-		newElementCellLayout->mesh = self->mesh;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newElementCellLayout;
-}
-
-void _ElementCellLayout_AssignFromXML( void* elementCellLayout, Stg_ComponentFactory *cf, void* data ){
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-	Mesh*              mesh;
-
-	_CellLayout_AssignFromXML( self, cf, data );
-
-	mesh =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", Mesh, True, data  ) ;
-	
-	_ElementCellLayout_Init( self, mesh );
-}
-	
-void _ElementCellLayout_Build( void *elementCellLayout, void *data ){
-	ElementCellLayout*	self = (ElementCellLayout*)elementCellLayout;
-
-	Stg_Component_Build( self->mesh, NULL, False );
-
-	if( !Mesh_HasIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), MT_VERTEX ) ) {
-		Stream* elementCellLayoutStream = Journal_Register( ErrorStream_Type, (Name)self->type  );
-		Journal_Printf( elementCellLayoutStream, "Warning: Mesh not configured to build element node table. "
-			"Activating it now.\n" );
-		abort();
-	}
-
-	ElementCellLayout_BuildShadowInfo( self );
-}
-	
-void _ElementCellLayout_Initialise( void *elementCellLayout, void *data ){
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-	Stg_Component_Initialise( self->mesh, data, False );
-}
-	
-void _ElementCellLayout_Execute( void *elementCellLayout, void *data ){
-}
-
-void _ElementCellLayout_Destroy( void *elementCellLayout, void *data ){
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-		
-	ElementCellLayout_DestroyShadowInfo( self );
-	NewClass_Delete( self->incArray );
-	
-	_CellLayout_Destroy( self, data );
-}
-
-Cell_Index _ElementCellLayout_CellLocalCount( void* elementCellLayout ) {
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-	return Mesh_GetLocalSize( self->mesh, Mesh_GetDimSize( self->mesh ) );
-}
-
-Cell_Index _ElementCellLayout_CellShadowCount( void* elementCellLayout ) {
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-	return Mesh_GetRemoteSize( self->mesh, Mesh_GetDimSize( self->mesh ) );
-}
-
-Cell_PointIndex _ElementCellLayout_PointCount( void* elementCellLayout, Cell_Index cellIndex ) {
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-
-	Mesh_GetIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), cellIndex, MT_VERTEX, 
-			   self->incArray );
-	return IArray_GetSize( self->incArray );
-}
-
-void _ElementCellLayout_InitialisePoints( void* elementCellLayout, Cell_Index cellIndex, Cell_PointIndex pointCount, 
-					  double*** points )
-{
-	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
-	Cell_PointIndex point_I;
-	unsigned	nInc;
-	unsigned*	inc;
-
-	Mesh_GetIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), cellIndex, MT_VERTEX, 
-			   self->incArray );
-	nInc = IArray_GetSize( self->incArray );
-	inc = (unsigned*)IArray_GetPtr( self->incArray );
-	
-	/* point to the mesh's node's coordinates */
-	for( point_I = 0; point_I < pointCount; point_I++ ) {
-		points[point_I] = &self->mesh->verts[inc[point_I]];
-	}
-}
-
-
-Cell_Index _ElementCellLayout_MapElementIdToCellId( void* elementCellLayout, unsigned element_dI ) {
-	
-	#ifdef CAUTIOUS
-	{
-		ElementCellLayout*      self = (ElementCellLayout*)elementCellLayout;
-		Stream* errorStr = Journal_Register( Error_Type, (Name)self->type  );
-		Journal_Firewall( element_dI < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ), errorStr, "Error - in %s(): User asked "
-			"for cell corresponding to element %d, but the mesh that this cell layout is based on only "
-			"has %d elements.\n", __func__, element_dI, Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	}	
-	#endif
-	
-	return element_dI;
-}
-
-
-Bool _ElementCellLayout_IsInCell( void* elementCellLayout, Cell_Index cellIndex, void* _particle ) {
-	ElementCellLayout*      self     = (ElementCellLayout*)elementCellLayout;
-	GlobalParticle*	        particle = (GlobalParticle*)_particle;
-	unsigned		elDim, elInd;
-
-	return Mesh_ElementHasPoint( self->mesh, cellIndex, particle->coord, (MeshTopology_Dim*)(&elDim), &elInd );
-}
-
-Cell_Index _ElementCellLayout_CellOf( void* elementCellLayout, void* _particle ) {
-	ElementCellLayout*      self     = (ElementCellLayout*)elementCellLayout;
-	GlobalParticle*	        particle = (GlobalParticle*)_particle;
-	unsigned		elInd;
-
-	if( !Mesh_SearchElements( self->mesh, particle->coord, &elInd ) )
-		elInd = Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) );
-
-	return elInd;
-}
-
-
-ShadowInfo* _ElementCellLayout_GetShadowInfo( void* elementCellLayout ) {
-	ElementCellLayout*      self = (ElementCellLayout*)elementCellLayout;
-
-	return &self->cellShadowInfo;
-}
-
-void ElementCellLayout_DestroyShadowInfo( ElementCellLayout* self ) {
-	unsigned	nIncProcs = self->cellShadowInfo.procNbrInfo->procNbrCnt;
-
-	/* Extract neighbouring proc information. */
-	Memory_Free( self->cellShadowInfo.procNbrInfo->procNbrTbl );
-   if( nIncProcs ) {
-      Memory_Free( self->cellShadowInfo.procShadowedCnt );
-      Memory_Free( self->cellShadowInfo.procShadowCnt );
-      Memory_Free( self->cellShadowInfo.procShadowedTbl );
-      Memory_Free( self->cellShadowInfo.procShadowTbl );
-   }
-	Memory_Free( self->cellShadowInfo.procNbrInfo );
-}
-
-void ElementCellLayout_BuildShadowInfo( ElementCellLayout* self ) {
-	unsigned	nDims;
-	Comm*		comm;
-	int	        nIncProcs;
-	const int*      incProcs;
-	unsigned	n_i;
-
-	nDims = Mesh_GetDimSize( self->mesh );
-	comm = Mesh_GetCommTopology( self->mesh, (MeshTopology_Dim)nDims );
-	Comm_GetNeighbours( comm, &nIncProcs, &incProcs );
-
-	/* Extract neighbouring proc information. */
-	self->cellShadowInfo.procNbrInfo = Memory_Alloc_Unnamed( ProcNbrInfo );
-	self->cellShadowInfo.procNbrInfo->procNbrCnt = nIncProcs;
-	self->cellShadowInfo.procNbrInfo->procNbrTbl = AllocArray( unsigned, nIncProcs );
-	memcpy( self->cellShadowInfo.procNbrInfo->procNbrTbl, incProcs, nIncProcs * sizeof(unsigned) );
-
-	/* Count shadow info. */
-	if( nIncProcs ) {
-		self->cellShadowInfo.procShadowedCnt = AllocArray( unsigned, nIncProcs );
-		memset( self->cellShadowInfo.procShadowedCnt, 0, nIncProcs * sizeof(unsigned) );
-		self->cellShadowInfo.procShadowCnt = AllocArray( unsigned, nIncProcs );
-		memset( self->cellShadowInfo.procShadowCnt, 0, nIncProcs * sizeof(unsigned) );
-	}
-	for( n_i = 0; n_i < Mesh_GetSharedSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
-		int	nSharers;
-		const int*	sharers;
-		int	s_i;
-
-		Mesh_GetSharers( self->mesh, (MeshTopology_Dim)nDims, n_i, 
-				 &nSharers, &sharers );
-		for( s_i = 0; s_i < nSharers; s_i++ )
-			self->cellShadowInfo.procShadowedCnt[sharers[s_i]]++;
-	}
-	for( n_i = 0; n_i < Mesh_GetRemoteSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
-		unsigned	owner;
-
-		owner = Mesh_GetOwner( self->mesh, (MeshTopology_Dim)nDims, n_i );
-		self->cellShadowInfo.procShadowCnt[owner]++;
-	}
-
-	/* Build shadow info indices. */
-	if( nIncProcs ) {
-		self->cellShadowInfo.procShadowedTbl = Memory_Alloc_2DComplex_Unnamed( unsigned, nIncProcs, 
-										       self->cellShadowInfo.procShadowedCnt );
-		self->cellShadowInfo.procShadowTbl = Memory_Alloc_2DComplex_Unnamed( unsigned, nIncProcs, 
-										     self->cellShadowInfo.procShadowCnt );
-		memset( self->cellShadowInfo.procShadowedCnt, 0, nIncProcs * sizeof(unsigned) );
-		memset( self->cellShadowInfo.procShadowCnt, 0, nIncProcs * sizeof(unsigned) );
-	}
-	for( n_i = 0; n_i < Mesh_GetSharedSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
-		unsigned	local;
-		unsigned	curInd;
-		int	        nSharers;
-		const int*	        sharers;
-		int	s_i;
-
-		local = Mesh_SharedToLocal( self->mesh, (MeshTopology_Dim)nDims, n_i );
-
-		Mesh_GetSharers( self->mesh, (MeshTopology_Dim)nDims, n_i, 
-				 &nSharers, &sharers );
-		for( s_i = 0; s_i < nSharers; s_i++ ) {
-			curInd = self->cellShadowInfo.procShadowedCnt[sharers[s_i]]++;
-			self->cellShadowInfo.procShadowedTbl[sharers[s_i]][curInd] = local;
-		}
-	}
-	for( n_i = 0; n_i < Mesh_GetRemoteSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
-		unsigned	domain;
-		unsigned	curInd;
-		unsigned	owner;
-
-		domain = Mesh_GetLocalSize( self->mesh, (MeshTopology_Dim)nDims ) + n_i;
-		owner = Mesh_GetOwner( self->mesh, (MeshTopology_Dim)nDims, n_i );
-		curInd = self->cellShadowInfo.procShadowCnt[owner]++;
-		self->cellShadowInfo.procShadowTbl[owner][curInd] = domain;
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ElementCellLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/ElementCellLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,378 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ElementCellLayout.c 4184 2007-09-25 07:54:17Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include "StandardParticle.h"
+
+const Type ElementCellLayout_Type = "ElementCellLayout";
+
+ElementCellLayout* ElementCellLayout_New( Name name, AbstractContext* context, void* mesh ) { 
+  ElementCellLayout* self = (ElementCellLayout*)_ElementCellLayout_DefaultNew( name );
+
+	self->isConstructed = True;
+	_CellLayout_Init( (CellLayout*)self, context );
+	_ElementCellLayout_Init( self, mesh );
+
+	return self;
+}
+
+void* _ElementCellLayout_DefaultNew( Name name ){
+	/* Variables set in this function */
+	SizeT                                                _sizeOfSelf = sizeof(ElementCellLayout);
+	Type                                                        type = ElementCellLayout_Type;
+	Stg_Class_DeleteFunction*                                _delete = _ElementCellLayout_Delete;
+	Stg_Class_PrintFunction*                                  _print = _ElementCellLayout_Print;
+	Stg_Class_CopyFunction*                                    _copy = _ElementCellLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = _ElementCellLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                      _construct = _ElementCellLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                              _build = _ElementCellLayout_Build;
+	Stg_Component_InitialiseFunction*                    _initialise = _ElementCellLayout_Initialise;
+	Stg_Component_ExecuteFunction*                          _execute = _ElementCellLayout_Execute;
+	Stg_Component_DestroyFunction*                          _destroy = _ElementCellLayout_Destroy;
+	AllocationType                                nameAllocationType = NON_GLOBAL;
+	CellLayout_CellCountFunction*                    _cellLocalCount = _ElementCellLayout_CellLocalCount;
+	CellLayout_CellCountFunction*                   _cellShadowCount = _ElementCellLayout_CellShadowCount;
+	CellLayout_PointCountFunction*                       _pointCount = _ElementCellLayout_PointCount;
+	CellLayout_InitialisePointsFunction*           _initialisePoints = _ElementCellLayout_InitialisePoints;
+	CellLayout_MapElementIdToCellIdFunction*   _mapElementIdToCellId = _ElementCellLayout_MapElementIdToCellId;
+	CellLayout_IsInCellFunction*                           _isInCell = _ElementCellLayout_IsInCell;
+	CellLayout_CellOfFunction*                               _cellOf = _ElementCellLayout_CellOf;
+	CellLayout_GetShadowInfoFunction*                 _getShadowInfo = _ElementCellLayout_GetShadowInfo;
+
+	return (void*) _ElementCellLayout_New(  ELEMENTCELLLAYOUT_PASSARGS  );
+}
+
+ElementCellLayout* _ElementCellLayout_New(  ELEMENTCELLLAYOUT_DEFARGS  ) {
+	ElementCellLayout* self;
+	
+	/* Allocate memory */
+	self = (ElementCellLayout*)_CellLayout_New(  CELLLAYOUT_PASSARGS  );
+	
+	/* General info */
+	
+	/* Virtual info */
+	
+	/* ElementCellLayout info */
+	
+	return self;
+}
+
+
+void _ElementCellLayout_Init( ElementCellLayout* self, void* mesh ) { 
+	/* General and Virtual info should already be set */
+	
+	/* ElementCellInfo info */
+	self->mesh = (Mesh*)mesh;
+	self->incArray = IArray_New();
+}
+
+void _ElementCellLayout_Delete( void* elementCellLayout ) {
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+
+	/* Stg_Class_Delete parent class */
+	_CellLayout_Delete( self );
+}
+
+void _ElementCellLayout_Print( void* elementCellLayout, Stream* stream ) {
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+
+	/* Set the Journal for printing informations */
+	Stream* elementCellLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( elementCellLayoutStream, "ElementCellLayout (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_CellLayout_Print( self, elementCellLayoutStream );
+	
+	/* Virtual info */
+	
+	/* ElementCellLayout info */
+	Journal_Printf( elementCellLayoutStream, "\tmesh (ptr): %p\n", self->mesh );
+}
+
+
+void* _ElementCellLayout_Copy( const void* elementCellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ElementCellLayout*	self = (ElementCellLayout*)elementCellLayout;
+	ElementCellLayout*	newElementCellLayout;
+	PtrMap*			map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newElementCellLayout = (ElementCellLayout*)_CellLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	if( deep ) {
+		newElementCellLayout->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
+	}
+	else {
+		newElementCellLayout->mesh = self->mesh;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newElementCellLayout;
+}
+
+void _ElementCellLayout_AssignFromXML( void* elementCellLayout, Stg_ComponentFactory *cf, void* data ){
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+	Mesh*              mesh;
+
+	_CellLayout_AssignFromXML( self, cf, data );
+
+	mesh =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", Mesh, True, data  ) ;
+	
+	_ElementCellLayout_Init( self, mesh );
+}
+	
+void _ElementCellLayout_Build( void *elementCellLayout, void *data ){
+	ElementCellLayout*	self = (ElementCellLayout*)elementCellLayout;
+
+	Stg_Component_Build( self->mesh, NULL, False );
+
+	if( !Mesh_HasIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), MT_VERTEX ) ) {
+		Stream* elementCellLayoutStream = Journal_Register( ErrorStream_Type, (Name)self->type  );
+		Journal_Printf( elementCellLayoutStream, "Warning: Mesh not configured to build element node table. "
+			"Activating it now.\n" );
+		abort();
+	}
+
+	ElementCellLayout_BuildShadowInfo( self );
+}
+	
+void _ElementCellLayout_Initialise( void *elementCellLayout, void *data ){
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+	Stg_Component_Initialise( self->mesh, data, False );
+}
+	
+void _ElementCellLayout_Execute( void *elementCellLayout, void *data ){
+}
+
+void _ElementCellLayout_Destroy( void *elementCellLayout, void *data ){
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+		
+	ElementCellLayout_DestroyShadowInfo( self );
+	NewClass_Delete( self->incArray );
+	
+	_CellLayout_Destroy( self, data );
+}
+
+Cell_Index _ElementCellLayout_CellLocalCount( void* elementCellLayout ) {
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+	return Mesh_GetLocalSize( self->mesh, Mesh_GetDimSize( self->mesh ) );
+}
+
+Cell_Index _ElementCellLayout_CellShadowCount( void* elementCellLayout ) {
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+	return Mesh_GetRemoteSize( self->mesh, Mesh_GetDimSize( self->mesh ) );
+}
+
+Cell_PointIndex _ElementCellLayout_PointCount( void* elementCellLayout, Cell_Index cellIndex ) {
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+
+	Mesh_GetIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), cellIndex, MT_VERTEX, 
+			   self->incArray );
+	return IArray_GetSize( self->incArray );
+}
+
+void _ElementCellLayout_InitialisePoints( void* elementCellLayout, Cell_Index cellIndex, Cell_PointIndex pointCount, 
+					  double*** points )
+{
+	ElementCellLayout* self = (ElementCellLayout*)elementCellLayout;
+	Cell_PointIndex point_I;
+	unsigned	nInc;
+	unsigned*	inc;
+
+	Mesh_GetIncidence( self->mesh, Mesh_GetDimSize( self->mesh ), cellIndex, MT_VERTEX, 
+			   self->incArray );
+	nInc = IArray_GetSize( self->incArray );
+	inc = (unsigned*)IArray_GetPtr( self->incArray );
+	
+	/* point to the mesh's node's coordinates */
+	for( point_I = 0; point_I < pointCount; point_I++ ) {
+		points[point_I] = &self->mesh->verts[inc[point_I]];
+	}
+}
+
+
+Cell_Index _ElementCellLayout_MapElementIdToCellId( void* elementCellLayout, unsigned element_dI ) {
+	
+	#ifdef CAUTIOUS
+	{
+		ElementCellLayout*      self = (ElementCellLayout*)elementCellLayout;
+		Stream* errorStr = Journal_Register( Error_Type, (Name)self->type  );
+		Journal_Firewall( element_dI < Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ), errorStr, "Error - in %s(): User asked "
+			"for cell corresponding to element %d, but the mesh that this cell layout is based on only "
+			"has %d elements.\n", __func__, element_dI, Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	}	
+	#endif
+	
+	return element_dI;
+}
+
+
+Bool _ElementCellLayout_IsInCell( void* elementCellLayout, Cell_Index cellIndex, void* _particle ) {
+	ElementCellLayout*      self     = (ElementCellLayout*)elementCellLayout;
+	GlobalParticle*	        particle = (GlobalParticle*)_particle;
+	unsigned		elDim, elInd;
+
+	return Mesh_ElementHasPoint( self->mesh, cellIndex, particle->coord, (MeshTopology_Dim*)(&elDim), &elInd );
+}
+
+Cell_Index _ElementCellLayout_CellOf( void* elementCellLayout, void* _particle ) {
+	ElementCellLayout*      self     = (ElementCellLayout*)elementCellLayout;
+	GlobalParticle*	        particle = (GlobalParticle*)_particle;
+	unsigned		elInd;
+
+	if( !Mesh_SearchElements( self->mesh, particle->coord, &elInd ) )
+		elInd = Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) );
+
+	return elInd;
+}
+
+
+ShadowInfo* _ElementCellLayout_GetShadowInfo( void* elementCellLayout ) {
+	ElementCellLayout*      self = (ElementCellLayout*)elementCellLayout;
+
+	return &self->cellShadowInfo;
+}
+
+void ElementCellLayout_DestroyShadowInfo( ElementCellLayout* self ) {
+	unsigned	nIncProcs = self->cellShadowInfo.procNbrInfo->procNbrCnt;
+
+	/* Extract neighbouring proc information. */
+	Memory_Free( self->cellShadowInfo.procNbrInfo->procNbrTbl );
+   if( nIncProcs ) {
+      Memory_Free( self->cellShadowInfo.procShadowedCnt );
+      Memory_Free( self->cellShadowInfo.procShadowCnt );
+      Memory_Free( self->cellShadowInfo.procShadowedTbl );
+      Memory_Free( self->cellShadowInfo.procShadowTbl );
+   }
+	Memory_Free( self->cellShadowInfo.procNbrInfo );
+}
+
+void ElementCellLayout_BuildShadowInfo( ElementCellLayout* self ) {
+	unsigned	nDims;
+	Comm*		comm;
+	int	        nIncProcs;
+	const int*      incProcs;
+	unsigned	n_i;
+
+	nDims = Mesh_GetDimSize( self->mesh );
+	comm = Mesh_GetCommTopology( self->mesh, (MeshTopology_Dim)nDims );
+	Comm_GetNeighbours( comm, &nIncProcs, &incProcs );
+
+	/* Extract neighbouring proc information. */
+	self->cellShadowInfo.procNbrInfo = Memory_Alloc_Unnamed( ProcNbrInfo );
+	self->cellShadowInfo.procNbrInfo->procNbrCnt = nIncProcs;
+	self->cellShadowInfo.procNbrInfo->procNbrTbl = AllocArray( unsigned, nIncProcs );
+	memcpy( self->cellShadowInfo.procNbrInfo->procNbrTbl, incProcs, nIncProcs * sizeof(unsigned) );
+
+	/* Count shadow info. */
+	if( nIncProcs ) {
+		self->cellShadowInfo.procShadowedCnt = AllocArray( unsigned, nIncProcs );
+		memset( self->cellShadowInfo.procShadowedCnt, 0, nIncProcs * sizeof(unsigned) );
+		self->cellShadowInfo.procShadowCnt = AllocArray( unsigned, nIncProcs );
+		memset( self->cellShadowInfo.procShadowCnt, 0, nIncProcs * sizeof(unsigned) );
+	}
+	for( n_i = 0; n_i < Mesh_GetSharedSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
+		int	nSharers;
+		const int*	sharers;
+		int	s_i;
+
+		Mesh_GetSharers( self->mesh, (MeshTopology_Dim)nDims, n_i, 
+				 &nSharers, &sharers );
+		for( s_i = 0; s_i < nSharers; s_i++ )
+			self->cellShadowInfo.procShadowedCnt[sharers[s_i]]++;
+	}
+	for( n_i = 0; n_i < Mesh_GetRemoteSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
+		unsigned	owner;
+
+		owner = Mesh_GetOwner( self->mesh, (MeshTopology_Dim)nDims, n_i );
+		self->cellShadowInfo.procShadowCnt[owner]++;
+	}
+
+	/* Build shadow info indices. */
+	if( nIncProcs ) {
+		self->cellShadowInfo.procShadowedTbl = Memory_Alloc_2DComplex_Unnamed( unsigned, nIncProcs, 
+										       self->cellShadowInfo.procShadowedCnt );
+		self->cellShadowInfo.procShadowTbl = Memory_Alloc_2DComplex_Unnamed( unsigned, nIncProcs, 
+										     self->cellShadowInfo.procShadowCnt );
+		memset( self->cellShadowInfo.procShadowedCnt, 0, nIncProcs * sizeof(unsigned) );
+		memset( self->cellShadowInfo.procShadowCnt, 0, nIncProcs * sizeof(unsigned) );
+	}
+	for( n_i = 0; n_i < Mesh_GetSharedSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
+		unsigned	local;
+		unsigned	curInd;
+		int	        nSharers;
+		const int*	        sharers;
+		int	s_i;
+
+		local = Mesh_SharedToLocal( self->mesh, (MeshTopology_Dim)nDims, n_i );
+
+		Mesh_GetSharers( self->mesh, (MeshTopology_Dim)nDims, n_i, 
+				 &nSharers, &sharers );
+		for( s_i = 0; s_i < nSharers; s_i++ ) {
+			curInd = self->cellShadowInfo.procShadowedCnt[sharers[s_i]]++;
+			self->cellShadowInfo.procShadowedTbl[sharers[s_i]][curInd] = local;
+		}
+	}
+	for( n_i = 0; n_i < Mesh_GetRemoteSize( self->mesh, (MeshTopology_Dim)nDims ); n_i++ ) {
+		unsigned	domain;
+		unsigned	curInd;
+		unsigned	owner;
+
+		domain = Mesh_GetLocalSize( self->mesh, (MeshTopology_Dim)nDims ) + n_i;
+		owner = Mesh_GetOwner( self->mesh, (MeshTopology_Dim)nDims, n_i );
+		curInd = self->cellShadowInfo.procShadowCnt[owner]++;
+		self->cellShadowInfo.procShadowTbl[owner][curInd] = domain;
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/FileParticleLayout.c
--- a/Swarm/src/FileParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,610 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: FileParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#ifdef READ_HDF5
-#include <hdf5.h>
-#endif
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "FileParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-#include "IntegrationPoint.h"
-#include "SwarmVariable.h"
-#include "SwarmVariable_Register.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-
-const Type FileParticleLayout_Type = "FileParticleLayout";
-
-FileParticleLayout* FileParticleLayout_New( Name name,
-      AbstractContext* context, 
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles, 
-      double           averageInitialParticlesPerCell, 
-      Name             filename, 
-      Index            checkpointfiles )
-{
-   FileParticleLayout* self = (FileParticleLayout*) _FileParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-   _FileParticleLayout_Init( self, filename, checkpointfiles );
-   self->isConstructed = True;
-
-   return self;
-}
-
-FileParticleLayout* _FileParticleLayout_New(  FILEPARTICLELAYOUT_DEFARGS  )
-{
-   FileParticleLayout* self;
-   
-   /* Allocate memory */
-   assert( _sizeOfSelf >= sizeof( FileParticleLayout ) );
-   self = (FileParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
-
-   /* set default attributes */
-   /* Unsafe */
-   self->filename = (char*)filename;
-   self->checkpointfiles = checkpointfiles;
-
-   return self;
-}
-
-
-void _FileParticleLayout_Init( void* particleLayout, Name filename, Index checkpointfiles )
-{
-   FileParticleLayout* self = (FileParticleLayout*) particleLayout;
-
-   self->filename = StG_Strdup( filename );
-   self->checkpointfiles = checkpointfiles;
-   self->errorStream = Journal_MyStream( Error_Type, self );
-}
-
-
-void _FileParticleLayout_Delete( void* particleLayout ) {
-   FileParticleLayout* self = (FileParticleLayout*)particleLayout;
-
-   /* Stg_Class_Delete parent class */
-   _GlobalParticleLayout_Delete( self );
-}
-
-void _FileParticleLayout_Print( void* particleLayout, Stream* stream ) {
-   FileParticleLayout* self = (FileParticleLayout*)particleLayout;
-   
-   /* General info */
-   Journal_Printf( stream, "FileParticleLayout (ptr): %p:\n", self );
-   Stream_Indent( stream );
-   
-   /* Parent class info */
-   _GlobalParticleLayout_Print( self, stream );
-   
-   /* FileParticleLayout */
-   Journal_Printf( stream, "filename: %s\n", self->filename );
-   
-   Stream_UnIndent( stream );
-}
-
-
-void* _FileParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-   FileParticleLayout*	self = (FileParticleLayout*)particleLayout;
-   FileParticleLayout*	newFileParticleLayout;
-   
-   newFileParticleLayout = (FileParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-   
-   newFileParticleLayout->filename = self->filename;
-
-   return (void*)newFileParticleLayout;
-}
-
-void* _FileParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(FileParticleLayout);
-	Type                                                                        type = FileParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _FileParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _FileParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _FileParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _FileParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _FileParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _FileParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _FileParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _FileParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _FileParticleLayout_Destroy;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _FileParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _FileParticleLayout_InitialiseParticles;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _FileParticleLayout_InitialiseParticle;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	Name                                                                    filename = NULL;
-	Index                                                            checkpointfiles = 0;
-
-   return (void*)_FileParticleLayout_New(  FILEPARTICLELAYOUT_PASSARGS  );/* checkpointfiles_renamed*/
-}
-
-void _FileParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ) {
-   FileParticleLayout* self     = (FileParticleLayout*) particleLayout;
-   Name                filename;
-   Index               checkpointfiles;
-
-   _GlobalParticleLayout_AssignFromXML( self, cf, data );
-
-   filename = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"filename", "Swarm"  );
-   checkpointfiles = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"checkpointfiles", 1  );
-
-#ifdef READ_HDF5
-   /* if doing checkpoint restart, grab number of particles swarmdump previously stored against */
-   if( self->context->loadFromCheckPoint ) checkpointfiles = _FileParticleLayout_GetFileCountFromTimeInfoFile( self->context );
-
-   Journal_Firewall( checkpointfiles > 0, self->errorStream,
-		"Error in %s for %s '%s' - determined number of fileParticleLayout checkpoint files (%d) for reload is not valid.\n",
-		__func__,
-		self->type,
-		self->name,
-		checkpointfiles );
-#endif
-
-   _FileParticleLayout_Init( self, filename, checkpointfiles );
-}
-   
-void _FileParticleLayout_Build( void* particleLayout, void* data ) {
-}
-
-void _FileParticleLayout_Initialise( void* particleLayout, void* data ) {
-}
-
-void _FileParticleLayout_Execute( void* particleLayout, void* data ) {
-}
-
-void _FileParticleLayout_Destroy( void* particleLayout, void* data ) {
-   FileParticleLayout*  self = (FileParticleLayout*)particleLayout;
-   Memory_Free( self->filename );
-
-   _GlobalParticleLayout_Destroy( self, data );
-}
-
-void _FileParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm ) {
-   FileParticleLayout*  self         = (FileParticleLayout*)particleLayout;
-   Swarm*               swarm        = (Swarm*)_swarm;
-   Name                 filename     = self->filename;
-   
-#ifdef READ_HDF5
-   hid_t                file;
-   hid_t                group_id, attrib_id;
-   Index                ii;
-   int                  nParticles;
-   herr_t               status;
-#else
-   MPI_File             mpiFile;
-   int                  openResult;
-   MPI_Offset           bytesCount;
-   SizeT                particleSize = swarm->particleExtensionMgr->finalSize;
-   ldiv_t               division;
-#endif
-
-   Journal_DPrintf( self->debug, "In %s(): for ParticleLayout \"%s\", of type %s\n",
-      __func__, self->name, self->type );
-   Stream_IndentBranch( Swarm_Debug ); 
-
-#ifdef READ_HDF5
-   self->lastParticleIndex  = Memory_Alloc_Array( Index, self->checkpointfiles, "lastParticleIndex" );
-   self->totalInitialParticles = 0;
-   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
-      char* filenameTemp = NULL;
-      /* Open the swarm checkpointing file */
-      if(self->checkpointfiles == 1)
-         Stg_asprintf( &filenameTemp, "%s.h5", filename );
-      else 
-         Stg_asprintf( &filenameTemp, "%s.%dof%d.h5", filename, ii, self->checkpointfiles );
-      
-      file = H5Fopen( filenameTemp, H5F_ACC_RDONLY, H5P_DEFAULT );
-      Journal_Firewall( file >= 0,
-              self->errorStream,
-              "Error in %s for %s '%s' - Cannot open file %s.\n",
-              __func__,
-              self->type,
-              self->name,
-              filenameTemp );
-      
-      /* get the file attributes to determine if this file contains particles */
-      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-         group_id  = H5Gopen(file, "/");
-         attrib_id = H5Aopen_name(group_id, "Swarm Particle Count");
-      #else
-         group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
-         attrib_id = H5Aopen(group_id, "Swarm Particle Count", H5P_DEFAULT);
-      #endif
-       Journal_Firewall( attrib_id > 0,
-              self->errorStream,
-              "\nError in %s for %s '%s' - Swarm Particle Count group not present in checkpoint file %s.\n  Perhaps you are trying to restart from an old checkpoint file.",
-              __func__,
-              self->type,
-              self->name,
-              filenameTemp );
-      status = H5Aread(attrib_id, H5T_NATIVE_INT, &nParticles);
-      H5Aclose(attrib_id);
-      H5Gclose(group_id);
-
-      self->totalInitialParticles += nParticles;
-      self->lastParticleIndex[ii-1] = self->totalInitialParticles;
-      
-      /* Close the dataspace and file */
-      H5Fclose( file );
-      Memory_Free( filenameTemp );
-   }
-#else
-   Journal_DPrintf( self->debug, "Finding number of bytes in checkpoint file \"%s\":\n",
-      self->filename );
-      
-   openResult = MPI_File_open( swarm->comm, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &mpiFile );
-   
-   Journal_Firewall( 
-      openResult == 0, 
-      self->errorStream,
-      "Error in %s for %s '%s' - Cannot open file %s.\n", 
-      __func__, 
-      self->type, 
-      self->name, 
-      filename );
-   
-   MPI_File_get_size( mpiFile, &bytesCount );
-   MPI_File_close( &mpiFile );
-
-   Journal_DPrintf( self->debug, "...calculated bytes total of %u.\n", bytesCount );
-   
-   /* Divide by particle size to get number of particles */
-   division = ldiv( bytesCount, (long) particleSize );
-   self->totalInitialParticles = (unsigned int) division.quot;
-   
-   Journal_DPrintf( self->debug, "given bytes total %u / particle size %u ->\n"
-      "\ttotalInitialParticles = %u.\n", bytesCount, (unsigned int)particleSize,
-      self->totalInitialParticles );
-
-   Journal_Firewall( 
-      division.rem == 0,
-      self->errorStream,
-      "Error in func %s for %s '%s' - Trying to read particle information from %s which stores %u bytes.\n"
-      "This doesn't produce an integer number of particles of size %u - It gives remainder = %u\n", 
-      __func__, 
-      self->type, 
-      self->name, 
-      filename, 
-      bytesCount, 
-      (unsigned int)particleSize, 
-      division.rem ); 
-
-   Journal_DPrintf( self->debug, "calling parent func to set cell counts:\n", bytesCount );
-#endif
-
-   _GlobalParticleLayout_SetInitialCounts( self, swarm );
-
-   Stream_UnIndentBranch( Swarm_Debug );  
-   Journal_DPrintf( self->debug, "...finished %s() for ParticleLayout \"%s\".\n",
-      __func__, self->name );
-}
-
-void _FileParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm ) {
-   FileParticleLayout*    self  = (FileParticleLayout*)particleLayout;
-   Swarm                 *swarm = (Swarm*)_swarm;
-   
-#ifdef READ_HDF5
-   SwarmVariable*         swarmVar;
-   Index                  swarmVar_I;
-   char                   dataSpaceName[1024];
-   hid_t                  file[self->checkpointfiles];
-   Index                  ii, jj, kk;
-   hid_t                  group_id, attrib_id;
-   int                    nParticles;
-   herr_t                 status;
-     
-   /* Allocate space to store arrays of dataspaces */   
-   assert( swarm->swarmVariable_Register );  
-   self->fileData  = Memory_Alloc_2DArray( hid_t, swarm->swarmVariable_Register->objects->count, self->checkpointfiles, (Name)"fileData"  );
-   self->fileSpace = Memory_Alloc_2DArray( hid_t, swarm->swarmVariable_Register->objects->count, self->checkpointfiles, (Name)"fileSpace" );
-   /* set these spaces to null initially */
-   for( jj = 0 ; jj < swarm->swarmVariable_Register->objects->count ; jj++)
-      for( kk = 0 ; kk < self->checkpointfiles ; kk++){
-         self->fileData [jj][kk] = 0;
-         self->fileSpace[jj][kk] = 0;
-      }
-      
-   /* Open the files */
-   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
-      char*  filenameTemp = NULL;
-      /* Open the swarm checkpointing file */
-      if(self->checkpointfiles == 1 )
-         Stg_asprintf( &filenameTemp, "%s.h5", self->filename );
-      else 
-         Stg_asprintf( &filenameTemp, "%s.%dof%d.h5", self->filename, ii, self->checkpointfiles );
-
-      file[ii-1] = H5Fopen( filenameTemp, H5F_ACC_RDONLY, H5P_DEFAULT );
-      Journal_Firewall( 
-            file[ii-1] >= 0, 
-            self->errorStream,
-            "Error in %s for %s '%s' - Cannot open file %s.\n", 
-            __func__, 
-            self->type, 
-            self->name, 
-            self->filename );
-
-      /* get the file attributes to determine if this file contains particles */
-      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-         group_id  = H5Gopen(file[ii-1], "/");
-         attrib_id = H5Aopen_name(group_id, "Swarm Particle Count");
-      #else
-         group_id  = H5Gopen2(file[ii-1], "/", H5P_DEFAULT);
-         attrib_id = H5Aopen(group_id, "Swarm Particle Count", H5P_DEFAULT);
-      #endif
-      status = H5Aread(attrib_id, H5T_NATIVE_INT, &nParticles);
-
-      H5Aclose(attrib_id);
-      H5Gclose(group_id);
-
-      if(nParticles > 0){
-         /* Open a dataspace for each swarmVariable */
-         for( swarmVar_I = 0; swarmVar_I < swarm->swarmVariable_Register->objects->count; swarmVar_I++ ) {
-            swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
-            
-            if( swarmVar->isCheckpointedAndReloaded ) {
-               sprintf( dataSpaceName, "/%s", swarmVar->name + strlen(swarm->name)+1 );
-               
-               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-                  self->fileData[swarmVar_I][ii-1]  = H5Dopen( file[ii-1], dataSpaceName );
-               #else
-                  self->fileData[swarmVar_I][ii-1]  = H5Dopen2( file[ii-1], dataSpaceName, H5P_DEFAULT );
-               #endif
-               /* if we cannot find the specified dataSpace, try again using the old naming convention */
-               if(self->fileData[swarmVar_I][ii-1] < 0){
-                  sprintf( dataSpaceName, "/%s", swarmVar->name );
-                  
-                  #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-                     self->fileData[swarmVar_I][ii-1]  = H5Dopen( file[ii-1], dataSpaceName );
-                  #else
-                     self->fileData[swarmVar_I][ii-1]  = H5Dopen2( file[ii-1], dataSpaceName, H5P_DEFAULT );
-                  #endif
-               }
-               /* if we still cannot find the specified dataSpace, there is a problem */
-               if(self->fileData[swarmVar_I][ii-1] < 0)
-                     Journal_Firewall( 
-                        NULL, 
-                        self->errorStream,
-                        "\n\nError in %s for %s '%s' \n Cannot open dataSpace for checkpointed swarmvariable (%s) that requries reloading.\n  Checkpoint files may be invalid.\n\n", 
-                        __func__, 
-                        self->type, 
-                        self->name,
-                        swarmVar->name );
-
-               
-               self->fileSpace[swarmVar_I][ii-1] = H5Dget_space( self->fileData[swarmVar_I][ii-1] );
-               
-               Variable_Update( swarmVar->variable );
-            }
-         }
-      }
-      Memory_Free( filenameTemp );
-   }
-       
-   self->start[1] = 0;
-   self->count[0] = 1; 
-   
-   _GlobalParticleLayout_InitialiseParticles( self, _swarm );
-
-   /* Close dataspaces and the file */
-   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
-      for( swarmVar_I = 0; swarmVar_I < swarm->swarmVariable_Register->objects->count; swarmVar_I++ ) {
-         swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
-         if( swarmVar->isCheckpointedAndReloaded ) {
-            if ( self->fileSpace[swarmVar_I][ii-1] ) H5Sclose( self->fileSpace[swarmVar_I][ii-1] );
-            if ( self->fileData [swarmVar_I][ii-1] ) H5Dclose( self->fileData [swarmVar_I][ii-1] );
-         }
-      }
-      H5Fclose( file[ii-1] );
-   }
-   
-   Memory_Free( self->fileData );
-   Memory_Free( self->fileSpace );
-   Memory_Free( self->lastParticleIndex );
-   
-#else
-   self->file = fopen( self->filename, "rb" );
-   Journal_Firewall( 
-      self->file != NULL, 
-      self->errorStream,
-      "Error in %s for %s '%s' - Cannot open file %s.\n", 
-      __func__, 
-      self->type, 
-      self->name, 
-      self->filename );
-
-   _GlobalParticleLayout_InitialiseParticles( self, _swarm );
-   
-   fclose( self->file );
-#endif
-}  
-	
-void _FileParticleLayout_InitialiseParticle( 
-	void*              particleLayout, 
-	void*              _swarm, 
-	Particle_Index     newParticle_I,
-	void*              particle )
-{
-   FileParticleLayout*	self = (FileParticleLayout*)particleLayout;
-   Swarm*					swarm = (Swarm*)_swarm;
-   SizeT						particleSize; 
-   int						result;
-
-#ifdef READ_HDF5
-   SwarmVariable*    swarmVar;
-   Index             swarmVar_I;
-   Index             ii;
-   hid_t             memSpace; 
-
-	result = 0;
-	particleSize = 0;
-   /* find out which file particle is contained within */
-   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
-      if( newParticle_I < self->lastParticleIndex[ii-1]) break;
-   }
-   self->start[0] = newParticle_I;
-   if(ii != 1) self->start[0] -= self->lastParticleIndex[ii-2];
-   
-   for( swarmVar_I = 0; swarmVar_I < swarm->nSwarmVars; swarmVar_I++ ) {
-      swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
-      /* only retrieve variable if it does not have a parent, as these
-         are not stored, and the data is retrieved when the parent is. 
-         Also do make sure variable is of type SwarmVariable (as opposed 
-         to materialSwarmVariable, which is not checkpointed). */
-      if( swarmVar->isCheckpointedAndReloaded ) {          
-         /* Update the hyperslab. */   
-         self->count[1] = swarmVar->dofCount;
-         memSpace = H5Screate_simple( 2, self->count, NULL );
-         H5Sselect_hyperslab( self->fileSpace[swarmVar_I][ii-1], H5S_SELECT_SET, self->start, NULL, self->count, NULL );
-         H5Sselect_all( memSpace );
-         
-         /* Treat the data differently depending on its type */
-         if( swarmVar->variable->dataTypes[0] == Variable_DataType_Int ) {
-            int* particleInfo = Memory_Alloc_Array( int, swarmVar->dofCount, "particleCheckpointInfo" );
-            
-            /* Read particle data. */
-            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_INT, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
-            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
-            Memory_Free( particleInfo );
-         }
-        
-         else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Char) {
-            char* particleInfo = Memory_Alloc_Array( char, swarmVar->dofCount, "particleCheckpointInfo" );
-            
-            /* Read particle data. */
-            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_CHAR, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
-            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
-            Memory_Free( particleInfo );
-         }
-            
-         else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ) {
-            float* particleInfo = Memory_Alloc_Array( float, swarmVar->dofCount, "particleCheckpointInfo" );
-            
-            /* Read particle data. */
-            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_FLOAT, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
-            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
-            Memory_Free( particleInfo );
-         }
-            
-         else {
-            double* particleInfo = Memory_Alloc_Array( double, swarmVar->dofCount, "particleCheckpointInfo" );
-            
-            /* Read particle data. */
-            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_DOUBLE, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
-            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
-            Memory_Free( particleInfo );
-         }   
-         H5Sclose( memSpace );
-      }
-   }
-      
-#else
-  	particleSize = swarm->particleExtensionMgr->finalSize;
-	result = fread( particle, particleSize, 1, self->file );
-
-   Journal_Firewall( 
-      result == 1,
-      self->errorStream,
-      "Error in func %s for %s '%s':\n"
-      "\tCouldn't read in particle %u - May have reached end-of-file.\n",
-      __func__, 
-      self->type, 
-      self->name, 
-      newParticle_I );
-#endif
-}
-
-#ifdef READ_HDF5
-Index _FileParticleLayout_GetFileCountFromTimeInfoFile( void* _context ){
-   AbstractContext*     context = (AbstractContext*)_context;
-   char*                timeInfoFileName = NULL;
-   char*                timeInfoFileNamePart = NULL;
-   Stream*              errorStr = Journal_Register( Error_Type, (Name)FileParticleLayout_Type  );
-   hid_t                file, fileSpace, fileData;
-   Index                checkpointnproc;
-   
-   timeInfoFileNamePart = Context_GetCheckPointReadPrefixString( context );
-   Stg_asprintf( &timeInfoFileName, "%stimeInfo.%.5u.h5", timeInfoFileNamePart, context->restartTimestep );
-    
-   /* Open the file and data set. */
-   file = H5Fopen( timeInfoFileName, H5F_ACC_RDONLY, H5P_DEFAULT );
-   Journal_Firewall( 
-      file >= 0, 
-      errorStr, "\n\nError- in %s(), Couldn't find checkpoint time info file with "
-      "filename \"%s\" - aborting.\n", __func__, timeInfoFileName );
-   
-   /* Read previous nproc from file */
-   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-   fileData = H5Dopen( file, "/nproc" );
-   #else
-   fileData = H5Dopen2( file, "/nproc", H5P_DEFAULT );
-   #endif
-   fileSpace = H5Dget_space( fileData );
-      
-   H5Dread( fileData, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &checkpointnproc );
-      
-   H5Sclose( fileSpace );
-   H5Dclose( fileData );
-   
-   H5Fclose( file );
-      
-   Memory_Free( timeInfoFileName );
-   Memory_Free( timeInfoFileNamePart );
-   return checkpointnproc;
-}
-#endif
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/FileParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/FileParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,610 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+** Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+** Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+** Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+** Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+** Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+** Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: FileParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifdef READ_HDF5
+#include <hdf5.h>
+#endif
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "FileParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+#include "IntegrationPoint.h"
+#include "SwarmVariable.h"
+#include "SwarmVariable_Register.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+const Type FileParticleLayout_Type = "FileParticleLayout";
+
+FileParticleLayout* FileParticleLayout_New( Name name,
+      AbstractContext* context, 
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles, 
+      double           averageInitialParticlesPerCell, 
+      Name             filename, 
+      Index            checkpointfiles )
+{
+   FileParticleLayout* self = (FileParticleLayout*) _FileParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+   _FileParticleLayout_Init( self, filename, checkpointfiles );
+   self->isConstructed = True;
+
+   return self;
+}
+
+FileParticleLayout* _FileParticleLayout_New(  FILEPARTICLELAYOUT_DEFARGS  )
+{
+   FileParticleLayout* self;
+   
+   /* Allocate memory */
+   assert( _sizeOfSelf >= sizeof( FileParticleLayout ) );
+   self = (FileParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
+
+   /* set default attributes */
+   /* Unsafe */
+   self->filename = (char*)filename;
+   self->checkpointfiles = checkpointfiles;
+
+   return self;
+}
+
+
+void _FileParticleLayout_Init( void* particleLayout, Name filename, Index checkpointfiles )
+{
+   FileParticleLayout* self = (FileParticleLayout*) particleLayout;
+
+   self->filename = StG_Strdup( filename );
+   self->checkpointfiles = checkpointfiles;
+   self->errorStream = Journal_MyStream( Error_Type, self );
+}
+
+
+void _FileParticleLayout_Delete( void* particleLayout ) {
+   FileParticleLayout* self = (FileParticleLayout*)particleLayout;
+
+   /* Stg_Class_Delete parent class */
+   _GlobalParticleLayout_Delete( self );
+}
+
+void _FileParticleLayout_Print( void* particleLayout, Stream* stream ) {
+   FileParticleLayout* self = (FileParticleLayout*)particleLayout;
+   
+   /* General info */
+   Journal_Printf( stream, "FileParticleLayout (ptr): %p:\n", self );
+   Stream_Indent( stream );
+   
+   /* Parent class info */
+   _GlobalParticleLayout_Print( self, stream );
+   
+   /* FileParticleLayout */
+   Journal_Printf( stream, "filename: %s\n", self->filename );
+   
+   Stream_UnIndent( stream );
+}
+
+
+void* _FileParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+   FileParticleLayout*	self = (FileParticleLayout*)particleLayout;
+   FileParticleLayout*	newFileParticleLayout;
+   
+   newFileParticleLayout = (FileParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+   
+   newFileParticleLayout->filename = self->filename;
+
+   return (void*)newFileParticleLayout;
+}
+
+void* _FileParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(FileParticleLayout);
+	Type                                                                        type = FileParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _FileParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _FileParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _FileParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _FileParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _FileParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _FileParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _FileParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _FileParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _FileParticleLayout_Destroy;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _FileParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _FileParticleLayout_InitialiseParticles;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _FileParticleLayout_InitialiseParticle;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	Name                                                                    filename = NULL;
+	Index                                                            checkpointfiles = 0;
+
+   return (void*)_FileParticleLayout_New(  FILEPARTICLELAYOUT_PASSARGS  );/* checkpointfiles_renamed*/
+}
+
+void _FileParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ) {
+   FileParticleLayout* self     = (FileParticleLayout*) particleLayout;
+   Name                filename;
+   Index               checkpointfiles;
+
+   _GlobalParticleLayout_AssignFromXML( self, cf, data );
+
+   filename = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"filename", "Swarm"  );
+   checkpointfiles = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"checkpointfiles", 1  );
+
+#ifdef READ_HDF5
+   /* if doing checkpoint restart, grab number of particles swarmdump previously stored against */
+   if( self->context->loadFromCheckPoint ) checkpointfiles = _FileParticleLayout_GetFileCountFromTimeInfoFile( self->context );
+
+   Journal_Firewall( checkpointfiles > 0, self->errorStream,
+		"Error in %s for %s '%s' - determined number of fileParticleLayout checkpoint files (%d) for reload is not valid.\n",
+		__func__,
+		self->type,
+		self->name,
+		checkpointfiles );
+#endif
+
+   _FileParticleLayout_Init( self, filename, checkpointfiles );
+}
+   
+void _FileParticleLayout_Build( void* particleLayout, void* data ) {
+}
+
+void _FileParticleLayout_Initialise( void* particleLayout, void* data ) {
+}
+
+void _FileParticleLayout_Execute( void* particleLayout, void* data ) {
+}
+
+void _FileParticleLayout_Destroy( void* particleLayout, void* data ) {
+   FileParticleLayout*  self = (FileParticleLayout*)particleLayout;
+   Memory_Free( self->filename );
+
+   _GlobalParticleLayout_Destroy( self, data );
+}
+
+void _FileParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm ) {
+   FileParticleLayout*  self         = (FileParticleLayout*)particleLayout;
+   Swarm*               swarm        = (Swarm*)_swarm;
+   Name                 filename     = self->filename;
+   
+#ifdef READ_HDF5
+   hid_t                file;
+   hid_t                group_id, attrib_id;
+   Index                ii;
+   int                  nParticles;
+   herr_t               status;
+#else
+   MPI_File             mpiFile;
+   int                  openResult;
+   MPI_Offset           bytesCount;
+   SizeT                particleSize = swarm->particleExtensionMgr->finalSize;
+   ldiv_t               division;
+#endif
+
+   Journal_DPrintf( self->debug, "In %s(): for ParticleLayout \"%s\", of type %s\n",
+      __func__, self->name, self->type );
+   Stream_IndentBranch( Swarm_Debug ); 
+
+#ifdef READ_HDF5
+   self->lastParticleIndex  = Memory_Alloc_Array( Index, self->checkpointfiles, "lastParticleIndex" );
+   self->totalInitialParticles = 0;
+   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
+      char* filenameTemp = NULL;
+      /* Open the swarm checkpointing file */
+      if(self->checkpointfiles == 1)
+         Stg_asprintf( &filenameTemp, "%s.h5", filename );
+      else 
+         Stg_asprintf( &filenameTemp, "%s.%dof%d.h5", filename, ii, self->checkpointfiles );
+      
+      file = H5Fopen( filenameTemp, H5F_ACC_RDONLY, H5P_DEFAULT );
+      Journal_Firewall( file >= 0,
+              self->errorStream,
+              "Error in %s for %s '%s' - Cannot open file %s.\n",
+              __func__,
+              self->type,
+              self->name,
+              filenameTemp );
+      
+      /* get the file attributes to determine if this file contains particles */
+      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+         group_id  = H5Gopen(file, "/");
+         attrib_id = H5Aopen_name(group_id, "Swarm Particle Count");
+      #else
+         group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
+         attrib_id = H5Aopen(group_id, "Swarm Particle Count", H5P_DEFAULT);
+      #endif
+       Journal_Firewall( attrib_id > 0,
+              self->errorStream,
+              "\nError in %s for %s '%s' - Swarm Particle Count group not present in checkpoint file %s.\n  Perhaps you are trying to restart from an old checkpoint file.",
+              __func__,
+              self->type,
+              self->name,
+              filenameTemp );
+      status = H5Aread(attrib_id, H5T_NATIVE_INT, &nParticles);
+      H5Aclose(attrib_id);
+      H5Gclose(group_id);
+
+      self->totalInitialParticles += nParticles;
+      self->lastParticleIndex[ii-1] = self->totalInitialParticles;
+      
+      /* Close the dataspace and file */
+      H5Fclose( file );
+      Memory_Free( filenameTemp );
+   }
+#else
+   Journal_DPrintf( self->debug, "Finding number of bytes in checkpoint file \"%s\":\n",
+      self->filename );
+      
+   openResult = MPI_File_open( swarm->comm, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &mpiFile );
+   
+   Journal_Firewall( 
+      openResult == 0, 
+      self->errorStream,
+      "Error in %s for %s '%s' - Cannot open file %s.\n", 
+      __func__, 
+      self->type, 
+      self->name, 
+      filename );
+   
+   MPI_File_get_size( mpiFile, &bytesCount );
+   MPI_File_close( &mpiFile );
+
+   Journal_DPrintf( self->debug, "...calculated bytes total of %u.\n", bytesCount );
+   
+   /* Divide by particle size to get number of particles */
+   division = ldiv( bytesCount, (long) particleSize );
+   self->totalInitialParticles = (unsigned int) division.quot;
+   
+   Journal_DPrintf( self->debug, "given bytes total %u / particle size %u ->\n"
+      "\ttotalInitialParticles = %u.\n", bytesCount, (unsigned int)particleSize,
+      self->totalInitialParticles );
+
+   Journal_Firewall( 
+      division.rem == 0,
+      self->errorStream,
+      "Error in func %s for %s '%s' - Trying to read particle information from %s which stores %u bytes.\n"
+      "This doesn't produce an integer number of particles of size %u - It gives remainder = %u\n", 
+      __func__, 
+      self->type, 
+      self->name, 
+      filename, 
+      bytesCount, 
+      (unsigned int)particleSize, 
+      division.rem ); 
+
+   Journal_DPrintf( self->debug, "calling parent func to set cell counts:\n", bytesCount );
+#endif
+
+   _GlobalParticleLayout_SetInitialCounts( self, swarm );
+
+   Stream_UnIndentBranch( Swarm_Debug );  
+   Journal_DPrintf( self->debug, "...finished %s() for ParticleLayout \"%s\".\n",
+      __func__, self->name );
+}
+
+void _FileParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm ) {
+   FileParticleLayout*    self  = (FileParticleLayout*)particleLayout;
+   Swarm                 *swarm = (Swarm*)_swarm;
+   
+#ifdef READ_HDF5
+   SwarmVariable*         swarmVar;
+   Index                  swarmVar_I;
+   char                   dataSpaceName[1024];
+   hid_t                  file[self->checkpointfiles];
+   Index                  ii, jj, kk;
+   hid_t                  group_id, attrib_id;
+   int                    nParticles;
+   herr_t                 status;
+     
+   /* Allocate space to store arrays of dataspaces */   
+   assert( swarm->swarmVariable_Register );  
+   self->fileData  = Memory_Alloc_2DArray( hid_t, swarm->swarmVariable_Register->objects->count, self->checkpointfiles, (Name)"fileData"  );
+   self->fileSpace = Memory_Alloc_2DArray( hid_t, swarm->swarmVariable_Register->objects->count, self->checkpointfiles, (Name)"fileSpace" );
+   /* set these spaces to null initially */
+   for( jj = 0 ; jj < swarm->swarmVariable_Register->objects->count ; jj++)
+      for( kk = 0 ; kk < self->checkpointfiles ; kk++){
+         self->fileData [jj][kk] = 0;
+         self->fileSpace[jj][kk] = 0;
+      }
+      
+   /* Open the files */
+   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
+      char*  filenameTemp = NULL;
+      /* Open the swarm checkpointing file */
+      if(self->checkpointfiles == 1 )
+         Stg_asprintf( &filenameTemp, "%s.h5", self->filename );
+      else 
+         Stg_asprintf( &filenameTemp, "%s.%dof%d.h5", self->filename, ii, self->checkpointfiles );
+
+      file[ii-1] = H5Fopen( filenameTemp, H5F_ACC_RDONLY, H5P_DEFAULT );
+      Journal_Firewall( 
+            file[ii-1] >= 0, 
+            self->errorStream,
+            "Error in %s for %s '%s' - Cannot open file %s.\n", 
+            __func__, 
+            self->type, 
+            self->name, 
+            self->filename );
+
+      /* get the file attributes to determine if this file contains particles */
+      #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+         group_id  = H5Gopen(file[ii-1], "/");
+         attrib_id = H5Aopen_name(group_id, "Swarm Particle Count");
+      #else
+         group_id  = H5Gopen2(file[ii-1], "/", H5P_DEFAULT);
+         attrib_id = H5Aopen(group_id, "Swarm Particle Count", H5P_DEFAULT);
+      #endif
+      status = H5Aread(attrib_id, H5T_NATIVE_INT, &nParticles);
+
+      H5Aclose(attrib_id);
+      H5Gclose(group_id);
+
+      if(nParticles > 0){
+         /* Open a dataspace for each swarmVariable */
+         for( swarmVar_I = 0; swarmVar_I < swarm->swarmVariable_Register->objects->count; swarmVar_I++ ) {
+            swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
+            
+            if( swarmVar->isCheckpointedAndReloaded ) {
+               sprintf( dataSpaceName, "/%s", swarmVar->name + strlen(swarm->name)+1 );
+               
+               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+                  self->fileData[swarmVar_I][ii-1]  = H5Dopen( file[ii-1], dataSpaceName );
+               #else
+                  self->fileData[swarmVar_I][ii-1]  = H5Dopen2( file[ii-1], dataSpaceName, H5P_DEFAULT );
+               #endif
+               /* if we cannot find the specified dataSpace, try again using the old naming convention */
+               if(self->fileData[swarmVar_I][ii-1] < 0){
+                  sprintf( dataSpaceName, "/%s", swarmVar->name );
+                  
+                  #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+                     self->fileData[swarmVar_I][ii-1]  = H5Dopen( file[ii-1], dataSpaceName );
+                  #else
+                     self->fileData[swarmVar_I][ii-1]  = H5Dopen2( file[ii-1], dataSpaceName, H5P_DEFAULT );
+                  #endif
+               }
+               /* if we still cannot find the specified dataSpace, there is a problem */
+               if(self->fileData[swarmVar_I][ii-1] < 0)
+                     Journal_Firewall( 
+                        NULL, 
+                        self->errorStream,
+                        "\n\nError in %s for %s '%s' \n Cannot open dataSpace for checkpointed swarmvariable (%s) that requries reloading.\n  Checkpoint files may be invalid.\n\n", 
+                        __func__, 
+                        self->type, 
+                        self->name,
+                        swarmVar->name );
+
+               
+               self->fileSpace[swarmVar_I][ii-1] = H5Dget_space( self->fileData[swarmVar_I][ii-1] );
+               
+               Variable_Update( swarmVar->variable );
+            }
+         }
+      }
+      Memory_Free( filenameTemp );
+   }
+       
+   self->start[1] = 0;
+   self->count[0] = 1; 
+   
+   _GlobalParticleLayout_InitialiseParticles( self, _swarm );
+
+   /* Close dataspaces and the file */
+   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
+      for( swarmVar_I = 0; swarmVar_I < swarm->swarmVariable_Register->objects->count; swarmVar_I++ ) {
+         swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
+         if( swarmVar->isCheckpointedAndReloaded ) {
+            if ( self->fileSpace[swarmVar_I][ii-1] ) H5Sclose( self->fileSpace[swarmVar_I][ii-1] );
+            if ( self->fileData [swarmVar_I][ii-1] ) H5Dclose( self->fileData [swarmVar_I][ii-1] );
+         }
+      }
+      H5Fclose( file[ii-1] );
+   }
+   
+   Memory_Free( self->fileData );
+   Memory_Free( self->fileSpace );
+   Memory_Free( self->lastParticleIndex );
+   
+#else
+   self->file = fopen( self->filename, "rb" );
+   Journal_Firewall( 
+      self->file != NULL, 
+      self->errorStream,
+      "Error in %s for %s '%s' - Cannot open file %s.\n", 
+      __func__, 
+      self->type, 
+      self->name, 
+      self->filename );
+
+   _GlobalParticleLayout_InitialiseParticles( self, _swarm );
+   
+   fclose( self->file );
+#endif
+}  
+	
+void _FileParticleLayout_InitialiseParticle( 
+	void*              particleLayout, 
+	void*              _swarm, 
+	Particle_Index     newParticle_I,
+	void*              particle )
+{
+   FileParticleLayout*	self = (FileParticleLayout*)particleLayout;
+   Swarm*					swarm = (Swarm*)_swarm;
+   SizeT						particleSize; 
+   int						result;
+
+#ifdef READ_HDF5
+   SwarmVariable*    swarmVar;
+   Index             swarmVar_I;
+   Index             ii;
+   hid_t             memSpace; 
+
+	result = 0;
+	particleSize = 0;
+   /* find out which file particle is contained within */
+   for( ii = 1 ; ii <= self->checkpointfiles ; ii++ ){
+      if( newParticle_I < self->lastParticleIndex[ii-1]) break;
+   }
+   self->start[0] = newParticle_I;
+   if(ii != 1) self->start[0] -= self->lastParticleIndex[ii-2];
+   
+   for( swarmVar_I = 0; swarmVar_I < swarm->nSwarmVars; swarmVar_I++ ) {
+      swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
+      /* only retrieve variable if it does not have a parent, as these
+         are not stored, and the data is retrieved when the parent is. 
+         Also do make sure variable is of type SwarmVariable (as opposed 
+         to materialSwarmVariable, which is not checkpointed). */
+      if( swarmVar->isCheckpointedAndReloaded ) {          
+         /* Update the hyperslab. */   
+         self->count[1] = swarmVar->dofCount;
+         memSpace = H5Screate_simple( 2, self->count, NULL );
+         H5Sselect_hyperslab( self->fileSpace[swarmVar_I][ii-1], H5S_SELECT_SET, self->start, NULL, self->count, NULL );
+         H5Sselect_all( memSpace );
+         
+         /* Treat the data differently depending on its type */
+         if( swarmVar->variable->dataTypes[0] == Variable_DataType_Int ) {
+            int* particleInfo = Memory_Alloc_Array( int, swarmVar->dofCount, "particleCheckpointInfo" );
+            
+            /* Read particle data. */
+            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_INT, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
+            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
+            Memory_Free( particleInfo );
+         }
+        
+         else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Char) {
+            char* particleInfo = Memory_Alloc_Array( char, swarmVar->dofCount, "particleCheckpointInfo" );
+            
+            /* Read particle data. */
+            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_CHAR, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
+            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
+            Memory_Free( particleInfo );
+         }
+            
+         else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ) {
+            float* particleInfo = Memory_Alloc_Array( float, swarmVar->dofCount, "particleCheckpointInfo" );
+            
+            /* Read particle data. */
+            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_FLOAT, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
+            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
+            Memory_Free( particleInfo );
+         }
+            
+         else {
+            double* particleInfo = Memory_Alloc_Array( double, swarmVar->dofCount, "particleCheckpointInfo" );
+            
+            /* Read particle data. */
+            H5Dread( self->fileData[swarmVar_I][ii-1], H5T_NATIVE_DOUBLE, memSpace, self->fileSpace[swarmVar_I][ii-1], H5P_DEFAULT, particleInfo );
+            Variable_SetValue( swarmVar->variable, swarm->particleLocalCount, particleInfo );
+            Memory_Free( particleInfo );
+         }   
+         H5Sclose( memSpace );
+      }
+   }
+      
+#else
+  	particleSize = swarm->particleExtensionMgr->finalSize;
+	result = fread( particle, particleSize, 1, self->file );
+
+   Journal_Firewall( 
+      result == 1,
+      self->errorStream,
+      "Error in func %s for %s '%s':\n"
+      "\tCouldn't read in particle %u - May have reached end-of-file.\n",
+      __func__, 
+      self->type, 
+      self->name, 
+      newParticle_I );
+#endif
+}
+
+#ifdef READ_HDF5
+Index _FileParticleLayout_GetFileCountFromTimeInfoFile( void* _context ){
+   AbstractContext*     context = (AbstractContext*)_context;
+   char*                timeInfoFileName = NULL;
+   char*                timeInfoFileNamePart = NULL;
+   Stream*              errorStr = Journal_Register( Error_Type, (Name)FileParticleLayout_Type  );
+   hid_t                file, fileSpace, fileData;
+   Index                checkpointnproc;
+   
+   timeInfoFileNamePart = Context_GetCheckPointReadPrefixString( context );
+   Stg_asprintf( &timeInfoFileName, "%stimeInfo.%.5u.h5", timeInfoFileNamePart, context->restartTimestep );
+    
+   /* Open the file and data set. */
+   file = H5Fopen( timeInfoFileName, H5F_ACC_RDONLY, H5P_DEFAULT );
+   Journal_Firewall( 
+      file >= 0, 
+      errorStr, "\n\nError- in %s(), Couldn't find checkpoint time info file with "
+      "filename \"%s\" - aborting.\n", __func__, timeInfoFileName );
+   
+   /* Read previous nproc from file */
+   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+   fileData = H5Dopen( file, "/nproc" );
+   #else
+   fileData = H5Dopen2( file, "/nproc", H5P_DEFAULT );
+   #endif
+   fileSpace = H5Dget_space( fileData );
+      
+   H5Dread( fileData, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &checkpointnproc );
+      
+   H5Sclose( fileSpace );
+   H5Dclose( fileData );
+   
+   H5Fclose( file );
+      
+   Memory_Free( timeInfoFileName );
+   Memory_Free( timeInfoFileNamePart );
+   return checkpointnproc;
+}
+#endif
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Finalise.c
--- a/Swarm/src/Finalise.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Finalise.c 3592 2006-05-18 05:42:04Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Finalise.h"
-
-#include "Swarm_Register.h"
-
-
-#include <stdio.h>
-
-Bool StgDomainSwarm_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	Stg_Class_Delete( stgSwarm_Register );
-
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/Finalise.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,54 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Finalise.c 3592 2006-05-18 05:42:04Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Finalise.h"
+
+#include "Swarm_Register.h"
+
+
+#include <stdio.h>
+
+Bool StgDomainSwarm_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	Stg_Class_Delete( stgSwarm_Register );
+
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/GaussBorderParticleLayout.c
--- a/Swarm/src/GaussBorderParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,370 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: GaussParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "PerCellParticleLayout.h"
-#include "GaussParticleLayout.h"
-#include "GaussBorderParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "IntegrationPoint.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-
-const Type GaussBorderParticleLayout_Type = "GaussBorderParticleLayout";
-
-GaussBorderParticleLayout* GaussBorderParticleLayout_New( 
-   Name name,
-   AbstractContext* context,
-   CoordSystem      coordSystem,
-   Bool             weightsInitialisedAtStartup,
-   Dimension_Index dim, 
-   Particle_InCellIndex* particlesPerDim ) {
-
-  GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)_GaussBorderParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _PerCellParticleLayout_Init( self );
-   _GaussParticleLayout_Init( self, dim, particlesPerDim );
-	_GaussBorderParticleLayout_Init( self );
-
-	return self;
-}
-
-GaussBorderParticleLayout* _GaussBorderParticleLayout_New(  GAUSSBORDERPARTICLELAYOUT_DEFARGS  )
-{
-	GaussBorderParticleLayout* self;
-	
-	/* Allocate memory */
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	dim             = 0;
-	particlesPerDim = NULL;
-
-	self = (GaussBorderParticleLayout*)_GaussParticleLayout_New(  GAUSSPARTICLELAYOUT_PASSARGS  );
-
-	
-	return self;
-}
-
-
-void _GaussBorderParticleLayout_Init( void* gaussBorderParticleLayout ) {
-	GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-
-	self->particlesPerFace = Memory_Alloc_Array_Unnamed( Particle_InCellIndex, 6); // up to 6 faces (3d case)
-	_GaussBorderParticleLayout_InitialiseParticlesPerFace( self );
-}
-
-void _GaussBorderParticleLayout_Delete( void* gaussBorderParticleLayout ) {
-	GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-	
-	_GaussParticleLayout_Delete( self );
-}
-
-void _GaussBorderParticleLayout_Print( void* gaussBorderParticleLayout, Stream* stream ) {
-	GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "GaussBorderParticleLayout (ptr): %p:\n", self );
-	
-	/* Parent class info */
-	_GaussParticleLayout_Print( self, stream );
-	
-	/* Virtual info */
-	
-	/* GaussBorderParticleLayout */
-	Stream_Indent( stream );
-	Journal_PrintValue( stream, self->dim );
-	Journal_PrintArray( stream, self->particlesPerDim, self->dim );
-	Journal_PrintArray( stream, self->particlesPerFace, ( (self->dim == 3) ? 6 : 4 ) );
-	Stream_UnIndent( stream );
-}
-
-
-void* _GaussBorderParticleLayout_Copy( const void* gaussBorderParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	GaussBorderParticleLayout*	self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-	GaussBorderParticleLayout*	newGaussBorderParticleLayout;
-	
-	newGaussBorderParticleLayout = (GaussBorderParticleLayout*)_GaussParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newGaussBorderParticleLayout->dim = self->dim;
-	memcpy( newGaussBorderParticleLayout->particlesPerDim, self->particlesPerDim, 3 * sizeof(unsigned int) );
-	
-	memcpy( newGaussBorderParticleLayout->particlesPerFace, self->particlesPerFace, 6 * sizeof(Particle_InCellIndex) );
-
-	return (void*)newGaussBorderParticleLayout;
-}
-
-void* _GaussBorderParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                     _sizeOfSelf = sizeof(GaussBorderParticleLayout);
-	Type                                                                             type = GaussBorderParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                     _delete = _GaussBorderParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                       _print = _GaussBorderParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                         _copy = _GaussBorderParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _GaussBorderParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                           _construct = _GaussBorderParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                                   _build = _GaussBorderParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                         _initialise = _GaussBorderParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                               _execute = _GaussBorderParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                               _destroy = _GaussBorderParticleLayout_Destroy;
-	AllocationType                                                     nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
-	CoordSystem                                                               coordSystem = LocalCoordSystem;
-	Bool                                                      weightsInitialisedAtStartup = True;
-	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _GaussBorderParticleLayout_InitialCount;
-	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _GaussBorderParticleLayout_InitialiseParticlesOfCell;
-	Dimension_Index                                                                   dim = 0;
-	Particle_InCellIndex*                                                 particlesPerDim = NULL;
-
-	return (GaussBorderParticleLayout*)_GaussBorderParticleLayout_New(  GAUSSBORDERPARTICLELAYOUT_PASSARGS  );
-}
-
-void _GaussBorderParticleLayout_AssignFromXML( void* gaussBorderParticleLayout, Stg_ComponentFactory* cf, void* data ) {
-	GaussBorderParticleLayout*   self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-
-   _GaussParticleLayout_AssignFromXML( self, cf, data );
-
-	_GaussBorderParticleLayout_Init( self );
-}
-	
-void _GaussBorderParticleLayout_Build( void* gaussBorderParticleLayout, void* data ) {
-   GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-   _GaussParticleLayout_Build( self, data );
-}
-	
-void _GaussBorderParticleLayout_Initialise( void* gaussBorderParticleLayout, void* data ) {
-   GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-   _GaussParticleLayout_Initialise( self, data );
-}
-	
-void _GaussBorderParticleLayout_Execute( void* gaussBorderParticleLayout, void* data ) {
-}
-
-void _GaussBorderParticleLayout_Destroy( void* gaussBorderParticleLayout, void* data ) {
-   GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-
-   Memory_Free( self->particlesPerFace );
-   _GaussParticleLayout_Destroy( self, data );
-}
-
-Particle_InCellIndex _GaussBorderParticleLayout_InitialCount( void* gaussBorderParticleLayout, void* celllayout, Cell_Index cell_I )
-{
-	GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-	Particle_InCellIndex count = 0;
-	Index numFaces = (self->dim == 3) ? 6 : 4;
-	Index face_I;
-
-	for( face_I = 0; face_I < numFaces; face_I++ ){
-		count += self->particlesPerFace[ face_I ];
-	}
-
-	return count;
-}
-
-
-#define TRIPLE_MAX( A, B, C )  MAX( MAX( (A), (B) ), (C) )
-
-
-/* remember this only has to initialise one particle at a time */
-void _GaussBorderParticleLayout_InitialiseParticlesOfCell( void* gaussBorderParticleLayout, void* _swarm, Cell_Index cell_I )
-{
-	GaussBorderParticleLayout*      self                = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-	Swarm*                    swarm               = (Swarm*)_swarm;
-	IntegrationPoint*         particle            = NULL;
-	Particle_InCellIndex      maxParticlesPerDim;
-	IJK                       ijkIndex;
-	Index                     index;
-	Dimension_Index           dim_I;
-	div_t                     divide;
-	double*                   weights;
-	double*                   abscissa;
-	Coord                     min;
-	Coord                     max;
-	Particle_InCellIndex      particlesThisCell = swarm->cellParticleCountTbl[cell_I];
-	Particle_InCellIndex      cParticle_I = 0;
-	Index			  face_I;
-	Particle_InCellIndex	  particle_I_ThisFace;
-
-	if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
-		/* TODO: This is a special rule allowing a Gauss particle layout to be used to initialise
-		global co-ords if you want to use it in a material swarm */
-		self->coordSystem = GlobalCoordSystem;
-	}
-
-	Swarm_GetCellMinMaxCoords( _swarm, cell_I, min, max );
-
-	/* Allocate Memory */
-	maxParticlesPerDim = TRIPLE_MAX( self->particlesPerDim[ I_AXIS ],
-		self->particlesPerDim[ J_AXIS ], self->particlesPerDim[ K_AXIS ] );
-
-	weights   = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss weights" );
-	abscissa  = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss abscissa" );
-
-	face_I = 0;
-	particle_I_ThisFace = 0;
-	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {
-		particle = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		particle->owningCell = cell_I;
-
-		/* Find which face (side) this particle lives on */
-		/* easier to keep track of the face thruout the loop than go and recalculate it each time, I think*/
-		if( particle_I_ThisFace == self->particlesPerFace[ face_I ] ) {
-			face_I++;
-			particle_I_ThisFace = 0;
-		}
-		
-		/* Find the i, j, k index of this particular particle */
-		// we're now looking at something with one less dimension than the cell, so we'll just ignore the K_AXIS
-		divide = div( particle_I_ThisFace, self->particlesPerDim[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, I_AXIS) ] );
-		
-		if( self->dim == 3 ) {
-			ijkIndex[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, J_AXIS) ] = divide.quot;
-		}
-
-		ijkIndex[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, I_AXIS) ] = divide.rem;
-
-		particle->weight = 1.0;
-			
-		for( dim_I = 0 ; dim_I <  (self->dim - 1) ; dim_I++ ) {
-			index = ijkIndex[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ];
-			GaussParticleLayout_GetAbscissaAndWeights1D( weights, abscissa, self->particlesPerDim[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] );
-
-			/* Assign particle stuff */
-			/* TODO: this is a hack, since this class doesn't officially know that the MaterialPointsSwarm
-			 * exists yet. However, we need some way for material swarms to use this layout, for testing
-			 * purposes. In the simple system of only 1 swarm type, this component always initialised
-			 * both local and global co-ords.
-			 * -- PatrickSunter - 1 May 2006
-			 */
-			// this is a slightly different version of the Gauss layout, so I'm assuming this bit still applies
-			// (and I've modified it to work with this layout)
-			if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
-				((GlobalParticle*)particle)->coord[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] = 
-                                  min[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] +
-					0.5 * ( max[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] 
-					- min[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] ) 
-					* ( abscissa[ index ] + 1.0 );
-			}
-			else {
-				particle->xi[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] = abscissa[ index ];
-				particle->weight *= weights[ index ];
-			}	
-		}
-		// assign the coordinate that's constant on this face. the %2 thing is just a convention I picked for labelling faces:
-		// even faces have a constant coord of -1, odd faces have +1 (so left is even with x=-1, right is odd with x=1, etc)
-		particle->xi[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, K_AXIS) ] = (face_I % 2 == 0) ? -1 : 1;
-		// currently assuming a cube, -1,-1,-1 to 1,1,1, just as the Gauss layout does.
-
-		particle_I_ThisFace++;
-	}	
-
-	Memory_Free( weights );
-	Memory_Free( abscissa );
-}
-
-
-/*
-  for a cuboids/square element, each face (or side) is essentially a 2d square (or 1d straight line); but which plane it's in varies from face to face.
-  the next function is just a means of encoding that: so face 1 (in a 3d cell) is in the i-k plane
-  thus we can treat it as a 2d face with 'i-axis' in the i direction and 'j-axis' in the *k* direction
-  for the sake of generality, we treat all faces as having an I_AXIS and J_AXIS; this function maps the axis and face no to
-  the 'real' axis that it corresponds to
-  the 'K-AXIS' is the axis that is 'constant' for this face. It's also the direction of the normal vector for the face (side)
-  the 'J-AXIS' in the 2d case isn't used
-
-  in other words, the function allows me to map from a general boundary section to a specific one ( and vice-versa ), which allows the code
-  above to be generalised and not consist of a largish switch-case statement.
-*/
-Dimension_Index GaussBorderParticleLayout_GetFaceAxis( void* gaussBorderParticleLayout, Index face_I, Dimension_Index axis) {
-	GaussBorderParticleLayout*	self;
-	Dimension_Index				faceAxes3D[6][3];
-
-	self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-
-	faceAxes3D[0][ I_AXIS ] = I_AXIS; faceAxes3D[0][ J_AXIS ] = K_AXIS; faceAxes3D[0][ K_AXIS ] = J_AXIS;
-	faceAxes3D[1][ I_AXIS ] = I_AXIS; faceAxes3D[1][ J_AXIS ] = K_AXIS; faceAxes3D[1][ K_AXIS ] = J_AXIS;
-	faceAxes3D[2][ I_AXIS ] = J_AXIS; faceAxes3D[2][ J_AXIS ] = K_AXIS; faceAxes3D[2][ K_AXIS ] = I_AXIS;
-	faceAxes3D[3][ I_AXIS ] = J_AXIS; faceAxes3D[3][ J_AXIS ] = K_AXIS; faceAxes3D[3][ K_AXIS ] = I_AXIS;
-	faceAxes3D[4][ I_AXIS ] = I_AXIS; faceAxes3D[4][ J_AXIS ] = J_AXIS; faceAxes3D[4][ K_AXIS ] = K_AXIS;
-	faceAxes3D[5][ I_AXIS ] = I_AXIS; faceAxes3D[5][ J_AXIS ] = J_AXIS; faceAxes3D[5][ K_AXIS ] = K_AXIS;
-
-	return faceAxes3D[face_I][axis];
-}
-
-Index GaussBorderParticleLayout_ParticleInCellIndexToFaceIndex( void* gaussBorderParticleLayout, Particle_InCellIndex cParticle_I) {
-	GaussBorderParticleLayout*	self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
-	Index								face_I;
-	Index								numfaces = (self->dim == 3) ? 6 : 4;
-	int								cParticle_I_signed = (int) cParticle_I;
-
-	for( face_I = 0; face_I < numfaces; face_I++ ) {
-		cParticle_I_signed -= self->particlesPerFace[ face_I ];
-		if(cParticle_I_signed < 0)	/* ParticleInCellIndex is unsigned int - which generally isn't <0...hence the signed int. */
-			break;
-	}
-
-	return face_I;
-}
-
-void _GaussBorderParticleLayout_InitialiseParticlesPerFace( GaussBorderParticleLayout* self )
-{
-	Index face_I;
-	Index numFaces = (self->dim == 3) ? 6 : 4;
-	Dimension_Index dim_I;
-
-	/* find no of particles for each face. */
-	for( face_I = 0; face_I < numFaces; face_I++ ) {
-		self->particlesPerFace[ face_I ] = 1;
-		for( dim_I = 0; dim_I < self->dim - 1; dim_I++ ){
-			self->particlesPerFace[ face_I ] *= self->particlesPerDim[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ];
-		}
-	}
-
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/GaussBorderParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/GaussBorderParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,370 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: GaussParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "PerCellParticleLayout.h"
+#include "GaussParticleLayout.h"
+#include "GaussBorderParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "IntegrationPoint.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+
+const Type GaussBorderParticleLayout_Type = "GaussBorderParticleLayout";
+
+GaussBorderParticleLayout* GaussBorderParticleLayout_New( 
+   Name name,
+   AbstractContext* context,
+   CoordSystem      coordSystem,
+   Bool             weightsInitialisedAtStartup,
+   Dimension_Index dim, 
+   Particle_InCellIndex* particlesPerDim ) {
+
+  GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)_GaussBorderParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _PerCellParticleLayout_Init( self );
+   _GaussParticleLayout_Init( self, dim, particlesPerDim );
+	_GaussBorderParticleLayout_Init( self );
+
+	return self;
+}
+
+GaussBorderParticleLayout* _GaussBorderParticleLayout_New(  GAUSSBORDERPARTICLELAYOUT_DEFARGS  )
+{
+	GaussBorderParticleLayout* self;
+	
+	/* Allocate memory */
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	dim             = 0;
+	particlesPerDim = NULL;
+
+	self = (GaussBorderParticleLayout*)_GaussParticleLayout_New(  GAUSSPARTICLELAYOUT_PASSARGS  );
+
+	
+	return self;
+}
+
+
+void _GaussBorderParticleLayout_Init( void* gaussBorderParticleLayout ) {
+	GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+
+	self->particlesPerFace = Memory_Alloc_Array_Unnamed( Particle_InCellIndex, 6); // up to 6 faces (3d case)
+	_GaussBorderParticleLayout_InitialiseParticlesPerFace( self );
+}
+
+void _GaussBorderParticleLayout_Delete( void* gaussBorderParticleLayout ) {
+	GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+	
+	_GaussParticleLayout_Delete( self );
+}
+
+void _GaussBorderParticleLayout_Print( void* gaussBorderParticleLayout, Stream* stream ) {
+	GaussBorderParticleLayout* self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "GaussBorderParticleLayout (ptr): %p:\n", self );
+	
+	/* Parent class info */
+	_GaussParticleLayout_Print( self, stream );
+	
+	/* Virtual info */
+	
+	/* GaussBorderParticleLayout */
+	Stream_Indent( stream );
+	Journal_PrintValue( stream, self->dim );
+	Journal_PrintArray( stream, self->particlesPerDim, self->dim );
+	Journal_PrintArray( stream, self->particlesPerFace, ( (self->dim == 3) ? 6 : 4 ) );
+	Stream_UnIndent( stream );
+}
+
+
+void* _GaussBorderParticleLayout_Copy( const void* gaussBorderParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	GaussBorderParticleLayout*	self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+	GaussBorderParticleLayout*	newGaussBorderParticleLayout;
+	
+	newGaussBorderParticleLayout = (GaussBorderParticleLayout*)_GaussParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newGaussBorderParticleLayout->dim = self->dim;
+	memcpy( newGaussBorderParticleLayout->particlesPerDim, self->particlesPerDim, 3 * sizeof(unsigned int) );
+	
+	memcpy( newGaussBorderParticleLayout->particlesPerFace, self->particlesPerFace, 6 * sizeof(Particle_InCellIndex) );
+
+	return (void*)newGaussBorderParticleLayout;
+}
+
+void* _GaussBorderParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                     _sizeOfSelf = sizeof(GaussBorderParticleLayout);
+	Type                                                                             type = GaussBorderParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                     _delete = _GaussBorderParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                       _print = _GaussBorderParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                         _copy = _GaussBorderParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _GaussBorderParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                           _construct = _GaussBorderParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                                   _build = _GaussBorderParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                         _initialise = _GaussBorderParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                               _execute = _GaussBorderParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                               _destroy = _GaussBorderParticleLayout_Destroy;
+	AllocationType                                                     nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
+	CoordSystem                                                               coordSystem = LocalCoordSystem;
+	Bool                                                      weightsInitialisedAtStartup = True;
+	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _GaussBorderParticleLayout_InitialCount;
+	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _GaussBorderParticleLayout_InitialiseParticlesOfCell;
+	Dimension_Index                                                                   dim = 0;
+	Particle_InCellIndex*                                                 particlesPerDim = NULL;
+
+	return (GaussBorderParticleLayout*)_GaussBorderParticleLayout_New(  GAUSSBORDERPARTICLELAYOUT_PASSARGS  );
+}
+
+void _GaussBorderParticleLayout_AssignFromXML( void* gaussBorderParticleLayout, Stg_ComponentFactory* cf, void* data ) {
+	GaussBorderParticleLayout*   self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+
+   _GaussParticleLayout_AssignFromXML( self, cf, data );
+
+	_GaussBorderParticleLayout_Init( self );
+}
+	
+void _GaussBorderParticleLayout_Build( void* gaussBorderParticleLayout, void* data ) {
+   GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+   _GaussParticleLayout_Build( self, data );
+}
+	
+void _GaussBorderParticleLayout_Initialise( void* gaussBorderParticleLayout, void* data ) {
+   GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+   _GaussParticleLayout_Initialise( self, data );
+}
+	
+void _GaussBorderParticleLayout_Execute( void* gaussBorderParticleLayout, void* data ) {
+}
+
+void _GaussBorderParticleLayout_Destroy( void* gaussBorderParticleLayout, void* data ) {
+   GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+
+   Memory_Free( self->particlesPerFace );
+   _GaussParticleLayout_Destroy( self, data );
+}
+
+Particle_InCellIndex _GaussBorderParticleLayout_InitialCount( void* gaussBorderParticleLayout, void* celllayout, Cell_Index cell_I )
+{
+	GaussBorderParticleLayout* self   = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+	Particle_InCellIndex count = 0;
+	Index numFaces = (self->dim == 3) ? 6 : 4;
+	Index face_I;
+
+	for( face_I = 0; face_I < numFaces; face_I++ ){
+		count += self->particlesPerFace[ face_I ];
+	}
+
+	return count;
+}
+
+
+#define TRIPLE_MAX( A, B, C )  MAX( MAX( (A), (B) ), (C) )
+
+
+/* remember this only has to initialise one particle at a time */
+void _GaussBorderParticleLayout_InitialiseParticlesOfCell( void* gaussBorderParticleLayout, void* _swarm, Cell_Index cell_I )
+{
+	GaussBorderParticleLayout*      self                = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+	Swarm*                    swarm               = (Swarm*)_swarm;
+	IntegrationPoint*         particle            = NULL;
+	Particle_InCellIndex      maxParticlesPerDim;
+	IJK                       ijkIndex;
+	Index                     index;
+	Dimension_Index           dim_I;
+	div_t                     divide;
+	double*                   weights;
+	double*                   abscissa;
+	Coord                     min;
+	Coord                     max;
+	Particle_InCellIndex      particlesThisCell = swarm->cellParticleCountTbl[cell_I];
+	Particle_InCellIndex      cParticle_I = 0;
+	Index			  face_I;
+	Particle_InCellIndex	  particle_I_ThisFace;
+
+	if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
+		/* TODO: This is a special rule allowing a Gauss particle layout to be used to initialise
+		global co-ords if you want to use it in a material swarm */
+		self->coordSystem = GlobalCoordSystem;
+	}
+
+	Swarm_GetCellMinMaxCoords( _swarm, cell_I, min, max );
+
+	/* Allocate Memory */
+	maxParticlesPerDim = TRIPLE_MAX( self->particlesPerDim[ I_AXIS ],
+		self->particlesPerDim[ J_AXIS ], self->particlesPerDim[ K_AXIS ] );
+
+	weights   = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss weights" );
+	abscissa  = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss abscissa" );
+
+	face_I = 0;
+	particle_I_ThisFace = 0;
+	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {
+		particle = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		particle->owningCell = cell_I;
+
+		/* Find which face (side) this particle lives on */
+		/* easier to keep track of the face thruout the loop than go and recalculate it each time, I think*/
+		if( particle_I_ThisFace == self->particlesPerFace[ face_I ] ) {
+			face_I++;
+			particle_I_ThisFace = 0;
+		}
+		
+		/* Find the i, j, k index of this particular particle */
+		// we're now looking at something with one less dimension than the cell, so we'll just ignore the K_AXIS
+		divide = div( particle_I_ThisFace, self->particlesPerDim[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, I_AXIS) ] );
+		
+		if( self->dim == 3 ) {
+			ijkIndex[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, J_AXIS) ] = divide.quot;
+		}
+
+		ijkIndex[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, I_AXIS) ] = divide.rem;
+
+		particle->weight = 1.0;
+			
+		for( dim_I = 0 ; dim_I <  (self->dim - 1) ; dim_I++ ) {
+			index = ijkIndex[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ];
+			GaussParticleLayout_GetAbscissaAndWeights1D( weights, abscissa, self->particlesPerDim[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] );
+
+			/* Assign particle stuff */
+			/* TODO: this is a hack, since this class doesn't officially know that the MaterialPointsSwarm
+			 * exists yet. However, we need some way for material swarms to use this layout, for testing
+			 * purposes. In the simple system of only 1 swarm type, this component always initialised
+			 * both local and global co-ords.
+			 * -- PatrickSunter - 1 May 2006
+			 */
+			// this is a slightly different version of the Gauss layout, so I'm assuming this bit still applies
+			// (and I've modified it to work with this layout)
+			if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
+				((GlobalParticle*)particle)->coord[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] = 
+                                  min[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] +
+					0.5 * ( max[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] 
+					- min[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] ) 
+					* ( abscissa[ index ] + 1.0 );
+			}
+			else {
+				particle->xi[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ] = abscissa[ index ];
+				particle->weight *= weights[ index ];
+			}	
+		}
+		// assign the coordinate that's constant on this face. the %2 thing is just a convention I picked for labelling faces:
+		// even faces have a constant coord of -1, odd faces have +1 (so left is even with x=-1, right is odd with x=1, etc)
+		particle->xi[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, K_AXIS) ] = (face_I % 2 == 0) ? -1 : 1;
+		// currently assuming a cube, -1,-1,-1 to 1,1,1, just as the Gauss layout does.
+
+		particle_I_ThisFace++;
+	}	
+
+	Memory_Free( weights );
+	Memory_Free( abscissa );
+}
+
+
+/*
+  for a cuboids/square element, each face (or side) is essentially a 2d square (or 1d straight line); but which plane it's in varies from face to face.
+  the next function is just a means of encoding that: so face 1 (in a 3d cell) is in the i-k plane
+  thus we can treat it as a 2d face with 'i-axis' in the i direction and 'j-axis' in the *k* direction
+  for the sake of generality, we treat all faces as having an I_AXIS and J_AXIS; this function maps the axis and face no to
+  the 'real' axis that it corresponds to
+  the 'K-AXIS' is the axis that is 'constant' for this face. It's also the direction of the normal vector for the face (side)
+  the 'J-AXIS' in the 2d case isn't used
+
+  in other words, the function allows me to map from a general boundary section to a specific one ( and vice-versa ), which allows the code
+  above to be generalised and not consist of a largish switch-case statement.
+*/
+Dimension_Index GaussBorderParticleLayout_GetFaceAxis( void* gaussBorderParticleLayout, Index face_I, Dimension_Index axis) {
+	GaussBorderParticleLayout*	self;
+	Dimension_Index				faceAxes3D[6][3];
+
+	self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+
+	faceAxes3D[0][ I_AXIS ] = I_AXIS; faceAxes3D[0][ J_AXIS ] = K_AXIS; faceAxes3D[0][ K_AXIS ] = J_AXIS;
+	faceAxes3D[1][ I_AXIS ] = I_AXIS; faceAxes3D[1][ J_AXIS ] = K_AXIS; faceAxes3D[1][ K_AXIS ] = J_AXIS;
+	faceAxes3D[2][ I_AXIS ] = J_AXIS; faceAxes3D[2][ J_AXIS ] = K_AXIS; faceAxes3D[2][ K_AXIS ] = I_AXIS;
+	faceAxes3D[3][ I_AXIS ] = J_AXIS; faceAxes3D[3][ J_AXIS ] = K_AXIS; faceAxes3D[3][ K_AXIS ] = I_AXIS;
+	faceAxes3D[4][ I_AXIS ] = I_AXIS; faceAxes3D[4][ J_AXIS ] = J_AXIS; faceAxes3D[4][ K_AXIS ] = K_AXIS;
+	faceAxes3D[5][ I_AXIS ] = I_AXIS; faceAxes3D[5][ J_AXIS ] = J_AXIS; faceAxes3D[5][ K_AXIS ] = K_AXIS;
+
+	return faceAxes3D[face_I][axis];
+}
+
+Index GaussBorderParticleLayout_ParticleInCellIndexToFaceIndex( void* gaussBorderParticleLayout, Particle_InCellIndex cParticle_I) {
+	GaussBorderParticleLayout*	self = (GaussBorderParticleLayout*)gaussBorderParticleLayout;
+	Index								face_I;
+	Index								numfaces = (self->dim == 3) ? 6 : 4;
+	int								cParticle_I_signed = (int) cParticle_I;
+
+	for( face_I = 0; face_I < numfaces; face_I++ ) {
+		cParticle_I_signed -= self->particlesPerFace[ face_I ];
+		if(cParticle_I_signed < 0)	/* ParticleInCellIndex is unsigned int - which generally isn't <0...hence the signed int. */
+			break;
+	}
+
+	return face_I;
+}
+
+void _GaussBorderParticleLayout_InitialiseParticlesPerFace( GaussBorderParticleLayout* self )
+{
+	Index face_I;
+	Index numFaces = (self->dim == 3) ? 6 : 4;
+	Dimension_Index dim_I;
+
+	/* find no of particles for each face. */
+	for( face_I = 0; face_I < numFaces; face_I++ ) {
+		self->particlesPerFace[ face_I ] = 1;
+		for( dim_I = 0; dim_I < self->dim - 1; dim_I++ ){
+			self->particlesPerFace[ face_I ] *= self->particlesPerDim[ GaussBorderParticleLayout_GetFaceAxis(self, face_I, dim_I) ];
+		}
+	}
+
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/GaussParticleLayout.c
--- a/Swarm/src/GaussParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,355 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: GaussParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "PerCellParticleLayout.h"
-#include "GaussParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "IntegrationPoint.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-
-const Type GaussParticleLayout_Type = "GaussParticleLayout";
-
-GaussParticleLayout* GaussParticleLayout_New( 
-   Name name, 
-   AbstractContext* context,
-   CoordSystem      coordSystem,
-   Bool             weightsInitialisedAtStartup,
-   Dimension_Index dim, 
-   Particle_InCellIndex* particlesPerDim ) {
-
-  GaussParticleLayout* self = (GaussParticleLayout*)_GaussParticleLayout_DefaultNew( name );
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _PerCellParticleLayout_Init( self );
-   _GaussParticleLayout_Init( self, dim, particlesPerDim );
-
-   return self;
-}
-
-GaussParticleLayout* _GaussParticleLayout_New(  GAUSSPARTICLELAYOUT_DEFARGS  )
-{
-	GaussParticleLayout* self;
-	
-   /* hard-wire these */
-   coordSystem = LocalCoordSystem;
-   weightsInitialisedAtStartup = True;
-   nameAllocationType = NON_GLOBAL;
-
-	/* Allocate memory */
-	self = (GaussParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
-
-   self->dim = dim;
-   if( particlesPerDim )
-     memcpy( self->particlesPerDim, particlesPerDim, 3 * sizeof(Particle_InCellIndex) );
-	
-	return self;
-}
-
-void _GaussParticleLayout_Init( void* gaussParticleLayout, Dimension_Index dim, Particle_InCellIndex* particlesPerDim ) {
-   GaussParticleLayout* self = (GaussParticleLayout*)gaussParticleLayout;
-
-   self->isConstructed       = True;
-   self->coordSystem         = LocalCoordSystem;
-   self->weightsInitialisedAtStartup = True;
-   self->dim                 = dim;
-   memcpy( self->particlesPerDim, particlesPerDim, 3 * sizeof(Particle_InCellIndex) );
-}
-
-void _GaussParticleLayout_Delete( void* gaussParticleLayout ) {
-	GaussParticleLayout* self = (GaussParticleLayout*)gaussParticleLayout;
-	
-	_PerCellParticleLayout_Delete( self );
-}
-
-void _GaussParticleLayout_Print( void* gaussParticleLayout, Stream* stream ) {
-	GaussParticleLayout* self = (GaussParticleLayout*)gaussParticleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "GaussParticleLayout (ptr): %p:\n", self );
-	
-	/* Parent class info */
-	_PerCellParticleLayout_Print( self, stream );
-	
-	/* Virtual info */
-	
-	/* GaussParticleLayout */
-	Stream_Indent( stream );
-	Journal_PrintValue( stream, self->dim );
-	Journal_PrintArray( stream, self->particlesPerDim, self->dim );
-	Stream_UnIndent( stream );
-}
-
-
-void* _GaussParticleLayout_Copy( const void* gaussParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	GaussParticleLayout*	self = (GaussParticleLayout*)gaussParticleLayout;
-	GaussParticleLayout*	newGaussParticleLayout;
-	
-	newGaussParticleLayout = (GaussParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newGaussParticleLayout->dim = self->dim;
-	memcpy( newGaussParticleLayout->particlesPerDim, self->particlesPerDim, 3 * sizeof(unsigned int) );
-
-	return (void*)newGaussParticleLayout;
-}
-
-void* _GaussParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                     _sizeOfSelf = sizeof(GaussParticleLayout);
-	Type                                                                             type = GaussParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                     _delete = _GaussParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                       _print = _GaussParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                         _copy = _GaussParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _GaussParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                           _construct = _GaussParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                                   _build = _GaussParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                         _initialise = _GaussParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                               _execute = _GaussParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                               _destroy = _GaussParticleLayout_Destroy;
-	AllocationType                                                     nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
-	CoordSystem                                                               coordSystem = LocalCoordSystem;
-	Bool                                                      weightsInitialisedAtStartup = True;
-	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _GaussParticleLayout_InitialCount;
-	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _GaussParticleLayout_InitialiseParticlesOfCell;
-	Dimension_Index                                                                   dim = 0;
-	Particle_InCellIndex*                                                 particlesPerDim = NULL;
-
-	return (GaussParticleLayout*)_GaussParticleLayout_New(  GAUSSPARTICLELAYOUT_PASSARGS  );
-}
-
-void _GaussParticleLayout_AssignFromXML( void* gaussParticleLayout, Stg_ComponentFactory* cf, void* data ) {
-	GaussParticleLayout*   self = (GaussParticleLayout*)gaussParticleLayout;
-	Particle_InCellIndex   particlesPerDim[3];
-	Particle_InCellIndex   defaultVal;
-	Dimension_Index        dim;
-
-   _PerCellParticleLayout_AssignFromXML( self, cf, data );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-	defaultVal = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticles", 2  );
-
-	particlesPerDim[ I_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticlesX", defaultVal  );
-	particlesPerDim[ J_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticlesY", defaultVal );
-	if ( dim == 3  )
-		particlesPerDim[ K_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticlesZ", defaultVal  );
-	else
-		particlesPerDim[ K_AXIS ] = 1;	
-
-	_GaussParticleLayout_Init( self, dim, particlesPerDim );
-}
-	
-void _GaussParticleLayout_Build( void* gaussParticleLayout, void* data ) {
-}
-	
-void _GaussParticleLayout_Initialise( void* gaussParticleLayout, void* data ) {
-}
-	
-void _GaussParticleLayout_Execute( void* gaussParticleLayout, void* data ) {
-}
-
-void _GaussParticleLayout_Destroy( void* gaussParticleLayout, void* data ) {
-}
-
-Particle_InCellIndex _GaussParticleLayout_InitialCount( void* gaussParticleLayout, void* celllayout, Cell_Index cell_I )
-{
-	GaussParticleLayout* self   = (GaussParticleLayout*)gaussParticleLayout;
-	Particle_InCellIndex count;
-	Dimension_Index      dim;	
-	Dimension_Index      dim_I;
-	
-	dim = self->dim;
-	count = 1;
-	for( dim_I = 0; dim_I < dim; dim_I++ ) {
-		count = count * (Particle_InCellIndex)( self->particlesPerDim[ dim_I ] );
-	}
-	
-	return count;
-	
-}
-
-#define TRIPLE_MAX( A, B, C )  MAX( MAX( (A), (B) ), (C) )
-
-/* remember this only has to initialise one particle at a time */
-void _GaussParticleLayout_InitialiseParticlesOfCell( void* gaussParticleLayout, void* _swarm, Cell_Index cell_I )
-{
-	GaussParticleLayout*      self                = (GaussParticleLayout*)gaussParticleLayout;
-	Swarm*                    swarm               = (Swarm*)_swarm;
-	IntegrationPoint*         particle            = NULL;
-	Index                     index2D;
-	Particle_InCellIndex      maxParticlesPerDim;
-	IJK                       ijkIndex;
-	Index                     index;
-	Dimension_Index           dim_I;
-	div_t                     divide;
-	double*                   weights;
-	double*                   abscissa;
-	Coord                     min;
-	Coord                     max;
-	Particle_InCellIndex      particlesThisCell = swarm->cellParticleCountTbl[cell_I];
-	Particle_InCellIndex      cParticle_I = 0;
-	
-
-	if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
-		/* TODO: This is a special rule allowing a Gauss particle layout to be used to initialise
-		global co-ords if you want to use it in a material swarm */
-		self->coordSystem = GlobalCoordSystem;
-	}
-
-	Swarm_GetCellMinMaxCoords( _swarm, cell_I, min, max );
-
-	/* Allocate Memory */
-	maxParticlesPerDim = TRIPLE_MAX( self->particlesPerDim[ I_AXIS ],
-		self->particlesPerDim[ J_AXIS ], self->particlesPerDim[ K_AXIS ] );
-
-	weights   = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss weights" );
-	abscissa  = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss abscissa" );
-
-	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {
-		particle = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		particle->owningCell = cell_I;
-		
-		/* Find the i, j, k index of this particular particle */
-		divide = div( cParticle_I, self->particlesPerDim[ I_AXIS ] * self->particlesPerDim[ J_AXIS ] );
-		ijkIndex[ K_AXIS ] = divide.quot;
-		index2D = divide.rem;
-
-		divide = div( index2D, self->particlesPerDim[ I_AXIS ] );
-		ijkIndex[ J_AXIS ] = divide.quot;
-		ijkIndex[ I_AXIS ] = divide.rem;
-
-		particle->weight = 1.0;
-		for( dim_I = 0 ; dim_I < self->dim ; dim_I++ ) {
-			index = ijkIndex[ dim_I ];
-			GaussParticleLayout_GetAbscissaAndWeights1D( weights, abscissa, self->particlesPerDim[ dim_I ] );
-
-			/* Assign particle stuff */
-			/* TODO: this is a hack, since this class doesn't officially know that the MaterialPointsSwarm
-			 * exists yet. However, we need some way for material swarms to use this layout, for testing
-			 * purposes. In the simple system of only 1 swarm type, this component always initialised
-			 * both local and global co-ords.
-			 * -- PatrickSunter - 1 May 2006
-			 */
-			if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
-				((GlobalParticle*)particle)->coord[ dim_I ] = 
-					min[ dim_I ] +
-						0.5 * ( max[ dim_I ] - min[ dim_I ] ) 
-						* ( abscissa[ index ] + 1.0 );
-			}
-			else {
-				particle->xi[ dim_I ] = abscissa[ index ];
-				particle->weight *= weights[ index ];
-			}	
-		}
-		
-	}	
-
-	Memory_Free( weights );
-	Memory_Free( abscissa );
-}
-
-
-/* Values taken from table from:
- * Eric W. Weisstein. "Legendre-Gauss Quadrature." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Legendre-GaussQuadrature.html */
-void GaussParticleLayout_GetAbscissaAndWeights1D( double* weight, double* abscissa, Index pointCount ) {
-	switch ( pointCount ) {
-		case 1:
-			abscissa[0]  = 0.0;
-			weight[0] = 2.0;
-			break;
-		case 2:
-			abscissa[0]  = - 1.0/sqrt(3.0);
-			abscissa[1]  = - abscissa[0];
-		
-			weight[0] = 1.0;
-			weight[1] = weight[0];
-			break;
-		case 3:
-			abscissa[0]  = - sqrt(15.0)/5.0;
-			abscissa[1]  = 0.0;
-			abscissa[2]  = - abscissa[0];
-		
-			weight[0] = 5.0/9.0;
-			weight[1] = 8.0/9.0;
-			weight[2] = weight[0];
-			break;
-		case 4:
-			abscissa[0]  = - sqrt( 525.0 + 70.0 * sqrt(30.0) )/35.0;
-			abscissa[1]  = - sqrt( 525.0 - 70.0 * sqrt(30.0) )/35.0;
-			abscissa[2]  = - abscissa[1];
-			abscissa[3]  = - abscissa[0];
-			
-			weight[0] = (18.0 - sqrt(30.0))/36.0;
-			weight[1] = (18.0 + sqrt(30.0))/36.0;
-			weight[2] = weight[1];
-			weight[3] = weight[0];
-			break;
-		case 5:
-			abscissa[0]  = - sqrt( 245.0 + 14.0 * sqrt( 70.0 ) )/21.0;
-			abscissa[1]  = - sqrt( 245.0 - 14.0 * sqrt( 70.0 ) )/21.0;
-			abscissa[2]  = 0.0;
-			abscissa[3]  = - abscissa[1];
-			abscissa[4]  = - abscissa[0];
-
-			weight[0] = ( 322.0 - 13.0 * sqrt( 70.0 ) )/900.0;
-			weight[1] = ( 322.0 + 13.0 * sqrt( 70.0 ) )/900.0;
-			weight[2] = 128.0/225.0;
-			weight[3] = weight[1];
-			weight[4] = weight[0];
-			break;
-		default:
-			Journal_Firewall( 
-				pointCount <= 5, 
-				Journal_Register( Error_Type, (Name)GaussParticleLayout_Type  ),
-				"In func %s: Cannot give values for '%u' gauss points\n.", 
-				__func__, 
-				pointCount );
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/GaussParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/GaussParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,355 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: GaussParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "PerCellParticleLayout.h"
+#include "GaussParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "IntegrationPoint.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+
+const Type GaussParticleLayout_Type = "GaussParticleLayout";
+
+GaussParticleLayout* GaussParticleLayout_New( 
+   Name name, 
+   AbstractContext* context,
+   CoordSystem      coordSystem,
+   Bool             weightsInitialisedAtStartup,
+   Dimension_Index dim, 
+   Particle_InCellIndex* particlesPerDim ) {
+
+  GaussParticleLayout* self = (GaussParticleLayout*)_GaussParticleLayout_DefaultNew( name );
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _PerCellParticleLayout_Init( self );
+   _GaussParticleLayout_Init( self, dim, particlesPerDim );
+
+   return self;
+}
+
+GaussParticleLayout* _GaussParticleLayout_New(  GAUSSPARTICLELAYOUT_DEFARGS  )
+{
+	GaussParticleLayout* self;
+	
+   /* hard-wire these */
+   coordSystem = LocalCoordSystem;
+   weightsInitialisedAtStartup = True;
+   nameAllocationType = NON_GLOBAL;
+
+	/* Allocate memory */
+	self = (GaussParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
+
+   self->dim = dim;
+   if( particlesPerDim )
+     memcpy( self->particlesPerDim, particlesPerDim, 3 * sizeof(Particle_InCellIndex) );
+	
+	return self;
+}
+
+void _GaussParticleLayout_Init( void* gaussParticleLayout, Dimension_Index dim, Particle_InCellIndex* particlesPerDim ) {
+   GaussParticleLayout* self = (GaussParticleLayout*)gaussParticleLayout;
+
+   self->isConstructed       = True;
+   self->coordSystem         = LocalCoordSystem;
+   self->weightsInitialisedAtStartup = True;
+   self->dim                 = dim;
+   memcpy( self->particlesPerDim, particlesPerDim, 3 * sizeof(Particle_InCellIndex) );
+}
+
+void _GaussParticleLayout_Delete( void* gaussParticleLayout ) {
+	GaussParticleLayout* self = (GaussParticleLayout*)gaussParticleLayout;
+	
+	_PerCellParticleLayout_Delete( self );
+}
+
+void _GaussParticleLayout_Print( void* gaussParticleLayout, Stream* stream ) {
+	GaussParticleLayout* self = (GaussParticleLayout*)gaussParticleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "GaussParticleLayout (ptr): %p:\n", self );
+	
+	/* Parent class info */
+	_PerCellParticleLayout_Print( self, stream );
+	
+	/* Virtual info */
+	
+	/* GaussParticleLayout */
+	Stream_Indent( stream );
+	Journal_PrintValue( stream, self->dim );
+	Journal_PrintArray( stream, self->particlesPerDim, self->dim );
+	Stream_UnIndent( stream );
+}
+
+
+void* _GaussParticleLayout_Copy( const void* gaussParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	GaussParticleLayout*	self = (GaussParticleLayout*)gaussParticleLayout;
+	GaussParticleLayout*	newGaussParticleLayout;
+	
+	newGaussParticleLayout = (GaussParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newGaussParticleLayout->dim = self->dim;
+	memcpy( newGaussParticleLayout->particlesPerDim, self->particlesPerDim, 3 * sizeof(unsigned int) );
+
+	return (void*)newGaussParticleLayout;
+}
+
+void* _GaussParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                     _sizeOfSelf = sizeof(GaussParticleLayout);
+	Type                                                                             type = GaussParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                     _delete = _GaussParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                       _print = _GaussParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                         _copy = _GaussParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _GaussParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                           _construct = _GaussParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                                   _build = _GaussParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                         _initialise = _GaussParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                               _execute = _GaussParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                               _destroy = _GaussParticleLayout_Destroy;
+	AllocationType                                                     nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
+	CoordSystem                                                               coordSystem = LocalCoordSystem;
+	Bool                                                      weightsInitialisedAtStartup = True;
+	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _GaussParticleLayout_InitialCount;
+	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _GaussParticleLayout_InitialiseParticlesOfCell;
+	Dimension_Index                                                                   dim = 0;
+	Particle_InCellIndex*                                                 particlesPerDim = NULL;
+
+	return (GaussParticleLayout*)_GaussParticleLayout_New(  GAUSSPARTICLELAYOUT_PASSARGS  );
+}
+
+void _GaussParticleLayout_AssignFromXML( void* gaussParticleLayout, Stg_ComponentFactory* cf, void* data ) {
+	GaussParticleLayout*   self = (GaussParticleLayout*)gaussParticleLayout;
+	Particle_InCellIndex   particlesPerDim[3];
+	Particle_InCellIndex   defaultVal;
+	Dimension_Index        dim;
+
+   _PerCellParticleLayout_AssignFromXML( self, cf, data );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+	defaultVal = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticles", 2  );
+
+	particlesPerDim[ I_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticlesX", defaultVal  );
+	particlesPerDim[ J_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticlesY", defaultVal );
+	if ( dim == 3  )
+		particlesPerDim[ K_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"gaussParticlesZ", defaultVal  );
+	else
+		particlesPerDim[ K_AXIS ] = 1;	
+
+	_GaussParticleLayout_Init( self, dim, particlesPerDim );
+}
+	
+void _GaussParticleLayout_Build( void* gaussParticleLayout, void* data ) {
+}
+	
+void _GaussParticleLayout_Initialise( void* gaussParticleLayout, void* data ) {
+}
+	
+void _GaussParticleLayout_Execute( void* gaussParticleLayout, void* data ) {
+}
+
+void _GaussParticleLayout_Destroy( void* gaussParticleLayout, void* data ) {
+}
+
+Particle_InCellIndex _GaussParticleLayout_InitialCount( void* gaussParticleLayout, void* celllayout, Cell_Index cell_I )
+{
+	GaussParticleLayout* self   = (GaussParticleLayout*)gaussParticleLayout;
+	Particle_InCellIndex count;
+	Dimension_Index      dim;	
+	Dimension_Index      dim_I;
+	
+	dim = self->dim;
+	count = 1;
+	for( dim_I = 0; dim_I < dim; dim_I++ ) {
+		count = count * (Particle_InCellIndex)( self->particlesPerDim[ dim_I ] );
+	}
+	
+	return count;
+	
+}
+
+#define TRIPLE_MAX( A, B, C )  MAX( MAX( (A), (B) ), (C) )
+
+/* remember this only has to initialise one particle at a time */
+void _GaussParticleLayout_InitialiseParticlesOfCell( void* gaussParticleLayout, void* _swarm, Cell_Index cell_I )
+{
+	GaussParticleLayout*      self                = (GaussParticleLayout*)gaussParticleLayout;
+	Swarm*                    swarm               = (Swarm*)_swarm;
+	IntegrationPoint*         particle            = NULL;
+	Index                     index2D;
+	Particle_InCellIndex      maxParticlesPerDim;
+	IJK                       ijkIndex;
+	Index                     index;
+	Dimension_Index           dim_I;
+	div_t                     divide;
+	double*                   weights;
+	double*                   abscissa;
+	Coord                     min;
+	Coord                     max;
+	Particle_InCellIndex      particlesThisCell = swarm->cellParticleCountTbl[cell_I];
+	Particle_InCellIndex      cParticle_I = 0;
+	
+
+	if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
+		/* TODO: This is a special rule allowing a Gauss particle layout to be used to initialise
+		global co-ords if you want to use it in a material swarm */
+		self->coordSystem = GlobalCoordSystem;
+	}
+
+	Swarm_GetCellMinMaxCoords( _swarm, cell_I, min, max );
+
+	/* Allocate Memory */
+	maxParticlesPerDim = TRIPLE_MAX( self->particlesPerDim[ I_AXIS ],
+		self->particlesPerDim[ J_AXIS ], self->particlesPerDim[ K_AXIS ] );
+
+	weights   = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss weights" );
+	abscissa  = Memory_Alloc_Array( double, maxParticlesPerDim, "gauss abscissa" );
+
+	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {
+		particle = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		particle->owningCell = cell_I;
+		
+		/* Find the i, j, k index of this particular particle */
+		divide = div( cParticle_I, self->particlesPerDim[ I_AXIS ] * self->particlesPerDim[ J_AXIS ] );
+		ijkIndex[ K_AXIS ] = divide.quot;
+		index2D = divide.rem;
+
+		divide = div( index2D, self->particlesPerDim[ I_AXIS ] );
+		ijkIndex[ J_AXIS ] = divide.quot;
+		ijkIndex[ I_AXIS ] = divide.rem;
+
+		particle->weight = 1.0;
+		for( dim_I = 0 ; dim_I < self->dim ; dim_I++ ) {
+			index = ijkIndex[ dim_I ];
+			GaussParticleLayout_GetAbscissaAndWeights1D( weights, abscissa, self->particlesPerDim[ dim_I ] );
+
+			/* Assign particle stuff */
+			/* TODO: this is a hack, since this class doesn't officially know that the MaterialPointsSwarm
+			 * exists yet. However, we need some way for material swarms to use this layout, for testing
+			 * purposes. In the simple system of only 1 swarm type, this component always initialised
+			 * both local and global co-ords.
+			 * -- PatrickSunter - 1 May 2006
+			 */
+			if ( 0 == strcmp( swarm->type, "MaterialPointsSwarm" ) ) {
+				((GlobalParticle*)particle)->coord[ dim_I ] = 
+					min[ dim_I ] +
+						0.5 * ( max[ dim_I ] - min[ dim_I ] ) 
+						* ( abscissa[ index ] + 1.0 );
+			}
+			else {
+				particle->xi[ dim_I ] = abscissa[ index ];
+				particle->weight *= weights[ index ];
+			}	
+		}
+		
+	}	
+
+	Memory_Free( weights );
+	Memory_Free( abscissa );
+}
+
+
+/* Values taken from table from:
+ * Eric W. Weisstein. "Legendre-Gauss Quadrature." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Legendre-GaussQuadrature.html */
+void GaussParticleLayout_GetAbscissaAndWeights1D( double* weight, double* abscissa, Index pointCount ) {
+	switch ( pointCount ) {
+		case 1:
+			abscissa[0]  = 0.0;
+			weight[0] = 2.0;
+			break;
+		case 2:
+			abscissa[0]  = - 1.0/sqrt(3.0);
+			abscissa[1]  = - abscissa[0];
+		
+			weight[0] = 1.0;
+			weight[1] = weight[0];
+			break;
+		case 3:
+			abscissa[0]  = - sqrt(15.0)/5.0;
+			abscissa[1]  = 0.0;
+			abscissa[2]  = - abscissa[0];
+		
+			weight[0] = 5.0/9.0;
+			weight[1] = 8.0/9.0;
+			weight[2] = weight[0];
+			break;
+		case 4:
+			abscissa[0]  = - sqrt( 525.0 + 70.0 * sqrt(30.0) )/35.0;
+			abscissa[1]  = - sqrt( 525.0 - 70.0 * sqrt(30.0) )/35.0;
+			abscissa[2]  = - abscissa[1];
+			abscissa[3]  = - abscissa[0];
+			
+			weight[0] = (18.0 - sqrt(30.0))/36.0;
+			weight[1] = (18.0 + sqrt(30.0))/36.0;
+			weight[2] = weight[1];
+			weight[3] = weight[0];
+			break;
+		case 5:
+			abscissa[0]  = - sqrt( 245.0 + 14.0 * sqrt( 70.0 ) )/21.0;
+			abscissa[1]  = - sqrt( 245.0 - 14.0 * sqrt( 70.0 ) )/21.0;
+			abscissa[2]  = 0.0;
+			abscissa[3]  = - abscissa[1];
+			abscissa[4]  = - abscissa[0];
+
+			weight[0] = ( 322.0 - 13.0 * sqrt( 70.0 ) )/900.0;
+			weight[1] = ( 322.0 + 13.0 * sqrt( 70.0 ) )/900.0;
+			weight[2] = 128.0/225.0;
+			weight[3] = weight[1];
+			weight[4] = weight[0];
+			break;
+		default:
+			Journal_Firewall( 
+				pointCount <= 5, 
+				Journal_Register( Error_Type, (Name)GaussParticleLayout_Type  ),
+				"In func %s: Cannot give values for '%u' gauss points\n.", 
+				__func__, 
+				pointCount );
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/GlobalParticleLayout.c
--- a/Swarm/src/GlobalParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,337 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: GlobalParticleLayout.c 3768 2006-08-22 00:33:26Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "CellLayout.h"
-
-const Type GlobalParticleLayout_Type = "GlobalParticleLayout";
-
-const Index GlobalParticleLayout_Invalid = (Index) 0;
-
-GlobalParticleLayout* _GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_DEFARGS  )
-{
-	GlobalParticleLayout* self;
-	
-	assert( _sizeOfSelf >= sizeof(GlobalParticleLayout) );
-
-   /* hard-wire class attributes */
-   coordSystem = GlobalCoordSystem;
-   weightsInitialisedAtStartup = False;
-
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (GlobalParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
-	
-   /* attributes */
-   self->totalInitialParticles = totalInitialParticles; 
-   self->averageInitialParticlesPerCell = averageInitialParticlesPerCell; 
-   /* virtual function */
-	self->_initialiseParticle = _initialiseParticle;
-	
-	return self;
-}
-
-
-void _GlobalParticleLayout_Init(
-      void*                                               particleLayout,
-      Particle_Index                                      totalInitialParticles,
-      double                                              averageInitialParticlesPerCell )
-{
-   GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
-
-   /* Note the total and average particles per cell need to be set in child
-   classes, as they may be worked out differently (eg the ManualParticleLayout
-   specifies the particles directly, so the total is implicit) */
-
-   self->totalInitialParticles = totalInitialParticles;
-   self->averageInitialParticlesPerCell = averageInitialParticlesPerCell;
-}
-
-void _GlobalParticleLayout_Delete( void* particleLayout ) {
-	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
-	
-	_ParticleLayout_Delete( self );
-}
-void _GlobalParticleLayout_Destroy( void* particleLayout, void* data ) {
-	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
-	
-	_ParticleLayout_Destroy( self, data );
-}
-
-void  _GlobalParticleLayout_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )  {
-   GlobalParticleLayout*	self = (GlobalParticleLayout*)component;
-   unsigned int totalInitialParticles;
-   double averageInitialParticlesPerCell;
-
-   _ParticleLayout_AssignFromXML( self, cf, data );
-
-   totalInitialParticles = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"totalInitialParticles", GlobalParticleLayout_Invalid );
-
-   averageInitialParticlesPerCell = (double )Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"averageInitialParticlesPerCell", GlobalParticleLayout_Invalid  );
-
-   _GlobalParticleLayout_Init( component, totalInitialParticles, averageInitialParticlesPerCell );
-}
-void _GlobalParticleLayout_Print( void* particleLayout, Stream* stream ) {
-	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
-	
-	Journal_Printf( stream, "GlobalParticleLayout (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_ParticleLayout_Print( self, stream );
-	
-	/* Virtual info */
-	Journal_Printf( stream, "\t_initialiseParticle (func ptr): %p\n", self->_initialiseParticle );
-	
-	/* GlobalParticleLayout info */
-	Journal_Printf( stream, "\ttotalInitialParticles: %u\n", self->totalInitialParticles );
-	Journal_Printf( stream, "\taverageInitialParticlesPerCell: %g\n", self->averageInitialParticlesPerCell );
-}
-
-
-void* _GlobalParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	GlobalParticleLayout*		self = (GlobalParticleLayout*)particleLayout;
-	GlobalParticleLayout*		newGlobalParticleLayout;
-	
-	newGlobalParticleLayout = (GlobalParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-
-	/* Virtual methods */
-	newGlobalParticleLayout->_initialiseParticle= self->_initialiseParticle;
-
-	/* data */
-	newGlobalParticleLayout->averageInitialParticlesPerCell = self->averageInitialParticlesPerCell;
-	newGlobalParticleLayout->totalInitialParticles = self->totalInitialParticles;
-	
-	return (void*)newGlobalParticleLayout;
-}
-
-
-/* Note: this function is required to also set the total particle count */
-void _GlobalParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
-{
-	GlobalParticleLayout*	self = (GlobalParticleLayout*)particleLayout;
-	Swarm*			swarm = (Swarm*)_swarm;
-	Cell_LocalIndex		cell_I;
-	char			tempStr[100];
-	Cell_Index		globalCellCount;
-
-	Journal_DPrintf( self->debug, "In %s(): for ParticleLayout \"%s\" (of type %s):\n",
-		__func__, self->name, self->type );
-	Stream_IndentBranch( Swarm_Debug );
-
-	Journal_DPrintf( self->debug, "Calculating total number of cells in system across all processors "
-		"using MPI_Allreduce:\n" );
-	MPI_Allreduce( &swarm->cellLocalCount, &globalCellCount, 1, MPI_UNSIGNED, MPI_SUM, swarm->comm );
-	Journal_DPrintf( self->debug, "...calculated total global cell count is %u\n", globalCellCount );
-	
-	Journal_DPrintf( self->debug, "Calculating totalInitialParticles and averageInitialParticlesPerCell:\n" );
-	Stream_IndentBranch( Swarm_Debug );
-	if ( self->totalInitialParticles ) {
-		self->averageInitialParticlesPerCell = self->totalInitialParticles / (double)globalCellCount;
-		Journal_DPrintf( self->debug, "totalInitialParticles set as %u, thus calculated "
-			"averageInitialParticlesPerCell as %f.\n", self->totalInitialParticles,
-			self->averageInitialParticlesPerCell );
-	}
-	else if ( self->averageInitialParticlesPerCell ) {
-		self->totalInitialParticles = globalCellCount * self->averageInitialParticlesPerCell;
-		Journal_DPrintf( self->debug, "averageInitialParticlesPerCell set as %f, thus calculated "
-			"totalInitialParticles as %u.\n", self->averageInitialParticlesPerCell,
-			self->totalInitialParticles );
-	}
-	else {
-		Stream*     errorStream = Journal_Register( Error_Type, (Name)self->type  );
-		
-		Journal_Firewall( self->totalInitialParticles || self->averageInitialParticlesPerCell,
-			errorStream, "Error - in %s(), ParticleLayout \"%s\" (of type %s): neither "
-			"totalInitialParticles or averageInitialParticlesPerCell was specified by "
-			"child class - one of these needs to be calculated so the "
-			"swarm cell memory storage can be set.\n",
-			__func__, self->name, self->type );
-	}
-	Stream_UnIndentBranch( Swarm_Debug );
-
-	/* We don't set the local particle count equal to totalInitialParticles,
-	since we're not sure how many of those are local yet */
-	swarm->particleLocalCount = 0;
-		
-	for( cell_I = 0; cell_I < swarm->cellLocalCount; cell_I++ ) {
-		/* Set initial counts to empty, till we add the particles */
-		swarm->cellParticleCountTbl[cell_I] = 0;
-		/* Set initial sizes to averageInitialParticlesPerCell, since its our best guess at how many
-		 * particles there will be after setup in this cell, and hence how much memory needed */
-		swarm->cellParticleSizeTbl[cell_I] = (int)( self->averageInitialParticlesPerCell + 0.5 );
-		
-		sprintf( tempStr, "Swarm->cellParticleTbl[%d]", cell_I );
-		swarm->cellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, swarm->cellParticleSizeTbl[cell_I], tempStr );
-	}
-
-	/* Now initialise the shadow cell particle counts */
-	for (; cell_I < swarm->cellDomainCount; cell_I++ ) {
-		swarm->cellParticleCountTbl[cell_I] = 0;
-		swarm->cellParticleSizeTbl[cell_I] = 0;
-		swarm->cellParticleTbl[cell_I] = NULL;
-	}
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void _GlobalParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
-{
-	GlobalParticleLayout*	self = (GlobalParticleLayout*)particleLayout;
-	Swarm*			swarm = (Swarm*)_swarm;
-	GlobalParticle*         particle = NULL;
-	Particle_Index		lParticle_I=0;
-	Particle_Index		newParticle_I=0;
-	Cell_Index		cell_I;
-	Particle_Index          globalParticlesInitialisedCount=0;
-	Progress*		prog;
-	int                     nRanks;
-	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	Journal_DPrintf( self->debug, "In %s(): for ParticleLayout \"%s\" (of type %s):\n",
-		__func__, self->name, self->type );
-	Stream_IndentBranch( Swarm_Debug );
-
-	Journal_DPrintf( self->debug, "For each of the %u total global requested particles, "
-		"generating a particle, and checking if it's in this processor's domain. If so, "
-		"adding it to the appropriate local cell.\n", self->totalInitialParticles );
-	Stream_IndentBranch( Swarm_Debug );
-
-	/* Use a progress meter. */
-	prog = Progress_New();
-	Progress_SetStream( prog, self->debug );
-	Progress_SetTitle( prog, "Generating global particles" );
-	Progress_SetPrefix( prog, "\t" );
-	Progress_SetRange( prog, 0, self->totalInitialParticles );
-	Progress_Update( prog );
-
-	/* Allocate a guess at the particle size to prevent a TONNE of unnecessary
-	   reallocation. */
-	MPI_Comm_size( MPI_COMM_WORLD, &nRanks );
-	assert( swarm->particleLocalCount == 0 );
-	swarm->particleLocalCount = self->totalInitialParticles/nRanks + 1;
-	Swarm_Realloc( swarm );
-	swarm->particleLocalCount = 0;
-	swarm->expanding = 1;
-
-	while( newParticle_I < self->totalInitialParticles ) {
-		
-		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-		GlobalParticleLayout_InitialiseParticle( self, swarm, newParticle_I, particle );
-		/* Work out which cell the new particle is in */
-		/* First specify the particle doesn't have an owning cell yet, so as
-		not to confuse the search algorithm if its an irregular cell/mesh layout */
-		particle->owningCell = swarm->cellDomainCount;
-
-		cell_I = CellLayout_CellOf( swarm->cellLayout, particle );
-
-		/* If we found a further particle inside our domain, add it to a cell */
-		if ( cell_I < swarm->cellLocalCount ) {
-			Journal_DPrintfL( self->debug, 3, "global particle %u at (%.2f,%.2f,%.2f) inside local cell %u\n"
-				"adding it to cell and saving it as local particle %u.\n",
-				newParticle_I, particle->coord[0], particle->coord[1], particle->coord[2],
-				cell_I, lParticle_I );
-				
-			Stream_IndentBranch( Swarm_Debug );
-			/* Add it to that cell */
-			Swarm_AddParticleToCell( swarm, cell_I, lParticle_I );
-			lParticle_I++;
-			swarm->particleLocalCount++;
-			Swarm_Realloc( swarm );
-			Stream_UnIndentBranch( Swarm_Debug );
-		}
-		else {
-			Journal_DPrintfL( self->debug, 4, "global particle %u at (%.2f,%.2f,%.2f) outside this proc's domain:\n"
-				"ignoring.\n", newParticle_I, particle->coord[0], particle->coord[1], particle->coord[2] );
-		}		
-				
-		newParticle_I++;
-
-		Progress_Increment( prog );
-	}
-
-	/* Removing the lock on the swarm and realloc once more to remove any
-	   unused space. */
-	swarm->expanding = 0;
-	Swarm_Realloc( swarm );
-
-	/* Delete progress meter. */
-	Stg_Class_Delete( prog );
-
-	Stream_UnIndentBranch( Swarm_Debug );
-
-	/* Do a test to make sure that the total particles assigned across all processors ==
-		totalInitialParticles count */
-	MPI_Allreduce( &swarm->particleLocalCount, &globalParticlesInitialisedCount, 1, MPI_UNSIGNED, MPI_SUM, swarm->comm );
-	Journal_Firewall( globalParticlesInitialisedCount == self->totalInitialParticles, errorStream,
-		"Error - in %s() - for GlobalParticleLayout \"%s\", of type %s: after initialising particles, "
-		"actual global count of particles initialised was %u, whereas the user requested global total "
-		"totalInitialParticles was %u.\n"
-      "If actual is < requested, it means some particles were not identified by any processor as "
-      "inside their domain.\n"
-      "This is usually caused because some particles are outside the mesh domain.\n"
-      "If actual > requested, it means that some particles were identified by _multiple_ processors "
-      "as belonging to their domain.\n"
-      "Both these states are erroneous.\n",
-		__func__, self->name, self->type, globalParticlesInitialisedCount, self->totalInitialParticles );
-
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void GlobalParticleLayout_InitialiseParticle( void* particleLayout, void* _swarm, Particle_Index newParticle_I, void* particle )
-{
-	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
-	
-	self->_initialiseParticle( self, _swarm, newParticle_I, particle );
-}
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/GlobalParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/GlobalParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,337 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: GlobalParticleLayout.c 3768 2006-08-22 00:33:26Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "CellLayout.h"
+
+const Type GlobalParticleLayout_Type = "GlobalParticleLayout";
+
+const Index GlobalParticleLayout_Invalid = (Index) 0;
+
+GlobalParticleLayout* _GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_DEFARGS  )
+{
+	GlobalParticleLayout* self;
+	
+	assert( _sizeOfSelf >= sizeof(GlobalParticleLayout) );
+
+   /* hard-wire class attributes */
+   coordSystem = GlobalCoordSystem;
+   weightsInitialisedAtStartup = False;
+
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (GlobalParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
+	
+   /* attributes */
+   self->totalInitialParticles = totalInitialParticles; 
+   self->averageInitialParticlesPerCell = averageInitialParticlesPerCell; 
+   /* virtual function */
+	self->_initialiseParticle = _initialiseParticle;
+	
+	return self;
+}
+
+
+void _GlobalParticleLayout_Init(
+      void*                                               particleLayout,
+      Particle_Index                                      totalInitialParticles,
+      double                                              averageInitialParticlesPerCell )
+{
+   GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
+
+   /* Note the total and average particles per cell need to be set in child
+   classes, as they may be worked out differently (eg the ManualParticleLayout
+   specifies the particles directly, so the total is implicit) */
+
+   self->totalInitialParticles = totalInitialParticles;
+   self->averageInitialParticlesPerCell = averageInitialParticlesPerCell;
+}
+
+void _GlobalParticleLayout_Delete( void* particleLayout ) {
+	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
+	
+	_ParticleLayout_Delete( self );
+}
+void _GlobalParticleLayout_Destroy( void* particleLayout, void* data ) {
+	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
+	
+	_ParticleLayout_Destroy( self, data );
+}
+
+void  _GlobalParticleLayout_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )  {
+   GlobalParticleLayout*	self = (GlobalParticleLayout*)component;
+   unsigned int totalInitialParticles;
+   double averageInitialParticlesPerCell;
+
+   _ParticleLayout_AssignFromXML( self, cf, data );
+
+   totalInitialParticles = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"totalInitialParticles", GlobalParticleLayout_Invalid );
+
+   averageInitialParticlesPerCell = (double )Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"averageInitialParticlesPerCell", GlobalParticleLayout_Invalid  );
+
+   _GlobalParticleLayout_Init( component, totalInitialParticles, averageInitialParticlesPerCell );
+}
+void _GlobalParticleLayout_Print( void* particleLayout, Stream* stream ) {
+	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
+	
+	Journal_Printf( stream, "GlobalParticleLayout (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_ParticleLayout_Print( self, stream );
+	
+	/* Virtual info */
+	Journal_Printf( stream, "\t_initialiseParticle (func ptr): %p\n", self->_initialiseParticle );
+	
+	/* GlobalParticleLayout info */
+	Journal_Printf( stream, "\ttotalInitialParticles: %u\n", self->totalInitialParticles );
+	Journal_Printf( stream, "\taverageInitialParticlesPerCell: %g\n", self->averageInitialParticlesPerCell );
+}
+
+
+void* _GlobalParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	GlobalParticleLayout*		self = (GlobalParticleLayout*)particleLayout;
+	GlobalParticleLayout*		newGlobalParticleLayout;
+	
+	newGlobalParticleLayout = (GlobalParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+
+	/* Virtual methods */
+	newGlobalParticleLayout->_initialiseParticle= self->_initialiseParticle;
+
+	/* data */
+	newGlobalParticleLayout->averageInitialParticlesPerCell = self->averageInitialParticlesPerCell;
+	newGlobalParticleLayout->totalInitialParticles = self->totalInitialParticles;
+	
+	return (void*)newGlobalParticleLayout;
+}
+
+
+/* Note: this function is required to also set the total particle count */
+void _GlobalParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
+{
+	GlobalParticleLayout*	self = (GlobalParticleLayout*)particleLayout;
+	Swarm*			swarm = (Swarm*)_swarm;
+	Cell_LocalIndex		cell_I;
+	char			tempStr[100];
+	Cell_Index		globalCellCount;
+
+	Journal_DPrintf( self->debug, "In %s(): for ParticleLayout \"%s\" (of type %s):\n",
+		__func__, self->name, self->type );
+	Stream_IndentBranch( Swarm_Debug );
+
+	Journal_DPrintf( self->debug, "Calculating total number of cells in system across all processors "
+		"using MPI_Allreduce:\n" );
+	MPI_Allreduce( &swarm->cellLocalCount, &globalCellCount, 1, MPI_UNSIGNED, MPI_SUM, swarm->comm );
+	Journal_DPrintf( self->debug, "...calculated total global cell count is %u\n", globalCellCount );
+	
+	Journal_DPrintf( self->debug, "Calculating totalInitialParticles and averageInitialParticlesPerCell:\n" );
+	Stream_IndentBranch( Swarm_Debug );
+	if ( self->totalInitialParticles ) {
+		self->averageInitialParticlesPerCell = self->totalInitialParticles / (double)globalCellCount;
+		Journal_DPrintf( self->debug, "totalInitialParticles set as %u, thus calculated "
+			"averageInitialParticlesPerCell as %f.\n", self->totalInitialParticles,
+			self->averageInitialParticlesPerCell );
+	}
+	else if ( self->averageInitialParticlesPerCell ) {
+		self->totalInitialParticles = globalCellCount * self->averageInitialParticlesPerCell;
+		Journal_DPrintf( self->debug, "averageInitialParticlesPerCell set as %f, thus calculated "
+			"totalInitialParticles as %u.\n", self->averageInitialParticlesPerCell,
+			self->totalInitialParticles );
+	}
+	else {
+		Stream*     errorStream = Journal_Register( Error_Type, (Name)self->type  );
+		
+		Journal_Firewall( self->totalInitialParticles || self->averageInitialParticlesPerCell,
+			errorStream, "Error - in %s(), ParticleLayout \"%s\" (of type %s): neither "
+			"totalInitialParticles or averageInitialParticlesPerCell was specified by "
+			"child class - one of these needs to be calculated so the "
+			"swarm cell memory storage can be set.\n",
+			__func__, self->name, self->type );
+	}
+	Stream_UnIndentBranch( Swarm_Debug );
+
+	/* We don't set the local particle count equal to totalInitialParticles,
+	since we're not sure how many of those are local yet */
+	swarm->particleLocalCount = 0;
+		
+	for( cell_I = 0; cell_I < swarm->cellLocalCount; cell_I++ ) {
+		/* Set initial counts to empty, till we add the particles */
+		swarm->cellParticleCountTbl[cell_I] = 0;
+		/* Set initial sizes to averageInitialParticlesPerCell, since its our best guess at how many
+		 * particles there will be after setup in this cell, and hence how much memory needed */
+		swarm->cellParticleSizeTbl[cell_I] = (int)( self->averageInitialParticlesPerCell + 0.5 );
+		
+		sprintf( tempStr, "Swarm->cellParticleTbl[%d]", cell_I );
+		swarm->cellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, swarm->cellParticleSizeTbl[cell_I], tempStr );
+	}
+
+	/* Now initialise the shadow cell particle counts */
+	for (; cell_I < swarm->cellDomainCount; cell_I++ ) {
+		swarm->cellParticleCountTbl[cell_I] = 0;
+		swarm->cellParticleSizeTbl[cell_I] = 0;
+		swarm->cellParticleTbl[cell_I] = NULL;
+	}
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void _GlobalParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
+{
+	GlobalParticleLayout*	self = (GlobalParticleLayout*)particleLayout;
+	Swarm*			swarm = (Swarm*)_swarm;
+	GlobalParticle*         particle = NULL;
+	Particle_Index		lParticle_I=0;
+	Particle_Index		newParticle_I=0;
+	Cell_Index		cell_I;
+	Particle_Index          globalParticlesInitialisedCount=0;
+	Progress*		prog;
+	int                     nRanks;
+	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	Journal_DPrintf( self->debug, "In %s(): for ParticleLayout \"%s\" (of type %s):\n",
+		__func__, self->name, self->type );
+	Stream_IndentBranch( Swarm_Debug );
+
+	Journal_DPrintf( self->debug, "For each of the %u total global requested particles, "
+		"generating a particle, and checking if it's in this processor's domain. If so, "
+		"adding it to the appropriate local cell.\n", self->totalInitialParticles );
+	Stream_IndentBranch( Swarm_Debug );
+
+	/* Use a progress meter. */
+	prog = Progress_New();
+	Progress_SetStream( prog, self->debug );
+	Progress_SetTitle( prog, "Generating global particles" );
+	Progress_SetPrefix( prog, "\t" );
+	Progress_SetRange( prog, 0, self->totalInitialParticles );
+	Progress_Update( prog );
+
+	/* Allocate a guess at the particle size to prevent a TONNE of unnecessary
+	   reallocation. */
+	MPI_Comm_size( MPI_COMM_WORLD, &nRanks );
+	assert( swarm->particleLocalCount == 0 );
+	swarm->particleLocalCount = self->totalInitialParticles/nRanks + 1;
+	Swarm_Realloc( swarm );
+	swarm->particleLocalCount = 0;
+	swarm->expanding = 1;
+
+	while( newParticle_I < self->totalInitialParticles ) {
+		
+		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+		GlobalParticleLayout_InitialiseParticle( self, swarm, newParticle_I, particle );
+		/* Work out which cell the new particle is in */
+		/* First specify the particle doesn't have an owning cell yet, so as
+		not to confuse the search algorithm if its an irregular cell/mesh layout */
+		particle->owningCell = swarm->cellDomainCount;
+
+		cell_I = CellLayout_CellOf( swarm->cellLayout, particle );
+
+		/* If we found a further particle inside our domain, add it to a cell */
+		if ( cell_I < swarm->cellLocalCount ) {
+			Journal_DPrintfL( self->debug, 3, "global particle %u at (%.2f,%.2f,%.2f) inside local cell %u\n"
+				"adding it to cell and saving it as local particle %u.\n",
+				newParticle_I, particle->coord[0], particle->coord[1], particle->coord[2],
+				cell_I, lParticle_I );
+				
+			Stream_IndentBranch( Swarm_Debug );
+			/* Add it to that cell */
+			Swarm_AddParticleToCell( swarm, cell_I, lParticle_I );
+			lParticle_I++;
+			swarm->particleLocalCount++;
+			Swarm_Realloc( swarm );
+			Stream_UnIndentBranch( Swarm_Debug );
+		}
+		else {
+			Journal_DPrintfL( self->debug, 4, "global particle %u at (%.2f,%.2f,%.2f) outside this proc's domain:\n"
+				"ignoring.\n", newParticle_I, particle->coord[0], particle->coord[1], particle->coord[2] );
+		}		
+				
+		newParticle_I++;
+
+		Progress_Increment( prog );
+	}
+
+	/* Removing the lock on the swarm and realloc once more to remove any
+	   unused space. */
+	swarm->expanding = 0;
+	Swarm_Realloc( swarm );
+
+	/* Delete progress meter. */
+	Stg_Class_Delete( prog );
+
+	Stream_UnIndentBranch( Swarm_Debug );
+
+	/* Do a test to make sure that the total particles assigned across all processors ==
+		totalInitialParticles count */
+	MPI_Allreduce( &swarm->particleLocalCount, &globalParticlesInitialisedCount, 1, MPI_UNSIGNED, MPI_SUM, swarm->comm );
+	Journal_Firewall( globalParticlesInitialisedCount == self->totalInitialParticles, errorStream,
+		"Error - in %s() - for GlobalParticleLayout \"%s\", of type %s: after initialising particles, "
+		"actual global count of particles initialised was %u, whereas the user requested global total "
+		"totalInitialParticles was %u.\n"
+      "If actual is < requested, it means some particles were not identified by any processor as "
+      "inside their domain.\n"
+      "This is usually caused because some particles are outside the mesh domain.\n"
+      "If actual > requested, it means that some particles were identified by _multiple_ processors "
+      "as belonging to their domain.\n"
+      "Both these states are erroneous.\n",
+		__func__, self->name, self->type, globalParticlesInitialisedCount, self->totalInitialParticles );
+
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void GlobalParticleLayout_InitialiseParticle( void* particleLayout, void* _swarm, Particle_Index newParticle_I, void* particle )
+{
+	GlobalParticleLayout* self = (GlobalParticleLayout*)particleLayout;
+	
+	self->_initialiseParticle( self, _swarm, newParticle_I, particle );
+}
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Init.c
--- a/Swarm/src/Init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,129 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Init.c 4174 2007-08-16 03:37:44Z DavidLee $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include "Swarm.h"
-#include "ParticleCommHandler.h"
-#include "ParticleMovementHandler.h"
-#include "ParticleShadowSync.h"
-/*#include "SwarmShapeVC.h"*/
-
-
-Stream* Swarm_VerboseConfig = NULL;
-Stream* Swarm_Debug = NULL;
-Stream* Swarm_Warning = NULL;
-Stream* Swarm_Error = NULL;
-
-
-Bool StgDomainSwarm_Init( int* argc, char** argv[] ) {
-	Swarm_VerboseConfig = Journal_Register( Info_Type, (Name)"Swarm_VerboseConfig"  );
-	Swarm_Debug = Journal_Register( Debug_Type, (Name)"Swarm"  );
-	Swarm_Warning = Journal_Register( Error_Type, (Name)"Swarm"  );
-	Swarm_Error = Journal_Register( Error_Type, (Name)"Swarm"  );
-	
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	VariableCondition_Register_Add( variableCondition_Register, SwarmShapeVC_Type, SwarmShapeVC_Factory );
-
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), GaussParticleLayout_Type, (Name)"0", _GaussParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), TriGaussParticleLayout_Type, "0", _TriGaussParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), GaussBorderParticleLayout_Type, (Name)"0", _GaussBorderParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), RandomParticleLayout_Type, "0", _RandomParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshParticleLayout_Type, (Name)"0", _MeshParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), SpaceFillerParticleLayout_Type, "0", _SpaceFillerParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), UnionParticleLayout_Type, (Name)"0", _UnionParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), WithinShapeParticleLayout_Type, "0", _WithinShapeParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), PlaneParticleLayout_Type, (Name)"0", _PlaneParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ManualParticleLayout_Type, "0", _ManualParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), LineParticleLayout_Type, (Name)"0", _LineParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), FileParticleLayout_Type, "0", _FileParticleLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SingleCellLayout_Type, (Name)"0", _SingleCellLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ElementCellLayout_Type, "0", _ElementCellLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), TriSingleCellLayout_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)_TriSingleCellLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Swarm_Type, "0", (Stg_Component_DefaultConstructorFunction*)_Swarm_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SwarmVariable_Type, (Name)"0", _SwarmVariable_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), OperatorSwarmVariable_Type, "0", _OperatorSwarmVariable_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SwarmOutput_Type, (Name)"0", _SwarmOutput_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), SwarmDump_Type, "0", _SwarmDump_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), ParticleShadowSync_Type, (Name)"0", ParticleShadowSync_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ParticleMovementHandler_Type, "0", ParticleMovementHandler_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SwarmShapeVC_Type, (Name)"0", _SwarmShapeVC_DefaultNew  );
-
-	RegisterParent( CellLayout_Type, Stg_Component_Type );
-	RegisterParent( ElementCellLayout_Type, CellLayout_Type );
-	RegisterParent( SingleCellLayout_Type, CellLayout_Type );
-	RegisterParent( TriSingleCellLayout_Type, CellLayout_Type );
-
-	RegisterParent( ParticleLayout_Type, Stg_Component_Type );
-
-	RegisterParent( GlobalParticleLayout_Type, ParticleLayout_Type );
-	RegisterParent( ManualParticleLayout_Type, GlobalParticleLayout_Type );
-	RegisterParent( LineParticleLayout_Type, GlobalParticleLayout_Type );
-	RegisterParent( FileParticleLayout_Type, GlobalParticleLayout_Type );
-	RegisterParent( SpaceFillerParticleLayout_Type, GlobalParticleLayout_Type );
-	RegisterParent( UnionParticleLayout_Type, GlobalParticleLayout_Type );
-	RegisterParent( WithinShapeParticleLayout_Type, SpaceFillerParticleLayout_Type );
-	RegisterParent( PlaneParticleLayout_Type, SpaceFillerParticleLayout_Type );
-
-	RegisterParent( PerCellParticleLayout_Type, ParticleLayout_Type );
-	RegisterParent( GaussParticleLayout_Type,   PerCellParticleLayout_Type );
-	RegisterParent( RandomParticleLayout_Type,   PerCellParticleLayout_Type );
-	RegisterParent( MeshParticleLayout_Type,   PerCellParticleLayout_Type );
-	RegisterParent( TriGaussParticleLayout_Type,   PerCellParticleLayout_Type );
-	RegisterParent( GaussBorderParticleLayout_Type,   GaussParticleLayout_Type );
-	
-	
-	RegisterParent( SwarmVariable_Register_Type, NamedObject_Register_Type );
-	RegisterParent( SwarmVariable_Type,         Stg_Component_Type );
-	RegisterParent( OperatorSwarmVariable_Type, SwarmVariable_Type );
-	RegisterParent( SwarmOutput_Type,           Stg_Component_Type );
-	RegisterParent( SwarmDump_Type,             Stg_Component_Type );
-	
-	RegisterParent( ParticleCommHandler_Type, Stg_Component_Type );
-	RegisterParent( ParticleMovementHandler_Type, ParticleCommHandler_Type);
-	RegisterParent( ParticleShadowSync_Type, ParticleCommHandler_Type);
-	RegisterParent( Swarm_Type, Stg_Component_Type );
-	RegisterParent( Swarm_Register_Type, Stg_Class_Type );
-	RegisterParent( SwarmShapeVC_Type,           VariableCondition_Type );
-
-	/* Create the singletons */
-	stgSwarm_Register = Swarm_Register_New(); 
-
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/Init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,129 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Init.c 4174 2007-08-16 03:37:44Z DavidLee $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include "Swarm.h"
+#include "ParticleCommHandler.h"
+#include "ParticleMovementHandler.h"
+#include "ParticleShadowSync.h"
+/*#include "SwarmShapeVC.h"*/
+
+
+Stream* Swarm_VerboseConfig = NULL;
+Stream* Swarm_Debug = NULL;
+Stream* Swarm_Warning = NULL;
+Stream* Swarm_Error = NULL;
+
+
+Bool StgDomainSwarm_Init( int* argc, char** argv[] ) {
+	Swarm_VerboseConfig = Journal_Register( Info_Type, (Name)"Swarm_VerboseConfig"  );
+	Swarm_Debug = Journal_Register( Debug_Type, (Name)"Swarm"  );
+	Swarm_Warning = Journal_Register( Error_Type, (Name)"Swarm"  );
+	Swarm_Error = Journal_Register( Error_Type, (Name)"Swarm"  );
+	
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	VariableCondition_Register_Add( variableCondition_Register, SwarmShapeVC_Type, SwarmShapeVC_Factory );
+
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), GaussParticleLayout_Type, (Name)"0", _GaussParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), TriGaussParticleLayout_Type, "0", _TriGaussParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), GaussBorderParticleLayout_Type, (Name)"0", _GaussBorderParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), RandomParticleLayout_Type, "0", _RandomParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshParticleLayout_Type, (Name)"0", _MeshParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), SpaceFillerParticleLayout_Type, "0", _SpaceFillerParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), UnionParticleLayout_Type, (Name)"0", _UnionParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), WithinShapeParticleLayout_Type, "0", _WithinShapeParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), PlaneParticleLayout_Type, (Name)"0", _PlaneParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ManualParticleLayout_Type, "0", _ManualParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), LineParticleLayout_Type, (Name)"0", _LineParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), FileParticleLayout_Type, "0", _FileParticleLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SingleCellLayout_Type, (Name)"0", _SingleCellLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ElementCellLayout_Type, "0", _ElementCellLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), TriSingleCellLayout_Type, (Name)"0", (Stg_Component_DefaultConstructorFunction*)_TriSingleCellLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Swarm_Type, "0", (Stg_Component_DefaultConstructorFunction*)_Swarm_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SwarmVariable_Type, (Name)"0", _SwarmVariable_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), OperatorSwarmVariable_Type, "0", _OperatorSwarmVariable_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SwarmOutput_Type, (Name)"0", _SwarmOutput_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), SwarmDump_Type, "0", _SwarmDump_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), ParticleShadowSync_Type, (Name)"0", ParticleShadowSync_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ParticleMovementHandler_Type, "0", ParticleMovementHandler_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), SwarmShapeVC_Type, (Name)"0", _SwarmShapeVC_DefaultNew  );
+
+	RegisterParent( CellLayout_Type, Stg_Component_Type );
+	RegisterParent( ElementCellLayout_Type, CellLayout_Type );
+	RegisterParent( SingleCellLayout_Type, CellLayout_Type );
+	RegisterParent( TriSingleCellLayout_Type, CellLayout_Type );
+
+	RegisterParent( ParticleLayout_Type, Stg_Component_Type );
+
+	RegisterParent( GlobalParticleLayout_Type, ParticleLayout_Type );
+	RegisterParent( ManualParticleLayout_Type, GlobalParticleLayout_Type );
+	RegisterParent( LineParticleLayout_Type, GlobalParticleLayout_Type );
+	RegisterParent( FileParticleLayout_Type, GlobalParticleLayout_Type );
+	RegisterParent( SpaceFillerParticleLayout_Type, GlobalParticleLayout_Type );
+	RegisterParent( UnionParticleLayout_Type, GlobalParticleLayout_Type );
+	RegisterParent( WithinShapeParticleLayout_Type, SpaceFillerParticleLayout_Type );
+	RegisterParent( PlaneParticleLayout_Type, SpaceFillerParticleLayout_Type );
+
+	RegisterParent( PerCellParticleLayout_Type, ParticleLayout_Type );
+	RegisterParent( GaussParticleLayout_Type,   PerCellParticleLayout_Type );
+	RegisterParent( RandomParticleLayout_Type,   PerCellParticleLayout_Type );
+	RegisterParent( MeshParticleLayout_Type,   PerCellParticleLayout_Type );
+	RegisterParent( TriGaussParticleLayout_Type,   PerCellParticleLayout_Type );
+	RegisterParent( GaussBorderParticleLayout_Type,   GaussParticleLayout_Type );
+	
+	
+	RegisterParent( SwarmVariable_Register_Type, NamedObject_Register_Type );
+	RegisterParent( SwarmVariable_Type,         Stg_Component_Type );
+	RegisterParent( OperatorSwarmVariable_Type, SwarmVariable_Type );
+	RegisterParent( SwarmOutput_Type,           Stg_Component_Type );
+	RegisterParent( SwarmDump_Type,             Stg_Component_Type );
+	
+	RegisterParent( ParticleCommHandler_Type, Stg_Component_Type );
+	RegisterParent( ParticleMovementHandler_Type, ParticleCommHandler_Type);
+	RegisterParent( ParticleShadowSync_Type, ParticleCommHandler_Type);
+	RegisterParent( Swarm_Type, Stg_Component_Type );
+	RegisterParent( Swarm_Register_Type, Stg_Class_Type );
+	RegisterParent( SwarmShapeVC_Type,           VariableCondition_Type );
+
+	/* Create the singletons */
+	stgSwarm_Register = Swarm_Register_New(); 
+
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/IntegrationPoint.c
--- a/Swarm/src/IntegrationPoint.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-**
-**
-** Assumptions:
-**
-** Comments:
-**
-** $Id: Swarm_Register.c 2745 2005-05-10 08:12:18Z RaquibulHassan $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "LineParticleLayout.h"
-#include "SwarmClass.h"
-#include "Swarm_Register.h"
-
-#include "StandardParticle.h"
-#include "IntegrationPoint.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-const Type IntegrationPoint_Type = "IntegrationPoint";
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/IntegrationPoint.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/IntegrationPoint.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,63 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+**
+**
+** Assumptions:
+**
+** Comments:
+**
+** $Id: Swarm_Register.c 2745 2005-05-10 08:12:18Z RaquibulHassan $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "LineParticleLayout.h"
+#include "SwarmClass.h"
+#include "Swarm_Register.h"
+
+#include "StandardParticle.h"
+#include "IntegrationPoint.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+const Type IntegrationPoint_Type = "IntegrationPoint";
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/LineParticleLayout.c
--- a/Swarm/src/LineParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,290 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: LineParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "LineParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-
-const Type LineParticleLayout_Type = "LineParticleLayout";
-
-LineParticleLayout* LineParticleLayout_New(
-		Name             name,
-      AbstractContext* context,
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles,
-      double           averageInitialParticlesPerCell,
-		Dimension_Index  dim,
-		Index            vertexCount,
-		Coord*           vertexList )
-{
-	LineParticleLayout* self = (LineParticleLayout*) _LineParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-	_LineParticleLayout_Init( self, dim, vertexCount, vertexList );
-	return self;
-}
-
-LineParticleLayout* _LineParticleLayout_New(  LINEPARTICLELAYOUT_DEFARGS  )
-{
-	LineParticleLayout* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof( LineParticleLayout ) );
-   self = (LineParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
-
-		self->dim = dim;
-		self->vertexCount = vertexCount;
-		self->vertexList = vertexList;
-	return self;
-}
-
-
-void _LineParticleLayout_Init( 
-		void*                                            particleLayout,
-		Dimension_Index                                  dim,
-		Index                                            vertexCount,
-		Coord*                                           vertexList )
-{
-	LineParticleLayout*     self        = (LineParticleLayout*) particleLayout;
-	double                  totalLength = 0.0;
-	Index                   segment_I;
-	double                  length;
-	
-	assert( self->totalInitialParticles >= 2 );
-	assert( vertexCount >= 2 );
-
-	self->dim = dim;
-	self->vertexCount = vertexCount;
-	self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
-	memcpy( self->vertexList, vertexList, sizeof(Coord) * vertexCount );
-
-	self->segmentLengthList = Memory_Alloc_Array( double, vertexCount - 1, "segmentLengthList" );
-	for ( segment_I = 0 ; segment_I < self->vertexCount - 1 ; segment_I++ ) {
-		length = StGermain_DistanceBetweenPoints( self->vertexList[ segment_I + 1 ], self->vertexList[ segment_I ], dim );
-		self->segmentLengthList[ segment_I ] = length;
-
-		totalLength += length;
-	}
-
-	self->dx = totalLength/( (double) self->totalInitialParticles - 1.0 );
-}
-
-
-void* _LineParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(LineParticleLayout);
-	Type                                                                        type = LineParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _LineParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _LineParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _LineParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _LineParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _LineParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _LineParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _LineParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _LineParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _LineParticleLayout_Destroy;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _GlobalParticleLayout_InitialiseParticles;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _LineParticleLayout_InitialiseParticle;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	Dimension_Index                                                              dim = 0;
-	Index                                                                vertexCount = 0;
-	Coord*                                                                vertexList = NULL;
-
-	return (void*)_LineParticleLayout_New(  LINEPARTICLELAYOUT_PASSARGS  );
-}
-
-	
-void _LineParticleLayout_Delete( void* particleLayout ) {
-	LineParticleLayout* self = (LineParticleLayout*)particleLayout;
-
-	_GlobalParticleLayout_Delete( self );
-
-}
-
-void _LineParticleLayout_Print( void* particleLayout, Stream* stream ) {
-	LineParticleLayout* self  = (LineParticleLayout*)particleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "LineParticleLayout (ptr): %p:\n", self );
-	Stream_Indent( stream );
-	
-	/* Parent class info */
-	_GlobalParticleLayout_Print( self, stream );
-	
-	/* LineParticleLayout */
-	/*Journal_PrintArray( stream, self->startCoord, 3 );*/
-	/*Journal_PrintArray( stream, self->endCoord, 3 );*/
-	
-	Stream_UnIndent( stream );
-}
-
-
-void* _LineParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	LineParticleLayout*		self                    = (LineParticleLayout*)particleLayout;
-	LineParticleLayout*		newLineParticleLayout;
-	
-	newLineParticleLayout = (LineParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-
-	/*memcpy( newLineParticleLayout->startCoord, self->startCoord, sizeof(Coord) );*/
-	/*memcpy( newLineParticleLayout->endCoord, self->endCoord, sizeof(Coord) );*/
-
-	return (void*)newLineParticleLayout;
-}
-
-
-void _LineParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ){
-	LineParticleLayout*     self                    = (LineParticleLayout*) particleLayout;
-	Particle_Index          totalInitialParticles;
-	Dimension_Index         dim;
-	Coord*                  vertexList;
-	Index                   vertexCount;
-	Index                   vertex_I;
-	Dictionary*             dictionary;
-	Stream*                 stream;
-	Dictionary_Entry_Value* entry;
-	Dictionary_Entry_Value* list;
-	double*                 coord;
-	
-	dictionary              = Dictionary_GetDictionary( cf->componentDict, self->name );
-	/*stream                  = cf->infoStream;*/
-	stream                  = Journal_MyStream( Info_Type, self );
-
-   _GlobalParticleLayout_AssignFromXML( self, cf, data );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-	/* Read list of vertices of each of the different line segments from the dictionary */
-	list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices" );
-	vertexCount = Dictionary_Entry_Value_GetCount( list  );
-	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
-	memset( vertexList, 0, vertexCount * sizeof(Coord) );
-
-	Stream_Indent( stream );
-	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
-		entry = Dictionary_Entry_Value_GetElement( list, vertex_I );
-		coord = vertexList[vertex_I];
-		/* Read Vertex */
-		coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"x") );
-		coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"y"));
-		if (dim == 3  ) {
-			coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"z") );
-		}
-
-		/* Print Position */
-		Journal_PrintfL( stream, 2, "(%0.3g, %0.3g, %0.3g)\n", coord[ I_AXIS ], coord[ J_AXIS ], coord[ K_AXIS ] );
-	}
-	Stream_UnIndent( stream );
-
-	totalInitialParticles = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"totalInitialParticles", 2  );
-
-	_LineParticleLayout_Init( self, dim, vertexCount, vertexList );
-
-	/* Delete this vertexList because _LineParticleLayout_Init made a copy of it */
-	Memory_Free( vertexList );
-}
-	
-void _LineParticleLayout_Build( void* particleLayout, void* data ) {
-}
-void _LineParticleLayout_Initialise( void* particleLayout, void* data ) {
-}
-void _LineParticleLayout_Execute( void* particleLayout, void* data ) {
-}
-void _LineParticleLayout_Destroy( void* particleLayout, void* data ) {
-	LineParticleLayout*        self             = (LineParticleLayout*)particleLayout;
-
-	Memory_Free( self->vertexList );
-	Memory_Free( self->segmentLengthList );
-
-   _GlobalParticleLayout_Destroy( self, data );
-}
-
-void _LineParticleLayout_InitialiseParticle( void* particleLayout, void* _swarm, Particle_Index newParticle_I, void* _particle )
-{
-	LineParticleLayout*        self             = (LineParticleLayout*)particleLayout;
-	unsigned                   axis_I;
-	Index                      segment_I;
-	double                     lengthFromVertex = self->dx * (double) newParticle_I;
-	double                     factor;
-	double                     segmentLength    = 0.0;
-	GlobalParticle*            particle         = (GlobalParticle*)_particle;
-
-	/* Find which segment the particle is in */
-	for ( segment_I = 0 ; segment_I < self->vertexCount - 1 ; segment_I++ ) {
-		segmentLength = self->segmentLengthList[ segment_I ];
-		if ( lengthFromVertex < self->segmentLengthList[ segment_I ] )
-			break;
-		lengthFromVertex -= segmentLength;
-	}
-	
-	/* Check if we are the last particle */
-	if ( segment_I == self->vertexCount - 1 ) {
-		memcpy( particle->coord, self->vertexList[ segment_I ], sizeof(Coord) );
-		return;
-	}
-
-	factor = lengthFromVertex / segmentLength;
-
-	memcpy( particle->coord, self->vertexList[ segment_I ], sizeof(Coord) );
-	for ( axis_I = 0 ; axis_I < self->dim ; axis_I++ ) {
-		particle->coord[axis_I] += factor 
-			* ( self->vertexList[ segment_I + 1 ][ axis_I ] - self->vertexList[ segment_I ][ axis_I ] )  ;
-	}
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/LineParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/LineParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,290 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: LineParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "LineParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+const Type LineParticleLayout_Type = "LineParticleLayout";
+
+LineParticleLayout* LineParticleLayout_New(
+		Name             name,
+      AbstractContext* context,
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles,
+      double           averageInitialParticlesPerCell,
+		Dimension_Index  dim,
+		Index            vertexCount,
+		Coord*           vertexList )
+{
+	LineParticleLayout* self = (LineParticleLayout*) _LineParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+	_LineParticleLayout_Init( self, dim, vertexCount, vertexList );
+	return self;
+}
+
+LineParticleLayout* _LineParticleLayout_New(  LINEPARTICLELAYOUT_DEFARGS  )
+{
+	LineParticleLayout* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof( LineParticleLayout ) );
+   self = (LineParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
+
+		self->dim = dim;
+		self->vertexCount = vertexCount;
+		self->vertexList = vertexList;
+	return self;
+}
+
+
+void _LineParticleLayout_Init( 
+		void*                                            particleLayout,
+		Dimension_Index                                  dim,
+		Index                                            vertexCount,
+		Coord*                                           vertexList )
+{
+	LineParticleLayout*     self        = (LineParticleLayout*) particleLayout;
+	double                  totalLength = 0.0;
+	Index                   segment_I;
+	double                  length;
+	
+	assert( self->totalInitialParticles >= 2 );
+	assert( vertexCount >= 2 );
+
+	self->dim = dim;
+	self->vertexCount = vertexCount;
+	self->vertexList = Memory_Alloc_Array( Coord, vertexCount, "vertexList" );
+	memcpy( self->vertexList, vertexList, sizeof(Coord) * vertexCount );
+
+	self->segmentLengthList = Memory_Alloc_Array( double, vertexCount - 1, "segmentLengthList" );
+	for ( segment_I = 0 ; segment_I < self->vertexCount - 1 ; segment_I++ ) {
+		length = StGermain_DistanceBetweenPoints( self->vertexList[ segment_I + 1 ], self->vertexList[ segment_I ], dim );
+		self->segmentLengthList[ segment_I ] = length;
+
+		totalLength += length;
+	}
+
+	self->dx = totalLength/( (double) self->totalInitialParticles - 1.0 );
+}
+
+
+void* _LineParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(LineParticleLayout);
+	Type                                                                        type = LineParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _LineParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _LineParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _LineParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _LineParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _LineParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _LineParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _LineParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _LineParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _LineParticleLayout_Destroy;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _GlobalParticleLayout_InitialiseParticles;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _LineParticleLayout_InitialiseParticle;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	Dimension_Index                                                              dim = 0;
+	Index                                                                vertexCount = 0;
+	Coord*                                                                vertexList = NULL;
+
+	return (void*)_LineParticleLayout_New(  LINEPARTICLELAYOUT_PASSARGS  );
+}
+
+	
+void _LineParticleLayout_Delete( void* particleLayout ) {
+	LineParticleLayout* self = (LineParticleLayout*)particleLayout;
+
+	_GlobalParticleLayout_Delete( self );
+
+}
+
+void _LineParticleLayout_Print( void* particleLayout, Stream* stream ) {
+	LineParticleLayout* self  = (LineParticleLayout*)particleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "LineParticleLayout (ptr): %p:\n", self );
+	Stream_Indent( stream );
+	
+	/* Parent class info */
+	_GlobalParticleLayout_Print( self, stream );
+	
+	/* LineParticleLayout */
+	/*Journal_PrintArray( stream, self->startCoord, 3 );*/
+	/*Journal_PrintArray( stream, self->endCoord, 3 );*/
+	
+	Stream_UnIndent( stream );
+}
+
+
+void* _LineParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	LineParticleLayout*		self                    = (LineParticleLayout*)particleLayout;
+	LineParticleLayout*		newLineParticleLayout;
+	
+	newLineParticleLayout = (LineParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+
+	/*memcpy( newLineParticleLayout->startCoord, self->startCoord, sizeof(Coord) );*/
+	/*memcpy( newLineParticleLayout->endCoord, self->endCoord, sizeof(Coord) );*/
+
+	return (void*)newLineParticleLayout;
+}
+
+
+void _LineParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ){
+	LineParticleLayout*     self                    = (LineParticleLayout*) particleLayout;
+	Particle_Index          totalInitialParticles;
+	Dimension_Index         dim;
+	Coord*                  vertexList;
+	Index                   vertexCount;
+	Index                   vertex_I;
+	Dictionary*             dictionary;
+	Stream*                 stream;
+	Dictionary_Entry_Value* entry;
+	Dictionary_Entry_Value* list;
+	double*                 coord;
+	
+	dictionary              = Dictionary_GetDictionary( cf->componentDict, self->name );
+	/*stream                  = cf->infoStream;*/
+	stream                  = Journal_MyStream( Info_Type, self );
+
+   _GlobalParticleLayout_AssignFromXML( self, cf, data );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+	/* Read list of vertices of each of the different line segments from the dictionary */
+	list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"vertices" );
+	vertexCount = Dictionary_Entry_Value_GetCount( list  );
+	vertexList = Memory_Alloc_Array( Coord , vertexCount, "Vertex Array" );
+	memset( vertexList, 0, vertexCount * sizeof(Coord) );
+
+	Stream_Indent( stream );
+	for ( vertex_I = 0 ; vertex_I < vertexCount ; vertex_I++) { 
+		entry = Dictionary_Entry_Value_GetElement( list, vertex_I );
+		coord = vertexList[vertex_I];
+		/* Read Vertex */
+		coord[ I_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"x") );
+		coord[ J_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"y"));
+		if (dim == 3  ) {
+			coord[ K_AXIS ] = Dictionary_Entry_Value_AsDouble( Dictionary_Entry_Value_GetMember( entry, (Dictionary_Entry_Key)"z") );
+		}
+
+		/* Print Position */
+		Journal_PrintfL( stream, 2, "(%0.3g, %0.3g, %0.3g)\n", coord[ I_AXIS ], coord[ J_AXIS ], coord[ K_AXIS ] );
+	}
+	Stream_UnIndent( stream );
+
+	totalInitialParticles = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"totalInitialParticles", 2  );
+
+	_LineParticleLayout_Init( self, dim, vertexCount, vertexList );
+
+	/* Delete this vertexList because _LineParticleLayout_Init made a copy of it */
+	Memory_Free( vertexList );
+}
+	
+void _LineParticleLayout_Build( void* particleLayout, void* data ) {
+}
+void _LineParticleLayout_Initialise( void* particleLayout, void* data ) {
+}
+void _LineParticleLayout_Execute( void* particleLayout, void* data ) {
+}
+void _LineParticleLayout_Destroy( void* particleLayout, void* data ) {
+	LineParticleLayout*        self             = (LineParticleLayout*)particleLayout;
+
+	Memory_Free( self->vertexList );
+	Memory_Free( self->segmentLengthList );
+
+   _GlobalParticleLayout_Destroy( self, data );
+}
+
+void _LineParticleLayout_InitialiseParticle( void* particleLayout, void* _swarm, Particle_Index newParticle_I, void* _particle )
+{
+	LineParticleLayout*        self             = (LineParticleLayout*)particleLayout;
+	unsigned                   axis_I;
+	Index                      segment_I;
+	double                     lengthFromVertex = self->dx * (double) newParticle_I;
+	double                     factor;
+	double                     segmentLength    = 0.0;
+	GlobalParticle*            particle         = (GlobalParticle*)_particle;
+
+	/* Find which segment the particle is in */
+	for ( segment_I = 0 ; segment_I < self->vertexCount - 1 ; segment_I++ ) {
+		segmentLength = self->segmentLengthList[ segment_I ];
+		if ( lengthFromVertex < self->segmentLengthList[ segment_I ] )
+			break;
+		lengthFromVertex -= segmentLength;
+	}
+	
+	/* Check if we are the last particle */
+	if ( segment_I == self->vertexCount - 1 ) {
+		memcpy( particle->coord, self->vertexList[ segment_I ], sizeof(Coord) );
+		return;
+	}
+
+	factor = lengthFromVertex / segmentLength;
+
+	memcpy( particle->coord, self->vertexList[ segment_I ], sizeof(Coord) );
+	for ( axis_I = 0 ; axis_I < self->dim ; axis_I++ ) {
+		particle->coord[axis_I] += factor 
+			* ( self->vertexList[ segment_I + 1 ][ axis_I ] - self->vertexList[ segment_I ][ axis_I ] )  ;
+	}
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ManualParticleLayout.c
--- a/Swarm/src/ManualParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,200 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ManualParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "ManualParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-const Type ManualParticleLayout_Type = "ManualParticleLayout";
-
-const Index ManualParticleLayout_Invalid = (Index)0;
-
-ManualParticleLayout* ManualParticleLayout_New( Name name,
-      AbstractContext* context, 
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles, 
-      double           averageInitialParticlesPerCell,
-      Dictionary*      dictionary ) 
-{
-	ManualParticleLayout* self = (ManualParticleLayout*) _ManualParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-	_ManualParticleLayout_Init( self, dictionary );
-	return self;
-}
-
-ManualParticleLayout* _ManualParticleLayout_New(  MANUALPARTICLELAYOUT_DEFARGS  )
-{
-	ManualParticleLayout* self;
-	
-	/* Allocate memory */
-	self = (ManualParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
-
-   self->dictionary = dictionary;
-
-	return self;
-}
-
-void _ManualParticleLayout_Init( void* manualParticleLayout, Dictionary* dictionary )
-{
-	ManualParticleLayout*	self                            = (ManualParticleLayout*)manualParticleLayout;
-	Dictionary_Entry_Value* manualParticlePositions         = NULL;
-
-	self->isConstructed = True;
-	self->dictionary    = dictionary;
-
-	manualParticlePositions = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"manualParticlePositions" );
-	self->totalInitialParticles = Dictionary_Entry_Value_GetCount( manualParticlePositions );
-	self->averageInitialParticlesPerCell = 0;
-}
-
-void _ManualParticleLayout_Delete( void* manualParticleLayout ) {
-	ManualParticleLayout* self = (ManualParticleLayout*)manualParticleLayout;
-
-	_GlobalParticleLayout_Delete( self  );
-}
-
-void _ManualParticleLayout_Print( void* manualParticleLayout, Stream* stream ) {
-	ManualParticleLayout* self  = (ManualParticleLayout*)manualParticleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "ManualParticleLayout (ptr): %p:\n", self );
-	Stream_Indent( stream );
-	
-	/* Parent class info */
-	_GlobalParticleLayout_Print( self, stream );
-	
-	/* ManualParticleLayout */
-	
-	Stream_UnIndent( stream );
-}
-
-void* _ManualParticleLayout_Copy( const void* manualParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ManualParticleLayout*		self                    = (ManualParticleLayout*)manualParticleLayout;
-	ManualParticleLayout*		newManualParticleLayout;
-	
-	newManualParticleLayout = (ManualParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-
-	return (void*)newManualParticleLayout;
-}
-
-void* _ManualParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(ManualParticleLayout);
-	Type                                                                        type = ManualParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _ManualParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _ManualParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _ManualParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _ManualParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _ManualParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _ManualParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _ManualParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _ManualParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _ManualParticleLayout_Destroy;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _GlobalParticleLayout_InitialiseParticles;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _ManualParticleLayout_InitialiseParticle;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	Dictionary*                                                           dictionary = NULL;
-
-	return (void*)_ManualParticleLayout_New(  MANUALPARTICLELAYOUT_PASSARGS  );
-}
-
-void _ManualParticleLayout_AssignFromXML( void* manualParticleLayout, Stg_ComponentFactory *cf, void* data ) {
-	ManualParticleLayout*      self       = (ManualParticleLayout*) manualParticleLayout;
-	Dictionary*                dictionary;
-	
-   _GlobalParticleLayout_AssignFromXML( self, cf, data );
-
-   dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-
-   _ManualParticleLayout_Init( self, dictionary );
-}
-	
-void _ManualParticleLayout_Build( void* manualParticleLayout, void* data ) {
-}
-void _ManualParticleLayout_Initialise( void* manualParticleLayout, void* data ) {
-}
-void _ManualParticleLayout_Execute( void* manualParticleLayout, void* data ) {
-}
-void _ManualParticleLayout_Destroy( void* manualParticleLayout, void* data ) {
-	ManualParticleLayout* self = (ManualParticleLayout*)manualParticleLayout;
-
-   _GlobalParticleLayout_Destroy( self, data );
-}
-
-void _ManualParticleLayout_InitialiseParticle( 
-		void* manualParticleLayout, 
-		void* _swarm, 
-		Particle_Index newParticle_I,
-		void* _particle )
-{
-	ManualParticleLayout*       self                    = (ManualParticleLayout*)manualParticleLayout;
-	Dictionary_Entry_Value*     manualParticlePositions = NULL;
-	Dictionary_Entry_Value*     particlePositionEntry   = NULL;
-	Dictionary*                 particlePositionDict    = NULL;
-	GlobalParticle*             particle                = (GlobalParticle*)_particle;
-
-	manualParticlePositions = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"manualParticlePositions"  );
-	particlePositionEntry = Dictionary_Entry_Value_GetElement( manualParticlePositions, newParticle_I );
-	particlePositionDict = Dictionary_Entry_Value_AsDictionary( particlePositionEntry );
-	particle->coord[I_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"x", 0.0  );
-	particle->coord[J_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"y", 0.0  );
-	particle->coord[K_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"z", 0.0  );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ManualParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/ManualParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,200 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ManualParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "ManualParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+const Type ManualParticleLayout_Type = "ManualParticleLayout";
+
+const Index ManualParticleLayout_Invalid = (Index)0;
+
+ManualParticleLayout* ManualParticleLayout_New( Name name,
+      AbstractContext* context, 
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles, 
+      double           averageInitialParticlesPerCell,
+      Dictionary*      dictionary ) 
+{
+	ManualParticleLayout* self = (ManualParticleLayout*) _ManualParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+	_ManualParticleLayout_Init( self, dictionary );
+	return self;
+}
+
+ManualParticleLayout* _ManualParticleLayout_New(  MANUALPARTICLELAYOUT_DEFARGS  )
+{
+	ManualParticleLayout* self;
+	
+	/* Allocate memory */
+	self = (ManualParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
+
+   self->dictionary = dictionary;
+
+	return self;
+}
+
+void _ManualParticleLayout_Init( void* manualParticleLayout, Dictionary* dictionary )
+{
+	ManualParticleLayout*	self                            = (ManualParticleLayout*)manualParticleLayout;
+	Dictionary_Entry_Value* manualParticlePositions         = NULL;
+
+	self->isConstructed = True;
+	self->dictionary    = dictionary;
+
+	manualParticlePositions = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"manualParticlePositions" );
+	self->totalInitialParticles = Dictionary_Entry_Value_GetCount( manualParticlePositions );
+	self->averageInitialParticlesPerCell = 0;
+}
+
+void _ManualParticleLayout_Delete( void* manualParticleLayout ) {
+	ManualParticleLayout* self = (ManualParticleLayout*)manualParticleLayout;
+
+	_GlobalParticleLayout_Delete( self  );
+}
+
+void _ManualParticleLayout_Print( void* manualParticleLayout, Stream* stream ) {
+	ManualParticleLayout* self  = (ManualParticleLayout*)manualParticleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "ManualParticleLayout (ptr): %p:\n", self );
+	Stream_Indent( stream );
+	
+	/* Parent class info */
+	_GlobalParticleLayout_Print( self, stream );
+	
+	/* ManualParticleLayout */
+	
+	Stream_UnIndent( stream );
+}
+
+void* _ManualParticleLayout_Copy( const void* manualParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ManualParticleLayout*		self                    = (ManualParticleLayout*)manualParticleLayout;
+	ManualParticleLayout*		newManualParticleLayout;
+	
+	newManualParticleLayout = (ManualParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+
+	return (void*)newManualParticleLayout;
+}
+
+void* _ManualParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(ManualParticleLayout);
+	Type                                                                        type = ManualParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _ManualParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _ManualParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _ManualParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _ManualParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _ManualParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _ManualParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _ManualParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _ManualParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _ManualParticleLayout_Destroy;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _GlobalParticleLayout_InitialiseParticles;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _ManualParticleLayout_InitialiseParticle;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	Dictionary*                                                           dictionary = NULL;
+
+	return (void*)_ManualParticleLayout_New(  MANUALPARTICLELAYOUT_PASSARGS  );
+}
+
+void _ManualParticleLayout_AssignFromXML( void* manualParticleLayout, Stg_ComponentFactory *cf, void* data ) {
+	ManualParticleLayout*      self       = (ManualParticleLayout*) manualParticleLayout;
+	Dictionary*                dictionary;
+	
+   _GlobalParticleLayout_AssignFromXML( self, cf, data );
+
+   dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+
+   _ManualParticleLayout_Init( self, dictionary );
+}
+	
+void _ManualParticleLayout_Build( void* manualParticleLayout, void* data ) {
+}
+void _ManualParticleLayout_Initialise( void* manualParticleLayout, void* data ) {
+}
+void _ManualParticleLayout_Execute( void* manualParticleLayout, void* data ) {
+}
+void _ManualParticleLayout_Destroy( void* manualParticleLayout, void* data ) {
+	ManualParticleLayout* self = (ManualParticleLayout*)manualParticleLayout;
+
+   _GlobalParticleLayout_Destroy( self, data );
+}
+
+void _ManualParticleLayout_InitialiseParticle( 
+		void* manualParticleLayout, 
+		void* _swarm, 
+		Particle_Index newParticle_I,
+		void* _particle )
+{
+	ManualParticleLayout*       self                    = (ManualParticleLayout*)manualParticleLayout;
+	Dictionary_Entry_Value*     manualParticlePositions = NULL;
+	Dictionary_Entry_Value*     particlePositionEntry   = NULL;
+	Dictionary*                 particlePositionDict    = NULL;
+	GlobalParticle*             particle                = (GlobalParticle*)_particle;
+
+	manualParticlePositions = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"manualParticlePositions"  );
+	particlePositionEntry = Dictionary_Entry_Value_GetElement( manualParticlePositions, newParticle_I );
+	particlePositionDict = Dictionary_Entry_Value_AsDictionary( particlePositionEntry );
+	particle->coord[I_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"x", 0.0  );
+	particle->coord[J_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"y", 0.0  );
+	particle->coord[K_AXIS] = Dictionary_GetDouble_WithDefault( particlePositionDict, (Dictionary_Entry_Key)"z", 0.0  );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/MeshParticleLayout.c
--- a/Swarm/src/MeshParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "PerCellParticleLayout.h"
-#include "MeshParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "Random.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-const Type MeshParticleLayout_Type = "MeshParticleLayout";
-
-
-MeshParticleLayout* MeshParticleLayout_New( 
-   Name                 name, 
-   AbstractContext* context,
-   CoordSystem      coordSystem,
-   Bool             weightsInitialisedAtStartup,
-   Mesh*            mesh,
-   Particle_InCellIndex cellParticleCount, 
-   unsigned int         seed ) 
-{
-	MeshParticleLayout* self = (MeshParticleLayout*) _MeshParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _PerCellParticleLayout_Init( self );
-	_MeshParticleLayout_Init( self, mesh, cellParticleCount, seed );
-
-	return self;
-}
-
-MeshParticleLayout* _MeshParticleLayout_New(  MESHPARTICLELAYOUT_DEFARGS  )
-{
-	MeshParticleLayout* self;
-
-   coordSystem = GlobalCoordSystem;   
-   weightsInitialisedAtStartup = False;
-	/* Allocate memory */
-	self = (MeshParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
-
-   self->mesh = mesh;
-   self->cellParticleCount = cellParticleCount;
-   self->seed = seed;
-
-	return self;
-}
-
-void _MeshParticleLayout_Init( void* meshParticleLayout, Mesh* mesh, Particle_InCellIndex cellParticleCount, unsigned int seed ) {
-	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
-
-	self->mesh = mesh;
-	self->isConstructed     = True;
-	self->cellParticleCount = cellParticleCount;
-	self->seed              = seed;
-	
-	Swarm_Random_Seed( self->seed );
-}
-
-
-void _MeshParticleLayout_Delete( void* meshParticleLayout ) {
-	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
-	
-	/* Stg_Class_Delete parent class */
-	_PerCellParticleLayout_Delete( self );
-}
-
-void _MeshParticleLayout_Print( void* meshParticleLayout, Stream* stream ) {
-	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
-	
-	/* Set the Journal for printing informations */
-	Stream* meshParticleLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( meshParticleLayoutStream, "MeshParticleLayout (ptr): %p:\n", self );
-	
-	/* Parent class info */
-	_PerCellParticleLayout_Print( self, stream );
-	
-	/* MeshParticleLayout */
-	Journal_Printf( meshParticleLayoutStream, "\tcellParticleCount: %u\n", self->cellParticleCount );
-	Journal_Printf( meshParticleLayoutStream, "\tseed: %u\n", self->seed );
-}
-
-
-void* _MeshParticleLayout_Copy( const void* meshParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	MeshParticleLayout*		self = (MeshParticleLayout*)meshParticleLayout;
-	MeshParticleLayout*		newMeshParticleLayout;
-	
-	newMeshParticleLayout = (MeshParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newMeshParticleLayout->cellParticleCount = self->cellParticleCount;
-	newMeshParticleLayout->seed = self->seed;
-	
-	return (void*)newMeshParticleLayout;
-}
-
-
-void* _MeshParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                     _sizeOfSelf = sizeof(MeshParticleLayout);
-	Type                                                                             type = MeshParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                     _delete = _MeshParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                       _print = _MeshParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                         _copy = _MeshParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _MeshParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                           _construct = _MeshParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                                   _build = _MeshParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                         _initialise = _MeshParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                               _execute = _MeshParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                               _destroy = _MeshParticleLayout_Destroy;
-	AllocationType                                                     nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
-	CoordSystem                                                               coordSystem = LocalCoordSystem;
-	Bool                                                      weightsInitialisedAtStartup = True;
-	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _MeshParticleLayout_InitialCount;
-	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _MeshParticleLayout_InitialiseParticlesOfCell;
-	Mesh*                                                                            mesh = NULL;
-	Particle_InCellIndex                                                cellParticleCount = 0;
-	unsigned int                                                                     seed = 0;
-
-	return (void*)_MeshParticleLayout_New(  MESHPARTICLELAYOUT_PASSARGS  );
-}
-
-void _MeshParticleLayout_AssignFromXML( void* meshParticleLayout, Stg_ComponentFactory* cf, void* data ) {
-	MeshParticleLayout*       self = (MeshParticleLayout*)meshParticleLayout;
-	Particle_InCellIndex        cellParticleCount;
-	unsigned int                seed;
-   Mesh* mesh = NULL;
-
-   _PerCellParticleLayout_AssignFromXML( self, cf, data );
-
-	cellParticleCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"cellParticleCount", 0  );
-	seed = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"seed", 13  );
-	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
-
-	_MeshParticleLayout_Init( self, mesh, cellParticleCount, seed );
-
-}
-	
-void _MeshParticleLayout_Build( void* meshParticleLayout, void* data ) {
-	MeshParticleLayout*       self = (MeshParticleLayout*)meshParticleLayout;
-
-	assert( self );
-
-	Stg_Component_Build( self->mesh, NULL, False );
-}
-	
-void _MeshParticleLayout_Initialise( void* meshParticleLayout, void* data ) {
-	MeshParticleLayout*       self = (MeshParticleLayout*)meshParticleLayout;
-
-	assert( self );
-
-	Stg_Component_Initialise( self->mesh, NULL, False );
-}
-	
-void _MeshParticleLayout_Execute( void* meshParticleLayout, void* data ) {
-	
-}
-	
-void _MeshParticleLayout_Destroy( void* meshParticleLayout, void* data ) {
-   MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
-
-   _PerCellParticleLayout_Destroy( self, data );
-}
-
-
-Particle_InCellIndex _MeshParticleLayout_InitialCount( void* meshParticleLayout, void* celllayout, Cell_Index cell_I ) {
-	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
-	return self->cellParticleCount;
-}
-
-void _MeshParticleLayout_InitialiseParticlesOfCell( void* meshParticleLayout, void* _swarm, Cell_Index cell_I ) {
-	MeshParticleLayout*	self = (MeshParticleLayout*)meshParticleLayout;
-	Swarm*              	swarm = (Swarm*)_swarm;
-	Coord               	min = {-1.0, -1.0, -1.0};
-	Coord               	max = {1.0, 1.0, 1.0};
-	Coord			localCoord;
-	double			basis[8];
-	unsigned		nDims = Mesh_GetDimSize( self->mesh );
-	double**		nodeCoords = self->mesh->verts;
-	unsigned		nNodes, *incNodes;
-	Particle_InCellIndex	particlesThisCell = swarm->cellParticleCountTbl[cell_I];
-	Particle_InCellIndex	cParticle_I = 0;
-	GlobalParticle*	        particle = NULL;
-	IArray*			inc;
-	unsigned		d_i, n_i;
-
-	assert( nDims == 2 || nDims == 3 );
-
-	inc = IArray_New();
-	Mesh_GetIncidence( self->mesh, (MeshTopology_Dim)nDims, cell_I, MT_VERTEX, 
-			   inc );
-	nNodes = IArray_GetSize( inc );
-	incNodes = (unsigned*)IArray_GetPtr( inc );
-
-	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {	
-		particle = (GlobalParticle*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		particle->owningCell = cell_I;
-		
-		for ( d_i = 0; d_i < nDims; d_i++ ) {
-			localCoord[d_i] = Swarm_Random_Random_WithMinMax( min[d_i], max[d_i] );
-		}
-
-		/* Convert the coordinate to global. Assumes quad or hex mesh. */
-		if( nDims == 2 ) {
-			basis[0] = 0.25 * (1.0 - localCoord[0]) * (1.0 - localCoord[1]);
-			basis[1] = 0.25 * (1.0 + localCoord[0]) * (1.0 - localCoord[1]);
-			basis[2] = 0.25 * (1.0 - localCoord[0]) * (1.0 + localCoord[1]);
-			basis[3] = 0.25 * (1.0 + localCoord[0]) * (1.0 + localCoord[1]);
-		}
-		else {
-			basis[0] = 0.125 * (1.0 - localCoord[0]) * (1.0 - localCoord[1]) * (1.0 - localCoord[2]);
-			basis[1] = 0.125 * (1.0 + localCoord[0]) * (1.0 - localCoord[1]) * (1.0 - localCoord[2]);
-			basis[2] = 0.125 * (1.0 - localCoord[0]) * (1.0 + localCoord[1]) * (1.0 - localCoord[2]);
-			basis[3] = 0.125 * (1.0 + localCoord[0]) * (1.0 + localCoord[1]) * (1.0 - localCoord[2]);
-			basis[4] = 0.125 * (1.0 - localCoord[0]) * (1.0 - localCoord[1]) * (1.0 + localCoord[2]);
-			basis[5] = 0.125 * (1.0 + localCoord[0]) * (1.0 - localCoord[1]) * (1.0 + localCoord[2]);
-			basis[6] = 0.125 * (1.0 - localCoord[0]) * (1.0 + localCoord[1]) * (1.0 + localCoord[2]);
-			basis[7] = 0.125 * (1.0 + localCoord[0]) * (1.0 + localCoord[1]) * (1.0 + localCoord[2]);
-		}
-
-		memset( particle->coord, 0, sizeof(double) * nDims );
-		for( d_i = 0; d_i < nDims; d_i++ ) {
-			for( n_i = 0; n_i < nNodes; n_i++ ) {
-				particle->coord[d_i] += basis[n_i] * nodeCoords[incNodes[n_i]][d_i];
-			}
-		}
-	}
-
-	NewClass_Delete( inc );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/MeshParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/MeshParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,277 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "PerCellParticleLayout.h"
+#include "MeshParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "Random.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+const Type MeshParticleLayout_Type = "MeshParticleLayout";
+
+
+MeshParticleLayout* MeshParticleLayout_New( 
+   Name                 name, 
+   AbstractContext* context,
+   CoordSystem      coordSystem,
+   Bool             weightsInitialisedAtStartup,
+   Mesh*            mesh,
+   Particle_InCellIndex cellParticleCount, 
+   unsigned int         seed ) 
+{
+	MeshParticleLayout* self = (MeshParticleLayout*) _MeshParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _PerCellParticleLayout_Init( self );
+	_MeshParticleLayout_Init( self, mesh, cellParticleCount, seed );
+
+	return self;
+}
+
+MeshParticleLayout* _MeshParticleLayout_New(  MESHPARTICLELAYOUT_DEFARGS  )
+{
+	MeshParticleLayout* self;
+
+   coordSystem = GlobalCoordSystem;   
+   weightsInitialisedAtStartup = False;
+	/* Allocate memory */
+	self = (MeshParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
+
+   self->mesh = mesh;
+   self->cellParticleCount = cellParticleCount;
+   self->seed = seed;
+
+	return self;
+}
+
+void _MeshParticleLayout_Init( void* meshParticleLayout, Mesh* mesh, Particle_InCellIndex cellParticleCount, unsigned int seed ) {
+	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
+
+	self->mesh = mesh;
+	self->isConstructed     = True;
+	self->cellParticleCount = cellParticleCount;
+	self->seed              = seed;
+	
+	Swarm_Random_Seed( self->seed );
+}
+
+
+void _MeshParticleLayout_Delete( void* meshParticleLayout ) {
+	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
+	
+	/* Stg_Class_Delete parent class */
+	_PerCellParticleLayout_Delete( self );
+}
+
+void _MeshParticleLayout_Print( void* meshParticleLayout, Stream* stream ) {
+	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
+	
+	/* Set the Journal for printing informations */
+	Stream* meshParticleLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( meshParticleLayoutStream, "MeshParticleLayout (ptr): %p:\n", self );
+	
+	/* Parent class info */
+	_PerCellParticleLayout_Print( self, stream );
+	
+	/* MeshParticleLayout */
+	Journal_Printf( meshParticleLayoutStream, "\tcellParticleCount: %u\n", self->cellParticleCount );
+	Journal_Printf( meshParticleLayoutStream, "\tseed: %u\n", self->seed );
+}
+
+
+void* _MeshParticleLayout_Copy( const void* meshParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	MeshParticleLayout*		self = (MeshParticleLayout*)meshParticleLayout;
+	MeshParticleLayout*		newMeshParticleLayout;
+	
+	newMeshParticleLayout = (MeshParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newMeshParticleLayout->cellParticleCount = self->cellParticleCount;
+	newMeshParticleLayout->seed = self->seed;
+	
+	return (void*)newMeshParticleLayout;
+}
+
+
+void* _MeshParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                     _sizeOfSelf = sizeof(MeshParticleLayout);
+	Type                                                                             type = MeshParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                     _delete = _MeshParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                       _print = _MeshParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                         _copy = _MeshParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _MeshParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                           _construct = _MeshParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                                   _build = _MeshParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                         _initialise = _MeshParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                               _execute = _MeshParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                               _destroy = _MeshParticleLayout_Destroy;
+	AllocationType                                                     nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
+	CoordSystem                                                               coordSystem = LocalCoordSystem;
+	Bool                                                      weightsInitialisedAtStartup = True;
+	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _MeshParticleLayout_InitialCount;
+	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _MeshParticleLayout_InitialiseParticlesOfCell;
+	Mesh*                                                                            mesh = NULL;
+	Particle_InCellIndex                                                cellParticleCount = 0;
+	unsigned int                                                                     seed = 0;
+
+	return (void*)_MeshParticleLayout_New(  MESHPARTICLELAYOUT_PASSARGS  );
+}
+
+void _MeshParticleLayout_AssignFromXML( void* meshParticleLayout, Stg_ComponentFactory* cf, void* data ) {
+	MeshParticleLayout*       self = (MeshParticleLayout*)meshParticleLayout;
+	Particle_InCellIndex        cellParticleCount;
+	unsigned int                seed;
+   Mesh* mesh = NULL;
+
+   _PerCellParticleLayout_AssignFromXML( self, cf, data );
+
+	cellParticleCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"cellParticleCount", 0  );
+	seed = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"seed", 13  );
+	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
+
+	_MeshParticleLayout_Init( self, mesh, cellParticleCount, seed );
+
+}
+	
+void _MeshParticleLayout_Build( void* meshParticleLayout, void* data ) {
+	MeshParticleLayout*       self = (MeshParticleLayout*)meshParticleLayout;
+
+	assert( self );
+
+	Stg_Component_Build( self->mesh, NULL, False );
+}
+	
+void _MeshParticleLayout_Initialise( void* meshParticleLayout, void* data ) {
+	MeshParticleLayout*       self = (MeshParticleLayout*)meshParticleLayout;
+
+	assert( self );
+
+	Stg_Component_Initialise( self->mesh, NULL, False );
+}
+	
+void _MeshParticleLayout_Execute( void* meshParticleLayout, void* data ) {
+	
+}
+	
+void _MeshParticleLayout_Destroy( void* meshParticleLayout, void* data ) {
+   MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
+
+   _PerCellParticleLayout_Destroy( self, data );
+}
+
+
+Particle_InCellIndex _MeshParticleLayout_InitialCount( void* meshParticleLayout, void* celllayout, Cell_Index cell_I ) {
+	MeshParticleLayout* self = (MeshParticleLayout*)meshParticleLayout;
+	return self->cellParticleCount;
+}
+
+void _MeshParticleLayout_InitialiseParticlesOfCell( void* meshParticleLayout, void* _swarm, Cell_Index cell_I ) {
+	MeshParticleLayout*	self = (MeshParticleLayout*)meshParticleLayout;
+	Swarm*              	swarm = (Swarm*)_swarm;
+	Coord               	min = {-1.0, -1.0, -1.0};
+	Coord               	max = {1.0, 1.0, 1.0};
+	Coord			localCoord;
+	double			basis[8];
+	unsigned		nDims = Mesh_GetDimSize( self->mesh );
+	double**		nodeCoords = self->mesh->verts;
+	unsigned		nNodes, *incNodes;
+	Particle_InCellIndex	particlesThisCell = swarm->cellParticleCountTbl[cell_I];
+	Particle_InCellIndex	cParticle_I = 0;
+	GlobalParticle*	        particle = NULL;
+	IArray*			inc;
+	unsigned		d_i, n_i;
+
+	assert( nDims == 2 || nDims == 3 );
+
+	inc = IArray_New();
+	Mesh_GetIncidence( self->mesh, (MeshTopology_Dim)nDims, cell_I, MT_VERTEX, 
+			   inc );
+	nNodes = IArray_GetSize( inc );
+	incNodes = (unsigned*)IArray_GetPtr( inc );
+
+	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {	
+		particle = (GlobalParticle*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		particle->owningCell = cell_I;
+		
+		for ( d_i = 0; d_i < nDims; d_i++ ) {
+			localCoord[d_i] = Swarm_Random_Random_WithMinMax( min[d_i], max[d_i] );
+		}
+
+		/* Convert the coordinate to global. Assumes quad or hex mesh. */
+		if( nDims == 2 ) {
+			basis[0] = 0.25 * (1.0 - localCoord[0]) * (1.0 - localCoord[1]);
+			basis[1] = 0.25 * (1.0 + localCoord[0]) * (1.0 - localCoord[1]);
+			basis[2] = 0.25 * (1.0 - localCoord[0]) * (1.0 + localCoord[1]);
+			basis[3] = 0.25 * (1.0 + localCoord[0]) * (1.0 + localCoord[1]);
+		}
+		else {
+			basis[0] = 0.125 * (1.0 - localCoord[0]) * (1.0 - localCoord[1]) * (1.0 - localCoord[2]);
+			basis[1] = 0.125 * (1.0 + localCoord[0]) * (1.0 - localCoord[1]) * (1.0 - localCoord[2]);
+			basis[2] = 0.125 * (1.0 - localCoord[0]) * (1.0 + localCoord[1]) * (1.0 - localCoord[2]);
+			basis[3] = 0.125 * (1.0 + localCoord[0]) * (1.0 + localCoord[1]) * (1.0 - localCoord[2]);
+			basis[4] = 0.125 * (1.0 - localCoord[0]) * (1.0 - localCoord[1]) * (1.0 + localCoord[2]);
+			basis[5] = 0.125 * (1.0 + localCoord[0]) * (1.0 - localCoord[1]) * (1.0 + localCoord[2]);
+			basis[6] = 0.125 * (1.0 - localCoord[0]) * (1.0 + localCoord[1]) * (1.0 + localCoord[2]);
+			basis[7] = 0.125 * (1.0 + localCoord[0]) * (1.0 + localCoord[1]) * (1.0 + localCoord[2]);
+		}
+
+		memset( particle->coord, 0, sizeof(double) * nDims );
+		for( d_i = 0; d_i < nDims; d_i++ ) {
+			for( n_i = 0; n_i < nNodes; n_i++ ) {
+				particle->coord[d_i] += basis[n_i] * nodeCoords[incNodes[n_i]][d_i];
+			}
+		}
+	}
+
+	NewClass_Delete( inc );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/OperatorSwarmVariable.c
--- a/Swarm/src/OperatorSwarmVariable.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,318 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: OperatorSwarmVariable.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <string.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "SwarmVariable_Register.h"
-#include "SwarmVariable.h"
-#include "OperatorSwarmVariable.h"
-#include "SwarmClass.h"
-
-#include <assert.h>
-
-const Type OperatorSwarmVariable_Type = "OperatorSwarmVariable";
-const Name defaultOperatorSwarmVariableName = "defaultOperatorSwarmVariableName";
-
-OperatorSwarmVariable* OperatorSwarmVariable_NewUnary( 
-	Name					name,
-	AbstractContext*	context,
-	void*					_swarmVariable,
-	Name					operatorName )
-{
-	SwarmVariable* swarmVariable = (SwarmVariable*) _swarmVariable;
-       	
-	return OperatorSwarmVariable_New( 
-		name,
-		context,
-		_OperatorSwarmVariable_UnaryValueAt, 
-		operatorName,
-		1,
-		&swarmVariable );
-}
-
-OperatorSwarmVariable* OperatorSwarmVariable_NewBinary( 
-	Name					name,
-	AbstractContext*	context,
-	void*					_swarmVariable1,
-	void*					_swarmVariable2,
-	Name					operatorName )
-{
-	SwarmVariable* swarmVariableList[2];
-       
-	swarmVariableList[0] = (SwarmVariable*) _swarmVariable1;
-	swarmVariableList[1] = (SwarmVariable*) _swarmVariable2;
-	
-	return OperatorSwarmVariable_New( 
-		name,
-		context,
-		_OperatorSwarmVariable_BinaryValueAt, 
-		operatorName,
-		2, 
-		swarmVariableList );
-}
-
-OperatorSwarmVariable* OperatorSwarmVariable_New( 
-	Name										name,
-	AbstractContext*						context,
-	SwarmVariable_ValueAtFunction*	_valueAt,
-	Name										operatorName,
-	Index										swarmVariableCount,
-	SwarmVariable**						swarmVariableList )
-{
-  OperatorSwarmVariable* self = (OperatorSwarmVariable*)_OperatorSwarmVariable_DefaultNew( name );
-
-	self->isConstructed = True;
-	_SwarmVariable_Init( (SwarmVariable*)self, context, swarmVariableList[0]->swarm, NULL, 0 );
-	_OperatorSwarmVariable_Init( self, operatorName, swarmVariableCount, swarmVariableList );
-
-	return self;
-}
-
-void* _OperatorSwarmVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(OperatorSwarmVariable);
-	Type                                                         type = OperatorSwarmVariable_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _OperatorSwarmVariable_Delete;
-	Stg_Class_PrintFunction*                                   _print = _OperatorSwarmVariable_Print;
-	Stg_Class_CopyFunction*                                     _copy = _OperatorSwarmVariable_Copy;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _OperatorSwarmVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _OperatorSwarmVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _OperatorSwarmVariable_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _OperatorSwarmVariable_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _OperatorSwarmVariable_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _OperatorSwarmVariable_Destroy;
-	AllocationType                                 nameAllocationType = NON_GLOBAL;
-	SwarmVariable_ValueAtFunction*                           _valueAt = _OperatorSwarmVariable_ValueAt;
-	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _OperatorSwarmVariable_GetMinGlobalMagnitude;
-	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _OperatorSwarmVariable_GetMaxGlobalMagnitude;
-
-	return (void*) _OperatorSwarmVariable_New(  OPERATORSWARMVARIABLE_PASSARGS  );
-}
-
-OperatorSwarmVariable* _OperatorSwarmVariable_New(  OPERATORSWARMVARIABLE_DEFARGS  ) {
-	OperatorSwarmVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(OperatorSwarmVariable) );
-	self = (OperatorSwarmVariable*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
-	
-	return self;
-}
-
-void _OperatorSwarmVariable_Delete( void* _swarmVariable ) {
-	OperatorSwarmVariable* self = (OperatorSwarmVariable*) _swarmVariable;
-
-	_SwarmVariable_Delete( self );
-}
-
-void _OperatorSwarmVariable_Print( void* _swarmVariable, Stream* stream ) {
-	OperatorSwarmVariable* self = (OperatorSwarmVariable*) _swarmVariable;
-	Index                  swarmVariable_I;
-
-	_SwarmVariable_Print( self, stream );
-
-	Journal_PrintValue( stream, self->swarmVariableCount );
-	for ( swarmVariable_I = 0 ; swarmVariable_I < self->swarmVariableCount ; swarmVariable_I++ ) 
-		Journal_Printf( stream, "\tSwarmVariable %u - '%s'\n", swarmVariable_I, self->swarmVariableList[ swarmVariable_I ]->name );
-
-}
-
-void _OperatorSwarmVariable_Init( void* _swarmVariable, Name operatorName, Index swarmVariableCount, SwarmVariable** swarmVariableList ) {
-	OperatorSwarmVariable*	self = (OperatorSwarmVariable*)_swarmVariable;
-	SwarmVariable*				swarmVariable;
-	Index							swarmVariable_I;
-	Stream*						errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	self->_operator = Operator_NewFromName( operatorName, swarmVariableList[0]->dofCount, self->dim );
-	self->dofCount = self->_operator->resultDofs; /* reset value */
-	self->swarmVariableCount = swarmVariableCount;
-   /* variable does not store data, so is not checkpointed */
-   self->isCheckpointedAndReloaded = False;
-
-	/* Copy swarm variable list */
-	self->swarmVariableList      = Memory_Alloc_Array( SwarmVariable*, swarmVariableCount, "Array of Swarm Variables" );
-	memcpy( self->swarmVariableList, swarmVariableList, swarmVariableCount * sizeof( SwarmVariable* ) );
-
-	for ( swarmVariable_I = 0 ; swarmVariable_I < swarmVariableCount ; swarmVariable_I++ ) {
-		swarmVariable = swarmVariableList[ swarmVariable_I ];
-		Journal_Firewall( swarmVariable != NULL, errorStream, 
-			"In func %s: SwarmVariable %u in list is NULL\n", __func__, swarmVariable_I );
-		Journal_Firewall( swarmVariable->dofCount <= MAX_DOF, errorStream, 
-			"In func %s: Swarm Variable '%s' has too many components.\n", __func__, swarmVariable->name );
-	}
-}
-
-void* _OperatorSwarmVariable_Copy( const void* swarmVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	OperatorSwarmVariable*	self = (OperatorSwarmVariable*)swarmVariable;
-	OperatorSwarmVariable*	newOperatorSwarmVariable;
-	
-	newOperatorSwarmVariable = (OperatorSwarmVariable*)_SwarmVariable_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newOperatorSwarmVariable->_operator              = self->_operator;
-	newOperatorSwarmVariable->swarmVariableCount     = self->swarmVariableCount;
-	
-	if (deep) {
-		newOperatorSwarmVariable->swarmVariableList = Memory_Alloc_Array( SwarmVariable*, self->swarmVariableCount, 
-				"Array of Swarm Variables" );
-		memcpy( newOperatorSwarmVariable->swarmVariableList, self->swarmVariableList, 
-				self->swarmVariableCount * sizeof( SwarmVariable* ) );
-	}
-	else 
-		newOperatorSwarmVariable->swarmVariableList = self->swarmVariableList;
-	
-	return (void*)newOperatorSwarmVariable;
-}
-
-void _OperatorSwarmVariable_AssignFromXML( void* swarmVariable, Stg_ComponentFactory* cf, void* data ) {
-	OperatorSwarmVariable*  self       = (OperatorSwarmVariable*) swarmVariable;
-	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	Dictionary_Entry_Value* list;
-	Index                   swarmVariableCount = 0;
-	Index                   swarmVariable_I;
-	Name                    swarmVariableName;
-	Name                    operatorName;
-	SwarmVariable**         swarmVariableList;
-	SwarmVariable_Register* swarmVariable_Register;
-
-	/* Call parent's construct function */
-	_SwarmVariable_AssignFromXML( self, cf, data );
-	swarmVariable_Register = self->swarm->swarmVariable_Register;
-
-	operatorName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Operator", ""  );
-
-	list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"SwarmVariables" );
-
-	swarmVariableCount = ( list ? Dictionary_Entry_Value_GetCount(list) : 1  );
-	swarmVariableList = Memory_Alloc_Array( SwarmVariable*, swarmVariableCount, "SwarmVars" );
-
-	for ( swarmVariable_I = 0 ; swarmVariable_I < swarmVariableCount ; swarmVariable_I++ ) {
-		swarmVariableName = (list ? 
-				Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, swarmVariable_I ) ) :
-				Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"SwarmVariable" )  );
-
-		/* Check in swarmVariable_Register first before assuming in LiveComponentRegister */
-		Journal_PrintfL( cf->infoStream, 2, "Looking for SwarmVariable '%s' in swarmVariable_Register.\n",
-				swarmVariableName );
-		swarmVariableList[swarmVariable_I] = (SwarmVariable*) 
-			SwarmVariable_Register_GetByName( swarmVariable_Register, swarmVariableName );
-		
-		if ( !swarmVariableList[swarmVariable_I] )
-			swarmVariableList[swarmVariable_I] = 
-				Stg_ComponentFactory_ConstructByName( cf, (Name)swarmVariableName, SwarmVariable, True, data  );
-	}
-
-	_SwarmVariable_AssignFromXML( self, cf, data );
-	_OperatorSwarmVariable_Init( self, operatorName, swarmVariableCount, swarmVariableList );
-
-	Memory_Free( swarmVariableList );
-}
-
-void _OperatorSwarmVariable_Build( void* swarmVariable, void* data ) {
-	OperatorSwarmVariable* self = (OperatorSwarmVariable*) swarmVariable;
-	Index                  swarmVariable_I;
-
-	for ( swarmVariable_I = 0 ; swarmVariable_I < self->swarmVariableCount ; swarmVariable_I++ ) 
-		Stg_Component_Build( self->swarmVariableList[ swarmVariable_I ] , data, False );
-}
-
-void _OperatorSwarmVariable_Execute( void* swarmVariable, void* data ) {}
-
-void _OperatorSwarmVariable_Destroy( void* swarmVariable, void* data ) {
-	OperatorSwarmVariable* self = (OperatorSwarmVariable*)swarmVariable;
-
-	Memory_Free( self->swarmVariableList );
-
-	_SwarmVariable_Destroy( self, data );
-}
-
-void _OperatorSwarmVariable_Initialise( void* swarmVariable, void* data ) {
-	OperatorSwarmVariable* self = (OperatorSwarmVariable*) swarmVariable;
-	Index                  swarmVariable_I;
-
-	for ( swarmVariable_I = 0 ; swarmVariable_I < self->swarmVariableCount ; swarmVariable_I++ ) 
-		Stg_Component_Initialise( self->swarmVariableList[ swarmVariable_I ] , data, False );
-}
-
-double _OperatorSwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) { 
-	/* Just use particle function */
-	return _SwarmVariable_GetMinGlobalMagnitude( swarmVariable); 
-}
-double _OperatorSwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
-	/* Just use particle function */
-	return _SwarmVariable_GetMaxGlobalMagnitude( swarmVariable); 
-}
-
-void _OperatorSwarmVariable_ValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	OperatorSwarmVariable* self            = (OperatorSwarmVariable*) swarmVariable;
-
-	switch ( self->swarmVariableCount ) {
-		case 1:
-			self->_valueAt = _OperatorSwarmVariable_UnaryValueAt; break;
-		case 2:
-			self->_valueAt = _OperatorSwarmVariable_BinaryValueAt; break;
-		default:
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-					"Can't use func '%s' with swarmVariableCount = %d\n", __func__, self->swarmVariableCount );
-	}
-
-	SwarmVariable_ValueAt( self, lParticle_I, value );
-}
-
-void _OperatorSwarmVariable_UnaryValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	OperatorSwarmVariable* self            = (OperatorSwarmVariable*) swarmVariable;
-	SwarmVariable*         swarm0          = self->swarmVariableList[0];
-	double                 swarmValue[ MAX_DOF ]; 
-
-	SwarmVariable_ValueAt( swarm0, lParticle_I, swarmValue );
-	Operator_CarryOutUnaryOperation( self->_operator, swarmValue, value );
-}
-
-void _OperatorSwarmVariable_BinaryValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	OperatorSwarmVariable* self            = (OperatorSwarmVariable*) swarmVariable;
-	SwarmVariable*         swarm0          = self->swarmVariableList[0];
-	SwarmVariable*         swarm1          = self->swarmVariableList[1];
-	double                 swarmValue0[ MAX_DOF ]; 
-	double                 swarmValue1[ MAX_DOF ]; 
-
-	SwarmVariable_ValueAt( swarm0, lParticle_I, swarmValue0 );
-	SwarmVariable_ValueAt( swarm1, lParticle_I, swarmValue1 );
-
-	Operator_CarryOutBinaryOperation( self->_operator, swarmValue0, swarmValue1, value ); 
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/OperatorSwarmVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/OperatorSwarmVariable.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,318 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: OperatorSwarmVariable.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <string.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "SwarmVariable_Register.h"
+#include "SwarmVariable.h"
+#include "OperatorSwarmVariable.h"
+#include "SwarmClass.h"
+
+#include <assert.h>
+
+const Type OperatorSwarmVariable_Type = "OperatorSwarmVariable";
+const Name defaultOperatorSwarmVariableName = "defaultOperatorSwarmVariableName";
+
+OperatorSwarmVariable* OperatorSwarmVariable_NewUnary( 
+	Name					name,
+	AbstractContext*	context,
+	void*					_swarmVariable,
+	Name					operatorName )
+{
+	SwarmVariable* swarmVariable = (SwarmVariable*) _swarmVariable;
+       	
+	return OperatorSwarmVariable_New( 
+		name,
+		context,
+		_OperatorSwarmVariable_UnaryValueAt, 
+		operatorName,
+		1,
+		&swarmVariable );
+}
+
+OperatorSwarmVariable* OperatorSwarmVariable_NewBinary( 
+	Name					name,
+	AbstractContext*	context,
+	void*					_swarmVariable1,
+	void*					_swarmVariable2,
+	Name					operatorName )
+{
+	SwarmVariable* swarmVariableList[2];
+       
+	swarmVariableList[0] = (SwarmVariable*) _swarmVariable1;
+	swarmVariableList[1] = (SwarmVariable*) _swarmVariable2;
+	
+	return OperatorSwarmVariable_New( 
+		name,
+		context,
+		_OperatorSwarmVariable_BinaryValueAt, 
+		operatorName,
+		2, 
+		swarmVariableList );
+}
+
+OperatorSwarmVariable* OperatorSwarmVariable_New( 
+	Name										name,
+	AbstractContext*						context,
+	SwarmVariable_ValueAtFunction*	_valueAt,
+	Name										operatorName,
+	Index										swarmVariableCount,
+	SwarmVariable**						swarmVariableList )
+{
+  OperatorSwarmVariable* self = (OperatorSwarmVariable*)_OperatorSwarmVariable_DefaultNew( name );
+
+	self->isConstructed = True;
+	_SwarmVariable_Init( (SwarmVariable*)self, context, swarmVariableList[0]->swarm, NULL, 0 );
+	_OperatorSwarmVariable_Init( self, operatorName, swarmVariableCount, swarmVariableList );
+
+	return self;
+}
+
+void* _OperatorSwarmVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(OperatorSwarmVariable);
+	Type                                                         type = OperatorSwarmVariable_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _OperatorSwarmVariable_Delete;
+	Stg_Class_PrintFunction*                                   _print = _OperatorSwarmVariable_Print;
+	Stg_Class_CopyFunction*                                     _copy = _OperatorSwarmVariable_Copy;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _OperatorSwarmVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _OperatorSwarmVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _OperatorSwarmVariable_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _OperatorSwarmVariable_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _OperatorSwarmVariable_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _OperatorSwarmVariable_Destroy;
+	AllocationType                                 nameAllocationType = NON_GLOBAL;
+	SwarmVariable_ValueAtFunction*                           _valueAt = _OperatorSwarmVariable_ValueAt;
+	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _OperatorSwarmVariable_GetMinGlobalMagnitude;
+	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _OperatorSwarmVariable_GetMaxGlobalMagnitude;
+
+	return (void*) _OperatorSwarmVariable_New(  OPERATORSWARMVARIABLE_PASSARGS  );
+}
+
+OperatorSwarmVariable* _OperatorSwarmVariable_New(  OPERATORSWARMVARIABLE_DEFARGS  ) {
+	OperatorSwarmVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(OperatorSwarmVariable) );
+	self = (OperatorSwarmVariable*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
+	
+	return self;
+}
+
+void _OperatorSwarmVariable_Delete( void* _swarmVariable ) {
+	OperatorSwarmVariable* self = (OperatorSwarmVariable*) _swarmVariable;
+
+	_SwarmVariable_Delete( self );
+}
+
+void _OperatorSwarmVariable_Print( void* _swarmVariable, Stream* stream ) {
+	OperatorSwarmVariable* self = (OperatorSwarmVariable*) _swarmVariable;
+	Index                  swarmVariable_I;
+
+	_SwarmVariable_Print( self, stream );
+
+	Journal_PrintValue( stream, self->swarmVariableCount );
+	for ( swarmVariable_I = 0 ; swarmVariable_I < self->swarmVariableCount ; swarmVariable_I++ ) 
+		Journal_Printf( stream, "\tSwarmVariable %u - '%s'\n", swarmVariable_I, self->swarmVariableList[ swarmVariable_I ]->name );
+
+}
+
+void _OperatorSwarmVariable_Init( void* _swarmVariable, Name operatorName, Index swarmVariableCount, SwarmVariable** swarmVariableList ) {
+	OperatorSwarmVariable*	self = (OperatorSwarmVariable*)_swarmVariable;
+	SwarmVariable*				swarmVariable;
+	Index							swarmVariable_I;
+	Stream*						errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	self->_operator = Operator_NewFromName( operatorName, swarmVariableList[0]->dofCount, self->dim );
+	self->dofCount = self->_operator->resultDofs; /* reset value */
+	self->swarmVariableCount = swarmVariableCount;
+   /* variable does not store data, so is not checkpointed */
+   self->isCheckpointedAndReloaded = False;
+
+	/* Copy swarm variable list */
+	self->swarmVariableList      = Memory_Alloc_Array( SwarmVariable*, swarmVariableCount, "Array of Swarm Variables" );
+	memcpy( self->swarmVariableList, swarmVariableList, swarmVariableCount * sizeof( SwarmVariable* ) );
+
+	for ( swarmVariable_I = 0 ; swarmVariable_I < swarmVariableCount ; swarmVariable_I++ ) {
+		swarmVariable = swarmVariableList[ swarmVariable_I ];
+		Journal_Firewall( swarmVariable != NULL, errorStream, 
+			"In func %s: SwarmVariable %u in list is NULL\n", __func__, swarmVariable_I );
+		Journal_Firewall( swarmVariable->dofCount <= MAX_DOF, errorStream, 
+			"In func %s: Swarm Variable '%s' has too many components.\n", __func__, swarmVariable->name );
+	}
+}
+
+void* _OperatorSwarmVariable_Copy( const void* swarmVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	OperatorSwarmVariable*	self = (OperatorSwarmVariable*)swarmVariable;
+	OperatorSwarmVariable*	newOperatorSwarmVariable;
+	
+	newOperatorSwarmVariable = (OperatorSwarmVariable*)_SwarmVariable_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newOperatorSwarmVariable->_operator              = self->_operator;
+	newOperatorSwarmVariable->swarmVariableCount     = self->swarmVariableCount;
+	
+	if (deep) {
+		newOperatorSwarmVariable->swarmVariableList = Memory_Alloc_Array( SwarmVariable*, self->swarmVariableCount, 
+				"Array of Swarm Variables" );
+		memcpy( newOperatorSwarmVariable->swarmVariableList, self->swarmVariableList, 
+				self->swarmVariableCount * sizeof( SwarmVariable* ) );
+	}
+	else 
+		newOperatorSwarmVariable->swarmVariableList = self->swarmVariableList;
+	
+	return (void*)newOperatorSwarmVariable;
+}
+
+void _OperatorSwarmVariable_AssignFromXML( void* swarmVariable, Stg_ComponentFactory* cf, void* data ) {
+	OperatorSwarmVariable*  self       = (OperatorSwarmVariable*) swarmVariable;
+	Dictionary*             dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	Dictionary_Entry_Value* list;
+	Index                   swarmVariableCount = 0;
+	Index                   swarmVariable_I;
+	Name                    swarmVariableName;
+	Name                    operatorName;
+	SwarmVariable**         swarmVariableList;
+	SwarmVariable_Register* swarmVariable_Register;
+
+	/* Call parent's construct function */
+	_SwarmVariable_AssignFromXML( self, cf, data );
+	swarmVariable_Register = self->swarm->swarmVariable_Register;
+
+	operatorName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Operator", ""  );
+
+	list = Dictionary_Get( dictionary, (Dictionary_Entry_Key)"SwarmVariables" );
+
+	swarmVariableCount = ( list ? Dictionary_Entry_Value_GetCount(list) : 1  );
+	swarmVariableList = Memory_Alloc_Array( SwarmVariable*, swarmVariableCount, "SwarmVars" );
+
+	for ( swarmVariable_I = 0 ; swarmVariable_I < swarmVariableCount ; swarmVariable_I++ ) {
+		swarmVariableName = (list ? 
+				Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, swarmVariable_I ) ) :
+				Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"SwarmVariable" )  );
+
+		/* Check in swarmVariable_Register first before assuming in LiveComponentRegister */
+		Journal_PrintfL( cf->infoStream, 2, "Looking for SwarmVariable '%s' in swarmVariable_Register.\n",
+				swarmVariableName );
+		swarmVariableList[swarmVariable_I] = (SwarmVariable*) 
+			SwarmVariable_Register_GetByName( swarmVariable_Register, swarmVariableName );
+		
+		if ( !swarmVariableList[swarmVariable_I] )
+			swarmVariableList[swarmVariable_I] = 
+				Stg_ComponentFactory_ConstructByName( cf, (Name)swarmVariableName, SwarmVariable, True, data  );
+	}
+
+	_SwarmVariable_AssignFromXML( self, cf, data );
+	_OperatorSwarmVariable_Init( self, operatorName, swarmVariableCount, swarmVariableList );
+
+	Memory_Free( swarmVariableList );
+}
+
+void _OperatorSwarmVariable_Build( void* swarmVariable, void* data ) {
+	OperatorSwarmVariable* self = (OperatorSwarmVariable*) swarmVariable;
+	Index                  swarmVariable_I;
+
+	for ( swarmVariable_I = 0 ; swarmVariable_I < self->swarmVariableCount ; swarmVariable_I++ ) 
+		Stg_Component_Build( self->swarmVariableList[ swarmVariable_I ] , data, False );
+}
+
+void _OperatorSwarmVariable_Execute( void* swarmVariable, void* data ) {}
+
+void _OperatorSwarmVariable_Destroy( void* swarmVariable, void* data ) {
+	OperatorSwarmVariable* self = (OperatorSwarmVariable*)swarmVariable;
+
+	Memory_Free( self->swarmVariableList );
+
+	_SwarmVariable_Destroy( self, data );
+}
+
+void _OperatorSwarmVariable_Initialise( void* swarmVariable, void* data ) {
+	OperatorSwarmVariable* self = (OperatorSwarmVariable*) swarmVariable;
+	Index                  swarmVariable_I;
+
+	for ( swarmVariable_I = 0 ; swarmVariable_I < self->swarmVariableCount ; swarmVariable_I++ ) 
+		Stg_Component_Initialise( self->swarmVariableList[ swarmVariable_I ] , data, False );
+}
+
+double _OperatorSwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) { 
+	/* Just use particle function */
+	return _SwarmVariable_GetMinGlobalMagnitude( swarmVariable); 
+}
+double _OperatorSwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
+	/* Just use particle function */
+	return _SwarmVariable_GetMaxGlobalMagnitude( swarmVariable); 
+}
+
+void _OperatorSwarmVariable_ValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	OperatorSwarmVariable* self            = (OperatorSwarmVariable*) swarmVariable;
+
+	switch ( self->swarmVariableCount ) {
+		case 1:
+			self->_valueAt = _OperatorSwarmVariable_UnaryValueAt; break;
+		case 2:
+			self->_valueAt = _OperatorSwarmVariable_BinaryValueAt; break;
+		default:
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+					"Can't use func '%s' with swarmVariableCount = %d\n", __func__, self->swarmVariableCount );
+	}
+
+	SwarmVariable_ValueAt( self, lParticle_I, value );
+}
+
+void _OperatorSwarmVariable_UnaryValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	OperatorSwarmVariable* self            = (OperatorSwarmVariable*) swarmVariable;
+	SwarmVariable*         swarm0          = self->swarmVariableList[0];
+	double                 swarmValue[ MAX_DOF ]; 
+
+	SwarmVariable_ValueAt( swarm0, lParticle_I, swarmValue );
+	Operator_CarryOutUnaryOperation( self->_operator, swarmValue, value );
+}
+
+void _OperatorSwarmVariable_BinaryValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	OperatorSwarmVariable* self            = (OperatorSwarmVariable*) swarmVariable;
+	SwarmVariable*         swarm0          = self->swarmVariableList[0];
+	SwarmVariable*         swarm1          = self->swarmVariableList[1];
+	double                 swarmValue0[ MAX_DOF ]; 
+	double                 swarmValue1[ MAX_DOF ]; 
+
+	SwarmVariable_ValueAt( swarm0, lParticle_I, swarmValue0 );
+	SwarmVariable_ValueAt( swarm1, lParticle_I, swarmValue1 );
+
+	Operator_CarryOutBinaryOperation( self->_operator, swarmValue0, swarmValue1, value ); 
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleCommHandler.c
--- a/Swarm/src/ParticleCommHandler.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,693 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ParticleCommHandler.c 4148 2007-06-26 03:49:27Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleCommHandler.h"
-
-#include "SwarmClass.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-const Type ParticleCommHandler_Type = "ParticleCommHandler";
-
-/* MPI tags */
-static const int SHADOW_PARTICLE_COUNTS_PER_CELL = 10;
-static const int SHADOW_PARTICLES = 20;
-
-ParticleCommHandler* _ParticleCommHandler_New(  PARTICLECOMMHANDLER_DEFARGS  )
-{
-	ParticleCommHandler* self;
-	
-	/* Allocate memory */
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (ParticleCommHandler*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* General info */
-	/* Virtual info */
-	self->allocateOutgoingCountArrays = _allocateOutgoingCountArrays;
-	self->allocateOutgoingParticleArrays	= _allocateOutgoingParticleArrays,
-	self->freeOutgoingArrays = _freeOutgoingArrays,
-	self->allocateIncomingCountArrays = _allocateIncomingCountArrays,
-	self->allocateIncomingParticleArrays = _allocateIncomingParticleArrays,
-	self->freeIncomingArrays = _freeIncomingArrays,
-	self->beginReceiveOfIncomingParticleCounts = _beginReceiveOfIncomingParticleCounts,
-	self->finishReceiveOfIncomingParticleCounts = _finishReceiveOfIncomingParticleCounts,
-	self->beginReceiveOfIncomingParticles = _beginReceiveOfIncomingParticles,
-	self->finishReceiveOfIncomingParticlesAndUpdateIndices = _finishReceiveOfIncomingParticlesAndUpdateIndices,
-	self->sendOutgoingParticleCounts = _sendOutgoingParticleCounts,
-	self->beginSendingParticles = _beginSendingParticles,
-	self->confirmOutgoingSendsCompleted = _confirmOutgoingSendsCompleted,
-	self->_commFunction = _commFunction;
-	
-	/* ParticleCommHandler info */
-	if( initFlag ){
-		_ParticleCommHandler_Init( self );
-	}
-	
-	return self;
-}
-
-
-void _ParticleCommHandler_Init(
-		ParticleCommHandler*     self )
-{
-	self->isConstructed = True;
-	self->swarm = NULL;
-	self->debug = Stream_RegisterChild( Swarm_Debug, self->type );
-
-	_ParticleCommHandler_ZeroShadowCommStrategyCounters( self );
-
-	self->shadowParticlesLeavingMeIndices = NULL;
-	self->shadowParticlesLeavingMeCountsPerCell = NULL;
-	self->shadowParticlesLeavingMeTotalCounts = NULL;
-	self->shadowParticlesLeavingMe = NULL;
-	self->shadowParticlesLeavingMeHandles = NULL;
-
-	self->particlesArrivingFromNbrShadowCellCounts = NULL;
-	self->particlesArrivingFromNbrShadowCellCountsHandles = NULL;
-	self->particlesArrivingFromNbrShadowCellsTotalCounts = NULL;
-	self->particlesArrivingFromNbrShadowCells = NULL;
-	self->particlesArrivingFromNbrShadowCellsHandles = NULL;
-}
-
-
-void _ParticleCommHandler_Delete(void* pCommsHandler ) {
-	/* Nothing to do, as the temporary arrays are deleted each step as soon as they are finished with. */
-	_Stg_Class_Delete( pCommsHandler );
-}
-
-
-void _ParticleCommHandler_Print( void* pCommsHandler, Stream* stream ) {
-	ParticleCommHandler*	self = (ParticleCommHandler*)pCommsHandler;
-	
-	/* General info */
-	Journal_Printf( stream, "ParticleCommHandler (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_Stg_Class_Print( self, stream );
-
-	/* Virtual info */
-	Journal_Printf( stream, "self->_commFunction(ptr): %p\n", 
-		self->_commFunction );
-
-	/* class info */	
-	Journal_Printf( stream, "self->swarm (ptr): %p\n", self->swarm ); 
-	Journal_Printf( stream, "self->shadowParticlesLeavingMeTotalCount: %d\n", self->shadowParticlesLeavingMeTotalCount ); 
-	Journal_Printf( stream, "self->shadowParticlesLeavingMeUnfilledCount: %d\n", self->shadowParticlesLeavingMeUnfilledCount ); 
-	Journal_Printf( stream, "self->currShadowParticleLeavingMeIndex: %d\n", self->currShadowParticleLeavingMeIndex ); 
-	Journal_Printf( stream, "self->shadowParticlesLeavingMeIndices (ptr): %p\n", self->shadowParticlesLeavingMeIndices ); 
-	Journal_Printf( stream, "self->currParticleLeavingMyDomainIndex: %d\n", self->currParticleLeavingMyDomainIndex ); 
-}
-
-
-void* _ParticleCommHandler_Copy( const void* particleCommHandler, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-
-	// TODO: put back in.
-	assert(0);
-
-}
-
-void _ParticleCommHandler_AssignFromXML( void* pCommHandler, Stg_ComponentFactory* cf, void* data ){
-	ParticleCommHandler*	self	= (ParticleCommHandler*)pCommHandler;
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !self->context  )
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-}
-	
-void _ParticleCommHandler_Build( void* pCommsHandler, void *data ){
-	
-}
-	
-void _ParticleCommHandler_Initialise( void* pCommsHandler, void *data ){
-	
-}
-	
-void _ParticleCommHandler_Execute( void* pCommsHandler, void *data ){
-}
-
-void _ParticleCommHandler_Destroy( void* pCommsHandler, void *data ){
-	
-}
-
-void _ParticleCommHandler_AllocateOutgoingParticlesArrays( ParticleCommHandler* self ) {
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		        nbrCount = procNbrInfo->procNbrCnt;
-	Neighbour_Index		        nbr_I;
-	SizeT				particlesArrayBytes;
-
-	/* Allocate the list of shadow particle indices to all nbrs */
-	self->shadowParticlesLeavingMeIndices = Memory_Alloc_Array( Particle_Index, self->shadowParticlesLeavingMeTotalCount,
-		"self->shadowParticlesLeavingMeIndices" );
-	self->shadowParticlesLeavingMeHandles = Memory_Alloc_Array(
-		MPI_Request*, procNbrInfo->procNbrCnt,
-		"ParticleCommHandler->shadowParticlesLeavingMeHandles");
-	self->shadowParticlesLeavingMe = Memory_Alloc_Array(
-		Particle*, procNbrInfo->procNbrCnt,
-		"ParticleCommHandler->shadowParticlesLeavingMe" );
-
-	for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
-
-		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] == 0 ) {
-			/* If we're not sending any particles to this proc, skip to next */
-			self->shadowParticlesLeavingMeHandles[nbr_I] = NULL;
-			self->shadowParticlesLeavingMe[nbr_I] = NULL;
-		}
-		else {
-			self->shadowParticlesLeavingMeHandles[nbr_I] = Memory_Alloc( MPI_Request,
-				"ParticleCommHandler->shadowParticlesLeavingMeHandles[]" );
-			particlesArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
-				self->shadowParticlesLeavingMeTotalCounts[nbr_I];
-			self->shadowParticlesLeavingMe[nbr_I] = (Particle*)Memory_Alloc_Bytes( particlesArrayBytes,
-				"Particle", "ParticleCommHandler->shadowParticlesLeavingMe[]" );
-		}
-	}
-}
-
-
-void _ParticleCommHandler_BeginReceiveOfIncomingParticleCounts( ParticleCommHandler* self ) {
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		        nbr_I;
-	Processor_Index		        proc_I;
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		proc_I = procNbrInfo->procNbrTbl[nbr_I];
-		MPI_Irecv( self->particlesArrivingFromNbrShadowCellCounts[nbr_I], cellShadowInfo->procShadowedCnt[nbr_I],
-			MPI_UNSIGNED, proc_I, SHADOW_PARTICLE_COUNTS_PER_CELL, self->swarm->comm,
-			self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I] );
-	}
-}
-
-
-void _ParticleCommHandler_FinishReceiveOfIncomingParticleCounts( ParticleCommHandler* self ) {
-	Cell_ShadowTransferIndex	stCell_I;
-	MPI_Status			status;
-	Processor_Index			proc_I;
-	Particle_Index			incomingCellParticleCount = 0;
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		        nbr_I;
-
-	/* TODO: may be worth converting the below into an MPI_Test loop */
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		proc_I = procNbrInfo->procNbrTbl[nbr_I];
-		
-		MPI_Wait( self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I], &status );
-
-		Journal_DPrintfL( self->debug, 1, "proc %d: recv shadow counts from nbr %d (rank %d):\n",
-			self->swarm->myRank, nbr_I, proc_I );
-		Journal_DPrintfL( self->debug, 2, "\tare [" );
-		self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] = 0;
-
-		for ( stCell_I=0; stCell_I < cellShadowInfo->procShadowedCnt[nbr_I]; stCell_I++ ) {
-			incomingCellParticleCount = self->particlesArrivingFromNbrShadowCellCounts[nbr_I][stCell_I];
-			Journal_DPrintfL( self->debug, 2, "%d, ", incomingCellParticleCount );
-			self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] += incomingCellParticleCount;
-		}
-		Journal_DPrintfL( self->debug, 2, "]\n" );
-		Journal_DPrintfL( self->debug, 1, "(Proc %d):....totalled to %d\n", self->swarm->myRank,
-			self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] );
-	}
-}
-
-
-void _ParticleCommHandler_AllocateIncomingParticlesArrays( ParticleCommHandler* self ) {
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		        nbr_I;
-	SizeT                           incomingViaShadowArrayBytes = 0;
-
-	self->particlesArrivingFromNbrShadowCellsHandles = Memory_Alloc_Array(
-		MPI_Request*, procNbrInfo->procNbrCnt,
-		"ParticleCommHandler->particlesArrivingFromNbrShadowCellsHandles");
-	self->particlesArrivingFromNbrShadowCells = Memory_Alloc_Array(
-		Particle*, procNbrInfo->procNbrCnt,
-		"ParticleCommHandler->particlesArrivingFromNbrShadowCells" );
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-
-		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] == 0 ) {
-			/* No particles to receive from this proc -> just clear recv ptr */
-			self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] = NULL;
-			self->particlesArrivingFromNbrShadowCells[nbr_I] = NULL;
-		}	
-		else { 
-			self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] =
-				Memory_Alloc(
-					MPI_Request,
-					"ParticleCommHandler->particlesArrivingFromNbrShadowCellsHandles[]" );
-
-			/* allocate particles recv array to right size */
-			incomingViaShadowArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
-				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
-			self->particlesArrivingFromNbrShadowCells[nbr_I] = (Particle*)Memory_Alloc_Bytes( incomingViaShadowArrayBytes,
-				"Particle", "particleCommHandler->particlesArrivingFromNbrShadowCells[]" );
-		}
-	}
-}
-
-
-void _ParticleCommHandler_BeginReceiveOfIncomingParticles( ParticleCommHandler* self ) {
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	SizeT                           incomingViaShadowArrayBytes = 0;
-	Neighbour_Index		        nbr_I;
-	Processor_Index			proc_I;
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] != 0 ) {
-			proc_I = procNbrInfo->procNbrTbl[nbr_I];
-
-			/* start non-blocking recv of particles */
-			incomingViaShadowArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
-				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
-			MPI_Irecv( self->particlesArrivingFromNbrShadowCells[nbr_I], incomingViaShadowArrayBytes, MPI_BYTE,
-				proc_I, SHADOW_PARTICLES, self->swarm->comm,
-				self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] );
-		}
-	}
-}
-
-void _ParticleCommHandler_AllocateOutgoingCountArrays( ParticleCommHandler* self ) {
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-
-	Neighbour_Index		nbrCount = procNbrInfo->procNbrCnt;
-
-	self->shadowParticlesLeavingMeCountsPerCell = Memory_Alloc_2DComplex(
-		Particle_Index, nbrCount, cellShadowInfo->procShadowCnt,
-		"ParticleCommHandler->shadowParticlesLeavingMeCountsPerCell" );
-	self->shadowParticlesLeavingMeTotalCounts = Memory_Alloc_Array( Particle_Index, nbrCount,
-		"ParticleCommHandler->shadowParticlesLeavingMeTotalCounts" );
-}
-
-
-void _ParticleCommHandler_ConfirmOutgoingSendsCompleted( ParticleCommHandler* self ) {
-	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		nbr_I;
-	MPI_Status		status;
-
-	/* MPI_Wait for all shadow sends to complete */
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] > 0 ) {
-			MPI_Wait( self->shadowParticlesLeavingMeHandles[nbr_I], &status );
-		}	
-	}
-}
-
-
-void _ParticleCommHandler_AllocateIncomingCountArrays( ParticleCommHandler* self )
-{
-	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		nbr_I;
-	Neighbour_Index         nbrCount = procNbrInfo->procNbrCnt;
-
-	self->particlesArrivingFromNbrShadowCellCounts = Memory_Alloc_2DComplex(
-		Particle_Index, nbrCount, cellShadowInfo->procShadowedCnt,
-		"ParticleCommHandler->particlesArrivingFromNbrShadowCellCounts" );
-	self->particlesArrivingFromNbrShadowCellCountsHandles = Memory_Alloc_Array( MPI_Request*, nbrCount,
-		"ParticleCommHandler->particlesArrivingFromNbrShadowCellCountsHandles" );
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I] = Memory_Alloc( MPI_Request,
-			"ParticleCommHandler->particlesArrivingFromNbrShadowCellCountsHandles[]" );
-	}
-	self->particlesArrivingFromNbrShadowCellsTotalCounts = Memory_Alloc_Array( Particle_Index, nbrCount,
-		"ParticleCommHandler->particlesArrivingFromNbrShadowCellsTotalCounts" );
-}
-
-
-void _ParticleCommHandler_ZeroShadowCommStrategyCounters( ParticleCommHandler* self ) {
-	self->currShadowParticleLeavingMeIndex = 0;
-	self->shadowParticlesLeavingMeTotalCount = 0;
-	self->shadowParticlesLeavingMeUnfilledCount = 0;
-}
-
-
-void _ParticleCommHandler_FreeIncomingArrays( ParticleCommHandler* self ) {
-	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		nbr_I;
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0 ) {
-
-			if( self->particlesArrivingFromNbrShadowCells ){
-				Memory_Free( self->particlesArrivingFromNbrShadowCells[nbr_I] );
-			}
-			Memory_Free( self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] );
-		}
-	}
-	
-	if( self->particlesArrivingFromNbrShadowCells ){
-		Memory_Free( self->particlesArrivingFromNbrShadowCells );
-	}
-
-	Memory_Free( self->particlesArrivingFromNbrShadowCellsHandles );
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		Memory_Free( self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I] );
-	}
-	Memory_Free( self->particlesArrivingFromNbrShadowCellCountsHandles );
-
-	Memory_Free( self->particlesArrivingFromNbrShadowCellCounts );
-	Memory_Free( self->particlesArrivingFromNbrShadowCellsTotalCounts );
-}
-
-
-void _ParticleCommHandler_FreeOutgoingArrays( ParticleCommHandler* self ) {
-	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		nbr_I;
-
-	Memory_Free( self->shadowParticlesLeavingMeCountsPerCell );
-	Memory_Free( self->shadowParticlesLeavingMeTotalCounts );
-
-	if( self->shadowParticlesLeavingMeIndices ){
-		Memory_Free( self->shadowParticlesLeavingMeIndices );
-		self->shadowParticlesLeavingMeIndices = NULL;
-	}
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] > 0 ) {
-			Memory_Free( self->shadowParticlesLeavingMe[nbr_I] );
-			Memory_Free( self->shadowParticlesLeavingMeHandles[nbr_I] );
-		}	
-	}
-	Memory_Free( self->shadowParticlesLeavingMe );
-	Memory_Free( self->shadowParticlesLeavingMeHandles );
-}
-
-void _ParticleCommHandler_SendParticleTotalsInShadowCellsToNbrs( ParticleCommHandler* self )
-{	
-	Cell_ShadowTransferIndex	stCell_I;
-	Cell_DomainIndex		dCell_I;
-	Index				nbr_I;
-	Processor_Index			proc_I;
-	Cell_ShadowTransferIndex	shadowCellsToProcCount;
-	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
-	Cell_PointIndex			currCellParticleCount;
-
-	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-
-	self->shadowParticlesLeavingMeTotalCount = 0;
-
-	for ( nbr_I = 0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		proc_I = procNbrInfo->procNbrTbl[nbr_I];
-	
-		shadowCellsToProcCount = cellShadowInfo->procShadowCnt[nbr_I];	
-		Journal_DPrintfL( self->debug, 3, "Saving particle count in %d shadow cells going to nbr %d (proc %d):\n\t",
-			shadowCellsToProcCount, nbr_I, proc_I );
-
-		self->shadowParticlesLeavingMeTotalCounts[nbr_I] = 0;
-
-		for ( stCell_I=0; stCell_I < shadowCellsToProcCount; stCell_I++ ) {
-			dCell_I = cellShadowInfo->procShadowTbl[nbr_I][stCell_I];
-			
-			currCellParticleCount =  self->swarm->cellParticleCountTbl[dCell_I];
-			Journal_DPrintfL( self->debug, 3, "(stCell_I=%d, dCell_I=%d, cnt=%d), ",
-				stCell_I, dCell_I, currCellParticleCount );
-			self->shadowParticlesLeavingMeCountsPerCell[nbr_I][stCell_I] = currCellParticleCount;
-			self->shadowParticlesLeavingMeTotalCounts[nbr_I] += currCellParticleCount;
-			self->shadowParticlesLeavingMeTotalCount += currCellParticleCount;
-		}	
-		Journal_DPrintfL( self->debug, 3, "\n" );
-
-		MPI_Ssend( self->shadowParticlesLeavingMeCountsPerCell[nbr_I], shadowCellsToProcCount, MPI_UNSIGNED,
-			proc_I, SHADOW_PARTICLE_COUNTS_PER_CELL, self->swarm->comm );
-	}	
-
-	self->shadowParticlesLeavingMeUnfilledCount = self->shadowParticlesLeavingMeTotalCount;
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void _ParticleCommHandler_BeginSendingParticlesInShadowCellsToNbrs( ParticleCommHandler* self ) {	
-	Cell_ShadowTransferIndex	stCell_I;
-	Cell_DomainIndex		dCell_I;
-	Neighbour_Index			nbr_I;
-	Processor_Index			proc_I;
-	Cell_ShadowTransferIndex	shadowCellsToProcCount;
-	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index			nbrCount = procNbrInfo->procNbrCnt;
-	Particle_InCellIndex		currCellParticleCount;
-	Particle_InCellIndex		cParticle_I;
-	Particle_Index			lParticle_I;
-	Particle_Index			tParticle_I=0; /*Index into the particle transfer array */
-	Index				leavingParticle_I=0; /*Index into the array of all leaving particle indices */
-	#if DEBUG
-	GlobalParticle*                 currParticle;
-	#endif
-	#if CAUTIOUS
-	Bool*                           cellsClearedForTransfer = NULL;
-	Neighbour_Index*                cellsClearedForTransferDests = NULL;
-	Stream*                         errorStream = Journal_Register( Error_Type, (Name)self->type  );
-	#endif
-
-	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
-	Stream_Indent( self->debug );
-
-	#if CAUTIOUS
-	/* These guys are used to check that we never try and send the same cell of particles twice */
-	cellsClearedForTransfer = Memory_Alloc_Array( Bool, self->swarm->cellDomainCount,
-		"cellsClearedForTransfer" );
-	cellsClearedForTransferDests = Memory_Alloc_Array( Neighbour_Index, self->swarm->cellDomainCount,
-		"cellsClearedForTransferDests" );
-	for ( dCell_I = 0; dCell_I < self->swarm->cellDomainCount; dCell_I++ ) {
-		cellsClearedForTransfer[dCell_I] = False;
-		cellsClearedForTransferDests[dCell_I] = 0;
-	}
-	#endif
-
-	Journal_DPrintfL( self->debug, 1, "Sending the shadow particles going to my %d neighbours:\n", nbrCount );
-
-	for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
-		tParticle_I=0; /* Reset index for new neighbour processor */
-
-		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] != 0 ) {
-			#ifdef CAUTIOUS
-			Neighbour_Index      prevNbr_I;
-			#endif
-
-			shadowCellsToProcCount = cellShadowInfo->procShadowCnt[nbr_I];	
-			proc_I = procNbrInfo->procNbrTbl[nbr_I];
-			Journal_DPrintfL( self->debug, 3, "nbr %d (proc %d) - %d shadow cells going to it:\n",
-				nbr_I, proc_I, shadowCellsToProcCount ); 
-			#ifdef CAUTIOUS
-			for ( prevNbr_I=0; prevNbr_I < nbr_I; prevNbr_I++ ) {
-				Journal_Firewall( proc_I != procNbrInfo->procNbrTbl[prevNbr_I], errorStream,
-					"Error - in %s(), on proc %u: found in our Swarm's ProcNbrInfo "
-					"that our nbr %u is proc %u, but we already sent particles to "
-					"that processor as nbr %u! Can't send same particles to same "
-					"proc twice.\n", __func__, self->swarm->myRank, nbr_I, proc_I,
-					prevNbr_I );
-			}
-			#endif
-
-			Stream_Indent( self->debug );
-
-
-			for ( stCell_I=0; stCell_I < shadowCellsToProcCount; stCell_I++ ) {
-				currCellParticleCount = self->shadowParticlesLeavingMeCountsPerCell[nbr_I][stCell_I];
-				dCell_I = cellShadowInfo->procShadowTbl[nbr_I][stCell_I];
-				#ifdef CAUTIOUS
-				Journal_Firewall( cellsClearedForTransfer[dCell_I] == False, errorStream,
-					"Error - in %s(), on proc %u: while trying to send shadow particles to "
-					"nbr %u (proc %u), tried to copy particles from domain cell %u, but "
-					"this cell has already had all its particles cleared for send to "
-					"nbr %u (proc %u).\n", __func__, self->swarm->myRank, nbr_I, proc_I,
-					dCell_I, cellsClearedForTransferDests[dCell_I],
-					procNbrInfo->procNbrTbl[cellsClearedForTransferDests[dCell_I]] );
-				#endif
-
-				Journal_DPrintfL( self->debug, 3, "Processing Cell %d (%d particles):\n", dCell_I,
-					currCellParticleCount );
-			
-				Stream_Indent( self->debug );
-
-				for ( cParticle_I=0; cParticle_I < currCellParticleCount; cParticle_I++ ) {
-
-					lParticle_I = self->swarm->cellParticleTbl[dCell_I][cParticle_I];
-					#if DEBUG
-					currParticle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
-					Journal_DPrintfL( self->debug, 3, "Copying PIC %d, particle %d at "
-						"(%.2f,%.2f,%.2g) to shadowParticlesLeavingMe[%d][%d]\n",
-						cParticle_I, lParticle_I,
-						currParticle->coord[0], currParticle->coord[1], currParticle->coord[2],
-						nbr_I, tParticle_I );
-					#endif	
-					Swarm_CopyParticleOffSwarm( self->swarm,
-						self->shadowParticlesLeavingMe[nbr_I], tParticle_I++,
-						lParticle_I );
-					/* Note: we have no guarantee that the local particle index of where these
-					shadow cells are leaving from is monotonically increasing: thus do an insertion
-					at the right place. */
-					{
-						Index		insertionIndex = 0;
-						Particle_Index*	currInsertionPtr;
-						for ( ;insertionIndex < leavingParticle_I; insertionIndex++ ) {
-							currInsertionPtr = &self->shadowParticlesLeavingMeIndices[insertionIndex];
-							if (lParticle_I < (*currInsertionPtr) )
-							{
-								memmove(
-									(Pointer)(((ArithPointer)currInsertionPtr) + sizeof(Particle_Index)), 
-									currInsertionPtr,
-									(leavingParticle_I - insertionIndex) * sizeof(Particle_Index) );
-
-								(*currInsertionPtr) = lParticle_I;
-								break;
-							}
-						}
-						if ( insertionIndex == leavingParticle_I) {
-							self->shadowParticlesLeavingMeIndices[leavingParticle_I] = lParticle_I;
-						}
-						leavingParticle_I++;
-					}
-
-				}
-				Stream_UnIndent( self->debug );
-
-				#ifdef CAUTIOUS
-				cellsClearedForTransfer[dCell_I] = True;
-				cellsClearedForTransferDests[dCell_I] = nbr_I;
-				#endif
-				/* Remember to clear the entries for that cell now. */
-				self->swarm->cellParticleCountTbl[dCell_I] = 0;
-				self->swarm->cellParticleSizeTbl[dCell_I] = 0;
-				if ( self->swarm->cellParticleTbl[dCell_I] ) {
-					Memory_Free( self->swarm->cellParticleTbl[dCell_I] );
-				}
-				self->swarm->cellParticleTbl[dCell_I] = NULL;
-
-			}
-			Stream_UnIndent( self->debug );
-
-			/* non blocking send out particles */
-			MPI_Issend( self->shadowParticlesLeavingMe[nbr_I],
-				self->shadowParticlesLeavingMeTotalCounts[nbr_I] * self->swarm->particleExtensionMgr->finalSize,
-				MPI_BYTE, proc_I, SHADOW_PARTICLES, self->swarm->comm,
-				self->shadowParticlesLeavingMeHandles[nbr_I] );
-		}
-	}
-	#if CAUTIOUS
-	Memory_Free( cellsClearedForTransfer );
-	Memory_Free( cellsClearedForTransferDests );
-	#endif
-	Stream_UnIndent( self->debug );
-}
-
-/* +++ Statistics Printing +++ */
-
-
-void _ParticleCommHandler_PrintCommunicationVolumeStats( ParticleCommHandler* self, double startTime, Stream* stream )
-{
-	double                  myProcTime = 0;
-	double*                 procTimes = NULL;
-	double                  maxProcTime = 0;
-	Particle_Index          totalParticlesRecvdViaShadowFromNbrs = 0;
-	ShadowInfo*             cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	Processor_Index         proc_I = 0;
-	ProcNbrInfo*            procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index         nbrCount = procNbrInfo->procNbrCnt;
-
-	myProcTime = MPI_Wtime() - startTime;
-
-
-	totalParticlesRecvdViaShadowFromNbrs = 0;
-
-	if ( self->swarm->cellShadowCount > 0 ) {
-		ShadowInfo*	        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-		ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
-		Neighbour_Index		nbr_I;
-
-		for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-			totalParticlesRecvdViaShadowFromNbrs += 
-				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
-		}	
-	}
-
-	for ( proc_I = 0; proc_I < self->swarm->nProc; proc_I++ ) {
-		MPI_Barrier( self->swarm->comm );
-
-		if ( self->swarm->myRank == proc_I ) {			
-			Journal_PrintfL( stream, 2, "...proc %d finished particle communication:\n", self->swarm->myRank );
-			Stream_Indent( stream );
-			Journal_PrintfL( stream, 2, "- Particle comm totals via shadow cells (%d nbr procs):"
-				" sent %d, recvd %d\n",
-				nbrCount, self->shadowParticlesLeavingMeTotalCount,
-				totalParticlesRecvdViaShadowFromNbrs );
-			Journal_PrintfL( stream, 2, "- time taken = %.2f (secs)\n", myProcTime );
-			Stream_UnIndent( stream );
-		}
-	}
-	MPI_Barrier( self->swarm->comm );
-
-	procTimes = Memory_Alloc_Array( double, self->swarm->nProc, "procTimes" );
-	MPI_Gather( &myProcTime, 1, MPI_DOUBLE, procTimes, 1, MPI_DOUBLE, 0, self->swarm->comm );
-	if (self->swarm->myRank == 0 ) {
-		for ( proc_I = 0; proc_I < self->swarm->nProc; proc_I++ ) {
-			if ( procTimes[proc_I] > maxProcTime ) {
-				maxProcTime = procTimes[proc_I];
-			}
-		}
-		// TODO: print some stats on max particles sent/recvd and total sent/recvd
-		Journal_PrintfL( stream, 2, "...Max Communication time by any proc was %.2f (secs)\n", maxProcTime );
-	}
-	Memory_Free( procTimes );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleCommHandler.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/ParticleCommHandler.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,693 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ParticleCommHandler.c 4148 2007-06-26 03:49:27Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleCommHandler.h"
+
+#include "SwarmClass.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+const Type ParticleCommHandler_Type = "ParticleCommHandler";
+
+/* MPI tags */
+static const int SHADOW_PARTICLE_COUNTS_PER_CELL = 10;
+static const int SHADOW_PARTICLES = 20;
+
+ParticleCommHandler* _ParticleCommHandler_New(  PARTICLECOMMHANDLER_DEFARGS  )
+{
+	ParticleCommHandler* self;
+	
+	/* Allocate memory */
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (ParticleCommHandler*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* General info */
+	/* Virtual info */
+	self->allocateOutgoingCountArrays = _allocateOutgoingCountArrays;
+	self->allocateOutgoingParticleArrays	= _allocateOutgoingParticleArrays,
+	self->freeOutgoingArrays = _freeOutgoingArrays,
+	self->allocateIncomingCountArrays = _allocateIncomingCountArrays,
+	self->allocateIncomingParticleArrays = _allocateIncomingParticleArrays,
+	self->freeIncomingArrays = _freeIncomingArrays,
+	self->beginReceiveOfIncomingParticleCounts = _beginReceiveOfIncomingParticleCounts,
+	self->finishReceiveOfIncomingParticleCounts = _finishReceiveOfIncomingParticleCounts,
+	self->beginReceiveOfIncomingParticles = _beginReceiveOfIncomingParticles,
+	self->finishReceiveOfIncomingParticlesAndUpdateIndices = _finishReceiveOfIncomingParticlesAndUpdateIndices,
+	self->sendOutgoingParticleCounts = _sendOutgoingParticleCounts,
+	self->beginSendingParticles = _beginSendingParticles,
+	self->confirmOutgoingSendsCompleted = _confirmOutgoingSendsCompleted,
+	self->_commFunction = _commFunction;
+	
+	/* ParticleCommHandler info */
+	if( initFlag ){
+		_ParticleCommHandler_Init( self );
+	}
+	
+	return self;
+}
+
+
+void _ParticleCommHandler_Init(
+		ParticleCommHandler*     self )
+{
+	self->isConstructed = True;
+	self->swarm = NULL;
+	self->debug = Stream_RegisterChild( Swarm_Debug, self->type );
+
+	_ParticleCommHandler_ZeroShadowCommStrategyCounters( self );
+
+	self->shadowParticlesLeavingMeIndices = NULL;
+	self->shadowParticlesLeavingMeCountsPerCell = NULL;
+	self->shadowParticlesLeavingMeTotalCounts = NULL;
+	self->shadowParticlesLeavingMe = NULL;
+	self->shadowParticlesLeavingMeHandles = NULL;
+
+	self->particlesArrivingFromNbrShadowCellCounts = NULL;
+	self->particlesArrivingFromNbrShadowCellCountsHandles = NULL;
+	self->particlesArrivingFromNbrShadowCellsTotalCounts = NULL;
+	self->particlesArrivingFromNbrShadowCells = NULL;
+	self->particlesArrivingFromNbrShadowCellsHandles = NULL;
+}
+
+
+void _ParticleCommHandler_Delete(void* pCommsHandler ) {
+	/* Nothing to do, as the temporary arrays are deleted each step as soon as they are finished with. */
+	_Stg_Class_Delete( pCommsHandler );
+}
+
+
+void _ParticleCommHandler_Print( void* pCommsHandler, Stream* stream ) {
+	ParticleCommHandler*	self = (ParticleCommHandler*)pCommsHandler;
+	
+	/* General info */
+	Journal_Printf( stream, "ParticleCommHandler (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_Stg_Class_Print( self, stream );
+
+	/* Virtual info */
+	Journal_Printf( stream, "self->_commFunction(ptr): %p\n", 
+		self->_commFunction );
+
+	/* class info */	
+	Journal_Printf( stream, "self->swarm (ptr): %p\n", self->swarm ); 
+	Journal_Printf( stream, "self->shadowParticlesLeavingMeTotalCount: %d\n", self->shadowParticlesLeavingMeTotalCount ); 
+	Journal_Printf( stream, "self->shadowParticlesLeavingMeUnfilledCount: %d\n", self->shadowParticlesLeavingMeUnfilledCount ); 
+	Journal_Printf( stream, "self->currShadowParticleLeavingMeIndex: %d\n", self->currShadowParticleLeavingMeIndex ); 
+	Journal_Printf( stream, "self->shadowParticlesLeavingMeIndices (ptr): %p\n", self->shadowParticlesLeavingMeIndices ); 
+	Journal_Printf( stream, "self->currParticleLeavingMyDomainIndex: %d\n", self->currParticleLeavingMyDomainIndex ); 
+}
+
+
+void* _ParticleCommHandler_Copy( const void* particleCommHandler, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+
+	// TODO: put back in.
+	assert(0);
+
+}
+
+void _ParticleCommHandler_AssignFromXML( void* pCommHandler, Stg_ComponentFactory* cf, void* data ){
+	ParticleCommHandler*	self	= (ParticleCommHandler*)pCommHandler;
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !self->context  )
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+}
+	
+void _ParticleCommHandler_Build( void* pCommsHandler, void *data ){
+	
+}
+	
+void _ParticleCommHandler_Initialise( void* pCommsHandler, void *data ){
+	
+}
+	
+void _ParticleCommHandler_Execute( void* pCommsHandler, void *data ){
+}
+
+void _ParticleCommHandler_Destroy( void* pCommsHandler, void *data ){
+	
+}
+
+void _ParticleCommHandler_AllocateOutgoingParticlesArrays( ParticleCommHandler* self ) {
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		        nbrCount = procNbrInfo->procNbrCnt;
+	Neighbour_Index		        nbr_I;
+	SizeT				particlesArrayBytes;
+
+	/* Allocate the list of shadow particle indices to all nbrs */
+	self->shadowParticlesLeavingMeIndices = Memory_Alloc_Array( Particle_Index, self->shadowParticlesLeavingMeTotalCount,
+		"self->shadowParticlesLeavingMeIndices" );
+	self->shadowParticlesLeavingMeHandles = Memory_Alloc_Array(
+		MPI_Request*, procNbrInfo->procNbrCnt,
+		"ParticleCommHandler->shadowParticlesLeavingMeHandles");
+	self->shadowParticlesLeavingMe = Memory_Alloc_Array(
+		Particle*, procNbrInfo->procNbrCnt,
+		"ParticleCommHandler->shadowParticlesLeavingMe" );
+
+	for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
+
+		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] == 0 ) {
+			/* If we're not sending any particles to this proc, skip to next */
+			self->shadowParticlesLeavingMeHandles[nbr_I] = NULL;
+			self->shadowParticlesLeavingMe[nbr_I] = NULL;
+		}
+		else {
+			self->shadowParticlesLeavingMeHandles[nbr_I] = Memory_Alloc( MPI_Request,
+				"ParticleCommHandler->shadowParticlesLeavingMeHandles[]" );
+			particlesArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
+				self->shadowParticlesLeavingMeTotalCounts[nbr_I];
+			self->shadowParticlesLeavingMe[nbr_I] = (Particle*)Memory_Alloc_Bytes( particlesArrayBytes,
+				"Particle", "ParticleCommHandler->shadowParticlesLeavingMe[]" );
+		}
+	}
+}
+
+
+void _ParticleCommHandler_BeginReceiveOfIncomingParticleCounts( ParticleCommHandler* self ) {
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		        nbr_I;
+	Processor_Index		        proc_I;
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		proc_I = procNbrInfo->procNbrTbl[nbr_I];
+		MPI_Irecv( self->particlesArrivingFromNbrShadowCellCounts[nbr_I], cellShadowInfo->procShadowedCnt[nbr_I],
+			MPI_UNSIGNED, proc_I, SHADOW_PARTICLE_COUNTS_PER_CELL, self->swarm->comm,
+			self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I] );
+	}
+}
+
+
+void _ParticleCommHandler_FinishReceiveOfIncomingParticleCounts( ParticleCommHandler* self ) {
+	Cell_ShadowTransferIndex	stCell_I;
+	MPI_Status			status;
+	Processor_Index			proc_I;
+	Particle_Index			incomingCellParticleCount = 0;
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		        nbr_I;
+
+	/* TODO: may be worth converting the below into an MPI_Test loop */
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		proc_I = procNbrInfo->procNbrTbl[nbr_I];
+		
+		MPI_Wait( self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I], &status );
+
+		Journal_DPrintfL( self->debug, 1, "proc %d: recv shadow counts from nbr %d (rank %d):\n",
+			self->swarm->myRank, nbr_I, proc_I );
+		Journal_DPrintfL( self->debug, 2, "\tare [" );
+		self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] = 0;
+
+		for ( stCell_I=0; stCell_I < cellShadowInfo->procShadowedCnt[nbr_I]; stCell_I++ ) {
+			incomingCellParticleCount = self->particlesArrivingFromNbrShadowCellCounts[nbr_I][stCell_I];
+			Journal_DPrintfL( self->debug, 2, "%d, ", incomingCellParticleCount );
+			self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] += incomingCellParticleCount;
+		}
+		Journal_DPrintfL( self->debug, 2, "]\n" );
+		Journal_DPrintfL( self->debug, 1, "(Proc %d):....totalled to %d\n", self->swarm->myRank,
+			self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] );
+	}
+}
+
+
+void _ParticleCommHandler_AllocateIncomingParticlesArrays( ParticleCommHandler* self ) {
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		        nbr_I;
+	SizeT                           incomingViaShadowArrayBytes = 0;
+
+	self->particlesArrivingFromNbrShadowCellsHandles = Memory_Alloc_Array(
+		MPI_Request*, procNbrInfo->procNbrCnt,
+		"ParticleCommHandler->particlesArrivingFromNbrShadowCellsHandles");
+	self->particlesArrivingFromNbrShadowCells = Memory_Alloc_Array(
+		Particle*, procNbrInfo->procNbrCnt,
+		"ParticleCommHandler->particlesArrivingFromNbrShadowCells" );
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+
+		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] == 0 ) {
+			/* No particles to receive from this proc -> just clear recv ptr */
+			self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] = NULL;
+			self->particlesArrivingFromNbrShadowCells[nbr_I] = NULL;
+		}	
+		else { 
+			self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] =
+				Memory_Alloc(
+					MPI_Request,
+					"ParticleCommHandler->particlesArrivingFromNbrShadowCellsHandles[]" );
+
+			/* allocate particles recv array to right size */
+			incomingViaShadowArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
+				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
+			self->particlesArrivingFromNbrShadowCells[nbr_I] = (Particle*)Memory_Alloc_Bytes( incomingViaShadowArrayBytes,
+				"Particle", "particleCommHandler->particlesArrivingFromNbrShadowCells[]" );
+		}
+	}
+}
+
+
+void _ParticleCommHandler_BeginReceiveOfIncomingParticles( ParticleCommHandler* self ) {
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	SizeT                           incomingViaShadowArrayBytes = 0;
+	Neighbour_Index		        nbr_I;
+	Processor_Index			proc_I;
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] != 0 ) {
+			proc_I = procNbrInfo->procNbrTbl[nbr_I];
+
+			/* start non-blocking recv of particles */
+			incomingViaShadowArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
+				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
+			MPI_Irecv( self->particlesArrivingFromNbrShadowCells[nbr_I], incomingViaShadowArrayBytes, MPI_BYTE,
+				proc_I, SHADOW_PARTICLES, self->swarm->comm,
+				self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] );
+		}
+	}
+}
+
+void _ParticleCommHandler_AllocateOutgoingCountArrays( ParticleCommHandler* self ) {
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+
+	Neighbour_Index		nbrCount = procNbrInfo->procNbrCnt;
+
+	self->shadowParticlesLeavingMeCountsPerCell = Memory_Alloc_2DComplex(
+		Particle_Index, nbrCount, cellShadowInfo->procShadowCnt,
+		"ParticleCommHandler->shadowParticlesLeavingMeCountsPerCell" );
+	self->shadowParticlesLeavingMeTotalCounts = Memory_Alloc_Array( Particle_Index, nbrCount,
+		"ParticleCommHandler->shadowParticlesLeavingMeTotalCounts" );
+}
+
+
+void _ParticleCommHandler_ConfirmOutgoingSendsCompleted( ParticleCommHandler* self ) {
+	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		nbr_I;
+	MPI_Status		status;
+
+	/* MPI_Wait for all shadow sends to complete */
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] > 0 ) {
+			MPI_Wait( self->shadowParticlesLeavingMeHandles[nbr_I], &status );
+		}	
+	}
+}
+
+
+void _ParticleCommHandler_AllocateIncomingCountArrays( ParticleCommHandler* self )
+{
+	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		nbr_I;
+	Neighbour_Index         nbrCount = procNbrInfo->procNbrCnt;
+
+	self->particlesArrivingFromNbrShadowCellCounts = Memory_Alloc_2DComplex(
+		Particle_Index, nbrCount, cellShadowInfo->procShadowedCnt,
+		"ParticleCommHandler->particlesArrivingFromNbrShadowCellCounts" );
+	self->particlesArrivingFromNbrShadowCellCountsHandles = Memory_Alloc_Array( MPI_Request*, nbrCount,
+		"ParticleCommHandler->particlesArrivingFromNbrShadowCellCountsHandles" );
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I] = Memory_Alloc( MPI_Request,
+			"ParticleCommHandler->particlesArrivingFromNbrShadowCellCountsHandles[]" );
+	}
+	self->particlesArrivingFromNbrShadowCellsTotalCounts = Memory_Alloc_Array( Particle_Index, nbrCount,
+		"ParticleCommHandler->particlesArrivingFromNbrShadowCellsTotalCounts" );
+}
+
+
+void _ParticleCommHandler_ZeroShadowCommStrategyCounters( ParticleCommHandler* self ) {
+	self->currShadowParticleLeavingMeIndex = 0;
+	self->shadowParticlesLeavingMeTotalCount = 0;
+	self->shadowParticlesLeavingMeUnfilledCount = 0;
+}
+
+
+void _ParticleCommHandler_FreeIncomingArrays( ParticleCommHandler* self ) {
+	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		nbr_I;
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0 ) {
+
+			if( self->particlesArrivingFromNbrShadowCells ){
+				Memory_Free( self->particlesArrivingFromNbrShadowCells[nbr_I] );
+			}
+			Memory_Free( self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] );
+		}
+	}
+	
+	if( self->particlesArrivingFromNbrShadowCells ){
+		Memory_Free( self->particlesArrivingFromNbrShadowCells );
+	}
+
+	Memory_Free( self->particlesArrivingFromNbrShadowCellsHandles );
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		Memory_Free( self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I] );
+	}
+	Memory_Free( self->particlesArrivingFromNbrShadowCellCountsHandles );
+
+	Memory_Free( self->particlesArrivingFromNbrShadowCellCounts );
+	Memory_Free( self->particlesArrivingFromNbrShadowCellsTotalCounts );
+}
+
+
+void _ParticleCommHandler_FreeOutgoingArrays( ParticleCommHandler* self ) {
+	ShadowInfo*		cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		nbr_I;
+
+	Memory_Free( self->shadowParticlesLeavingMeCountsPerCell );
+	Memory_Free( self->shadowParticlesLeavingMeTotalCounts );
+
+	if( self->shadowParticlesLeavingMeIndices ){
+		Memory_Free( self->shadowParticlesLeavingMeIndices );
+		self->shadowParticlesLeavingMeIndices = NULL;
+	}
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] > 0 ) {
+			Memory_Free( self->shadowParticlesLeavingMe[nbr_I] );
+			Memory_Free( self->shadowParticlesLeavingMeHandles[nbr_I] );
+		}	
+	}
+	Memory_Free( self->shadowParticlesLeavingMe );
+	Memory_Free( self->shadowParticlesLeavingMeHandles );
+}
+
+void _ParticleCommHandler_SendParticleTotalsInShadowCellsToNbrs( ParticleCommHandler* self )
+{	
+	Cell_ShadowTransferIndex	stCell_I;
+	Cell_DomainIndex		dCell_I;
+	Index				nbr_I;
+	Processor_Index			proc_I;
+	Cell_ShadowTransferIndex	shadowCellsToProcCount;
+	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
+	Cell_PointIndex			currCellParticleCount;
+
+	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+
+	self->shadowParticlesLeavingMeTotalCount = 0;
+
+	for ( nbr_I = 0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		proc_I = procNbrInfo->procNbrTbl[nbr_I];
+	
+		shadowCellsToProcCount = cellShadowInfo->procShadowCnt[nbr_I];	
+		Journal_DPrintfL( self->debug, 3, "Saving particle count in %d shadow cells going to nbr %d (proc %d):\n\t",
+			shadowCellsToProcCount, nbr_I, proc_I );
+
+		self->shadowParticlesLeavingMeTotalCounts[nbr_I] = 0;
+
+		for ( stCell_I=0; stCell_I < shadowCellsToProcCount; stCell_I++ ) {
+			dCell_I = cellShadowInfo->procShadowTbl[nbr_I][stCell_I];
+			
+			currCellParticleCount =  self->swarm->cellParticleCountTbl[dCell_I];
+			Journal_DPrintfL( self->debug, 3, "(stCell_I=%d, dCell_I=%d, cnt=%d), ",
+				stCell_I, dCell_I, currCellParticleCount );
+			self->shadowParticlesLeavingMeCountsPerCell[nbr_I][stCell_I] = currCellParticleCount;
+			self->shadowParticlesLeavingMeTotalCounts[nbr_I] += currCellParticleCount;
+			self->shadowParticlesLeavingMeTotalCount += currCellParticleCount;
+		}	
+		Journal_DPrintfL( self->debug, 3, "\n" );
+
+		MPI_Ssend( self->shadowParticlesLeavingMeCountsPerCell[nbr_I], shadowCellsToProcCount, MPI_UNSIGNED,
+			proc_I, SHADOW_PARTICLE_COUNTS_PER_CELL, self->swarm->comm );
+	}	
+
+	self->shadowParticlesLeavingMeUnfilledCount = self->shadowParticlesLeavingMeTotalCount;
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void _ParticleCommHandler_BeginSendingParticlesInShadowCellsToNbrs( ParticleCommHandler* self ) {	
+	Cell_ShadowTransferIndex	stCell_I;
+	Cell_DomainIndex		dCell_I;
+	Neighbour_Index			nbr_I;
+	Processor_Index			proc_I;
+	Cell_ShadowTransferIndex	shadowCellsToProcCount;
+	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index			nbrCount = procNbrInfo->procNbrCnt;
+	Particle_InCellIndex		currCellParticleCount;
+	Particle_InCellIndex		cParticle_I;
+	Particle_Index			lParticle_I;
+	Particle_Index			tParticle_I=0; /*Index into the particle transfer array */
+	Index				leavingParticle_I=0; /*Index into the array of all leaving particle indices */
+	#if DEBUG
+	GlobalParticle*                 currParticle;
+	#endif
+	#if CAUTIOUS
+	Bool*                           cellsClearedForTransfer = NULL;
+	Neighbour_Index*                cellsClearedForTransferDests = NULL;
+	Stream*                         errorStream = Journal_Register( Error_Type, (Name)self->type  );
+	#endif
+
+	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
+	Stream_Indent( self->debug );
+
+	#if CAUTIOUS
+	/* These guys are used to check that we never try and send the same cell of particles twice */
+	cellsClearedForTransfer = Memory_Alloc_Array( Bool, self->swarm->cellDomainCount,
+		"cellsClearedForTransfer" );
+	cellsClearedForTransferDests = Memory_Alloc_Array( Neighbour_Index, self->swarm->cellDomainCount,
+		"cellsClearedForTransferDests" );
+	for ( dCell_I = 0; dCell_I < self->swarm->cellDomainCount; dCell_I++ ) {
+		cellsClearedForTransfer[dCell_I] = False;
+		cellsClearedForTransferDests[dCell_I] = 0;
+	}
+	#endif
+
+	Journal_DPrintfL( self->debug, 1, "Sending the shadow particles going to my %d neighbours:\n", nbrCount );
+
+	for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
+		tParticle_I=0; /* Reset index for new neighbour processor */
+
+		if ( self->shadowParticlesLeavingMeTotalCounts[nbr_I] != 0 ) {
+			#ifdef CAUTIOUS
+			Neighbour_Index      prevNbr_I;
+			#endif
+
+			shadowCellsToProcCount = cellShadowInfo->procShadowCnt[nbr_I];	
+			proc_I = procNbrInfo->procNbrTbl[nbr_I];
+			Journal_DPrintfL( self->debug, 3, "nbr %d (proc %d) - %d shadow cells going to it:\n",
+				nbr_I, proc_I, shadowCellsToProcCount ); 
+			#ifdef CAUTIOUS
+			for ( prevNbr_I=0; prevNbr_I < nbr_I; prevNbr_I++ ) {
+				Journal_Firewall( proc_I != procNbrInfo->procNbrTbl[prevNbr_I], errorStream,
+					"Error - in %s(), on proc %u: found in our Swarm's ProcNbrInfo "
+					"that our nbr %u is proc %u, but we already sent particles to "
+					"that processor as nbr %u! Can't send same particles to same "
+					"proc twice.\n", __func__, self->swarm->myRank, nbr_I, proc_I,
+					prevNbr_I );
+			}
+			#endif
+
+			Stream_Indent( self->debug );
+
+
+			for ( stCell_I=0; stCell_I < shadowCellsToProcCount; stCell_I++ ) {
+				currCellParticleCount = self->shadowParticlesLeavingMeCountsPerCell[nbr_I][stCell_I];
+				dCell_I = cellShadowInfo->procShadowTbl[nbr_I][stCell_I];
+				#ifdef CAUTIOUS
+				Journal_Firewall( cellsClearedForTransfer[dCell_I] == False, errorStream,
+					"Error - in %s(), on proc %u: while trying to send shadow particles to "
+					"nbr %u (proc %u), tried to copy particles from domain cell %u, but "
+					"this cell has already had all its particles cleared for send to "
+					"nbr %u (proc %u).\n", __func__, self->swarm->myRank, nbr_I, proc_I,
+					dCell_I, cellsClearedForTransferDests[dCell_I],
+					procNbrInfo->procNbrTbl[cellsClearedForTransferDests[dCell_I]] );
+				#endif
+
+				Journal_DPrintfL( self->debug, 3, "Processing Cell %d (%d particles):\n", dCell_I,
+					currCellParticleCount );
+			
+				Stream_Indent( self->debug );
+
+				for ( cParticle_I=0; cParticle_I < currCellParticleCount; cParticle_I++ ) {
+
+					lParticle_I = self->swarm->cellParticleTbl[dCell_I][cParticle_I];
+					#if DEBUG
+					currParticle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
+					Journal_DPrintfL( self->debug, 3, "Copying PIC %d, particle %d at "
+						"(%.2f,%.2f,%.2g) to shadowParticlesLeavingMe[%d][%d]\n",
+						cParticle_I, lParticle_I,
+						currParticle->coord[0], currParticle->coord[1], currParticle->coord[2],
+						nbr_I, tParticle_I );
+					#endif	
+					Swarm_CopyParticleOffSwarm( self->swarm,
+						self->shadowParticlesLeavingMe[nbr_I], tParticle_I++,
+						lParticle_I );
+					/* Note: we have no guarantee that the local particle index of where these
+					shadow cells are leaving from is monotonically increasing: thus do an insertion
+					at the right place. */
+					{
+						Index		insertionIndex = 0;
+						Particle_Index*	currInsertionPtr;
+						for ( ;insertionIndex < leavingParticle_I; insertionIndex++ ) {
+							currInsertionPtr = &self->shadowParticlesLeavingMeIndices[insertionIndex];
+							if (lParticle_I < (*currInsertionPtr) )
+							{
+								memmove(
+									(Pointer)(((ArithPointer)currInsertionPtr) + sizeof(Particle_Index)), 
+									currInsertionPtr,
+									(leavingParticle_I - insertionIndex) * sizeof(Particle_Index) );
+
+								(*currInsertionPtr) = lParticle_I;
+								break;
+							}
+						}
+						if ( insertionIndex == leavingParticle_I) {
+							self->shadowParticlesLeavingMeIndices[leavingParticle_I] = lParticle_I;
+						}
+						leavingParticle_I++;
+					}
+
+				}
+				Stream_UnIndent( self->debug );
+
+				#ifdef CAUTIOUS
+				cellsClearedForTransfer[dCell_I] = True;
+				cellsClearedForTransferDests[dCell_I] = nbr_I;
+				#endif
+				/* Remember to clear the entries for that cell now. */
+				self->swarm->cellParticleCountTbl[dCell_I] = 0;
+				self->swarm->cellParticleSizeTbl[dCell_I] = 0;
+				if ( self->swarm->cellParticleTbl[dCell_I] ) {
+					Memory_Free( self->swarm->cellParticleTbl[dCell_I] );
+				}
+				self->swarm->cellParticleTbl[dCell_I] = NULL;
+
+			}
+			Stream_UnIndent( self->debug );
+
+			/* non blocking send out particles */
+			MPI_Issend( self->shadowParticlesLeavingMe[nbr_I],
+				self->shadowParticlesLeavingMeTotalCounts[nbr_I] * self->swarm->particleExtensionMgr->finalSize,
+				MPI_BYTE, proc_I, SHADOW_PARTICLES, self->swarm->comm,
+				self->shadowParticlesLeavingMeHandles[nbr_I] );
+		}
+	}
+	#if CAUTIOUS
+	Memory_Free( cellsClearedForTransfer );
+	Memory_Free( cellsClearedForTransferDests );
+	#endif
+	Stream_UnIndent( self->debug );
+}
+
+/* +++ Statistics Printing +++ */
+
+
+void _ParticleCommHandler_PrintCommunicationVolumeStats( ParticleCommHandler* self, double startTime, Stream* stream )
+{
+	double                  myProcTime = 0;
+	double*                 procTimes = NULL;
+	double                  maxProcTime = 0;
+	Particle_Index          totalParticlesRecvdViaShadowFromNbrs = 0;
+	ShadowInfo*             cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	Processor_Index         proc_I = 0;
+	ProcNbrInfo*            procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index         nbrCount = procNbrInfo->procNbrCnt;
+
+	myProcTime = MPI_Wtime() - startTime;
+
+
+	totalParticlesRecvdViaShadowFromNbrs = 0;
+
+	if ( self->swarm->cellShadowCount > 0 ) {
+		ShadowInfo*	        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+		ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
+		Neighbour_Index		nbr_I;
+
+		for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+			totalParticlesRecvdViaShadowFromNbrs += 
+				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
+		}	
+	}
+
+	for ( proc_I = 0; proc_I < self->swarm->nProc; proc_I++ ) {
+		MPI_Barrier( self->swarm->comm );
+
+		if ( self->swarm->myRank == proc_I ) {			
+			Journal_PrintfL( stream, 2, "...proc %d finished particle communication:\n", self->swarm->myRank );
+			Stream_Indent( stream );
+			Journal_PrintfL( stream, 2, "- Particle comm totals via shadow cells (%d nbr procs):"
+				" sent %d, recvd %d\n",
+				nbrCount, self->shadowParticlesLeavingMeTotalCount,
+				totalParticlesRecvdViaShadowFromNbrs );
+			Journal_PrintfL( stream, 2, "- time taken = %.2f (secs)\n", myProcTime );
+			Stream_UnIndent( stream );
+		}
+	}
+	MPI_Barrier( self->swarm->comm );
+
+	procTimes = Memory_Alloc_Array( double, self->swarm->nProc, "procTimes" );
+	MPI_Gather( &myProcTime, 1, MPI_DOUBLE, procTimes, 1, MPI_DOUBLE, 0, self->swarm->comm );
+	if (self->swarm->myRank == 0 ) {
+		for ( proc_I = 0; proc_I < self->swarm->nProc; proc_I++ ) {
+			if ( procTimes[proc_I] > maxProcTime ) {
+				maxProcTime = procTimes[proc_I];
+			}
+		}
+		// TODO: print some stats on max particles sent/recvd and total sent/recvd
+		Journal_PrintfL( stream, 2, "...Max Communication time by any proc was %.2f (secs)\n", maxProcTime );
+	}
+	Memory_Free( procTimes );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleLayout.c
--- a/Swarm/src/ParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ParticleLayout.c 3629 2006-06-13 08:36:51Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-const Type ParticleLayout_Type = "ParticleLayout";
-
-ParticleLayout* _ParticleLayout_New(  PARTICLELAYOUT_DEFARGS  )
-{
-   ParticleLayout*		self;
-	
-   /* hard-wire this var */
-   nameAllocationType = NON_GLOBAL;
-
-   /* Allocate memory */
-   assert( _sizeOfSelf >= sizeof(ParticleLayout) );
-   self = (ParticleLayout*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-   /* General info */
-   self->coordSystem = coordSystem;	
-   self->weightsInitialisedAtStartup = weightsInitialisedAtStartup;	
-
-   /* Virtual functions */
-   self->_setInitialCounts = _setInitialCounts;
-   self->_initialiseParticles = _initialiseParticles;
-	
-    return self;
-}
-
-
-void _ParticleLayout_Init( 
-   void*           particleLayout, 
-   AbstractContext* context,
-   CoordSystem     coordSystem,
-   Bool            weightsInitialisedAtStartup ) 
-{ 
-   ParticleLayout* self = (ParticleLayout*)particleLayout;
-
-   self->context = context;
-   self->debug = Stream_RegisterChild( Swarm_Debug, self->type );
-
-   self->coordSystem = coordSystem;
-   self->weightsInitialisedAtStartup = weightsInitialisedAtStartup;
-}
-
-void _ParticleLayout_Delete( void* particleLayout ) {
-    ParticleLayout* self = (ParticleLayout*)particleLayout;
-	
-    /* Stg_Class_Delete parent class */
-    _Stg_Component_Delete( self );
-}
-
-void _ParticleLayout_Print( void* particleLayout, Stream* stream ) {
-    ParticleLayout* self = (ParticleLayout*)particleLayout;
-	
-    Journal_Printf( stream, "ParticleLayout (ptr): %p\n", self );
-	
-    /* Parent class info */
-    _Stg_Class_Print( self, stream );
-	
-    /* Virtual info */
-    Journal_Printf( stream, "\t_setInitialCounts (func ptr): %p\n", self->_setInitialCounts );
-    Journal_Printf( stream, "\t_initialiseParticles (func ptr): %p\n", self->_initialiseParticles );
-	
-    /* ParticleLayout info */
-    Journal_Printf( 
-        stream, 
-        "\tcoordSystem: %s\n", 
-        ( self->coordSystem == LocalCoordSystem ) ? "LocalCoordSystem" : "GlobalCoordSystem" );
-    Journal_Printf( 
-        stream, 
-        "\tweightsInitialisedAtStartup : %s\n",
-        self->weightsInitialisedAtStartup ? "True" : "False" );
-}
-
-
-void* _ParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    ParticleLayout*		self = (ParticleLayout*)particleLayout;
-    ParticleLayout*		newParticleLayout;
-	
-    newParticleLayout = (ParticleLayout*)_Stg_Class_Copy( self, dest, deep, nameExt, ptrMap );
-	
-    /* Virtual methods */
-    newParticleLayout->_setInitialCounts = self->_setInitialCounts;
-    newParticleLayout->_initialiseParticles = self->_initialiseParticles;
-    newParticleLayout->coordSystem = self->coordSystem;
-    newParticleLayout->weightsInitialisedAtStartup = self->weightsInitialisedAtStartup;
-
-    return (void*)newParticleLayout;
-}
-
-void _ParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ) {
-   ParticleLayout* self = (ParticleLayout*) particleLayout;
-   AbstractContext* context=NULL;
-
-   context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-   if( !context  )
-      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-   _ParticleLayout_Init( self, context, GlobalCoordSystem, False );
-
-}
-
-void _ParticleLayout_Destroy( void* particleLayout, void* data ) {}
-
-void ParticleLayout_InitialiseParticles( void* particleLayout, void* swarm ) {
-    ParticleLayout* self = (ParticleLayout*)particleLayout;
-	
-    self->_initialiseParticles( self, swarm );
-}
-
-void ParticleLayout_SetInitialCounts( void* particleLayout, void* swarm ) {
-    ParticleLayout* self = (ParticleLayout*)particleLayout;
-	
-    self->_setInitialCounts( particleLayout, swarm );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/ParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,157 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ParticleLayout.c 3629 2006-06-13 08:36:51Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+const Type ParticleLayout_Type = "ParticleLayout";
+
+ParticleLayout* _ParticleLayout_New(  PARTICLELAYOUT_DEFARGS  )
+{
+   ParticleLayout*		self;
+	
+   /* hard-wire this var */
+   nameAllocationType = NON_GLOBAL;
+
+   /* Allocate memory */
+   assert( _sizeOfSelf >= sizeof(ParticleLayout) );
+   self = (ParticleLayout*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+   /* General info */
+   self->coordSystem = coordSystem;	
+   self->weightsInitialisedAtStartup = weightsInitialisedAtStartup;	
+
+   /* Virtual functions */
+   self->_setInitialCounts = _setInitialCounts;
+   self->_initialiseParticles = _initialiseParticles;
+	
+    return self;
+}
+
+
+void _ParticleLayout_Init( 
+   void*           particleLayout, 
+   AbstractContext* context,
+   CoordSystem     coordSystem,
+   Bool            weightsInitialisedAtStartup ) 
+{ 
+   ParticleLayout* self = (ParticleLayout*)particleLayout;
+
+   self->context = context;
+   self->debug = Stream_RegisterChild( Swarm_Debug, self->type );
+
+   self->coordSystem = coordSystem;
+   self->weightsInitialisedAtStartup = weightsInitialisedAtStartup;
+}
+
+void _ParticleLayout_Delete( void* particleLayout ) {
+    ParticleLayout* self = (ParticleLayout*)particleLayout;
+	
+    /* Stg_Class_Delete parent class */
+    _Stg_Component_Delete( self );
+}
+
+void _ParticleLayout_Print( void* particleLayout, Stream* stream ) {
+    ParticleLayout* self = (ParticleLayout*)particleLayout;
+	
+    Journal_Printf( stream, "ParticleLayout (ptr): %p\n", self );
+	
+    /* Parent class info */
+    _Stg_Class_Print( self, stream );
+	
+    /* Virtual info */
+    Journal_Printf( stream, "\t_setInitialCounts (func ptr): %p\n", self->_setInitialCounts );
+    Journal_Printf( stream, "\t_initialiseParticles (func ptr): %p\n", self->_initialiseParticles );
+	
+    /* ParticleLayout info */
+    Journal_Printf( 
+        stream, 
+        "\tcoordSystem: %s\n", 
+        ( self->coordSystem == LocalCoordSystem ) ? "LocalCoordSystem" : "GlobalCoordSystem" );
+    Journal_Printf( 
+        stream, 
+        "\tweightsInitialisedAtStartup : %s\n",
+        self->weightsInitialisedAtStartup ? "True" : "False" );
+}
+
+
+void* _ParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    ParticleLayout*		self = (ParticleLayout*)particleLayout;
+    ParticleLayout*		newParticleLayout;
+	
+    newParticleLayout = (ParticleLayout*)_Stg_Class_Copy( self, dest, deep, nameExt, ptrMap );
+	
+    /* Virtual methods */
+    newParticleLayout->_setInitialCounts = self->_setInitialCounts;
+    newParticleLayout->_initialiseParticles = self->_initialiseParticles;
+    newParticleLayout->coordSystem = self->coordSystem;
+    newParticleLayout->weightsInitialisedAtStartup = self->weightsInitialisedAtStartup;
+
+    return (void*)newParticleLayout;
+}
+
+void _ParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ) {
+   ParticleLayout* self = (ParticleLayout*) particleLayout;
+   AbstractContext* context=NULL;
+
+   context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+   if( !context  )
+      context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+   _ParticleLayout_Init( self, context, GlobalCoordSystem, False );
+
+}
+
+void _ParticleLayout_Destroy( void* particleLayout, void* data ) {}
+
+void ParticleLayout_InitialiseParticles( void* particleLayout, void* swarm ) {
+    ParticleLayout* self = (ParticleLayout*)particleLayout;
+	
+    self->_initialiseParticles( self, swarm );
+}
+
+void ParticleLayout_SetInitialCounts( void* particleLayout, void* swarm ) {
+    ParticleLayout* self = (ParticleLayout*)particleLayout;
+	
+    self->_setInitialCounts( particleLayout, swarm );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleMovementHandler.c
--- a/Swarm/src/ParticleMovementHandler.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1005 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ParticleMovementHandler.c 4001 2007-02-09 01:26:29Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "ShadowInfo.h"
-#include "shortcuts.h"
-#include "ParticleCommHandler.h"
-#include "ParticleMovementHandler.h"
-
-#include "SwarmClass.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-const Type ParticleMovementHandler_Type = "ParticleMovementHandler";
-
-void *ParticleMovementHandler_DefaultNew( Name name )
-{
-	/* Variables set in this function */
-	SizeT                                                        _sizeOfSelf = sizeof(ParticleMovementHandler);
-	Type                                                                type = ParticleMovementHandler_Type;
-	Stg_Class_DeleteFunction*                                        _delete = _ParticleMovementHandler_Delete;
-	Stg_Class_PrintFunction*                                          _print = _ParticleMovementHandler_Print;
-	Stg_Class_CopyFunction*                                            _copy = _ParticleMovementHandler_CopyFunc;
-	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleMovementHandler_DefaultNew;
-	Stg_Component_ConstructFunction*                              _construct = _ParticleMovementHandler_AssignFromXML;
-	Stg_Component_BuildFunction*                                      _build = _ParticleMovementHandler_Build;
-	Stg_Component_InitialiseFunction*                            _initialise = _ParticleMovementHandler_Initialise;
-	Stg_Component_ExecuteFunction*                                  _execute = _ParticleMovementHandler_Execute;
-	Stg_Component_DestroyFunction*                                  _destroy = _ParticleMovementHandler_Destroy;
-	Bool                                                            initFlag = False;
-	Bool                                       useGlobalFallbackCommStrategy = False;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
-	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
-	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
-	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
-	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
-	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
-	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
-	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
-	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
-
-	return _ParticleMovementHandler_New(  PARTICLEMOVEMENTHANDLER_PASSARGS  );
-}
-
-
-ParticleMovementHandler* ParticleMovementHandler_New( 
-		Name name,
-		Bool useGlobalFallbackCommStrategy
-		)
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(ParticleMovementHandler);
-	Type                                                      type = ParticleMovementHandler_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ParticleMovementHandler_Delete;
-	Stg_Class_PrintFunction*                                _print = _ParticleMovementHandler_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ParticleMovementHandler_CopyFunc;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleMovementHandler_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ParticleMovementHandler_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ParticleMovementHandler_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ParticleMovementHandler_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ParticleMovementHandler_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ParticleMovementHandler_Destroy;
-	Bool                                                  initFlag = True;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
-	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
-	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
-	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
-	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
-	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
-	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
-	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
-	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
-
-	return _ParticleMovementHandler_New(  PARTICLEMOVEMENTHANDLER_PASSARGS  );
-}
-
-
-ParticleMovementHandler* _ParticleMovementHandler_New(  PARTICLEMOVEMENTHANDLER_DEFARGS  )
-{
-	ParticleMovementHandler* self;
-	
-	/* Allocate memory */
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	_allocateOutgoingCountArrays                      = _ParticleCommHandler_AllocateOutgoingCountArrays;
-	_allocateOutgoingParticleArrays                   = _ParticleCommHandler_AllocateOutgoingParticlesArrays;
-	_freeOutgoingArrays                               = _ParticleCommHandler_FreeOutgoingArrays;
-	_allocateIncomingCountArrays                      = _ParticleCommHandler_AllocateIncomingCountArrays;
-	_allocateIncomingParticleArrays                   = _ParticleCommHandler_AllocateIncomingParticlesArrays;
-	_freeIncomingArrays                               = _ParticleCommHandler_FreeIncomingArrays;
-	_beginReceiveOfIncomingParticleCounts             = _ParticleCommHandler_BeginReceiveOfIncomingParticleCounts;
-	_finishReceiveOfIncomingParticleCounts            = _ParticleCommHandler_FinishReceiveOfIncomingParticleCounts;
-	_beginReceiveOfIncomingParticles                  = _ParticleCommHandler_BeginReceiveOfIncomingParticles;
-	_finishReceiveOfIncomingParticlesAndUpdateIndices = ParticleMovementHandler_FinishReceiveAndUpdateShadowParticlesEnteringMyDomain;
-	_sendOutgoingParticleCounts                       = _ParticleCommHandler_SendParticleTotalsInShadowCellsToNbrs;
-	_beginSendingParticles                            = _ParticleCommHandler_BeginSendingParticlesInShadowCellsToNbrs;
-	_confirmOutgoingSendsCompleted                    = _ParticleCommHandler_ConfirmOutgoingSendsCompleted;
-	_commFunction                                     = ParticleMovementHandler_HandleParticleMovementBetweenProcs;
-
-	self = (ParticleMovementHandler*)_ParticleCommHandler_New(  PARTICLECOMMHANDLER_PASSARGS  );
-	
-	/* General info */
-	/* Virtual info */
-	
-	/* ParticleMovementHandler info */
-	if( initFlag ){
-		_ParticleMovementHandler_Init( self, useGlobalFallbackCommStrategy );
-	}
-	
-	return self;
-}
-
-
-void _ParticleMovementHandler_Init(
-		ParticleMovementHandler*     self,
-		Bool                     useGlobalFallbackCommStrategy
-		)
-{
-	_ParticleCommHandler_Init( (ParticleCommHandler*)self );
-	self->defensive = False;
-	self->useGlobalFallbackCommStrategy = useGlobalFallbackCommStrategy;
-	self->particlesOutsideDomainIndices = NULL;
-	ParticleMovementHandler_ZeroGlobalCommStrategyCounters( self );	
-}
-
-
-void _ParticleMovementHandler_Delete(void* pCommsHandler ) {
-	/* Nothing to do, as the temporary arrays are deleted each step as soon as they are finished with. */
-	_ParticleCommHandler_Delete( pCommsHandler );
-}
-
-
-void _ParticleMovementHandler_Print( void* pCommsHandler, Stream* stream ) {
-	ParticleMovementHandler*	self = (ParticleMovementHandler*)pCommsHandler;
-	
-	/* General info */
-	Journal_Printf( stream, "ParticleMovementHandler (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_ParticleCommHandler_Print( self, stream );
-
-	/* Virtual info */
-
-	Journal_Printf( stream, "self->particlesOutsideDomainTotalCount: %d\n", self->particlesOutsideDomainTotalCount ); 
-	Journal_Printf( stream, "self->particlesOutsideDomainUnfiledCount: %d\n", self->particlesOutsideDomainUnfilledCount ); 
-	Journal_Printf( stream, "self->particlesOutsideDomainIndices(ptr): %p\n", self->particlesOutsideDomainIndices ); 
-}
-
-
-void* _ParticleMovementHandler_CopyFunc( const void* particleMovementHandler, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	
-	return _ParticleCommHandler_Copy( particleMovementHandler, dest, deep,
-		   nameExt, ptrMap );
-}
-
-void _ParticleMovementHandler_AssignFromXML( void* pCommsHandler, Stg_ComponentFactory* cf, void* data ){
-	ParticleMovementHandler *self = (ParticleMovementHandler*)pCommsHandler;
-
-	self->isConstructed = True;
-	_ParticleMovementHandler_Init ( self, True );
-}
-	
-void _ParticleMovementHandler_Build( void* pCommsHandler, void *data ){
-	
-}
-	
-void _ParticleMovementHandler_Initialise( void* pCommsHandler, void *data ){
-	
-}
-	
-void _ParticleMovementHandler_Execute( void* pCommsHandler, void *data ){
-	ParticleCommHandler*	self = (ParticleCommHandler*)pCommsHandler;
-	Swarm					*swarm = (Swarm*)data;
-
-	if( !swarm || !Stg_CheckType( swarm, Swarm ) )
-		return;
-
-	self->swarm = swarm;
-	self->_commFunction( self );	
-}
-
-void _ParticleMovementHandler_Destroy( void* pCommsHandler, void *data ){
-	
-}
-
-void ParticleMovementHandler_HandleParticleMovementBetweenProcs( ParticleCommHandler* pCommsHandler ) {
-	ParticleMovementHandler*	self = (ParticleMovementHandler*)pCommsHandler;
-	double                  startTime = 0;
-	Stream*                 info = Journal_Register( Info_Type, (Name)self->type  );
-
-	Journal_DPrintfL( self->debug, 1, "In %s(), for swarm \"%s\":\n", __func__, self->swarm->name );
-	if ( 1 == self->swarm->nProc ) {
-		Journal_DPrintfL( self->debug, 1, "Serial run -> nothing to communicate, returning.\n" );
-		Stream_UnIndentBranch( Swarm_Debug );
-		return;
-	}
-
-	Stream_IndentBranch( Swarm_Debug );
-
-	startTime = MPI_Wtime();
-
-	if ( self->swarm->cellShadowCount > 0 ) {
-		/* Allocate the recv count arrays and handles */
-		self->allocateIncomingCountArrays( (ParticleCommHandler*)self );
-		self->allocateOutgoingCountArrays( (ParticleCommHandler*)self );
-
-		/* First thing to do is begin non-blocking receive of incoming particles (for latency hiding) */
-		self->beginReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
-
-		/* Do a blocking send of outgoing counts, so our nbrs know what to receive */
-		self->sendOutgoingParticleCounts( (ParticleCommHandler*)self );
-
-		/* Now need to make sure that incoming particle counts are here, then begin receiving particles
-		   (We do this as early as possible for latency hiding purposes */
-		self->finishReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
-		self->allocateIncomingParticleArrays( (ParticleCommHandler*)self );
-		self->beginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
-			
-		/* OK, now begin sending out particles we know need to go to nbrs */
-		self->allocateOutgoingParticleArrays( (ParticleCommHandler*)self );
-		self->beginSendingParticles( (ParticleCommHandler*)self );
-	}
-	
-	if ( self->useGlobalFallbackCommStrategy ) {
-		self->particlesOutsideDomainIndices = Memory_Alloc_Array( Particle_Index, self->swarm->particlesArrayDelta,
-			"self->particlesOutsideDomainIndices" );
-
-		ParticleMovementHandler_DoGlobalFallbackCommunication( self );
-	}
-
-	if ( self->swarm->cellShadowCount > 0 ) {
-		/* Ok, at this point make sure our non-blocking receive of incoming via domain boundary
- 		 *  particles have completed: then immediately insert these particles into our local swarm */
-		self->finishReceiveOfIncomingParticlesAndUpdateIndices( (ParticleCommHandler*)self );
-	}
-
-	/* final update of the 'holes' in my particles list (some may be left if we sent more than we recv'd overall */
-	ParticleMovementHandler_FillRemainingHolesInLocalParticlesArray( (ParticleCommHandler*)self );
-
-	/* NB: Can't delete these until here, as they're needed by the "fillRemainingHoles" function above. */
-	if ( self->useGlobalFallbackCommStrategy ) {
-		Memory_Free( self->particlesOutsideDomainIndices );
-		self->particlesOutsideDomainIndices = NULL;
-	}
-
-	if ( self->swarm->cellShadowCount > 0 ) {
-		self->confirmOutgoingSendsCompleted( (ParticleCommHandler*)self );
-	}
-
-	_ParticleCommHandler_PrintCommunicationVolumeStats( (ParticleCommHandler*)self, startTime, info );
-
-	MPI_Barrier( self->swarm->comm );
-
-	/* clean up allocated memory, and zero counters, ready for next timestep */
-	if ( self->swarm->cellShadowCount > 0 ) {
-		self->freeIncomingArrays( (ParticleCommHandler*)self );
-		self->freeOutgoingArrays( (ParticleCommHandler*)self );
-	}
-	
-	_ParticleCommHandler_ZeroShadowCommStrategyCounters( (ParticleCommHandler*)self );
-	
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void ParticleMovementHandler_ZeroGlobalCommStrategyCounters( ParticleMovementHandler* self ) {
-	self->particlesOutsideDomainTotalCount = 0;
-	self->particlesOutsideDomainUnfilledCount = 0;
-	self->currParticleLeavingMyDomainIndex = 0;
-	self->globalParticlesArrivingMyDomainCount = 0;
-	self->globalParticlesOutsideDomainTotal = 0;
-}
-
-/* +++ Global fallback method related +++ */
-void ParticleMovementHandler_DoGlobalFallbackCommunication( ParticleMovementHandler* self ) {
-
-	ParticleMovementHandler_FindParticlesThatHaveMovedOutsideMyDomain( self );
-
-	ParticleMovementHandler_ShareAndUpdateParticlesThatHaveMovedOutsideDomains(
-		self,
-		&self->globalParticlesArrivingMyDomainCount,
-		&self->globalParticlesOutsideDomainTotal );
-
-}
-
-
-void ParticleMovementHandler_FindParticlesThatHaveMovedOutsideMyDomain( ParticleMovementHandler* self )
-{
-	Particle_Index		particlesOutsideDomainSize = 0;
-	GlobalParticle*         currParticle = NULL;
-	Particle_Index		lParticle_I = 0;
-
-	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-
-	self->particlesOutsideDomainTotalCount = 0;
-	self->currParticleLeavingMyDomainIndex = 0;
-	particlesOutsideDomainSize = self->swarm->particlesArrayDelta;
-
-
-	Journal_DPrintfL( self->debug, 1, "Checking the owning cell of each of my swarm's %d particles:\n",
-		self->swarm->particleLocalCount );
-	Stream_IndentBranch( Swarm_Debug );
-
-	for ( lParticle_I=0; lParticle_I < self->swarm->particleLocalCount; lParticle_I++ ) {
-
-		currParticle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
-		if ( currParticle->owningCell == self->swarm->cellDomainCount ) {
-			Journal_DPrintfL( self->debug, 3, "particle %d has moved outside domain to (%.2f,%.2f,%.2f): "
-				"saving index\n", lParticle_I, currParticle->coord[0], currParticle->coord[1],
-								currParticle->coord[2] );
-			if ( self->particlesOutsideDomainTotalCount == particlesOutsideDomainSize ) { 
-				particlesOutsideDomainSize += self->swarm->particlesArrayDelta;
-				Journal_DPrintfL( self->debug, 3, "(Need more memory to save indexes: increasing from %d to %d.)\n",
-					self->particlesOutsideDomainTotalCount, particlesOutsideDomainSize );
-				self->particlesOutsideDomainIndices = Memory_Realloc_Array( self->particlesOutsideDomainIndices,
-					Particle_Index, particlesOutsideDomainSize );
-			}
-			self->particlesOutsideDomainIndices[self->particlesOutsideDomainTotalCount++] = lParticle_I;
-		}	
-
-	}	
-	Stream_UnIndentBranch( Swarm_Debug );
-
-	self->particlesOutsideDomainUnfilledCount = self->particlesOutsideDomainTotalCount;
-
-	#if DEBUG
-	{
-		Particle_Index		particle_I = 0;
-		if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
-			Journal_DPrintf( self->debug, "%d Particles have moved outside my domain:\n\t[",
-				self->particlesOutsideDomainTotalCount );
-			for ( ; particle_I < self->particlesOutsideDomainTotalCount; particle_I++ ) {
-				Journal_DPrintf( self->debug, "%d, ", self->particlesOutsideDomainIndices[particle_I] );
-			}
-			Journal_DPrintf( self->debug, "]\n" );
-		}
-	}
-	#endif
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void ParticleMovementHandler_ShareAndUpdateParticlesThatHaveMovedOutsideDomains(
-		ParticleMovementHandler* self,
-		Particle_Index*      globalParticlesArrivingMyDomainCountPtr,
-		Particle_Index*      globalParticlesOutsideDomainTotalPtr )
-{
-	Particle_Index*		globalParticlesOutsideDomainCounts = NULL;		
-	Particle_Index		maxGlobalParticlesOutsideDomainCount = 0;		
-	Processor_Index		proc_I = 0;
-	Particle_Index		lParticle_I = 0;
-	Particle_Index		particle_I = 0;
-
-	Journal_DPrintfL( self->debug, 2, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-
-	(*globalParticlesArrivingMyDomainCountPtr) = 0;
-	(*globalParticlesOutsideDomainTotalPtr) = 0;		
-
-	/* Find the counts of particles	outside domain... */
-	ParticleMovementHandler_GetCountOfParticlesOutsideDomainPerProcessor(
-		self,
-		&globalParticlesOutsideDomainCounts,
-		&maxGlobalParticlesOutsideDomainCount,
-		globalParticlesOutsideDomainTotalPtr );
-
-	if ( (*globalParticlesOutsideDomainTotalPtr) > 0 ) {
-		Particle*		particlesLeavingMyDomain = NULL;
-		Particle*		globalParticlesLeavingDomains = NULL;
-		SizeT			particlesLeavingDomainSizeBytes = 0;
-		Cell_DomainIndex	lCell_I = 0;
-		GlobalParticle*	        currParticle = NULL;
-		Particle_Index		currProcParticlesOutsideDomainCount = 0;
-		Particle_Index		currProcOffset = 0;
-
-		particlesLeavingDomainSizeBytes = self->swarm->particleExtensionMgr->finalSize
-			* maxGlobalParticlesOutsideDomainCount;
-		particlesLeavingMyDomain = (Particle*)Memory_Alloc_Bytes( particlesLeavingDomainSizeBytes, "Particle",
-			"particlesLeavingMyDomain" );
-
-		// TODO: investigate doing this with an MPI_Indexed datatype instead...
-		Journal_DPrintfL( self->debug, 2, "Copying particles leaving my domain to temp. transfer array\n" );
-		Stream_IndentBranch( Swarm_Debug );
-
-		#if 0
-		MPI_Type_indexed( 
-			self->particlesOutsideDomainTotalCount,
-			blocklens,
-			self->particlesOutsideDomainIndices,//change to contiguous indices?
-			MPI_BYTE,
-			ParticlesLeavingDomainTransferIndexed
-			);
-		#endif	
-
-		for ( particle_I=0; particle_I < self->particlesOutsideDomainTotalCount; particle_I++ ) {
-			Journal_DPrintfL( self->debug, 3, "Copying particle %d to particlesLeavingMyDomain[%d]\n",
-				self->particlesOutsideDomainIndices[particle_I], particle_I );
-			Swarm_CopyParticleOffSwarm( self->swarm,
-				particlesLeavingMyDomain, particle_I,
-				self->particlesOutsideDomainIndices[particle_I] );
-		}	
-		Stream_UnIndentBranch( Swarm_Debug );
-
-		/* allocate the big global receive buffer */
-		globalParticlesLeavingDomains = (Particle*)Memory_Alloc_Bytes( particlesLeavingDomainSizeBytes * self->swarm->nProc,
-			"Particle", "globalParticlesLeavingDomains" );
-
-		Journal_DPrintfL( self->debug, 2, "Getting the global array of particles leaving domains\n" );
-		MPI_Allgather( particlesLeavingMyDomain, particlesLeavingDomainSizeBytes, MPI_BYTE,
-			globalParticlesLeavingDomains, particlesLeavingDomainSizeBytes, MPI_BYTE,
-			self->swarm->comm );
-
-		Journal_DPrintfL( self->debug, 2, "Checking through the global array of particles leaving domains, "
-			"and snaffling those moving into my domain:\n" );
-		Stream_IndentBranch( Swarm_Debug );
-		for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
-
-			if ( proc_I == self->swarm->myRank ) continue;
-
-			currProcOffset = proc_I * maxGlobalParticlesOutsideDomainCount;
-			currProcParticlesOutsideDomainCount = globalParticlesOutsideDomainCounts[proc_I];
-			
-			Journal_DPrintfL( self->debug, 3, "Checking particles that left proc. %d:\n", proc_I );
-			for ( particle_I=0; particle_I < currProcParticlesOutsideDomainCount; particle_I++ ) {
-				currParticle = (GlobalParticle*)ParticleAt( globalParticlesLeavingDomains,
-					(currProcOffset + particle_I),
-					self->swarm->particleExtensionMgr->finalSize );
-				lCell_I = CellLayout_CellOf( self->swarm->cellLayout, currParticle );
-				if ( lCell_I < self->swarm->cellLocalCount ) { 
-					#if DEBUG
-					Journal_DPrintfL( self->debug, 3, "Found particle at (%.2f,%.2f,%.2f) that's moved "
-						"into my local cell %d...\n", currParticle->coord[0],
-						currParticle->coord[1], currParticle->coord[2], lCell_I );
-					#endif	
-					
-					/* copy particle to the lowest available slot in my particles array */
-					lParticle_I = ParticleMovementHandler_FindFreeSlotAndPrepareForInsertion( (ParticleCommHandler*)self );
-
-					Swarm_CopyParticleOntoSwarm( self->swarm, lParticle_I,
-						globalParticlesLeavingDomains, (currProcOffset + particle_I) );
-					Swarm_AddParticleToCell( self->swarm, lCell_I, lParticle_I );
-					(*globalParticlesArrivingMyDomainCountPtr)++;
-				}
-				#if DEBUG
-				else {
-					currParticle = (GlobalParticle*)ParticleAt( globalParticlesLeavingDomains, 
-						(currProcOffset + particle_I),
-						self->swarm->particleExtensionMgr->finalSize );
-					Journal_DPrintfL( self->debug, 3, "Ignoring particle at (%.2f,%.2f,%.2f) since "
-						"not in my local cells...\n", currParticle->coord[0],
-						currParticle->coord[1], currParticle->coord[2] );
-				}
-				#endif
-			}		
-		}	
-		Stream_UnIndentBranch( Swarm_Debug );
-
-		Memory_Free( particlesLeavingMyDomain );
-		Memory_Free( globalParticlesLeavingDomains );
-
-		/* Defensive check to make sure particles not lost/created accidentally somehow */
-		if( self->defensive == True ) {
-			ParticleMovementHandler_EnsureParticleCountLeavingDomainsEqualsCountEnteringGlobally( self );
-		}
-	}	
-	Memory_Free( globalParticlesOutsideDomainCounts );
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void ParticleMovementHandler_EnsureParticleCountLeavingDomainsEqualsCountEnteringGlobally( ParticleMovementHandler* self ) {
-	Particle_Index		totalParticlesFoundEnteringDomains = 0;
-
-	MPI_Reduce( &self->globalParticlesArrivingMyDomainCount, &totalParticlesFoundEnteringDomains,
-		    1, MPI_UNSIGNED, MPI_SUM, 0, self->swarm->comm );
-
-	if ( 0 == self->swarm->myRank ) {
-		Stream*   errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-		Journal_Firewall( totalParticlesFoundEnteringDomains == self->globalParticlesOutsideDomainTotal,
-				  errorStream, "Error - in %s(): %d particles were found across all processors to be "
-				  "leaving the individual domains directly, but after sharing and searching %d were "
-				  "found entering them directly! These must match as no particles should be "
-				  "lost/created through advection.\n",
-				  __func__, self->globalParticlesOutsideDomainTotal,
-				  totalParticlesFoundEnteringDomains );
-	}
-}
-
-
-void ParticleMovementHandler_GetCountOfParticlesOutsideDomainPerProcessor(
-	ParticleMovementHandler*	self,
-	Particle_Index**	globalParticlesOutsideDomainCountsPtr,
-	Particle_Index*		maxGlobalParticlesOutsideDomainCountPtr,
-	Particle_Index*		globalParticlesOutsideDomainTotalPtr )
-{
-	Processor_Index		proc_I;
-
-	(*globalParticlesOutsideDomainCountsPtr) = Memory_Alloc_Array( Particle_Index, self->swarm->nProc,
-		"(*globalParticlesOutsideDomainCountsPtr)" );
-		
-	MPI_Allgather( (&self->particlesOutsideDomainTotalCount), 1, MPI_UNSIGNED, 
-		(*globalParticlesOutsideDomainCountsPtr), 1, MPI_UNSIGNED, self->swarm->comm );
-	
-	(*globalParticlesOutsideDomainTotalPtr) = 0;
-	for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
-		(*globalParticlesOutsideDomainTotalPtr) += (*globalParticlesOutsideDomainCountsPtr)[proc_I];
-		if ( (*globalParticlesOutsideDomainCountsPtr)[proc_I] > (*maxGlobalParticlesOutsideDomainCountPtr) ) {
-			(*maxGlobalParticlesOutsideDomainCountPtr) = (*globalParticlesOutsideDomainCountsPtr)[proc_I];
-		}
-	}	
-
-	#if DEBUG
-	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
-		Journal_DPrintf( self->debug, "Global counts of particles moving outside domains:\n" );
-		Journal_DPrintf( self->debug, "\tTotal: %d, Counts: [", (*globalParticlesOutsideDomainTotalPtr) );
-		for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
-			Journal_DPrintf( self->debug, "%d, ", (*globalParticlesOutsideDomainCountsPtr)[proc_I] );
-		}	
-		Journal_DPrintf( self->debug, "]\n" );
-	}	
-	#endif
-}
-
-/* TODO: look at using MPI_Indexed instead */
-void ParticleMovementHandler_FinishReceiveAndUpdateShadowParticlesEnteringMyDomain( ParticleCommHandler* self ) {
-	MPI_Status	status;
-	Cell_ShadowTransferIndex	stCell_I;
-	Cell_LocalIndex			lCell_I;
-	Neighbour_Index			nbr_I;
-	Cell_ShadowTransferIndex	shadowCellsFromProcCount;
-	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index			nbrCount = procNbrInfo->procNbrCnt;
-	Particle_InCellIndex		incomingCellParticleCount;
-	Particle_InCellIndex		cParticle_I;
-	Particle_Index			lParticle_I;
-	Index				incomingParticle_I=0; /*Index into the array of all leaving particle indices */
-	Index				incomingParticleSetsNotYetReceivedCount;
-	Bool*				incomingParticlesReceived;
-	#if DEBUG
-	GlobalParticle*                 currParticle;
-	#endif
-
-	Journal_DPrintf( self->debug, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-	
-	incomingParticlesReceived = Memory_Alloc_Array_Unnamed( Bool, nbrCount );
-
-	/* Calculate how many particle sets we have to receive */
-	incomingParticleSetsNotYetReceivedCount = 0;
-	for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
-		incomingParticlesReceived[nbr_I] = False;
-		if (self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0) {
-			incomingParticleSetsNotYetReceivedCount++;
-		}
-	}
-
-	while ( incomingParticleSetsNotYetReceivedCount > 0 ) {
-		int flag = 0;
-		Journal_DPrintfL( self->debug, 3, "%d particle sets still to go...\n", incomingParticleSetsNotYetReceivedCount );
-		for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
-			if ( (self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0) &&
-				(False == incomingParticlesReceived[nbr_I]) )
-			{
-				MPI_Test( self->particlesArrivingFromNbrShadowCellsHandles[nbr_I], &flag, &status );
-				if ( False == flag ) {
-					/* No results yet from this proc -> continue to next. */
-					continue;
-				}
-				else {
-					Journal_DPrintfL( self->debug, 3, "Received particles from nbr %d (proc %d):\n",
-						nbr_I, procNbrInfo->procNbrTbl[nbr_I] );
-					Stream_Indent( self->debug );
-
-					incomingParticle_I = 0;
-					shadowCellsFromProcCount = cellShadowInfo->procShadowedCnt[nbr_I];
-
-				
-					for ( stCell_I=0; stCell_I < shadowCellsFromProcCount; stCell_I++ ) {
-
-						lCell_I = cellShadowInfo->procShadowedTbl[nbr_I][stCell_I];
-						Journal_DPrintfL( self->debug, 3, "Incoming cell %d (local index %d):\n",
-							stCell_I, lCell_I );
-						Stream_Indent( self->debug );
-
-						incomingCellParticleCount =
-							self->particlesArrivingFromNbrShadowCellCounts[nbr_I][stCell_I];
-
-						for ( cParticle_I=0; cParticle_I < incomingCellParticleCount; cParticle_I++ ) {	
-
-							#if DEBUG
-							currParticle = (GlobalParticle*)ParticleAt(
-								self->particlesArrivingFromNbrShadowCells[nbr_I],
-								incomingParticle_I,
-								self->swarm->particleExtensionMgr->finalSize );
-							Journal_DPrintfL( self->debug, 3, "Handling its PIC %d: - at "
-								"(%.2f,%.2f,%.2f)\n", cParticle_I,
-								currParticle->coord[0], currParticle->coord[1],
-								currParticle->coord[2] );
-							#endif
-
-							Stream_Indent( self->debug );
-
-							lParticle_I = ParticleMovementHandler_FindFreeSlotAndPrepareForInsertion( self );
-
-							Swarm_CopyParticleOntoSwarm(
-								self->swarm,
-								lParticle_I,
-								self->particlesArrivingFromNbrShadowCells[nbr_I], incomingParticle_I++ ); 
-
-							Swarm_AddParticleToCell( self->swarm, lCell_I, lParticle_I );
-							
-							Stream_UnIndent( self->debug );
-						}	
-						Stream_UnIndent( self->debug );
-					}
-					incomingParticlesReceived[nbr_I] = True;
-					incomingParticleSetsNotYetReceivedCount--;
-					Stream_UnIndent( self->debug );
-				}
-			}
-		}
-	}	
-
-	Memory_Free( incomingParticlesReceived );
-
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-/* +++ Managment of particle array insertions/deletions +++ */
-
-
-Particle_Index ParticleMovementHandler_FindFreeSlotAndPrepareForInsertion( ParticleCommHandler* self )
-{
-	Particle_Index	lParticle_I = 0;
-
-	if ( self->shadowParticlesLeavingMeUnfilledCount > 0 ) {
-		Journal_DPrintfL( self->debug, 3, "Still %d holes available from "
-			"particles leaving via shadow cells\n-> free slot to add into is %d\n",
-			self->shadowParticlesLeavingMeUnfilledCount,
-			self->shadowParticlesLeavingMeIndices[self->currShadowParticleLeavingMeIndex]);
-			
-		lParticle_I = self->shadowParticlesLeavingMeIndices[self->currShadowParticleLeavingMeIndex];
-
-		self->currShadowParticleLeavingMeIndex++;
-		self->shadowParticlesLeavingMeUnfilledCount--;
-	}
-	else if ( self->particlesOutsideDomainUnfilledCount ) {
-		Journal_DPrintfL( self->debug, 3, "Still %d holes available from "
-			"particles leaving domain direct\n-> free slot to add into is %d\n", 
-			self->particlesOutsideDomainUnfilledCount,
-			self->particlesOutsideDomainIndices[self->currParticleLeavingMyDomainIndex]);
-
-		lParticle_I = self->particlesOutsideDomainIndices[self->currParticleLeavingMyDomainIndex];
-
-		self->currParticleLeavingMyDomainIndex++;
-		self->particlesOutsideDomainUnfilledCount--;
-	}
-	else {
-		Journal_DPrintfL( self->debug, 3, "No holes left from leaving "
-			"particles\n-> slot to insert into is end of array %d\n", 
-			self->swarm->particleLocalCount );
-		lParticle_I = self->swarm->particleLocalCount;
-		/*
-		if ( self->swarm->particleLocalCount == self->swarm->particlesArraySize ) {
-			Journal_DPrintfL( self->debug, 3, "Particles array memory used up "
-				"-> increasing from %d entries by %d\n",
-				self->swarm->particlesArraySize, self->swarm->particlesArrayDelta );
-			self->swarm->particlesArraySize += self->swarm->particlesArrayDelta;
-			self->swarm->particles = Memory_Realloc_Array_Bytes(
-				self->swarm->particles,
-				self->swarm->particleExtensionMgr->finalSize,
-				self->swarm->particlesArraySize );
-		}
-		*/
-		self->swarm->particleLocalCount++;
-		Swarm_Realloc( self->swarm );
-	}
-
-	return lParticle_I;
-}
-
-
-void ParticleMovementHandler_FillRemainingHolesInLocalParticlesArray( ParticleCommHandler* self )
-{
-	Particle_Index		prevParticlesArraySize = self->swarm->particlesArraySize;
-	Particle_Index		numHolesToFill;
-	Particle_InCellIndex	cParticle_I;
-	StandardParticle*	oldPtrToMovedParticle;
-	Cell_LocalIndex		owningCell;
-	Particle_Index		indexToInsertAt;
-	Particle_Index*		leavingParticlesArray = NULL;
-	Index			currLeavingParticleArrayEntry = 0;
-	Index			highestLeavingParticleArrayEntry;
-	Index			leavingParticlesUnfilledCount = 0;
-	Particle_Index		highestLeavingParticleIndex;
-	Particle_Index		candidateParticleToMove;
-	Bool			finishedFlag = False;
-	Bool			mergedArrayCreated = False;
-	Particle_Index		prevParticleCount = self->swarm->particleLocalCount;
-	
-	Journal_DPrintf( self->debug, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-
-	numHolesToFill = self->particlesOutsideDomainUnfilledCount + self->shadowParticlesLeavingMeUnfilledCount;
-	if ( numHolesToFill == 0 ) {
-		Journal_DPrintfL( self->debug, 2, "No holes to fill -> nothing to do, returning.\n" );
-		Stream_UnIndentBranch( Swarm_Debug );
-		return;
-	}
-	#if DEBUG
-	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
-		ParticleMovementHandler_PrintParticleSlotsYetToFill( self );
-	}	
-	#endif
-
-	/* work out the list we have to iterate over: */
-	if ( self->shadowParticlesLeavingMeUnfilledCount && !self->particlesOutsideDomainUnfilledCount ) {
-		Journal_DPrintfL( self->debug, 2, "Particles have only left via shadow cells -> no need to merge lists\n" );
-		leavingParticlesArray = &self->shadowParticlesLeavingMeIndices[self->currShadowParticleLeavingMeIndex];
-	}
-	else if ( self->particlesOutsideDomainUnfilledCount && !self->shadowParticlesLeavingMeUnfilledCount ) {
-		Journal_DPrintfL( self->debug, 2, "Particles have only left domain directly -> no need to merge lists\n" );
-		leavingParticlesArray = &self->particlesOutsideDomainIndices[self->currParticleLeavingMyDomainIndex];
-	} 
-	else {
-		Journal_DPrintfL( self->debug, 2, "Particles have left both via shadow cells and domain directly -> merge lists\n" );
-		leavingParticlesArray = ParticleMovementHandler_MergeListsOfUnfilledParticleSlots( self );
-		mergedArrayCreated = True;
-	}
-
-	/* Ok: while there are holes left to fill, find the highest candidate, move it, and reduce the count. */
-	Journal_DPrintfL( self->debug, 2, "Starting run through the %d particles to fill:\n", numHolesToFill );
-	Stream_IndentBranch( Swarm_Debug );
-
-	currLeavingParticleArrayEntry = 0;
-	highestLeavingParticleArrayEntry = numHolesToFill-1;
-	leavingParticlesUnfilledCount = numHolesToFill;
-
-	while ( leavingParticlesUnfilledCount > 0 ) {
-
-		indexToInsertAt = leavingParticlesArray[currLeavingParticleArrayEntry];
-		Journal_DPrintfL( self->debug, 3, "Attempting to fill leaving slot %d (at particle index %d):\n",
-			currLeavingParticleArrayEntry, indexToInsertAt );
-
-		Stream_Indent( self->debug );
-
-		/* This is where we work out the index of which particle to move into the free slot.
-		 * We Start from the end of the particles array, then decrement by 1 until we find a candidate that
-		 * hasn't itself already left. 
-		 * We also need to consider the possibility that every candidate higher than the current index
-		 * has also left, in which case we are done, and finish the while process. 
-		 * See the ParticleCommHandler Twiki page for diagrams illustrating this algorithm.
-		 */
-
-		candidateParticleToMove = self->swarm->particleLocalCount-1;
-		highestLeavingParticleIndex = leavingParticlesArray[highestLeavingParticleArrayEntry];
-		Journal_DPrintfL( self->debug, 3, "Searching for highest particle that hasn't also moved:\n" );
-		Stream_Indent( self->debug );	
-
-		while ( candidateParticleToMove == leavingParticlesArray[highestLeavingParticleArrayEntry] ) {
-			/* Check if that was the last candidate particle above the current one: */
-			/* This test needs to be at the top of this loop to handle the case where we have one
-			particle that's leaving */
-
-			if ( candidateParticleToMove <= indexToInsertAt ) {
-				Journal_DPrintfL( self->debug, 3, "** No more particles above current "
-					"hole %d to fill: we're done. **\n", indexToInsertAt );
-				/* Need the line below to mark the fact we failed to fill the current indexToInsertAt hole */
-				self->swarm->particleLocalCount--;
-				finishedFlag = True;
-				break;
-			}
-
-			Journal_DPrintfL( self->debug, 3, "Candidate particle %d has also left...\n",
-				candidateParticleToMove );
-
-			highestLeavingParticleArrayEntry--;
-			highestLeavingParticleIndex = leavingParticlesArray[highestLeavingParticleArrayEntry];
-			leavingParticlesUnfilledCount--;
-			self->swarm->particleLocalCount--;
-			candidateParticleToMove--;
-		}	
-		Stream_UnIndent( self->debug );	
-
-		if ( True == finishedFlag ) {
-			/* We must have hit the "no more candidate particles" criterion in the search loop, so
-			 * quit trying to fill empty holes entirely. */
-			Stream_UnIndent( self->debug );
-			break;
-		}
-
-		Journal_DPrintfL( self->debug, 3, "Highest valid particle found at index %d:\n",
-			candidateParticleToMove );
-		Journal_DFirewall( (candidateParticleToMove > indexToInsertAt), Swarm_Error,
-			"Error in %s: Empty hole filling\nalgorithm has stuffed up somehow,"
-			" since particle to be moved %d is <= slot to insert into %d.\n",
-			__func__, candidateParticleToMove, indexToInsertAt );
-		Stream_Indent( self->debug );	
-
-		Journal_DPrintfL( self->debug, 3, "Copying particle data from %d to %d\n",
-			candidateParticleToMove, indexToInsertAt );
-		Swarm_CopyParticleWithinSwarm( self->swarm, indexToInsertAt, candidateParticleToMove );
-
-		/* update the cell that the moved particle lives in to have the correct index into the
-		 * particle array for it. */
-		oldPtrToMovedParticle = Swarm_ParticleAt( self->swarm, candidateParticleToMove );
-		owningCell = oldPtrToMovedParticle->owningCell;
-		cParticle_I = Swarm_GetParticleIndexWithinCell( self->swarm, owningCell, candidateParticleToMove );
-		Journal_DPrintfL( self->debug, 3, "Updating owning cell: (Cell %d, PIC index %d) now -> p.i. %d\n",
-			owningCell, cParticle_I, indexToInsertAt );
-		self->swarm->cellParticleTbl[owningCell][cParticle_I] = indexToInsertAt;
-
-
-		Stream_UnIndent( self->debug );	
-
-		/* update the counters/indices */
-		currLeavingParticleArrayEntry++;
-		leavingParticlesUnfilledCount--;
-		self->swarm->particleLocalCount--;
-
-		Stream_UnIndent( self->debug );
-	}
-	Stream_UnIndentBranch( Swarm_Debug );
-
-	/* we only need to free the array of leaving particle slots if its a new merged list */
-	if ( mergedArrayCreated == True ) {
-		Memory_Free( leavingParticlesArray );
-	}
-
-	/* ------------------------- */
-	Journal_DPrintfL( self->debug, 2, "Local particle count reduced from %d to %d\n", prevParticleCount,
-		self->swarm->particleLocalCount );
-
-	/* Update the memory allocated to the particles array if particle count has reduced significantly */
-	while ( self->swarm->particlesArraySize > self->swarm->particleLocalCount + self->swarm->particlesArrayDelta ) {
-		self->swarm->particlesArraySize -= self->swarm->particlesArrayDelta;
-	}
-	if ( self->swarm->particlesArraySize < prevParticlesArraySize ) {
-		Journal_DPrintfL( self->debug, 2, "Reducing particles array entries from %d to %d\n",
-			prevParticlesArraySize, self->swarm->particlesArraySize );
-		Swarm_Realloc( self->swarm );
-		/*
-		self->swarm->particles = Memory_Realloc_Array_Bytes(
-			self->swarm->particles,
-			self->swarm->particleExtensionMgr->finalSize,
-			self->swarm->particlesArraySize );
-		*/
-	}	
-
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-Particle_Index* ParticleMovementHandler_MergeListsOfUnfilledParticleSlots( ParticleCommHandler* self )
-{
-	Particle_Index*		mergedLeavingParticleArray = NULL;
-	Particle_Index		slotsToFillTotalCount = 0;
-	Index			currMergedLeavingParticleEntry = 0;
-	Index			lowestUnmergedLeavingViaShadow = self->currShadowParticleLeavingMeIndex;
-	Index			lowestUnmergedLeavingDomain = self->currParticleLeavingMyDomainIndex;
-	Particle_Index		indexOfLowestUnmergedLeavingDomain = 0;
-	Index*			lowestUnmergedLeavingEntryToUpdatePtr = NULL;
-	Particle_Index		candidateMergeParticle = 0;
-
-	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
-	Stream_Indent( self->debug );
-
-	slotsToFillTotalCount = self->particlesOutsideDomainUnfilledCount + self->shadowParticlesLeavingMeUnfilledCount;
-	mergedLeavingParticleArray = Memory_Alloc_Array( Particle_Index, slotsToFillTotalCount, "mergedLeavingParticlesArray" );
-
-	while ( currMergedLeavingParticleEntry < slotsToFillTotalCount ) {
-		/* Need to initialise this to the max particle count every loop, in case the first condition is false,
-		so the 2nd will always hit it. */
-		candidateMergeParticle = self->swarm->particleLocalCount;
-		 
-		if ( lowestUnmergedLeavingViaShadow < self->shadowParticlesLeavingMeTotalCount ) {
-			candidateMergeParticle = self->shadowParticlesLeavingMeIndices[lowestUnmergedLeavingViaShadow];
-			lowestUnmergedLeavingEntryToUpdatePtr = &lowestUnmergedLeavingViaShadow;
-		}
-		if ( lowestUnmergedLeavingDomain < self->particlesOutsideDomainTotalCount ) {
-			indexOfLowestUnmergedLeavingDomain = self->particlesOutsideDomainIndices[lowestUnmergedLeavingDomain];
-
-			if ( indexOfLowestUnmergedLeavingDomain < candidateMergeParticle ) { 
-				candidateMergeParticle = indexOfLowestUnmergedLeavingDomain;
-				lowestUnmergedLeavingEntryToUpdatePtr = &lowestUnmergedLeavingDomain;
-			}	
-		}
-		
-		mergedLeavingParticleArray[currMergedLeavingParticleEntry++] = candidateMergeParticle;
-		(*lowestUnmergedLeavingEntryToUpdatePtr)++;
-
-		#if DEBUG
-		Journal_Firewall( lowestUnmergedLeavingViaShadow <= self->shadowParticlesLeavingMeTotalCount,
-			Swarm_Error, "Error: merging of unfilled particle lists stuffed up.\n" );
-		Journal_Firewall( lowestUnmergedLeavingDomain <= self->particlesOutsideDomainTotalCount,
-			Swarm_Error, "Error: merging of unfilled particle lists stuffed up.\n" );
-		#endif
-	}
-
-	#if DEBUG
-	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
-		Journal_DPrintf( self->debug, "Merged list of particles leaving proc:\n\t{" );
-		for ( currMergedLeavingParticleEntry=0; currMergedLeavingParticleEntry < slotsToFillTotalCount;
-			currMergedLeavingParticleEntry++ ) 
-		{
-			Journal_DPrintf( self->debug, "%d, ",
-				mergedLeavingParticleArray[currMergedLeavingParticleEntry] );
-		}
-		Journal_DPrintf( self->debug, "}\n" );
-	}
-	#endif
-	
-	Stream_UnIndent( self->debug );
-
-	return mergedLeavingParticleArray;
-}
-
-
-void ParticleMovementHandler_PrintParticleSlotsYetToFill( ParticleCommHandler* self ) {	
-	Index leavingParticleEntry;
-
-	Journal_DPrintf( self->debug, "%d slots yet to fill from particles leaving via shadow cells:\n",
-		self->shadowParticlesLeavingMeUnfilledCount );
-	leavingParticleEntry = self->currShadowParticleLeavingMeIndex;
-	Journal_DPrintf( self->debug, "\t{ " );
-	for ( ; leavingParticleEntry < self->shadowParticlesLeavingMeTotalCount; leavingParticleEntry++ ) {
-		Journal_DPrintf( self->debug, "%d, ", 
-			self->shadowParticlesLeavingMeIndices[leavingParticleEntry] );
-	}
-	Journal_DPrintf( self->debug, "}\n" );
-		
-	Journal_DPrintf( self->debug, "%d slots yet to fill from particles leaving domain directly:\n",
-		self->particlesOutsideDomainUnfilledCount );
-	leavingParticleEntry = self->currParticleLeavingMyDomainIndex;
-	Journal_DPrintf( self->debug, "\t{ " );
-	for ( ; leavingParticleEntry < self->particlesOutsideDomainTotalCount; leavingParticleEntry++ ) {
-		Journal_DPrintf( self->debug, "%d, ", 
-			self->particlesOutsideDomainIndices[leavingParticleEntry] );
-	}
-	Journal_DPrintf( self->debug, "}\n" );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleMovementHandler.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/ParticleMovementHandler.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1005 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ParticleMovementHandler.c 4001 2007-02-09 01:26:29Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "ShadowInfo.h"
+#include "shortcuts.h"
+#include "ParticleCommHandler.h"
+#include "ParticleMovementHandler.h"
+
+#include "SwarmClass.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+const Type ParticleMovementHandler_Type = "ParticleMovementHandler";
+
+void *ParticleMovementHandler_DefaultNew( Name name )
+{
+	/* Variables set in this function */
+	SizeT                                                        _sizeOfSelf = sizeof(ParticleMovementHandler);
+	Type                                                                type = ParticleMovementHandler_Type;
+	Stg_Class_DeleteFunction*                                        _delete = _ParticleMovementHandler_Delete;
+	Stg_Class_PrintFunction*                                          _print = _ParticleMovementHandler_Print;
+	Stg_Class_CopyFunction*                                            _copy = _ParticleMovementHandler_CopyFunc;
+	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleMovementHandler_DefaultNew;
+	Stg_Component_ConstructFunction*                              _construct = _ParticleMovementHandler_AssignFromXML;
+	Stg_Component_BuildFunction*                                      _build = _ParticleMovementHandler_Build;
+	Stg_Component_InitialiseFunction*                            _initialise = _ParticleMovementHandler_Initialise;
+	Stg_Component_ExecuteFunction*                                  _execute = _ParticleMovementHandler_Execute;
+	Stg_Component_DestroyFunction*                                  _destroy = _ParticleMovementHandler_Destroy;
+	Bool                                                            initFlag = False;
+	Bool                                       useGlobalFallbackCommStrategy = False;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
+	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
+	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
+	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
+	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
+	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
+	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
+	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
+	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
+
+	return _ParticleMovementHandler_New(  PARTICLEMOVEMENTHANDLER_PASSARGS  );
+}
+
+
+ParticleMovementHandler* ParticleMovementHandler_New( 
+		Name name,
+		Bool useGlobalFallbackCommStrategy
+		)
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(ParticleMovementHandler);
+	Type                                                      type = ParticleMovementHandler_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ParticleMovementHandler_Delete;
+	Stg_Class_PrintFunction*                                _print = _ParticleMovementHandler_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ParticleMovementHandler_CopyFunc;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleMovementHandler_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ParticleMovementHandler_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ParticleMovementHandler_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ParticleMovementHandler_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ParticleMovementHandler_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ParticleMovementHandler_Destroy;
+	Bool                                                  initFlag = True;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
+	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
+	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
+	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
+	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
+	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
+	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
+	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
+	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
+
+	return _ParticleMovementHandler_New(  PARTICLEMOVEMENTHANDLER_PASSARGS  );
+}
+
+
+ParticleMovementHandler* _ParticleMovementHandler_New(  PARTICLEMOVEMENTHANDLER_DEFARGS  )
+{
+	ParticleMovementHandler* self;
+	
+	/* Allocate memory */
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	_allocateOutgoingCountArrays                      = _ParticleCommHandler_AllocateOutgoingCountArrays;
+	_allocateOutgoingParticleArrays                   = _ParticleCommHandler_AllocateOutgoingParticlesArrays;
+	_freeOutgoingArrays                               = _ParticleCommHandler_FreeOutgoingArrays;
+	_allocateIncomingCountArrays                      = _ParticleCommHandler_AllocateIncomingCountArrays;
+	_allocateIncomingParticleArrays                   = _ParticleCommHandler_AllocateIncomingParticlesArrays;
+	_freeIncomingArrays                               = _ParticleCommHandler_FreeIncomingArrays;
+	_beginReceiveOfIncomingParticleCounts             = _ParticleCommHandler_BeginReceiveOfIncomingParticleCounts;
+	_finishReceiveOfIncomingParticleCounts            = _ParticleCommHandler_FinishReceiveOfIncomingParticleCounts;
+	_beginReceiveOfIncomingParticles                  = _ParticleCommHandler_BeginReceiveOfIncomingParticles;
+	_finishReceiveOfIncomingParticlesAndUpdateIndices = ParticleMovementHandler_FinishReceiveAndUpdateShadowParticlesEnteringMyDomain;
+	_sendOutgoingParticleCounts                       = _ParticleCommHandler_SendParticleTotalsInShadowCellsToNbrs;
+	_beginSendingParticles                            = _ParticleCommHandler_BeginSendingParticlesInShadowCellsToNbrs;
+	_confirmOutgoingSendsCompleted                    = _ParticleCommHandler_ConfirmOutgoingSendsCompleted;
+	_commFunction                                     = ParticleMovementHandler_HandleParticleMovementBetweenProcs;
+
+	self = (ParticleMovementHandler*)_ParticleCommHandler_New(  PARTICLECOMMHANDLER_PASSARGS  );
+	
+	/* General info */
+	/* Virtual info */
+	
+	/* ParticleMovementHandler info */
+	if( initFlag ){
+		_ParticleMovementHandler_Init( self, useGlobalFallbackCommStrategy );
+	}
+	
+	return self;
+}
+
+
+void _ParticleMovementHandler_Init(
+		ParticleMovementHandler*     self,
+		Bool                     useGlobalFallbackCommStrategy
+		)
+{
+	_ParticleCommHandler_Init( (ParticleCommHandler*)self );
+	self->defensive = False;
+	self->useGlobalFallbackCommStrategy = useGlobalFallbackCommStrategy;
+	self->particlesOutsideDomainIndices = NULL;
+	ParticleMovementHandler_ZeroGlobalCommStrategyCounters( self );	
+}
+
+
+void _ParticleMovementHandler_Delete(void* pCommsHandler ) {
+	/* Nothing to do, as the temporary arrays are deleted each step as soon as they are finished with. */
+	_ParticleCommHandler_Delete( pCommsHandler );
+}
+
+
+void _ParticleMovementHandler_Print( void* pCommsHandler, Stream* stream ) {
+	ParticleMovementHandler*	self = (ParticleMovementHandler*)pCommsHandler;
+	
+	/* General info */
+	Journal_Printf( stream, "ParticleMovementHandler (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_ParticleCommHandler_Print( self, stream );
+
+	/* Virtual info */
+
+	Journal_Printf( stream, "self->particlesOutsideDomainTotalCount: %d\n", self->particlesOutsideDomainTotalCount ); 
+	Journal_Printf( stream, "self->particlesOutsideDomainUnfiledCount: %d\n", self->particlesOutsideDomainUnfilledCount ); 
+	Journal_Printf( stream, "self->particlesOutsideDomainIndices(ptr): %p\n", self->particlesOutsideDomainIndices ); 
+}
+
+
+void* _ParticleMovementHandler_CopyFunc( const void* particleMovementHandler, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	
+	return _ParticleCommHandler_Copy( particleMovementHandler, dest, deep,
+		   nameExt, ptrMap );
+}
+
+void _ParticleMovementHandler_AssignFromXML( void* pCommsHandler, Stg_ComponentFactory* cf, void* data ){
+	ParticleMovementHandler *self = (ParticleMovementHandler*)pCommsHandler;
+
+	self->isConstructed = True;
+	_ParticleMovementHandler_Init ( self, True );
+}
+	
+void _ParticleMovementHandler_Build( void* pCommsHandler, void *data ){
+	
+}
+	
+void _ParticleMovementHandler_Initialise( void* pCommsHandler, void *data ){
+	
+}
+	
+void _ParticleMovementHandler_Execute( void* pCommsHandler, void *data ){
+	ParticleCommHandler*	self = (ParticleCommHandler*)pCommsHandler;
+	Swarm					*swarm = (Swarm*)data;
+
+	if( !swarm || !Stg_CheckType( swarm, Swarm ) )
+		return;
+
+	self->swarm = swarm;
+	self->_commFunction( self );	
+}
+
+void _ParticleMovementHandler_Destroy( void* pCommsHandler, void *data ){
+	
+}
+
+void ParticleMovementHandler_HandleParticleMovementBetweenProcs( ParticleCommHandler* pCommsHandler ) {
+	ParticleMovementHandler*	self = (ParticleMovementHandler*)pCommsHandler;
+	double                  startTime = 0;
+	Stream*                 info = Journal_Register( Info_Type, (Name)self->type  );
+
+	Journal_DPrintfL( self->debug, 1, "In %s(), for swarm \"%s\":\n", __func__, self->swarm->name );
+	if ( 1 == self->swarm->nProc ) {
+		Journal_DPrintfL( self->debug, 1, "Serial run -> nothing to communicate, returning.\n" );
+		Stream_UnIndentBranch( Swarm_Debug );
+		return;
+	}
+
+	Stream_IndentBranch( Swarm_Debug );
+
+	startTime = MPI_Wtime();
+
+	if ( self->swarm->cellShadowCount > 0 ) {
+		/* Allocate the recv count arrays and handles */
+		self->allocateIncomingCountArrays( (ParticleCommHandler*)self );
+		self->allocateOutgoingCountArrays( (ParticleCommHandler*)self );
+
+		/* First thing to do is begin non-blocking receive of incoming particles (for latency hiding) */
+		self->beginReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
+
+		/* Do a blocking send of outgoing counts, so our nbrs know what to receive */
+		self->sendOutgoingParticleCounts( (ParticleCommHandler*)self );
+
+		/* Now need to make sure that incoming particle counts are here, then begin receiving particles
+		   (We do this as early as possible for latency hiding purposes */
+		self->finishReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
+		self->allocateIncomingParticleArrays( (ParticleCommHandler*)self );
+		self->beginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
+			
+		/* OK, now begin sending out particles we know need to go to nbrs */
+		self->allocateOutgoingParticleArrays( (ParticleCommHandler*)self );
+		self->beginSendingParticles( (ParticleCommHandler*)self );
+	}
+	
+	if ( self->useGlobalFallbackCommStrategy ) {
+		self->particlesOutsideDomainIndices = Memory_Alloc_Array( Particle_Index, self->swarm->particlesArrayDelta,
+			"self->particlesOutsideDomainIndices" );
+
+		ParticleMovementHandler_DoGlobalFallbackCommunication( self );
+	}
+
+	if ( self->swarm->cellShadowCount > 0 ) {
+		/* Ok, at this point make sure our non-blocking receive of incoming via domain boundary
+ 		 *  particles have completed: then immediately insert these particles into our local swarm */
+		self->finishReceiveOfIncomingParticlesAndUpdateIndices( (ParticleCommHandler*)self );
+	}
+
+	/* final update of the 'holes' in my particles list (some may be left if we sent more than we recv'd overall */
+	ParticleMovementHandler_FillRemainingHolesInLocalParticlesArray( (ParticleCommHandler*)self );
+
+	/* NB: Can't delete these until here, as they're needed by the "fillRemainingHoles" function above. */
+	if ( self->useGlobalFallbackCommStrategy ) {
+		Memory_Free( self->particlesOutsideDomainIndices );
+		self->particlesOutsideDomainIndices = NULL;
+	}
+
+	if ( self->swarm->cellShadowCount > 0 ) {
+		self->confirmOutgoingSendsCompleted( (ParticleCommHandler*)self );
+	}
+
+	_ParticleCommHandler_PrintCommunicationVolumeStats( (ParticleCommHandler*)self, startTime, info );
+
+	MPI_Barrier( self->swarm->comm );
+
+	/* clean up allocated memory, and zero counters, ready for next timestep */
+	if ( self->swarm->cellShadowCount > 0 ) {
+		self->freeIncomingArrays( (ParticleCommHandler*)self );
+		self->freeOutgoingArrays( (ParticleCommHandler*)self );
+	}
+	
+	_ParticleCommHandler_ZeroShadowCommStrategyCounters( (ParticleCommHandler*)self );
+	
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void ParticleMovementHandler_ZeroGlobalCommStrategyCounters( ParticleMovementHandler* self ) {
+	self->particlesOutsideDomainTotalCount = 0;
+	self->particlesOutsideDomainUnfilledCount = 0;
+	self->currParticleLeavingMyDomainIndex = 0;
+	self->globalParticlesArrivingMyDomainCount = 0;
+	self->globalParticlesOutsideDomainTotal = 0;
+}
+
+/* +++ Global fallback method related +++ */
+void ParticleMovementHandler_DoGlobalFallbackCommunication( ParticleMovementHandler* self ) {
+
+	ParticleMovementHandler_FindParticlesThatHaveMovedOutsideMyDomain( self );
+
+	ParticleMovementHandler_ShareAndUpdateParticlesThatHaveMovedOutsideDomains(
+		self,
+		&self->globalParticlesArrivingMyDomainCount,
+		&self->globalParticlesOutsideDomainTotal );
+
+}
+
+
+void ParticleMovementHandler_FindParticlesThatHaveMovedOutsideMyDomain( ParticleMovementHandler* self )
+{
+	Particle_Index		particlesOutsideDomainSize = 0;
+	GlobalParticle*         currParticle = NULL;
+	Particle_Index		lParticle_I = 0;
+
+	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+
+	self->particlesOutsideDomainTotalCount = 0;
+	self->currParticleLeavingMyDomainIndex = 0;
+	particlesOutsideDomainSize = self->swarm->particlesArrayDelta;
+
+
+	Journal_DPrintfL( self->debug, 1, "Checking the owning cell of each of my swarm's %d particles:\n",
+		self->swarm->particleLocalCount );
+	Stream_IndentBranch( Swarm_Debug );
+
+	for ( lParticle_I=0; lParticle_I < self->swarm->particleLocalCount; lParticle_I++ ) {
+
+		currParticle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
+		if ( currParticle->owningCell == self->swarm->cellDomainCount ) {
+			Journal_DPrintfL( self->debug, 3, "particle %d has moved outside domain to (%.2f,%.2f,%.2f): "
+				"saving index\n", lParticle_I, currParticle->coord[0], currParticle->coord[1],
+								currParticle->coord[2] );
+			if ( self->particlesOutsideDomainTotalCount == particlesOutsideDomainSize ) { 
+				particlesOutsideDomainSize += self->swarm->particlesArrayDelta;
+				Journal_DPrintfL( self->debug, 3, "(Need more memory to save indexes: increasing from %d to %d.)\n",
+					self->particlesOutsideDomainTotalCount, particlesOutsideDomainSize );
+				self->particlesOutsideDomainIndices = Memory_Realloc_Array( self->particlesOutsideDomainIndices,
+					Particle_Index, particlesOutsideDomainSize );
+			}
+			self->particlesOutsideDomainIndices[self->particlesOutsideDomainTotalCount++] = lParticle_I;
+		}	
+
+	}	
+	Stream_UnIndentBranch( Swarm_Debug );
+
+	self->particlesOutsideDomainUnfilledCount = self->particlesOutsideDomainTotalCount;
+
+	#if DEBUG
+	{
+		Particle_Index		particle_I = 0;
+		if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
+			Journal_DPrintf( self->debug, "%d Particles have moved outside my domain:\n\t[",
+				self->particlesOutsideDomainTotalCount );
+			for ( ; particle_I < self->particlesOutsideDomainTotalCount; particle_I++ ) {
+				Journal_DPrintf( self->debug, "%d, ", self->particlesOutsideDomainIndices[particle_I] );
+			}
+			Journal_DPrintf( self->debug, "]\n" );
+		}
+	}
+	#endif
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void ParticleMovementHandler_ShareAndUpdateParticlesThatHaveMovedOutsideDomains(
+		ParticleMovementHandler* self,
+		Particle_Index*      globalParticlesArrivingMyDomainCountPtr,
+		Particle_Index*      globalParticlesOutsideDomainTotalPtr )
+{
+	Particle_Index*		globalParticlesOutsideDomainCounts = NULL;		
+	Particle_Index		maxGlobalParticlesOutsideDomainCount = 0;		
+	Processor_Index		proc_I = 0;
+	Particle_Index		lParticle_I = 0;
+	Particle_Index		particle_I = 0;
+
+	Journal_DPrintfL( self->debug, 2, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+
+	(*globalParticlesArrivingMyDomainCountPtr) = 0;
+	(*globalParticlesOutsideDomainTotalPtr) = 0;		
+
+	/* Find the counts of particles	outside domain... */
+	ParticleMovementHandler_GetCountOfParticlesOutsideDomainPerProcessor(
+		self,
+		&globalParticlesOutsideDomainCounts,
+		&maxGlobalParticlesOutsideDomainCount,
+		globalParticlesOutsideDomainTotalPtr );
+
+	if ( (*globalParticlesOutsideDomainTotalPtr) > 0 ) {
+		Particle*		particlesLeavingMyDomain = NULL;
+		Particle*		globalParticlesLeavingDomains = NULL;
+		SizeT			particlesLeavingDomainSizeBytes = 0;
+		Cell_DomainIndex	lCell_I = 0;
+		GlobalParticle*	        currParticle = NULL;
+		Particle_Index		currProcParticlesOutsideDomainCount = 0;
+		Particle_Index		currProcOffset = 0;
+
+		particlesLeavingDomainSizeBytes = self->swarm->particleExtensionMgr->finalSize
+			* maxGlobalParticlesOutsideDomainCount;
+		particlesLeavingMyDomain = (Particle*)Memory_Alloc_Bytes( particlesLeavingDomainSizeBytes, "Particle",
+			"particlesLeavingMyDomain" );
+
+		// TODO: investigate doing this with an MPI_Indexed datatype instead...
+		Journal_DPrintfL( self->debug, 2, "Copying particles leaving my domain to temp. transfer array\n" );
+		Stream_IndentBranch( Swarm_Debug );
+
+		#if 0
+		MPI_Type_indexed( 
+			self->particlesOutsideDomainTotalCount,
+			blocklens,
+			self->particlesOutsideDomainIndices,//change to contiguous indices?
+			MPI_BYTE,
+			ParticlesLeavingDomainTransferIndexed
+			);
+		#endif	
+
+		for ( particle_I=0; particle_I < self->particlesOutsideDomainTotalCount; particle_I++ ) {
+			Journal_DPrintfL( self->debug, 3, "Copying particle %d to particlesLeavingMyDomain[%d]\n",
+				self->particlesOutsideDomainIndices[particle_I], particle_I );
+			Swarm_CopyParticleOffSwarm( self->swarm,
+				particlesLeavingMyDomain, particle_I,
+				self->particlesOutsideDomainIndices[particle_I] );
+		}	
+		Stream_UnIndentBranch( Swarm_Debug );
+
+		/* allocate the big global receive buffer */
+		globalParticlesLeavingDomains = (Particle*)Memory_Alloc_Bytes( particlesLeavingDomainSizeBytes * self->swarm->nProc,
+			"Particle", "globalParticlesLeavingDomains" );
+
+		Journal_DPrintfL( self->debug, 2, "Getting the global array of particles leaving domains\n" );
+		MPI_Allgather( particlesLeavingMyDomain, particlesLeavingDomainSizeBytes, MPI_BYTE,
+			globalParticlesLeavingDomains, particlesLeavingDomainSizeBytes, MPI_BYTE,
+			self->swarm->comm );
+
+		Journal_DPrintfL( self->debug, 2, "Checking through the global array of particles leaving domains, "
+			"and snaffling those moving into my domain:\n" );
+		Stream_IndentBranch( Swarm_Debug );
+		for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
+
+			if ( proc_I == self->swarm->myRank ) continue;
+
+			currProcOffset = proc_I * maxGlobalParticlesOutsideDomainCount;
+			currProcParticlesOutsideDomainCount = globalParticlesOutsideDomainCounts[proc_I];
+			
+			Journal_DPrintfL( self->debug, 3, "Checking particles that left proc. %d:\n", proc_I );
+			for ( particle_I=0; particle_I < currProcParticlesOutsideDomainCount; particle_I++ ) {
+				currParticle = (GlobalParticle*)ParticleAt( globalParticlesLeavingDomains,
+					(currProcOffset + particle_I),
+					self->swarm->particleExtensionMgr->finalSize );
+				lCell_I = CellLayout_CellOf( self->swarm->cellLayout, currParticle );
+				if ( lCell_I < self->swarm->cellLocalCount ) { 
+					#if DEBUG
+					Journal_DPrintfL( self->debug, 3, "Found particle at (%.2f,%.2f,%.2f) that's moved "
+						"into my local cell %d...\n", currParticle->coord[0],
+						currParticle->coord[1], currParticle->coord[2], lCell_I );
+					#endif	
+					
+					/* copy particle to the lowest available slot in my particles array */
+					lParticle_I = ParticleMovementHandler_FindFreeSlotAndPrepareForInsertion( (ParticleCommHandler*)self );
+
+					Swarm_CopyParticleOntoSwarm( self->swarm, lParticle_I,
+						globalParticlesLeavingDomains, (currProcOffset + particle_I) );
+					Swarm_AddParticleToCell( self->swarm, lCell_I, lParticle_I );
+					(*globalParticlesArrivingMyDomainCountPtr)++;
+				}
+				#if DEBUG
+				else {
+					currParticle = (GlobalParticle*)ParticleAt( globalParticlesLeavingDomains, 
+						(currProcOffset + particle_I),
+						self->swarm->particleExtensionMgr->finalSize );
+					Journal_DPrintfL( self->debug, 3, "Ignoring particle at (%.2f,%.2f,%.2f) since "
+						"not in my local cells...\n", currParticle->coord[0],
+						currParticle->coord[1], currParticle->coord[2] );
+				}
+				#endif
+			}		
+		}	
+		Stream_UnIndentBranch( Swarm_Debug );
+
+		Memory_Free( particlesLeavingMyDomain );
+		Memory_Free( globalParticlesLeavingDomains );
+
+		/* Defensive check to make sure particles not lost/created accidentally somehow */
+		if( self->defensive == True ) {
+			ParticleMovementHandler_EnsureParticleCountLeavingDomainsEqualsCountEnteringGlobally( self );
+		}
+	}	
+	Memory_Free( globalParticlesOutsideDomainCounts );
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void ParticleMovementHandler_EnsureParticleCountLeavingDomainsEqualsCountEnteringGlobally( ParticleMovementHandler* self ) {
+	Particle_Index		totalParticlesFoundEnteringDomains = 0;
+
+	MPI_Reduce( &self->globalParticlesArrivingMyDomainCount, &totalParticlesFoundEnteringDomains,
+		    1, MPI_UNSIGNED, MPI_SUM, 0, self->swarm->comm );
+
+	if ( 0 == self->swarm->myRank ) {
+		Stream*   errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+		Journal_Firewall( totalParticlesFoundEnteringDomains == self->globalParticlesOutsideDomainTotal,
+				  errorStream, "Error - in %s(): %d particles were found across all processors to be "
+				  "leaving the individual domains directly, but after sharing and searching %d were "
+				  "found entering them directly! These must match as no particles should be "
+				  "lost/created through advection.\n",
+				  __func__, self->globalParticlesOutsideDomainTotal,
+				  totalParticlesFoundEnteringDomains );
+	}
+}
+
+
+void ParticleMovementHandler_GetCountOfParticlesOutsideDomainPerProcessor(
+	ParticleMovementHandler*	self,
+	Particle_Index**	globalParticlesOutsideDomainCountsPtr,
+	Particle_Index*		maxGlobalParticlesOutsideDomainCountPtr,
+	Particle_Index*		globalParticlesOutsideDomainTotalPtr )
+{
+	Processor_Index		proc_I;
+
+	(*globalParticlesOutsideDomainCountsPtr) = Memory_Alloc_Array( Particle_Index, self->swarm->nProc,
+		"(*globalParticlesOutsideDomainCountsPtr)" );
+		
+	MPI_Allgather( (&self->particlesOutsideDomainTotalCount), 1, MPI_UNSIGNED, 
+		(*globalParticlesOutsideDomainCountsPtr), 1, MPI_UNSIGNED, self->swarm->comm );
+	
+	(*globalParticlesOutsideDomainTotalPtr) = 0;
+	for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
+		(*globalParticlesOutsideDomainTotalPtr) += (*globalParticlesOutsideDomainCountsPtr)[proc_I];
+		if ( (*globalParticlesOutsideDomainCountsPtr)[proc_I] > (*maxGlobalParticlesOutsideDomainCountPtr) ) {
+			(*maxGlobalParticlesOutsideDomainCountPtr) = (*globalParticlesOutsideDomainCountsPtr)[proc_I];
+		}
+	}	
+
+	#if DEBUG
+	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
+		Journal_DPrintf( self->debug, "Global counts of particles moving outside domains:\n" );
+		Journal_DPrintf( self->debug, "\tTotal: %d, Counts: [", (*globalParticlesOutsideDomainTotalPtr) );
+		for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
+			Journal_DPrintf( self->debug, "%d, ", (*globalParticlesOutsideDomainCountsPtr)[proc_I] );
+		}	
+		Journal_DPrintf( self->debug, "]\n" );
+	}	
+	#endif
+}
+
+/* TODO: look at using MPI_Indexed instead */
+void ParticleMovementHandler_FinishReceiveAndUpdateShadowParticlesEnteringMyDomain( ParticleCommHandler* self ) {
+	MPI_Status	status;
+	Cell_ShadowTransferIndex	stCell_I;
+	Cell_LocalIndex			lCell_I;
+	Neighbour_Index			nbr_I;
+	Cell_ShadowTransferIndex	shadowCellsFromProcCount;
+	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index			nbrCount = procNbrInfo->procNbrCnt;
+	Particle_InCellIndex		incomingCellParticleCount;
+	Particle_InCellIndex		cParticle_I;
+	Particle_Index			lParticle_I;
+	Index				incomingParticle_I=0; /*Index into the array of all leaving particle indices */
+	Index				incomingParticleSetsNotYetReceivedCount;
+	Bool*				incomingParticlesReceived;
+	#if DEBUG
+	GlobalParticle*                 currParticle;
+	#endif
+
+	Journal_DPrintf( self->debug, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+	
+	incomingParticlesReceived = Memory_Alloc_Array_Unnamed( Bool, nbrCount );
+
+	/* Calculate how many particle sets we have to receive */
+	incomingParticleSetsNotYetReceivedCount = 0;
+	for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
+		incomingParticlesReceived[nbr_I] = False;
+		if (self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0) {
+			incomingParticleSetsNotYetReceivedCount++;
+		}
+	}
+
+	while ( incomingParticleSetsNotYetReceivedCount > 0 ) {
+		int flag = 0;
+		Journal_DPrintfL( self->debug, 3, "%d particle sets still to go...\n", incomingParticleSetsNotYetReceivedCount );
+		for ( nbr_I=0; nbr_I < nbrCount; nbr_I++ ) {
+			if ( (self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0) &&
+				(False == incomingParticlesReceived[nbr_I]) )
+			{
+				MPI_Test( self->particlesArrivingFromNbrShadowCellsHandles[nbr_I], &flag, &status );
+				if ( False == flag ) {
+					/* No results yet from this proc -> continue to next. */
+					continue;
+				}
+				else {
+					Journal_DPrintfL( self->debug, 3, "Received particles from nbr %d (proc %d):\n",
+						nbr_I, procNbrInfo->procNbrTbl[nbr_I] );
+					Stream_Indent( self->debug );
+
+					incomingParticle_I = 0;
+					shadowCellsFromProcCount = cellShadowInfo->procShadowedCnt[nbr_I];
+
+				
+					for ( stCell_I=0; stCell_I < shadowCellsFromProcCount; stCell_I++ ) {
+
+						lCell_I = cellShadowInfo->procShadowedTbl[nbr_I][stCell_I];
+						Journal_DPrintfL( self->debug, 3, "Incoming cell %d (local index %d):\n",
+							stCell_I, lCell_I );
+						Stream_Indent( self->debug );
+
+						incomingCellParticleCount =
+							self->particlesArrivingFromNbrShadowCellCounts[nbr_I][stCell_I];
+
+						for ( cParticle_I=0; cParticle_I < incomingCellParticleCount; cParticle_I++ ) {	
+
+							#if DEBUG
+							currParticle = (GlobalParticle*)ParticleAt(
+								self->particlesArrivingFromNbrShadowCells[nbr_I],
+								incomingParticle_I,
+								self->swarm->particleExtensionMgr->finalSize );
+							Journal_DPrintfL( self->debug, 3, "Handling its PIC %d: - at "
+								"(%.2f,%.2f,%.2f)\n", cParticle_I,
+								currParticle->coord[0], currParticle->coord[1],
+								currParticle->coord[2] );
+							#endif
+
+							Stream_Indent( self->debug );
+
+							lParticle_I = ParticleMovementHandler_FindFreeSlotAndPrepareForInsertion( self );
+
+							Swarm_CopyParticleOntoSwarm(
+								self->swarm,
+								lParticle_I,
+								self->particlesArrivingFromNbrShadowCells[nbr_I], incomingParticle_I++ ); 
+
+							Swarm_AddParticleToCell( self->swarm, lCell_I, lParticle_I );
+							
+							Stream_UnIndent( self->debug );
+						}	
+						Stream_UnIndent( self->debug );
+					}
+					incomingParticlesReceived[nbr_I] = True;
+					incomingParticleSetsNotYetReceivedCount--;
+					Stream_UnIndent( self->debug );
+				}
+			}
+		}
+	}	
+
+	Memory_Free( incomingParticlesReceived );
+
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+/* +++ Managment of particle array insertions/deletions +++ */
+
+
+Particle_Index ParticleMovementHandler_FindFreeSlotAndPrepareForInsertion( ParticleCommHandler* self )
+{
+	Particle_Index	lParticle_I = 0;
+
+	if ( self->shadowParticlesLeavingMeUnfilledCount > 0 ) {
+		Journal_DPrintfL( self->debug, 3, "Still %d holes available from "
+			"particles leaving via shadow cells\n-> free slot to add into is %d\n",
+			self->shadowParticlesLeavingMeUnfilledCount,
+			self->shadowParticlesLeavingMeIndices[self->currShadowParticleLeavingMeIndex]);
+			
+		lParticle_I = self->shadowParticlesLeavingMeIndices[self->currShadowParticleLeavingMeIndex];
+
+		self->currShadowParticleLeavingMeIndex++;
+		self->shadowParticlesLeavingMeUnfilledCount--;
+	}
+	else if ( self->particlesOutsideDomainUnfilledCount ) {
+		Journal_DPrintfL( self->debug, 3, "Still %d holes available from "
+			"particles leaving domain direct\n-> free slot to add into is %d\n", 
+			self->particlesOutsideDomainUnfilledCount,
+			self->particlesOutsideDomainIndices[self->currParticleLeavingMyDomainIndex]);
+
+		lParticle_I = self->particlesOutsideDomainIndices[self->currParticleLeavingMyDomainIndex];
+
+		self->currParticleLeavingMyDomainIndex++;
+		self->particlesOutsideDomainUnfilledCount--;
+	}
+	else {
+		Journal_DPrintfL( self->debug, 3, "No holes left from leaving "
+			"particles\n-> slot to insert into is end of array %d\n", 
+			self->swarm->particleLocalCount );
+		lParticle_I = self->swarm->particleLocalCount;
+		/*
+		if ( self->swarm->particleLocalCount == self->swarm->particlesArraySize ) {
+			Journal_DPrintfL( self->debug, 3, "Particles array memory used up "
+				"-> increasing from %d entries by %d\n",
+				self->swarm->particlesArraySize, self->swarm->particlesArrayDelta );
+			self->swarm->particlesArraySize += self->swarm->particlesArrayDelta;
+			self->swarm->particles = Memory_Realloc_Array_Bytes(
+				self->swarm->particles,
+				self->swarm->particleExtensionMgr->finalSize,
+				self->swarm->particlesArraySize );
+		}
+		*/
+		self->swarm->particleLocalCount++;
+		Swarm_Realloc( self->swarm );
+	}
+
+	return lParticle_I;
+}
+
+
+void ParticleMovementHandler_FillRemainingHolesInLocalParticlesArray( ParticleCommHandler* self )
+{
+	Particle_Index		prevParticlesArraySize = self->swarm->particlesArraySize;
+	Particle_Index		numHolesToFill;
+	Particle_InCellIndex	cParticle_I;
+	StandardParticle*	oldPtrToMovedParticle;
+	Cell_LocalIndex		owningCell;
+	Particle_Index		indexToInsertAt;
+	Particle_Index*		leavingParticlesArray = NULL;
+	Index			currLeavingParticleArrayEntry = 0;
+	Index			highestLeavingParticleArrayEntry;
+	Index			leavingParticlesUnfilledCount = 0;
+	Particle_Index		highestLeavingParticleIndex;
+	Particle_Index		candidateParticleToMove;
+	Bool			finishedFlag = False;
+	Bool			mergedArrayCreated = False;
+	Particle_Index		prevParticleCount = self->swarm->particleLocalCount;
+	
+	Journal_DPrintf( self->debug, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+
+	numHolesToFill = self->particlesOutsideDomainUnfilledCount + self->shadowParticlesLeavingMeUnfilledCount;
+	if ( numHolesToFill == 0 ) {
+		Journal_DPrintfL( self->debug, 2, "No holes to fill -> nothing to do, returning.\n" );
+		Stream_UnIndentBranch( Swarm_Debug );
+		return;
+	}
+	#if DEBUG
+	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
+		ParticleMovementHandler_PrintParticleSlotsYetToFill( self );
+	}	
+	#endif
+
+	/* work out the list we have to iterate over: */
+	if ( self->shadowParticlesLeavingMeUnfilledCount && !self->particlesOutsideDomainUnfilledCount ) {
+		Journal_DPrintfL( self->debug, 2, "Particles have only left via shadow cells -> no need to merge lists\n" );
+		leavingParticlesArray = &self->shadowParticlesLeavingMeIndices[self->currShadowParticleLeavingMeIndex];
+	}
+	else if ( self->particlesOutsideDomainUnfilledCount && !self->shadowParticlesLeavingMeUnfilledCount ) {
+		Journal_DPrintfL( self->debug, 2, "Particles have only left domain directly -> no need to merge lists\n" );
+		leavingParticlesArray = &self->particlesOutsideDomainIndices[self->currParticleLeavingMyDomainIndex];
+	} 
+	else {
+		Journal_DPrintfL( self->debug, 2, "Particles have left both via shadow cells and domain directly -> merge lists\n" );
+		leavingParticlesArray = ParticleMovementHandler_MergeListsOfUnfilledParticleSlots( self );
+		mergedArrayCreated = True;
+	}
+
+	/* Ok: while there are holes left to fill, find the highest candidate, move it, and reduce the count. */
+	Journal_DPrintfL( self->debug, 2, "Starting run through the %d particles to fill:\n", numHolesToFill );
+	Stream_IndentBranch( Swarm_Debug );
+
+	currLeavingParticleArrayEntry = 0;
+	highestLeavingParticleArrayEntry = numHolesToFill-1;
+	leavingParticlesUnfilledCount = numHolesToFill;
+
+	while ( leavingParticlesUnfilledCount > 0 ) {
+
+		indexToInsertAt = leavingParticlesArray[currLeavingParticleArrayEntry];
+		Journal_DPrintfL( self->debug, 3, "Attempting to fill leaving slot %d (at particle index %d):\n",
+			currLeavingParticleArrayEntry, indexToInsertAt );
+
+		Stream_Indent( self->debug );
+
+		/* This is where we work out the index of which particle to move into the free slot.
+		 * We Start from the end of the particles array, then decrement by 1 until we find a candidate that
+		 * hasn't itself already left. 
+		 * We also need to consider the possibility that every candidate higher than the current index
+		 * has also left, in which case we are done, and finish the while process. 
+		 * See the ParticleCommHandler Twiki page for diagrams illustrating this algorithm.
+		 */
+
+		candidateParticleToMove = self->swarm->particleLocalCount-1;
+		highestLeavingParticleIndex = leavingParticlesArray[highestLeavingParticleArrayEntry];
+		Journal_DPrintfL( self->debug, 3, "Searching for highest particle that hasn't also moved:\n" );
+		Stream_Indent( self->debug );	
+
+		while ( candidateParticleToMove == leavingParticlesArray[highestLeavingParticleArrayEntry] ) {
+			/* Check if that was the last candidate particle above the current one: */
+			/* This test needs to be at the top of this loop to handle the case where we have one
+			particle that's leaving */
+
+			if ( candidateParticleToMove <= indexToInsertAt ) {
+				Journal_DPrintfL( self->debug, 3, "** No more particles above current "
+					"hole %d to fill: we're done. **\n", indexToInsertAt );
+				/* Need the line below to mark the fact we failed to fill the current indexToInsertAt hole */
+				self->swarm->particleLocalCount--;
+				finishedFlag = True;
+				break;
+			}
+
+			Journal_DPrintfL( self->debug, 3, "Candidate particle %d has also left...\n",
+				candidateParticleToMove );
+
+			highestLeavingParticleArrayEntry--;
+			highestLeavingParticleIndex = leavingParticlesArray[highestLeavingParticleArrayEntry];
+			leavingParticlesUnfilledCount--;
+			self->swarm->particleLocalCount--;
+			candidateParticleToMove--;
+		}	
+		Stream_UnIndent( self->debug );	
+
+		if ( True == finishedFlag ) {
+			/* We must have hit the "no more candidate particles" criterion in the search loop, so
+			 * quit trying to fill empty holes entirely. */
+			Stream_UnIndent( self->debug );
+			break;
+		}
+
+		Journal_DPrintfL( self->debug, 3, "Highest valid particle found at index %d:\n",
+			candidateParticleToMove );
+		Journal_DFirewall( (candidateParticleToMove > indexToInsertAt), Swarm_Error,
+			"Error in %s: Empty hole filling\nalgorithm has stuffed up somehow,"
+			" since particle to be moved %d is <= slot to insert into %d.\n",
+			__func__, candidateParticleToMove, indexToInsertAt );
+		Stream_Indent( self->debug );	
+
+		Journal_DPrintfL( self->debug, 3, "Copying particle data from %d to %d\n",
+			candidateParticleToMove, indexToInsertAt );
+		Swarm_CopyParticleWithinSwarm( self->swarm, indexToInsertAt, candidateParticleToMove );
+
+		/* update the cell that the moved particle lives in to have the correct index into the
+		 * particle array for it. */
+		oldPtrToMovedParticle = Swarm_ParticleAt( self->swarm, candidateParticleToMove );
+		owningCell = oldPtrToMovedParticle->owningCell;
+		cParticle_I = Swarm_GetParticleIndexWithinCell( self->swarm, owningCell, candidateParticleToMove );
+		Journal_DPrintfL( self->debug, 3, "Updating owning cell: (Cell %d, PIC index %d) now -> p.i. %d\n",
+			owningCell, cParticle_I, indexToInsertAt );
+		self->swarm->cellParticleTbl[owningCell][cParticle_I] = indexToInsertAt;
+
+
+		Stream_UnIndent( self->debug );	
+
+		/* update the counters/indices */
+		currLeavingParticleArrayEntry++;
+		leavingParticlesUnfilledCount--;
+		self->swarm->particleLocalCount--;
+
+		Stream_UnIndent( self->debug );
+	}
+	Stream_UnIndentBranch( Swarm_Debug );
+
+	/* we only need to free the array of leaving particle slots if its a new merged list */
+	if ( mergedArrayCreated == True ) {
+		Memory_Free( leavingParticlesArray );
+	}
+
+	/* ------------------------- */
+	Journal_DPrintfL( self->debug, 2, "Local particle count reduced from %d to %d\n", prevParticleCount,
+		self->swarm->particleLocalCount );
+
+	/* Update the memory allocated to the particles array if particle count has reduced significantly */
+	while ( self->swarm->particlesArraySize > self->swarm->particleLocalCount + self->swarm->particlesArrayDelta ) {
+		self->swarm->particlesArraySize -= self->swarm->particlesArrayDelta;
+	}
+	if ( self->swarm->particlesArraySize < prevParticlesArraySize ) {
+		Journal_DPrintfL( self->debug, 2, "Reducing particles array entries from %d to %d\n",
+			prevParticlesArraySize, self->swarm->particlesArraySize );
+		Swarm_Realloc( self->swarm );
+		/*
+		self->swarm->particles = Memory_Realloc_Array_Bytes(
+			self->swarm->particles,
+			self->swarm->particleExtensionMgr->finalSize,
+			self->swarm->particlesArraySize );
+		*/
+	}	
+
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+Particle_Index* ParticleMovementHandler_MergeListsOfUnfilledParticleSlots( ParticleCommHandler* self )
+{
+	Particle_Index*		mergedLeavingParticleArray = NULL;
+	Particle_Index		slotsToFillTotalCount = 0;
+	Index			currMergedLeavingParticleEntry = 0;
+	Index			lowestUnmergedLeavingViaShadow = self->currShadowParticleLeavingMeIndex;
+	Index			lowestUnmergedLeavingDomain = self->currParticleLeavingMyDomainIndex;
+	Particle_Index		indexOfLowestUnmergedLeavingDomain = 0;
+	Index*			lowestUnmergedLeavingEntryToUpdatePtr = NULL;
+	Particle_Index		candidateMergeParticle = 0;
+
+	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
+	Stream_Indent( self->debug );
+
+	slotsToFillTotalCount = self->particlesOutsideDomainUnfilledCount + self->shadowParticlesLeavingMeUnfilledCount;
+	mergedLeavingParticleArray = Memory_Alloc_Array( Particle_Index, slotsToFillTotalCount, "mergedLeavingParticlesArray" );
+
+	while ( currMergedLeavingParticleEntry < slotsToFillTotalCount ) {
+		/* Need to initialise this to the max particle count every loop, in case the first condition is false,
+		so the 2nd will always hit it. */
+		candidateMergeParticle = self->swarm->particleLocalCount;
+		 
+		if ( lowestUnmergedLeavingViaShadow < self->shadowParticlesLeavingMeTotalCount ) {
+			candidateMergeParticle = self->shadowParticlesLeavingMeIndices[lowestUnmergedLeavingViaShadow];
+			lowestUnmergedLeavingEntryToUpdatePtr = &lowestUnmergedLeavingViaShadow;
+		}
+		if ( lowestUnmergedLeavingDomain < self->particlesOutsideDomainTotalCount ) {
+			indexOfLowestUnmergedLeavingDomain = self->particlesOutsideDomainIndices[lowestUnmergedLeavingDomain];
+
+			if ( indexOfLowestUnmergedLeavingDomain < candidateMergeParticle ) { 
+				candidateMergeParticle = indexOfLowestUnmergedLeavingDomain;
+				lowestUnmergedLeavingEntryToUpdatePtr = &lowestUnmergedLeavingDomain;
+			}	
+		}
+		
+		mergedLeavingParticleArray[currMergedLeavingParticleEntry++] = candidateMergeParticle;
+		(*lowestUnmergedLeavingEntryToUpdatePtr)++;
+
+		#if DEBUG
+		Journal_Firewall( lowestUnmergedLeavingViaShadow <= self->shadowParticlesLeavingMeTotalCount,
+			Swarm_Error, "Error: merging of unfilled particle lists stuffed up.\n" );
+		Journal_Firewall( lowestUnmergedLeavingDomain <= self->particlesOutsideDomainTotalCount,
+			Swarm_Error, "Error: merging of unfilled particle lists stuffed up.\n" );
+		#endif
+	}
+
+	#if DEBUG
+	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
+		Journal_DPrintf( self->debug, "Merged list of particles leaving proc:\n\t{" );
+		for ( currMergedLeavingParticleEntry=0; currMergedLeavingParticleEntry < slotsToFillTotalCount;
+			currMergedLeavingParticleEntry++ ) 
+		{
+			Journal_DPrintf( self->debug, "%d, ",
+				mergedLeavingParticleArray[currMergedLeavingParticleEntry] );
+		}
+		Journal_DPrintf( self->debug, "}\n" );
+	}
+	#endif
+	
+	Stream_UnIndent( self->debug );
+
+	return mergedLeavingParticleArray;
+}
+
+
+void ParticleMovementHandler_PrintParticleSlotsYetToFill( ParticleCommHandler* self ) {	
+	Index leavingParticleEntry;
+
+	Journal_DPrintf( self->debug, "%d slots yet to fill from particles leaving via shadow cells:\n",
+		self->shadowParticlesLeavingMeUnfilledCount );
+	leavingParticleEntry = self->currShadowParticleLeavingMeIndex;
+	Journal_DPrintf( self->debug, "\t{ " );
+	for ( ; leavingParticleEntry < self->shadowParticlesLeavingMeTotalCount; leavingParticleEntry++ ) {
+		Journal_DPrintf( self->debug, "%d, ", 
+			self->shadowParticlesLeavingMeIndices[leavingParticleEntry] );
+	}
+	Journal_DPrintf( self->debug, "}\n" );
+		
+	Journal_DPrintf( self->debug, "%d slots yet to fill from particles leaving domain directly:\n",
+		self->particlesOutsideDomainUnfilledCount );
+	leavingParticleEntry = self->currParticleLeavingMyDomainIndex;
+	Journal_DPrintf( self->debug, "\t{ " );
+	for ( ; leavingParticleEntry < self->particlesOutsideDomainTotalCount; leavingParticleEntry++ ) {
+		Journal_DPrintf( self->debug, "%d, ", 
+			self->particlesOutsideDomainIndices[leavingParticleEntry] );
+	}
+	Journal_DPrintf( self->debug, "}\n" );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleShadowSync.c
--- a/Swarm/src/ParticleShadowSync.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,600 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ParticleShadowSync.c 4001 2007-02-09 01:26:29Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ShadowInfo.h"
-#include "ParticleCommHandler.h"
-#include "ParticleShadowSync.h"
-
-#include "SwarmClass.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-const Type ParticleShadowSync_Type = "ParticleShadowSync";
-
-/* MPI tags */
-static const int SHADOW_PARTICLE_COUNTS_PER_CELL = 10;
-static const int SHADOW_PARTICLES = 20;
-
-void* ParticleShadowSync_DefaultNew( Name name )
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(ParticleShadowSync);
-	Type                                                      type = ParticleShadowSync_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ParticleShadowSync_Delete;
-	Stg_Class_PrintFunction*                                _print = _ParticleShadowSync_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ParticleShadowSync_CopyFunc;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleShadowSync_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ParticleShadowSync_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ParticleShadowSync_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ParticleShadowSync_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ParticleShadowSync_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ParticleShadowSync_Destroy;
-	Bool                                                  initFlag = False;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
-	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
-	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
-	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
-	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
-	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
-	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
-	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
-	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
-
-	return _ParticleShadowSync_New(  PARTICLESHADOWSYNC_PASSARGS  );
-}
-
-
-ParticleShadowSync* ParticleShadowSync_New( 
-		Name name,
-		void* swarm
-		)
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(ParticleShadowSync);
-	Type                                                      type = ParticleShadowSync_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ParticleShadowSync_Delete;
-	Stg_Class_PrintFunction*                                _print = _ParticleShadowSync_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ParticleShadowSync_CopyFunc;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleShadowSync_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ParticleShadowSync_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ParticleShadowSync_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ParticleShadowSync_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ParticleShadowSync_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ParticleShadowSync_Destroy;
-	Bool                                                  initFlag = True;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
-	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
-	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
-	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
-	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
-	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
-	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
-	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
-	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
-	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
-	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
-	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
-
-		return _ParticleShadowSync_New(  PARTICLESHADOWSYNC_PASSARGS  );
-}
-
-
-ParticleShadowSync* _ParticleShadowSync_New(  PARTICLESHADOWSYNC_DEFARGS  )
-{
-	ParticleShadowSync* self;
-	
-	/* Allocate memory */
-	
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	_allocateOutgoingCountArrays                      = _ParticleCommHandler_AllocateOutgoingCountArrays;
-	_allocateOutgoingParticleArrays                   = NULL;
-	_freeOutgoingArrays                               = _ParticleCommHandler_FreeOutgoingArrays;
-	_allocateIncomingCountArrays                      = _ParticleCommHandler_AllocateIncomingCountArrays;
-	_allocateIncomingParticleArrays                   = NULL;
-	_freeIncomingArrays                               = _ParticleCommHandler_FreeIncomingArrays;
-	_beginReceiveOfIncomingParticleCounts             = _ParticleCommHandler_BeginReceiveOfIncomingParticleCounts;
-	_finishReceiveOfIncomingParticleCounts            = _ParticleShadowSync_FinishReceiveOfIncomingParticleCounts;
-	_beginReceiveOfIncomingParticles                  = _ParticleShadowSync_BeginReceiveOfIncomingParticles;
-	_finishReceiveOfIncomingParticlesAndUpdateIndices = _ParticleShadowSync_FinishReceiveOfIncomingParticles;
-	_sendOutgoingParticleCounts                       = _ParticleShadowSync_SendParticleTotalsInShadowCellsToNbrs;
-	_beginSendingParticles                            = _ParticleShadowSync_SendShadowParticles;
-	_confirmOutgoingSendsCompleted                    = _ParticleCommHandler_ConfirmOutgoingSendsCompleted;
-	_commFunction                                     = ParticleShadowSync_HandleParticleMovementBetweenProcs;
-	_sizeOfSelf                                       = sizeof(ParticleShadowSync);
-	type                                              = ParticleShadowSync_Type;
-	_delete                                           = _ParticleShadowSync_Delete;
-	_print                                            = _ParticleShadowSync_Print;
-	_copy                                             = _ParticleShadowSync_CopyFunc;
-	_defaultConstructor                               = (Stg_Component_DefaultConstructorFunction*)ParticleShadowSync_DefaultNew;
-	_construct                                        = _ParticleShadowSync_AssignFromXML;
-	_build                                            = _ParticleShadowSync_Build;
-	_initialise                                       = _ParticleShadowSync_Initialise;
-	_execute                                          = _ParticleShadowSync_Execute;
-	_destroy                                          = _ParticleShadowSync_Destroy;
-
-	self = (ParticleShadowSync*)_ParticleCommHandler_New(  PARTICLECOMMHANDLER_PASSARGS  );
-	
-	/* General info */
-	/* Virtual info */
-	
-	/* ParticleShadowSync info */
-	if( initFlag ){
-		_ParticleShadowSync_Init( self );
-	}
-	
-	return self;
-}
-
-
-void _ParticleShadowSync_Init(
-		ParticleShadowSync*     self )
-{
-	_ParticleCommHandler_Init( (ParticleCommHandler*)self );
-	self->particlesOutsideDomainIndices = NULL;
-	_ParticleCommHandler_ZeroShadowCommStrategyCounters( (ParticleCommHandler*)self );
-}
-
-
-void _ParticleShadowSync_Delete(void* pCommsHandler ) {
-
-	_ParticleCommHandler_Delete( pCommsHandler );
-}
-
-
-void _ParticleShadowSync_Print( void* pCommsHandler, Stream* stream ) {
-	ParticleShadowSync*	self = (ParticleShadowSync*)pCommsHandler;
-	
-	/* General info */
-	Journal_Printf( stream, "ParticleShadowSync (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_ParticleCommHandler_Print( self, stream );
-
-	/* Virtual info */
-}
-
-
-void* _ParticleShadowSync_CopyFunc( const void* particleMovementHandler, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	
-	return _ParticleCommHandler_Copy( particleMovementHandler, dest, deep,
-		   nameExt, ptrMap );
-}
-
-void _ParticleShadowSync_AssignFromXML( void* pCommsHandler, Stg_ComponentFactory* cf, void* data ){
-	ParticleShadowSync *self = (ParticleShadowSync*)pCommsHandler;
-
-	self->isConstructed = True;
-	_ParticleShadowSync_Init( self );
-}
-	
-void _ParticleShadowSync_Build( void* pCommsHandler, void *data ){
-}
-	
-void _ParticleShadowSync_Initialise( void* pCommsHandler, void *data ){
-	
-}
-	
-void _ParticleShadowSync_Execute( void* pCommsHandler, void *data ){
-	ParticleCommHandler*	self = (ParticleCommHandler*)pCommsHandler;
-	Swarm					*swarm = (Swarm*)data;
-	
-	self->swarm = swarm;
-	assert( self->swarm );
-
-	if( swarm->shadowTablesBuilt == False ){
-		_Swarm_BuildShadowParticles( self->swarm );
-	}
-
-	self->_commFunction( self );	
-}
-
-void _ParticleShadowSync_Destroy( void* pCommsHandler, void *data ){
-	
-}
-
-void _ParticleShadowSync_SendParticleTotalsInShadowCellsToNbrs( ParticleCommHandler* self )
-{	
-	Processor_Index			proc_I;
-	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		nbr_I, nbrCount;
-	Cell_Index              lCellID, cellParticleCount, shadowedCell_I;	
-
-	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-
-	self->shadowParticlesLeavingMeTotalCount = 0;
-
-	nbrCount = procNbrInfo->procNbrCnt;
-	for( nbr_I = 0 ; nbr_I < nbrCount ; nbr_I++ ) {
-		proc_I = procNbrInfo->procNbrTbl[nbr_I];
-		
-		self->shadowParticlesLeavingMeTotalCounts[nbr_I] = 0;
-		for( shadowedCell_I = 0 ; shadowedCell_I < cellShadowInfo->procShadowedCnt[ nbr_I ]; shadowedCell_I++ ) {
-			lCellID = cellShadowInfo->procShadowedTbl[nbr_I][shadowedCell_I];
-			cellParticleCount = self->swarm->cellParticleCountTbl[ lCellID ];
-			self->shadowParticlesLeavingMeCountsPerCell[nbr_I][shadowedCell_I] = cellParticleCount;
-
-			self->shadowParticlesLeavingMeTotalCounts[nbr_I] += cellParticleCount;
-		}
-		MPI_Ssend( self->shadowParticlesLeavingMeCountsPerCell[nbr_I], cellShadowInfo->procShadowCnt[nbr_I], MPI_UNSIGNED,
-			proc_I, SHADOW_PARTICLE_COUNTS_PER_CELL, self->swarm->comm );
-	}
-
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-void _ParticleShadowSync_FinishReceiveOfIncomingParticleCounts( ParticleCommHandler* self ) {
-	MPI_Status			status;
-	Processor_Index			proc_I;
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		        nbr_I;
-	unsigned i = 0;
-
-	self->swarm->shadowParticleCount = 0;
-	/* TODO: may be worth converting the below into an MPI_Test loop */
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		proc_I = procNbrInfo->procNbrTbl[nbr_I];
-		
-		MPI_Wait( self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I], &status );
-
-		self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] = 0;
-		for( i=0; i<cellShadowInfo->procShadowCnt[nbr_I]; i++ ){
-			Index shadowCell = 0;
-
-			shadowCell = cellShadowInfo->procShadowTbl[nbr_I][i];
-			self->swarm->shadowCellParticleCountTbl[shadowCell-self->swarm->cellLocalCount] = 0;
-
-			self->swarm->shadowCellParticleTbl[shadowCell] = Memory_Realloc_Array( self->swarm->shadowCellParticleTbl[shadowCell], Particle_Index,
-																	(self->particlesArrivingFromNbrShadowCellCounts[nbr_I][i]) );
-
-			self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] += self->particlesArrivingFromNbrShadowCellCounts[nbr_I][i];
-		}
-	
-		self->swarm->shadowParticleCount+= self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
-	}
-}
-
-void _ParticleShadowSync_BeginReceiveOfIncomingParticles( ParticleCommHandler* pCommHandler ) {
-	ParticleShadowSync		*self = (ParticleShadowSync*)pCommHandler;
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	long                           incomingViaShadowArrayBytes = 0;
-	Neighbour_Index		        nbr_I;
-	Processor_Index			proc_I;
-	unsigned i = 0;
-	char* recvLocation  = NULL;
-
-	self->particlesArrivingFromNbrShadowCellsHandles = Memory_Alloc_Array_Unnamed( MPI_Request*, procNbrInfo->procNbrCnt );
-	for( i=0; i<procNbrInfo->procNbrCnt; i++ ){
-		self->particlesArrivingFromNbrShadowCellsHandles[i] = Memory_Alloc_Array_Unnamed( MPI_Request, 1 );
-	}
-
-	self->swarm->shadowParticles = (Particle*)Memory_Realloc( self->swarm->shadowParticles,
-			self->swarm->particleExtensionMgr->finalSize*(self->swarm->shadowParticleCount) );
-	
-	recvLocation = (char*)self->swarm->shadowParticles;
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		
-		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] != 0 ) {
-			proc_I = procNbrInfo->procNbrTbl[nbr_I];
-
-			/* start non-blocking recv of particles */
-			incomingViaShadowArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
-				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
-			
-			/*printf( "receiving %ld bytes\n", incomingViaShadowArrayBytes );*/
-			MPI_Irecv( recvLocation, incomingViaShadowArrayBytes, MPI_BYTE,
-				proc_I, SHADOW_PARTICLES, self->swarm->comm,
-				self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] );
-			
-			recvLocation += incomingViaShadowArrayBytes;
-		}
-	}
-}
-
-void _ParticleShadowSync_FinishReceiveOfIncomingParticles( ParticleCommHandler* pCommHandler ) {
-	ParticleShadowSync *self = (ParticleShadowSync*)pCommHandler;
-	MPI_Status			status;
-	Processor_Index			proc_I;
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Neighbour_Index		        nbr_I;
-	unsigned i = 0, j = 0;
-	int shadowParticleCounter;
-	int shadowCell = 0;
-
-	shadowParticleCounter = 0;
-	/* TODO: may be worth converting the below into an MPI_Test loop */
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		proc_I = procNbrInfo->procNbrTbl[nbr_I];
-		
-		if( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0 ){
-			MPI_Wait( self->particlesArrivingFromNbrShadowCellsHandles[nbr_I], &status );
-		}
-	}
-
-	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-		for( i=0; i<cellShadowInfo->procShadowCnt[nbr_I]; i++ ){
-			
-			shadowCell = cellShadowInfo->procShadowTbl[nbr_I][i];
-			for( j=0; j<self->particlesArrivingFromNbrShadowCellCounts[nbr_I][i]; j++ ){
-
-				Swarm_AddShadowParticleToShadowCell( self->swarm, shadowCell, shadowParticleCounter );
-				shadowParticleCounter++;
-			}
-		}
-	}
-}
-
-void _ParticleShadowSync_SendShadowParticles( ParticleCommHandler *self )
-{
-	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
-	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
-	Processor_Index			proc_I;
-	unsigned i = 0, j = 0, k = 0, cell = 0;
-	unsigned int	arrayIndex = 0;
-	long			arraySize = 0;
-	unsigned int	pIndex = 0;
-
-	self->shadowParticlesLeavingMeHandles = Memory_Alloc_Array_Unnamed( MPI_Request*, procNbrInfo->procNbrCnt );
-	self->shadowParticlesLeavingMe = Memory_Alloc_Array_Unnamed( Particle*, procNbrInfo->procNbrCnt );
-
-	for( i=0; i<procNbrInfo->procNbrCnt; i++ ){
-		proc_I = procNbrInfo->procNbrTbl[i];
-
-		if( self->shadowParticlesLeavingMeTotalCounts[i] != 0 ){
-
-			self->shadowParticlesLeavingMeHandles[i] = Memory_Alloc_Array_Unnamed( MPI_Request, 1 );
-
-			arraySize =  self->swarm->particleExtensionMgr->finalSize * self->shadowParticlesLeavingMeTotalCounts[i];
-			self->shadowParticlesLeavingMe[i] = (Particle*)Memory_Alloc_Bytes( arraySize, "Particle", "pCommHandler->outgoingPArray" );
-			memset( self->shadowParticlesLeavingMe[i], 0, arraySize );
-
-			arrayIndex = 0;
-			for( j=0; j<cellShadowInfo->procShadowedCnt[i]; j++ ){
-				cell = cellShadowInfo->procShadowedTbl[i][j];
-
-				for( k=0; k<self->swarm->cellParticleCountTbl[cell]; k++ ){
-					pIndex = self->swarm->cellParticleTbl[cell][k];
-				
-					Swarm_CopyParticleOffSwarm( self->swarm,
-							self->shadowParticlesLeavingMe[i], arrayIndex++,
-							pIndex );
-				}
-			}
-			
-			/*printf( "sending %ld bytes\n", self->shadowParticlesLeavingMeTotalCounts[i] * self->swarm->particleExtensionMgr->finalSize );*/
-			MPI_Issend( self->shadowParticlesLeavingMe[i],
-			self->shadowParticlesLeavingMeTotalCounts[i] * self->swarm->particleExtensionMgr->finalSize,
-			MPI_BYTE, proc_I, SHADOW_PARTICLES, self->swarm->comm,
-			self->shadowParticlesLeavingMeHandles[i] );
-		}
-	}
-}
-
-void ParticleShadowSync_HandleParticleMovementBetweenProcs( ParticleCommHandler* pCommsHandler ) {
-	ParticleShadowSync*	self = (ParticleShadowSync*)pCommsHandler;
-
-	Journal_DPrintfL( self->debug, 1, "In %s(), for swarm \"%s\":\n", __func__, self->swarm->name );
-	if ( 1 == self->swarm->nProc ) {
-		Journal_DPrintfL( self->debug, 1, "Serial run -> nothing to communicate in %s, returning.\n", __func__ );
-		Stream_UnIndentBranch( Swarm_Debug );
-		return;
-	}
-
-	Stream_IndentBranch( Swarm_Debug );
-	
-	if ( self->swarm->cellShadowCount > 0 ) {
-		/* Allocate the recv count arrays and handles */
-		
-		/*---_ParticleCommHandler_AllocateIncomingCountArrays( (ParticleCommHandler*)self );
-		_ParticleCommHandler_AllocateOutgoingCountArrays( (ParticleCommHandler*)self );*/
-		self->allocateIncomingCountArrays( (ParticleCommHandler*)self );
-		self->allocateOutgoingCountArrays( (ParticleCommHandler*)self );
-
-
-
-		/* First thing to do is begin non-blocking receive of incoming particles (for latency hiding) */
-		/*---_ParticleCommHandler_BeginReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );*/
-		self->beginReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
-
-
-		/* Do a blocking send of outgoing counts, so our nbrs know what to receive */
-		//_ParticleCommHandler_SendParticleTotalsInShadowCellsToNbrs( (ParticleCommHandler*)self );
-	
-		/*---_ParticleShadowSync_SendParticleTotalsInShadowCellsToNbrs( (ParticleCommHandler*)self );*/
-		self->sendOutgoingParticleCounts( (ParticleCommHandler*)self );
-
-		
-		/* Now need to make sure that incoming particle counts are here, then begin receiving particles
-		   (We do this as early as possible for latency hiding purposes */
-		
-		/*---_ParticleShadowSync_FinishReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );*/
-		self->finishReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
-
-
-		/*---_ParticleShadowSync_BeginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
-		_ParticleShadowSync_SendShadowParticles( (ParticleCommHandler*)self );*/
-		self->beginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
-		self->beginSendingParticles( (ParticleCommHandler*)self );
-
-
-		/*---_ParticleCommHandler_ConfirmOutgoingSendsCompleted( (ParticleCommHandler*)self );
-		_ParticleShadowSync_FinishReceiveOfIncomingParticles( self );*/
-		self->confirmOutgoingSendsCompleted( (ParticleCommHandler*)self );
-		self->finishReceiveOfIncomingParticlesAndUpdateIndices( (ParticleCommHandler*)self );
-
-
-		/*---_ParticleCommHandler_FreeOutgoingArrays( (ParticleCommHandler*)self );
-		_ParticleCommHandler_FreeIncomingArrays( (ParticleCommHandler*)self );*/
-		self->freeIncomingArrays( (ParticleCommHandler*)self );
-		self->freeOutgoingArrays( (ParticleCommHandler*)self );
-
-
-		/* This is where our own Data structure comes into play  Jules and Raq*/
-		//----_ParticleCommHandler_AllocateIncomingParticlesArrays( (ParticleCommHandler*)self );
-		//----_ParticleCommHandler_BeginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
-			
-		/* OK, now begin sending out particles we know need to go to nbrs */
-		//----_ParticleCommHandler_AllocateOutgoingParticlesArrays( (ParticleCommHandler*)self );
-		//----_ParticleCommHandler_BeginSendingParticlesInShadowCellsToNbrs( (ParticleCommHandler*)self );
-	}
-	
-	MPI_Barrier( self->swarm->comm );
-
-	_ParticleCommHandler_ZeroShadowCommStrategyCounters( (ParticleCommHandler*)self );
-	
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-void ParticleShadowSync_FindParticlesThatHaveMovedOutsideMyDomain( ParticleShadowSync* self )
-{
-	Particle_Index		particlesOutsideDomainSize = 0;
-	GlobalParticle*         currParticle = NULL;
-	Particle_Index		lParticle_I = 0;
-
-	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
-	Stream_IndentBranch( Swarm_Debug );
-
-	self->particlesOutsideDomainTotalCount = 0;
-	particlesOutsideDomainSize = self->swarm->particlesArrayDelta;
-
-
-	Journal_DPrintfL( self->debug, 1, "Checking the owning cell of each of my swarm's %d particles:\n",
-		self->swarm->particleLocalCount );
-	Stream_IndentBranch( Swarm_Debug );
-
-	for ( lParticle_I=0; lParticle_I < self->swarm->particleLocalCount; lParticle_I++ ) {
-
-		currParticle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
-		if ( currParticle->owningCell == self->swarm->cellDomainCount ) {
-			Journal_DPrintfL( self->debug, 3, "particle %d has moved outside domain to (%.2f,%.2f,%.2f): "
-				"saving index\n", lParticle_I, currParticle->coord[0], currParticle->coord[1],
-								currParticle->coord[2] );
-			if ( self->particlesOutsideDomainTotalCount == particlesOutsideDomainSize ) { 
-				particlesOutsideDomainSize += self->swarm->particlesArrayDelta;
-				Journal_DPrintfL( self->debug, 3, "(Need more memory to save indexes: increasing from %d to %d.)\n",
-					self->particlesOutsideDomainTotalCount, particlesOutsideDomainSize );
-				self->particlesOutsideDomainIndices = Memory_Realloc_Array( self->particlesOutsideDomainIndices,
-					Particle_Index, particlesOutsideDomainSize );
-			}
-			self->particlesOutsideDomainIndices[self->particlesOutsideDomainTotalCount++] = lParticle_I;
-		}	
-
-	}	
-	Stream_UnIndentBranch( Swarm_Debug );
-
-	self->particlesOutsideDomainUnfilledCount = self->particlesOutsideDomainTotalCount;
-
-	#if DEBUG
-	{
-		Particle_Index		particle_I = 0;
-		if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
-			Journal_DPrintf( self->debug, "%d Particles have moved outside my domain:\n\t[",
-				self->particlesOutsideDomainTotalCount );
-			for ( ; particle_I < self->particlesOutsideDomainTotalCount; particle_I++ ) {
-				Journal_DPrintf( self->debug, "%d, ", self->particlesOutsideDomainIndices[particle_I] );
-			}
-			Journal_DPrintf( self->debug, "]\n" );
-		}
-	}
-	#endif
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-void ParticleShadowSync_GetCountOfParticlesOutsideDomainPerProcessor(
-	ParticleShadowSync*	self,
-	Particle_Index**	globalParticlesOutsideDomainCountsPtr,
-	Particle_Index*		maxGlobalParticlesOutsideDomainCountPtr,
-	Particle_Index*		globalParticlesOutsideDomainTotalPtr )
-{
-	Processor_Index		proc_I;
-
-	(*globalParticlesOutsideDomainCountsPtr) = Memory_Alloc_Array( Particle_Index, self->swarm->nProc,
-		"(*globalParticlesOutsideDomainCountsPtr)" );
-		
-	MPI_Allgather( (&self->particlesOutsideDomainTotalCount), 1, MPI_UNSIGNED, 
-		(*globalParticlesOutsideDomainCountsPtr), 1, MPI_UNSIGNED, self->swarm->comm );
-	
-	(*globalParticlesOutsideDomainTotalPtr) = 0;
-	for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
-		(*globalParticlesOutsideDomainTotalPtr) += (*globalParticlesOutsideDomainCountsPtr)[proc_I];
-		if ( (*globalParticlesOutsideDomainCountsPtr)[proc_I] > (*maxGlobalParticlesOutsideDomainCountPtr) ) {
-			(*maxGlobalParticlesOutsideDomainCountPtr) = (*globalParticlesOutsideDomainCountsPtr)[proc_I];
-		}
-	}	
-
-	#if DEBUG
-	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
-		Journal_DPrintf( self->debug, "Global counts of particles moving outside domains:\n" );
-		Journal_DPrintf( self->debug, "\tTotal: %d, Counts: [", (*globalParticlesOutsideDomainTotalPtr) );
-		for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
-			Journal_DPrintf( self->debug, "%d, ", (*globalParticlesOutsideDomainCountsPtr)[proc_I] );
-		}	
-		Journal_DPrintf( self->debug, "]\n" );
-	}	
-	#endif
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/ParticleShadowSync.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/ParticleShadowSync.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,600 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ParticleShadowSync.c 4001 2007-02-09 01:26:29Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ShadowInfo.h"
+#include "ParticleCommHandler.h"
+#include "ParticleShadowSync.h"
+
+#include "SwarmClass.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+const Type ParticleShadowSync_Type = "ParticleShadowSync";
+
+/* MPI tags */
+static const int SHADOW_PARTICLE_COUNTS_PER_CELL = 10;
+static const int SHADOW_PARTICLES = 20;
+
+void* ParticleShadowSync_DefaultNew( Name name )
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(ParticleShadowSync);
+	Type                                                      type = ParticleShadowSync_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ParticleShadowSync_Delete;
+	Stg_Class_PrintFunction*                                _print = _ParticleShadowSync_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ParticleShadowSync_CopyFunc;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleShadowSync_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ParticleShadowSync_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ParticleShadowSync_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ParticleShadowSync_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ParticleShadowSync_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ParticleShadowSync_Destroy;
+	Bool                                                  initFlag = False;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
+	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
+	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
+	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
+	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
+	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
+	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
+	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
+	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
+
+	return _ParticleShadowSync_New(  PARTICLESHADOWSYNC_PASSARGS  );
+}
+
+
+ParticleShadowSync* ParticleShadowSync_New( 
+		Name name,
+		void* swarm
+		)
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(ParticleShadowSync);
+	Type                                                      type = ParticleShadowSync_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ParticleShadowSync_Delete;
+	Stg_Class_PrintFunction*                                _print = _ParticleShadowSync_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ParticleShadowSync_CopyFunc;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)ParticleShadowSync_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ParticleShadowSync_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ParticleShadowSync_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ParticleShadowSync_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ParticleShadowSync_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ParticleShadowSync_Destroy;
+	Bool                                                  initFlag = True;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType                                                                                        nameAllocationType = (AllocationType)ZERO;
+	ParticleCommHandler_AllocateOutgoingCountArrays*                                            _allocateOutgoingCountArrays = ZERO;
+	ParticleCommHandler_AllocateOutgoingParticleArrays*                                      _allocateOutgoingParticleArrays = ZERO;
+	ParticleCommHandler_FreeOutgoingArrays*                                                              _freeOutgoingArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingCountArrays*                                            _allocateIncomingCountArrays = ZERO;
+	ParticleCommHandler_AllocateIncomingParticleArrays*                                      _allocateIncomingParticleArrays = ZERO;
+	ParticleCommHandler_FreeIncomingArrays*                                                              _freeIncomingArrays = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticleCounts*                          _beginReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticleCounts*                        _finishReceiveOfIncomingParticleCounts = ZERO;
+	ParticleCommHandler_BeginReceiveOfIncomingParticles*                                    _beginReceiveOfIncomingParticles = ZERO;
+	ParticleCommHandler_FinishReceiveOfIncomingParticlesAndUpdateIndices*  _finishReceiveOfIncomingParticlesAndUpdateIndices = ZERO;
+	ParticleCommHandler_SendOutgoingParticleCounts*                                              _sendOutgoingParticleCounts = ZERO;
+	ParticleCommHandler_BeginSendingParticles*                                                        _beginSendingParticles = ZERO;
+	ParticleCommHandler_ConfirmOutgoingSendsCompleted*                                        _confirmOutgoingSendsCompleted = ZERO;
+	ParticleCommHandler_CommFunction*                                                                          _commFunction = ZERO;
+
+		return _ParticleShadowSync_New(  PARTICLESHADOWSYNC_PASSARGS  );
+}
+
+
+ParticleShadowSync* _ParticleShadowSync_New(  PARTICLESHADOWSYNC_DEFARGS  )
+{
+	ParticleShadowSync* self;
+	
+	/* Allocate memory */
+	
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	_allocateOutgoingCountArrays                      = _ParticleCommHandler_AllocateOutgoingCountArrays;
+	_allocateOutgoingParticleArrays                   = NULL;
+	_freeOutgoingArrays                               = _ParticleCommHandler_FreeOutgoingArrays;
+	_allocateIncomingCountArrays                      = _ParticleCommHandler_AllocateIncomingCountArrays;
+	_allocateIncomingParticleArrays                   = NULL;
+	_freeIncomingArrays                               = _ParticleCommHandler_FreeIncomingArrays;
+	_beginReceiveOfIncomingParticleCounts             = _ParticleCommHandler_BeginReceiveOfIncomingParticleCounts;
+	_finishReceiveOfIncomingParticleCounts            = _ParticleShadowSync_FinishReceiveOfIncomingParticleCounts;
+	_beginReceiveOfIncomingParticles                  = _ParticleShadowSync_BeginReceiveOfIncomingParticles;
+	_finishReceiveOfIncomingParticlesAndUpdateIndices = _ParticleShadowSync_FinishReceiveOfIncomingParticles;
+	_sendOutgoingParticleCounts                       = _ParticleShadowSync_SendParticleTotalsInShadowCellsToNbrs;
+	_beginSendingParticles                            = _ParticleShadowSync_SendShadowParticles;
+	_confirmOutgoingSendsCompleted                    = _ParticleCommHandler_ConfirmOutgoingSendsCompleted;
+	_commFunction                                     = ParticleShadowSync_HandleParticleMovementBetweenProcs;
+	_sizeOfSelf                                       = sizeof(ParticleShadowSync);
+	type                                              = ParticleShadowSync_Type;
+	_delete                                           = _ParticleShadowSync_Delete;
+	_print                                            = _ParticleShadowSync_Print;
+	_copy                                             = _ParticleShadowSync_CopyFunc;
+	_defaultConstructor                               = (Stg_Component_DefaultConstructorFunction*)ParticleShadowSync_DefaultNew;
+	_construct                                        = _ParticleShadowSync_AssignFromXML;
+	_build                                            = _ParticleShadowSync_Build;
+	_initialise                                       = _ParticleShadowSync_Initialise;
+	_execute                                          = _ParticleShadowSync_Execute;
+	_destroy                                          = _ParticleShadowSync_Destroy;
+
+	self = (ParticleShadowSync*)_ParticleCommHandler_New(  PARTICLECOMMHANDLER_PASSARGS  );
+	
+	/* General info */
+	/* Virtual info */
+	
+	/* ParticleShadowSync info */
+	if( initFlag ){
+		_ParticleShadowSync_Init( self );
+	}
+	
+	return self;
+}
+
+
+void _ParticleShadowSync_Init(
+		ParticleShadowSync*     self )
+{
+	_ParticleCommHandler_Init( (ParticleCommHandler*)self );
+	self->particlesOutsideDomainIndices = NULL;
+	_ParticleCommHandler_ZeroShadowCommStrategyCounters( (ParticleCommHandler*)self );
+}
+
+
+void _ParticleShadowSync_Delete(void* pCommsHandler ) {
+
+	_ParticleCommHandler_Delete( pCommsHandler );
+}
+
+
+void _ParticleShadowSync_Print( void* pCommsHandler, Stream* stream ) {
+	ParticleShadowSync*	self = (ParticleShadowSync*)pCommsHandler;
+	
+	/* General info */
+	Journal_Printf( stream, "ParticleShadowSync (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_ParticleCommHandler_Print( self, stream );
+
+	/* Virtual info */
+}
+
+
+void* _ParticleShadowSync_CopyFunc( const void* particleMovementHandler, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	
+	return _ParticleCommHandler_Copy( particleMovementHandler, dest, deep,
+		   nameExt, ptrMap );
+}
+
+void _ParticleShadowSync_AssignFromXML( void* pCommsHandler, Stg_ComponentFactory* cf, void* data ){
+	ParticleShadowSync *self = (ParticleShadowSync*)pCommsHandler;
+
+	self->isConstructed = True;
+	_ParticleShadowSync_Init( self );
+}
+	
+void _ParticleShadowSync_Build( void* pCommsHandler, void *data ){
+}
+	
+void _ParticleShadowSync_Initialise( void* pCommsHandler, void *data ){
+	
+}
+	
+void _ParticleShadowSync_Execute( void* pCommsHandler, void *data ){
+	ParticleCommHandler*	self = (ParticleCommHandler*)pCommsHandler;
+	Swarm					*swarm = (Swarm*)data;
+	
+	self->swarm = swarm;
+	assert( self->swarm );
+
+	if( swarm->shadowTablesBuilt == False ){
+		_Swarm_BuildShadowParticles( self->swarm );
+	}
+
+	self->_commFunction( self );	
+}
+
+void _ParticleShadowSync_Destroy( void* pCommsHandler, void *data ){
+	
+}
+
+void _ParticleShadowSync_SendParticleTotalsInShadowCellsToNbrs( ParticleCommHandler* self )
+{	
+	Processor_Index			proc_I;
+	ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*			procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		nbr_I, nbrCount;
+	Cell_Index              lCellID, cellParticleCount, shadowedCell_I;	
+
+	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+
+	self->shadowParticlesLeavingMeTotalCount = 0;
+
+	nbrCount = procNbrInfo->procNbrCnt;
+	for( nbr_I = 0 ; nbr_I < nbrCount ; nbr_I++ ) {
+		proc_I = procNbrInfo->procNbrTbl[nbr_I];
+		
+		self->shadowParticlesLeavingMeTotalCounts[nbr_I] = 0;
+		for( shadowedCell_I = 0 ; shadowedCell_I < cellShadowInfo->procShadowedCnt[ nbr_I ]; shadowedCell_I++ ) {
+			lCellID = cellShadowInfo->procShadowedTbl[nbr_I][shadowedCell_I];
+			cellParticleCount = self->swarm->cellParticleCountTbl[ lCellID ];
+			self->shadowParticlesLeavingMeCountsPerCell[nbr_I][shadowedCell_I] = cellParticleCount;
+
+			self->shadowParticlesLeavingMeTotalCounts[nbr_I] += cellParticleCount;
+		}
+		MPI_Ssend( self->shadowParticlesLeavingMeCountsPerCell[nbr_I], cellShadowInfo->procShadowCnt[nbr_I], MPI_UNSIGNED,
+			proc_I, SHADOW_PARTICLE_COUNTS_PER_CELL, self->swarm->comm );
+	}
+
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+void _ParticleShadowSync_FinishReceiveOfIncomingParticleCounts( ParticleCommHandler* self ) {
+	MPI_Status			status;
+	Processor_Index			proc_I;
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		        nbr_I;
+	unsigned i = 0;
+
+	self->swarm->shadowParticleCount = 0;
+	/* TODO: may be worth converting the below into an MPI_Test loop */
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		proc_I = procNbrInfo->procNbrTbl[nbr_I];
+		
+		MPI_Wait( self->particlesArrivingFromNbrShadowCellCountsHandles[nbr_I], &status );
+
+		self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] = 0;
+		for( i=0; i<cellShadowInfo->procShadowCnt[nbr_I]; i++ ){
+			Index shadowCell = 0;
+
+			shadowCell = cellShadowInfo->procShadowTbl[nbr_I][i];
+			self->swarm->shadowCellParticleCountTbl[shadowCell-self->swarm->cellLocalCount] = 0;
+
+			self->swarm->shadowCellParticleTbl[shadowCell] = Memory_Realloc_Array( self->swarm->shadowCellParticleTbl[shadowCell], Particle_Index,
+																	(self->particlesArrivingFromNbrShadowCellCounts[nbr_I][i]) );
+
+			self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] += self->particlesArrivingFromNbrShadowCellCounts[nbr_I][i];
+		}
+	
+		self->swarm->shadowParticleCount+= self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
+	}
+}
+
+void _ParticleShadowSync_BeginReceiveOfIncomingParticles( ParticleCommHandler* pCommHandler ) {
+	ParticleShadowSync		*self = (ParticleShadowSync*)pCommHandler;
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	long                           incomingViaShadowArrayBytes = 0;
+	Neighbour_Index		        nbr_I;
+	Processor_Index			proc_I;
+	unsigned i = 0;
+	char* recvLocation  = NULL;
+
+	self->particlesArrivingFromNbrShadowCellsHandles = Memory_Alloc_Array_Unnamed( MPI_Request*, procNbrInfo->procNbrCnt );
+	for( i=0; i<procNbrInfo->procNbrCnt; i++ ){
+		self->particlesArrivingFromNbrShadowCellsHandles[i] = Memory_Alloc_Array_Unnamed( MPI_Request, 1 );
+	}
+
+	self->swarm->shadowParticles = (Particle*)Memory_Realloc( self->swarm->shadowParticles,
+			self->swarm->particleExtensionMgr->finalSize*(self->swarm->shadowParticleCount) );
+	
+	recvLocation = (char*)self->swarm->shadowParticles;
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		
+		if ( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] != 0 ) {
+			proc_I = procNbrInfo->procNbrTbl[nbr_I];
+
+			/* start non-blocking recv of particles */
+			incomingViaShadowArrayBytes = self->swarm->particleExtensionMgr->finalSize * 
+				self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I];
+			
+			/*printf( "receiving %ld bytes\n", incomingViaShadowArrayBytes );*/
+			MPI_Irecv( recvLocation, incomingViaShadowArrayBytes, MPI_BYTE,
+				proc_I, SHADOW_PARTICLES, self->swarm->comm,
+				self->particlesArrivingFromNbrShadowCellsHandles[nbr_I] );
+			
+			recvLocation += incomingViaShadowArrayBytes;
+		}
+	}
+}
+
+void _ParticleShadowSync_FinishReceiveOfIncomingParticles( ParticleCommHandler* pCommHandler ) {
+	ParticleShadowSync *self = (ParticleShadowSync*)pCommHandler;
+	MPI_Status			status;
+	Processor_Index			proc_I;
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Neighbour_Index		        nbr_I;
+	unsigned i = 0, j = 0;
+	int shadowParticleCounter;
+	int shadowCell = 0;
+
+	shadowParticleCounter = 0;
+	/* TODO: may be worth converting the below into an MPI_Test loop */
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		proc_I = procNbrInfo->procNbrTbl[nbr_I];
+		
+		if( self->particlesArrivingFromNbrShadowCellsTotalCounts[nbr_I] > 0 ){
+			MPI_Wait( self->particlesArrivingFromNbrShadowCellsHandles[nbr_I], &status );
+		}
+	}
+
+	for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+		for( i=0; i<cellShadowInfo->procShadowCnt[nbr_I]; i++ ){
+			
+			shadowCell = cellShadowInfo->procShadowTbl[nbr_I][i];
+			for( j=0; j<self->particlesArrivingFromNbrShadowCellCounts[nbr_I][i]; j++ ){
+
+				Swarm_AddShadowParticleToShadowCell( self->swarm, shadowCell, shadowParticleCounter );
+				shadowParticleCounter++;
+			}
+		}
+	}
+}
+
+void _ParticleShadowSync_SendShadowParticles( ParticleCommHandler *self )
+{
+	ShadowInfo*		        cellShadowInfo = CellLayout_GetShadowInfo( self->swarm->cellLayout );
+	ProcNbrInfo*		        procNbrInfo = cellShadowInfo->procNbrInfo;
+	Processor_Index			proc_I;
+	unsigned i = 0, j = 0, k = 0, cell = 0;
+	unsigned int	arrayIndex = 0;
+	long			arraySize = 0;
+	unsigned int	pIndex = 0;
+
+	self->shadowParticlesLeavingMeHandles = Memory_Alloc_Array_Unnamed( MPI_Request*, procNbrInfo->procNbrCnt );
+	self->shadowParticlesLeavingMe = Memory_Alloc_Array_Unnamed( Particle*, procNbrInfo->procNbrCnt );
+
+	for( i=0; i<procNbrInfo->procNbrCnt; i++ ){
+		proc_I = procNbrInfo->procNbrTbl[i];
+
+		if( self->shadowParticlesLeavingMeTotalCounts[i] != 0 ){
+
+			self->shadowParticlesLeavingMeHandles[i] = Memory_Alloc_Array_Unnamed( MPI_Request, 1 );
+
+			arraySize =  self->swarm->particleExtensionMgr->finalSize * self->shadowParticlesLeavingMeTotalCounts[i];
+			self->shadowParticlesLeavingMe[i] = (Particle*)Memory_Alloc_Bytes( arraySize, "Particle", "pCommHandler->outgoingPArray" );
+			memset( self->shadowParticlesLeavingMe[i], 0, arraySize );
+
+			arrayIndex = 0;
+			for( j=0; j<cellShadowInfo->procShadowedCnt[i]; j++ ){
+				cell = cellShadowInfo->procShadowedTbl[i][j];
+
+				for( k=0; k<self->swarm->cellParticleCountTbl[cell]; k++ ){
+					pIndex = self->swarm->cellParticleTbl[cell][k];
+				
+					Swarm_CopyParticleOffSwarm( self->swarm,
+							self->shadowParticlesLeavingMe[i], arrayIndex++,
+							pIndex );
+				}
+			}
+			
+			/*printf( "sending %ld bytes\n", self->shadowParticlesLeavingMeTotalCounts[i] * self->swarm->particleExtensionMgr->finalSize );*/
+			MPI_Issend( self->shadowParticlesLeavingMe[i],
+			self->shadowParticlesLeavingMeTotalCounts[i] * self->swarm->particleExtensionMgr->finalSize,
+			MPI_BYTE, proc_I, SHADOW_PARTICLES, self->swarm->comm,
+			self->shadowParticlesLeavingMeHandles[i] );
+		}
+	}
+}
+
+void ParticleShadowSync_HandleParticleMovementBetweenProcs( ParticleCommHandler* pCommsHandler ) {
+	ParticleShadowSync*	self = (ParticleShadowSync*)pCommsHandler;
+
+	Journal_DPrintfL( self->debug, 1, "In %s(), for swarm \"%s\":\n", __func__, self->swarm->name );
+	if ( 1 == self->swarm->nProc ) {
+		Journal_DPrintfL( self->debug, 1, "Serial run -> nothing to communicate in %s, returning.\n", __func__ );
+		Stream_UnIndentBranch( Swarm_Debug );
+		return;
+	}
+
+	Stream_IndentBranch( Swarm_Debug );
+	
+	if ( self->swarm->cellShadowCount > 0 ) {
+		/* Allocate the recv count arrays and handles */
+		
+		/*---_ParticleCommHandler_AllocateIncomingCountArrays( (ParticleCommHandler*)self );
+		_ParticleCommHandler_AllocateOutgoingCountArrays( (ParticleCommHandler*)self );*/
+		self->allocateIncomingCountArrays( (ParticleCommHandler*)self );
+		self->allocateOutgoingCountArrays( (ParticleCommHandler*)self );
+
+
+
+		/* First thing to do is begin non-blocking receive of incoming particles (for latency hiding) */
+		/*---_ParticleCommHandler_BeginReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );*/
+		self->beginReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
+
+
+		/* Do a blocking send of outgoing counts, so our nbrs know what to receive */
+		//_ParticleCommHandler_SendParticleTotalsInShadowCellsToNbrs( (ParticleCommHandler*)self );
+	
+		/*---_ParticleShadowSync_SendParticleTotalsInShadowCellsToNbrs( (ParticleCommHandler*)self );*/
+		self->sendOutgoingParticleCounts( (ParticleCommHandler*)self );
+
+		
+		/* Now need to make sure that incoming particle counts are here, then begin receiving particles
+		   (We do this as early as possible for latency hiding purposes */
+		
+		/*---_ParticleShadowSync_FinishReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );*/
+		self->finishReceiveOfIncomingParticleCounts( (ParticleCommHandler*)self );
+
+
+		/*---_ParticleShadowSync_BeginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
+		_ParticleShadowSync_SendShadowParticles( (ParticleCommHandler*)self );*/
+		self->beginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
+		self->beginSendingParticles( (ParticleCommHandler*)self );
+
+
+		/*---_ParticleCommHandler_ConfirmOutgoingSendsCompleted( (ParticleCommHandler*)self );
+		_ParticleShadowSync_FinishReceiveOfIncomingParticles( self );*/
+		self->confirmOutgoingSendsCompleted( (ParticleCommHandler*)self );
+		self->finishReceiveOfIncomingParticlesAndUpdateIndices( (ParticleCommHandler*)self );
+
+
+		/*---_ParticleCommHandler_FreeOutgoingArrays( (ParticleCommHandler*)self );
+		_ParticleCommHandler_FreeIncomingArrays( (ParticleCommHandler*)self );*/
+		self->freeIncomingArrays( (ParticleCommHandler*)self );
+		self->freeOutgoingArrays( (ParticleCommHandler*)self );
+
+
+		/* This is where our own Data structure comes into play  Jules and Raq*/
+		//----_ParticleCommHandler_AllocateIncomingParticlesArrays( (ParticleCommHandler*)self );
+		//----_ParticleCommHandler_BeginReceiveOfIncomingParticles( (ParticleCommHandler*)self );
+			
+		/* OK, now begin sending out particles we know need to go to nbrs */
+		//----_ParticleCommHandler_AllocateOutgoingParticlesArrays( (ParticleCommHandler*)self );
+		//----_ParticleCommHandler_BeginSendingParticlesInShadowCellsToNbrs( (ParticleCommHandler*)self );
+	}
+	
+	MPI_Barrier( self->swarm->comm );
+
+	_ParticleCommHandler_ZeroShadowCommStrategyCounters( (ParticleCommHandler*)self );
+	
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+void ParticleShadowSync_FindParticlesThatHaveMovedOutsideMyDomain( ParticleShadowSync* self )
+{
+	Particle_Index		particlesOutsideDomainSize = 0;
+	GlobalParticle*         currParticle = NULL;
+	Particle_Index		lParticle_I = 0;
+
+	Journal_DPrintfL( self->debug, 1, "In %s():\n", __func__ );
+	Stream_IndentBranch( Swarm_Debug );
+
+	self->particlesOutsideDomainTotalCount = 0;
+	particlesOutsideDomainSize = self->swarm->particlesArrayDelta;
+
+
+	Journal_DPrintfL( self->debug, 1, "Checking the owning cell of each of my swarm's %d particles:\n",
+		self->swarm->particleLocalCount );
+	Stream_IndentBranch( Swarm_Debug );
+
+	for ( lParticle_I=0; lParticle_I < self->swarm->particleLocalCount; lParticle_I++ ) {
+
+		currParticle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
+		if ( currParticle->owningCell == self->swarm->cellDomainCount ) {
+			Journal_DPrintfL( self->debug, 3, "particle %d has moved outside domain to (%.2f,%.2f,%.2f): "
+				"saving index\n", lParticle_I, currParticle->coord[0], currParticle->coord[1],
+								currParticle->coord[2] );
+			if ( self->particlesOutsideDomainTotalCount == particlesOutsideDomainSize ) { 
+				particlesOutsideDomainSize += self->swarm->particlesArrayDelta;
+				Journal_DPrintfL( self->debug, 3, "(Need more memory to save indexes: increasing from %d to %d.)\n",
+					self->particlesOutsideDomainTotalCount, particlesOutsideDomainSize );
+				self->particlesOutsideDomainIndices = Memory_Realloc_Array( self->particlesOutsideDomainIndices,
+					Particle_Index, particlesOutsideDomainSize );
+			}
+			self->particlesOutsideDomainIndices[self->particlesOutsideDomainTotalCount++] = lParticle_I;
+		}	
+
+	}	
+	Stream_UnIndentBranch( Swarm_Debug );
+
+	self->particlesOutsideDomainUnfilledCount = self->particlesOutsideDomainTotalCount;
+
+	#if DEBUG
+	{
+		Particle_Index		particle_I = 0;
+		if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
+			Journal_DPrintf( self->debug, "%d Particles have moved outside my domain:\n\t[",
+				self->particlesOutsideDomainTotalCount );
+			for ( ; particle_I < self->particlesOutsideDomainTotalCount; particle_I++ ) {
+				Journal_DPrintf( self->debug, "%d, ", self->particlesOutsideDomainIndices[particle_I] );
+			}
+			Journal_DPrintf( self->debug, "]\n" );
+		}
+	}
+	#endif
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+void ParticleShadowSync_GetCountOfParticlesOutsideDomainPerProcessor(
+	ParticleShadowSync*	self,
+	Particle_Index**	globalParticlesOutsideDomainCountsPtr,
+	Particle_Index*		maxGlobalParticlesOutsideDomainCountPtr,
+	Particle_Index*		globalParticlesOutsideDomainTotalPtr )
+{
+	Processor_Index		proc_I;
+
+	(*globalParticlesOutsideDomainCountsPtr) = Memory_Alloc_Array( Particle_Index, self->swarm->nProc,
+		"(*globalParticlesOutsideDomainCountsPtr)" );
+		
+	MPI_Allgather( (&self->particlesOutsideDomainTotalCount), 1, MPI_UNSIGNED, 
+		(*globalParticlesOutsideDomainCountsPtr), 1, MPI_UNSIGNED, self->swarm->comm );
+	
+	(*globalParticlesOutsideDomainTotalPtr) = 0;
+	for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
+		(*globalParticlesOutsideDomainTotalPtr) += (*globalParticlesOutsideDomainCountsPtr)[proc_I];
+		if ( (*globalParticlesOutsideDomainCountsPtr)[proc_I] > (*maxGlobalParticlesOutsideDomainCountPtr) ) {
+			(*maxGlobalParticlesOutsideDomainCountPtr) = (*globalParticlesOutsideDomainCountsPtr)[proc_I];
+		}
+	}	
+
+	#if DEBUG
+	if ( Stream_IsPrintableLevel( self->debug, 2 ) ) {
+		Journal_DPrintf( self->debug, "Global counts of particles moving outside domains:\n" );
+		Journal_DPrintf( self->debug, "\tTotal: %d, Counts: [", (*globalParticlesOutsideDomainTotalPtr) );
+		for ( proc_I=0; proc_I < self->swarm->nProc; proc_I++ ) {
+			Journal_DPrintf( self->debug, "%d, ", (*globalParticlesOutsideDomainCountsPtr)[proc_I] );
+		}	
+		Journal_DPrintf( self->debug, "]\n" );
+	}	
+	#endif
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/PerCellParticleLayout.c
--- a/Swarm/src/PerCellParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,189 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: PerCellParticleLayout.c 3526 2006-04-13 03:59:17Z AlanLo $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "PerCellParticleLayout.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-
-const Type PerCellParticleLayout_Type = "PerCellParticleLayout";
-
-PerCellParticleLayout* _PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_DEFARGS  )
-{
-   PerCellParticleLayout*		self;
-
-   /* Allocate memory */
-   assert( _sizeOfSelf >= sizeof(PerCellParticleLayout) );
-   self = (PerCellParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
-
-   /* General info */
-
-   /* Virtual functions */
-   self->_initialCount = _initialCount;
-   self->_initialiseParticlesOfCell = _initialiseParticlesOfCell;
-
-   return self;
-}
-
-
-void _PerCellParticleLayout_Init( void* particleLayout )
-{
-	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
-	
-	self->isConstructed = True;
-}
-
-void _PerCellParticleLayout_Delete( void* particleLayout ) {
-	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
-	
-	_ParticleLayout_Delete( self );
-}
-
-void _PerCellParticleLayout_Print( void* particleLayout, Stream* stream ) {
-	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
-	
-	Journal_Printf( stream, "PerCellParticleLayout (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_ParticleLayout_Print( self, stream );
-	
-	/* Virtual info */
-	Journal_Printf( stream, "\t_initialCount (func ptr): %p\n", self->_initialCount );
-	Journal_Printf( stream, "\t_initialiseParticlesOfCell (func ptr): %p\n", self->_initialiseParticlesOfCell );
-	
-}
-
-void _PerCellParticleLayout_Destroy( void* particleLayout, void* data ) {}
-
-void _PerCellParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ) {
-	PerCellParticleLayout*		self = (PerCellParticleLayout*)particleLayout;
-
-   _ParticleLayout_AssignFromXML( self, cf, data );
-
-   _PerCellParticleLayout_Init( self );
-}
-
-void* _PerCellParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	PerCellParticleLayout*		self = (PerCellParticleLayout*)particleLayout;
-	PerCellParticleLayout*		newPerCellParticleLayout;
-	
-	newPerCellParticleLayout = (PerCellParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-
-	/* Virtual methods */
-	newPerCellParticleLayout->_initialCount = self->_initialCount;
-	newPerCellParticleLayout->_initialiseParticlesOfCell = self->_initialiseParticlesOfCell;
-	
-	return (void*)newPerCellParticleLayout;
-}
-
-
-/* Note: this function is required to also set the total particle count */
-void _PerCellParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
-{
-	PerCellParticleLayout*	self = (PerCellParticleLayout*)particleLayout;
-	Swarm*			swarm = (Swarm*)_swarm;
-	Cell_DomainIndex	cell_I = 0;
-	char			tempStr[100];
-
-	for( cell_I = 0; cell_I < swarm->cellLocalCount; cell_I++ ) {
-		swarm->cellParticleCountTbl[cell_I] = PerCellParticleLayout_InitialCount( self, swarm->cellLayout, cell_I );
-		
-		/* Initially, just set to the same sizes as initial particle counts */
-		swarm->cellParticleSizeTbl[cell_I] = swarm->cellParticleCountTbl[cell_I];
-		sprintf( tempStr, "Swarm->cellParticleTbl[%d]", cell_I );
-		swarm->cellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, swarm->cellParticleCountTbl[cell_I], tempStr );
-		swarm->particleLocalCount += swarm->cellParticleCountTbl[cell_I];
-	}
-
-	/* Now initialise the shadow cell particle counts */
-	for (; cell_I < swarm->cellDomainCount; cell_I++ ) {
-		swarm->cellParticleCountTbl[cell_I] = 0;
-		swarm->cellParticleSizeTbl[cell_I] = 0;
-		swarm->cellParticleTbl[cell_I] = NULL;
-	}
-}
-
-void _PerCellParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
-{
-	PerCellParticleLayout*	self = (PerCellParticleLayout*)particleLayout;
-	Swarm*			swarm = (Swarm*)_swarm;
-	Cell_Index		cell_I;
-	Particle_InCellIndex	cellParticle_I;
-	Particle_Index		currParticleIndex = 0;
-	StandardParticle*	particle = NULL;
-	
-	/* Go through and init particles, cell-by-cell */
-	/* Note: don't put particles in the shadow cells... */
-	for( cell_I = 0; cell_I < swarm->cellLocalCount; cell_I++ ) {
-		Particle_InCellIndex		count = swarm->cellParticleCountTbl[cell_I];
-		
-		for( cellParticle_I = 0; cellParticle_I < count; cellParticle_I++ ) {
-			swarm->cellParticleTbl[cell_I][cellParticle_I] = currParticleIndex++;
-			particle = Swarm_ParticleInCellAt( swarm, cell_I, cellParticle_I );
-			particle->owningCell = cell_I;
-		}	
-
-		PerCellParticleLayout_InitialiseParticlesOfCell( self, swarm, cell_I );
-	}
-}
-
-void PerCellParticleLayout_InitialiseParticlesOfCell( void* particleLayout, void* _swarm, Cell_Index cell_I )
-{
-	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
-	
-	self->_initialiseParticlesOfCell( self, _swarm, cell_I );
-}
-
-Particle_InCellIndex PerCellParticleLayout_InitialCount( void* particleLayout, void* _swarm, Cell_Index cell_I )
-{
-	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
-	
-	return self->_initialCount( self, _swarm, cell_I );
-}
-
-
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/PerCellParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/PerCellParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,189 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: PerCellParticleLayout.c 3526 2006-04-13 03:59:17Z AlanLo $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "PerCellParticleLayout.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+
+const Type PerCellParticleLayout_Type = "PerCellParticleLayout";
+
+PerCellParticleLayout* _PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_DEFARGS  )
+{
+   PerCellParticleLayout*		self;
+
+   /* Allocate memory */
+   assert( _sizeOfSelf >= sizeof(PerCellParticleLayout) );
+   self = (PerCellParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
+
+   /* General info */
+
+   /* Virtual functions */
+   self->_initialCount = _initialCount;
+   self->_initialiseParticlesOfCell = _initialiseParticlesOfCell;
+
+   return self;
+}
+
+
+void _PerCellParticleLayout_Init( void* particleLayout )
+{
+	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
+	
+	self->isConstructed = True;
+}
+
+void _PerCellParticleLayout_Delete( void* particleLayout ) {
+	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
+	
+	_ParticleLayout_Delete( self );
+}
+
+void _PerCellParticleLayout_Print( void* particleLayout, Stream* stream ) {
+	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
+	
+	Journal_Printf( stream, "PerCellParticleLayout (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_ParticleLayout_Print( self, stream );
+	
+	/* Virtual info */
+	Journal_Printf( stream, "\t_initialCount (func ptr): %p\n", self->_initialCount );
+	Journal_Printf( stream, "\t_initialiseParticlesOfCell (func ptr): %p\n", self->_initialiseParticlesOfCell );
+	
+}
+
+void _PerCellParticleLayout_Destroy( void* particleLayout, void* data ) {}
+
+void _PerCellParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ) {
+	PerCellParticleLayout*		self = (PerCellParticleLayout*)particleLayout;
+
+   _ParticleLayout_AssignFromXML( self, cf, data );
+
+   _PerCellParticleLayout_Init( self );
+}
+
+void* _PerCellParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	PerCellParticleLayout*		self = (PerCellParticleLayout*)particleLayout;
+	PerCellParticleLayout*		newPerCellParticleLayout;
+	
+	newPerCellParticleLayout = (PerCellParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+
+	/* Virtual methods */
+	newPerCellParticleLayout->_initialCount = self->_initialCount;
+	newPerCellParticleLayout->_initialiseParticlesOfCell = self->_initialiseParticlesOfCell;
+	
+	return (void*)newPerCellParticleLayout;
+}
+
+
+/* Note: this function is required to also set the total particle count */
+void _PerCellParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
+{
+	PerCellParticleLayout*	self = (PerCellParticleLayout*)particleLayout;
+	Swarm*			swarm = (Swarm*)_swarm;
+	Cell_DomainIndex	cell_I = 0;
+	char			tempStr[100];
+
+	for( cell_I = 0; cell_I < swarm->cellLocalCount; cell_I++ ) {
+		swarm->cellParticleCountTbl[cell_I] = PerCellParticleLayout_InitialCount( self, swarm->cellLayout, cell_I );
+		
+		/* Initially, just set to the same sizes as initial particle counts */
+		swarm->cellParticleSizeTbl[cell_I] = swarm->cellParticleCountTbl[cell_I];
+		sprintf( tempStr, "Swarm->cellParticleTbl[%d]", cell_I );
+		swarm->cellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, swarm->cellParticleCountTbl[cell_I], tempStr );
+		swarm->particleLocalCount += swarm->cellParticleCountTbl[cell_I];
+	}
+
+	/* Now initialise the shadow cell particle counts */
+	for (; cell_I < swarm->cellDomainCount; cell_I++ ) {
+		swarm->cellParticleCountTbl[cell_I] = 0;
+		swarm->cellParticleSizeTbl[cell_I] = 0;
+		swarm->cellParticleTbl[cell_I] = NULL;
+	}
+}
+
+void _PerCellParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
+{
+	PerCellParticleLayout*	self = (PerCellParticleLayout*)particleLayout;
+	Swarm*			swarm = (Swarm*)_swarm;
+	Cell_Index		cell_I;
+	Particle_InCellIndex	cellParticle_I;
+	Particle_Index		currParticleIndex = 0;
+	StandardParticle*	particle = NULL;
+	
+	/* Go through and init particles, cell-by-cell */
+	/* Note: don't put particles in the shadow cells... */
+	for( cell_I = 0; cell_I < swarm->cellLocalCount; cell_I++ ) {
+		Particle_InCellIndex		count = swarm->cellParticleCountTbl[cell_I];
+		
+		for( cellParticle_I = 0; cellParticle_I < count; cellParticle_I++ ) {
+			swarm->cellParticleTbl[cell_I][cellParticle_I] = currParticleIndex++;
+			particle = Swarm_ParticleInCellAt( swarm, cell_I, cellParticle_I );
+			particle->owningCell = cell_I;
+		}	
+
+		PerCellParticleLayout_InitialiseParticlesOfCell( self, swarm, cell_I );
+	}
+}
+
+void PerCellParticleLayout_InitialiseParticlesOfCell( void* particleLayout, void* _swarm, Cell_Index cell_I )
+{
+	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
+	
+	self->_initialiseParticlesOfCell( self, _swarm, cell_I );
+}
+
+Particle_InCellIndex PerCellParticleLayout_InitialCount( void* particleLayout, void* _swarm, Cell_Index cell_I )
+{
+	PerCellParticleLayout* self = (PerCellParticleLayout*)particleLayout;
+	
+	return self->_initialCount( self, _swarm, cell_I );
+}
+
+
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/PlaneParticleLayout.c
--- a/Swarm/src/PlaneParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,231 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: PlaneParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "SpaceFillerParticleLayout.h"
-#include "PlaneParticleLayout.h"
-#include "CellLayout.h"
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-const Type PlaneParticleLayout_Type = "PlaneParticleLayout";
-
-const Index PlaneParticleLayout_Invalid = (Index) 0;
-
-PlaneParticleLayout* PlaneParticleLayout_New( 
-      Name             name,
-      AbstractContext* context, 
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles, 
-      double           averageInitialParticlesPerCell,
-      Dimension_Index  dim,
-      Axis             planeAxis, 
-      double           planeCoord )
-{
-	PlaneParticleLayout* self = (PlaneParticleLayout*) _PlaneParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-	_SpaceFillerParticleLayout_Init( self, dim );
-	_PlaneParticleLayout_Init( self, planeAxis, planeCoord );
-	
-	return self;
-}
-
-PlaneParticleLayout* _PlaneParticleLayout_New(  PLANEPARTICLELAYOUT_DEFARGS  )
-{
-	PlaneParticleLayout* self;
-	
-	/* Allocate memory */
-	self = (PlaneParticleLayout*)_SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_PASSARGS  );  /* dim */
-
-   self->planeAxis = planeAxis;
-   self->planeCoord = planeCoord;
-	
-	return self;
-}
-
-void _PlaneParticleLayout_Init( 
-		void*           particleLayout, 
-		Axis            planeAxis, 
-		double          planeCoord )
-{
-	PlaneParticleLayout* self = (PlaneParticleLayout*) particleLayout;
-
-	self->planeAxis  = planeAxis;
-	self->planeCoord = planeCoord;
-}
-
-
-void* _PlaneParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(PlaneParticleLayout);
-	Type                                                                        type = PlaneParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _PlaneParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _PlaneParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _PlaneParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _PlaneParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _PlaneParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _PlaneParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _PlaneParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _PlaneParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _PlaneParticleLayout_Destroy;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _SpaceFillerParticleLayout_InitialiseParticles;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _PlaneParticleLayout_InitialiseParticle;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	Dimension_Index                                                              dim = 0;
-	Axis                                                                   planeAxis = (Axis)0;
-	double                                                                planeCoord = 0;
-
-   return (void*)_PlaneParticleLayout_New(  PLANEPARTICLELAYOUT_PASSARGS  );
-}
-
-	
-void _PlaneParticleLayout_Destroy( void* particleLayout, void* data ){
-   PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
-   _SpaceFillerParticleLayout_Destroy( self, data );
-}
-
-void _PlaneParticleLayout_Delete( void* particleLayout ) {
-	PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
-
-	/* Stg_Class_Delete parent class */
-	_SpaceFillerParticleLayout_Delete( self );
-
-}
-
-void _PlaneParticleLayout_Print( void* particleLayout, Stream* stream ) {
-	PlaneParticleLayout* self  = (PlaneParticleLayout*)particleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "PlaneParticleLayout (ptr): %p:\n", self );
-	Stream_Indent( stream );
-	
-	/* Parent class info */
-	_SpaceFillerParticleLayout_Print( self, stream );
-	
-	/* PlaneParticleLayout */
-	Journal_PrintValue( stream, self->planeAxis );
-	Journal_PrintValue( stream, self->planeCoord );
-	
-	Stream_UnIndent( stream );
-}
-
-
-void* _PlaneParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	PlaneParticleLayout*		self                    = (PlaneParticleLayout*)particleLayout;
-	PlaneParticleLayout*		newPlaneParticleLayout;
-	
-	newPlaneParticleLayout = (PlaneParticleLayout*)_SpaceFillerParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newPlaneParticleLayout->planeAxis  = self->planeAxis;
-	newPlaneParticleLayout->planeCoord = self->planeCoord;
-
-	return (void*)newPlaneParticleLayout;
-}
-
-
-void _PlaneParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ){
-	PlaneParticleLayout* self = (PlaneParticleLayout*) particleLayout;
-	Axis   planeAxis;
-	double planeCoord;
-	char*  planeAxisString;
-	
-	_SpaceFillerParticleLayout_AssignFromXML( self, cf, data );
-
-	planeAxisString = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"planeAxis", ""  );
-	planeCoord = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"planeCoord", 0.0 );
-
-	/* Check to make sure that some value is given for plane axis */
-	Journal_Firewall( strlen( planeAxisString  ) > 0, Journal_MyStream( Error_Type, self ),
-		"Error for %s '%s': No axis given in param 'planeAxis'.\n", self->type, self->name );
-
-	/* Make axis case insensitive */
-	planeAxisString[0] = toupper(planeAxisString[0]);
-	Journal_Firewall( planeAxisString[0] >= 'X' && planeAxisString[0] <= 'Z', Journal_MyStream( Error_Type, self ),
-		"Error for %s '%s': Incorrect axis '%c' given for param 'planeAxis'.\n", self->type, self->name,planeAxisString[0]);
-
-	planeAxis = (Axis)(planeAxisString[0] - 'X');
-
-	_PlaneParticleLayout_Init( self, planeAxis, planeCoord );
-	
-}
-	
-void _PlaneParticleLayout_Build( void* particleLayout, void* data ){
-   PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
-   _SpaceFillerParticleLayout_Build( self, data );
-}
-	
-void _PlaneParticleLayout_Initialise( void* particleLayout, void* data ){
-   PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
-   _SpaceFillerParticleLayout_Initialise( self, data );
-}
-	
-void _PlaneParticleLayout_Execute( void* particleLayout, void* data ){
-	
-}
-
-void _PlaneParticleLayout_InitialiseParticle( 
-		void* spaceFillerParticleLayout, 
-		void* _swarm, 
-		Particle_Index newParticle_I,
-		void* _particle )
-{
-	PlaneParticleLayout*        self     = (PlaneParticleLayout*)spaceFillerParticleLayout;
-	Swarm*                      swarm    = (Swarm*)_swarm;
-	GlobalParticle*             particle = (GlobalParticle*)_particle;
-
-	_SpaceFillerParticleLayout_InitialiseParticle( self, swarm, newParticle_I, particle );
-	particle->coord[ self->planeAxis ] = self->planeCoord;
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/PlaneParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/PlaneParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,231 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: PlaneParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "SpaceFillerParticleLayout.h"
+#include "PlaneParticleLayout.h"
+#include "CellLayout.h"
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+const Type PlaneParticleLayout_Type = "PlaneParticleLayout";
+
+const Index PlaneParticleLayout_Invalid = (Index) 0;
+
+PlaneParticleLayout* PlaneParticleLayout_New( 
+      Name             name,
+      AbstractContext* context, 
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles, 
+      double           averageInitialParticlesPerCell,
+      Dimension_Index  dim,
+      Axis             planeAxis, 
+      double           planeCoord )
+{
+	PlaneParticleLayout* self = (PlaneParticleLayout*) _PlaneParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+	_SpaceFillerParticleLayout_Init( self, dim );
+	_PlaneParticleLayout_Init( self, planeAxis, planeCoord );
+	
+	return self;
+}
+
+PlaneParticleLayout* _PlaneParticleLayout_New(  PLANEPARTICLELAYOUT_DEFARGS  )
+{
+	PlaneParticleLayout* self;
+	
+	/* Allocate memory */
+	self = (PlaneParticleLayout*)_SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_PASSARGS  );  /* dim */
+
+   self->planeAxis = planeAxis;
+   self->planeCoord = planeCoord;
+	
+	return self;
+}
+
+void _PlaneParticleLayout_Init( 
+		void*           particleLayout, 
+		Axis            planeAxis, 
+		double          planeCoord )
+{
+	PlaneParticleLayout* self = (PlaneParticleLayout*) particleLayout;
+
+	self->planeAxis  = planeAxis;
+	self->planeCoord = planeCoord;
+}
+
+
+void* _PlaneParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(PlaneParticleLayout);
+	Type                                                                        type = PlaneParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _PlaneParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _PlaneParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _PlaneParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _PlaneParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _PlaneParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _PlaneParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _PlaneParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _PlaneParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _PlaneParticleLayout_Destroy;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _SpaceFillerParticleLayout_InitialiseParticles;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _PlaneParticleLayout_InitialiseParticle;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	Dimension_Index                                                              dim = 0;
+	Axis                                                                   planeAxis = (Axis)0;
+	double                                                                planeCoord = 0;
+
+   return (void*)_PlaneParticleLayout_New(  PLANEPARTICLELAYOUT_PASSARGS  );
+}
+
+	
+void _PlaneParticleLayout_Destroy( void* particleLayout, void* data ){
+   PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
+   _SpaceFillerParticleLayout_Destroy( self, data );
+}
+
+void _PlaneParticleLayout_Delete( void* particleLayout ) {
+	PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
+
+	/* Stg_Class_Delete parent class */
+	_SpaceFillerParticleLayout_Delete( self );
+
+}
+
+void _PlaneParticleLayout_Print( void* particleLayout, Stream* stream ) {
+	PlaneParticleLayout* self  = (PlaneParticleLayout*)particleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "PlaneParticleLayout (ptr): %p:\n", self );
+	Stream_Indent( stream );
+	
+	/* Parent class info */
+	_SpaceFillerParticleLayout_Print( self, stream );
+	
+	/* PlaneParticleLayout */
+	Journal_PrintValue( stream, self->planeAxis );
+	Journal_PrintValue( stream, self->planeCoord );
+	
+	Stream_UnIndent( stream );
+}
+
+
+void* _PlaneParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	PlaneParticleLayout*		self                    = (PlaneParticleLayout*)particleLayout;
+	PlaneParticleLayout*		newPlaneParticleLayout;
+	
+	newPlaneParticleLayout = (PlaneParticleLayout*)_SpaceFillerParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newPlaneParticleLayout->planeAxis  = self->planeAxis;
+	newPlaneParticleLayout->planeCoord = self->planeCoord;
+
+	return (void*)newPlaneParticleLayout;
+}
+
+
+void _PlaneParticleLayout_AssignFromXML( void* particleLayout, Stg_ComponentFactory *cf, void* data ){
+	PlaneParticleLayout* self = (PlaneParticleLayout*) particleLayout;
+	Axis   planeAxis;
+	double planeCoord;
+	char*  planeAxisString;
+	
+	_SpaceFillerParticleLayout_AssignFromXML( self, cf, data );
+
+	planeAxisString = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"planeAxis", ""  );
+	planeCoord = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"planeCoord", 0.0 );
+
+	/* Check to make sure that some value is given for plane axis */
+	Journal_Firewall( strlen( planeAxisString  ) > 0, Journal_MyStream( Error_Type, self ),
+		"Error for %s '%s': No axis given in param 'planeAxis'.\n", self->type, self->name );
+
+	/* Make axis case insensitive */
+	planeAxisString[0] = toupper(planeAxisString[0]);
+	Journal_Firewall( planeAxisString[0] >= 'X' && planeAxisString[0] <= 'Z', Journal_MyStream( Error_Type, self ),
+		"Error for %s '%s': Incorrect axis '%c' given for param 'planeAxis'.\n", self->type, self->name,planeAxisString[0]);
+
+	planeAxis = (Axis)(planeAxisString[0] - 'X');
+
+	_PlaneParticleLayout_Init( self, planeAxis, planeCoord );
+	
+}
+	
+void _PlaneParticleLayout_Build( void* particleLayout, void* data ){
+   PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
+   _SpaceFillerParticleLayout_Build( self, data );
+}
+	
+void _PlaneParticleLayout_Initialise( void* particleLayout, void* data ){
+   PlaneParticleLayout* self = (PlaneParticleLayout*)particleLayout;
+   _SpaceFillerParticleLayout_Initialise( self, data );
+}
+	
+void _PlaneParticleLayout_Execute( void* particleLayout, void* data ){
+	
+}
+
+void _PlaneParticleLayout_InitialiseParticle( 
+		void* spaceFillerParticleLayout, 
+		void* _swarm, 
+		Particle_Index newParticle_I,
+		void* _particle )
+{
+	PlaneParticleLayout*        self     = (PlaneParticleLayout*)spaceFillerParticleLayout;
+	Swarm*                      swarm    = (Swarm*)_swarm;
+	GlobalParticle*             particle = (GlobalParticle*)_particle;
+
+	_SpaceFillerParticleLayout_InitialiseParticle( self, swarm, newParticle_I, particle );
+	particle->coord[ self->planeAxis ] = self->planeCoord;
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Random.c
--- a/Swarm/src/Random.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Random.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Random.h"
-
-#include <assert.h>
-
-/* Park and Miller "minimul standard" constants */
-const long int Swarm_Random_RandMax = 2147483647;	/* Swarm_Random_RandMax = (2^31)-1, taken from max int */
-static const long int a = 16807;			/* a = 7^5, taken from algorithm */
-static const unsigned long int mask = 123459876;	/* taken from algorithm */
-
-/* Schrage's algorithm constants */
-static const long int q = 127773;			/* q = [Swarm_Random_RandMax / a] */
-static const long int r = 2836;				/* r = m mod a */
-
-/* Park and Miller "minimul standard" variables */
-static long Swarm_Random_maskedSeed;
-
-
-void Swarm_Random_Seed( long seed ) {
-	assert( mask - seed != 0 );
-	Swarm_Random_maskedSeed = seed ^ mask;
-}
-
-
-double Swarm_Random_Random() {
-	const long int tmp = Swarm_Random_maskedSeed / q;
-	Swarm_Random_maskedSeed = a * (Swarm_Random_maskedSeed - tmp * q) - r * tmp;
-	if( Swarm_Random_maskedSeed < 0 ) {
-		Swarm_Random_maskedSeed += Swarm_Random_RandMax;
-	}
-	return Swarm_Random_maskedSeed;
-}
-
-double Swarm_Random_Random_WithMinMax( double min, double max ) {
-	return ( max - min ) * Swarm_Random_Random() / (double)Swarm_Random_RandMax + min;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Random.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/Random.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,76 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Random.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Random.h"
+
+#include <assert.h>
+
+/* Park and Miller "minimul standard" constants */
+const long int Swarm_Random_RandMax = 2147483647;	/* Swarm_Random_RandMax = (2^31)-1, taken from max int */
+static const long int a = 16807;			/* a = 7^5, taken from algorithm */
+static const unsigned long int mask = 123459876;	/* taken from algorithm */
+
+/* Schrage's algorithm constants */
+static const long int q = 127773;			/* q = [Swarm_Random_RandMax / a] */
+static const long int r = 2836;				/* r = m mod a */
+
+/* Park and Miller "minimul standard" variables */
+static long Swarm_Random_maskedSeed;
+
+
+void Swarm_Random_Seed( long seed ) {
+	assert( mask - seed != 0 );
+	Swarm_Random_maskedSeed = seed ^ mask;
+}
+
+
+double Swarm_Random_Random() {
+	const long int tmp = Swarm_Random_maskedSeed / q;
+	Swarm_Random_maskedSeed = a * (Swarm_Random_maskedSeed - tmp * q) - r * tmp;
+	if( Swarm_Random_maskedSeed < 0 ) {
+		Swarm_Random_maskedSeed += Swarm_Random_RandMax;
+	}
+	return Swarm_Random_maskedSeed;
+}
+
+double Swarm_Random_Random_WithMinMax( double min, double max ) {
+	return ( max - min ) * Swarm_Random_Random() / (double)Swarm_Random_RandMax + min;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/RandomParticleLayout.c
--- a/Swarm/src/RandomParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,219 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: RandomParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "PerCellParticleLayout.h"
-#include "RandomParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "Random.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-const Type RandomParticleLayout_Type = "RandomParticleLayout";
-
-
-RandomParticleLayout* RandomParticleLayout_New( 
-   Name name, 
-   AbstractContext* context,
-   CoordSystem      coordSystem,
-   Bool             weightsInitialisedAtStartup,
-   Particle_InCellIndex cellParticleCount, 
-   unsigned int         seed ) 
-{
-	RandomParticleLayout* self = (RandomParticleLayout*) _RandomParticleLayout_DefaultNew( name );
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _PerCellParticleLayout_Init( self );
-	_RandomParticleLayout_Init( self, cellParticleCount, seed );
-
-	return self;
-}
-
-RandomParticleLayout* _RandomParticleLayout_New(  RANDOMPARTICLELAYOUT_DEFARGS  )
-{
-	RandomParticleLayout* self;
-	
-   /* hard-wire these */
-   coordSystem = GlobalCoordSystem;
-   weightsInitialisedAtStartup = False;
-   nameAllocationType = NON_GLOBAL;
-
-	/* Allocate memory */
-	self = (RandomParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
-
-	return self;
-}
-
-void _RandomParticleLayout_Init( void* randomParticleLayout, Particle_InCellIndex cellParticleCount, unsigned int seed ) {
-	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
-
-	self->isConstructed     = True;
-	self->cellParticleCount = cellParticleCount;
-	self->seed              = seed;
-	
-	Swarm_Random_Seed( self->seed );
-}
-
-
-void _RandomParticleLayout_Delete( void* randomParticleLayout ) {
-	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
-	
-	/* Stg_Class_Delete parent class */
-	_PerCellParticleLayout_Delete( self );
-}
-
-void _RandomParticleLayout_Print( void* randomParticleLayout, Stream* stream ) {
-	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
-	
-	/* Set the Journal for printing informations */
-	Stream* randomParticleLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( randomParticleLayoutStream, "RandomParticleLayout (ptr): %p:\n", self );
-	
-	/* Parent class info */
-	_PerCellParticleLayout_Print( self, stream );
-	
-	/* RandomParticleLayout */
-	Journal_Printf( randomParticleLayoutStream, "\tcellParticleCount: %u\n", self->cellParticleCount );
-	Journal_Printf( randomParticleLayoutStream, "\tseed: %u\n", self->seed );
-}
-
-
-void* _RandomParticleLayout_Copy( const void* randomParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	RandomParticleLayout*		self = (RandomParticleLayout*)randomParticleLayout;
-	RandomParticleLayout*		newRandomParticleLayout;
-	
-	newRandomParticleLayout = (RandomParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newRandomParticleLayout->cellParticleCount = self->cellParticleCount;
-	newRandomParticleLayout->seed = self->seed;
-	
-	return (void*)newRandomParticleLayout;
-}
-
-
-void* _RandomParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                     _sizeOfSelf = sizeof(RandomParticleLayout);
-	Type                                                                             type = RandomParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                     _delete = _RandomParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                       _print = _RandomParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                         _copy = _RandomParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _RandomParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                           _construct = _RandomParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                                   _build = _RandomParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                         _initialise = _RandomParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                               _execute = _RandomParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                               _destroy = _RandomParticleLayout_Destroy;
-	AllocationType                                                     nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
-	CoordSystem                                                               coordSystem = GlobalCoordSystem;
-	Bool                                                      weightsInitialisedAtStartup = False;
-	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _RandomParticleLayout_InitialCount;
-	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _RandomParticleLayout_InitialiseParticlesOfCell;
-
-	return (void*)_RandomParticleLayout_New(  RANDOMPARTICLELAYOUT_PASSARGS  );
-}
-
-void _RandomParticleLayout_AssignFromXML( void* randomParticleLayout, Stg_ComponentFactory* cf, void* data ) {
-	RandomParticleLayout*       self = (RandomParticleLayout*)randomParticleLayout;
-	Particle_InCellIndex        cellParticleCount;
-	unsigned int                seed;
-
-   _PerCellParticleLayout_AssignFromXML( self, cf, data );
-
-	cellParticleCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"cellParticleCount", 0  );
-	seed = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"seed", 13  );
-	
-	_RandomParticleLayout_Init( self, cellParticleCount, seed );
-}
-	
-void _RandomParticleLayout_Build( void* randomParticleLayout, void* data ) {
-	
-}
-	
-void _RandomParticleLayout_Initialise( void* randomParticleLayout, void* data ) {
-	
-}
-	
-void _RandomParticleLayout_Execute( void* randomParticleLayout, void* data ) {
-	
-}
-	
-void _RandomParticleLayout_Destroy( void* randomParticleLayout, void* data ) {
-   RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
-
-   _PerCellParticleLayout_Destroy( self, data );
-}
-
-
-Particle_InCellIndex _RandomParticleLayout_InitialCount( void* randomParticleLayout, void* celllayout, Cell_Index cell_I ) {
-	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
-	return self->cellParticleCount;
-}
-
-void _RandomParticleLayout_InitialiseParticlesOfCell( void* randomParticleLayout, void* _swarm, Cell_Index cell_I ) {
-	Swarm*              	swarm = (Swarm*)_swarm;
-	Coord               	min;
-	Coord               	max;
-	Dimension_Index     	dim_I;
-	Particle_InCellIndex	particlesThisCell = swarm->cellParticleCountTbl[cell_I];
-	Particle_InCellIndex	cParticle_I = 0;
-	GlobalParticle*	        particle = NULL;
-	
-	Swarm_GetCellMinMaxCoords( swarm, cell_I, min, max );
-
-	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {	
-		
-		particle = (GlobalParticle*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		particle->owningCell = cell_I;
-		
-		for ( dim_I = 0 ; dim_I < 3 ; dim_I++ ) {
-			particle->coord[ dim_I ] = Swarm_Random_Random_WithMinMax( min[ dim_I ], max[ dim_I ] );
-		}
-	}
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/RandomParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/RandomParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,219 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: RandomParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "PerCellParticleLayout.h"
+#include "RandomParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "Random.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+const Type RandomParticleLayout_Type = "RandomParticleLayout";
+
+
+RandomParticleLayout* RandomParticleLayout_New( 
+   Name name, 
+   AbstractContext* context,
+   CoordSystem      coordSystem,
+   Bool             weightsInitialisedAtStartup,
+   Particle_InCellIndex cellParticleCount, 
+   unsigned int         seed ) 
+{
+	RandomParticleLayout* self = (RandomParticleLayout*) _RandomParticleLayout_DefaultNew( name );
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _PerCellParticleLayout_Init( self );
+	_RandomParticleLayout_Init( self, cellParticleCount, seed );
+
+	return self;
+}
+
+RandomParticleLayout* _RandomParticleLayout_New(  RANDOMPARTICLELAYOUT_DEFARGS  )
+{
+	RandomParticleLayout* self;
+	
+   /* hard-wire these */
+   coordSystem = GlobalCoordSystem;
+   weightsInitialisedAtStartup = False;
+   nameAllocationType = NON_GLOBAL;
+
+	/* Allocate memory */
+	self = (RandomParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
+
+	return self;
+}
+
+void _RandomParticleLayout_Init( void* randomParticleLayout, Particle_InCellIndex cellParticleCount, unsigned int seed ) {
+	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
+
+	self->isConstructed     = True;
+	self->cellParticleCount = cellParticleCount;
+	self->seed              = seed;
+	
+	Swarm_Random_Seed( self->seed );
+}
+
+
+void _RandomParticleLayout_Delete( void* randomParticleLayout ) {
+	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
+	
+	/* Stg_Class_Delete parent class */
+	_PerCellParticleLayout_Delete( self );
+}
+
+void _RandomParticleLayout_Print( void* randomParticleLayout, Stream* stream ) {
+	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
+	
+	/* Set the Journal for printing informations */
+	Stream* randomParticleLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( randomParticleLayoutStream, "RandomParticleLayout (ptr): %p:\n", self );
+	
+	/* Parent class info */
+	_PerCellParticleLayout_Print( self, stream );
+	
+	/* RandomParticleLayout */
+	Journal_Printf( randomParticleLayoutStream, "\tcellParticleCount: %u\n", self->cellParticleCount );
+	Journal_Printf( randomParticleLayoutStream, "\tseed: %u\n", self->seed );
+}
+
+
+void* _RandomParticleLayout_Copy( const void* randomParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	RandomParticleLayout*		self = (RandomParticleLayout*)randomParticleLayout;
+	RandomParticleLayout*		newRandomParticleLayout;
+	
+	newRandomParticleLayout = (RandomParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newRandomParticleLayout->cellParticleCount = self->cellParticleCount;
+	newRandomParticleLayout->seed = self->seed;
+	
+	return (void*)newRandomParticleLayout;
+}
+
+
+void* _RandomParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                     _sizeOfSelf = sizeof(RandomParticleLayout);
+	Type                                                                             type = RandomParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                     _delete = _RandomParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                       _print = _RandomParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                         _copy = _RandomParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _RandomParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                           _construct = _RandomParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                                   _build = _RandomParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                         _initialise = _RandomParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                               _execute = _RandomParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                               _destroy = _RandomParticleLayout_Destroy;
+	AllocationType                                                     nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
+	CoordSystem                                                               coordSystem = GlobalCoordSystem;
+	Bool                                                      weightsInitialisedAtStartup = False;
+	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _RandomParticleLayout_InitialCount;
+	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _RandomParticleLayout_InitialiseParticlesOfCell;
+
+	return (void*)_RandomParticleLayout_New(  RANDOMPARTICLELAYOUT_PASSARGS  );
+}
+
+void _RandomParticleLayout_AssignFromXML( void* randomParticleLayout, Stg_ComponentFactory* cf, void* data ) {
+	RandomParticleLayout*       self = (RandomParticleLayout*)randomParticleLayout;
+	Particle_InCellIndex        cellParticleCount;
+	unsigned int                seed;
+
+   _PerCellParticleLayout_AssignFromXML( self, cf, data );
+
+	cellParticleCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"cellParticleCount", 0  );
+	seed = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"seed", 13  );
+	
+	_RandomParticleLayout_Init( self, cellParticleCount, seed );
+}
+	
+void _RandomParticleLayout_Build( void* randomParticleLayout, void* data ) {
+	
+}
+	
+void _RandomParticleLayout_Initialise( void* randomParticleLayout, void* data ) {
+	
+}
+	
+void _RandomParticleLayout_Execute( void* randomParticleLayout, void* data ) {
+	
+}
+	
+void _RandomParticleLayout_Destroy( void* randomParticleLayout, void* data ) {
+   RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
+
+   _PerCellParticleLayout_Destroy( self, data );
+}
+
+
+Particle_InCellIndex _RandomParticleLayout_InitialCount( void* randomParticleLayout, void* celllayout, Cell_Index cell_I ) {
+	RandomParticleLayout* self = (RandomParticleLayout*)randomParticleLayout;
+	return self->cellParticleCount;
+}
+
+void _RandomParticleLayout_InitialiseParticlesOfCell( void* randomParticleLayout, void* _swarm, Cell_Index cell_I ) {
+	Swarm*              	swarm = (Swarm*)_swarm;
+	Coord               	min;
+	Coord               	max;
+	Dimension_Index     	dim_I;
+	Particle_InCellIndex	particlesThisCell = swarm->cellParticleCountTbl[cell_I];
+	Particle_InCellIndex	cParticle_I = 0;
+	GlobalParticle*	        particle = NULL;
+	
+	Swarm_GetCellMinMaxCoords( swarm, cell_I, min, max );
+
+	for ( cParticle_I = 0; cParticle_I < particlesThisCell; cParticle_I++ ) {	
+		
+		particle = (GlobalParticle*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		particle->owningCell = cell_I;
+		
+		for ( dim_I = 0 ; dim_I < 3 ; dim_I++ ) {
+			particle->coord[ dim_I ] = Swarm_Random_Random_WithMinMax( min[ dim_I ], max[ dim_I ] );
+		}
+	}
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SingleCellLayout.c
--- a/Swarm/src/SingleCellLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,388 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SingleCellLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "CellLayout.h"
-#include "SingleCellLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-const Type SingleCellLayout_Type = "SingleCellLayout";
-
-
-SingleCellLayout* SingleCellLayout_New( Name name, AbstractContext* context, const Bool dimExists[3], const XYZ min, const XYZ max ) { 
-	SingleCellLayout* self = (SingleCellLayout*) _SingleCellLayout_DefaultNew( name );
-
-	self->isConstructed = True;
-	_CellLayout_Init( (CellLayout*)self, context );
-	_SingleCellLayout_Init( self, dimExists, min, max );
-
-	return self;
-}
-
-void* _SingleCellLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                _sizeOfSelf = sizeof(SingleCellLayout);
-	Type                                                        type = SingleCellLayout_Type;
-	Stg_Class_DeleteFunction*                                _delete = _SingleCellLayout_Delete;
-	Stg_Class_PrintFunction*                                  _print = _SingleCellLayout_Print;
-	Stg_Class_CopyFunction*                                    _copy = _SingleCellLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = _SingleCellLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                      _construct = _SingleCellLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                              _build = _SingleCellLayout_Build;
-	Stg_Component_InitialiseFunction*                    _initialise = _SingleCellLayout_Initialise;
-	Stg_Component_ExecuteFunction*                          _execute = _SingleCellLayout_Execute;
-	Stg_Component_DestroyFunction*                          _destroy = _SingleCellLayout_Destroy;
-	AllocationType                                nameAllocationType = NON_GLOBAL;
-	CellLayout_CellCountFunction*                    _cellLocalCount = _SingleCellLayout_CellLocalCount;
-	CellLayout_CellCountFunction*                   _cellShadowCount = _SingleCellLayout_CellShadowCount;
-	CellLayout_PointCountFunction*                       _pointCount = _SingleCellLayout_PointCount;
-	CellLayout_InitialisePointsFunction*           _initialisePoints = _SingleCellLayout_InitialisePoints;
-	CellLayout_MapElementIdToCellIdFunction*   _mapElementIdToCellId = _SingleCellLayout_MapElementIdToCellId;
-	CellLayout_IsInCellFunction*                           _isInCell = _SingleCellLayout_IsInCell;
-	CellLayout_CellOfFunction*                               _cellOf = _SingleCellLayout_CellOf;
-	CellLayout_GetShadowInfoFunction*                 _getShadowInfo = _SingleCellLayout_GetShadowInfo;
-
-	return (void*)_SingleCellLayout_New(  SINGLECELLLAYOUT_PASSARGS  );
-}
-
-SingleCellLayout* _SingleCellLayout_New(  SINGLECELLLAYOUT_DEFARGS  ) {
-	SingleCellLayout* self;
-	
-	/* Allocate memory */
-	self = (SingleCellLayout*)_CellLayout_New(  CELLLAYOUT_PASSARGS  );
-	
-	/* Virtual info */
-	
-	/* SingleCellLayout info */
-	
-	return self;
-}
-
-void _SingleCellLayout_Init( void* cellLayout, const Bool dimExists[3], const XYZ min, const XYZ max ) { 
-	SingleCellLayout* self        = (SingleCellLayout*) cellLayout;
-	Dimension_Index   dim_I;
-	XYZ               minDefaults = { -1.0, -1.0, -1.0 };
-	XYZ               maxDefaults = { 1.0, 1.0, 1.0 };
-	
-	/* General and Virtual info should already be set */
-
-	self->isConstructed = True;
-	for ( dim_I=0; dim_I < 3; dim_I++ ) {
-		self->dimExists[dim_I] = dimExists[dim_I];
-	}
-	
-	/* Get min and max values */
-	if ( min )
-		memcpy( self->min, min, sizeof( XYZ ));
-	else
-		memcpy( self->min, minDefaults, sizeof( XYZ ));
-	if ( max )
-		memcpy( self->max, max, sizeof( XYZ ));
-	else
-		memcpy( self->max, maxDefaults, sizeof( XYZ ));
-
-	for ( dim_I=0; dim_I < 3; dim_I++ ) {
-		if ( !dimExists[dim_I] ) {
-			self->min[dim_I] = 0.0;
-			self->max[dim_I] = 0.0;
-		}
-	}	
-
-	/* Since pointcount and cell points are the same for all cells, calculate them now */
-	_SingleCellLayout_CalculateGlobalPointCount( self );
-	_SingleCellLayout_InitialiseGlobalCellPointPositions( self );
-}
-
-
-void _SingleCellLayout_Delete( void* singleCellLayout ) {
-	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
-	
-	/* Stg_Class_Delete parent class */
-	_CellLayout_Delete( self );
-}
-
-void _SingleCellLayout_Print( void* singleCellLayout, Stream* stream ) {
-	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
-	Index i;
-	
-	/* Set the Journal for printing informations */
-	Stream* singleCellLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( singleCellLayoutStream, "SingleCellLayout (ptr): %p\n", self ); 
-	
-	/* Parent class info */
-	_CellLayout_Print( self, stream );
-	
-	/* Virtual info */
-	
-	/* SingleCellLayout info */
-	Journal_Printf( singleCellLayoutStream, "self->dimExists[" );
-	for (i=I_AXIS; i < 3; i++ ) {
-		Journal_Printf( singleCellLayoutStream, " %d,", self->dimExists[i] );
-	}
-	Journal_Printf( singleCellLayoutStream, "]\n" );
-	
-	Journal_Printf( singleCellLayoutStream, "self->min[" );
-	for (i=I_AXIS; i < 3; i++ ) {
-		Journal_Printf( singleCellLayoutStream, " %f,", self->min[i] );
-	}	
-	Journal_Printf( singleCellLayoutStream, "]\n" );
-	
-	Journal_Printf( singleCellLayoutStream, "self->max[" );
-	for (i=I_AXIS; i < 3; i++ ) {
-		Journal_Printf( singleCellLayoutStream, " %f,", self->max[i] );
-	}	
-	Journal_Printf( singleCellLayoutStream, "]\n" );
-}
-
-
-void* _SingleCellLayout_Copy( const void* singleCellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SingleCellLayout*	self = (SingleCellLayout*)singleCellLayout;
-	SingleCellLayout*	newSingleCellLayout;
-	PtrMap*			map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newSingleCellLayout = (SingleCellLayout*)_CellLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newSingleCellLayout->dimExists[0] = self->dimExists[0];
-	newSingleCellLayout->dimExists[1] = self->dimExists[1];
-	newSingleCellLayout->dimExists[2] = self->dimExists[2];
-	newSingleCellLayout->min[0] = self->min[0];
-	newSingleCellLayout->min[1] = self->min[1];
-	newSingleCellLayout->min[2] = self->min[2];
-	newSingleCellLayout->max[0] = self->max[0];
-	newSingleCellLayout->max[1] = self->max[1];
-	newSingleCellLayout->max[2] = self->max[2];
-	newSingleCellLayout->pointCount = self->pointCount;
-	
-	if( deep ) {
-          if( (newSingleCellLayout->cellPointCoords = (double**)PtrMap_Find( map, self->cellPointCoords )) == NULL && self->cellPointCoords ) {
-			unsigned	p_i;
-
-			newSingleCellLayout->cellPointCoords = Memory_Alloc_2DArray( double, newSingleCellLayout->pointCount, 3, (Name)"SingleCellLayout->cellPoints" );
-			for( p_i = 0; p_i < newSingleCellLayout->pointCount; p_i++  )
-				memcpy( newSingleCellLayout->cellPointCoords[p_i], self->cellPointCoords[p_i], 
-					sizeof(double) * 3 * newSingleCellLayout->pointCount );
-			PtrMap_Append( map, self->cellPointCoords, newSingleCellLayout->cellPointCoords );
-		}
-	}
-	else {
-		newSingleCellLayout->cellPointCoords = self->cellPointCoords;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newSingleCellLayout;
-}
-
-void _SingleCellLayout_AssignFromXML( void* singleCellLayout, Stg_ComponentFactory* cf, void* data ){
-	SingleCellLayout* self              = (SingleCellLayout*)singleCellLayout;
-	Bool              dimExists[]       = { False, False, False };
-	Dimension_Index   dim;
-	XYZ               min;
-	XYZ               max;
-
-	_CellLayout_AssignFromXML( self, cf, data );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-	dimExists[ I_AXIS ] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dimExistsI", True  );
-	dimExists[ J_AXIS ] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dimExistsJ", True  );
-	dimExists[ K_AXIS ] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dimExistsK", (dim == 3) ? True : False  );
-
-	min[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minX", -1.0  );
-	min[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minY", -1.0  );
-	min[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minZ", -1.0  );
-
-	max[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxX", 1.0  );
-	max[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxY", 1.0  );
-	max[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxZ", 1.0  );
-
-	_SingleCellLayout_Init( self, dimExists, min, max );
-}
-	
-void _SingleCellLayout_Build( void* singleCellLayout, void* data ){
-	
-}
-	
-void _SingleCellLayout_Initialise( void* singleCellLayout, void* data ){
-	
-}
-	
-void _SingleCellLayout_Execute( void* singleCellLayout, void* data ){
-	
-}
-	
-void _SingleCellLayout_Destroy( void* singleCellLayout, void* data ){
-	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
-
-	Memory_Free( self->cellPointCoords );
-
-	_CellLayout_Destroy( self, data );
-}
-
-Cell_Index _SingleCellLayout_CellLocalCount( void* singleCellLayout ) {
-	/* There is only one cell... */
-	return 1;
-}
-
-
-Cell_Index _SingleCellLayout_CellShadowCount( void* singleCellLayout ) {
-	/* No shadow cells */
-	return 0;
-}
-
-
-void _SingleCellLayout_CalculateGlobalPointCount( SingleCellLayout* self ) {
-	Index dim_I;
-
-	self->pointCount = 1;
-	for ( dim_I = I_AXIS; dim_I < 3; dim_I++ ) {
-		if ( self->dimExists[dim_I] )
-			self->pointCount *= 2;
-	}
-}
-
-
-Cell_PointIndex _SingleCellLayout_PointCount( void* singleCellLayout, Cell_Index cellIndex ) {
-	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
-
-	/* already calculated, just return that value */
-	return self->pointCount;
-}
-
-
-void _SingleCellLayout_InitialiseGlobalCellPointPositions( SingleCellLayout* self ) {
-	Cell_PointIndex	point_I = 0;
-	Coord		tempCoord;
-	double*		currPointCoord = NULL;
-	int		i, j, k;	/* loop iterators for each dimension */
-	
-	tempCoord[0] = self->min[I_AXIS];
-	tempCoord[1] = self->min[J_AXIS];
-	tempCoord[2] = self->min[K_AXIS];
-	 
-	self->cellPointCoords = Memory_Alloc_2DArray( double, self->pointCount, 3, (Name)"SingleCellLayout->cellPoints" );
-	
-	/* Now generate the coordinates */
-	for ( k=0; k <= self->dimExists[K_AXIS]; k++ ) {
-		for (j=0; j <= self->dimExists[J_AXIS]; j++ ) {
-			for (i=0; i <= self->dimExists[I_AXIS]; i++ ) {
-				currPointCoord = self->cellPointCoords[ RegularMeshUtils_ascendingIJK_ToHughesNodeNumberMap[point_I++] ];
-				currPointCoord[I_AXIS] = tempCoord[I_AXIS];
-				currPointCoord[J_AXIS] = tempCoord[J_AXIS];
-				currPointCoord[K_AXIS] = tempCoord[K_AXIS];
-
-				/* flip/flop the i for next time */
-				tempCoord[I_AXIS] = ( self->min[I_AXIS] == tempCoord[I_AXIS] ) ? self->max[I_AXIS] : self->min[I_AXIS];
-			}
-
-			/* flip/flop the j for next time */
-			tempCoord[J_AXIS] = ( self->min[J_AXIS] == tempCoord[J_AXIS] ) ? self->max[J_AXIS] : self->min[J_AXIS];
-		}
-		/* flip/flop the k for next time */
-		tempCoord[K_AXIS] = ( self->min[K_AXIS] == tempCoord[K_AXIS]  ) ? self->max[K_AXIS] : self->min[K_AXIS];
-	}
-}
-
-
-void _SingleCellLayout_InitialisePoints( void* singleCellLayout, Cell_Index cellIndex, Cell_PointIndex pointCount, 
-		Cell_Points points ) 
-{
-	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
-	Cell_PointIndex point_I = 0;
-
-	/* since points have been pre-calculated, just return pointers to them */
-	for ( point_I=0; point_I < pointCount; point_I++ ) {
-		points[point_I] = &self->cellPointCoords[point_I];
-	}
-}
-
-
-Cell_Index _SingleCellLayout_MapElementIdToCellId( void* cellLayout, Element_DomainIndex element_dI ) {
-	
-	/* Always 0: see the header comment */
-	return 0;
-}
-
-
-Bool _SingleCellLayout_IsInCell( void* singleCellLayout, Cell_Index cellIndex, void* particle ) {
-	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
-	double** coord = (double**)particle;
-	Index dim_I = 0;
-	
-	for (dim_I=0; dim_I < 3; dim_I++ ) {
-		if ( self->dimExists[dim_I] ) {
-			if ( ((*coord)[dim_I] < self->min[dim_I]) || ((*coord)[dim_I] > self->max[dim_I]) ) {  
-				return False;
-			}	
-		}
-	}	
-	
-	return True;
-}
-
-
-Cell_Index _SingleCellLayout_CellOf( void* singleCellLayout, void* particle ) {
-	
-	/* in the single cell case, all particles belong to this cell */
-	return 0;
-}
-
-
-ShadowInfo* _SingleCellLayout_GetShadowInfo( void* singleCellLayout ) {
-	/* SingleCellLayout*      self = (SingleCellLayout*)singleCellLayout; */
-
-	/* TODO: this should return a shadow info with at least nbr info for my processors */
-	Journal_Firewall( 0, Swarm_Warning, "Error: %s not implemented yet!\n", __func__ );
-	return NULL;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SingleCellLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SingleCellLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,388 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SingleCellLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "CellLayout.h"
+#include "SingleCellLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+const Type SingleCellLayout_Type = "SingleCellLayout";
+
+
+SingleCellLayout* SingleCellLayout_New( Name name, AbstractContext* context, const Bool dimExists[3], const XYZ min, const XYZ max ) { 
+	SingleCellLayout* self = (SingleCellLayout*) _SingleCellLayout_DefaultNew( name );
+
+	self->isConstructed = True;
+	_CellLayout_Init( (CellLayout*)self, context );
+	_SingleCellLayout_Init( self, dimExists, min, max );
+
+	return self;
+}
+
+void* _SingleCellLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                _sizeOfSelf = sizeof(SingleCellLayout);
+	Type                                                        type = SingleCellLayout_Type;
+	Stg_Class_DeleteFunction*                                _delete = _SingleCellLayout_Delete;
+	Stg_Class_PrintFunction*                                  _print = _SingleCellLayout_Print;
+	Stg_Class_CopyFunction*                                    _copy = _SingleCellLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = _SingleCellLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                      _construct = _SingleCellLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                              _build = _SingleCellLayout_Build;
+	Stg_Component_InitialiseFunction*                    _initialise = _SingleCellLayout_Initialise;
+	Stg_Component_ExecuteFunction*                          _execute = _SingleCellLayout_Execute;
+	Stg_Component_DestroyFunction*                          _destroy = _SingleCellLayout_Destroy;
+	AllocationType                                nameAllocationType = NON_GLOBAL;
+	CellLayout_CellCountFunction*                    _cellLocalCount = _SingleCellLayout_CellLocalCount;
+	CellLayout_CellCountFunction*                   _cellShadowCount = _SingleCellLayout_CellShadowCount;
+	CellLayout_PointCountFunction*                       _pointCount = _SingleCellLayout_PointCount;
+	CellLayout_InitialisePointsFunction*           _initialisePoints = _SingleCellLayout_InitialisePoints;
+	CellLayout_MapElementIdToCellIdFunction*   _mapElementIdToCellId = _SingleCellLayout_MapElementIdToCellId;
+	CellLayout_IsInCellFunction*                           _isInCell = _SingleCellLayout_IsInCell;
+	CellLayout_CellOfFunction*                               _cellOf = _SingleCellLayout_CellOf;
+	CellLayout_GetShadowInfoFunction*                 _getShadowInfo = _SingleCellLayout_GetShadowInfo;
+
+	return (void*)_SingleCellLayout_New(  SINGLECELLLAYOUT_PASSARGS  );
+}
+
+SingleCellLayout* _SingleCellLayout_New(  SINGLECELLLAYOUT_DEFARGS  ) {
+	SingleCellLayout* self;
+	
+	/* Allocate memory */
+	self = (SingleCellLayout*)_CellLayout_New(  CELLLAYOUT_PASSARGS  );
+	
+	/* Virtual info */
+	
+	/* SingleCellLayout info */
+	
+	return self;
+}
+
+void _SingleCellLayout_Init( void* cellLayout, const Bool dimExists[3], const XYZ min, const XYZ max ) { 
+	SingleCellLayout* self        = (SingleCellLayout*) cellLayout;
+	Dimension_Index   dim_I;
+	XYZ               minDefaults = { -1.0, -1.0, -1.0 };
+	XYZ               maxDefaults = { 1.0, 1.0, 1.0 };
+	
+	/* General and Virtual info should already be set */
+
+	self->isConstructed = True;
+	for ( dim_I=0; dim_I < 3; dim_I++ ) {
+		self->dimExists[dim_I] = dimExists[dim_I];
+	}
+	
+	/* Get min and max values */
+	if ( min )
+		memcpy( self->min, min, sizeof( XYZ ));
+	else
+		memcpy( self->min, minDefaults, sizeof( XYZ ));
+	if ( max )
+		memcpy( self->max, max, sizeof( XYZ ));
+	else
+		memcpy( self->max, maxDefaults, sizeof( XYZ ));
+
+	for ( dim_I=0; dim_I < 3; dim_I++ ) {
+		if ( !dimExists[dim_I] ) {
+			self->min[dim_I] = 0.0;
+			self->max[dim_I] = 0.0;
+		}
+	}	
+
+	/* Since pointcount and cell points are the same for all cells, calculate them now */
+	_SingleCellLayout_CalculateGlobalPointCount( self );
+	_SingleCellLayout_InitialiseGlobalCellPointPositions( self );
+}
+
+
+void _SingleCellLayout_Delete( void* singleCellLayout ) {
+	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
+	
+	/* Stg_Class_Delete parent class */
+	_CellLayout_Delete( self );
+}
+
+void _SingleCellLayout_Print( void* singleCellLayout, Stream* stream ) {
+	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
+	Index i;
+	
+	/* Set the Journal for printing informations */
+	Stream* singleCellLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( singleCellLayoutStream, "SingleCellLayout (ptr): %p\n", self ); 
+	
+	/* Parent class info */
+	_CellLayout_Print( self, stream );
+	
+	/* Virtual info */
+	
+	/* SingleCellLayout info */
+	Journal_Printf( singleCellLayoutStream, "self->dimExists[" );
+	for (i=I_AXIS; i < 3; i++ ) {
+		Journal_Printf( singleCellLayoutStream, " %d,", self->dimExists[i] );
+	}
+	Journal_Printf( singleCellLayoutStream, "]\n" );
+	
+	Journal_Printf( singleCellLayoutStream, "self->min[" );
+	for (i=I_AXIS; i < 3; i++ ) {
+		Journal_Printf( singleCellLayoutStream, " %f,", self->min[i] );
+	}	
+	Journal_Printf( singleCellLayoutStream, "]\n" );
+	
+	Journal_Printf( singleCellLayoutStream, "self->max[" );
+	for (i=I_AXIS; i < 3; i++ ) {
+		Journal_Printf( singleCellLayoutStream, " %f,", self->max[i] );
+	}	
+	Journal_Printf( singleCellLayoutStream, "]\n" );
+}
+
+
+void* _SingleCellLayout_Copy( const void* singleCellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SingleCellLayout*	self = (SingleCellLayout*)singleCellLayout;
+	SingleCellLayout*	newSingleCellLayout;
+	PtrMap*			map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newSingleCellLayout = (SingleCellLayout*)_CellLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newSingleCellLayout->dimExists[0] = self->dimExists[0];
+	newSingleCellLayout->dimExists[1] = self->dimExists[1];
+	newSingleCellLayout->dimExists[2] = self->dimExists[2];
+	newSingleCellLayout->min[0] = self->min[0];
+	newSingleCellLayout->min[1] = self->min[1];
+	newSingleCellLayout->min[2] = self->min[2];
+	newSingleCellLayout->max[0] = self->max[0];
+	newSingleCellLayout->max[1] = self->max[1];
+	newSingleCellLayout->max[2] = self->max[2];
+	newSingleCellLayout->pointCount = self->pointCount;
+	
+	if( deep ) {
+          if( (newSingleCellLayout->cellPointCoords = (double**)PtrMap_Find( map, self->cellPointCoords )) == NULL && self->cellPointCoords ) {
+			unsigned	p_i;
+
+			newSingleCellLayout->cellPointCoords = Memory_Alloc_2DArray( double, newSingleCellLayout->pointCount, 3, (Name)"SingleCellLayout->cellPoints" );
+			for( p_i = 0; p_i < newSingleCellLayout->pointCount; p_i++  )
+				memcpy( newSingleCellLayout->cellPointCoords[p_i], self->cellPointCoords[p_i], 
+					sizeof(double) * 3 * newSingleCellLayout->pointCount );
+			PtrMap_Append( map, self->cellPointCoords, newSingleCellLayout->cellPointCoords );
+		}
+	}
+	else {
+		newSingleCellLayout->cellPointCoords = self->cellPointCoords;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newSingleCellLayout;
+}
+
+void _SingleCellLayout_AssignFromXML( void* singleCellLayout, Stg_ComponentFactory* cf, void* data ){
+	SingleCellLayout* self              = (SingleCellLayout*)singleCellLayout;
+	Bool              dimExists[]       = { False, False, False };
+	Dimension_Index   dim;
+	XYZ               min;
+	XYZ               max;
+
+	_CellLayout_AssignFromXML( self, cf, data );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+	dimExists[ I_AXIS ] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dimExistsI", True  );
+	dimExists[ J_AXIS ] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dimExistsJ", True  );
+	dimExists[ K_AXIS ] = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"dimExistsK", (dim == 3) ? True : False  );
+
+	min[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minX", -1.0  );
+	min[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minY", -1.0  );
+	min[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"minZ", -1.0  );
+
+	max[ I_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxX", 1.0  );
+	max[ J_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxY", 1.0  );
+	max[ K_AXIS ] = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"maxZ", 1.0  );
+
+	_SingleCellLayout_Init( self, dimExists, min, max );
+}
+	
+void _SingleCellLayout_Build( void* singleCellLayout, void* data ){
+	
+}
+	
+void _SingleCellLayout_Initialise( void* singleCellLayout, void* data ){
+	
+}
+	
+void _SingleCellLayout_Execute( void* singleCellLayout, void* data ){
+	
+}
+	
+void _SingleCellLayout_Destroy( void* singleCellLayout, void* data ){
+	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
+
+	Memory_Free( self->cellPointCoords );
+
+	_CellLayout_Destroy( self, data );
+}
+
+Cell_Index _SingleCellLayout_CellLocalCount( void* singleCellLayout ) {
+	/* There is only one cell... */
+	return 1;
+}
+
+
+Cell_Index _SingleCellLayout_CellShadowCount( void* singleCellLayout ) {
+	/* No shadow cells */
+	return 0;
+}
+
+
+void _SingleCellLayout_CalculateGlobalPointCount( SingleCellLayout* self ) {
+	Index dim_I;
+
+	self->pointCount = 1;
+	for ( dim_I = I_AXIS; dim_I < 3; dim_I++ ) {
+		if ( self->dimExists[dim_I] )
+			self->pointCount *= 2;
+	}
+}
+
+
+Cell_PointIndex _SingleCellLayout_PointCount( void* singleCellLayout, Cell_Index cellIndex ) {
+	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
+
+	/* already calculated, just return that value */
+	return self->pointCount;
+}
+
+
+void _SingleCellLayout_InitialiseGlobalCellPointPositions( SingleCellLayout* self ) {
+	Cell_PointIndex	point_I = 0;
+	Coord		tempCoord;
+	double*		currPointCoord = NULL;
+	int		i, j, k;	/* loop iterators for each dimension */
+	
+	tempCoord[0] = self->min[I_AXIS];
+	tempCoord[1] = self->min[J_AXIS];
+	tempCoord[2] = self->min[K_AXIS];
+	 
+	self->cellPointCoords = Memory_Alloc_2DArray( double, self->pointCount, 3, (Name)"SingleCellLayout->cellPoints" );
+	
+	/* Now generate the coordinates */
+	for ( k=0; k <= self->dimExists[K_AXIS]; k++ ) {
+		for (j=0; j <= self->dimExists[J_AXIS]; j++ ) {
+			for (i=0; i <= self->dimExists[I_AXIS]; i++ ) {
+				currPointCoord = self->cellPointCoords[ RegularMeshUtils_ascendingIJK_ToHughesNodeNumberMap[point_I++] ];
+				currPointCoord[I_AXIS] = tempCoord[I_AXIS];
+				currPointCoord[J_AXIS] = tempCoord[J_AXIS];
+				currPointCoord[K_AXIS] = tempCoord[K_AXIS];
+
+				/* flip/flop the i for next time */
+				tempCoord[I_AXIS] = ( self->min[I_AXIS] == tempCoord[I_AXIS] ) ? self->max[I_AXIS] : self->min[I_AXIS];
+			}
+
+			/* flip/flop the j for next time */
+			tempCoord[J_AXIS] = ( self->min[J_AXIS] == tempCoord[J_AXIS] ) ? self->max[J_AXIS] : self->min[J_AXIS];
+		}
+		/* flip/flop the k for next time */
+		tempCoord[K_AXIS] = ( self->min[K_AXIS] == tempCoord[K_AXIS]  ) ? self->max[K_AXIS] : self->min[K_AXIS];
+	}
+}
+
+
+void _SingleCellLayout_InitialisePoints( void* singleCellLayout, Cell_Index cellIndex, Cell_PointIndex pointCount, 
+		Cell_Points points ) 
+{
+	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
+	Cell_PointIndex point_I = 0;
+
+	/* since points have been pre-calculated, just return pointers to them */
+	for ( point_I=0; point_I < pointCount; point_I++ ) {
+		points[point_I] = &self->cellPointCoords[point_I];
+	}
+}
+
+
+Cell_Index _SingleCellLayout_MapElementIdToCellId( void* cellLayout, Element_DomainIndex element_dI ) {
+	
+	/* Always 0: see the header comment */
+	return 0;
+}
+
+
+Bool _SingleCellLayout_IsInCell( void* singleCellLayout, Cell_Index cellIndex, void* particle ) {
+	SingleCellLayout* self = (SingleCellLayout*)singleCellLayout;
+	double** coord = (double**)particle;
+	Index dim_I = 0;
+	
+	for (dim_I=0; dim_I < 3; dim_I++ ) {
+		if ( self->dimExists[dim_I] ) {
+			if ( ((*coord)[dim_I] < self->min[dim_I]) || ((*coord)[dim_I] > self->max[dim_I]) ) {  
+				return False;
+			}	
+		}
+	}	
+	
+	return True;
+}
+
+
+Cell_Index _SingleCellLayout_CellOf( void* singleCellLayout, void* particle ) {
+	
+	/* in the single cell case, all particles belong to this cell */
+	return 0;
+}
+
+
+ShadowInfo* _SingleCellLayout_GetShadowInfo( void* singleCellLayout ) {
+	/* SingleCellLayout*      self = (SingleCellLayout*)singleCellLayout; */
+
+	/* TODO: this should return a shadow info with at least nbr info for my processors */
+	Journal_Firewall( 0, Swarm_Warning, "Error: %s not implemented yet!\n", __func__ );
+	return NULL;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SpaceFillerParticleLayout.c
--- a/Swarm/src/SpaceFillerParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,242 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SpaceFillerParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "SpaceFillerParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-const Type SpaceFillerParticleLayout_Type = "SpaceFillerParticleLayout";
-
-const Index SpaceFillerParticleLayout_Invalid = (Index) 0;
-
-SpaceFillerParticleLayout* SpaceFillerParticleLayout_New( 
-		Name             name,
-      AbstractContext* context, 
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles, 
-      double           averageInitialParticlesPerCell,
-		Dimension_Index  dim )
-{
-	SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*) _SpaceFillerParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-	_SpaceFillerParticleLayout_Init( self, dim );
-	return self;
-}
-
-SpaceFillerParticleLayout* _SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_DEFARGS  )
-{
-   SpaceFillerParticleLayout* self;
-
-   /* Allocate memory */
-   self = (SpaceFillerParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
-
-   self->dim = dim;
-
-	return self;
-}
-
-void _SpaceFillerParticleLayout_Init( 
-		void*                   spaceFillerParticleLayout,
-		Dimension_Index         dim )
-{
-	SpaceFillerParticleLayout*	self = (SpaceFillerParticleLayout*) spaceFillerParticleLayout;
-
-	self->isConstructed = True;
-	self->dim           = dim;
-
-	self->sobolGenerator[I_AXIS] = SobolGenerator_NewFromTable( "xSobolGenerator" );
-	self->sobolGenerator[J_AXIS] = SobolGenerator_NewFromTable( "ySobolGenerator" );
-	if ( dim == 3 )
-		self->sobolGenerator[K_AXIS] = SobolGenerator_NewFromTable( "zSobolGenerator" );
-
-	/* Must set one or the other. Fail if both set, or none */
-	Journal_Firewall( 
-		(self->totalInitialParticles == SpaceFillerParticleLayout_Invalid)
-			^ ((Index)self->averageInitialParticlesPerCell == SpaceFillerParticleLayout_Invalid),
-		Journal_MyStream( Error_Type, self ),
-		"Error in func %s for %s '%s' - Both averageInitialParticlesPerCell and totalInitialParticles%sspecified.\n",
-		__func__, 
-		self->type, 
-		self->name,
-		(self->totalInitialParticles == SpaceFillerParticleLayout_Invalid) ? " not " : " " );
-	
-}
-
-
-	
-void _SpaceFillerParticleLayout_Delete( void* spaceFillerParticleLayout ) {
-	SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
-
-	_GlobalParticleLayout_Delete( self );
-}
-
-void _SpaceFillerParticleLayout_Print( void* spaceFillerParticleLayout, Stream* stream ) {
-	SpaceFillerParticleLayout* self  = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "SpaceFillerParticleLayout (ptr): %p:\n", self );
-	Stream_Indent( stream );
-	
-	/* Parent class info */
-	_GlobalParticleLayout_Print( self, stream );
-	
-	/* SpaceFillerParticleLayout */
-	Journal_PrintValue( stream, self->dim );
-	
-	Stream_UnIndent( stream );
-}
-
-void* _SpaceFillerParticleLayout_Copy( const void* spaceFillerParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SpaceFillerParticleLayout*		self                    = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
-	SpaceFillerParticleLayout*		newSpaceFillerParticleLayout;
-	
-	newSpaceFillerParticleLayout = (SpaceFillerParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newSpaceFillerParticleLayout->dim = self->dim;
-
-	return (void*)newSpaceFillerParticleLayout;
-}
-
-void* _SpaceFillerParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(SpaceFillerParticleLayout);
-	Type                                                                        type = SpaceFillerParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _SpaceFillerParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _SpaceFillerParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _SpaceFillerParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _SpaceFillerParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _SpaceFillerParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _SpaceFillerParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _SpaceFillerParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _SpaceFillerParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _SpaceFillerParticleLayout_Destroy;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _SpaceFillerParticleLayout_InitialiseParticles;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _SpaceFillerParticleLayout_InitialiseParticle;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	Dimension_Index                                                              dim = 0;
-
-	return (void*)_SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_PASSARGS  );
-}
-
-
-void _SpaceFillerParticleLayout_AssignFromXML( void* spaceFillerParticleLayout, Stg_ComponentFactory *cf, void* data ) {
-   SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*) spaceFillerParticleLayout;
-   Dimension_Index            dim;
-
-   _GlobalParticleLayout_AssignFromXML( self, cf, data );
-
-   dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-   _SpaceFillerParticleLayout_Init( self, dim );
-}
-	
-void _SpaceFillerParticleLayout_Build( void* spaceFillerParticleLayout, void* data ) {
-}
-void _SpaceFillerParticleLayout_Initialise( void* spaceFillerParticleLayout, void* data ) {
-}	
-void _SpaceFillerParticleLayout_Execute( void* spaceFillerParticleLayout, void* data ) {	
-}
-void _SpaceFillerParticleLayout_Destroy( void* spaceFillerParticleLayout, void* data ) {	
-   SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
-   unsigned dim_I;
-   
-   for ( dim_I = 0 ; dim_I < self->dim ; dim_I++ ) 
-      Stg_Class_Delete( self->sobolGenerator[ dim_I ] );
-
-   _GlobalParticleLayout_Destroy( self, data );
-}
-
-void _SpaceFillerParticleLayout_InitialiseParticles( void* spaceFillerParticleLayout, void* swarm ) {
-	SpaceFillerParticleLayout*        self     = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
-
-	/* Initialise random number generator */
-	_GlobalParticleLayout_InitialiseParticles( self, swarm );
-}
-
-void _SpaceFillerParticleLayout_InitialiseParticle( 
-		void*             spaceFillerParticleLayout, 
-		void*             _swarm, 
-		Particle_Index    newParticle_I,
-		void*             _particle )
-{
-	SpaceFillerParticleLayout*  self     = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
-	Swarm*                      swarm    = (Swarm*)_swarm;
-	double				minCrd[3];
-	double				maxCrd[3];
-	Dimension_Index             dim_I;
-	double*                     coord;
-	GlobalParticle*             particle = (GlobalParticle*)_particle;
-	/* Note: we have to assume element cell layout to get the full box coords - maybe these
-	should be available as part of all cell layouts */
-	ElementCellLayout*          eCellLayout = Stg_CheckType( swarm->cellLayout, ElementCellLayout );
-	Mesh*                       mesh = eCellLayout->mesh;
-
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-
-	coord = particle->coord;
-	memset( coord, 0, sizeof(Coord) );
-
-	for ( dim_I = 0; dim_I < self->dim; dim_I++ ) {
-		coord[ dim_I ] = SobolGenerator_GetNextNumber_WithMinMax(
-			self->sobolGenerator[ dim_I ], 
-			minCrd[ dim_I ], 
-			maxCrd[ dim_I ]);
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SpaceFillerParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SpaceFillerParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,242 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SpaceFillerParticleLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "SpaceFillerParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+const Type SpaceFillerParticleLayout_Type = "SpaceFillerParticleLayout";
+
+const Index SpaceFillerParticleLayout_Invalid = (Index) 0;
+
+SpaceFillerParticleLayout* SpaceFillerParticleLayout_New( 
+		Name             name,
+      AbstractContext* context, 
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles, 
+      double           averageInitialParticlesPerCell,
+		Dimension_Index  dim )
+{
+	SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*) _SpaceFillerParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+	_SpaceFillerParticleLayout_Init( self, dim );
+	return self;
+}
+
+SpaceFillerParticleLayout* _SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_DEFARGS  )
+{
+   SpaceFillerParticleLayout* self;
+
+   /* Allocate memory */
+   self = (SpaceFillerParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
+
+   self->dim = dim;
+
+	return self;
+}
+
+void _SpaceFillerParticleLayout_Init( 
+		void*                   spaceFillerParticleLayout,
+		Dimension_Index         dim )
+{
+	SpaceFillerParticleLayout*	self = (SpaceFillerParticleLayout*) spaceFillerParticleLayout;
+
+	self->isConstructed = True;
+	self->dim           = dim;
+
+	self->sobolGenerator[I_AXIS] = SobolGenerator_NewFromTable( "xSobolGenerator" );
+	self->sobolGenerator[J_AXIS] = SobolGenerator_NewFromTable( "ySobolGenerator" );
+	if ( dim == 3 )
+		self->sobolGenerator[K_AXIS] = SobolGenerator_NewFromTable( "zSobolGenerator" );
+
+	/* Must set one or the other. Fail if both set, or none */
+	Journal_Firewall( 
+		(self->totalInitialParticles == SpaceFillerParticleLayout_Invalid)
+			^ ((Index)self->averageInitialParticlesPerCell == SpaceFillerParticleLayout_Invalid),
+		Journal_MyStream( Error_Type, self ),
+		"Error in func %s for %s '%s' - Both averageInitialParticlesPerCell and totalInitialParticles%sspecified.\n",
+		__func__, 
+		self->type, 
+		self->name,
+		(self->totalInitialParticles == SpaceFillerParticleLayout_Invalid) ? " not " : " " );
+	
+}
+
+
+	
+void _SpaceFillerParticleLayout_Delete( void* spaceFillerParticleLayout ) {
+	SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
+
+	_GlobalParticleLayout_Delete( self );
+}
+
+void _SpaceFillerParticleLayout_Print( void* spaceFillerParticleLayout, Stream* stream ) {
+	SpaceFillerParticleLayout* self  = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "SpaceFillerParticleLayout (ptr): %p:\n", self );
+	Stream_Indent( stream );
+	
+	/* Parent class info */
+	_GlobalParticleLayout_Print( self, stream );
+	
+	/* SpaceFillerParticleLayout */
+	Journal_PrintValue( stream, self->dim );
+	
+	Stream_UnIndent( stream );
+}
+
+void* _SpaceFillerParticleLayout_Copy( const void* spaceFillerParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SpaceFillerParticleLayout*		self                    = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
+	SpaceFillerParticleLayout*		newSpaceFillerParticleLayout;
+	
+	newSpaceFillerParticleLayout = (SpaceFillerParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newSpaceFillerParticleLayout->dim = self->dim;
+
+	return (void*)newSpaceFillerParticleLayout;
+}
+
+void* _SpaceFillerParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(SpaceFillerParticleLayout);
+	Type                                                                        type = SpaceFillerParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _SpaceFillerParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _SpaceFillerParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _SpaceFillerParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _SpaceFillerParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _SpaceFillerParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _SpaceFillerParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _SpaceFillerParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _SpaceFillerParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _SpaceFillerParticleLayout_Destroy;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _SpaceFillerParticleLayout_InitialiseParticles;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _SpaceFillerParticleLayout_InitialiseParticle;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	Dimension_Index                                                              dim = 0;
+
+	return (void*)_SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_PASSARGS  );
+}
+
+
+void _SpaceFillerParticleLayout_AssignFromXML( void* spaceFillerParticleLayout, Stg_ComponentFactory *cf, void* data ) {
+   SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*) spaceFillerParticleLayout;
+   Dimension_Index            dim;
+
+   _GlobalParticleLayout_AssignFromXML( self, cf, data );
+
+   dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+   _SpaceFillerParticleLayout_Init( self, dim );
+}
+	
+void _SpaceFillerParticleLayout_Build( void* spaceFillerParticleLayout, void* data ) {
+}
+void _SpaceFillerParticleLayout_Initialise( void* spaceFillerParticleLayout, void* data ) {
+}	
+void _SpaceFillerParticleLayout_Execute( void* spaceFillerParticleLayout, void* data ) {	
+}
+void _SpaceFillerParticleLayout_Destroy( void* spaceFillerParticleLayout, void* data ) {	
+   SpaceFillerParticleLayout* self = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
+   unsigned dim_I;
+   
+   for ( dim_I = 0 ; dim_I < self->dim ; dim_I++ ) 
+      Stg_Class_Delete( self->sobolGenerator[ dim_I ] );
+
+   _GlobalParticleLayout_Destroy( self, data );
+}
+
+void _SpaceFillerParticleLayout_InitialiseParticles( void* spaceFillerParticleLayout, void* swarm ) {
+	SpaceFillerParticleLayout*        self     = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
+
+	/* Initialise random number generator */
+	_GlobalParticleLayout_InitialiseParticles( self, swarm );
+}
+
+void _SpaceFillerParticleLayout_InitialiseParticle( 
+		void*             spaceFillerParticleLayout, 
+		void*             _swarm, 
+		Particle_Index    newParticle_I,
+		void*             _particle )
+{
+	SpaceFillerParticleLayout*  self     = (SpaceFillerParticleLayout*)spaceFillerParticleLayout;
+	Swarm*                      swarm    = (Swarm*)_swarm;
+	double				minCrd[3];
+	double				maxCrd[3];
+	Dimension_Index             dim_I;
+	double*                     coord;
+	GlobalParticle*             particle = (GlobalParticle*)_particle;
+	/* Note: we have to assume element cell layout to get the full box coords - maybe these
+	should be available as part of all cell layouts */
+	ElementCellLayout*          eCellLayout = Stg_CheckType( swarm->cellLayout, ElementCellLayout );
+	Mesh*                       mesh = eCellLayout->mesh;
+
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+
+	coord = particle->coord;
+	memset( coord, 0, sizeof(Coord) );
+
+	for ( dim_I = 0; dim_I < self->dim; dim_I++ ) {
+		coord[ dim_I ] = SobolGenerator_GetNextNumber_WithMinMax(
+			self->sobolGenerator[ dim_I ], 
+			minCrd[ dim_I ], 
+			maxCrd[ dim_I ]);
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/StandardParticle.c
--- a/Swarm/src/StandardParticle.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-**
-**
-** Assumptions:
-**
-** Comments:
-**
-** $Id: Swarm_Register.c 2745 2005-05-10 08:12:18Z RaquibulHassan $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-
-#include "StandardParticle.h"
-
-const Type StandardParticle_Type = "StandardParticle";
-const Type LocalParticle_Type    = "LocalParticle";
-const Type GlobalParticle_Type   = "GlobalParticle";
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/StandardParticle.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/StandardParticle.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,54 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+**
+**
+** Assumptions:
+**
+** Comments:
+**
+** $Id: Swarm_Register.c 2745 2005-05-10 08:12:18Z RaquibulHassan $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+
+#include "StandardParticle.h"
+
+const Type StandardParticle_Type = "StandardParticle";
+const Type LocalParticle_Type    = "LocalParticle";
+const Type GlobalParticle_Type   = "GlobalParticle";
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmClass.c
--- a/Swarm/src/SwarmClass.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1655 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SwarmClass.c 4191 2007-10-05 06:23:59Z DavidLee $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#ifdef READ_HDF5
-#include <hdf5.h>
-#endif
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "SwarmClass.h"
-
-#include "StandardParticle.h"
-#include "ShadowInfo.h"
-#include "CellLayout.h"
-#include "ElementCellLayout.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "SingleCellLayout.h"
-#include "FileParticleLayout.h"
-#include "ParticleCommHandler.h"
-#include "ParticleMovementHandler.h"
-#include "ParticleShadowSync.h"
-#include "IntegrationPoint.h"
-#include "SwarmVariable_Register.h"
-#include "SwarmVariable.h"
-#include "Swarm_Register.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-
-const Type Swarm_Type = "Swarm";
-const Name defaultSwarmParticleCommHandlerName = "defaultSwarmPHandlerName";
-
-/** Default extra factor to malloc for particles array. This is because the number of particles on each process
-may increase due to advection, splitting/merging etc, and we want to avoid reallocing if possible. */
-const double       DEFAULT_EXTRA_PARTICLES_FACTOR = 0.05;
-const unsigned int MINIMUM_PARTICLES_ARRAY_DELTA = 100;
-const unsigned int DEFAULT_CELL_PARTICLE_TBL_DELTA = 4;
-
-/* --- Function Definitions --- */
-
-Swarm* Swarm_New( 
-   Name                                  name,
-   AbstractContext*                      context,
-   void*                                 cellLayout,
-   void*                                 particleLayout,
-   Dimension_Index                       dim,
-   SizeT                                 particleSize,
-   ExtensionManager_Register*            extensionMgr_Register,
-   Variable_Register*                    variable_Register,
-   MPI_Comm                              comm,
-   void*				                       ics ) 
-{
-  Swarm* self = (Swarm*)_Swarm_DefaultNew( name ); 
-
-   _Swarm_Init( 
-      self, context,
-      cellLayout,
-      particleLayout,
-      dim,
-      particleSize,
-      DEFAULT_CELL_PARTICLE_TBL_DELTA,
-      DEFAULT_EXTRA_PARTICLES_FACTOR,
-      extensionMgr_Register,
-      variable_Register,
-      comm, 
-      ics );
-
-   self->isConstructed = True;
-
-
-   return self;
-}
-
-Swarm* _Swarm_New(  SWARM_DEFARGS  )
-{
-	Swarm* self;
-	
-	/* Allocate memory */
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (Swarm*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	self->particleSize = particleSize;
-	self->commHandlerList = Stg_ObjectList_New();
-	self->nSwarmVars = 0;
-	self->swarmVars = NULL;
-	self->owningCellVariable = NULL;
-        self->ics = (VariableCondition*)ics;
-
-	return self;
-}
-
-void _Swarm_Init( 
-   Swarm*                                self, 
-   AbstractContext*                      context,
-   void*                                 cellLayout,
-   void*                                 particleLayout,
-   Dimension_Index                       dim,
-   SizeT                                 particleSize,
-   Particle_InCellIndex                  cellParticleTblDelta, 
-   double                                extraParticlesFactor,
-   ExtensionManager_Register*            extensionMgr_Register,
-   Variable_Register*                    variable_Register,
-   MPI_Comm                              comm,
-   void*				      ics )
-{
-	StandardParticle   particle;
-	Stream*            errorStream = Journal_Register( Error_Type, (Name)self->type  );
-   LiveComponentRegister* lcReg = NULL; 	
-
-	self->debug = Stream_RegisterChild( Swarm_Debug, self->type );
-	self->dim   = dim;
-	self->comm = comm;
-	MPI_Comm_rank( comm, (int *)&self->myRank );
-	MPI_Comm_size( comm, (int *)&self->nProc );
-	self->stillDoingInitialisation = True;
-	/* Check point and reload by default - only things like integration swarms will turn this off */
-	self->isSwarmTypeToCheckPointAndReload = True;
-
-   self->particleSize = particleSize;
-   self->context = (AbstractContext*)context;
-	self->cellLayout = (CellLayout*)cellLayout;
-	self->particleLayout = (ParticleLayout*)particleLayout;
-	
-	/* Check that if either the CellLayout or ParticleLayout is inappropriate to be checkpointed,
-		we set tthe appropriate flags -- PatrickSunter, 22 August 2006 */
-	if ( Stg_Class_IsInstance( self->cellLayout, SingleCellLayout_Type ) ) {
-		self->isSwarmTypeToCheckPointAndReload = False;
-	}
-	
-	self->cellLocalCount = 0;
-	self->cellDomainCount = 0;
-	self->cellShadowCount = 0;
-	self->cellPointTbl = NULL;
-	self->cellPointCountTbl = NULL;
-	
-	self->cellParticleTbl = NULL;
-	self->cellParticleCountTbl = NULL;
-	self->cellParticleSizeTbl = NULL;
-	self->shadowCellParticleTbl = NULL;
-	self->shadowCellParticleCountTbl = NULL;
-	self->shadowParticleCount = 0;
-	self->cellParticleTblDelta = cellParticleTblDelta;
-	
-	self->particles = NULL;
-	self->shadowParticles = NULL;
-	self->particleLocalCount = 0;
-	self->particlesArraySize = 0;
-	self->particlesArrayDelta = 0;
-	self->extraParticlesFactor = extraParticlesFactor;
-
-	self->shadowTablesBuilt = False;
-
-	Journal_Firewall( extraParticlesFactor > 0.0, errorStream, "Error - in %s: extraParticlesFactor "
-		"given as %.3f, but this must be greater than zero to allow swarm to be realloc'ed larger "
-		"if necessary\n", extraParticlesFactor );
-
-	if ( variable_Register ) {
-		self->swarmVariable_Register = SwarmVariable_Register_New( variable_Register );
-	}
-	else {
-		self->swarmVariable_Register = NULL;
-	}
-
-	self->particleExtensionMgr = ExtensionManager_New_OfStruct( "particle", self->particleSize );
-	ExtensionManager_Register_Add( extensionMgr_Register, self->particleExtensionMgr );
-
-	self->owningCellVariable = Swarm_NewScalarVariable(
-			self,
-			"OwningCell",
-			GetOffsetOfMember( particle , owningCell ),
-			Variable_DataType_Int ); /* Should be unsigned int */
-
-   lcReg = LiveComponentRegister_GetLiveComponentRegister(); /* only needed for tests like GaussLayoutSingleCellSuite which don't have liveComponent_Registers */
-   if( lcReg ) {
-      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->owningCellVariable );
-      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->owningCellVariable->variable );
-   }
-
-   /* disable checkpointing of OwningCell as it is reinitialised on startup */   
-   self->owningCellVariable->isCheckpointedAndReloaded = False;
-
-	self->swarmReg_I = Swarm_Register_Add( Swarm_Register_GetSwarm_Register(), self );
-
-	if ( ics ) {
-		self->ics = Stg_CheckType( ics, VariableCondition );
-	}
-
-	self->incArray = IArray_New();
-
-	self->expanding = 0;
-}
-
-
-void* _Swarm_ParticleInCellAt( void* swarm, Cell_Index cell_I, Particle_InCellIndex cParticle_I ) {
-	Swarm* self =	(Swarm*)swarm;
-	
-	return (void*)Swarm_ParticleInCellAt( self, cell_I, cParticle_I );
-}
-
-
-void* _Swarm_ParticleAt( void* swarm, Particle_Index dParticle_I ) {
-	Swarm* self = (Swarm*)swarm;
-	
-	return (void*)Swarm_ParticleAt( self, dParticle_I );
-}
-
-
-void _Swarm_Delete( void* swarm ) {
-	Swarm*			self = (Swarm*)swarm;
-
-	_Stg_Component_Delete( self );
-}
-
-
-void _Swarm_Print( void* swarm, Stream* stream ) {
-	Swarm* self = (Swarm*)swarm;
-	
-	Cell_Index cell_I;
-	
-	/* Set the Journal for printing informations */
-	Stream* swarmStream = stream;
-	
-	/* General info */
-	Journal_Printf( swarmStream, "Swarm (ptr): %p\n", self );
-	
-	/* Parent class info */
-	_Stg_Component_Print( self, stream );
-	
-	/* Virtual info */
-
-	/* Swarm info */
-	Stg_Class_Print( self->cellLayout, stream );
-	Stg_Class_Print( self->particleLayout, stream );
-	Journal_Printf( swarmStream, "\tcellLocalCount: %u\n", self->cellLocalCount );
-	Journal_Printf( swarmStream, "\tcellDomainCount: %u\n", self->cellDomainCount );
-	Journal_Printf( swarmStream, "\tcellShadowCount: %u\n", self->cellShadowCount );
-	Journal_Printf( swarmStream, "\tcellPointCountTbl (ptr): %p\n", self->cellPointCountTbl );
-	Journal_Printf( swarmStream, "\tcellPointCountTbl[0-%u]: ", self->cellDomainCount );
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		Journal_Printf( swarmStream, "%.3u ", self->cellPointCountTbl[cell_I] );
-	}
-	Journal_Printf( swarmStream, "\n" );
-	
-	Journal_Printf( swarmStream, "\tcellPointTbl (ptr): %p\n", self->cellPointTbl );
-	Journal_Printf( swarmStream, "\tcellPointTbl[0-%u]: {\n", self->cellDomainCount );
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		Cell_PointIndex point_I;
-
-		Journal_Printf( swarmStream, "\tcellPointTbl[%u][0-%u]: ", cell_I, self->cellPointCountTbl[cell_I] );
-		for( point_I = 0; point_I < self->cellPointCountTbl[cell_I]; point_I++ ) {
-			Journal_Printf( swarmStream, "{%.3g %.3g %.3g} ",
-				(*self->cellPointTbl[cell_I][point_I])[0], 
-				(*self->cellPointTbl[cell_I][point_I])[1], 
-				(*self->cellPointTbl[cell_I][point_I])[2] );
-		}
-		Journal_Printf( swarmStream, "\n" );
-	}
-	Journal_Printf( swarmStream, "}\n" );
-	Journal_Printf( swarmStream, "\n" );
-	
-	Journal_Printf( swarmStream, "\tcellParticleCountTbl (ptr): %p\n", self->cellParticleCountTbl );
-	Journal_Printf( swarmStream, "\tcellParticleCountTbl[0-%u]: ", self->cellDomainCount );
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		Journal_Printf( swarmStream, "%.3u ", self->cellParticleCountTbl[cell_I] );
-	}
-	Journal_Printf( swarmStream, "\n" );
-	Journal_Printf( swarmStream, "\tcellParticleSizeTbl (ptr): %p\n", self->cellParticleSizeTbl );
-	Journal_Printf( swarmStream, "\tcellParticleSizeTbl[0-%u]: ", self->cellDomainCount );
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		Journal_Printf( swarmStream, "%.3u ", self->cellParticleSizeTbl[cell_I] );
-	}
-	Journal_Printf( swarmStream, "\n" );
-
-	/* Print( self->particleExtensionMgr, stream ); */
-	Journal_Printf( swarmStream, "\tcellParticleTbl (ptr): %p\n", self->cellParticleTbl );
-	Journal_Printf( swarmStream, "\tcellParticleTbl [0-%u]: {\n", self->cellDomainCount );
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		Particle_InCellIndex cParticle_I;
-		Particle_Index dParticle_I;
-
-		Journal_Printf( swarmStream, "\t\tcellParticleTbl[%u][0-%u]:\n", cell_I, self->cellParticleCountTbl[cell_I] );
-		for( cParticle_I = 0; cParticle_I < self->cellParticleCountTbl[cell_I]; cParticle_I++ ) {
-			dParticle_I = self->cellParticleTbl[cell_I][cParticle_I];
-			Journal_Printf( swarmStream, "\t\t\t(part. index) %d\n", dParticle_I );
-		}
-		Journal_Printf( swarmStream, "\n" );
-	}
-	Journal_Printf( swarmStream, "\t}\n" );
-	Journal_Printf( swarmStream, "\tparticlesArraySize: %d\n", self->particlesArraySize );
-	Journal_Printf( swarmStream, "\tparticlesArrayDelta: %d\n", self->particlesArrayDelta );
-	Journal_Printf( swarmStream, "\textraParticlesFactor: %.3g\n", self->extraParticlesFactor );
-
-	if ( self->ics ) {
-		Stg_Class_Print( self->ics, stream );
-	}
-	else {
-		Journal_Printf( stream, "\tics: (null)... not provided (may be Operator type)\n" );
-	}
-}
-
-
-void* _Swarm_Copy( const void* swarm, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Swarm*		self = (Swarm*)swarm;
-	Swarm*		newSwarm;
-	PtrMap*		map = ptrMap;
-	Bool		ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newSwarm = (Swarm*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
-	PtrMap_Append( map, self, newSwarm );
-	
-	newSwarm->myRank = self->myRank;
-	newSwarm->nProc = self->nProc;
-	newSwarm->comm = self->comm;
-	newSwarm->cellLocalCount = self->cellLocalCount;
-	newSwarm->cellDomainCount = self->cellDomainCount;
-	newSwarm->cellShadowCount = self->cellShadowCount;
-	newSwarm->cellParticleTblDelta = self->cellParticleTblDelta;
-	newSwarm->particleLocalCount = self->particleLocalCount;
-	newSwarm->particlesArraySize = self->particlesArraySize;
-	newSwarm->particlesArrayDelta = self->particlesArrayDelta;
-	newSwarm->extraParticlesFactor = self->extraParticlesFactor;
-	
-	if( self->shadowTablesBuilt ){
-		newSwarm->shadowParticleCount = self->shadowParticleCount;
-	}
-
-	if( deep ) {
-		/* Classes */
-		newSwarm->cellLayout = (CellLayout*)Stg_Class_Copy( self->cellLayout, NULL, deep, nameExt, map );
-		newSwarm->particleLayout = (ParticleLayout*)Stg_Class_Copy( self->particleLayout, NULL, deep, nameExt, map );
-		newSwarm->debug = (Stream*)Stg_Class_Copy( self->debug, NULL, deep, nameExt, map );
-		newSwarm->particleExtensionMgr = (ExtensionManager*)Stg_Class_Copy( self->particleExtensionMgr, NULL, deep, nameExt, map );
-		newSwarm->commHandlerList = (Stg_ObjectList*)Stg_Class_Copy( self->commHandlerList, NULL, deep, nameExt, map );
-		
-		/* Arrays */
-		if( (newSwarm->cellPointCountTbl = (Cell_PointIndex*)PtrMap_Find( map, self->cellPointCountTbl )) == NULL ) {
-			if( self->cellPointCountTbl ) {
-				newSwarm->cellPointCountTbl = Memory_Alloc_Array( Cell_PointIndex, newSwarm->cellDomainCount, "Swarm->cellPointCountTbl" );
-				memcpy( newSwarm->cellPointCountTbl, self->cellPointCountTbl, newSwarm->cellDomainCount * sizeof( Cell_PointIndex ) );
-				PtrMap_Append( map, self->cellPointCountTbl, newSwarm->cellPointCountTbl );
-			}
-			else {
-				newSwarm->cellPointCountTbl = NULL;
-			}
-		}
-		
-		if( (newSwarm->cellPointTbl = (double****)PtrMap_Find( map, self->cellPointTbl )) == NULL ) {
-			if( newSwarm->cellPointCountTbl && self->cellPointTbl ) {
-				Index	cell_I;
-				
-				newSwarm->cellPointTbl = Memory_Alloc_2DComplex( Cell_Point, newSwarm->cellDomainCount, newSwarm->cellPointCountTbl, "Swarm->cellPointTbl" );
-				for( cell_I = 0; cell_I < newSwarm->cellDomainCount; cell_I++ ) {
-					memcpy( newSwarm->cellPointTbl[cell_I], self->cellPointTbl[cell_I], newSwarm->cellPointCountTbl[cell_I] * sizeof(Cell_Point) );
-				}
-				PtrMap_Append( map, self->cellPointTbl, newSwarm->cellPointTbl );
-			}
-			else {
-				newSwarm->cellPointTbl = NULL;
-			}
-		}
-		
-		if( (newSwarm->cellParticleCountTbl = (Particle_InCellIndex*)PtrMap_Find( map, self->cellParticleCountTbl )) == NULL ) {
-			if( self->cellParticleCountTbl ) {
-				newSwarm->cellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, newSwarm->cellDomainCount, "Swarm->cellParticleCountTbl" );
-				memcpy( newSwarm->cellParticleCountTbl, self->cellParticleCountTbl, newSwarm->cellDomainCount * sizeof( Particle_InCellIndex ) );
-				PtrMap_Append( map, self->cellParticleCountTbl, newSwarm->cellParticleCountTbl );
-			}
-			else {
-				newSwarm->cellParticleCountTbl = NULL;
-			}
-		}
-		
-		if( (newSwarm->cellParticleSizeTbl = (Particle_InCellIndex*)PtrMap_Find( map, self->cellParticleSizeTbl )) == NULL ) {
-			if( self->cellParticleSizeTbl ) {
-				newSwarm->cellParticleSizeTbl = Memory_Alloc_Array( Particle_InCellIndex, newSwarm->cellDomainCount, "Swarm->cellParticleSizeTbl" );
-				memcpy( newSwarm->cellParticleSizeTbl, self->cellParticleSizeTbl, newSwarm->cellDomainCount * sizeof( Particle_InCellIndex ) );
-				PtrMap_Append( map, self->cellParticleSizeTbl, newSwarm->cellParticleSizeTbl );
-			}
-			else {
-				newSwarm->cellParticleSizeTbl = NULL;
-			}
-		}
-		
-		if( (newSwarm->cellParticleTbl = (Particle_Index**)PtrMap_Find( map, self->cellParticleTbl )) == NULL ) {
-			if( newSwarm->cellParticleCountTbl && self->cellParticleTbl ) {
-				Index	cell_I;
-				
-				newSwarm->cellParticleTbl = Memory_Alloc_Array( Cell_Particles, newSwarm->cellDomainCount, "Swarm->cellParticleTbl" );
-				for( cell_I = 0; cell_I < newSwarm->cellDomainCount; cell_I++ ) {
-					if( newSwarm->cellParticleCountTbl[cell_I] ) {
-						newSwarm->cellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, newSwarm->cellParticleCountTbl[cell_I], "Swarm->cellParticleTbl[]" );
-						memcpy( newSwarm->cellParticleTbl[cell_I], self->cellParticleTbl[cell_I], newSwarm->cellParticleCountTbl[cell_I] * sizeof(Particle_Index) );
-					}
-					else {
-						newSwarm->cellParticleTbl[cell_I] = NULL;
-					}
-				}
-				PtrMap_Append( map, self->cellParticleTbl, newSwarm->cellParticleTbl );
-			}
-			else {
-				newSwarm->cellParticleTbl = NULL;
-			}
-		}
-		
-		if( (newSwarm->particles = (Particle*)PtrMap_Find( map, self->particles )) == NULL ) {
-			if( self->particles ) {
-				newSwarm->particles = (Particle_List)ExtensionManager_Malloc( newSwarm->particleExtensionMgr, newSwarm->particlesArraySize );
-				memcpy( newSwarm->particles, self->particles, newSwarm->particlesArraySize * ExtensionManager_GetFinalSize( newSwarm->particleExtensionMgr ) );
-				PtrMap_Append( map, self->particles, newSwarm->particles );
-			}
-			else {
-				newSwarm->particles = NULL;
-			}
-		}
-
-		/*shadow info*/
-		if( self->shadowTablesBuilt ){
-
-                  if( (newSwarm->shadowCellParticleCountTbl = (Particle_InCellIndex*)PtrMap_Find( map, self->shadowCellParticleCountTbl )) == NULL ) {
-				if( self->shadowCellParticleCountTbl ) {
-					newSwarm->shadowCellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, newSwarm->cellDomainCount, "Swarm->shadowCellParticleCountTbl" );
-					memcpy( newSwarm->shadowCellParticleCountTbl, self->shadowCellParticleCountTbl, newSwarm->cellDomainCount * sizeof( Particle_InCellIndex ) );
-					PtrMap_Append( map, self->shadowCellParticleCountTbl, newSwarm->shadowCellParticleCountTbl );
-				}
-				else {
-					newSwarm->shadowCellParticleCountTbl = NULL;
-				}
-			}
-		
-                  if( (newSwarm->shadowCellParticleTbl = (Particle_Index**)PtrMap_Find( map, self->shadowCellParticleTbl )) == NULL ) {
-				if( newSwarm->shadowCellParticleCountTbl && self->shadowCellParticleTbl ) {
-					Index	cell_I;
-				
-					newSwarm->shadowCellParticleTbl = Memory_Alloc_Array( Cell_Particles, newSwarm->cellDomainCount, "Swarm->shadowCellParticleTbl" );
-					for( cell_I = 0; cell_I < newSwarm->cellDomainCount; cell_I++ ) {
-						if( newSwarm->shadowCellParticleCountTbl[cell_I] ) {
-							newSwarm->shadowCellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, newSwarm->shadowCellParticleCountTbl[cell_I],
-									"Swarm->shadowCellParticleTbl[]" );
-							memcpy( newSwarm->shadowCellParticleTbl[cell_I], self->shadowCellParticleTbl[cell_I],
-									newSwarm->shadowCellParticleCountTbl[cell_I] * sizeof(Particle_Index) );
-						}
-						else {
-							newSwarm->shadowCellParticleTbl[cell_I] = NULL;
-						}
-					}
-					PtrMap_Append( map, self->shadowCellParticleTbl, newSwarm->shadowCellParticleTbl );
-				}
-				else {
-					newSwarm->shadowCellParticleTbl = NULL;
-				}
-			}
-		
-                  if( (newSwarm->shadowParticles = (Particle*)PtrMap_Find( map, self->shadowParticles )) == NULL ) {
-				if( self->shadowParticles ) {
-					newSwarm->shadowParticles = (Particle_List)ExtensionManager_Malloc( newSwarm->particleExtensionMgr, newSwarm->shadowParticleCount);
-					memcpy( newSwarm->shadowParticles, self->shadowParticles,
-							newSwarm->shadowParticleCount* ExtensionManager_GetFinalSize( newSwarm->particleExtensionMgr ) );
-					PtrMap_Append( map, self->shadowParticles, newSwarm->shadowParticles );
-				}
-				else {
-					newSwarm->shadowParticles = NULL;
-				}
-			}		
-		}
-
-		newSwarm->ics = self->ics ? (VariableCondition*)Stg_Class_Copy( self->ics, NULL, deep, nameExt, map ) : NULL;
-	}
-	else {
-		newSwarm->cellLayout = self->cellLayout;
-		newSwarm->particleLayout = self->particleLayout;
-		newSwarm->debug = self->debug;
-		newSwarm->cellPointTbl = self->cellPointTbl;
-		newSwarm->cellPointCountTbl = self->cellPointCountTbl;
-		newSwarm->cellParticleTbl = self->cellParticleTbl;
-		newSwarm->cellParticleCountTbl = self->cellParticleCountTbl;
-		newSwarm->cellParticleSizeTbl = self->cellParticleSizeTbl;
-		newSwarm->particles = self->particles;
-
-		newSwarm->shadowCellParticleTbl = self->shadowCellParticleTbl;
-		newSwarm->shadowCellParticleCountTbl = self->shadowCellParticleCountTbl;
-		newSwarm->shadowParticles = self->shadowParticles;
-
-		newSwarm->particleExtensionMgr = self->particleExtensionMgr;
-		newSwarm->commHandlerList = self->commHandlerList;
-
-		newSwarm->ics = self->ics;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newSwarm;
-}
-
-void* _Swarm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                _sizeOfSelf = sizeof(Swarm);
-	Type                                                        type = Swarm_Type;
-	Stg_Class_DeleteFunction*                                _delete = _Swarm_Delete;
-	Stg_Class_PrintFunction*                                  _print = _Swarm_Print;
-	Stg_Class_CopyFunction*                                    _copy = _Swarm_Copy;
-	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = _Swarm_DefaultNew;
-	Stg_Component_ConstructFunction*                      _construct = _Swarm_AssignFromXML;
-	Stg_Component_BuildFunction*                              _build = _Swarm_Build;
-	Stg_Component_InitialiseFunction*                    _initialise = _Swarm_Initialise;
-	Stg_Component_ExecuteFunction*                          _execute = _Swarm_Execute;
-	Stg_Component_DestroyFunction*                          _destroy = _Swarm_Destroy;
-	SizeT                                               particleSize = sizeof(IntegrationPoint);
-	void*                                                        ics = NULL;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return _Swarm_New(  SWARM_PASSARGS  );			    /* ics_renamed */
-}
-
-void _Swarm_AssignFromXML( void* swarm, Stg_ComponentFactory* cf, void* data ) {
-	Swarm*                  self                     = (Swarm*)swarm;
-   AbstractContext*        context                  = NULL;
-	CellLayout*             cellLayout               = NULL;
-	ParticleLayout*         particleLayout           = NULL;
-	void*                   extensionManagerRegister = NULL;
-	double                  extraParticlesFactor     = 0.0;
-	Particle_InCellIndex    cellParticleTblDelta     = 0;
-	Dimension_Index         dim;
-	Type                    particleType;
-	Variable_Register*      variable_Register        = NULL;
-	VariableCondition* 	ic            		 = NULL;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-	
-	particleType = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"ParticleType", IntegrationPoint_Type  );
-	
-	cellLayout =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)CellLayout_Type, CellLayout, True, data  ) ;
-	particleLayout =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)ParticleLayout_Type, ParticleLayout, True, data );
-	
-	extensionManagerRegister = extensionMgr_Register; 
-	assert( extensionManagerRegister );
-	variable_Register = context->variable_Register; 
-	assert( variable_Register  );
-	
-	cellParticleTblDelta = 
-		Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"cellParticleTblDelta", DEFAULT_CELL_PARTICLE_TBL_DELTA );
-	extraParticlesFactor = 
-		Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"extraParticlesFactor", DEFAULT_EXTRA_PARTICLES_FACTOR );
-	
-	{
-		unsigned int count = 0;
-		unsigned i = 0;
-		Stg_Component **components = NULL;
-
-		components = (Stg_Component** )Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"ParticleCommHandlers", Stg_ComponentFactory_Unlimited, ParticleCommHandler, False, &count, data );
-
-		if( count == 0  ){
- 			Journal_Printf( self->debug, "Warning: Swarm has 0 Communication handlers..!\n" );
- 		}
- 		else{
- 			for( i=0; i<count; i++ ){
- 				Stg_ObjectList_Append( self->commHandlerList, components[i] );
- 			}
- 			Memory_Free( components );
-		}
-	}
-
-	/* construct the variable condition IC */
-	ic = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IC", VariableCondition, False, data  );
-	
-	_Swarm_Init( 
-			self, context,
-			cellLayout,
-			particleLayout, 
-			dim,
-         sizeof(IntegrationPoint),
-			cellParticleTblDelta,
-			extraParticlesFactor,
-			(ExtensionManager_Register*)extensionManagerRegister,
-			variable_Register,
-			context->communicator,
-			ic );
-}
-
-
-void _Swarm_Build( void* swarm, void* data ) {
-	Swarm* self = (Swarm*)swarm;
-	AbstractContext* context = self->context;
-	
-	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\" (of type %s)\n", __func__, self->name, self->type ); 
-	Stream_IndentBranch( Swarm_Debug );
-
-	Stg_Component_Build( self->cellLayout, data, False );
-	Stg_Component_Build( self->particleLayout, data, False );
-	
-	Journal_DPrintf( self->debug, "allocating memory for cell->particle mappings:\n" );
-	_Swarm_BuildCells( self, data );
-	Journal_DPrintf( self->debug, "...done.\n" );
-
-	/* if loading from checkpoint, then delete the particle layout
-	 * created due to the user's specification in the input file,
-	 * and replace it with a FileParticleLayout, so that the particles
-	 * can be re-loaded with their exact state at the checkpointed time
-	 */
-	if ( context && context->loadFromCheckPoint ) {
-		Journal_DPrintf( self->debug, "detected loadFromCheckPoint mode enabled:\n" );
-		Stream_Indent( self->debug );
-
-		if ( False == self->isSwarmTypeToCheckPointAndReload ) {
-			Journal_DPrintf( self->debug, "...but this swarm type is set to not be checkpointed/reloaded, "
-				"so continuing.\n" );
-		}
-		else {
-			Swarm_ReplaceCurrentParticleLayoutWithFileParticleLayout( self, context );
-		}	
-		Stream_UnIndent( self->debug );
-	}
-	
-	Journal_DPrintf( self->debug, "allocating memory for particles:\n" );
-	_Swarm_BuildParticles( self, data );
-	Journal_DPrintf( self->debug, "...done.\n" );
-
-	Journal_DPrintf( self->debug, "setting up the particle owningCell SwarmVariable:\n" );
-	Stg_Component_Build( self->owningCellVariable, data, False );
-	Journal_DPrintf( self->debug, "...done.\n" );
-	
-	Stream_UnIndentBranch( Swarm_Debug );
-	Journal_DPrintf( self->debug, "...done in %s().\n", __func__ );
-
-	if( self->ics && !(context && (True == context->loadFromCheckPoint) ) ) {
-		Stg_Component_Build( self->ics, data, False );
-	}
-}
-
-			
-void _Swarm_Initialise( void* swarm, void* data ) {
-	Swarm* self = (Swarm*)swarm;
-
-	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\" (of type %s)\n", __func__, self->name, self->type ); 
-	Stream_IndentBranch( Swarm_Debug );
-   Stg_Component_Initialise( self->owningCellVariable, data, False );
-
-	_Swarm_InitialiseCells( self, data );
-	_Swarm_InitialiseParticles( self, data );
-	
-	if( self->ics ) {
-		Journal_DPrintf( self->debug, "applying the ICs for this swarm.\n" );
-		Stream_Indent( self->debug );
-		Stg_Component_Initialise( self->ics, data, False );
-		/* call the initial conditions plugin here */
-		VariableCondition_Apply( self->ics, data );
-	}
-
-   self->stillDoingInitialisation = False;  /* this needs to go after the _Swarm_InitialiseParticles call */
-	
-	Stream_UnIndentBranch( Swarm_Debug );
-   
-   Journal_DPrintf( self->debug, "...done in %s().\n", __func__ );
-
-}
-
-
-void _Swarm_Execute( void* swarm, void* data ) {
-}
-
-void _Swarm_Destroy( void* swarm, void* data ) {
-	Swarm* self = (Swarm*)swarm;
-   Cell_LocalIndex cell_I;
-
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		if( self->cellParticleTbl[cell_I] ){
-			Memory_Free( self->cellParticleTbl[cell_I] );
-		}
-
-		if(self->shadowTablesBuilt){
-			if( self->shadowCellParticleTbl[cell_I] ){
-				Memory_Free( self->shadowCellParticleTbl[cell_I] );
-			}
-		}
-	}
-
-	if( self->shadowTablesBuilt ){
-		Memory_Free( self->shadowCellParticleTbl );
-		Memory_Free( self->shadowCellParticleCountTbl );
-		if ( self->shadowParticles ) {
-			ExtensionManager_Free( self->particleExtensionMgr, self->shadowParticles );
-		}
-	}
-
-	Memory_Free( self->cellParticleTbl );
-	Memory_Free( self->cellParticleCountTbl );
-	Memory_Free( self->cellParticleSizeTbl );
-	if ( self->particles ) {
-		ExtensionManager_Free( self->particleExtensionMgr, self->particles );
-	}
-	if(self->owningCellVariable)
-		Stg_Component_Destroy(self->owningCellVariable, data, False );
-
- //  Stg_ObjectList_DeleteAllObjects( self->commHandlerList );
-	Stg_Class_Delete( self->commHandlerList );
-
-	FreeArray( self->swarmVars );
-
-	Memory_Free( self->cellPointTbl );
-	Memory_Free( self->cellPointCountTbl );
-
-	/* Delete SwarmVariable_Register if it has been created */
-	if ( self->swarmVariable_Register ) {
-		Stg_Class_Delete( self->swarmVariable_Register );
-	}
-
-	NewClass_Delete( self->incArray );
-
-	Swarm_Register_RemoveIndex( Swarm_Register_GetSwarm_Register(), self->swarmReg_I );
-
-
-
-
-}
-
-void _Swarm_BuildCells( void* swarm, void* data ) {
-	Swarm*			self = (Swarm*)swarm;
-	Cell_Index		cell_I;
-	Cell_PointIndex		pointCount;
-	
-	/* Need to do this first - as the cellLayout may be dependent on a mesh etc */
-	Stg_Component_Build( self->cellLayout, data, False );
-
-	Journal_DPrintf( self->debug, "In %s():\n", __func__ ); 
-	Stream_IndentBranch( Swarm_Debug );
-
-	self->cellLocalCount = CellLayout_CellLocalCount( self->cellLayout );
-	self->cellShadowCount = CellLayout_CellShadowCount( self->cellLayout );
-	self->cellDomainCount = self->cellLocalCount + self->cellShadowCount;
-
-	Journal_DPrintf( self->debug, "CellLayout \"%s\" (of type %s) returned cell counts of:\n"
-		"cellLocalCount: %u, cellShadowCount: %u, cellDomainCount: %u",
-		self->cellLayout->name, self->cellLayout->type,
-		self->cellLocalCount, self->cellShadowCount, self->cellDomainCount );
-
-	self->cellPointCountTbl = Memory_Alloc_Array( Cell_PointIndex, self->cellDomainCount, "Swarm->cellPointCountTbl" );
-	pointCount = 0;
-
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		self->cellPointCountTbl[cell_I] = CellLayout_PointCount( self->cellLayout, cell_I );
-		pointCount += self->cellPointCountTbl[cell_I];
-	}
-
-	self->cellPointTbl = Memory_Alloc_2DComplex( Cell_Point, self->cellDomainCount, self->cellPointCountTbl, "Swarm->cellPointTbl" );
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void _Swarm_BuildParticles( void* swarm, void* data ) {
-	Swarm*			self = (Swarm*)swarm;
-	
-	/* Need to do this first - as the particleLayout may be dependent on a mesh etc */
-	Stg_Component_Build( self->particleLayout, data, False );
-
-	self->cellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, self->cellDomainCount,
-		"Swarm->cellParticleCountTbl" );
-	self->cellParticleSizeTbl = Memory_Alloc_Array( Particle_InCellIndex, self->cellDomainCount,
-		"Swarm->cellParticleSizeTbl" );
-	self->cellParticleTbl = Memory_Alloc_Array( Cell_Particles, self->cellDomainCount, "Swarm->cellParticleTbl" ); 
-	
-	ParticleLayout_SetInitialCounts( self->particleLayout, self );
-	
-	/* Now allocate the particles array */
-	/* We allocate extra space to try & avoid avoid reallocing later as particles are advected etc. */
-	self->particlesArrayDelta = (Particle_Index)( (double) self->particleLocalCount * self->extraParticlesFactor);
-	if ( 0 == self->particlesArrayDelta ) {
-		self->particlesArrayDelta = MINIMUM_PARTICLES_ARRAY_DELTA;		
-	}
-
-	self->particlesArraySize = self->particleLocalCount + self->particlesArrayDelta;
-
-	self->particles = (Particle_List)ExtensionManager_Malloc( self->particleExtensionMgr, self->particlesArraySize );
-}
-
-void _Swarm_BuildShadowParticles( void* swarm ) {
-	Swarm*			self = (Swarm*)swarm;
-	unsigned i = 0;
-	
-	self->shadowTablesBuilt = True;
-
-	self->shadowCellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, self->cellDomainCount,
-		"Swarm->shadowCellParticleCountTbl" );
-	self->shadowCellParticleTbl = Memory_Alloc_Array( Cell_Particles, self->cellDomainCount, "Swarm->shadowCellParticleTbl" );
-	for( i=0; i<self->cellDomainCount; i++ ){
-		self->shadowCellParticleTbl[i] = NULL;
-	}
-	
-	self->shadowParticles = NULL;
-}
-
-void _Swarm_InitialiseCells( void* swarm, void* data ) {
-	Swarm*			self = (Swarm*)swarm;
-	Cell_Index		cell_I;
-	
-	/* Need to do this first - as the cellLayout may be dependent on a mesh etc */
-	Stg_Component_Initialise( self->cellLayout, data, False );
-
-	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
-		CellLayout_InitialiseCellPoints( self->cellLayout, cell_I, self->cellPointCountTbl[cell_I], 
-			self->cellPointTbl[cell_I] );
-	}
-}
-
-
-void _Swarm_InitialiseParticles( void* swarm, void* data ) {
-	Swarm*			self = (Swarm*)swarm;
-	
-	/* Need to do this first - as the particleLayout may be dependent on a mesh etc */
-	Stg_Component_Initialise( self->particleLayout, data, False );
-
-	ParticleLayout_InitialiseParticles( self->particleLayout, self );
-
-	/* Need to re-do the delta calculation here, since if using a global particle layouts, we didn't know the 
-	 * localParticleCount until the above call, and had just used a default delta. We can now calculate the
-	 * correct one. */
-	self->particlesArrayDelta = (Particle_Index)( (double) self->particleLocalCount * self->extraParticlesFactor);
-	if ( 0 == self->particlesArrayDelta ) {
-		self->particlesArrayDelta = MINIMUM_PARTICLES_ARRAY_DELTA;		
-	}
-
-	Swarm_UpdateAllParticleOwners( self );
-}
-
-
-/** This function assmes particle advection and hence global coords are used */
-void Swarm_UpdateAllParticleOwners( void* swarm ) {
-	Swarm*			self = (Swarm*)swarm;
-	Particle_Index		lParticle_I;
-	Progress*		prog;
-
-	/* TODO: need to reconsideer - gauss particle layout should be allowed, but not swarms that have no local
-	 * co-ordinates */
-	if ( self->particleLayout->coordSystem == LocalCoordSystem ) {
-		/* Assumption: Local coord layouts don't go through advection so no need to update */
-		return;
-	}
-
-	prog = Progress_New();
-	Progress_SetTitle( prog, "Updating particle owners" );
-	Progress_SetPrefix( prog, "\t" );
-	Progress_SetRange( prog, 0, self->particleLocalCount );
-	Progress_Update( prog );
-	
-	Journal_DPrintfL( self->debug, 1, "In %s() for Swarm \"%s\"\n", __func__, self->name );
-	Stream_IndentBranch( Swarm_Debug );	
-	for ( lParticle_I=0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
-		Swarm_UpdateParticleOwner( self, lParticle_I );
-		Progress_Increment( prog );
-	}
-
-	Stg_Class_Delete( prog );
-
-	/* UpdateAllParticleOwners is called during initialisation,to set up initial
-	 * ownership relationships, and if that's the case we don't want to invoke
-	 * the ParticleCommHandler since we know there's been no movement between
-	 * processors yet. */
-	if ( False == self->stillDoingInitialisation ) { 
-		/*Stg_Component_Execute( self->particleCommunicationHandler[0], NULL, True );
-		Stg_Component_Execute( self->particleCommunicationHandler[1], NULL, True );*/
-		{
-			unsigned ii;
-			for( ii=0; ii<self->commHandlerList->count; ii++ ){
-				ParticleCommHandler *pComm = NULL;
-
-				pComm = (ParticleCommHandler*)(Stg_ObjectList_At(self->commHandlerList, ii));
-				Stg_Component_Execute( pComm, self, True);
-			}
-		}
-	}
-
-	Stream_UnIndentBranch( Swarm_Debug );
-}
-
-
-void Swarm_UpdateParticleOwner( void* swarm, Particle_Index particle_I ) {
-	Swarm* 			self           = (Swarm*)swarm;
-	GlobalParticle*	        particle       = (GlobalParticle*) Swarm_ParticleAt( self, particle_I );
-	Cell_DomainIndex	newOwningCell;
-	Particle_InCellIndex	cParticle_I;
-	Coord*			coordPtr       = &particle->coord;
-
-	Journal_DPrintfL( self->debug, 3, "In %s: for particle %d, old cell %d\n", __func__,
-		particle_I, particle->owningCell );
-	Stream_Indent( self->debug );	
-	
-	Journal_DPrintfL( self->debug, 3, "updated coord (%f,%f,%f) is: ", (*coordPtr)[0], (*coordPtr)[1], (*coordPtr)[2] );
-
-	newOwningCell = CellLayout_CellOf( self->cellLayout, particle );
-
-	if ( newOwningCell == particle->owningCell ) {
-		Journal_DPrintfL( self->debug, 3, "still in same cell.\n" );
-	}
-	else {
-		Cell_LocalIndex		oldOwningCell = particle->owningCell;
-
-		Journal_DPrintfL( self->debug, 3, "in new cell %d.\n", newOwningCell );
-		cParticle_I = Swarm_GetParticleIndexWithinCell( self, particle->owningCell, particle_I );
-		Swarm_RemoveParticleFromCell( self, oldOwningCell, cParticle_I );
-	
-		/* if new cell is in my domain, add entry to new cell's table */
-		if ( newOwningCell == self->cellDomainCount ) {
-			Journal_DPrintfL( self->debug, 3, "New cell == domain count -> Particle has moved outside domain.\n" );
-			particle->owningCell = self->cellDomainCount;
-		}	
-		#ifdef CAUTIOUS
-		else if ( newOwningCell >= self->cellDomainCount ) {	
-			Stream*    errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-			Journal_Firewall( 0, errorStream,
-				"Error - in %s(): particle %u's new domain cell calculated as "
-				"%u, but this is greater than the count of domain cells %u. "
-				"Something has gone wrong.\n",
-				__func__, particle_I, newOwningCell, self->cellDomainCount );
-		}		
-		#endif
-		else {
-			Swarm_AddParticleToCell( self, newOwningCell, particle_I );
-		}
-	}
-	Stream_UnIndent( self->debug );	
-}
-
-
-void Swarm_RemoveParticleFromCell( void* swarm, Cell_DomainIndex dCell_I, Particle_InCellIndex cParticle_I ) {
-	Swarm* 			self = (Swarm*)swarm;
-	Particle_InCellIndex*	sizePtr = &self->cellParticleSizeTbl[dCell_I];
-	Particle_InCellIndex*	countPtr = &self->cellParticleCountTbl[dCell_I];
-
-	Journal_DPrintfL( self->debug, 3, "Removing PIC %d from cell %d: particle count now %d",
-		cParticle_I, dCell_I, (*countPtr)-1 );
-	self->cellParticleTbl[dCell_I][cParticle_I] = self->cellParticleTbl[dCell_I][*countPtr-1];
-	(*countPtr)--;
-	if ( *countPtr == (*sizePtr - self->cellParticleTblDelta) ) {
-		Journal_DPrintfL( self->debug, 3, " - (reducing entries alloced to %d)", (*countPtr) );
-		(*sizePtr) = *countPtr;
-		self->cellParticleTbl[dCell_I] = Memory_Realloc_Array( self->cellParticleTbl[dCell_I],
-			Particle_Index, *sizePtr );
-	}
-	Journal_DPrintfL( self->debug, 3, "\n" );
-}
-
-
-void Swarm_DeleteParticle( void* swarm, Particle_Index particleToDelete_lI ) {
-	Swarm* 			self = (Swarm*)swarm;
-	Particle_InCellIndex    cParticle_I = 0;
-	Particle_Index          lastParticle_I = 0;
-	GlobalParticle*         lastParticle = NULL;	
-	GlobalParticle*         particleToDelete = NULL;	
-	SizeT                   particleSize = self->particleExtensionMgr->finalSize;
-	Stream*                 errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-	Journal_Firewall( particleToDelete_lI < self->particleLocalCount, errorStr,
-		"Error- in %s(): particleToDelete_lI passed in (%u) is >= swarm's local particle count %u.\n",
-		__func__, particleToDelete_lI, self->particleLocalCount );
-
-	particleToDelete = (GlobalParticle*)Swarm_ParticleAt( self, particleToDelete_lI );
-	cParticle_I = Swarm_GetParticleIndexWithinCell( self, particleToDelete->owningCell, particleToDelete_lI );
-
-	Swarm_RemoveParticleFromCell( self, particleToDelete->owningCell, cParticle_I );
-
-	lastParticle_I = self->particleLocalCount - 1;
-	lastParticle   = (GlobalParticle*)Swarm_ParticleAt( self, lastParticle_I );
-
-	/* In the current data structure for particles (a regular array), if we delete a particle we need to "swap"
-	 * the 'last' particle into the hole we just created, and update it's cell's reference to it.
-	 * The only special case is if the particle we are deleting happens to be the last particle, in which case
-	 * no swap is necessary. */ 
-	if ( particleToDelete_lI != lastParticle_I ) {
-		/* Get last Particle information */
-		Cell_Index            lastParticle_CellIndex       = lastParticle->owningCell;
-		Particle_InCellIndex  lastParticle_IndexWithinCell = 0;
-		
-		lastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( self, lastParticle_CellIndex, lastParticle_I);
-
-		Journal_DPrintfL( self->debug, 2, 
-				"Copying over particle %u using last particle %u from cell %u (cell particle index - %u)\n", 
-				particleToDelete_lI, lastParticle_I, lastParticle_CellIndex, lastParticle_IndexWithinCell );
-
-		/* Copy over particle */
-		memcpy( particleToDelete, lastParticle, particleSize );
-			
-		/* Change value in cell particle table to point to new index in array */
-		self->cellParticleTbl[lastParticle_CellIndex][ lastParticle_IndexWithinCell ] = particleToDelete_lI;
-	}
-
-	/* Re-set memory at location of last particle to zero so it is clear that it's been deleted */
-	memset( lastParticle, 0, particleSize );
-
-	self->particleLocalCount--;
-	/* Call the memory management function in case we need to re-allocate the swarm size smaller now */
-	Swarm_Realloc( swarm );
-}
-
-
-void Swarm_DeleteParticleAndReplaceWithNew( void* swarm, Particle_Index particleToDelete_lI,
-		void* replacementParticle, Cell_Index replacementParticle_cellIndex )
-{
-	Swarm* 			self = (Swarm*)swarm;
-	Particle_InCellIndex    cParticle_I = 0;
-	GlobalParticle*         particleToDelete = NULL;	
-	Stream*                 errorStr = Journal_Register( Error_Type, (Name)self->type  );
-	
-	Journal_Firewall( particleToDelete_lI < self->particleLocalCount, errorStr,
-		"Error- in %s(): particleToDelete_lI passed in (%u) is >= swarm's local particle count %u.\n",
-		__func__, particleToDelete_lI, self->particleLocalCount );
-
-	particleToDelete = (GlobalParticle*)Swarm_ParticleAt( self, particleToDelete_lI );
-	cParticle_I = Swarm_GetParticleIndexWithinCell( self, particleToDelete->owningCell, particleToDelete_lI );
-
-	Swarm_RemoveParticleFromCell( self, particleToDelete->owningCell, cParticle_I );
-
-	Journal_DPrintfL( self->debug, 2, 
-		"Copying over particle %u using replacement particle, and adding it to cell %u\n", 
-		particleToDelete_lI, replacementParticle_cellIndex );
-
-	/* Copy over particle to delete with it's replacement */
-	memcpy( particleToDelete, replacementParticle, self->particleExtensionMgr->finalSize );
-			
-	/* Add a reference to replacement particle in appropriate cell entry */
-	Swarm_AddParticleToCell( self, replacementParticle_cellIndex, particleToDelete_lI );
-}
-
-
-void Swarm_AddParticleToCell( void* swarm, Cell_DomainIndex dCell_I, Particle_Index particle_I ) {
-	Swarm* 			self = (Swarm*)swarm;
-	Particle_InCellIndex*	newCountPtr = &self->cellParticleCountTbl[dCell_I];
-	Particle_InCellIndex*	newSizePtr = &self->cellParticleSizeTbl[dCell_I];
-	#ifdef CAUTIOUS
-	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
-	#endif
-
-	Journal_DPrintfL( self->debug, 3, "Adding particle %d to cell %d: cell's particle count now %d",
-		particle_I, dCell_I, (*newCountPtr)+1 );
-
-	#ifdef CAUTIOUS
-	Journal_Firewall( dCell_I < self->cellDomainCount, errorStream,
-		"Error - in %s(): cannot add particle %u to req. domain cell, since "
-		"dCell_I passed in of %u is greater than the count of domain cells %u.\n",
-		__func__, particle_I, dCell_I, self->cellDomainCount );
-	#endif
-
-	Swarm_ParticleAt( self, particle_I)->owningCell = dCell_I;
-
-	if ( *newCountPtr == *newSizePtr ) {
-		(*newSizePtr) += self->cellParticleTblDelta;
-		Journal_DPrintfL( self->debug, 3, " - (increasing entries alloced to %d)", (*newSizePtr) );
-		self->cellParticleTbl[dCell_I] = Memory_Realloc_Array( self->cellParticleTbl[dCell_I],
-			Particle_Index, (*newSizePtr) );
-	}	
-	self->cellParticleTbl[dCell_I][*newCountPtr] = particle_I;
-	(*newCountPtr)++;
-	Journal_DPrintfL( self->debug, 3, "\n" );
-}
-
-void Swarm_AddShadowParticleToShadowCell( void* swarm, Cell_DomainIndex dCell_I, Particle_Index shadowParticle_I ) {
-	Swarm* 			self = (Swarm*)swarm;
-	
-	if( self->shadowTablesBuilt ){
-		Particle_InCellIndex*	newCountPtr = &self->shadowCellParticleCountTbl[dCell_I-self->cellLocalCount];
-		#ifdef CAUTIOUS
-		Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
-		#endif
-
-		Journal_DPrintfL( self->debug, 3, "Adding shadow particle %d to shadow cell %d: shadow cell's particle count now %d",
-			shadowParticle_I, dCell_I, (*newCountPtr)+1 );
-
-		#ifdef CAUTIOUS
-		Journal_Firewall( dCell_I < self->cellDomainCount, errorStream,
-				"Error - in %s(): cannot add particle %u to req. shadow cell, since "
-			"dCell_I passed in of %u is greater than the count of domain cells %u.\n",
-			__func__, shadowParticle_I, dCell_I, self->cellDomainCount );
-		#endif
-
-		Swarm_ShadowParticleAt( self, shadowParticle_I)->owningCell = dCell_I;
-
-		self->shadowCellParticleTbl[dCell_I][*newCountPtr] = shadowParticle_I;
-		(*newCountPtr)++;
-		Journal_DPrintfL( self->debug, 3, "\n" );
-	}
-}
-
-Particle_InCellIndex Swarm_GetParticleIndexWithinCell( void* swarm, Cell_DomainIndex owningCell, Particle_Index particle_I) {
-	Swarm* 			self = (Swarm*)swarm;
-	Particle_InCellIndex	cParticle_I;
-	Particle_InCellIndex	particleCount = self->cellParticleCountTbl[owningCell];
-
-	/* find the PIC index in the cell */
-	for ( cParticle_I=0; cParticle_I < particleCount; cParticle_I++ ) {
-		if ( particle_I == self->cellParticleTbl[owningCell][cParticle_I] ) break;
-	}	
-	#if DEBUG
-		Journal_Firewall( cParticle_I < self->cellParticleCountTbl[owningCell], Swarm_Error,
-			"Error- In func %s: Particle %u not found among cell %u's %u particles.\n",
-			__func__, particle_I, owningCell, particleCount );
-	#endif
-
-	return cParticle_I;
-}
-
-Particle_Index Swarm_FindClosestParticle( void* _swarm, Dimension_Index dim, double* coord, double *distance) {
-	Swarm*               swarm       = (Swarm*) _swarm;
-	Particle_InCellIndex cParticle_I;
-	Cell_LocalIndex      lCell_I;
-	GlobalParticle       testParticle;
-	double               minDistance;
-	double               distanceToParticle;
-	NeighbourIndex       neighbourCount;
-	NeighbourIndex       neighbour_I;
-	NeighbourIndex*      neighbourList;
-	Particle_Index       closestParticle_I;
-
-	/* Find cell this coordinate is in */
-	memcpy( testParticle.coord, coord, sizeof(Coord) );
-	/* First specify the particle doesn't have an owning cell yet, so as
-	not to confuse the search algorithm */
-	testParticle.owningCell = swarm->cellDomainCount;
-	lCell_I = CellLayout_CellOf( swarm->cellLayout, &testParticle );
-
-	/* Test if this cell is on this processor - if not then bail */
-	if (lCell_I >= swarm->cellLocalCount)
-		return (Particle_Index) -1;
-
-	/* Find Closest Particle in this Cell */
-	cParticle_I = Swarm_FindClosestParticleInCell( swarm, lCell_I, dim, coord, &minDistance );
-
-	/* Convert to Local Particle Index */
-	closestParticle_I = swarm->cellParticleTbl[ lCell_I ][ cParticle_I ];
-
-	/* Find neighbours to this cell - TODO This Assumes ElementCellLayout */
-	Mesh_GetIncidence( ((ElementCellLayout*)swarm->cellLayout)->mesh, (MeshTopology_Dim)dim, lCell_I, (MeshTopology_Dim)dim, swarm->incArray );
-	neighbourCount = IArray_GetSize( swarm->incArray );
-	neighbourList = (NeighbourIndex*)IArray_GetPtr( swarm->incArray );
-
-	/* Loop over neighbours */
-	for ( neighbour_I = 0 ; neighbour_I < neighbourCount ; neighbour_I++ ) {
-		lCell_I = neighbourList[ neighbour_I ];
-
-		if( lCell_I < swarm->cellDomainCount ) {
-			cParticle_I = Swarm_FindClosestParticleInCell( swarm, lCell_I, dim, coord, &distanceToParticle );
-
-			/* Check to see if closest particle in this cell is closest to this coord */
-			if (minDistance > distanceToParticle) {
-				minDistance = distanceToParticle;
-				closestParticle_I = swarm->cellParticleTbl[ lCell_I ][ cParticle_I ];
-			}
-		}
-	}
-
-	/* Return Distance to this particle */
-	if (distance != NULL)
-		*distance = minDistance;
-	return closestParticle_I;
-}
-
-
-Particle_InCellIndex Swarm_FindClosestParticleInCell( void* swarm, Cell_DomainIndex dCell_I, Dimension_Index dim, double* coord, double* distance ) {
-	Swarm*               self                = (Swarm*) swarm;
-	Particle_InCellIndex cParticle_I         = 0;
-	Particle_InCellIndex particle_I          = 0;
-	GlobalParticle*      particle            = NULL;
-	double               minDistance         = HUGE_VAL;
-	double               distanceToParticle;
-
-	/* TODO: need to reconsider - gauss particle layout should be allowed, but not swarms that have no local
-	 * co-ordinates */
-	/*
-	Journal_Firewall(
-		self->particleLayout->coordSystem == GlobalCoordSystem,
-		Journal_MyStream( Error_Type, self ),
-		"Error in %s(), swarm %s:%s is not using a global coord system\n",
-		__func__,
-		self->type,
-		self->name );
-	*/	
-	
-	Journal_Firewall( dCell_I < self->cellDomainCount, Swarm_Error, "Bad Cell_DomainIndex %u.\n", dCell_I );
-
-	/* Loop over particles find closest to vertex */
-	for( cParticle_I = 0 ; cParticle_I < self->cellParticleCountTbl[dCell_I] ; cParticle_I++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleInCellAt( self, dCell_I, cParticle_I );
-
-		/* Calculate distance to particle */
-		distanceToParticle = 
-			(particle->coord[ I_AXIS ] - coord[ I_AXIS ]) * 
-			(particle->coord[ I_AXIS ] - coord[ I_AXIS ]) +
-			(particle->coord[ J_AXIS ] - coord[ J_AXIS ]) * 
-			(particle->coord[ J_AXIS ] - coord[ J_AXIS ]) ;
-
-		if (dim == 3) {
-			distanceToParticle += 
-				(particle->coord[ K_AXIS ] - coord[ K_AXIS ]) * 
-				(particle->coord[ K_AXIS ] - coord[ K_AXIS ]) ;
-		}
-		/* Don't do square root here because it is unnessesary: i.e. a < b <=> sqrt(a) < sqrt(b) */
-			
-		/* Check if this is the closest particle */
-		if (minDistance > distanceToParticle) {
-			particle_I = cParticle_I;
-			minDistance = distanceToParticle;
-		}
-	}
-
-	/* Return Distance to this particle */
-	if (distance != NULL)
-		/* Do square root here in case someone wants to actually use this distance */
-		*distance = sqrt(minDistance);
-
-	return particle_I;
-}
-
-void Swarm_PrintParticleCoords( void* swarm, Stream* stream ) {
-	Swarm* 			self = (Swarm*)swarm;
-	Particle_Index		lParticle_I=0;
-	GlobalParticle*   	currParticle = NULL;
-	double*			coord = NULL;
-	
-	Journal_Printf( stream, "Printing coords of all local processor particles:\n" );
-	
-	Stream_Indent( stream );
-	for ( lParticle_I = 0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
-		currParticle = (GlobalParticle*)Swarm_ParticleAt( self, lParticle_I );
-		coord = currParticle->coord;
-
-		Journal_Printf( stream, "local particle %6d: (%7.5g, %7.5g, %7.5g)\n",
-			lParticle_I, coord[0], coord[1], coord[2] );
-	}
-	Stream_UnIndent( stream );
-}
-
-
-void Swarm_PrintParticleCoords_ByCell( void* swarm, Stream* stream ) {
-	Swarm* 			self = (Swarm*)swarm;
-	Cell_Index		lCell_I=0;
-	Particle_InCellIndex	cParticle_I=0;
-	Particle_Index		lParticle_I=0;
-	GlobalParticle*         currParticle = NULL;
-	double*			coord = NULL;
-	
-	Journal_Printf( stream, "Printing coords of all local particles, cell-by-cell:\n" );
-	
-	Stream_Indent( stream );
-	for ( lCell_I = 0; lCell_I < self->cellLocalCount; lCell_I++ ) {
-		Journal_Printf( stream, "Local Cell %3d:\n", lCell_I );
-		
-		for ( cParticle_I = 0; cParticle_I < self->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-			lParticle_I = self->cellParticleTbl[lCell_I][cParticle_I];
-			currParticle = (GlobalParticle*)Swarm_ParticleAt( self, lParticle_I );
-			coord = currParticle->coord;
-
-			Journal_Printf( stream, "\tpart. InCell %3d (local index %6d): (%7.5g, %7.5g, %7.5g)\n",
-				cParticle_I, lParticle_I, coord[0], coord[1], coord[2] );
-		}		
-	}
-	Stream_UnIndent( stream );
-}
-
-
-void Swarm_GetCellMinMaxCoords( void* swarm, Cell_DomainIndex cell_I, Coord min, Coord max ) {
-	Swarm*              self     =  (Swarm*) swarm;
-	Dimension_Index		  dim_I;
-	unsigned                 dim      = self->dim;
-	Cell_PointIndex		  cPoint_I;
-	double*             currCoord;
-
-	for ( dim_I = 0; dim_I < dim; dim_I++ ) {
-		min[dim_I] = (*self->cellPointTbl[cell_I][0])[dim_I];
-		max[dim_I] = (*self->cellPointTbl[cell_I][0])[dim_I];
-	}
-
-	for ( cPoint_I = 1; cPoint_I < self->cellPointCountTbl[cell_I]; cPoint_I++ ) {
-		for ( dim_I = 0; dim_I < dim; dim_I++ ) {
-			currCoord = (*self->cellPointTbl[cell_I][cPoint_I]);
-			if ( currCoord[dim_I] < min[dim_I] ) {
-				min[dim_I] = currCoord[dim_I];
-			}
-			else if ( currCoord[dim_I] > max[dim_I] ) {
-				max[dim_I] = currCoord[dim_I];
-			}
-		}
-	}
-}
-
-
-
-SwarmVariable* Swarm_NewScalarVariable( 
-		void*                           swarm,
-		Name                            nameExt,
-		SizeT                           dataOffset,
-		Variable_DataType               dataType )
-{
-	Swarm*                   self              = (Swarm*) swarm;
-	char*                    name;
-	Variable*                variable;
-	SizeT                    dataOffsets[]     = { 0 };		/* Init value later */
-	Variable_DataType        dataTypes[]       = { (Variable_DataType)0 };		/* Init value later */
-	Index                    dataTypeCounts[]  = { 1 };
-	SwarmVariable*           swarmVariable;
-	Variable_Register*       variable_Register      = NULL;
-	SwarmVariable_Register*  swarmVariable_Register = NULL;
-
-	Journal_Firewall(
-		dataOffset < ExtensionManager_GetFinalSize( self->particleExtensionMgr ),
-		Journal_MyStream( Error_Type, self ),
-		"Error in func %s - Failed to create Variable from extension: data offset within particle structure provided was invalid.\n"
-		"\t%s %s\n"
-		"\tdataOffset = %d, particle size = %d\n",
-		__func__,
-		self->type,
-		self->name,
-		dataOffset,
-		ExtensionManager_GetFinalSize( self->particleExtensionMgr ) );
-		
-	dataOffsets[0] = dataOffset;
-	dataTypes[0]   = dataType;
-	
-	/* Get Pointers To Registers */
-	swarmVariable_Register = self->swarmVariable_Register;
-	if ( swarmVariable_Register ) 
-		variable_Register = swarmVariable_Register->variable_Register;
-	
-	name = Stg_Object_AppendSuffix( self, (Name)nameExt  );
-	variable = Variable_New( 
-		name,
-		self->context,
-		1, 
-		dataOffsets, 
-		dataTypes, 
-		dataTypeCounts, 
-		0, /* no component names */
-		&self->particleExtensionMgr->finalSize,
-		&self->particleLocalCount,
-		NULL,
-		(void**)&self->particles,
-		variable_Register );
-
-	swarmVariable = SwarmVariable_New( name, self->context, self, variable, 1 );
-   /* set variable to be checkpointed */
-	swarmVariable->isCheckpointedAndReloaded = True;
-
-	Memory_Free( name );
-
-	return swarmVariable;
-}
-
-SwarmVariable* Swarm_NewVectorVariable( 
-		void*                           _swarm,
-		Name                            nameExt,
-		SizeT                           dataOffset,
-		Variable_DataType               dataType,
-		Index                           dataTypeCount,
-		...                         /* vector component names */ )
-{
-	Swarm*                   self             = (Swarm*) _swarm;
-	Variable*                variable;
-	SizeT                    dataOffsets[]    = { 0 };	/* Init later... */
-	Variable_DataType	     dataTypes[]      = { (Variable_DataType)0 };	/* Init later... */	
-	Index                    dataTypeCounts[] = { 0 };	/* Init later... */	
-	char**                   dataNames;
-	Index                    vector_I;
-	char*                    name;
-	SwarmVariable*           swarmVariable;
-	Variable_Register*       variable_Register      = NULL;
-	SwarmVariable_Register*  swarmVariable_Register = NULL;
-	va_list                  ap;
-
-	/* Initialise arrays */
-	dataOffsets[0]    = dataOffset;
-	dataTypes[0]      = dataType;
-	dataTypeCounts[0] = dataTypeCount;
-	
-	/* Create name for normal variable */
-	Stg_asprintf( &name, "%s-%s", self->name, nameExt );
-
-	/* Get names of extra variables */
-	dataNames = Memory_Alloc_Array( char*, dataTypeCount, "dataNames" );
-	va_start( ap, dataTypeCount );
-	for( vector_I = 0; vector_I < dataTypeCount; vector_I++ ) {
-		dataNames[vector_I] = Stg_Object_AppendSuffix( self, (Name)(Name ) va_arg( ap, Name ) );
-	}
-	va_end( ap );
-	
-	/* Get Pointers To Registers */
-	swarmVariable_Register = self->swarmVariable_Register;
-	if ( swarmVariable_Register ) 
-		variable_Register = swarmVariable_Register->variable_Register;
-	
-	/* Construct */
-	variable = Variable_New( 
-		name,
-		self->context,
-		1, 
-		dataOffsets, 
-		dataTypes, 
-		dataTypeCounts, 
-		(Name*)dataNames,
-		&self->particleExtensionMgr->finalSize,
-		&self->particleLocalCount,
-		NULL,
-		(void**)&self->particles,
-		variable_Register );
-
-	/* Need to free these guys individually */
-	for( vector_I = 0; vector_I < dataTypeCount; vector_I++ ) {
-		if ( swarmVariable_Register && variable_Register ) {
-			swarmVariable = SwarmVariable_New( 
-					dataNames[ vector_I ], self->context, 
-					self, 
-					Variable_Register_GetByName( variable_Register, dataNames[ vector_I ] ),
-					1 );
-         /* disable checkpointing of children, as data is stored when parent is checkpointed */
-         swarmVariable->isCheckpointedAndReloaded = False;
-		}
-		Memory_Free( dataNames[ vector_I ] );
-	}
-	swarmVariable = SwarmVariable_New( name, self->context, self, variable, dataTypeCount );
-   /* set variable to be checkpointed */
-   swarmVariable->isCheckpointedAndReloaded = True;
-
-	Memory_Free( dataNames );
-	Memory_Free( name );
-	
-	return swarmVariable;
-}
-
-
-void Swarm_Realloc( void* swarm ) {
-	Swarm*         self               = (Swarm*) swarm;
-	Particle_Index particleLocalCount = self->particleLocalCount;
-	Particle_Index delta              = self->particlesArrayDelta;
-	unsigned v_i;
-
-	if ( !self->expanding && particleLocalCount <= self->particlesArraySize - delta ) {
-		/* Decrease size of array if necessary */
-		self->particlesArraySize = particleLocalCount;
-	}
-	else if ( particleLocalCount >= self->particlesArraySize ) {
-	    /* Increase size of array if necessary */
-	    self->particlesArraySize = (particleLocalCount/delta + 1)*delta;
-	}
-	else {
-		/* If no change in the size of the array happened then get out of this function */
-		return;
-	}
-
-	/* Do realloc */
-	self->particles = (Particle*)Memory_Realloc_Array_Bytes(
-			self->particles,
-			self->particleExtensionMgr->finalSize,
-			self->particlesArraySize );
-
-	/*
-	** NEED TO UPDATE THINGS IF ARRAYS ARE REALLOC'D
-	*/
-	for( v_i = 0; v_i < self->nSwarmVars; v_i++ ) {
-		if( self->swarmVars[v_i]->variable )
-			Variable_Update( self->swarmVars[v_i]->variable );
-	}
-
-
-#ifdef DEBUG
-	/* Set extra memory at end of array to zero */
-	if ( self->particlesArraySize > particleLocalCount ) {
-		Particle_Index newParticleCount = self->particlesArraySize - particleLocalCount;
-		void*          startNewParticlePtr = Swarm_ParticleAt( self, particleLocalCount );
-		memset( startNewParticlePtr, 0, self->particleExtensionMgr->finalSize * newParticleCount );
-	}
-#endif	
-}
-
-
-void Swarm_CheckCoordsAreFinite( void* swarm ) {
-	Swarm*              self               = (Swarm*) swarm;
-	GlobalParticle*     particle;
-	double*             coord;
-	Stream*             errorStream        = Journal_Register( Error_Type, (Name)self->type );
-	Dimension_Index     dim                = self->dim;
-	Particle_Index      particleLocalCount = self->particleLocalCount;
-	Particle_Index      lParticle_I;
-
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-		particle = (GlobalParticle* )Swarm_ParticleAt( self, lParticle_I );
-		coord    = particle->coord;
-		
-		Journal_Firewall( 
-				! isinf( coord[0] ) && ! isinf( coord[1] ) && ( dim == 2 || ! isinf(coord[2]) ), 
-				errorStream,
-				"Error in func %s - Coord for particle with %u is not finite (%g, %g, %g).\n", 
-				__func__, lParticle_I, coord[0], coord[1], (dim == 3 ? coord[2] : 0.0) );
-	}
-}
-
-
-void Swarm_AssignIndexWithinShape( void* swarm, void* _shape, Variable* variableToAssign, Index indexToAssign ) {
-	Swarm*            self              = Stg_CheckType( swarm, Swarm );
-	Stg_Shape*        shape             = Stg_CheckType( _shape, Stg_Shape );
-	GlobalParticle*   particle;
-	Particle_Index    lParticle_I;
-
-	Journal_Firewall( 
-		self->particleLocalCount == variableToAssign->arraySize,
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"In func %s: Trying to assign to variable '%s' with a different number of values \
-		than the number of particles in swarm '%s'.\n",
-		__func__, variableToAssign->name, self->name );
-		
-
-
-	for ( lParticle_I = 0 ; lParticle_I < self->particleLocalCount ; lParticle_I++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( self, lParticle_I );
-
-		if ( Stg_Shape_IsCoordInside( shape, particle->coord ) ) 
-			Variable_SetValueInt( variableToAssign, lParticle_I, indexToAssign );
-	}
-}
-
-StandardParticle* Swarm_CreateNewParticle( void* swarm, Particle_Index* newParticle_I ) {
-	Swarm*              self               = (Swarm*) swarm;
-
-	*newParticle_I = self->particleLocalCount;
-	self->particleLocalCount++;
-	Swarm_Realloc( self );
-	
-	return Swarm_ParticleAt( self, *newParticle_I );
-}
-
-
-void Swarm_ReplaceCurrentParticleLayoutWithFileParticleLayout( void* swarm, void* _context ) {
-	Swarm*               self = (Swarm*)swarm;
-	AbstractContext*     context = (AbstractContext*)_context;
-	char*                name = NULL;
-	char*                swarmFileName     = NULL;
-	char*                swarmFileNamePart = NULL;
-	Index                checkpointfiles;
-
-	Stg_asprintf( &name, "%s-fileParticleLayout", self->name );
-
-   swarmFileNamePart = Context_GetCheckPointReadPrefixString( context );
-#ifdef READ_HDF5
-	Stg_asprintf( &swarmFileName, "%s%s.%05d", swarmFileNamePart, self->name, context->restartTimestep );
-#else
-	Stg_asprintf( &swarmFileName, "%s%s.%05d.dat", swarmFileNamePart, self->name, context->restartTimestep );
-#endif
-	
-	Journal_DPrintf( self->debug, "overriding the particleLayout specified via XML/constructor\n"
-		"of \"%s\" (of type %s) with a FileParticleLayout to load\n"
-		"this swarm's checkpoint file from checkpointReadPath \"%s\",\n"
-		"with prefix \"%s\" from timestep %u with total name:\n\"%s\"\n",
-		self->particleLayout->name, self->particleLayout->type,
-		context->checkpointReadPath,
-		context->checkPointPrefixString, context->restartTimestep,
-		swarmFileName );
-
-	/* TODO: deleting this makes sense if this swarm "owns" the particle layout. Is it
-	* possible for 2 swarms to have the same particle layout? I guess so - may need
-	* to rethink later. Deleting is ok though for now since the "reference counter"
-	* was incremented when we got it out of the LC register.
-	* PatrickSunter - 13 June 2006
-	*/
-	Stg_Component_Destroy( self->particleLayout, NULL, False );
-	/* find out how many files fileparticlelayout is stored across.. currently for this function we assume we are reading from checkpoints.. TODO generalise */
-	/* set to one incase reading ascii */
-	checkpointfiles = 1;
-	/* now check if using hdf5 */ 
-	#ifdef READ_HDF5
-	checkpointfiles = _FileParticleLayout_GetFileCountFromTimeInfoFile( context );
-	#endif
-
-	self->particleLayout = (ParticleLayout*)FileParticleLayout_New( name, NULL, GlobalCoordSystem, False, 0, 0.0, swarmFileName, checkpointfiles );
-
-   Memory_Free( name );
-   Memory_Free( swarmFileName );
-   Memory_Free( swarmFileNamePart );
-   
-}
-
-Bool Swarm_AddCommHandler( Swarm *self, void *commHandler )
-{
-	assert( commHandler );
-
-	if( IsChild( ((Stg_Component*)commHandler)->type, ParticleCommHandler_Type ) ){
-		Stg_ObjectList_Append( self->commHandlerList, commHandler );
-		return True;
-	}
-	else{
-		Journal_Firewall( 0, self->debug, "Trying to add a class which is not of the type ParticleCommHandler..!\n " );
-		return False;
-	}
-}
-
-void Swarm_AddVariable( Swarm* self, SwarmVariable* swarmVar ) {
-	assert( self );
-	assert( swarmVar );
-
-	self->swarmVars = MemRearray( self->swarmVars, SwarmVariable*, self->nSwarmVars + 1, 
-				      SwarmClass_Type );
-	self->swarmVars[self->nSwarmVars] = swarmVar;
-	self->nSwarmVars++;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmClass.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SwarmClass.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1655 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SwarmClass.c 4191 2007-10-05 06:23:59Z DavidLee $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifdef READ_HDF5
+#include <hdf5.h>
+#endif
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "SwarmClass.h"
+
+#include "StandardParticle.h"
+#include "ShadowInfo.h"
+#include "CellLayout.h"
+#include "ElementCellLayout.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "SingleCellLayout.h"
+#include "FileParticleLayout.h"
+#include "ParticleCommHandler.h"
+#include "ParticleMovementHandler.h"
+#include "ParticleShadowSync.h"
+#include "IntegrationPoint.h"
+#include "SwarmVariable_Register.h"
+#include "SwarmVariable.h"
+#include "Swarm_Register.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+
+const Type Swarm_Type = "Swarm";
+const Name defaultSwarmParticleCommHandlerName = "defaultSwarmPHandlerName";
+
+/** Default extra factor to malloc for particles array. This is because the number of particles on each process
+may increase due to advection, splitting/merging etc, and we want to avoid reallocing if possible. */
+const double       DEFAULT_EXTRA_PARTICLES_FACTOR = 0.05;
+const unsigned int MINIMUM_PARTICLES_ARRAY_DELTA = 100;
+const unsigned int DEFAULT_CELL_PARTICLE_TBL_DELTA = 4;
+
+/* --- Function Definitions --- */
+
+Swarm* Swarm_New( 
+   Name                                  name,
+   AbstractContext*                      context,
+   void*                                 cellLayout,
+   void*                                 particleLayout,
+   Dimension_Index                       dim,
+   SizeT                                 particleSize,
+   ExtensionManager_Register*            extensionMgr_Register,
+   Variable_Register*                    variable_Register,
+   MPI_Comm                              comm,
+   void*				                       ics ) 
+{
+  Swarm* self = (Swarm*)_Swarm_DefaultNew( name ); 
+
+   _Swarm_Init( 
+      self, context,
+      cellLayout,
+      particleLayout,
+      dim,
+      particleSize,
+      DEFAULT_CELL_PARTICLE_TBL_DELTA,
+      DEFAULT_EXTRA_PARTICLES_FACTOR,
+      extensionMgr_Register,
+      variable_Register,
+      comm, 
+      ics );
+
+   self->isConstructed = True;
+
+
+   return self;
+}
+
+Swarm* _Swarm_New(  SWARM_DEFARGS  )
+{
+	Swarm* self;
+	
+	/* Allocate memory */
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (Swarm*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	self->particleSize = particleSize;
+	self->commHandlerList = Stg_ObjectList_New();
+	self->nSwarmVars = 0;
+	self->swarmVars = NULL;
+	self->owningCellVariable = NULL;
+        self->ics = (VariableCondition*)ics;
+
+	return self;
+}
+
+void _Swarm_Init( 
+   Swarm*                                self, 
+   AbstractContext*                      context,
+   void*                                 cellLayout,
+   void*                                 particleLayout,
+   Dimension_Index                       dim,
+   SizeT                                 particleSize,
+   Particle_InCellIndex                  cellParticleTblDelta, 
+   double                                extraParticlesFactor,
+   ExtensionManager_Register*            extensionMgr_Register,
+   Variable_Register*                    variable_Register,
+   MPI_Comm                              comm,
+   void*				      ics )
+{
+	StandardParticle   particle;
+	Stream*            errorStream = Journal_Register( Error_Type, (Name)self->type  );
+   LiveComponentRegister* lcReg = NULL; 	
+
+	self->debug = Stream_RegisterChild( Swarm_Debug, self->type );
+	self->dim   = dim;
+	self->comm = comm;
+	MPI_Comm_rank( comm, (int *)&self->myRank );
+	MPI_Comm_size( comm, (int *)&self->nProc );
+	self->stillDoingInitialisation = True;
+	/* Check point and reload by default - only things like integration swarms will turn this off */
+	self->isSwarmTypeToCheckPointAndReload = True;
+
+   self->particleSize = particleSize;
+   self->context = (AbstractContext*)context;
+	self->cellLayout = (CellLayout*)cellLayout;
+	self->particleLayout = (ParticleLayout*)particleLayout;
+	
+	/* Check that if either the CellLayout or ParticleLayout is inappropriate to be checkpointed,
+		we set tthe appropriate flags -- PatrickSunter, 22 August 2006 */
+	if ( Stg_Class_IsInstance( self->cellLayout, SingleCellLayout_Type ) ) {
+		self->isSwarmTypeToCheckPointAndReload = False;
+	}
+	
+	self->cellLocalCount = 0;
+	self->cellDomainCount = 0;
+	self->cellShadowCount = 0;
+	self->cellPointTbl = NULL;
+	self->cellPointCountTbl = NULL;
+	
+	self->cellParticleTbl = NULL;
+	self->cellParticleCountTbl = NULL;
+	self->cellParticleSizeTbl = NULL;
+	self->shadowCellParticleTbl = NULL;
+	self->shadowCellParticleCountTbl = NULL;
+	self->shadowParticleCount = 0;
+	self->cellParticleTblDelta = cellParticleTblDelta;
+	
+	self->particles = NULL;
+	self->shadowParticles = NULL;
+	self->particleLocalCount = 0;
+	self->particlesArraySize = 0;
+	self->particlesArrayDelta = 0;
+	self->extraParticlesFactor = extraParticlesFactor;
+
+	self->shadowTablesBuilt = False;
+
+	Journal_Firewall( extraParticlesFactor > 0.0, errorStream, "Error - in %s: extraParticlesFactor "
+		"given as %.3f, but this must be greater than zero to allow swarm to be realloc'ed larger "
+		"if necessary\n", extraParticlesFactor );
+
+	if ( variable_Register ) {
+		self->swarmVariable_Register = SwarmVariable_Register_New( variable_Register );
+	}
+	else {
+		self->swarmVariable_Register = NULL;
+	}
+
+	self->particleExtensionMgr = ExtensionManager_New_OfStruct( "particle", self->particleSize );
+	ExtensionManager_Register_Add( extensionMgr_Register, self->particleExtensionMgr );
+
+	self->owningCellVariable = Swarm_NewScalarVariable(
+			self,
+			"OwningCell",
+			GetOffsetOfMember( particle , owningCell ),
+			Variable_DataType_Int ); /* Should be unsigned int */
+
+   lcReg = LiveComponentRegister_GetLiveComponentRegister(); /* only needed for tests like GaussLayoutSingleCellSuite which don't have liveComponent_Registers */
+   if( lcReg ) {
+      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->owningCellVariable );
+      LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->owningCellVariable->variable );
+   }
+
+   /* disable checkpointing of OwningCell as it is reinitialised on startup */   
+   self->owningCellVariable->isCheckpointedAndReloaded = False;
+
+	self->swarmReg_I = Swarm_Register_Add( Swarm_Register_GetSwarm_Register(), self );
+
+	if ( ics ) {
+		self->ics = Stg_CheckType( ics, VariableCondition );
+	}
+
+	self->incArray = IArray_New();
+
+	self->expanding = 0;
+}
+
+
+void* _Swarm_ParticleInCellAt( void* swarm, Cell_Index cell_I, Particle_InCellIndex cParticle_I ) {
+	Swarm* self =	(Swarm*)swarm;
+	
+	return (void*)Swarm_ParticleInCellAt( self, cell_I, cParticle_I );
+}
+
+
+void* _Swarm_ParticleAt( void* swarm, Particle_Index dParticle_I ) {
+	Swarm* self = (Swarm*)swarm;
+	
+	return (void*)Swarm_ParticleAt( self, dParticle_I );
+}
+
+
+void _Swarm_Delete( void* swarm ) {
+	Swarm*			self = (Swarm*)swarm;
+
+	_Stg_Component_Delete( self );
+}
+
+
+void _Swarm_Print( void* swarm, Stream* stream ) {
+	Swarm* self = (Swarm*)swarm;
+	
+	Cell_Index cell_I;
+	
+	/* Set the Journal for printing informations */
+	Stream* swarmStream = stream;
+	
+	/* General info */
+	Journal_Printf( swarmStream, "Swarm (ptr): %p\n", self );
+	
+	/* Parent class info */
+	_Stg_Component_Print( self, stream );
+	
+	/* Virtual info */
+
+	/* Swarm info */
+	Stg_Class_Print( self->cellLayout, stream );
+	Stg_Class_Print( self->particleLayout, stream );
+	Journal_Printf( swarmStream, "\tcellLocalCount: %u\n", self->cellLocalCount );
+	Journal_Printf( swarmStream, "\tcellDomainCount: %u\n", self->cellDomainCount );
+	Journal_Printf( swarmStream, "\tcellShadowCount: %u\n", self->cellShadowCount );
+	Journal_Printf( swarmStream, "\tcellPointCountTbl (ptr): %p\n", self->cellPointCountTbl );
+	Journal_Printf( swarmStream, "\tcellPointCountTbl[0-%u]: ", self->cellDomainCount );
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		Journal_Printf( swarmStream, "%.3u ", self->cellPointCountTbl[cell_I] );
+	}
+	Journal_Printf( swarmStream, "\n" );
+	
+	Journal_Printf( swarmStream, "\tcellPointTbl (ptr): %p\n", self->cellPointTbl );
+	Journal_Printf( swarmStream, "\tcellPointTbl[0-%u]: {\n", self->cellDomainCount );
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		Cell_PointIndex point_I;
+
+		Journal_Printf( swarmStream, "\tcellPointTbl[%u][0-%u]: ", cell_I, self->cellPointCountTbl[cell_I] );
+		for( point_I = 0; point_I < self->cellPointCountTbl[cell_I]; point_I++ ) {
+			Journal_Printf( swarmStream, "{%.3g %.3g %.3g} ",
+				(*self->cellPointTbl[cell_I][point_I])[0], 
+				(*self->cellPointTbl[cell_I][point_I])[1], 
+				(*self->cellPointTbl[cell_I][point_I])[2] );
+		}
+		Journal_Printf( swarmStream, "\n" );
+	}
+	Journal_Printf( swarmStream, "}\n" );
+	Journal_Printf( swarmStream, "\n" );
+	
+	Journal_Printf( swarmStream, "\tcellParticleCountTbl (ptr): %p\n", self->cellParticleCountTbl );
+	Journal_Printf( swarmStream, "\tcellParticleCountTbl[0-%u]: ", self->cellDomainCount );
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		Journal_Printf( swarmStream, "%.3u ", self->cellParticleCountTbl[cell_I] );
+	}
+	Journal_Printf( swarmStream, "\n" );
+	Journal_Printf( swarmStream, "\tcellParticleSizeTbl (ptr): %p\n", self->cellParticleSizeTbl );
+	Journal_Printf( swarmStream, "\tcellParticleSizeTbl[0-%u]: ", self->cellDomainCount );
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		Journal_Printf( swarmStream, "%.3u ", self->cellParticleSizeTbl[cell_I] );
+	}
+	Journal_Printf( swarmStream, "\n" );
+
+	/* Print( self->particleExtensionMgr, stream ); */
+	Journal_Printf( swarmStream, "\tcellParticleTbl (ptr): %p\n", self->cellParticleTbl );
+	Journal_Printf( swarmStream, "\tcellParticleTbl [0-%u]: {\n", self->cellDomainCount );
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		Particle_InCellIndex cParticle_I;
+		Particle_Index dParticle_I;
+
+		Journal_Printf( swarmStream, "\t\tcellParticleTbl[%u][0-%u]:\n", cell_I, self->cellParticleCountTbl[cell_I] );
+		for( cParticle_I = 0; cParticle_I < self->cellParticleCountTbl[cell_I]; cParticle_I++ ) {
+			dParticle_I = self->cellParticleTbl[cell_I][cParticle_I];
+			Journal_Printf( swarmStream, "\t\t\t(part. index) %d\n", dParticle_I );
+		}
+		Journal_Printf( swarmStream, "\n" );
+	}
+	Journal_Printf( swarmStream, "\t}\n" );
+	Journal_Printf( swarmStream, "\tparticlesArraySize: %d\n", self->particlesArraySize );
+	Journal_Printf( swarmStream, "\tparticlesArrayDelta: %d\n", self->particlesArrayDelta );
+	Journal_Printf( swarmStream, "\textraParticlesFactor: %.3g\n", self->extraParticlesFactor );
+
+	if ( self->ics ) {
+		Stg_Class_Print( self->ics, stream );
+	}
+	else {
+		Journal_Printf( stream, "\tics: (null)... not provided (may be Operator type)\n" );
+	}
+}
+
+
+void* _Swarm_Copy( const void* swarm, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Swarm*		self = (Swarm*)swarm;
+	Swarm*		newSwarm;
+	PtrMap*		map = ptrMap;
+	Bool		ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newSwarm = (Swarm*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
+	PtrMap_Append( map, self, newSwarm );
+	
+	newSwarm->myRank = self->myRank;
+	newSwarm->nProc = self->nProc;
+	newSwarm->comm = self->comm;
+	newSwarm->cellLocalCount = self->cellLocalCount;
+	newSwarm->cellDomainCount = self->cellDomainCount;
+	newSwarm->cellShadowCount = self->cellShadowCount;
+	newSwarm->cellParticleTblDelta = self->cellParticleTblDelta;
+	newSwarm->particleLocalCount = self->particleLocalCount;
+	newSwarm->particlesArraySize = self->particlesArraySize;
+	newSwarm->particlesArrayDelta = self->particlesArrayDelta;
+	newSwarm->extraParticlesFactor = self->extraParticlesFactor;
+	
+	if( self->shadowTablesBuilt ){
+		newSwarm->shadowParticleCount = self->shadowParticleCount;
+	}
+
+	if( deep ) {
+		/* Classes */
+		newSwarm->cellLayout = (CellLayout*)Stg_Class_Copy( self->cellLayout, NULL, deep, nameExt, map );
+		newSwarm->particleLayout = (ParticleLayout*)Stg_Class_Copy( self->particleLayout, NULL, deep, nameExt, map );
+		newSwarm->debug = (Stream*)Stg_Class_Copy( self->debug, NULL, deep, nameExt, map );
+		newSwarm->particleExtensionMgr = (ExtensionManager*)Stg_Class_Copy( self->particleExtensionMgr, NULL, deep, nameExt, map );
+		newSwarm->commHandlerList = (Stg_ObjectList*)Stg_Class_Copy( self->commHandlerList, NULL, deep, nameExt, map );
+		
+		/* Arrays */
+		if( (newSwarm->cellPointCountTbl = (Cell_PointIndex*)PtrMap_Find( map, self->cellPointCountTbl )) == NULL ) {
+			if( self->cellPointCountTbl ) {
+				newSwarm->cellPointCountTbl = Memory_Alloc_Array( Cell_PointIndex, newSwarm->cellDomainCount, "Swarm->cellPointCountTbl" );
+				memcpy( newSwarm->cellPointCountTbl, self->cellPointCountTbl, newSwarm->cellDomainCount * sizeof( Cell_PointIndex ) );
+				PtrMap_Append( map, self->cellPointCountTbl, newSwarm->cellPointCountTbl );
+			}
+			else {
+				newSwarm->cellPointCountTbl = NULL;
+			}
+		}
+		
+		if( (newSwarm->cellPointTbl = (double****)PtrMap_Find( map, self->cellPointTbl )) == NULL ) {
+			if( newSwarm->cellPointCountTbl && self->cellPointTbl ) {
+				Index	cell_I;
+				
+				newSwarm->cellPointTbl = Memory_Alloc_2DComplex( Cell_Point, newSwarm->cellDomainCount, newSwarm->cellPointCountTbl, "Swarm->cellPointTbl" );
+				for( cell_I = 0; cell_I < newSwarm->cellDomainCount; cell_I++ ) {
+					memcpy( newSwarm->cellPointTbl[cell_I], self->cellPointTbl[cell_I], newSwarm->cellPointCountTbl[cell_I] * sizeof(Cell_Point) );
+				}
+				PtrMap_Append( map, self->cellPointTbl, newSwarm->cellPointTbl );
+			}
+			else {
+				newSwarm->cellPointTbl = NULL;
+			}
+		}
+		
+		if( (newSwarm->cellParticleCountTbl = (Particle_InCellIndex*)PtrMap_Find( map, self->cellParticleCountTbl )) == NULL ) {
+			if( self->cellParticleCountTbl ) {
+				newSwarm->cellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, newSwarm->cellDomainCount, "Swarm->cellParticleCountTbl" );
+				memcpy( newSwarm->cellParticleCountTbl, self->cellParticleCountTbl, newSwarm->cellDomainCount * sizeof( Particle_InCellIndex ) );
+				PtrMap_Append( map, self->cellParticleCountTbl, newSwarm->cellParticleCountTbl );
+			}
+			else {
+				newSwarm->cellParticleCountTbl = NULL;
+			}
+		}
+		
+		if( (newSwarm->cellParticleSizeTbl = (Particle_InCellIndex*)PtrMap_Find( map, self->cellParticleSizeTbl )) == NULL ) {
+			if( self->cellParticleSizeTbl ) {
+				newSwarm->cellParticleSizeTbl = Memory_Alloc_Array( Particle_InCellIndex, newSwarm->cellDomainCount, "Swarm->cellParticleSizeTbl" );
+				memcpy( newSwarm->cellParticleSizeTbl, self->cellParticleSizeTbl, newSwarm->cellDomainCount * sizeof( Particle_InCellIndex ) );
+				PtrMap_Append( map, self->cellParticleSizeTbl, newSwarm->cellParticleSizeTbl );
+			}
+			else {
+				newSwarm->cellParticleSizeTbl = NULL;
+			}
+		}
+		
+		if( (newSwarm->cellParticleTbl = (Particle_Index**)PtrMap_Find( map, self->cellParticleTbl )) == NULL ) {
+			if( newSwarm->cellParticleCountTbl && self->cellParticleTbl ) {
+				Index	cell_I;
+				
+				newSwarm->cellParticleTbl = Memory_Alloc_Array( Cell_Particles, newSwarm->cellDomainCount, "Swarm->cellParticleTbl" );
+				for( cell_I = 0; cell_I < newSwarm->cellDomainCount; cell_I++ ) {
+					if( newSwarm->cellParticleCountTbl[cell_I] ) {
+						newSwarm->cellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, newSwarm->cellParticleCountTbl[cell_I], "Swarm->cellParticleTbl[]" );
+						memcpy( newSwarm->cellParticleTbl[cell_I], self->cellParticleTbl[cell_I], newSwarm->cellParticleCountTbl[cell_I] * sizeof(Particle_Index) );
+					}
+					else {
+						newSwarm->cellParticleTbl[cell_I] = NULL;
+					}
+				}
+				PtrMap_Append( map, self->cellParticleTbl, newSwarm->cellParticleTbl );
+			}
+			else {
+				newSwarm->cellParticleTbl = NULL;
+			}
+		}
+		
+		if( (newSwarm->particles = (Particle*)PtrMap_Find( map, self->particles )) == NULL ) {
+			if( self->particles ) {
+				newSwarm->particles = (Particle_List)ExtensionManager_Malloc( newSwarm->particleExtensionMgr, newSwarm->particlesArraySize );
+				memcpy( newSwarm->particles, self->particles, newSwarm->particlesArraySize * ExtensionManager_GetFinalSize( newSwarm->particleExtensionMgr ) );
+				PtrMap_Append( map, self->particles, newSwarm->particles );
+			}
+			else {
+				newSwarm->particles = NULL;
+			}
+		}
+
+		/*shadow info*/
+		if( self->shadowTablesBuilt ){
+
+                  if( (newSwarm->shadowCellParticleCountTbl = (Particle_InCellIndex*)PtrMap_Find( map, self->shadowCellParticleCountTbl )) == NULL ) {
+				if( self->shadowCellParticleCountTbl ) {
+					newSwarm->shadowCellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, newSwarm->cellDomainCount, "Swarm->shadowCellParticleCountTbl" );
+					memcpy( newSwarm->shadowCellParticleCountTbl, self->shadowCellParticleCountTbl, newSwarm->cellDomainCount * sizeof( Particle_InCellIndex ) );
+					PtrMap_Append( map, self->shadowCellParticleCountTbl, newSwarm->shadowCellParticleCountTbl );
+				}
+				else {
+					newSwarm->shadowCellParticleCountTbl = NULL;
+				}
+			}
+		
+                  if( (newSwarm->shadowCellParticleTbl = (Particle_Index**)PtrMap_Find( map, self->shadowCellParticleTbl )) == NULL ) {
+				if( newSwarm->shadowCellParticleCountTbl && self->shadowCellParticleTbl ) {
+					Index	cell_I;
+				
+					newSwarm->shadowCellParticleTbl = Memory_Alloc_Array( Cell_Particles, newSwarm->cellDomainCount, "Swarm->shadowCellParticleTbl" );
+					for( cell_I = 0; cell_I < newSwarm->cellDomainCount; cell_I++ ) {
+						if( newSwarm->shadowCellParticleCountTbl[cell_I] ) {
+							newSwarm->shadowCellParticleTbl[cell_I] = Memory_Alloc_Array( Particle_Index, newSwarm->shadowCellParticleCountTbl[cell_I],
+									"Swarm->shadowCellParticleTbl[]" );
+							memcpy( newSwarm->shadowCellParticleTbl[cell_I], self->shadowCellParticleTbl[cell_I],
+									newSwarm->shadowCellParticleCountTbl[cell_I] * sizeof(Particle_Index) );
+						}
+						else {
+							newSwarm->shadowCellParticleTbl[cell_I] = NULL;
+						}
+					}
+					PtrMap_Append( map, self->shadowCellParticleTbl, newSwarm->shadowCellParticleTbl );
+				}
+				else {
+					newSwarm->shadowCellParticleTbl = NULL;
+				}
+			}
+		
+                  if( (newSwarm->shadowParticles = (Particle*)PtrMap_Find( map, self->shadowParticles )) == NULL ) {
+				if( self->shadowParticles ) {
+					newSwarm->shadowParticles = (Particle_List)ExtensionManager_Malloc( newSwarm->particleExtensionMgr, newSwarm->shadowParticleCount);
+					memcpy( newSwarm->shadowParticles, self->shadowParticles,
+							newSwarm->shadowParticleCount* ExtensionManager_GetFinalSize( newSwarm->particleExtensionMgr ) );
+					PtrMap_Append( map, self->shadowParticles, newSwarm->shadowParticles );
+				}
+				else {
+					newSwarm->shadowParticles = NULL;
+				}
+			}		
+		}
+
+		newSwarm->ics = self->ics ? (VariableCondition*)Stg_Class_Copy( self->ics, NULL, deep, nameExt, map ) : NULL;
+	}
+	else {
+		newSwarm->cellLayout = self->cellLayout;
+		newSwarm->particleLayout = self->particleLayout;
+		newSwarm->debug = self->debug;
+		newSwarm->cellPointTbl = self->cellPointTbl;
+		newSwarm->cellPointCountTbl = self->cellPointCountTbl;
+		newSwarm->cellParticleTbl = self->cellParticleTbl;
+		newSwarm->cellParticleCountTbl = self->cellParticleCountTbl;
+		newSwarm->cellParticleSizeTbl = self->cellParticleSizeTbl;
+		newSwarm->particles = self->particles;
+
+		newSwarm->shadowCellParticleTbl = self->shadowCellParticleTbl;
+		newSwarm->shadowCellParticleCountTbl = self->shadowCellParticleCountTbl;
+		newSwarm->shadowParticles = self->shadowParticles;
+
+		newSwarm->particleExtensionMgr = self->particleExtensionMgr;
+		newSwarm->commHandlerList = self->commHandlerList;
+
+		newSwarm->ics = self->ics;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newSwarm;
+}
+
+void* _Swarm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                _sizeOfSelf = sizeof(Swarm);
+	Type                                                        type = Swarm_Type;
+	Stg_Class_DeleteFunction*                                _delete = _Swarm_Delete;
+	Stg_Class_PrintFunction*                                  _print = _Swarm_Print;
+	Stg_Class_CopyFunction*                                    _copy = _Swarm_Copy;
+	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = _Swarm_DefaultNew;
+	Stg_Component_ConstructFunction*                      _construct = _Swarm_AssignFromXML;
+	Stg_Component_BuildFunction*                              _build = _Swarm_Build;
+	Stg_Component_InitialiseFunction*                    _initialise = _Swarm_Initialise;
+	Stg_Component_ExecuteFunction*                          _execute = _Swarm_Execute;
+	Stg_Component_DestroyFunction*                          _destroy = _Swarm_Destroy;
+	SizeT                                               particleSize = sizeof(IntegrationPoint);
+	void*                                                        ics = NULL;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return _Swarm_New(  SWARM_PASSARGS  );			    /* ics_renamed */
+}
+
+void _Swarm_AssignFromXML( void* swarm, Stg_ComponentFactory* cf, void* data ) {
+	Swarm*                  self                     = (Swarm*)swarm;
+   AbstractContext*        context                  = NULL;
+	CellLayout*             cellLayout               = NULL;
+	ParticleLayout*         particleLayout           = NULL;
+	void*                   extensionManagerRegister = NULL;
+	double                  extraParticlesFactor     = 0.0;
+	Particle_InCellIndex    cellParticleTblDelta     = 0;
+	Dimension_Index         dim;
+	Type                    particleType;
+	Variable_Register*      variable_Register        = NULL;
+	VariableCondition* 	ic            		 = NULL;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+	
+	particleType = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"ParticleType", IntegrationPoint_Type  );
+	
+	cellLayout =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)CellLayout_Type, CellLayout, True, data  ) ;
+	particleLayout =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)ParticleLayout_Type, ParticleLayout, True, data );
+	
+	extensionManagerRegister = extensionMgr_Register; 
+	assert( extensionManagerRegister );
+	variable_Register = context->variable_Register; 
+	assert( variable_Register  );
+	
+	cellParticleTblDelta = 
+		Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"cellParticleTblDelta", DEFAULT_CELL_PARTICLE_TBL_DELTA );
+	extraParticlesFactor = 
+		Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"extraParticlesFactor", DEFAULT_EXTRA_PARTICLES_FACTOR );
+	
+	{
+		unsigned int count = 0;
+		unsigned i = 0;
+		Stg_Component **components = NULL;
+
+		components = (Stg_Component** )Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"ParticleCommHandlers", Stg_ComponentFactory_Unlimited, ParticleCommHandler, False, &count, data );
+
+		if( count == 0  ){
+ 			Journal_Printf( self->debug, "Warning: Swarm has 0 Communication handlers..!\n" );
+ 		}
+ 		else{
+ 			for( i=0; i<count; i++ ){
+ 				Stg_ObjectList_Append( self->commHandlerList, components[i] );
+ 			}
+ 			Memory_Free( components );
+		}
+	}
+
+	/* construct the variable condition IC */
+	ic = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IC", VariableCondition, False, data  );
+	
+	_Swarm_Init( 
+			self, context,
+			cellLayout,
+			particleLayout, 
+			dim,
+         sizeof(IntegrationPoint),
+			cellParticleTblDelta,
+			extraParticlesFactor,
+			(ExtensionManager_Register*)extensionManagerRegister,
+			variable_Register,
+			context->communicator,
+			ic );
+}
+
+
+void _Swarm_Build( void* swarm, void* data ) {
+	Swarm* self = (Swarm*)swarm;
+	AbstractContext* context = self->context;
+	
+	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\" (of type %s)\n", __func__, self->name, self->type ); 
+	Stream_IndentBranch( Swarm_Debug );
+
+	Stg_Component_Build( self->cellLayout, data, False );
+	Stg_Component_Build( self->particleLayout, data, False );
+	
+	Journal_DPrintf( self->debug, "allocating memory for cell->particle mappings:\n" );
+	_Swarm_BuildCells( self, data );
+	Journal_DPrintf( self->debug, "...done.\n" );
+
+	/* if loading from checkpoint, then delete the particle layout
+	 * created due to the user's specification in the input file,
+	 * and replace it with a FileParticleLayout, so that the particles
+	 * can be re-loaded with their exact state at the checkpointed time
+	 */
+	if ( context && context->loadFromCheckPoint ) {
+		Journal_DPrintf( self->debug, "detected loadFromCheckPoint mode enabled:\n" );
+		Stream_Indent( self->debug );
+
+		if ( False == self->isSwarmTypeToCheckPointAndReload ) {
+			Journal_DPrintf( self->debug, "...but this swarm type is set to not be checkpointed/reloaded, "
+				"so continuing.\n" );
+		}
+		else {
+			Swarm_ReplaceCurrentParticleLayoutWithFileParticleLayout( self, context );
+		}	
+		Stream_UnIndent( self->debug );
+	}
+	
+	Journal_DPrintf( self->debug, "allocating memory for particles:\n" );
+	_Swarm_BuildParticles( self, data );
+	Journal_DPrintf( self->debug, "...done.\n" );
+
+	Journal_DPrintf( self->debug, "setting up the particle owningCell SwarmVariable:\n" );
+	Stg_Component_Build( self->owningCellVariable, data, False );
+	Journal_DPrintf( self->debug, "...done.\n" );
+	
+	Stream_UnIndentBranch( Swarm_Debug );
+	Journal_DPrintf( self->debug, "...done in %s().\n", __func__ );
+
+	if( self->ics && !(context && (True == context->loadFromCheckPoint) ) ) {
+		Stg_Component_Build( self->ics, data, False );
+	}
+}
+
+			
+void _Swarm_Initialise( void* swarm, void* data ) {
+	Swarm* self = (Swarm*)swarm;
+
+	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\" (of type %s)\n", __func__, self->name, self->type ); 
+	Stream_IndentBranch( Swarm_Debug );
+   Stg_Component_Initialise( self->owningCellVariable, data, False );
+
+	_Swarm_InitialiseCells( self, data );
+	_Swarm_InitialiseParticles( self, data );
+	
+	if( self->ics ) {
+		Journal_DPrintf( self->debug, "applying the ICs for this swarm.\n" );
+		Stream_Indent( self->debug );
+		Stg_Component_Initialise( self->ics, data, False );
+		/* call the initial conditions plugin here */
+		VariableCondition_Apply( self->ics, data );
+	}
+
+   self->stillDoingInitialisation = False;  /* this needs to go after the _Swarm_InitialiseParticles call */
+	
+	Stream_UnIndentBranch( Swarm_Debug );
+   
+   Journal_DPrintf( self->debug, "...done in %s().\n", __func__ );
+
+}
+
+
+void _Swarm_Execute( void* swarm, void* data ) {
+}
+
+void _Swarm_Destroy( void* swarm, void* data ) {
+	Swarm* self = (Swarm*)swarm;
+   Cell_LocalIndex cell_I;
+
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		if( self->cellParticleTbl[cell_I] ){
+			Memory_Free( self->cellParticleTbl[cell_I] );
+		}
+
+		if(self->shadowTablesBuilt){
+			if( self->shadowCellParticleTbl[cell_I] ){
+				Memory_Free( self->shadowCellParticleTbl[cell_I] );
+			}
+		}
+	}
+
+	if( self->shadowTablesBuilt ){
+		Memory_Free( self->shadowCellParticleTbl );
+		Memory_Free( self->shadowCellParticleCountTbl );
+		if ( self->shadowParticles ) {
+			ExtensionManager_Free( self->particleExtensionMgr, self->shadowParticles );
+		}
+	}
+
+	Memory_Free( self->cellParticleTbl );
+	Memory_Free( self->cellParticleCountTbl );
+	Memory_Free( self->cellParticleSizeTbl );
+	if ( self->particles ) {
+		ExtensionManager_Free( self->particleExtensionMgr, self->particles );
+	}
+	if(self->owningCellVariable)
+		Stg_Component_Destroy(self->owningCellVariable, data, False );
+
+ //  Stg_ObjectList_DeleteAllObjects( self->commHandlerList );
+	Stg_Class_Delete( self->commHandlerList );
+
+	FreeArray( self->swarmVars );
+
+	Memory_Free( self->cellPointTbl );
+	Memory_Free( self->cellPointCountTbl );
+
+	/* Delete SwarmVariable_Register if it has been created */
+	if ( self->swarmVariable_Register ) {
+		Stg_Class_Delete( self->swarmVariable_Register );
+	}
+
+	NewClass_Delete( self->incArray );
+
+	Swarm_Register_RemoveIndex( Swarm_Register_GetSwarm_Register(), self->swarmReg_I );
+
+
+
+
+}
+
+void _Swarm_BuildCells( void* swarm, void* data ) {
+	Swarm*			self = (Swarm*)swarm;
+	Cell_Index		cell_I;
+	Cell_PointIndex		pointCount;
+	
+	/* Need to do this first - as the cellLayout may be dependent on a mesh etc */
+	Stg_Component_Build( self->cellLayout, data, False );
+
+	Journal_DPrintf( self->debug, "In %s():\n", __func__ ); 
+	Stream_IndentBranch( Swarm_Debug );
+
+	self->cellLocalCount = CellLayout_CellLocalCount( self->cellLayout );
+	self->cellShadowCount = CellLayout_CellShadowCount( self->cellLayout );
+	self->cellDomainCount = self->cellLocalCount + self->cellShadowCount;
+
+	Journal_DPrintf( self->debug, "CellLayout \"%s\" (of type %s) returned cell counts of:\n"
+		"cellLocalCount: %u, cellShadowCount: %u, cellDomainCount: %u",
+		self->cellLayout->name, self->cellLayout->type,
+		self->cellLocalCount, self->cellShadowCount, self->cellDomainCount );
+
+	self->cellPointCountTbl = Memory_Alloc_Array( Cell_PointIndex, self->cellDomainCount, "Swarm->cellPointCountTbl" );
+	pointCount = 0;
+
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		self->cellPointCountTbl[cell_I] = CellLayout_PointCount( self->cellLayout, cell_I );
+		pointCount += self->cellPointCountTbl[cell_I];
+	}
+
+	self->cellPointTbl = Memory_Alloc_2DComplex( Cell_Point, self->cellDomainCount, self->cellPointCountTbl, "Swarm->cellPointTbl" );
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void _Swarm_BuildParticles( void* swarm, void* data ) {
+	Swarm*			self = (Swarm*)swarm;
+	
+	/* Need to do this first - as the particleLayout may be dependent on a mesh etc */
+	Stg_Component_Build( self->particleLayout, data, False );
+
+	self->cellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, self->cellDomainCount,
+		"Swarm->cellParticleCountTbl" );
+	self->cellParticleSizeTbl = Memory_Alloc_Array( Particle_InCellIndex, self->cellDomainCount,
+		"Swarm->cellParticleSizeTbl" );
+	self->cellParticleTbl = Memory_Alloc_Array( Cell_Particles, self->cellDomainCount, "Swarm->cellParticleTbl" ); 
+	
+	ParticleLayout_SetInitialCounts( self->particleLayout, self );
+	
+	/* Now allocate the particles array */
+	/* We allocate extra space to try & avoid avoid reallocing later as particles are advected etc. */
+	self->particlesArrayDelta = (Particle_Index)( (double) self->particleLocalCount * self->extraParticlesFactor);
+	if ( 0 == self->particlesArrayDelta ) {
+		self->particlesArrayDelta = MINIMUM_PARTICLES_ARRAY_DELTA;		
+	}
+
+	self->particlesArraySize = self->particleLocalCount + self->particlesArrayDelta;
+
+	self->particles = (Particle_List)ExtensionManager_Malloc( self->particleExtensionMgr, self->particlesArraySize );
+}
+
+void _Swarm_BuildShadowParticles( void* swarm ) {
+	Swarm*			self = (Swarm*)swarm;
+	unsigned i = 0;
+	
+	self->shadowTablesBuilt = True;
+
+	self->shadowCellParticleCountTbl = Memory_Alloc_Array( Particle_InCellIndex, self->cellDomainCount,
+		"Swarm->shadowCellParticleCountTbl" );
+	self->shadowCellParticleTbl = Memory_Alloc_Array( Cell_Particles, self->cellDomainCount, "Swarm->shadowCellParticleTbl" );
+	for( i=0; i<self->cellDomainCount; i++ ){
+		self->shadowCellParticleTbl[i] = NULL;
+	}
+	
+	self->shadowParticles = NULL;
+}
+
+void _Swarm_InitialiseCells( void* swarm, void* data ) {
+	Swarm*			self = (Swarm*)swarm;
+	Cell_Index		cell_I;
+	
+	/* Need to do this first - as the cellLayout may be dependent on a mesh etc */
+	Stg_Component_Initialise( self->cellLayout, data, False );
+
+	for( cell_I = 0; cell_I < self->cellDomainCount; cell_I++ ) {
+		CellLayout_InitialiseCellPoints( self->cellLayout, cell_I, self->cellPointCountTbl[cell_I], 
+			self->cellPointTbl[cell_I] );
+	}
+}
+
+
+void _Swarm_InitialiseParticles( void* swarm, void* data ) {
+	Swarm*			self = (Swarm*)swarm;
+	
+	/* Need to do this first - as the particleLayout may be dependent on a mesh etc */
+	Stg_Component_Initialise( self->particleLayout, data, False );
+
+	ParticleLayout_InitialiseParticles( self->particleLayout, self );
+
+	/* Need to re-do the delta calculation here, since if using a global particle layouts, we didn't know the 
+	 * localParticleCount until the above call, and had just used a default delta. We can now calculate the
+	 * correct one. */
+	self->particlesArrayDelta = (Particle_Index)( (double) self->particleLocalCount * self->extraParticlesFactor);
+	if ( 0 == self->particlesArrayDelta ) {
+		self->particlesArrayDelta = MINIMUM_PARTICLES_ARRAY_DELTA;		
+	}
+
+	Swarm_UpdateAllParticleOwners( self );
+}
+
+
+/** This function assmes particle advection and hence global coords are used */
+void Swarm_UpdateAllParticleOwners( void* swarm ) {
+	Swarm*			self = (Swarm*)swarm;
+	Particle_Index		lParticle_I;
+	Progress*		prog;
+
+	/* TODO: need to reconsideer - gauss particle layout should be allowed, but not swarms that have no local
+	 * co-ordinates */
+	if ( self->particleLayout->coordSystem == LocalCoordSystem ) {
+		/* Assumption: Local coord layouts don't go through advection so no need to update */
+		return;
+	}
+
+	prog = Progress_New();
+	Progress_SetTitle( prog, "Updating particle owners" );
+	Progress_SetPrefix( prog, "\t" );
+	Progress_SetRange( prog, 0, self->particleLocalCount );
+	Progress_Update( prog );
+	
+	Journal_DPrintfL( self->debug, 1, "In %s() for Swarm \"%s\"\n", __func__, self->name );
+	Stream_IndentBranch( Swarm_Debug );	
+	for ( lParticle_I=0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
+		Swarm_UpdateParticleOwner( self, lParticle_I );
+		Progress_Increment( prog );
+	}
+
+	Stg_Class_Delete( prog );
+
+	/* UpdateAllParticleOwners is called during initialisation,to set up initial
+	 * ownership relationships, and if that's the case we don't want to invoke
+	 * the ParticleCommHandler since we know there's been no movement between
+	 * processors yet. */
+	if ( False == self->stillDoingInitialisation ) { 
+		/*Stg_Component_Execute( self->particleCommunicationHandler[0], NULL, True );
+		Stg_Component_Execute( self->particleCommunicationHandler[1], NULL, True );*/
+		{
+			unsigned ii;
+			for( ii=0; ii<self->commHandlerList->count; ii++ ){
+				ParticleCommHandler *pComm = NULL;
+
+				pComm = (ParticleCommHandler*)(Stg_ObjectList_At(self->commHandlerList, ii));
+				Stg_Component_Execute( pComm, self, True);
+			}
+		}
+	}
+
+	Stream_UnIndentBranch( Swarm_Debug );
+}
+
+
+void Swarm_UpdateParticleOwner( void* swarm, Particle_Index particle_I ) {
+	Swarm* 			self           = (Swarm*)swarm;
+	GlobalParticle*	        particle       = (GlobalParticle*) Swarm_ParticleAt( self, particle_I );
+	Cell_DomainIndex	newOwningCell;
+	Particle_InCellIndex	cParticle_I;
+	Coord*			coordPtr       = &particle->coord;
+
+	Journal_DPrintfL( self->debug, 3, "In %s: for particle %d, old cell %d\n", __func__,
+		particle_I, particle->owningCell );
+	Stream_Indent( self->debug );	
+	
+	Journal_DPrintfL( self->debug, 3, "updated coord (%f,%f,%f) is: ", (*coordPtr)[0], (*coordPtr)[1], (*coordPtr)[2] );
+
+	newOwningCell = CellLayout_CellOf( self->cellLayout, particle );
+
+	if ( newOwningCell == particle->owningCell ) {
+		Journal_DPrintfL( self->debug, 3, "still in same cell.\n" );
+	}
+	else {
+		Cell_LocalIndex		oldOwningCell = particle->owningCell;
+
+		Journal_DPrintfL( self->debug, 3, "in new cell %d.\n", newOwningCell );
+		cParticle_I = Swarm_GetParticleIndexWithinCell( self, particle->owningCell, particle_I );
+		Swarm_RemoveParticleFromCell( self, oldOwningCell, cParticle_I );
+	
+		/* if new cell is in my domain, add entry to new cell's table */
+		if ( newOwningCell == self->cellDomainCount ) {
+			Journal_DPrintfL( self->debug, 3, "New cell == domain count -> Particle has moved outside domain.\n" );
+			particle->owningCell = self->cellDomainCount;
+		}	
+		#ifdef CAUTIOUS
+		else if ( newOwningCell >= self->cellDomainCount ) {	
+			Stream*    errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+			Journal_Firewall( 0, errorStream,
+				"Error - in %s(): particle %u's new domain cell calculated as "
+				"%u, but this is greater than the count of domain cells %u. "
+				"Something has gone wrong.\n",
+				__func__, particle_I, newOwningCell, self->cellDomainCount );
+		}		
+		#endif
+		else {
+			Swarm_AddParticleToCell( self, newOwningCell, particle_I );
+		}
+	}
+	Stream_UnIndent( self->debug );	
+}
+
+
+void Swarm_RemoveParticleFromCell( void* swarm, Cell_DomainIndex dCell_I, Particle_InCellIndex cParticle_I ) {
+	Swarm* 			self = (Swarm*)swarm;
+	Particle_InCellIndex*	sizePtr = &self->cellParticleSizeTbl[dCell_I];
+	Particle_InCellIndex*	countPtr = &self->cellParticleCountTbl[dCell_I];
+
+	Journal_DPrintfL( self->debug, 3, "Removing PIC %d from cell %d: particle count now %d",
+		cParticle_I, dCell_I, (*countPtr)-1 );
+	self->cellParticleTbl[dCell_I][cParticle_I] = self->cellParticleTbl[dCell_I][*countPtr-1];
+	(*countPtr)--;
+	if ( *countPtr == (*sizePtr - self->cellParticleTblDelta) ) {
+		Journal_DPrintfL( self->debug, 3, " - (reducing entries alloced to %d)", (*countPtr) );
+		(*sizePtr) = *countPtr;
+		self->cellParticleTbl[dCell_I] = Memory_Realloc_Array( self->cellParticleTbl[dCell_I],
+			Particle_Index, *sizePtr );
+	}
+	Journal_DPrintfL( self->debug, 3, "\n" );
+}
+
+
+void Swarm_DeleteParticle( void* swarm, Particle_Index particleToDelete_lI ) {
+	Swarm* 			self = (Swarm*)swarm;
+	Particle_InCellIndex    cParticle_I = 0;
+	Particle_Index          lastParticle_I = 0;
+	GlobalParticle*         lastParticle = NULL;	
+	GlobalParticle*         particleToDelete = NULL;	
+	SizeT                   particleSize = self->particleExtensionMgr->finalSize;
+	Stream*                 errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+	Journal_Firewall( particleToDelete_lI < self->particleLocalCount, errorStr,
+		"Error- in %s(): particleToDelete_lI passed in (%u) is >= swarm's local particle count %u.\n",
+		__func__, particleToDelete_lI, self->particleLocalCount );
+
+	particleToDelete = (GlobalParticle*)Swarm_ParticleAt( self, particleToDelete_lI );
+	cParticle_I = Swarm_GetParticleIndexWithinCell( self, particleToDelete->owningCell, particleToDelete_lI );
+
+	Swarm_RemoveParticleFromCell( self, particleToDelete->owningCell, cParticle_I );
+
+	lastParticle_I = self->particleLocalCount - 1;
+	lastParticle   = (GlobalParticle*)Swarm_ParticleAt( self, lastParticle_I );
+
+	/* In the current data structure for particles (a regular array), if we delete a particle we need to "swap"
+	 * the 'last' particle into the hole we just created, and update it's cell's reference to it.
+	 * The only special case is if the particle we are deleting happens to be the last particle, in which case
+	 * no swap is necessary. */ 
+	if ( particleToDelete_lI != lastParticle_I ) {
+		/* Get last Particle information */
+		Cell_Index            lastParticle_CellIndex       = lastParticle->owningCell;
+		Particle_InCellIndex  lastParticle_IndexWithinCell = 0;
+		
+		lastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( self, lastParticle_CellIndex, lastParticle_I);
+
+		Journal_DPrintfL( self->debug, 2, 
+				"Copying over particle %u using last particle %u from cell %u (cell particle index - %u)\n", 
+				particleToDelete_lI, lastParticle_I, lastParticle_CellIndex, lastParticle_IndexWithinCell );
+
+		/* Copy over particle */
+		memcpy( particleToDelete, lastParticle, particleSize );
+			
+		/* Change value in cell particle table to point to new index in array */
+		self->cellParticleTbl[lastParticle_CellIndex][ lastParticle_IndexWithinCell ] = particleToDelete_lI;
+	}
+
+	/* Re-set memory at location of last particle to zero so it is clear that it's been deleted */
+	memset( lastParticle, 0, particleSize );
+
+	self->particleLocalCount--;
+	/* Call the memory management function in case we need to re-allocate the swarm size smaller now */
+	Swarm_Realloc( swarm );
+}
+
+
+void Swarm_DeleteParticleAndReplaceWithNew( void* swarm, Particle_Index particleToDelete_lI,
+		void* replacementParticle, Cell_Index replacementParticle_cellIndex )
+{
+	Swarm* 			self = (Swarm*)swarm;
+	Particle_InCellIndex    cParticle_I = 0;
+	GlobalParticle*         particleToDelete = NULL;	
+	Stream*                 errorStr = Journal_Register( Error_Type, (Name)self->type  );
+	
+	Journal_Firewall( particleToDelete_lI < self->particleLocalCount, errorStr,
+		"Error- in %s(): particleToDelete_lI passed in (%u) is >= swarm's local particle count %u.\n",
+		__func__, particleToDelete_lI, self->particleLocalCount );
+
+	particleToDelete = (GlobalParticle*)Swarm_ParticleAt( self, particleToDelete_lI );
+	cParticle_I = Swarm_GetParticleIndexWithinCell( self, particleToDelete->owningCell, particleToDelete_lI );
+
+	Swarm_RemoveParticleFromCell( self, particleToDelete->owningCell, cParticle_I );
+
+	Journal_DPrintfL( self->debug, 2, 
+		"Copying over particle %u using replacement particle, and adding it to cell %u\n", 
+		particleToDelete_lI, replacementParticle_cellIndex );
+
+	/* Copy over particle to delete with it's replacement */
+	memcpy( particleToDelete, replacementParticle, self->particleExtensionMgr->finalSize );
+			
+	/* Add a reference to replacement particle in appropriate cell entry */
+	Swarm_AddParticleToCell( self, replacementParticle_cellIndex, particleToDelete_lI );
+}
+
+
+void Swarm_AddParticleToCell( void* swarm, Cell_DomainIndex dCell_I, Particle_Index particle_I ) {
+	Swarm* 			self = (Swarm*)swarm;
+	Particle_InCellIndex*	newCountPtr = &self->cellParticleCountTbl[dCell_I];
+	Particle_InCellIndex*	newSizePtr = &self->cellParticleSizeTbl[dCell_I];
+	#ifdef CAUTIOUS
+	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
+	#endif
+
+	Journal_DPrintfL( self->debug, 3, "Adding particle %d to cell %d: cell's particle count now %d",
+		particle_I, dCell_I, (*newCountPtr)+1 );
+
+	#ifdef CAUTIOUS
+	Journal_Firewall( dCell_I < self->cellDomainCount, errorStream,
+		"Error - in %s(): cannot add particle %u to req. domain cell, since "
+		"dCell_I passed in of %u is greater than the count of domain cells %u.\n",
+		__func__, particle_I, dCell_I, self->cellDomainCount );
+	#endif
+
+	Swarm_ParticleAt( self, particle_I)->owningCell = dCell_I;
+
+	if ( *newCountPtr == *newSizePtr ) {
+		(*newSizePtr) += self->cellParticleTblDelta;
+		Journal_DPrintfL( self->debug, 3, " - (increasing entries alloced to %d)", (*newSizePtr) );
+		self->cellParticleTbl[dCell_I] = Memory_Realloc_Array( self->cellParticleTbl[dCell_I],
+			Particle_Index, (*newSizePtr) );
+	}	
+	self->cellParticleTbl[dCell_I][*newCountPtr] = particle_I;
+	(*newCountPtr)++;
+	Journal_DPrintfL( self->debug, 3, "\n" );
+}
+
+void Swarm_AddShadowParticleToShadowCell( void* swarm, Cell_DomainIndex dCell_I, Particle_Index shadowParticle_I ) {
+	Swarm* 			self = (Swarm*)swarm;
+	
+	if( self->shadowTablesBuilt ){
+		Particle_InCellIndex*	newCountPtr = &self->shadowCellParticleCountTbl[dCell_I-self->cellLocalCount];
+		#ifdef CAUTIOUS
+		Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
+		#endif
+
+		Journal_DPrintfL( self->debug, 3, "Adding shadow particle %d to shadow cell %d: shadow cell's particle count now %d",
+			shadowParticle_I, dCell_I, (*newCountPtr)+1 );
+
+		#ifdef CAUTIOUS
+		Journal_Firewall( dCell_I < self->cellDomainCount, errorStream,
+				"Error - in %s(): cannot add particle %u to req. shadow cell, since "
+			"dCell_I passed in of %u is greater than the count of domain cells %u.\n",
+			__func__, shadowParticle_I, dCell_I, self->cellDomainCount );
+		#endif
+
+		Swarm_ShadowParticleAt( self, shadowParticle_I)->owningCell = dCell_I;
+
+		self->shadowCellParticleTbl[dCell_I][*newCountPtr] = shadowParticle_I;
+		(*newCountPtr)++;
+		Journal_DPrintfL( self->debug, 3, "\n" );
+	}
+}
+
+Particle_InCellIndex Swarm_GetParticleIndexWithinCell( void* swarm, Cell_DomainIndex owningCell, Particle_Index particle_I) {
+	Swarm* 			self = (Swarm*)swarm;
+	Particle_InCellIndex	cParticle_I;
+	Particle_InCellIndex	particleCount = self->cellParticleCountTbl[owningCell];
+
+	/* find the PIC index in the cell */
+	for ( cParticle_I=0; cParticle_I < particleCount; cParticle_I++ ) {
+		if ( particle_I == self->cellParticleTbl[owningCell][cParticle_I] ) break;
+	}	
+	#if DEBUG
+		Journal_Firewall( cParticle_I < self->cellParticleCountTbl[owningCell], Swarm_Error,
+			"Error- In func %s: Particle %u not found among cell %u's %u particles.\n",
+			__func__, particle_I, owningCell, particleCount );
+	#endif
+
+	return cParticle_I;
+}
+
+Particle_Index Swarm_FindClosestParticle( void* _swarm, Dimension_Index dim, double* coord, double *distance) {
+	Swarm*               swarm       = (Swarm*) _swarm;
+	Particle_InCellIndex cParticle_I;
+	Cell_LocalIndex      lCell_I;
+	GlobalParticle       testParticle;
+	double               minDistance;
+	double               distanceToParticle;
+	NeighbourIndex       neighbourCount;
+	NeighbourIndex       neighbour_I;
+	NeighbourIndex*      neighbourList;
+	Particle_Index       closestParticle_I;
+
+	/* Find cell this coordinate is in */
+	memcpy( testParticle.coord, coord, sizeof(Coord) );
+	/* First specify the particle doesn't have an owning cell yet, so as
+	not to confuse the search algorithm */
+	testParticle.owningCell = swarm->cellDomainCount;
+	lCell_I = CellLayout_CellOf( swarm->cellLayout, &testParticle );
+
+	/* Test if this cell is on this processor - if not then bail */
+	if (lCell_I >= swarm->cellLocalCount)
+		return (Particle_Index) -1;
+
+	/* Find Closest Particle in this Cell */
+	cParticle_I = Swarm_FindClosestParticleInCell( swarm, lCell_I, dim, coord, &minDistance );
+
+	/* Convert to Local Particle Index */
+	closestParticle_I = swarm->cellParticleTbl[ lCell_I ][ cParticle_I ];
+
+	/* Find neighbours to this cell - TODO This Assumes ElementCellLayout */
+	Mesh_GetIncidence( ((ElementCellLayout*)swarm->cellLayout)->mesh, (MeshTopology_Dim)dim, lCell_I, (MeshTopology_Dim)dim, swarm->incArray );
+	neighbourCount = IArray_GetSize( swarm->incArray );
+	neighbourList = (NeighbourIndex*)IArray_GetPtr( swarm->incArray );
+
+	/* Loop over neighbours */
+	for ( neighbour_I = 0 ; neighbour_I < neighbourCount ; neighbour_I++ ) {
+		lCell_I = neighbourList[ neighbour_I ];
+
+		if( lCell_I < swarm->cellDomainCount ) {
+			cParticle_I = Swarm_FindClosestParticleInCell( swarm, lCell_I, dim, coord, &distanceToParticle );
+
+			/* Check to see if closest particle in this cell is closest to this coord */
+			if (minDistance > distanceToParticle) {
+				minDistance = distanceToParticle;
+				closestParticle_I = swarm->cellParticleTbl[ lCell_I ][ cParticle_I ];
+			}
+		}
+	}
+
+	/* Return Distance to this particle */
+	if (distance != NULL)
+		*distance = minDistance;
+	return closestParticle_I;
+}
+
+
+Particle_InCellIndex Swarm_FindClosestParticleInCell( void* swarm, Cell_DomainIndex dCell_I, Dimension_Index dim, double* coord, double* distance ) {
+	Swarm*               self                = (Swarm*) swarm;
+	Particle_InCellIndex cParticle_I         = 0;
+	Particle_InCellIndex particle_I          = 0;
+	GlobalParticle*      particle            = NULL;
+	double               minDistance         = HUGE_VAL;
+	double               distanceToParticle;
+
+	/* TODO: need to reconsider - gauss particle layout should be allowed, but not swarms that have no local
+	 * co-ordinates */
+	/*
+	Journal_Firewall(
+		self->particleLayout->coordSystem == GlobalCoordSystem,
+		Journal_MyStream( Error_Type, self ),
+		"Error in %s(), swarm %s:%s is not using a global coord system\n",
+		__func__,
+		self->type,
+		self->name );
+	*/	
+	
+	Journal_Firewall( dCell_I < self->cellDomainCount, Swarm_Error, "Bad Cell_DomainIndex %u.\n", dCell_I );
+
+	/* Loop over particles find closest to vertex */
+	for( cParticle_I = 0 ; cParticle_I < self->cellParticleCountTbl[dCell_I] ; cParticle_I++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleInCellAt( self, dCell_I, cParticle_I );
+
+		/* Calculate distance to particle */
+		distanceToParticle = 
+			(particle->coord[ I_AXIS ] - coord[ I_AXIS ]) * 
+			(particle->coord[ I_AXIS ] - coord[ I_AXIS ]) +
+			(particle->coord[ J_AXIS ] - coord[ J_AXIS ]) * 
+			(particle->coord[ J_AXIS ] - coord[ J_AXIS ]) ;
+
+		if (dim == 3) {
+			distanceToParticle += 
+				(particle->coord[ K_AXIS ] - coord[ K_AXIS ]) * 
+				(particle->coord[ K_AXIS ] - coord[ K_AXIS ]) ;
+		}
+		/* Don't do square root here because it is unnessesary: i.e. a < b <=> sqrt(a) < sqrt(b) */
+			
+		/* Check if this is the closest particle */
+		if (minDistance > distanceToParticle) {
+			particle_I = cParticle_I;
+			minDistance = distanceToParticle;
+		}
+	}
+
+	/* Return Distance to this particle */
+	if (distance != NULL)
+		/* Do square root here in case someone wants to actually use this distance */
+		*distance = sqrt(minDistance);
+
+	return particle_I;
+}
+
+void Swarm_PrintParticleCoords( void* swarm, Stream* stream ) {
+	Swarm* 			self = (Swarm*)swarm;
+	Particle_Index		lParticle_I=0;
+	GlobalParticle*   	currParticle = NULL;
+	double*			coord = NULL;
+	
+	Journal_Printf( stream, "Printing coords of all local processor particles:\n" );
+	
+	Stream_Indent( stream );
+	for ( lParticle_I = 0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
+		currParticle = (GlobalParticle*)Swarm_ParticleAt( self, lParticle_I );
+		coord = currParticle->coord;
+
+		Journal_Printf( stream, "local particle %6d: (%7.5g, %7.5g, %7.5g)\n",
+			lParticle_I, coord[0], coord[1], coord[2] );
+	}
+	Stream_UnIndent( stream );
+}
+
+
+void Swarm_PrintParticleCoords_ByCell( void* swarm, Stream* stream ) {
+	Swarm* 			self = (Swarm*)swarm;
+	Cell_Index		lCell_I=0;
+	Particle_InCellIndex	cParticle_I=0;
+	Particle_Index		lParticle_I=0;
+	GlobalParticle*         currParticle = NULL;
+	double*			coord = NULL;
+	
+	Journal_Printf( stream, "Printing coords of all local particles, cell-by-cell:\n" );
+	
+	Stream_Indent( stream );
+	for ( lCell_I = 0; lCell_I < self->cellLocalCount; lCell_I++ ) {
+		Journal_Printf( stream, "Local Cell %3d:\n", lCell_I );
+		
+		for ( cParticle_I = 0; cParticle_I < self->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+			lParticle_I = self->cellParticleTbl[lCell_I][cParticle_I];
+			currParticle = (GlobalParticle*)Swarm_ParticleAt( self, lParticle_I );
+			coord = currParticle->coord;
+
+			Journal_Printf( stream, "\tpart. InCell %3d (local index %6d): (%7.5g, %7.5g, %7.5g)\n",
+				cParticle_I, lParticle_I, coord[0], coord[1], coord[2] );
+		}		
+	}
+	Stream_UnIndent( stream );
+}
+
+
+void Swarm_GetCellMinMaxCoords( void* swarm, Cell_DomainIndex cell_I, Coord min, Coord max ) {
+	Swarm*              self     =  (Swarm*) swarm;
+	Dimension_Index		  dim_I;
+	unsigned                 dim      = self->dim;
+	Cell_PointIndex		  cPoint_I;
+	double*             currCoord;
+
+	for ( dim_I = 0; dim_I < dim; dim_I++ ) {
+		min[dim_I] = (*self->cellPointTbl[cell_I][0])[dim_I];
+		max[dim_I] = (*self->cellPointTbl[cell_I][0])[dim_I];
+	}
+
+	for ( cPoint_I = 1; cPoint_I < self->cellPointCountTbl[cell_I]; cPoint_I++ ) {
+		for ( dim_I = 0; dim_I < dim; dim_I++ ) {
+			currCoord = (*self->cellPointTbl[cell_I][cPoint_I]);
+			if ( currCoord[dim_I] < min[dim_I] ) {
+				min[dim_I] = currCoord[dim_I];
+			}
+			else if ( currCoord[dim_I] > max[dim_I] ) {
+				max[dim_I] = currCoord[dim_I];
+			}
+		}
+	}
+}
+
+
+
+SwarmVariable* Swarm_NewScalarVariable( 
+		void*                           swarm,
+		Name                            nameExt,
+		SizeT                           dataOffset,
+		Variable_DataType               dataType )
+{
+	Swarm*                   self              = (Swarm*) swarm;
+	char*                    name;
+	Variable*                variable;
+	SizeT                    dataOffsets[]     = { 0 };		/* Init value later */
+	Variable_DataType        dataTypes[]       = { (Variable_DataType)0 };		/* Init value later */
+	Index                    dataTypeCounts[]  = { 1 };
+	SwarmVariable*           swarmVariable;
+	Variable_Register*       variable_Register      = NULL;
+	SwarmVariable_Register*  swarmVariable_Register = NULL;
+
+	Journal_Firewall(
+		dataOffset < ExtensionManager_GetFinalSize( self->particleExtensionMgr ),
+		Journal_MyStream( Error_Type, self ),
+		"Error in func %s - Failed to create Variable from extension: data offset within particle structure provided was invalid.\n"
+		"\t%s %s\n"
+		"\tdataOffset = %d, particle size = %d\n",
+		__func__,
+		self->type,
+		self->name,
+		dataOffset,
+		ExtensionManager_GetFinalSize( self->particleExtensionMgr ) );
+		
+	dataOffsets[0] = dataOffset;
+	dataTypes[0]   = dataType;
+	
+	/* Get Pointers To Registers */
+	swarmVariable_Register = self->swarmVariable_Register;
+	if ( swarmVariable_Register ) 
+		variable_Register = swarmVariable_Register->variable_Register;
+	
+	name = Stg_Object_AppendSuffix( self, (Name)nameExt  );
+	variable = Variable_New( 
+		name,
+		self->context,
+		1, 
+		dataOffsets, 
+		dataTypes, 
+		dataTypeCounts, 
+		0, /* no component names */
+		&self->particleExtensionMgr->finalSize,
+		&self->particleLocalCount,
+		NULL,
+		(void**)&self->particles,
+		variable_Register );
+
+	swarmVariable = SwarmVariable_New( name, self->context, self, variable, 1 );
+   /* set variable to be checkpointed */
+	swarmVariable->isCheckpointedAndReloaded = True;
+
+	Memory_Free( name );
+
+	return swarmVariable;
+}
+
+SwarmVariable* Swarm_NewVectorVariable( 
+		void*                           _swarm,
+		Name                            nameExt,
+		SizeT                           dataOffset,
+		Variable_DataType               dataType,
+		Index                           dataTypeCount,
+		...                         /* vector component names */ )
+{
+	Swarm*                   self             = (Swarm*) _swarm;
+	Variable*                variable;
+	SizeT                    dataOffsets[]    = { 0 };	/* Init later... */
+	Variable_DataType	     dataTypes[]      = { (Variable_DataType)0 };	/* Init later... */	
+	Index                    dataTypeCounts[] = { 0 };	/* Init later... */	
+	char**                   dataNames;
+	Index                    vector_I;
+	char*                    name;
+	SwarmVariable*           swarmVariable;
+	Variable_Register*       variable_Register      = NULL;
+	SwarmVariable_Register*  swarmVariable_Register = NULL;
+	va_list                  ap;
+
+	/* Initialise arrays */
+	dataOffsets[0]    = dataOffset;
+	dataTypes[0]      = dataType;
+	dataTypeCounts[0] = dataTypeCount;
+	
+	/* Create name for normal variable */
+	Stg_asprintf( &name, "%s-%s", self->name, nameExt );
+
+	/* Get names of extra variables */
+	dataNames = Memory_Alloc_Array( char*, dataTypeCount, "dataNames" );
+	va_start( ap, dataTypeCount );
+	for( vector_I = 0; vector_I < dataTypeCount; vector_I++ ) {
+		dataNames[vector_I] = Stg_Object_AppendSuffix( self, (Name)(Name ) va_arg( ap, Name ) );
+	}
+	va_end( ap );
+	
+	/* Get Pointers To Registers */
+	swarmVariable_Register = self->swarmVariable_Register;
+	if ( swarmVariable_Register ) 
+		variable_Register = swarmVariable_Register->variable_Register;
+	
+	/* Construct */
+	variable = Variable_New( 
+		name,
+		self->context,
+		1, 
+		dataOffsets, 
+		dataTypes, 
+		dataTypeCounts, 
+		(Name*)dataNames,
+		&self->particleExtensionMgr->finalSize,
+		&self->particleLocalCount,
+		NULL,
+		(void**)&self->particles,
+		variable_Register );
+
+	/* Need to free these guys individually */
+	for( vector_I = 0; vector_I < dataTypeCount; vector_I++ ) {
+		if ( swarmVariable_Register && variable_Register ) {
+			swarmVariable = SwarmVariable_New( 
+					dataNames[ vector_I ], self->context, 
+					self, 
+					Variable_Register_GetByName( variable_Register, dataNames[ vector_I ] ),
+					1 );
+         /* disable checkpointing of children, as data is stored when parent is checkpointed */
+         swarmVariable->isCheckpointedAndReloaded = False;
+		}
+		Memory_Free( dataNames[ vector_I ] );
+	}
+	swarmVariable = SwarmVariable_New( name, self->context, self, variable, dataTypeCount );
+   /* set variable to be checkpointed */
+   swarmVariable->isCheckpointedAndReloaded = True;
+
+	Memory_Free( dataNames );
+	Memory_Free( name );
+	
+	return swarmVariable;
+}
+
+
+void Swarm_Realloc( void* swarm ) {
+	Swarm*         self               = (Swarm*) swarm;
+	Particle_Index particleLocalCount = self->particleLocalCount;
+	Particle_Index delta              = self->particlesArrayDelta;
+	unsigned v_i;
+
+	if ( !self->expanding && particleLocalCount <= self->particlesArraySize - delta ) {
+		/* Decrease size of array if necessary */
+		self->particlesArraySize = particleLocalCount;
+	}
+	else if ( particleLocalCount >= self->particlesArraySize ) {
+	    /* Increase size of array if necessary */
+	    self->particlesArraySize = (particleLocalCount/delta + 1)*delta;
+	}
+	else {
+		/* If no change in the size of the array happened then get out of this function */
+		return;
+	}
+
+	/* Do realloc */
+	self->particles = (Particle*)Memory_Realloc_Array_Bytes(
+			self->particles,
+			self->particleExtensionMgr->finalSize,
+			self->particlesArraySize );
+
+	/*
+	** NEED TO UPDATE THINGS IF ARRAYS ARE REALLOC'D
+	*/
+	for( v_i = 0; v_i < self->nSwarmVars; v_i++ ) {
+		if( self->swarmVars[v_i]->variable )
+			Variable_Update( self->swarmVars[v_i]->variable );
+	}
+
+
+#ifdef DEBUG
+	/* Set extra memory at end of array to zero */
+	if ( self->particlesArraySize > particleLocalCount ) {
+		Particle_Index newParticleCount = self->particlesArraySize - particleLocalCount;
+		void*          startNewParticlePtr = Swarm_ParticleAt( self, particleLocalCount );
+		memset( startNewParticlePtr, 0, self->particleExtensionMgr->finalSize * newParticleCount );
+	}
+#endif	
+}
+
+
+void Swarm_CheckCoordsAreFinite( void* swarm ) {
+	Swarm*              self               = (Swarm*) swarm;
+	GlobalParticle*     particle;
+	double*             coord;
+	Stream*             errorStream        = Journal_Register( Error_Type, (Name)self->type );
+	Dimension_Index     dim                = self->dim;
+	Particle_Index      particleLocalCount = self->particleLocalCount;
+	Particle_Index      lParticle_I;
+
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+		particle = (GlobalParticle* )Swarm_ParticleAt( self, lParticle_I );
+		coord    = particle->coord;
+		
+		Journal_Firewall( 
+				! isinf( coord[0] ) && ! isinf( coord[1] ) && ( dim == 2 || ! isinf(coord[2]) ), 
+				errorStream,
+				"Error in func %s - Coord for particle with %u is not finite (%g, %g, %g).\n", 
+				__func__, lParticle_I, coord[0], coord[1], (dim == 3 ? coord[2] : 0.0) );
+	}
+}
+
+
+void Swarm_AssignIndexWithinShape( void* swarm, void* _shape, Variable* variableToAssign, Index indexToAssign ) {
+	Swarm*            self              = Stg_CheckType( swarm, Swarm );
+	Stg_Shape*        shape             = Stg_CheckType( _shape, Stg_Shape );
+	GlobalParticle*   particle;
+	Particle_Index    lParticle_I;
+
+	Journal_Firewall( 
+		self->particleLocalCount == variableToAssign->arraySize,
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"In func %s: Trying to assign to variable '%s' with a different number of values \
+		than the number of particles in swarm '%s'.\n",
+		__func__, variableToAssign->name, self->name );
+		
+
+
+	for ( lParticle_I = 0 ; lParticle_I < self->particleLocalCount ; lParticle_I++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( self, lParticle_I );
+
+		if ( Stg_Shape_IsCoordInside( shape, particle->coord ) ) 
+			Variable_SetValueInt( variableToAssign, lParticle_I, indexToAssign );
+	}
+}
+
+StandardParticle* Swarm_CreateNewParticle( void* swarm, Particle_Index* newParticle_I ) {
+	Swarm*              self               = (Swarm*) swarm;
+
+	*newParticle_I = self->particleLocalCount;
+	self->particleLocalCount++;
+	Swarm_Realloc( self );
+	
+	return Swarm_ParticleAt( self, *newParticle_I );
+}
+
+
+void Swarm_ReplaceCurrentParticleLayoutWithFileParticleLayout( void* swarm, void* _context ) {
+	Swarm*               self = (Swarm*)swarm;
+	AbstractContext*     context = (AbstractContext*)_context;
+	char*                name = NULL;
+	char*                swarmFileName     = NULL;
+	char*                swarmFileNamePart = NULL;
+	Index                checkpointfiles;
+
+	Stg_asprintf( &name, "%s-fileParticleLayout", self->name );
+
+   swarmFileNamePart = Context_GetCheckPointReadPrefixString( context );
+#ifdef READ_HDF5
+	Stg_asprintf( &swarmFileName, "%s%s.%05d", swarmFileNamePart, self->name, context->restartTimestep );
+#else
+	Stg_asprintf( &swarmFileName, "%s%s.%05d.dat", swarmFileNamePart, self->name, context->restartTimestep );
+#endif
+	
+	Journal_DPrintf( self->debug, "overriding the particleLayout specified via XML/constructor\n"
+		"of \"%s\" (of type %s) with a FileParticleLayout to load\n"
+		"this swarm's checkpoint file from checkpointReadPath \"%s\",\n"
+		"with prefix \"%s\" from timestep %u with total name:\n\"%s\"\n",
+		self->particleLayout->name, self->particleLayout->type,
+		context->checkpointReadPath,
+		context->checkPointPrefixString, context->restartTimestep,
+		swarmFileName );
+
+	/* TODO: deleting this makes sense if this swarm "owns" the particle layout. Is it
+	* possible for 2 swarms to have the same particle layout? I guess so - may need
+	* to rethink later. Deleting is ok though for now since the "reference counter"
+	* was incremented when we got it out of the LC register.
+	* PatrickSunter - 13 June 2006
+	*/
+	Stg_Component_Destroy( self->particleLayout, NULL, False );
+	/* find out how many files fileparticlelayout is stored across.. currently for this function we assume we are reading from checkpoints.. TODO generalise */
+	/* set to one incase reading ascii */
+	checkpointfiles = 1;
+	/* now check if using hdf5 */ 
+	#ifdef READ_HDF5
+	checkpointfiles = _FileParticleLayout_GetFileCountFromTimeInfoFile( context );
+	#endif
+
+	self->particleLayout = (ParticleLayout*)FileParticleLayout_New( name, NULL, GlobalCoordSystem, False, 0, 0.0, swarmFileName, checkpointfiles );
+
+   Memory_Free( name );
+   Memory_Free( swarmFileName );
+   Memory_Free( swarmFileNamePart );
+   
+}
+
+Bool Swarm_AddCommHandler( Swarm *self, void *commHandler )
+{
+	assert( commHandler );
+
+	if( IsChild( ((Stg_Component*)commHandler)->type, ParticleCommHandler_Type ) ){
+		Stg_ObjectList_Append( self->commHandlerList, commHandler );
+		return True;
+	}
+	else{
+		Journal_Firewall( 0, self->debug, "Trying to add a class which is not of the type ParticleCommHandler..!\n " );
+		return False;
+	}
+}
+
+void Swarm_AddVariable( Swarm* self, SwarmVariable* swarmVar ) {
+	assert( self );
+	assert( swarmVar );
+
+	self->swarmVars = MemRearray( self->swarmVars, SwarmVariable*, self->nSwarmVars + 1, 
+				      SwarmClass_Type );
+	self->swarmVars[self->nSwarmVars] = swarmVar;
+	self->nSwarmVars++;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmDump.c
--- a/Swarm/src/SwarmDump.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,462 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**      Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**      Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**      Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SwarmDump.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "SwarmDump.h"
-#include "SwarmVariable.h"
-#include "SwarmVariable_Register.h"
-
-#include <assert.h>
-#include <string.h>
-
-#ifdef WRITE_HDF5
-#include <hdf5.h>
-#endif
-
-const Type SwarmDump_Type = "SwarmDump";
-
-
-SwarmDump* SwarmDump_New(               
-	Name		name,
-	void*		context,
-	Swarm**	swarmList,
-	Index		swarmCount,
-	Bool		newFileEachTime )
-{
-  SwarmDump* self = (SwarmDump*)_SwarmDump_DefaultNew( name );
-
-	_SwarmDump_Init( self, context, swarmList, swarmCount, newFileEachTime );
-	return self;
-}
-
-SwarmDump* _SwarmDump_New(  SWARMDUMP_DEFARGS  ) {
-        SwarmDump*              self;
-        
-        /* Allocate memory */
-        assert( _sizeOfSelf >= sizeof(SwarmDump) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-        self = (SwarmDump*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-        
-        /* Virtual functions */
-
-        return self;
-}
-
-void _SwarmDump_Init( 
-                SwarmDump*                                         self,
-                void*                                              context,
-                Swarm**                                            swarmList,
-                Index                                              swarmCount,
-                Bool                                               newFileEachTime )
-{
-        self->isConstructed = True;
-
-        self->swarmList = Memory_Alloc_Array( Swarm*, swarmCount, "swarmList" );
-        memcpy( self->swarmList, swarmList, swarmCount * sizeof(Swarm*) );
-        self->swarmCount = swarmCount;
-
-        self->newFileEachTime = newFileEachTime;
-                
-        /* Only append hook to context's save EP if context is given */
-        if ( context ) {
-                EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_SaveClass ), SwarmDump_Execute, self );
-        }
-}
-
-
-void _SwarmDump_Delete( void* swarmDump ) {
-        SwarmDump* self = (SwarmDump*) swarmDump;
-        
-        Memory_Free( self->swarmList );
-        _Stg_Component_Delete( self );
-}
-
-void _SwarmDump_Print( void* _swarmDump, Stream* stream ) {
-        SwarmDump* self = (SwarmDump*) _swarmDump;
-        Index      swarm_I;
-
-        Journal_Printf( stream, "SwarmDump - '%s'\n", self->name );
-        Stream_Indent( stream );
-        _Stg_Component_Print( self, stream );
-
-        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
-                Journal_Printf( stream, "Swarm - '%s'\n", self->swarmList[ swarm_I ]->name );
-        }
-
-        Stream_UnIndent( stream );
-}
-
-void* _SwarmDump_Copy( const void* swarmDump, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-        SwarmDump*      self = (SwarmDump*)swarmDump;
-        SwarmDump*      newSwarmDump;
-        PtrMap*                 map = ptrMap;
-        Bool                    ownMap = False;
-        
-        if( !map ) {
-                map = PtrMap_New( 10 );
-                ownMap = True;
-        }
-        
-        newSwarmDump = (SwarmDump*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
-        memcpy( newSwarmDump->swarmList, self->swarmList, self->swarmCount * sizeof(Swarm*) );
-        newSwarmDump->swarmCount = self->swarmCount;
-
-        if( ownMap ) {
-                Stg_Class_Delete( map );
-        }
-                                
-        return (void*)newSwarmDump;
-}
-
-
-void* _SwarmDump_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(SwarmDump);
-	Type                                                      type = SwarmDump_Type;
-	Stg_Class_DeleteFunction*                              _delete = _SwarmDump_Delete;
-	Stg_Class_PrintFunction*                                _print = _SwarmDump_Print;
-	Stg_Class_CopyFunction*                                  _copy = _SwarmDump_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _SwarmDump_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _SwarmDump_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _SwarmDump_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _SwarmDump_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _SwarmDump_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _SwarmDump_Destroy;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-                return (void*) _SwarmDump_New(  SWARMDUMP_PASSARGS  );
-}
-void _SwarmDump_AssignFromXML( void* swarmDump, Stg_ComponentFactory* cf, void* data ) {
-        SwarmDump*                  self         = (SwarmDump*)swarmDump;
-        Swarm**                 swarmList;
-        Bool                    newFileEachTime;
-        Index                   swarmCount;
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !self->context  )
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-        swarmList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"Swarm", Stg_ComponentFactory_Unlimited, Swarm, True, &swarmCount, data  ) ;
-        newFileEachTime = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"newFileEachTime", True  );
-
-        _SwarmDump_Init( 
-                        self,
-                        (AbstractContext*)self->context,
-                        swarmList,
-                        swarmCount,
-                        newFileEachTime );
-
-        Memory_Free( swarmList );
-}
-
-void _SwarmDump_Build( void* swarmDump, void* data ) {
-        SwarmDump*       self                = (SwarmDump*)     swarmDump;
-        Index        swarm_I;
-
-        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
-                Stg_Component_Build( self->swarmList[ swarm_I ], data, False );
-        }
-}
-
-void _SwarmDump_Initialise( void* swarmDump, void* data ) {
-        SwarmDump*       self                = (SwarmDump*)     swarmDump;
-        Index        swarm_I;
-
-        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
-                Stg_Component_Initialise( self->swarmList[ swarm_I ], data, False );
-        }
-}
-
-void _SwarmDump_Execute( void* swarmDump, void* data ) {
-        SwarmDump*            self                = (SwarmDump*)     swarmDump;
-        AbstractContext*  context             = Stg_CheckType( data, AbstractContext );
-        Particle_Index    particleLocalCount;
-        SizeT             particleSize;
-        Index             swarm_I;
-        Swarm*            swarm;
-        Stream*           debug = Journal_Register( Debug_Type, (Name)self->type  );
-        Processor_Index   rank_I;
-
-        Journal_DPrintf( debug, "Proc %d: beginning Swarm binary checkpoint in %s():\n", self->swarmList[0]->myRank, __func__ );
-        Stream_Indent( debug );
-        
-        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
-                char*			swarmSaveFileName      = NULL;
-                char*			swarmSaveFileNamePart1 = NULL;
-                char*			swarmSaveFileNamePart2 = NULL;
-
-                swarmSaveFileNamePart1 = Context_GetCheckPointWritePrefixString( context );
-
-                swarm = self->swarmList[ swarm_I ];
-                particleLocalCount = swarm->particleLocalCount;
-                particleSize = (SizeT) swarm->particleExtensionMgr->finalSize;
-
-                if ( self->newFileEachTime )
-                    Stg_asprintf( &swarmSaveFileNamePart2, "%s/%s.%05d", swarmSaveFileNamePart1, swarm->name, context->timeStep );
-                else
-                    Stg_asprintf( &swarmSaveFileNamePart2, "%s/%s"     , swarmSaveFileNamePart1, swarm->name );
-
-                #ifdef WRITE_HDF5
-                   if(swarm->nProc == 1)
-                           Stg_asprintf( &swarmSaveFileName, "%s.h5", swarmSaveFileNamePart2 );
-                   else
-                           Stg_asprintf( &swarmSaveFileName, "%s.%dof%d.h5", swarmSaveFileNamePart2, (swarm->myRank + 1), swarm->nProc );
-                #else
-                   Stg_asprintf( &swarmSaveFileName, "%s.dat", swarmSaveFileNamePart2 );
-                #endif
-                 
-                #ifdef DEBUG
-                   for ( rank_I = 0; rank_I < swarm->nProc; rank_I++ ) {
-                           if ( swarm->myRank == rank_I ) {
-                                   Journal_DPrintf( debug, "Proc %d: for swarm \"%s\", dumping its %u particles of size %u bytes "
-                                           "each (= %g bytes total) to file %s\n", swarm->myRank, swarm->name, particleLocalCount,
-                                           particleSize, (float)(particleLocalCount * particleSize), swarmSaveFileName );
-                           }       
-                           MPI_Barrier( swarm->comm );
-                   }
-                #endif
-
-                #ifdef WRITE_HDF5
-                   SwarmDump_DumpToHDF5( self, swarm, swarmSaveFileName );
-                #else
-                   BinaryStream_WriteAllProcessors( swarmSaveFileName, swarm->particles, particleSize, (SizeT) particleLocalCount, swarm->comm );
-                #endif
-                Memory_Free( swarmSaveFileName );
-                Memory_Free( swarmSaveFileNamePart1 );
-                Memory_Free( swarmSaveFileNamePart2 );
-
-        }
-        Stream_UnIndent( debug );
-        Journal_DPrintf( debug, "Proc %d: finished Swarm binary checkpoint.\n", self->swarmList[0]->myRank );
-}
-
-void _SwarmDump_Destroy( void* swarmDump, void* data ) {
-}
-
-/** Virtual Function Wrappers */
-void SwarmDump_Execute( void* swarmDump, void* context ) {
-        SwarmDump*        self                = (SwarmDump*)     swarmDump;
-
-        self->_execute( self, context );
-}
-
-#ifdef WRITE_HDF5
-void SwarmDump_DumpToHDF5( SwarmDump* self, Swarm* swarm, Name filename ) {
-   hid_t                   file, fileSpace, fileData;
-   hid_t                   memSpace;
-   hid_t                   props;
-   hid_t                   attribData_id, attrib_id, group_id;
-   /*herr_t                  status;*/
-   hsize_t                 size[2];
-   hsize_t                 cdims[2];
-   hsize_t                 a_dims;
-   int                     attribData;
-   hsize_t                 count[2];
-   Particle_Index          lParticle_I = 0;
-   Stream*                 errorStr = Journal_Register( Error_Type, (Name)self->type  );
-   SwarmVariable*          swarmVar;
-   Index                   swarmVar_I;
-   char                    dataSpaceName[1024];
-                
-   /* Open the HDF5 output file. */
-   file = H5Fcreate( filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
-   Journal_Firewall( 
-                file >= 0, 
-                errorStr,
-                "Error in %s for %s '%s' - Cannot create file %s.\n", 
-                __func__, 
-                self->type, 
-                self->name, 
-                filename );
-
-   /* create file attribute to indicate whether file is empty, as HDF5 does not allow empty datasets */
-   attribData = swarm->particleLocalCount;
-   a_dims = 1;
-   attribData_id = H5Screate_simple(1, &a_dims, NULL);
-   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-      group_id  = H5Gopen(file, "/");
-      attrib_id = H5Acreate(group_id, "Swarm Particle Count", H5T_STD_I32BE, attribData_id, H5P_DEFAULT);
-   #else
-      group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
-      attrib_id = H5Acreate2(group_id, "Swarm Particle Count", H5T_STD_I32BE, attribData_id, H5P_DEFAULT, H5P_DEFAULT);
-   #endif
-   H5Awrite(attrib_id, H5T_NATIVE_INT, &attribData);
-   H5Aclose(attrib_id);
-   H5Gclose(group_id);
-   H5Sclose(attribData_id);
-
-   if(swarm->particleLocalCount > 0){
-      /* Loop through the swarmVariable_Register */
-      for( swarmVar_I = 0; swarmVar_I < swarm->swarmVariable_Register->objects->count; swarmVar_I++ ) {
-         swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
-   
-         /* check that the swarmVariable should be stored */
-         if( swarmVar->isCheckpointedAndReloaded ) {
-            
-            /* Create our file space. */
-            size[0]  = swarm->particleLocalCount;
-            size[1]  = swarmVar->dofCount;   
-            fileSpace = H5Screate_simple( 2, size, NULL );
-            
-            /* Create our memory space. */
-            count[0] = swarm->particleLocalCount;
-            count[1] = swarmVar->dofCount;
-            memSpace = H5Screate_simple( 2, count, NULL );
-            H5Sselect_all( memSpace );
-           
-            /* set data chunking size.  as we are not opening and closing
-               dataset frequently, a large chunk size (the largest!) seems
-               appropriate, and gives good compression */
-            cdims[0] = swarm->particleLocalCount;
-            cdims[1] = swarmVar->dofCount;
-            
-            props  = H5Pcreate( H5P_DATASET_CREATE );
-            /* turn on hdf chunking.. as it is required for compression */
-            //status = H5Pset_chunk(props, 2, cdims);
-            /* turn on compression */
-            //status = H5Pset_deflate( props, 6);
-            /* turn on data checksum */ 
-            //status = H5Pset_fletcher32(props);
-   
-            /* Create a new dataspace */
-            sprintf( dataSpaceName, "/%s", swarmVar->name + strlen(swarm->name)+1 );
-            if( swarmVar->variable->dataTypes[0] == Variable_DataType_Int ) {
-               /* Allocate space for the values to be written to file */
-               int** value = Memory_Alloc_2DArray( int, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
-               
-               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_INT, fileSpace, props );
-               #else
-               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_INT, fileSpace,
-                                      H5P_DEFAULT, props, H5P_DEFAULT );
-               #endif
-               
-               /* Loop through local particles */      
-               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-                  /* Write the value of the current swarmVariable at the current particle to the temp array */
-                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
-               }
-               /* Write array to dataspace */
-               H5Dwrite( fileData, H5T_NATIVE_INT, memSpace, fileSpace, H5P_DEFAULT, *value );
-               Memory_Free( value );
-            }
-            else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Char) {
-               char** value;
-               /* Allocate space for the values to be written to file */
-               value = Memory_Alloc_2DArray( char, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
-               
-               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_CHAR, fileSpace, props );
-               #else
-               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_CHAR, fileSpace,
-                                      H5P_DEFAULT, props, H5P_DEFAULT );
-               #endif
-               
-               /* Loop through local particles */      
-               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-                  /* Write the value of the current swarmVariable at the current particle to the temp array */
-                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
-               }
-               /* Write array to dataspace */
-               H5Dwrite( fileData, H5T_NATIVE_CHAR, memSpace, fileSpace, H5P_DEFAULT, *value );
-               Memory_Free( value );
-            }
-            else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ) {
-               float** value;
-               /* Allocate space for the values to be written to file */
-               value = Memory_Alloc_2DArray( float, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
-               
-               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_FLOAT, fileSpace, props );
-               #else
-               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_FLOAT, fileSpace,
-                                      H5P_DEFAULT, props, H5P_DEFAULT );
-               #endif
-               
-               /* Loop through local particles */      
-               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {       
-                  /* Write the value of the current swarmVariable at the current particle to the temp array */
-                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
-               }
-               /* Write array to dataspace */
-               H5Dwrite( fileData, H5T_NATIVE_FLOAT, memSpace, fileSpace, H5P_DEFAULT, *value );
-               Memory_Free( value );
-            }
-            else {
-               double** value;
-               /* Allocate space for the values to be written to file */
-               value = Memory_Alloc_2DArray( double, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
-               
-               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
-               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_DOUBLE, fileSpace, props );
-               #else
-               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_DOUBLE, fileSpace,
-                                      H5P_DEFAULT, props, H5P_DEFAULT );
-               #endif          
-               
-               /* Loop through local particles */      
-               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-                  /* Write the value of the current swarmVariable at the current particle to the temp array */
-                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
-               }
-               /* Write array to dataspace */
-               H5Dwrite( fileData, H5T_NATIVE_DOUBLE, memSpace, fileSpace, H5P_DEFAULT, *value );
-               Memory_Free( value );
-            }
-            /* Close the dataspace */
-            H5Dclose( fileData );
-            H5Sclose( fileSpace );
-            H5Pclose( props );
-         }
-      }  
-   }
-   /* Close off all our handles. */
-   H5Fclose( file );
-   
-}
-#endif
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmDump.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SwarmDump.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,462 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**      Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**      Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**      Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SwarmDump.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "SwarmDump.h"
+#include "SwarmVariable.h"
+#include "SwarmVariable_Register.h"
+
+#include <assert.h>
+#include <string.h>
+
+#ifdef WRITE_HDF5
+#include <hdf5.h>
+#endif
+
+const Type SwarmDump_Type = "SwarmDump";
+
+
+SwarmDump* SwarmDump_New(               
+	Name		name,
+	void*		context,
+	Swarm**	swarmList,
+	Index		swarmCount,
+	Bool		newFileEachTime )
+{
+  SwarmDump* self = (SwarmDump*)_SwarmDump_DefaultNew( name );
+
+	_SwarmDump_Init( self, context, swarmList, swarmCount, newFileEachTime );
+	return self;
+}
+
+SwarmDump* _SwarmDump_New(  SWARMDUMP_DEFARGS  ) {
+        SwarmDump*              self;
+        
+        /* Allocate memory */
+        assert( _sizeOfSelf >= sizeof(SwarmDump) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+        self = (SwarmDump*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+        
+        /* Virtual functions */
+
+        return self;
+}
+
+void _SwarmDump_Init( 
+                SwarmDump*                                         self,
+                void*                                              context,
+                Swarm**                                            swarmList,
+                Index                                              swarmCount,
+                Bool                                               newFileEachTime )
+{
+        self->isConstructed = True;
+
+        self->swarmList = Memory_Alloc_Array( Swarm*, swarmCount, "swarmList" );
+        memcpy( self->swarmList, swarmList, swarmCount * sizeof(Swarm*) );
+        self->swarmCount = swarmCount;
+
+        self->newFileEachTime = newFileEachTime;
+                
+        /* Only append hook to context's save EP if context is given */
+        if ( context ) {
+                EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_SaveClass ), SwarmDump_Execute, self );
+        }
+}
+
+
+void _SwarmDump_Delete( void* swarmDump ) {
+        SwarmDump* self = (SwarmDump*) swarmDump;
+        
+        Memory_Free( self->swarmList );
+        _Stg_Component_Delete( self );
+}
+
+void _SwarmDump_Print( void* _swarmDump, Stream* stream ) {
+        SwarmDump* self = (SwarmDump*) _swarmDump;
+        Index      swarm_I;
+
+        Journal_Printf( stream, "SwarmDump - '%s'\n", self->name );
+        Stream_Indent( stream );
+        _Stg_Component_Print( self, stream );
+
+        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
+                Journal_Printf( stream, "Swarm - '%s'\n", self->swarmList[ swarm_I ]->name );
+        }
+
+        Stream_UnIndent( stream );
+}
+
+void* _SwarmDump_Copy( const void* swarmDump, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+        SwarmDump*      self = (SwarmDump*)swarmDump;
+        SwarmDump*      newSwarmDump;
+        PtrMap*                 map = ptrMap;
+        Bool                    ownMap = False;
+        
+        if( !map ) {
+                map = PtrMap_New( 10 );
+                ownMap = True;
+        }
+        
+        newSwarmDump = (SwarmDump*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
+        memcpy( newSwarmDump->swarmList, self->swarmList, self->swarmCount * sizeof(Swarm*) );
+        newSwarmDump->swarmCount = self->swarmCount;
+
+        if( ownMap ) {
+                Stg_Class_Delete( map );
+        }
+                                
+        return (void*)newSwarmDump;
+}
+
+
+void* _SwarmDump_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(SwarmDump);
+	Type                                                      type = SwarmDump_Type;
+	Stg_Class_DeleteFunction*                              _delete = _SwarmDump_Delete;
+	Stg_Class_PrintFunction*                                _print = _SwarmDump_Print;
+	Stg_Class_CopyFunction*                                  _copy = _SwarmDump_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _SwarmDump_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _SwarmDump_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _SwarmDump_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _SwarmDump_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _SwarmDump_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _SwarmDump_Destroy;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+                return (void*) _SwarmDump_New(  SWARMDUMP_PASSARGS  );
+}
+void _SwarmDump_AssignFromXML( void* swarmDump, Stg_ComponentFactory* cf, void* data ) {
+        SwarmDump*                  self         = (SwarmDump*)swarmDump;
+        Swarm**                 swarmList;
+        Bool                    newFileEachTime;
+        Index                   swarmCount;
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !self->context  )
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+        swarmList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"Swarm", Stg_ComponentFactory_Unlimited, Swarm, True, &swarmCount, data  ) ;
+        newFileEachTime = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"newFileEachTime", True  );
+
+        _SwarmDump_Init( 
+                        self,
+                        (AbstractContext*)self->context,
+                        swarmList,
+                        swarmCount,
+                        newFileEachTime );
+
+        Memory_Free( swarmList );
+}
+
+void _SwarmDump_Build( void* swarmDump, void* data ) {
+        SwarmDump*       self                = (SwarmDump*)     swarmDump;
+        Index        swarm_I;
+
+        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
+                Stg_Component_Build( self->swarmList[ swarm_I ], data, False );
+        }
+}
+
+void _SwarmDump_Initialise( void* swarmDump, void* data ) {
+        SwarmDump*       self                = (SwarmDump*)     swarmDump;
+        Index        swarm_I;
+
+        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
+                Stg_Component_Initialise( self->swarmList[ swarm_I ], data, False );
+        }
+}
+
+void _SwarmDump_Execute( void* swarmDump, void* data ) {
+        SwarmDump*            self                = (SwarmDump*)     swarmDump;
+        AbstractContext*  context             = Stg_CheckType( data, AbstractContext );
+        Particle_Index    particleLocalCount;
+        SizeT             particleSize;
+        Index             swarm_I;
+        Swarm*            swarm;
+        Stream*           debug = Journal_Register( Debug_Type, (Name)self->type  );
+        Processor_Index   rank_I;
+
+        Journal_DPrintf( debug, "Proc %d: beginning Swarm binary checkpoint in %s():\n", self->swarmList[0]->myRank, __func__ );
+        Stream_Indent( debug );
+        
+        for ( swarm_I = 0 ; swarm_I < self->swarmCount ; swarm_I++ ) {
+                char*			swarmSaveFileName      = NULL;
+                char*			swarmSaveFileNamePart1 = NULL;
+                char*			swarmSaveFileNamePart2 = NULL;
+
+                swarmSaveFileNamePart1 = Context_GetCheckPointWritePrefixString( context );
+
+                swarm = self->swarmList[ swarm_I ];
+                particleLocalCount = swarm->particleLocalCount;
+                particleSize = (SizeT) swarm->particleExtensionMgr->finalSize;
+
+                if ( self->newFileEachTime )
+                    Stg_asprintf( &swarmSaveFileNamePart2, "%s/%s.%05d", swarmSaveFileNamePart1, swarm->name, context->timeStep );
+                else
+                    Stg_asprintf( &swarmSaveFileNamePart2, "%s/%s"     , swarmSaveFileNamePart1, swarm->name );
+
+                #ifdef WRITE_HDF5
+                   if(swarm->nProc == 1)
+                           Stg_asprintf( &swarmSaveFileName, "%s.h5", swarmSaveFileNamePart2 );
+                   else
+                           Stg_asprintf( &swarmSaveFileName, "%s.%dof%d.h5", swarmSaveFileNamePart2, (swarm->myRank + 1), swarm->nProc );
+                #else
+                   Stg_asprintf( &swarmSaveFileName, "%s.dat", swarmSaveFileNamePart2 );
+                #endif
+                 
+                #ifdef DEBUG
+                   for ( rank_I = 0; rank_I < swarm->nProc; rank_I++ ) {
+                           if ( swarm->myRank == rank_I ) {
+                                   Journal_DPrintf( debug, "Proc %d: for swarm \"%s\", dumping its %u particles of size %u bytes "
+                                           "each (= %g bytes total) to file %s\n", swarm->myRank, swarm->name, particleLocalCount,
+                                           particleSize, (float)(particleLocalCount * particleSize), swarmSaveFileName );
+                           }       
+                           MPI_Barrier( swarm->comm );
+                   }
+                #endif
+
+                #ifdef WRITE_HDF5
+                   SwarmDump_DumpToHDF5( self, swarm, swarmSaveFileName );
+                #else
+                   BinaryStream_WriteAllProcessors( swarmSaveFileName, swarm->particles, particleSize, (SizeT) particleLocalCount, swarm->comm );
+                #endif
+                Memory_Free( swarmSaveFileName );
+                Memory_Free( swarmSaveFileNamePart1 );
+                Memory_Free( swarmSaveFileNamePart2 );
+
+        }
+        Stream_UnIndent( debug );
+        Journal_DPrintf( debug, "Proc %d: finished Swarm binary checkpoint.\n", self->swarmList[0]->myRank );
+}
+
+void _SwarmDump_Destroy( void* swarmDump, void* data ) {
+}
+
+/** Virtual Function Wrappers */
+void SwarmDump_Execute( void* swarmDump, void* context ) {
+        SwarmDump*        self                = (SwarmDump*)     swarmDump;
+
+        self->_execute( self, context );
+}
+
+#ifdef WRITE_HDF5
+void SwarmDump_DumpToHDF5( SwarmDump* self, Swarm* swarm, Name filename ) {
+   hid_t                   file, fileSpace, fileData;
+   hid_t                   memSpace;
+   hid_t                   props;
+   hid_t                   attribData_id, attrib_id, group_id;
+   /*herr_t                  status;*/
+   hsize_t                 size[2];
+   hsize_t                 cdims[2];
+   hsize_t                 a_dims;
+   int                     attribData;
+   hsize_t                 count[2];
+   Particle_Index          lParticle_I = 0;
+   Stream*                 errorStr = Journal_Register( Error_Type, (Name)self->type  );
+   SwarmVariable*          swarmVar;
+   Index                   swarmVar_I;
+   char                    dataSpaceName[1024];
+                
+   /* Open the HDF5 output file. */
+   file = H5Fcreate( filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
+   Journal_Firewall( 
+                file >= 0, 
+                errorStr,
+                "Error in %s for %s '%s' - Cannot create file %s.\n", 
+                __func__, 
+                self->type, 
+                self->name, 
+                filename );
+
+   /* create file attribute to indicate whether file is empty, as HDF5 does not allow empty datasets */
+   attribData = swarm->particleLocalCount;
+   a_dims = 1;
+   attribData_id = H5Screate_simple(1, &a_dims, NULL);
+   #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+      group_id  = H5Gopen(file, "/");
+      attrib_id = H5Acreate(group_id, "Swarm Particle Count", H5T_STD_I32BE, attribData_id, H5P_DEFAULT);
+   #else
+      group_id  = H5Gopen2(file, "/", H5P_DEFAULT);
+      attrib_id = H5Acreate2(group_id, "Swarm Particle Count", H5T_STD_I32BE, attribData_id, H5P_DEFAULT, H5P_DEFAULT);
+   #endif
+   H5Awrite(attrib_id, H5T_NATIVE_INT, &attribData);
+   H5Aclose(attrib_id);
+   H5Gclose(group_id);
+   H5Sclose(attribData_id);
+
+   if(swarm->particleLocalCount > 0){
+      /* Loop through the swarmVariable_Register */
+      for( swarmVar_I = 0; swarmVar_I < swarm->swarmVariable_Register->objects->count; swarmVar_I++ ) {
+         swarmVar = SwarmVariable_Register_GetByIndex( swarm->swarmVariable_Register, swarmVar_I );
+   
+         /* check that the swarmVariable should be stored */
+         if( swarmVar->isCheckpointedAndReloaded ) {
+            
+            /* Create our file space. */
+            size[0]  = swarm->particleLocalCount;
+            size[1]  = swarmVar->dofCount;   
+            fileSpace = H5Screate_simple( 2, size, NULL );
+            
+            /* Create our memory space. */
+            count[0] = swarm->particleLocalCount;
+            count[1] = swarmVar->dofCount;
+            memSpace = H5Screate_simple( 2, count, NULL );
+            H5Sselect_all( memSpace );
+           
+            /* set data chunking size.  as we are not opening and closing
+               dataset frequently, a large chunk size (the largest!) seems
+               appropriate, and gives good compression */
+            cdims[0] = swarm->particleLocalCount;
+            cdims[1] = swarmVar->dofCount;
+            
+            props  = H5Pcreate( H5P_DATASET_CREATE );
+            /* turn on hdf chunking.. as it is required for compression */
+            //status = H5Pset_chunk(props, 2, cdims);
+            /* turn on compression */
+            //status = H5Pset_deflate( props, 6);
+            /* turn on data checksum */ 
+            //status = H5Pset_fletcher32(props);
+   
+            /* Create a new dataspace */
+            sprintf( dataSpaceName, "/%s", swarmVar->name + strlen(swarm->name)+1 );
+            if( swarmVar->variable->dataTypes[0] == Variable_DataType_Int ) {
+               /* Allocate space for the values to be written to file */
+               int** value = Memory_Alloc_2DArray( int, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
+               
+               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_INT, fileSpace, props );
+               #else
+               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_INT, fileSpace,
+                                      H5P_DEFAULT, props, H5P_DEFAULT );
+               #endif
+               
+               /* Loop through local particles */      
+               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+                  /* Write the value of the current swarmVariable at the current particle to the temp array */
+                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
+               }
+               /* Write array to dataspace */
+               H5Dwrite( fileData, H5T_NATIVE_INT, memSpace, fileSpace, H5P_DEFAULT, *value );
+               Memory_Free( value );
+            }
+            else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Char) {
+               char** value;
+               /* Allocate space for the values to be written to file */
+               value = Memory_Alloc_2DArray( char, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
+               
+               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_CHAR, fileSpace, props );
+               #else
+               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_CHAR, fileSpace,
+                                      H5P_DEFAULT, props, H5P_DEFAULT );
+               #endif
+               
+               /* Loop through local particles */      
+               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+                  /* Write the value of the current swarmVariable at the current particle to the temp array */
+                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
+               }
+               /* Write array to dataspace */
+               H5Dwrite( fileData, H5T_NATIVE_CHAR, memSpace, fileSpace, H5P_DEFAULT, *value );
+               Memory_Free( value );
+            }
+            else if( swarmVar->variable->dataTypes[0] == Variable_DataType_Float ) {
+               float** value;
+               /* Allocate space for the values to be written to file */
+               value = Memory_Alloc_2DArray( float, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
+               
+               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_FLOAT, fileSpace, props );
+               #else
+               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_FLOAT, fileSpace,
+                                      H5P_DEFAULT, props, H5P_DEFAULT );
+               #endif
+               
+               /* Loop through local particles */      
+               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {       
+                  /* Write the value of the current swarmVariable at the current particle to the temp array */
+                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
+               }
+               /* Write array to dataspace */
+               H5Dwrite( fileData, H5T_NATIVE_FLOAT, memSpace, fileSpace, H5P_DEFAULT, *value );
+               Memory_Free( value );
+            }
+            else {
+               double** value;
+               /* Allocate space for the values to be written to file */
+               value = Memory_Alloc_2DArray( double, swarm->particleLocalCount, swarmVar->dofCount, (Name)"swarmVariableValue"  );
+               
+               #if H5_VERS_MAJOR == 1 && H5_VERS_MINOR < 8
+               fileData = H5Dcreate( file, dataSpaceName, H5T_NATIVE_DOUBLE, fileSpace, props );
+               #else
+               fileData = H5Dcreate2( file, dataSpaceName, H5T_NATIVE_DOUBLE, fileSpace,
+                                      H5P_DEFAULT, props, H5P_DEFAULT );
+               #endif          
+               
+               /* Loop through local particles */      
+               for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+                  /* Write the value of the current swarmVariable at the current particle to the temp array */
+                  Variable_GetValue( swarmVar->variable, lParticle_I, value[lParticle_I] );
+               }
+               /* Write array to dataspace */
+               H5Dwrite( fileData, H5T_NATIVE_DOUBLE, memSpace, fileSpace, H5P_DEFAULT, *value );
+               Memory_Free( value );
+            }
+            /* Close the dataspace */
+            H5Dclose( fileData );
+            H5Sclose( fileSpace );
+            H5Pclose( props );
+         }
+      }  
+   }
+   /* Close off all our handles. */
+   H5Fclose( file );
+   
+}
+#endif
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmOutput.c
--- a/Swarm/src/SwarmOutput.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,383 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SwarmOutput.c 4011 2007-02-19 05:54:38Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "SwarmOutput.h"
-#include "SwarmVariable.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type SwarmOutput_Type = "SwarmOutput";
-
-
-SwarmOutput* SwarmOutput_New(		
-		Name                                               name,
-		void*                                              context,
-		Swarm*                                             swarm,
-		Name                                               baseFilename,
-		unsigned int                                       columnWidth, 
-		unsigned int                                       decimalLength,
-		char*                                              borderString )		
-{
-  SwarmOutput* self = (SwarmOutput*)_SwarmOutput_DefaultNew( name );
-
-	_SwarmOutput_Init( self, context, swarm, baseFilename, columnWidth, decimalLength, borderString );
-	return self;
-}
-
-SwarmOutput* _SwarmOutput_New(  SWARMOUTPUT_DEFARGS  ) 
-{
-	SwarmOutput*		self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SwarmOutput) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (SwarmOutput*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* Virtual functions */
-	self->_printHeader                = _printHeader;
-	self->_printData                  = _printData;
-
-	return self;
-}
-
-void _SwarmOutput_Init( 
-		SwarmOutput*                                       self,
-		void*                                              context,
-		Swarm*                                             swarm,
-		Name                                               baseFilename,
-		unsigned int                                       columnWidth, 
-		unsigned int                                       decimalLength,
-		char*                                              borderString )
-{
-	SwarmVariable* swarmVariable;
-	ExtensionInfo_Index handle;
-	/* Add ourselves to the register for later retrieval by clients */
-	self->isConstructed = True;
-
-	self->swarm                  = swarm;
-	self->baseFilename           = baseFilename;
-
-	handle = ExtensionManager_Add( swarm->particleExtensionMgr, (Name)SwarmOutput_Type, sizeof( int )  );
-	swarmVariable = Swarm_NewScalarVariable( 
-			swarm,
-			"globalIndexVariable",
-			(ArithPointer) ExtensionManager_Get( swarm->particleExtensionMgr, 0, handle ), 
-			Variable_DataType_Int );
-	self->globalIndexVariable = swarmVariable->variable;
-
-	self->columnWidth = columnWidth;
-	self->borderString = StG_Strdup( borderString );
-	Stg_asprintf( &self->doubleFormatString, "%%%d.%dg", columnWidth, decimalLength );
-
-	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_DumpClass ),	SwarmOutput_Execute, self );
-}
-
-
-void _SwarmOutput_Delete( void* swarmOutput ) {
-	SwarmOutput* self = (SwarmOutput*) swarmOutput;
-
-	Memory_Free( self->doubleFormatString );
-	Memory_Free( self->borderString );
-	_Stg_Component_Delete( self );
-}
-
-void _SwarmOutput_Print( void* _swarmOutput, Stream* stream ) {
-	SwarmOutput* self = (SwarmOutput*) _swarmOutput;
-
-	Journal_Printf( stream, "SwarmOutput - '%s'\n", self->name );
-	Stream_Indent( stream );
-	_Stg_Component_Print( self, stream );
-
-	Journal_PrintPointer( stream, self->_printHeader );
-	Journal_PrintPointer( stream, self->_printData );
-
-	Journal_Printf( stream, "Swarm - '%s'\n", self->swarm->name );
-	Journal_Printf( stream, "globalIndexVariable - '%s'\n", self->globalIndexVariable->name );
-
-	Stream_UnIndent( stream );
-}
-
-void* _SwarmOutput_Copy( const void* swarmOutput, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SwarmOutput*	self = (SwarmOutput*)swarmOutput;
-	SwarmOutput*	newSwarmOutput;
-	PtrMap*			map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newSwarmOutput = (SwarmOutput*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
-	
-	newSwarmOutput->_printHeader               = self->_printHeader;
-	newSwarmOutput->_printData                 = self->_printData  ;
-
-	newSwarmOutput->swarm                      = self->swarm;
-	newSwarmOutput->globalIndexVariable        = self->globalIndexVariable;
-
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-				
-	return (void*)newSwarmOutput;
-}
-
-
-void* _SwarmOutput_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(SwarmOutput);
-	Type                                                      type = SwarmOutput_Type;
-	Stg_Class_DeleteFunction*                              _delete = _SwarmOutput_Delete;
-	Stg_Class_PrintFunction*                                _print = _SwarmOutput_Print;
-	Stg_Class_CopyFunction*                                  _copy = _SwarmOutput_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _SwarmOutput_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _SwarmOutput_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _SwarmOutput_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _SwarmOutput_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _SwarmOutput_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _SwarmOutput_Destroy;
-	SwarmOutput_PrintHeaderFunction*                  _printHeader = _SwarmOutput_PrintHeader;
-	SwarmOutput_PrintDataFunction*                      _printData = _SwarmOutput_PrintData;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-		return (void*) _SwarmOutput_New(  SWARMOUTPUT_PASSARGS  );
-}
-void _SwarmOutput_AssignFromXML( void* swarmOutput, Stg_ComponentFactory* cf, void* data ) {
-	SwarmOutput*	        self         = (SwarmOutput*)swarmOutput;
-	Swarm*                  swarm;
-	Name                    baseFilename;
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !self->context  )
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	swarm        =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data   ) ;
-	baseFilename = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"baseFilename", self->name  );
-
-	_SwarmOutput_Init( 
-			self,
-			(AbstractContext*)self->context,
-			swarm, 
-			baseFilename, 
-			Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"columnWidth", 12  ), 
-			Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"decimalLength", 6  ), 
-			Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"borderString", "    " )  );
-}
-
-void _SwarmOutput_Build( void* swarmOutput, void* data ) {
-	SwarmOutput*	 self                = (SwarmOutput*)     swarmOutput;
-
-	Stg_Component_Build( self->globalIndexVariable, data, False );
-}
-
-void _SwarmOutput_Initialise( void* swarmOutput, void* data ) {
-	SwarmOutput*	 self                = (SwarmOutput*)     swarmOutput;
-	AbstractContext* context             = self->context;
-	Swarm*           swarm               = self->swarm;
-	Variable*        globalIndexVariable = self->globalIndexVariable;
-	Particle_Index   lParticle_I;
-	char*            filename;
-	Stream*          stream              = Journal_Register( Info_Type, (Name)SwarmOutput_Type  );
-
-   /* re-enable printing from current rank process */
-	Stream_SetPrintingRank( stream, context->rank );
-   
-	Stg_Component_Initialise( self->globalIndexVariable, context, False );
-
-   if( !context->loadFromCheckPoint ) _SwarmOutput_SetGlobalIndicies( self, context );
-
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		/* Open file */
-		Stg_asprintf( &filename, "%s.%05d.dat", self->baseFilename, Variable_GetValueInt( globalIndexVariable, lParticle_I ) );
-		if( context->loadFromCheckPoint )
-			Stream_AppendFile_WithPrependedPath( stream, context->outputPath, filename );
-		else
-			Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
-
-		/* Print to file */
-		SwarmOutput_PrintHeader( self, stream, lParticle_I, data );
-		Journal_Printf( stream, "\n" );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void _SwarmOutput_Execute( void* swarmOutput, void* data ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	AbstractContext*  context             = (AbstractContext*) data;
-	Swarm*            swarm               = self->swarm;
-	Variable*         globalIndexVariable = self->globalIndexVariable;
-	Particle_Index    lParticle_I;
-	char*             filename;
-	Stream*           stream              = Journal_Register( Info_Type, (Name)SwarmOutput_Type  );
-
-   /* re-enable printing from current rank process */
-	Stream_SetPrintingRank( stream, context->rank );
-
-	Variable_Update( globalIndexVariable );
-
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		/* Open file */
-		Stg_asprintf( &filename, "%s.%05d.dat", self->baseFilename, Variable_GetValueInt( globalIndexVariable, lParticle_I ) );
-		Stream_AppendFile_WithPrependedPath( stream, context->outputPath, filename );
-
-		/* Print to file */
-		SwarmOutput_PrintData( self, stream, lParticle_I, data );
-		Journal_Printf( stream, "\n" );
-		Stream_Flush( stream );
-		Stream_CloseAndFreeFile( stream );
-	}
-}
-
-void _SwarmOutput_Destroy( void* swarmOutput, void* data ) {
-}
-
-/*** Default Implementations ***/
-void _SwarmOutput_PrintHeader( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* data ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	char*             firstBorderString;
-
-	/* Print First Border with '#' in the front */
-	firstBorderString = StG_Strdup( self->borderString );
-	firstBorderString[0] = '#';
-	Journal_Printf( stream, firstBorderString );
-	Memory_Free( firstBorderString );
-
-	Journal_PrintString_WithLength( stream, "Timestep", self->columnWidth );
-
-	SwarmOutput_PrintString( self, stream, "Time" );
-	SwarmOutput_PrintString( self, stream, "CoordX" );
-	SwarmOutput_PrintString( self, stream, "CoordY" );
-	SwarmOutput_PrintString( self, stream, "CoordZ" );
-}
-
-void _SwarmOutput_PrintData( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* data ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	AbstractContext*  context             = (AbstractContext*) data;
-	Swarm*            swarm               = self->swarm;
-	GlobalParticle*   particle            = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-	double*           coord               = particle->coord;
-		
-	SwarmOutput_PrintValue( self, stream, context->timeStep );
-	SwarmOutput_PrintValue( self, stream, context->currentTime + AbstractContext_Dt( context ) );
-	SwarmOutput_PrintValue( self, stream, coord[ I_AXIS ] );
-	SwarmOutput_PrintValue( self, stream, coord[ J_AXIS ] );
-	SwarmOutput_PrintValue( self, stream, coord[ K_AXIS ] );
-}
-
-
-/** Virtual Function Wrappers */
-void SwarmOutput_Execute( void* swarmOutput, void* context ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-
-	self->_execute( self, context );
-}
-void SwarmOutput_PrintHeader( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* context ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	self->_printHeader( self, stream, lParticle_I, context );
-}
-void SwarmOutput_PrintData( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* context ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	self->_printData( self, stream, lParticle_I, context );
-}
-
-void _SwarmOutput_SetGlobalIndicies( void* swarmOutput, void* data ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	AbstractContext*  context             = (AbstractContext*) data;
-	Swarm*            swarm               = self->swarm;
-	Variable*         globalIndexVariable = self->globalIndexVariable;
-	Particle_Index    lParticle_I;
-	Particle_Index    particleCount       = 0;
-	int               rank                = context->rank;
-	int               nproc               = context->nproc;
-	MPI_Status        status;
-
-	Variable_Update( globalIndexVariable );
-
-	/* Receive total number of particles from previous processor */
-	if ( rank != 0 ) {
-		MPI_Recv( &particleCount, 1, MPI_UNSIGNED, rank - 1, 0, context->communicator, &status );
-	}
-	
-	/* Assign value to particle */
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-		Variable_SetValueInt( globalIndexVariable, lParticle_I, particleCount );
-		particleCount++;
-	}
-
-	/* Send total number of particles next processor */
-	if ( rank != nproc - 1 ) {
-		MPI_Send( &particleCount, 1, MPI_UNSIGNED, rank + 1, 0, context->communicator );
-	}
-}
-
-void SwarmOutput_PrintString( void* swarmOutput, Stream* stream, Name string ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-
-	Journal_Printf( stream, "%s", self->borderString );
-	Journal_PrintString_WithLength( stream, string, self->columnWidth );
-}
-
-void SwarmOutput_PrintDouble( void* swarmOutput, Stream* stream, double value ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-
-	Journal_Printf( stream, "%s", self->borderString );
-	Journal_Printf( stream, self->doubleFormatString, value );
-}
-
-void SwarmOutput_PrintTuple( void* swarmOutput, Stream* stream, double* value, Index size ) {
-	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
-	Index             count;
-
-	Journal_Printf( stream, "%s", self->borderString );
-	for( count = 0 ; count < size ; count++ ) {
-		Journal_Printf( stream, self->doubleFormatString, value[count] );
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmOutput.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SwarmOutput.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,383 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SwarmOutput.c 4011 2007-02-19 05:54:38Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "SwarmOutput.h"
+#include "SwarmVariable.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type SwarmOutput_Type = "SwarmOutput";
+
+
+SwarmOutput* SwarmOutput_New(		
+		Name                                               name,
+		void*                                              context,
+		Swarm*                                             swarm,
+		Name                                               baseFilename,
+		unsigned int                                       columnWidth, 
+		unsigned int                                       decimalLength,
+		char*                                              borderString )		
+{
+  SwarmOutput* self = (SwarmOutput*)_SwarmOutput_DefaultNew( name );
+
+	_SwarmOutput_Init( self, context, swarm, baseFilename, columnWidth, decimalLength, borderString );
+	return self;
+}
+
+SwarmOutput* _SwarmOutput_New(  SWARMOUTPUT_DEFARGS  ) 
+{
+	SwarmOutput*		self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SwarmOutput) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (SwarmOutput*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* Virtual functions */
+	self->_printHeader                = _printHeader;
+	self->_printData                  = _printData;
+
+	return self;
+}
+
+void _SwarmOutput_Init( 
+		SwarmOutput*                                       self,
+		void*                                              context,
+		Swarm*                                             swarm,
+		Name                                               baseFilename,
+		unsigned int                                       columnWidth, 
+		unsigned int                                       decimalLength,
+		char*                                              borderString )
+{
+	SwarmVariable* swarmVariable;
+	ExtensionInfo_Index handle;
+	/* Add ourselves to the register for later retrieval by clients */
+	self->isConstructed = True;
+
+	self->swarm                  = swarm;
+	self->baseFilename           = baseFilename;
+
+	handle = ExtensionManager_Add( swarm->particleExtensionMgr, (Name)SwarmOutput_Type, sizeof( int )  );
+	swarmVariable = Swarm_NewScalarVariable( 
+			swarm,
+			"globalIndexVariable",
+			(ArithPointer) ExtensionManager_Get( swarm->particleExtensionMgr, 0, handle ), 
+			Variable_DataType_Int );
+	self->globalIndexVariable = swarmVariable->variable;
+
+	self->columnWidth = columnWidth;
+	self->borderString = StG_Strdup( borderString );
+	Stg_asprintf( &self->doubleFormatString, "%%%d.%dg", columnWidth, decimalLength );
+
+	EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_DumpClass ),	SwarmOutput_Execute, self );
+}
+
+
+void _SwarmOutput_Delete( void* swarmOutput ) {
+	SwarmOutput* self = (SwarmOutput*) swarmOutput;
+
+	Memory_Free( self->doubleFormatString );
+	Memory_Free( self->borderString );
+	_Stg_Component_Delete( self );
+}
+
+void _SwarmOutput_Print( void* _swarmOutput, Stream* stream ) {
+	SwarmOutput* self = (SwarmOutput*) _swarmOutput;
+
+	Journal_Printf( stream, "SwarmOutput - '%s'\n", self->name );
+	Stream_Indent( stream );
+	_Stg_Component_Print( self, stream );
+
+	Journal_PrintPointer( stream, self->_printHeader );
+	Journal_PrintPointer( stream, self->_printData );
+
+	Journal_Printf( stream, "Swarm - '%s'\n", self->swarm->name );
+	Journal_Printf( stream, "globalIndexVariable - '%s'\n", self->globalIndexVariable->name );
+
+	Stream_UnIndent( stream );
+}
+
+void* _SwarmOutput_Copy( const void* swarmOutput, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SwarmOutput*	self = (SwarmOutput*)swarmOutput;
+	SwarmOutput*	newSwarmOutput;
+	PtrMap*			map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newSwarmOutput = (SwarmOutput*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
+	
+	newSwarmOutput->_printHeader               = self->_printHeader;
+	newSwarmOutput->_printData                 = self->_printData  ;
+
+	newSwarmOutput->swarm                      = self->swarm;
+	newSwarmOutput->globalIndexVariable        = self->globalIndexVariable;
+
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+				
+	return (void*)newSwarmOutput;
+}
+
+
+void* _SwarmOutput_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(SwarmOutput);
+	Type                                                      type = SwarmOutput_Type;
+	Stg_Class_DeleteFunction*                              _delete = _SwarmOutput_Delete;
+	Stg_Class_PrintFunction*                                _print = _SwarmOutput_Print;
+	Stg_Class_CopyFunction*                                  _copy = _SwarmOutput_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _SwarmOutput_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _SwarmOutput_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _SwarmOutput_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _SwarmOutput_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _SwarmOutput_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _SwarmOutput_Destroy;
+	SwarmOutput_PrintHeaderFunction*                  _printHeader = _SwarmOutput_PrintHeader;
+	SwarmOutput_PrintDataFunction*                      _printData = _SwarmOutput_PrintData;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+		return (void*) _SwarmOutput_New(  SWARMOUTPUT_PASSARGS  );
+}
+void _SwarmOutput_AssignFromXML( void* swarmOutput, Stg_ComponentFactory* cf, void* data ) {
+	SwarmOutput*	        self         = (SwarmOutput*)swarmOutput;
+	Swarm*                  swarm;
+	Name                    baseFilename;
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !self->context  )
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	swarm        =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data   ) ;
+	baseFilename = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"baseFilename", self->name  );
+
+	_SwarmOutput_Init( 
+			self,
+			(AbstractContext*)self->context,
+			swarm, 
+			baseFilename, 
+			Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"columnWidth", 12  ), 
+			Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"decimalLength", 6  ), 
+			Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"borderString", "    " )  );
+}
+
+void _SwarmOutput_Build( void* swarmOutput, void* data ) {
+	SwarmOutput*	 self                = (SwarmOutput*)     swarmOutput;
+
+	Stg_Component_Build( self->globalIndexVariable, data, False );
+}
+
+void _SwarmOutput_Initialise( void* swarmOutput, void* data ) {
+	SwarmOutput*	 self                = (SwarmOutput*)     swarmOutput;
+	AbstractContext* context             = self->context;
+	Swarm*           swarm               = self->swarm;
+	Variable*        globalIndexVariable = self->globalIndexVariable;
+	Particle_Index   lParticle_I;
+	char*            filename;
+	Stream*          stream              = Journal_Register( Info_Type, (Name)SwarmOutput_Type  );
+
+   /* re-enable printing from current rank process */
+	Stream_SetPrintingRank( stream, context->rank );
+   
+	Stg_Component_Initialise( self->globalIndexVariable, context, False );
+
+   if( !context->loadFromCheckPoint ) _SwarmOutput_SetGlobalIndicies( self, context );
+
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		/* Open file */
+		Stg_asprintf( &filename, "%s.%05d.dat", self->baseFilename, Variable_GetValueInt( globalIndexVariable, lParticle_I ) );
+		if( context->loadFromCheckPoint )
+			Stream_AppendFile_WithPrependedPath( stream, context->outputPath, filename );
+		else
+			Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
+
+		/* Print to file */
+		SwarmOutput_PrintHeader( self, stream, lParticle_I, data );
+		Journal_Printf( stream, "\n" );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void _SwarmOutput_Execute( void* swarmOutput, void* data ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	AbstractContext*  context             = (AbstractContext*) data;
+	Swarm*            swarm               = self->swarm;
+	Variable*         globalIndexVariable = self->globalIndexVariable;
+	Particle_Index    lParticle_I;
+	char*             filename;
+	Stream*           stream              = Journal_Register( Info_Type, (Name)SwarmOutput_Type  );
+
+   /* re-enable printing from current rank process */
+	Stream_SetPrintingRank( stream, context->rank );
+
+	Variable_Update( globalIndexVariable );
+
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		/* Open file */
+		Stg_asprintf( &filename, "%s.%05d.dat", self->baseFilename, Variable_GetValueInt( globalIndexVariable, lParticle_I ) );
+		Stream_AppendFile_WithPrependedPath( stream, context->outputPath, filename );
+
+		/* Print to file */
+		SwarmOutput_PrintData( self, stream, lParticle_I, data );
+		Journal_Printf( stream, "\n" );
+		Stream_Flush( stream );
+		Stream_CloseAndFreeFile( stream );
+	}
+}
+
+void _SwarmOutput_Destroy( void* swarmOutput, void* data ) {
+}
+
+/*** Default Implementations ***/
+void _SwarmOutput_PrintHeader( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* data ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	char*             firstBorderString;
+
+	/* Print First Border with '#' in the front */
+	firstBorderString = StG_Strdup( self->borderString );
+	firstBorderString[0] = '#';
+	Journal_Printf( stream, firstBorderString );
+	Memory_Free( firstBorderString );
+
+	Journal_PrintString_WithLength( stream, "Timestep", self->columnWidth );
+
+	SwarmOutput_PrintString( self, stream, "Time" );
+	SwarmOutput_PrintString( self, stream, "CoordX" );
+	SwarmOutput_PrintString( self, stream, "CoordY" );
+	SwarmOutput_PrintString( self, stream, "CoordZ" );
+}
+
+void _SwarmOutput_PrintData( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* data ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	AbstractContext*  context             = (AbstractContext*) data;
+	Swarm*            swarm               = self->swarm;
+	GlobalParticle*   particle            = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+	double*           coord               = particle->coord;
+		
+	SwarmOutput_PrintValue( self, stream, context->timeStep );
+	SwarmOutput_PrintValue( self, stream, context->currentTime + AbstractContext_Dt( context ) );
+	SwarmOutput_PrintValue( self, stream, coord[ I_AXIS ] );
+	SwarmOutput_PrintValue( self, stream, coord[ J_AXIS ] );
+	SwarmOutput_PrintValue( self, stream, coord[ K_AXIS ] );
+}
+
+
+/** Virtual Function Wrappers */
+void SwarmOutput_Execute( void* swarmOutput, void* context ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+
+	self->_execute( self, context );
+}
+void SwarmOutput_PrintHeader( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* context ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	self->_printHeader( self, stream, lParticle_I, context );
+}
+void SwarmOutput_PrintData( void* swarmOutput, Stream* stream, Particle_Index lParticle_I, void* context ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	self->_printData( self, stream, lParticle_I, context );
+}
+
+void _SwarmOutput_SetGlobalIndicies( void* swarmOutput, void* data ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	AbstractContext*  context             = (AbstractContext*) data;
+	Swarm*            swarm               = self->swarm;
+	Variable*         globalIndexVariable = self->globalIndexVariable;
+	Particle_Index    lParticle_I;
+	Particle_Index    particleCount       = 0;
+	int               rank                = context->rank;
+	int               nproc               = context->nproc;
+	MPI_Status        status;
+
+	Variable_Update( globalIndexVariable );
+
+	/* Receive total number of particles from previous processor */
+	if ( rank != 0 ) {
+		MPI_Recv( &particleCount, 1, MPI_UNSIGNED, rank - 1, 0, context->communicator, &status );
+	}
+	
+	/* Assign value to particle */
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+		Variable_SetValueInt( globalIndexVariable, lParticle_I, particleCount );
+		particleCount++;
+	}
+
+	/* Send total number of particles next processor */
+	if ( rank != nproc - 1 ) {
+		MPI_Send( &particleCount, 1, MPI_UNSIGNED, rank + 1, 0, context->communicator );
+	}
+}
+
+void SwarmOutput_PrintString( void* swarmOutput, Stream* stream, Name string ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+
+	Journal_Printf( stream, "%s", self->borderString );
+	Journal_PrintString_WithLength( stream, string, self->columnWidth );
+}
+
+void SwarmOutput_PrintDouble( void* swarmOutput, Stream* stream, double value ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+
+	Journal_Printf( stream, "%s", self->borderString );
+	Journal_Printf( stream, self->doubleFormatString, value );
+}
+
+void SwarmOutput_PrintTuple( void* swarmOutput, Stream* stream, double* value, Index size ) {
+	SwarmOutput*	  self                = (SwarmOutput*)     swarmOutput;
+	Index             count;
+
+	Journal_Printf( stream, "%s", self->borderString );
+	for( count = 0 ; count < size ; count++ ) {
+		Journal_Printf( stream, self->doubleFormatString, value[count] );
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmShapeVC.c
--- a/Swarm/src/SwarmShapeVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,548 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SwarmShapeVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "SwarmShapeVC.h"
-
-#include "Swarm.h"
-#include <assert.h>
-#include <string.h>
-
-const Type SwarmShapeVC_Type = "SwarmShapeVC";
-const Name defaultSwarmShapeVCName = "defaultSwarmShapeVCName";
-
-/*-----------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-VariableCondition* SwarmShapeVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									data )
-{
-	return (VariableCondition*) SwarmShapeVC_New( defaultSwarmShapeVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Swarm*)data );
-}
-
-SwarmShapeVC* SwarmShapeVC_New(
-	Name									name,
-	AbstractContext*					context,
-	Name									_dictionaryEntryName, 
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									_swarm )
-{
-	SwarmShapeVC* self = (SwarmShapeVC*) _SwarmShapeVC_DefaultNew( name );
-
-	self->isConstructed = True;
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
-	_SwarmShapeVC_Init( self, _dictionaryEntryName, _swarm );
-
-	return self;
-}
-
-void* _SwarmShapeVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(SwarmShapeVC);
-	Type                                                       type = SwarmShapeVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _SwarmShapeVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _SwarmShapeVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _SwarmShapeVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _SwarmShapeVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _SwarmShapeVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _SwarmShapeVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _SwarmShapeVC_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _VariableCondition_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _SwarmShapeVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _SwarmShapeVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _SwarmShapeVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _SwarmShapeVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _SwarmShapeVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _SwarmShapeVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _SwarmShapeVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _SwarmShapeVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _SwarmShapeVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return (void*) _SwarmShapeVC_New(  SWARMSHAPEVC_PASSARGS  );
-}
-
-SwarmShapeVC* _SwarmShapeVC_New(  SWARMSHAPEVC_DEFARGS  ) {
-	SwarmShapeVC* self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(SwarmShapeVC) );
-	self = (SwarmShapeVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-	/* Virtual info */
-	
-	return self;
-}
-
-
-void _SwarmShapeVC_Init( void* variableCondition, Name _dictionaryEntryName, void* _swarm ) {
-	SwarmShapeVC* self = (SwarmShapeVC*) variableCondition;
-
-	self->conFunc_Register = condFunc_Register; 
-	
-	self->_dictionaryEntryName = _dictionaryEntryName;
-	self->_swarm                = (Swarm*)_swarm;
-	self->_entryTbl            = 0;
-	self->_entryCount          = 0;
-
-	assert( _swarm && Stg_Class_IsInstance( _swarm, Swarm_Type ) );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-
-void _SwarmShapeVC_Delete( void* variableCondition ) {
-	SwarmShapeVC* self = (SwarmShapeVC*)variableCondition;
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Delete(self);
-}
-
-void _SwarmShapeVC_Destroy( void* variableCondition, void* data ) {
-	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
-	
-	if ( self->_entryTbl ) 
-		Memory_Free(self->_entryTbl);
-
-	if ( self->shapeName )
-          Memory_Free( self->shapeName );
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Destroy( self, data );
-}
-
-void _SwarmShapeVC_Print(void* variableCondition, Stream* stream) {
-	SwarmShapeVC*                self = (SwarmShapeVC*)variableCondition;
-	SwarmShapeVC_Entry_Index     entry_I;
-	Index                   array_I;
-	
-	/* General info */
-	Journal_Printf( stream, "SwarmShapeVC (ptr): %p\n", self);
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	Journal_Printf( stream, "\tdictionary (ptr): %p\n", self->dictionary);
-	Journal_Printf( stream, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-	if (self->_dictionaryEntryName)
-		Journal_Printf( stream, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-	if ( self->_shape )
-		Journal_Printf( stream, "\t_shape: %s '%s'\n", self->_shape->type, self->_shape->name );
-	
-	Journal_Printf( stream, "\t_entryCount: %u\n", self->_entryCount);
-	Journal_Printf( stream, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-	if (self->_entryTbl) {
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++) {
-			Journal_Printf( stream, "\t\t_entryTbl[%u]:\n", entry_I);
-			Journal_Printf( stream, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-			if (self->_entryTbl[entry_I].varName)
-				Journal_Printf( stream, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-			Journal_Printf( stream, "\t\t\tvalue:\n");
-			switch (self->_entryTbl[entry_I].value.type) {
-				case VC_ValueType_Double:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Double\n" );
-					Journal_Printf( stream, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-					break;
-					
-				case VC_ValueType_Int:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Int\n" );
-					Journal_Printf( stream, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-					break;
-					
-				case VC_ValueType_Short:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Short\n" );
-					Journal_Printf( stream, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-					break;
-					
-				case VC_ValueType_Char:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Char\n");
-					Journal_Printf( stream, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-					break;
-					
-				case VC_ValueType_Ptr:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-					Journal_Printf( stream, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-					break;
-					
-				case VC_ValueType_DoubleArray:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-					Journal_Printf( stream, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-					Journal_Printf( stream, "\t\t\t\tasDoubleArray (ptr): %p\n", 
-						self->_entryTbl[entry_I].value.as.typeArray.array);
-					if (self->_entryTbl[entry_I].value.as.typeArray.array)
-						for ( array_I = 0;  array_I < self->_entryTbl[entry_I].value.as.typeArray.size;  array_I++)
-							Journal_Printf( stream, "\t\t\t\tasDoubleArray[%u]: %g\n",  array_I,
-								self->_entryTbl[entry_I].value.as.typeArray.array[ array_I]);
-					break;
-					
-				case VC_ValueType_CFIndex:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-					Journal_Printf( stream, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-					break;
-			}
-		}
-	}
-	Journal_Printf( stream, "\t_swarm (ptr): %p\n", self->_swarm);
-	
-	/* Print parent */
-	_VariableCondition_Print( self );
-}
-
-
-void* _SwarmShapeVC_Copy( const void* variableCondition, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-	SwarmShapeVC*   self           = (SwarmShapeVC*)variableCondition;
-	SwarmShapeVC*   newSwarmShapeVC;
-	PtrMap*         map            = ptrMap;
-	Bool            ownMap         = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newSwarmShapeVC = (SwarmShapeVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-	newSwarmShapeVC->_dictionaryEntryName = self->_dictionaryEntryName;
-	newSwarmShapeVC->_shape = self->_shape;
-	newSwarmShapeVC->_entryCount = self->_entryCount;
-	
-	if( deep ) {
-		newSwarmShapeVC->_swarm = (Swarm*)Stg_Class_Copy( self->_swarm, NULL, deep, nameExt, map );
-		
-		if( (newSwarmShapeVC->_entryTbl = (SwarmShapeVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-			newSwarmShapeVC->_entryTbl = Memory_Alloc_Array( SwarmShapeVC_Entry, newSwarmShapeVC->_entryCount, "SwarmShapeVC->_entryTbl");
-			memcpy( newSwarmShapeVC->_entryTbl, self->_entryTbl, sizeof(SwarmShapeVC_Entry) * newSwarmShapeVC->_entryCount );
-			PtrMap_Append( map, newSwarmShapeVC->_entryTbl, self->_entryTbl );
-		}
-	}
-	else {
-		newSwarmShapeVC->_swarm = self->_swarm;
-		newSwarmShapeVC->_entryTbl = self->_entryTbl;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newSwarmShapeVC;
-}
-	
-/****************** Stg_Component Virtual Functions ******************/
-void _SwarmShapeVC_AssignFromXML( void* variableCondition, Stg_ComponentFactory* cf, void* data ) {
-	SwarmShapeVC*		self = (SwarmShapeVC*)variableCondition;
-	void*					conFunc_Register = NULL;
-	void*					variable_Register = NULL;
-	AbstractContext*	context;
-
-	self = Stg_ComponentFactory_ConstructByName( cf, (Name)self->name, SwarmShapeVC, False, data  );
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
-
-	variable_Register = context->variable_Register; 
-	assert( variable_Register  );
-	self->variable_Register = (Variable_Register*)variable_Register;
-
-	_VariableCondition_Init( self, context, (Variable_Register*)variable_Register, (ConditionFunction_Register*)conFunc_Register, NULL );
-	
-	self->dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-}
-
-void _SwarmShapeVC_Build(  void* variableCondition, void* data ) {
-	SwarmShapeVC*		self 	= (SwarmShapeVC*)variableCondition;
-	AbstractContext* 	context = (AbstractContext*) data;
-	
-	assert( context && Stg_Class_IsInstance( context, AbstractContext_Type ) );
-
-	self->_swarm = Stg_ComponentFactory_ConstructByKey( context->CF, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, 0  ) ; 
-	assert( self->_swarm  );
-	
-	self->_shape = Stg_ComponentFactory_ConstructByKey( context->CF, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, 0 /* dummy */  ) ;
-	assert( self->_shape  );
-
-	_VariableCondition_Build( self, data );
-
-	Stg_Component_Build( self->_shape, data, False );
-}
-	
-/****************** VariableCondition Virtual Functions ******************/
-void _SwarmShapeVC_BuildSelf(  void* variableCondition, void* data /* for build phase */ ) {
-	SwarmShapeVC*         	self    = (SwarmShapeVC*)variableCondition;
-	AbstractContext* 	context = (AbstractContext*) data;
-
-	assert( context && Stg_Class_IsInstance( context, AbstractContext_Type ) );
-
-	/* dave - 06.08.07 */
-	/*self->shapeName = Stg_ComponentFactory_GetString( context->CF, self->name, (Dictionary_Entry_Key)"Shape", "" );
-*/
-	/*Journal_Firewall( strlen( self->shapeName  ) > 0, Journal_MyStream( Error_Type, self ),
-			"You need to fill out the 'Shape' dictionary entry for this SwarmShapeVC.\n" );*/
-	/*assert( self->shapeName );*/
-	
-	/*Stg_Component_Build( self->_swarm, data, False );*/ /* remove this call? */
-	Stg_Component_Build( self->_shape, data, False );
-}
-
-/* added to call the porisity field standard condition plugin */
-void _SwarmShapeVC_Initialise(  void* variableCondition, void* data ) {
-	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
-
-	_VariableCondition_Initialise( self, data );
-
-	/* need to call the standard condition function here */
-}
-	
-void _SwarmShapeVC_PrintConcise( void* variableCondition, Stream* stream ) {
-	SwarmShapeVC* self = (SwarmShapeVC*) variableCondition;
-	
-	Journal_Printf( stream, "\ttype: %s, Shape: %s '%s'", self->type, self->_shape->type, self->_shape->name );
-}
-
-void _SwarmShapeVC_ReadDictionary( void* variableCondition, void* dict /**/ ) {
-	SwarmShapeVC*                  	self = (SwarmShapeVC*)variableCondition;
-	Dictionary_Entry_Value*   	vcDictVal;
-	Dictionary_Entry_Value    	_vcDictVal;
-	Dictionary_Entry_Value*   	varsVal;
-	SwarmShapeVC_Entry_Index	entry_I;
-	Dictionary*			dictionary = (Dictionary*)dict; /**/
-	
-	/* Find dictionary entry */
-	if (self->_dictionaryEntryName)
-		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
-	else {
-		vcDictVal = &_vcDictVal;
-		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
-	}
-
-	if (vcDictVal) {
-		/* Get Name of Shape from dictionary - Grab pointer to shape later on */
-		self->shapeName = StG_Strdup( 
-				Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"Shape" ))  );
-
-		/* Obtain the variable entries */
-		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-		self->_entryTbl = Memory_Alloc_Array( SwarmShapeVC_Entry, self->_entryCount, "SwarmShapeVC->_entryTbl" );
-		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
-			char*			valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
-				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-			if (0 == strcasecmp(valType, "func")) {
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-				if ( cfIndex == (Index) -1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-						"definition of swarmShapeVC \"%s\" (applies to shape \"%s\"), the cond. func. applied to "
-						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-						__func__, self->_dictionaryEntryName, self->shapeName,
-						self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}
-			else if (0 == strcasecmp(valType, "array"))
-			{
-				Dictionary_Entry_Value*	valueElement;
-				Index			i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
-					self->_entryTbl[entry_I].value.as.typeArray.size, "SwarmShapeVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-				{
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
-						Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
-				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
-			{
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_DPrintf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else
-	{
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-	}
-}
-
-IndexSet* _SwarmShapeVC_GetSet(void* variableCondition) {
-	SwarmShapeVC*		self = (SwarmShapeVC*)variableCondition;
-	Swarm*			swarm = self->_swarm;
-	IndexSet*		set;
-	Index           	particleDomainCount;
-	unsigned		particleIndex;
-	GlobalParticle*		particle; /* check that this is ok for the given swarm type */
-
-	/*Stg_Component_Initialise( swarm, NULL, False );*/
-	/*Stg_Component_Build( swarm, NULL, False );*/
-
-	particleDomainCount = swarm->particleLocalCount; /* sizeof(swarm particle array) - think this is right?? */
-	set = IndexSet_New( particleDomainCount );
-
-	for( particleIndex = 0; particleIndex < particleDomainCount; particleIndex++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, particleIndex );
-		if( Stg_Shape_IsCoordInside( self->_shape, particle->coord ) ) {
-			IndexSet_Add( set, particleIndex );
-		}	
-	}
-
-	return set;
-}
-
-VariableCondition_VariableIndex _SwarmShapeVC_GetVariableCount(void* variableCondition, Index globalIndex) {
-	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
-
-	return self->_entryCount;
-}
-
-Variable_Index _SwarmShapeVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex) {
-	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
-	Variable_Index	searchedIndex = 0;
-	Stream*			errorStr = Journal_Register( Error_Type, (Name)self->type );
-	Name				varName;
-	Swarm*			swarm = self->_swarm;
-	char*				swarmVarName;
-
-	varName = self->_entryTbl[varIndex].varName;
-
-	swarmVarName = (char*)calloc( strlen(swarm->name) + 1 + strlen(varName ) + 1, sizeof(char) );
-	strcat( swarmVarName, swarm->name );
-	strcat( swarmVarName, "-" );
-	strcat( swarmVarName, varName );
-	/*searchedIndex = (Variable_Index)-1;
-	for( swarmVar_I = 0; swarmVar_I < self->_swarm->nSwarmVars; swarmVar_I++ ) {
-		if( swarm->swarmVars[swarmVar_I]->name && !strcmp(swarmVarName, swarm->swarmVars[swarmVar_I]->name) ) {
-			searchedIndex = swarmVar_I;
-		}
-	}*/
-	searchedIndex = Variable_Register_GetIndex(self->variable_Register, swarmVarName );
-	
-	Journal_Firewall( 
-			( searchedIndex < self->variable_Register->count ),
-			errorStr,
-			"Error- in %s: searching for index of varIndex %u (\"%s\") at global node number %u failed"
-			" - register returned index %u, greater than count %u.\n",
-			__func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
-
-	return searchedIndex; 
-}
-
-
-VariableCondition_ValueIndex _SwarmShapeVC_GetValueIndex(
-		void*                                       variableCondition, 
-		Index                                       globalIndex, 
-		VariableCondition_VariableIndex             varIndex )
-{
-	return varIndex;
-}
-
-
-VariableCondition_ValueIndex _SwarmShapeVC_GetValueCount(void* variableCondition) {
-	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-VariableCondition_Value _SwarmShapeVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex) {
-	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
-
-	return self->_entryTbl[valIndex].value;
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmShapeVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SwarmShapeVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,548 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SwarmShapeVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "SwarmShapeVC.h"
+
+#include "Swarm.h"
+#include <assert.h>
+#include <string.h>
+
+const Type SwarmShapeVC_Type = "SwarmShapeVC";
+const Name defaultSwarmShapeVCName = "defaultSwarmShapeVCName";
+
+/*-----------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+VariableCondition* SwarmShapeVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									data )
+{
+	return (VariableCondition*) SwarmShapeVC_New( defaultSwarmShapeVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Swarm*)data );
+}
+
+SwarmShapeVC* SwarmShapeVC_New(
+	Name									name,
+	AbstractContext*					context,
+	Name									_dictionaryEntryName, 
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									_swarm )
+{
+	SwarmShapeVC* self = (SwarmShapeVC*) _SwarmShapeVC_DefaultNew( name );
+
+	self->isConstructed = True;
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
+	_SwarmShapeVC_Init( self, _dictionaryEntryName, _swarm );
+
+	return self;
+}
+
+void* _SwarmShapeVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(SwarmShapeVC);
+	Type                                                       type = SwarmShapeVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _SwarmShapeVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _SwarmShapeVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _SwarmShapeVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _SwarmShapeVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _SwarmShapeVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _SwarmShapeVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _SwarmShapeVC_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _VariableCondition_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _SwarmShapeVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _SwarmShapeVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _SwarmShapeVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _SwarmShapeVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _SwarmShapeVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _SwarmShapeVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _SwarmShapeVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _SwarmShapeVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _SwarmShapeVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return (void*) _SwarmShapeVC_New(  SWARMSHAPEVC_PASSARGS  );
+}
+
+SwarmShapeVC* _SwarmShapeVC_New(  SWARMSHAPEVC_DEFARGS  ) {
+	SwarmShapeVC* self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(SwarmShapeVC) );
+	self = (SwarmShapeVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+	/* Virtual info */
+	
+	return self;
+}
+
+
+void _SwarmShapeVC_Init( void* variableCondition, Name _dictionaryEntryName, void* _swarm ) {
+	SwarmShapeVC* self = (SwarmShapeVC*) variableCondition;
+
+	self->conFunc_Register = condFunc_Register; 
+	
+	self->_dictionaryEntryName = _dictionaryEntryName;
+	self->_swarm                = (Swarm*)_swarm;
+	self->_entryTbl            = 0;
+	self->_entryCount          = 0;
+
+	assert( _swarm && Stg_Class_IsInstance( _swarm, Swarm_Type ) );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+
+void _SwarmShapeVC_Delete( void* variableCondition ) {
+	SwarmShapeVC* self = (SwarmShapeVC*)variableCondition;
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Delete(self);
+}
+
+void _SwarmShapeVC_Destroy( void* variableCondition, void* data ) {
+	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
+	
+	if ( self->_entryTbl ) 
+		Memory_Free(self->_entryTbl);
+
+	if ( self->shapeName )
+          Memory_Free( self->shapeName );
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Destroy( self, data );
+}
+
+void _SwarmShapeVC_Print(void* variableCondition, Stream* stream) {
+	SwarmShapeVC*                self = (SwarmShapeVC*)variableCondition;
+	SwarmShapeVC_Entry_Index     entry_I;
+	Index                   array_I;
+	
+	/* General info */
+	Journal_Printf( stream, "SwarmShapeVC (ptr): %p\n", self);
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	Journal_Printf( stream, "\tdictionary (ptr): %p\n", self->dictionary);
+	Journal_Printf( stream, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+	if (self->_dictionaryEntryName)
+		Journal_Printf( stream, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+	if ( self->_shape )
+		Journal_Printf( stream, "\t_shape: %s '%s'\n", self->_shape->type, self->_shape->name );
+	
+	Journal_Printf( stream, "\t_entryCount: %u\n", self->_entryCount);
+	Journal_Printf( stream, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+	if (self->_entryTbl) {
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++) {
+			Journal_Printf( stream, "\t\t_entryTbl[%u]:\n", entry_I);
+			Journal_Printf( stream, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+			if (self->_entryTbl[entry_I].varName)
+				Journal_Printf( stream, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+			Journal_Printf( stream, "\t\t\tvalue:\n");
+			switch (self->_entryTbl[entry_I].value.type) {
+				case VC_ValueType_Double:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Double\n" );
+					Journal_Printf( stream, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+					break;
+					
+				case VC_ValueType_Int:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Int\n" );
+					Journal_Printf( stream, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+					break;
+					
+				case VC_ValueType_Short:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Short\n" );
+					Journal_Printf( stream, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+					break;
+					
+				case VC_ValueType_Char:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Char\n");
+					Journal_Printf( stream, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+					break;
+					
+				case VC_ValueType_Ptr:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+					Journal_Printf( stream, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+					break;
+					
+				case VC_ValueType_DoubleArray:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+					Journal_Printf( stream, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+					Journal_Printf( stream, "\t\t\t\tasDoubleArray (ptr): %p\n", 
+						self->_entryTbl[entry_I].value.as.typeArray.array);
+					if (self->_entryTbl[entry_I].value.as.typeArray.array)
+						for ( array_I = 0;  array_I < self->_entryTbl[entry_I].value.as.typeArray.size;  array_I++)
+							Journal_Printf( stream, "\t\t\t\tasDoubleArray[%u]: %g\n",  array_I,
+								self->_entryTbl[entry_I].value.as.typeArray.array[ array_I]);
+					break;
+					
+				case VC_ValueType_CFIndex:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+					Journal_Printf( stream, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+					break;
+			}
+		}
+	}
+	Journal_Printf( stream, "\t_swarm (ptr): %p\n", self->_swarm);
+	
+	/* Print parent */
+	_VariableCondition_Print( self );
+}
+
+
+void* _SwarmShapeVC_Copy( const void* variableCondition, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+	SwarmShapeVC*   self           = (SwarmShapeVC*)variableCondition;
+	SwarmShapeVC*   newSwarmShapeVC;
+	PtrMap*         map            = ptrMap;
+	Bool            ownMap         = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newSwarmShapeVC = (SwarmShapeVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+	newSwarmShapeVC->_dictionaryEntryName = self->_dictionaryEntryName;
+	newSwarmShapeVC->_shape = self->_shape;
+	newSwarmShapeVC->_entryCount = self->_entryCount;
+	
+	if( deep ) {
+		newSwarmShapeVC->_swarm = (Swarm*)Stg_Class_Copy( self->_swarm, NULL, deep, nameExt, map );
+		
+		if( (newSwarmShapeVC->_entryTbl = (SwarmShapeVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+			newSwarmShapeVC->_entryTbl = Memory_Alloc_Array( SwarmShapeVC_Entry, newSwarmShapeVC->_entryCount, "SwarmShapeVC->_entryTbl");
+			memcpy( newSwarmShapeVC->_entryTbl, self->_entryTbl, sizeof(SwarmShapeVC_Entry) * newSwarmShapeVC->_entryCount );
+			PtrMap_Append( map, newSwarmShapeVC->_entryTbl, self->_entryTbl );
+		}
+	}
+	else {
+		newSwarmShapeVC->_swarm = self->_swarm;
+		newSwarmShapeVC->_entryTbl = self->_entryTbl;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newSwarmShapeVC;
+}
+	
+/****************** Stg_Component Virtual Functions ******************/
+void _SwarmShapeVC_AssignFromXML( void* variableCondition, Stg_ComponentFactory* cf, void* data ) {
+	SwarmShapeVC*		self = (SwarmShapeVC*)variableCondition;
+	void*					conFunc_Register = NULL;
+	void*					variable_Register = NULL;
+	AbstractContext*	context;
+
+	self = Stg_ComponentFactory_ConstructByName( cf, (Name)self->name, SwarmShapeVC, False, data  );
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data );
+
+	variable_Register = context->variable_Register; 
+	assert( variable_Register  );
+	self->variable_Register = (Variable_Register*)variable_Register;
+
+	_VariableCondition_Init( self, context, (Variable_Register*)variable_Register, (ConditionFunction_Register*)conFunc_Register, NULL );
+	
+	self->dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+}
+
+void _SwarmShapeVC_Build(  void* variableCondition, void* data ) {
+	SwarmShapeVC*		self 	= (SwarmShapeVC*)variableCondition;
+	AbstractContext* 	context = (AbstractContext*) data;
+	
+	assert( context && Stg_Class_IsInstance( context, AbstractContext_Type ) );
+
+	self->_swarm = Stg_ComponentFactory_ConstructByKey( context->CF, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, 0  ) ; 
+	assert( self->_swarm  );
+	
+	self->_shape = Stg_ComponentFactory_ConstructByKey( context->CF, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, 0 /* dummy */  ) ;
+	assert( self->_shape  );
+
+	_VariableCondition_Build( self, data );
+
+	Stg_Component_Build( self->_shape, data, False );
+}
+	
+/****************** VariableCondition Virtual Functions ******************/
+void _SwarmShapeVC_BuildSelf(  void* variableCondition, void* data /* for build phase */ ) {
+	SwarmShapeVC*         	self    = (SwarmShapeVC*)variableCondition;
+	AbstractContext* 	context = (AbstractContext*) data;
+
+	assert( context && Stg_Class_IsInstance( context, AbstractContext_Type ) );
+
+	/* dave - 06.08.07 */
+	/*self->shapeName = Stg_ComponentFactory_GetString( context->CF, self->name, (Dictionary_Entry_Key)"Shape", "" );
+*/
+	/*Journal_Firewall( strlen( self->shapeName  ) > 0, Journal_MyStream( Error_Type, self ),
+			"You need to fill out the 'Shape' dictionary entry for this SwarmShapeVC.\n" );*/
+	/*assert( self->shapeName );*/
+	
+	/*Stg_Component_Build( self->_swarm, data, False );*/ /* remove this call? */
+	Stg_Component_Build( self->_shape, data, False );
+}
+
+/* added to call the porisity field standard condition plugin */
+void _SwarmShapeVC_Initialise(  void* variableCondition, void* data ) {
+	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
+
+	_VariableCondition_Initialise( self, data );
+
+	/* need to call the standard condition function here */
+}
+	
+void _SwarmShapeVC_PrintConcise( void* variableCondition, Stream* stream ) {
+	SwarmShapeVC* self = (SwarmShapeVC*) variableCondition;
+	
+	Journal_Printf( stream, "\ttype: %s, Shape: %s '%s'", self->type, self->_shape->type, self->_shape->name );
+}
+
+void _SwarmShapeVC_ReadDictionary( void* variableCondition, void* dict /**/ ) {
+	SwarmShapeVC*                  	self = (SwarmShapeVC*)variableCondition;
+	Dictionary_Entry_Value*   	vcDictVal;
+	Dictionary_Entry_Value    	_vcDictVal;
+	Dictionary_Entry_Value*   	varsVal;
+	SwarmShapeVC_Entry_Index	entry_I;
+	Dictionary*			dictionary = (Dictionary*)dict; /**/
+	
+	/* Find dictionary entry */
+	if (self->_dictionaryEntryName)
+		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
+	else {
+		vcDictVal = &_vcDictVal;
+		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
+	}
+
+	if (vcDictVal) {
+		/* Get Name of Shape from dictionary - Grab pointer to shape later on */
+		self->shapeName = StG_Strdup( 
+				Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"Shape" ))  );
+
+		/* Obtain the variable entries */
+		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+		self->_entryTbl = Memory_Alloc_Array( SwarmShapeVC_Entry, self->_entryCount, "SwarmShapeVC->_entryTbl" );
+		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
+			char*			valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
+				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+			if (0 == strcasecmp(valType, "func")) {
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+				if ( cfIndex == (Index) -1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+						"definition of swarmShapeVC \"%s\" (applies to shape \"%s\"), the cond. func. applied to "
+						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+						__func__, self->_dictionaryEntryName, self->shapeName,
+						self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}
+			else if (0 == strcasecmp(valType, "array"))
+			{
+				Dictionary_Entry_Value*	valueElement;
+				Index			i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
+					self->_entryTbl[entry_I].value.as.typeArray.size, "SwarmShapeVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+				{
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
+						Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
+				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
+			{
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_DPrintf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else
+	{
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+	}
+}
+
+IndexSet* _SwarmShapeVC_GetSet(void* variableCondition) {
+	SwarmShapeVC*		self = (SwarmShapeVC*)variableCondition;
+	Swarm*			swarm = self->_swarm;
+	IndexSet*		set;
+	Index           	particleDomainCount;
+	unsigned		particleIndex;
+	GlobalParticle*		particle; /* check that this is ok for the given swarm type */
+
+	/*Stg_Component_Initialise( swarm, NULL, False );*/
+	/*Stg_Component_Build( swarm, NULL, False );*/
+
+	particleDomainCount = swarm->particleLocalCount; /* sizeof(swarm particle array) - think this is right?? */
+	set = IndexSet_New( particleDomainCount );
+
+	for( particleIndex = 0; particleIndex < particleDomainCount; particleIndex++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, particleIndex );
+		if( Stg_Shape_IsCoordInside( self->_shape, particle->coord ) ) {
+			IndexSet_Add( set, particleIndex );
+		}	
+	}
+
+	return set;
+}
+
+VariableCondition_VariableIndex _SwarmShapeVC_GetVariableCount(void* variableCondition, Index globalIndex) {
+	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
+
+	return self->_entryCount;
+}
+
+Variable_Index _SwarmShapeVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex) {
+	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
+	Variable_Index	searchedIndex = 0;
+	Stream*			errorStr = Journal_Register( Error_Type, (Name)self->type );
+	Name				varName;
+	Swarm*			swarm = self->_swarm;
+	char*				swarmVarName;
+
+	varName = self->_entryTbl[varIndex].varName;
+
+	swarmVarName = (char*)calloc( strlen(swarm->name) + 1 + strlen(varName ) + 1, sizeof(char) );
+	strcat( swarmVarName, swarm->name );
+	strcat( swarmVarName, "-" );
+	strcat( swarmVarName, varName );
+	/*searchedIndex = (Variable_Index)-1;
+	for( swarmVar_I = 0; swarmVar_I < self->_swarm->nSwarmVars; swarmVar_I++ ) {
+		if( swarm->swarmVars[swarmVar_I]->name && !strcmp(swarmVarName, swarm->swarmVars[swarmVar_I]->name) ) {
+			searchedIndex = swarmVar_I;
+		}
+	}*/
+	searchedIndex = Variable_Register_GetIndex(self->variable_Register, swarmVarName );
+	
+	Journal_Firewall( 
+			( searchedIndex < self->variable_Register->count ),
+			errorStr,
+			"Error- in %s: searching for index of varIndex %u (\"%s\") at global node number %u failed"
+			" - register returned index %u, greater than count %u.\n",
+			__func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
+
+	return searchedIndex; 
+}
+
+
+VariableCondition_ValueIndex _SwarmShapeVC_GetValueIndex(
+		void*                                       variableCondition, 
+		Index                                       globalIndex, 
+		VariableCondition_VariableIndex             varIndex )
+{
+	return varIndex;
+}
+
+
+VariableCondition_ValueIndex _SwarmShapeVC_GetValueCount(void* variableCondition) {
+	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+VariableCondition_Value _SwarmShapeVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex) {
+	SwarmShapeVC*	self = (SwarmShapeVC*)variableCondition;
+
+	return self->_entryTbl[valIndex].value;
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmVariable.c
--- a/Swarm/src/SwarmVariable.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,378 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SwarmVariable.c 4139 2007-06-12 02:39:52Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "SwarmClass.h"
-#include "SwarmVariable_Register.h"
-#include "SwarmVariable.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type SwarmVariable_Type = "SwarmVariable";
-
-SwarmVariable* SwarmVariable_New(		
-	Name					name,
-	AbstractContext*	context,
-	Swarm*				swarm,
-	Variable*			variable,
-	Index					dofCount )
-{
-	SwarmVariable* self = (SwarmVariable*) _SwarmVariable_DefaultNew( name );
-
-	self->isConstructed = True;
-	_SwarmVariable_Init( self, context, swarm, variable, dofCount );
-
-	return self;
-}
-
-void* _SwarmVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(SwarmVariable);
-	Type                                                         type = SwarmVariable_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _SwarmVariable_Delete;
-	Stg_Class_PrintFunction*                                   _print = _SwarmVariable_Print;
-	Stg_Class_CopyFunction*                                     _copy = _SwarmVariable_Copy;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _SwarmVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _SwarmVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _SwarmVariable_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _SwarmVariable_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _SwarmVariable_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _SwarmVariable_Destroy;
-	AllocationType                                 nameAllocationType = NON_GLOBAL;
-	SwarmVariable_ValueAtFunction*                           _valueAt = _SwarmVariable_ValueAt;
-	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _SwarmVariable_GetMinGlobalMagnitude;
-	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _SwarmVariable_GetMaxGlobalMagnitude;
-
-	return (void*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
-}
-
-SwarmVariable* _SwarmVariable_New(  SWARMVARIABLE_DEFARGS  ) {
-	SwarmVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SwarmVariable) );
-	self = (SwarmVariable*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* Virtual functions */
-	self->_valueAt						= _valueAt;
-	self->_getMinGlobalMagnitude	= _getMinGlobalMagnitude;
-	self->_getMaxGlobalMagnitude	= _getMaxGlobalMagnitude;
-
-	return self;
-}
-
-void _SwarmVariable_Init( void* swarmVariable, AbstractContext* context, Swarm* swarm, Variable* variable, Index dofCount ) {
-	SwarmVariable* self = (SwarmVariable*) swarmVariable;
-
-	self->context                   = context;
-	self->swarm                     = swarm;
-	self->variable                  = variable;
-	self->dofCount                  = dofCount;
-	self->swarmVariable_Register    = swarm->swarmVariable_Register;
-	self->dim                       = swarm->dim;
-   self->isCheckpointedAndReloaded = True;
-	
-	if( variable )
-		Swarm_AddVariable( swarm, self );
-	if ( self->swarmVariable_Register != NULL )	
-		SwarmVariable_Register_Add( self->swarmVariable_Register, self );
-}
-
-void _SwarmVariable_Delete( void* swarmVariable ) {
-	SwarmVariable* self = (SwarmVariable*) swarmVariable;
-
-	_Stg_Component_Delete( self );
-}
-
-void _SwarmVariable_Print( void* _swarmVariable, Stream* stream ) {
-	SwarmVariable* self = (SwarmVariable*) _swarmVariable;
-
-	Journal_Printf( stream, "SwarmVariable - '%s'\n", self->name );
-	Stream_Indent( stream );
-	_Stg_Component_Print( self, stream );
-
-	Journal_PrintPointer( stream, self->_valueAt );
-	Journal_PrintPointer( stream, self->_getMinGlobalMagnitude );
-	Journal_PrintPointer( stream, self->_getMaxGlobalMagnitude );
-
-	Journal_Printf( stream, "Swarm - '%s'\n", self->swarm->name );
-	if ( self->variable != NULL )
-		Journal_Printf( stream, "Variable - '%s'\n", self->variable->name );
-
-	Journal_PrintValue( stream, self->dofCount );
-	Journal_PrintPointer( stream, self->swarmVariable_Register );
-	Stream_UnIndent( stream );
-}
-
-void* _SwarmVariable_Copy( const void* swarmVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	SwarmVariable*	newSwarmVariable;
-	PtrMap*			map = ptrMap;
-	Bool				ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newSwarmVariable = (SwarmVariable*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
-	
-	newSwarmVariable->_valueAt						= self->_valueAt;
-	newSwarmVariable->_getMinGlobalMagnitude	= self->_getMinGlobalMagnitude;
-	newSwarmVariable->_getMaxGlobalMagnitude	= self->_getMaxGlobalMagnitude;
-
-	newSwarmVariable->swarm							= self->swarm;
-	newSwarmVariable->variable						= self->variable;
-	newSwarmVariable->dofCount						= self->dofCount;
-	newSwarmVariable->swarmVariable_Register	= self->swarmVariable_Register;
-
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-				
-	return (void*)newSwarmVariable;
-}
-
-void _SwarmVariable_AssignFromXML( void* swarmVariable, Stg_ComponentFactory* cf, void* data ) {
-	SwarmVariable*		self = (SwarmVariable*)swarmVariable;
-	Swarm*				swarm;
-	Variable*			variable;
-	Index					dofCount;
-	AbstractContext*	context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data  );
-	variable =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Variable", Variable, False, data  );
-	dofCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"dofCount", 0  );
-
-	_SwarmVariable_Init( self, context, swarm, variable, dofCount );
-}
-
-void _SwarmVariable_Build( void* swarmVariable, void* data ) {
-	SwarmVariable* self = (SwarmVariable*)swarmVariable;
-
-	if ( self->variable )
-		Stg_Component_Build( self->variable, data, False );
-}
-
-void _SwarmVariable_Initialise( void* swarmVariable, void* data ) {
-	SwarmVariable* self = (SwarmVariable*)swarmVariable;
-
-	if ( self->variable ) {
-		Variable_Update( self->variable );
-		Stg_Component_Initialise( self->variable, data, False );
-	}
-}
-
-void _SwarmVariable_Execute( void* swarmVariable, void* data ) {
-}
-
-void _SwarmVariable_Destroy( void* swarmVariable, void* data ) {
-	SwarmVariable* self = (SwarmVariable*)swarmVariable;
-   
-   Stg_Component_Destroy( self->swarm, data, False );
-   if( self->variable )
-		Stg_Component_Destroy(self->variable, data, False);
-}
-
-double SwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	return self->_getMinGlobalMagnitude( self );
-}
-
-double SwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	return self->_getMaxGlobalMagnitude( self );
-}
-
-/*** Default Implementations ***/
-
-void _SwarmVariable_ValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	Variable*		variable = self->variable;
-
-	switch( variable->dataTypes[0] ) {
-		case Variable_DataType_Double:
-			self->_valueAt = _SwarmVariable_ValueAtDouble;
-			break;
-		case Variable_DataType_Int:
-			self->_valueAt = _SwarmVariable_ValueAtInt;
-			break;
-		case Variable_DataType_Float:
-			self->_valueAt = _SwarmVariable_ValueAtFloat;
-			break;
-		case Variable_DataType_Char:
-			self->_valueAt = _SwarmVariable_ValueAtChar;
-			break;
-		case Variable_DataType_Short:
-			self->_valueAt = _SwarmVariable_ValueAtShort;
-			break;
-		default:
-			assert(0);
-	}
-	SwarmVariable_ValueAt( self, lParticle_I, value );
-}
-	
-void _SwarmVariable_ValueAtDouble( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	double*			dataPtr;
-
-	dataPtr = Variable_GetPtrDouble( self->variable, lParticle_I );
-	memcpy( value, dataPtr, sizeof(double) * self->dofCount );
-}
-
-void _SwarmVariable_ValueAtInt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	Variable*		variable = self->variable;
-	Dof_Index		dofCount = self->dofCount;
-	Dof_Index		dof_I;
-
-	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
-		value[ dof_I ] = (double) Variable_GetValueAtInt( variable, lParticle_I, dof_I );
-	}
-}
-
-void _SwarmVariable_ValueAtFloat( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	Variable*		variable = self->variable;
-	Dof_Index		dofCount = self->dofCount;
-	Dof_Index		dof_I;
-
-	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
-		value[ dof_I ] = (double) Variable_GetValueAtFloat( variable, lParticle_I, dof_I );
-	}
-}
-
-void _SwarmVariable_ValueAtChar( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	Variable*		variable = self->variable;
-	Dof_Index		dofCount = self->dofCount;
-	Dof_Index		dof_I;
-
-	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
-		value[ dof_I ] = (double) Variable_GetValueAtChar( variable, lParticle_I, dof_I );
-	}
-}
-
-void _SwarmVariable_ValueAtShort( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	Variable*		variable = self->variable;
-	Dof_Index		dofCount = self->dofCount;
-	Dof_Index		dof_I;
-
-	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
-		value[ dof_I ] = (double) Variable_GetValueAtShort( variable, lParticle_I, dof_I );
-	}
-}
-	
-double _SwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	double*			value;
-	Swarm*			swarm = self->swarm;
-	Particle_Index	particleLocalCount = swarm->particleLocalCount;
-	Particle_Index	lParticle_I;
-	double			localMin = HUGE_VAL;
-	double			globalMin;
-	Index				dofCount = self->dofCount;
-	double			magnitude;
-
-	value = Memory_Alloc_Array( double, dofCount, "value" );
-
-	/* Search through all local particles and find smallest value of variable */
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-		SwarmVariable_ValueAt( self, lParticle_I, value );
-
-		if ( dofCount == 1 )
-			magnitude = value[0];
-		else 
-			assert(0); /*TODO */
-
-		if ( localMin > magnitude )
-			localMin = magnitude;
-	}
-
-	Memory_Free( value );
-	MPI_Allreduce( &localMin, &globalMin, dofCount, MPI_DOUBLE, MPI_MIN, swarm->comm );
-
-	return globalMin;
-}
-
-
-double _SwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
-	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
-	double*			value;
-	Swarm*			swarm = self->swarm;
-	Particle_Index	particleLocalCount = swarm->particleLocalCount;
-	Particle_Index	lParticle_I;
-	double			localMax = -HUGE_VAL;
-	double			globalMax;
-	Index				dofCount = self->dofCount;
-	double			magnitude;
-
-	value = Memory_Alloc_Array( double, dofCount, "value" );
-
-	/* Search through all local particles and find smallest value of variable */
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-		SwarmVariable_ValueAt( self, lParticle_I, value );
-
-		if ( dofCount == 1 )
-			magnitude = value[0];
-		else 
-			assert(0); /*TODO */
-
-		if ( localMax < magnitude )
-			localMax = magnitude;
-	}
-
-	Memory_Free( value );
-	MPI_Allreduce( &localMax, &globalMax, dofCount, MPI_DOUBLE, MPI_MAX, swarm->comm );
-	
-	return globalMax;
-}
-
-	
-
-
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SwarmVariable.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,378 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SwarmVariable.c 4139 2007-06-12 02:39:52Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "SwarmClass.h"
+#include "SwarmVariable_Register.h"
+#include "SwarmVariable.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type SwarmVariable_Type = "SwarmVariable";
+
+SwarmVariable* SwarmVariable_New(		
+	Name					name,
+	AbstractContext*	context,
+	Swarm*				swarm,
+	Variable*			variable,
+	Index					dofCount )
+{
+	SwarmVariable* self = (SwarmVariable*) _SwarmVariable_DefaultNew( name );
+
+	self->isConstructed = True;
+	_SwarmVariable_Init( self, context, swarm, variable, dofCount );
+
+	return self;
+}
+
+void* _SwarmVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(SwarmVariable);
+	Type                                                         type = SwarmVariable_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _SwarmVariable_Delete;
+	Stg_Class_PrintFunction*                                   _print = _SwarmVariable_Print;
+	Stg_Class_CopyFunction*                                     _copy = _SwarmVariable_Copy;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _SwarmVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _SwarmVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _SwarmVariable_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _SwarmVariable_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _SwarmVariable_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _SwarmVariable_Destroy;
+	AllocationType                                 nameAllocationType = NON_GLOBAL;
+	SwarmVariable_ValueAtFunction*                           _valueAt = _SwarmVariable_ValueAt;
+	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _SwarmVariable_GetMinGlobalMagnitude;
+	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _SwarmVariable_GetMaxGlobalMagnitude;
+
+	return (void*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
+}
+
+SwarmVariable* _SwarmVariable_New(  SWARMVARIABLE_DEFARGS  ) {
+	SwarmVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SwarmVariable) );
+	self = (SwarmVariable*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* Virtual functions */
+	self->_valueAt						= _valueAt;
+	self->_getMinGlobalMagnitude	= _getMinGlobalMagnitude;
+	self->_getMaxGlobalMagnitude	= _getMaxGlobalMagnitude;
+
+	return self;
+}
+
+void _SwarmVariable_Init( void* swarmVariable, AbstractContext* context, Swarm* swarm, Variable* variable, Index dofCount ) {
+	SwarmVariable* self = (SwarmVariable*) swarmVariable;
+
+	self->context                   = context;
+	self->swarm                     = swarm;
+	self->variable                  = variable;
+	self->dofCount                  = dofCount;
+	self->swarmVariable_Register    = swarm->swarmVariable_Register;
+	self->dim                       = swarm->dim;
+   self->isCheckpointedAndReloaded = True;
+	
+	if( variable )
+		Swarm_AddVariable( swarm, self );
+	if ( self->swarmVariable_Register != NULL )	
+		SwarmVariable_Register_Add( self->swarmVariable_Register, self );
+}
+
+void _SwarmVariable_Delete( void* swarmVariable ) {
+	SwarmVariable* self = (SwarmVariable*) swarmVariable;
+
+	_Stg_Component_Delete( self );
+}
+
+void _SwarmVariable_Print( void* _swarmVariable, Stream* stream ) {
+	SwarmVariable* self = (SwarmVariable*) _swarmVariable;
+
+	Journal_Printf( stream, "SwarmVariable - '%s'\n", self->name );
+	Stream_Indent( stream );
+	_Stg_Component_Print( self, stream );
+
+	Journal_PrintPointer( stream, self->_valueAt );
+	Journal_PrintPointer( stream, self->_getMinGlobalMagnitude );
+	Journal_PrintPointer( stream, self->_getMaxGlobalMagnitude );
+
+	Journal_Printf( stream, "Swarm - '%s'\n", self->swarm->name );
+	if ( self->variable != NULL )
+		Journal_Printf( stream, "Variable - '%s'\n", self->variable->name );
+
+	Journal_PrintValue( stream, self->dofCount );
+	Journal_PrintPointer( stream, self->swarmVariable_Register );
+	Stream_UnIndent( stream );
+}
+
+void* _SwarmVariable_Copy( const void* swarmVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	SwarmVariable*	newSwarmVariable;
+	PtrMap*			map = ptrMap;
+	Bool				ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newSwarmVariable = (SwarmVariable*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
+	
+	newSwarmVariable->_valueAt						= self->_valueAt;
+	newSwarmVariable->_getMinGlobalMagnitude	= self->_getMinGlobalMagnitude;
+	newSwarmVariable->_getMaxGlobalMagnitude	= self->_getMaxGlobalMagnitude;
+
+	newSwarmVariable->swarm							= self->swarm;
+	newSwarmVariable->variable						= self->variable;
+	newSwarmVariable->dofCount						= self->dofCount;
+	newSwarmVariable->swarmVariable_Register	= self->swarmVariable_Register;
+
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+				
+	return (void*)newSwarmVariable;
+}
+
+void _SwarmVariable_AssignFromXML( void* swarmVariable, Stg_ComponentFactory* cf, void* data ) {
+	SwarmVariable*		self = (SwarmVariable*)swarmVariable;
+	Swarm*				swarm;
+	Variable*			variable;
+	Index					dofCount;
+	AbstractContext*	context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", AbstractContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data  );
+	variable =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Variable", Variable, False, data  );
+	dofCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"dofCount", 0  );
+
+	_SwarmVariable_Init( self, context, swarm, variable, dofCount );
+}
+
+void _SwarmVariable_Build( void* swarmVariable, void* data ) {
+	SwarmVariable* self = (SwarmVariable*)swarmVariable;
+
+	if ( self->variable )
+		Stg_Component_Build( self->variable, data, False );
+}
+
+void _SwarmVariable_Initialise( void* swarmVariable, void* data ) {
+	SwarmVariable* self = (SwarmVariable*)swarmVariable;
+
+	if ( self->variable ) {
+		Variable_Update( self->variable );
+		Stg_Component_Initialise( self->variable, data, False );
+	}
+}
+
+void _SwarmVariable_Execute( void* swarmVariable, void* data ) {
+}
+
+void _SwarmVariable_Destroy( void* swarmVariable, void* data ) {
+	SwarmVariable* self = (SwarmVariable*)swarmVariable;
+   
+   Stg_Component_Destroy( self->swarm, data, False );
+   if( self->variable )
+		Stg_Component_Destroy(self->variable, data, False);
+}
+
+double SwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	return self->_getMinGlobalMagnitude( self );
+}
+
+double SwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	return self->_getMaxGlobalMagnitude( self );
+}
+
+/*** Default Implementations ***/
+
+void _SwarmVariable_ValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	Variable*		variable = self->variable;
+
+	switch( variable->dataTypes[0] ) {
+		case Variable_DataType_Double:
+			self->_valueAt = _SwarmVariable_ValueAtDouble;
+			break;
+		case Variable_DataType_Int:
+			self->_valueAt = _SwarmVariable_ValueAtInt;
+			break;
+		case Variable_DataType_Float:
+			self->_valueAt = _SwarmVariable_ValueAtFloat;
+			break;
+		case Variable_DataType_Char:
+			self->_valueAt = _SwarmVariable_ValueAtChar;
+			break;
+		case Variable_DataType_Short:
+			self->_valueAt = _SwarmVariable_ValueAtShort;
+			break;
+		default:
+			assert(0);
+	}
+	SwarmVariable_ValueAt( self, lParticle_I, value );
+}
+	
+void _SwarmVariable_ValueAtDouble( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	double*			dataPtr;
+
+	dataPtr = Variable_GetPtrDouble( self->variable, lParticle_I );
+	memcpy( value, dataPtr, sizeof(double) * self->dofCount );
+}
+
+void _SwarmVariable_ValueAtInt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	Variable*		variable = self->variable;
+	Dof_Index		dofCount = self->dofCount;
+	Dof_Index		dof_I;
+
+	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
+		value[ dof_I ] = (double) Variable_GetValueAtInt( variable, lParticle_I, dof_I );
+	}
+}
+
+void _SwarmVariable_ValueAtFloat( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	Variable*		variable = self->variable;
+	Dof_Index		dofCount = self->dofCount;
+	Dof_Index		dof_I;
+
+	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
+		value[ dof_I ] = (double) Variable_GetValueAtFloat( variable, lParticle_I, dof_I );
+	}
+}
+
+void _SwarmVariable_ValueAtChar( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	Variable*		variable = self->variable;
+	Dof_Index		dofCount = self->dofCount;
+	Dof_Index		dof_I;
+
+	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
+		value[ dof_I ] = (double) Variable_GetValueAtChar( variable, lParticle_I, dof_I );
+	}
+}
+
+void _SwarmVariable_ValueAtShort( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	Variable*		variable = self->variable;
+	Dof_Index		dofCount = self->dofCount;
+	Dof_Index		dof_I;
+
+	for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
+		value[ dof_I ] = (double) Variable_GetValueAtShort( variable, lParticle_I, dof_I );
+	}
+}
+	
+double _SwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	double*			value;
+	Swarm*			swarm = self->swarm;
+	Particle_Index	particleLocalCount = swarm->particleLocalCount;
+	Particle_Index	lParticle_I;
+	double			localMin = HUGE_VAL;
+	double			globalMin;
+	Index				dofCount = self->dofCount;
+	double			magnitude;
+
+	value = Memory_Alloc_Array( double, dofCount, "value" );
+
+	/* Search through all local particles and find smallest value of variable */
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+		SwarmVariable_ValueAt( self, lParticle_I, value );
+
+		if ( dofCount == 1 )
+			magnitude = value[0];
+		else 
+			assert(0); /*TODO */
+
+		if ( localMin > magnitude )
+			localMin = magnitude;
+	}
+
+	Memory_Free( value );
+	MPI_Allreduce( &localMin, &globalMin, dofCount, MPI_DOUBLE, MPI_MIN, swarm->comm );
+
+	return globalMin;
+}
+
+
+double _SwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
+	SwarmVariable*	self = (SwarmVariable*)swarmVariable;
+	double*			value;
+	Swarm*			swarm = self->swarm;
+	Particle_Index	particleLocalCount = swarm->particleLocalCount;
+	Particle_Index	lParticle_I;
+	double			localMax = -HUGE_VAL;
+	double			globalMax;
+	Index				dofCount = self->dofCount;
+	double			magnitude;
+
+	value = Memory_Alloc_Array( double, dofCount, "value" );
+
+	/* Search through all local particles and find smallest value of variable */
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+		SwarmVariable_ValueAt( self, lParticle_I, value );
+
+		if ( dofCount == 1 )
+			magnitude = value[0];
+		else 
+			assert(0); /*TODO */
+
+		if ( localMax < magnitude )
+			localMax = magnitude;
+	}
+
+	Memory_Free( value );
+	MPI_Allreduce( &localMax, &globalMax, dofCount, MPI_DOUBLE, MPI_MAX, swarm->comm );
+	
+	return globalMax;
+}
+
+	
+
+
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmVariable_Register.c
--- a/Swarm/src/SwarmVariable_Register.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SwarmVariable_Register.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "SwarmVariable_Register.h"
-
-#include <assert.h>
-
-
-const Type SwarmVariable_Register_Type = "SwarmVariable_Register";
-
-SwarmVariable_Register*	SwarmVariable_Register_New( Variable_Register* variable_Register ) {
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(SwarmVariable_Register);
-	Type                              type = SwarmVariable_Register_Type;
-	Stg_Class_DeleteFunction*      _delete = _NamedObject_Register_Delete;
-	Stg_Class_PrintFunction*        _print = _NamedObject_Register_Print;
-	Stg_Class_CopyFunction*          _copy = NULL;
-
-	SwarmVariable_Register* self = (SwarmVariable_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
-
-	self->variable_Register = variable_Register;
-
-	return self;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/SwarmVariable_Register.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/SwarmVariable_Register.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,62 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SwarmVariable_Register.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "SwarmVariable_Register.h"
+
+#include <assert.h>
+
+
+const Type SwarmVariable_Register_Type = "SwarmVariable_Register";
+
+SwarmVariable_Register*	SwarmVariable_Register_New( Variable_Register* variable_Register ) {
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(SwarmVariable_Register);
+	Type                              type = SwarmVariable_Register_Type;
+	Stg_Class_DeleteFunction*      _delete = _NamedObject_Register_Delete;
+	Stg_Class_PrintFunction*        _print = _NamedObject_Register_Print;
+	Stg_Class_CopyFunction*          _copy = NULL;
+
+	SwarmVariable_Register* self = (SwarmVariable_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
+
+	self->variable_Register = variable_Register;
+
+	return self;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Swarm_Register.c
--- a/Swarm/src/Swarm_Register.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,256 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-**
-**
-** Assumptions:
-**
-** Comments:
-**
-** $Id: Swarm_Register.c 2745 2005-05-10 08:12:18Z RaquibulHassan $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "Swarm_Register.h"
-
-#include "ParticleLayout.h"
-#include "SwarmClass.h"
-#include "SwarmDump.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <string.h>
-
-
-/* Textual name of this class */
-const Type Swarm_Register_Type = "Swarm_Register";
-Swarm_Register* stgSwarm_Register = NULL;
-
-Swarm_Register* _Swarm_Register_New(  SWARM_REGISTER_DEFARGS  )
-{
-	Swarm_Register* self = NULL;
-
-	assert( _sizeOfSelf >= sizeof(Swarm_Register) );
-	self = (Swarm_Register*) _Stg_Class_New(  STG_CLASS_PASSARGS  );
-	
-	return self;
-}
-	
-Swarm_Register* Swarm_Register_New(  )
-{
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(Swarm_Register);
-	Type                              type = Swarm_Register_Type;
-	Stg_Class_DeleteFunction*      _delete = _Swarm_Register_Delete;
-	Stg_Class_PrintFunction*        _print = _Swarm_Register_Print;
-
-	Swarm_Register* self = NULL;
-
-	/* The following terms are parameters that have been passed into or defined in this function but are being set before being passed onto the parent */
-	Stg_Class_CopyFunction*  _copy = NULL;
-
-	self = _Swarm_Register_New(  SWARM_REGISTER_PASSARGS  );
-
-	Swarm_Register_Init( self );
-
-	if ( !stgSwarm_Register ) {
-		stgSwarm_Register = self;
-	}
-	return self;
-}
-
-void _Swarm_Register_Init( Swarm_Register* self )
-{
-}
-	
-void Swarm_Register_Init( Swarm_Register* self )
-{
-	assert( self );
-
-	self->swarmList = Stg_ObjectList_New( );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _Swarm_Register_Delete( void* swarmRegister )
-{
-	Swarm_Register* self = (Swarm_Register *) swarmRegister;
-
-	assert( self );
-
-	/** Actually, don't delete all swarms as they have already been deleted by the
-	live component register : or else leave it up to the user */
-	/* Stg_ObjectList_DeleteAllObjects( self->swarmList ); */
-
-	Stg_Class_Delete( self->swarmList );
-	if ( stgSwarm_Register == self ) {
-		stgSwarm_Register = NULL;
-	}
-	_Stg_Class_Delete( self );
-}
-
-void _Swarm_Register_Print( void* swarmRegister, Stream* stream )
-{
-	Swarm_Register* self = (Swarm_Register *) swarmRegister;
-
-	assert( self );
-	
-	/* General info */
-	Journal_Printf( (void*) stream, "Swarm_Register (ptr): %p\n", self );
-	
-	/* Print parent class */
-	_Stg_Class_Print( self, stream );
-	
-	Journal_Printf( (void*) stream, "swarmList (ptr): %p\n", self->swarmList );
-	Stg_Class_Print( self->swarmList, stream );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-Index Swarm_Register_Add( Swarm_Register* self, void* swarm )
-{
-	assert( self );
-	return Stg_ObjectList_Append( self->swarmList, swarm );
-}
-
-void Swarm_Register_RemoveIndex( Swarm_Register* self, unsigned int index )
-{
-   unsigned swarm_i = 0;
-	assert( self );
-	/* The third argument controls if the Delete phase is run or not in this function
-	 * KEEP = Don't run delete
-	 * DELETE = Run delete
-	 */
-	_Stg_ObjectList_RemoveByIndex( self->swarmList, index, KEEP );
-
-   /* decrement each swarms own index of where it is in swarm register,
-   this is done because the function _Stg_ObjectList_RemoveByIndex() memmoves
-   the block of memory in the list, with out altering the values within the memory */
-   for( swarm_i = index ; swarm_i < self->swarmList->count ; swarm_i++ ) {
-      ((Swarm*)self->swarmList->data[swarm_i])->swarmReg_I--;
-   }
-}
-	
-Swarm* Swarm_Register_Get( Swarm_Register* self, Name name )
-{
-	assert( self );
-	
-	return (Swarm*)Stg_ObjectList_Get( self->swarmList, (Name)name  );
-}
-
-Swarm* Swarm_Register_At( void* swarmRegister, Index index ) {
-	Swarm_Register* self      = (Swarm_Register *) swarmRegister;
-	assert( self );
-
-	return (Swarm*) Stg_ObjectList_At( self->swarmList, index );
-}
-	
-unsigned int Swarm_Register_GetCount( Swarm_Register* self )
-{
-	assert( self );
-
-	return self->swarmList->count;
-}
-
-Index Swarm_Register_GetIndexFromPointer( Swarm_Register* self, void* ptr ) {
-	Index i;
-
-	for ( i = 0; i < self->swarmList->count; ++i ) {
-		if ( (void*)self->swarmList->data[i] == ptr ) {
-			return i;
-		}
-	}
-
-	return (Index)-1;
-}
-
-
-Swarm_Register* Swarm_Register_GetSwarm_Register() {
-	return stgSwarm_Register;
-}
-
-
-void Swarm_Register_SaveAllRegisteredSwarms( Swarm_Register* self, void* context ) {
-	Index                     swarmCount = self->swarmList->count;
-	Swarm**                   swarmList = NULL;
-	Index                     swarm_I;
-	Index                     swarmsToDumpCount = 0;
-	SwarmDump*                swarmDumper;
-	Swarm*                    swarm;
-	Stream*                   debug = Journal_Register( DebugStream_Type, (Name)self->type );
-
-	if ( swarmCount == 0  ) {
-		return;
-	}	
-	
-	Journal_Printf( debug, "In %s(): about to save the swarms to disk:\n", __func__ );
-
-	swarmList = Memory_Alloc_Array_Unnamed( Swarm*, swarmCount ); 
-
-	for ( swarm_I=0 ; swarm_I < swarmCount; swarm_I++ ) {
-		swarm = Swarm_Register_At( self, swarm_I );
-		if ( swarm->isSwarmTypeToCheckPointAndReload == True ) {
-			swarmList[swarmsToDumpCount++] = swarm;
-		}
-	}
-	
-	if ( swarmsToDumpCount == 0 ) {
-		Journal_Printf( debug, "found 0 swarms that need to be checkpointed -> nothing to do\n",
-			swarmsToDumpCount );
-	}
-	else {
-		Journal_Printf( debug, "\t(found %u swarms that need to be checkpointed)\n",
-			swarmsToDumpCount );
-
-		/* Create new SwarmDump object to check point the swarms
-		 * We're not passing in the 'context' as the second argument because we don't need the swarm dumper to 
-		 * add a hook on the Save entrypoint - contexts can manually execute this function */ 
-		swarmDumper = SwarmDump_New( "swarmDumper", NULL, swarmList, swarmsToDumpCount, True );
-		/* Passing the context through allows the swarmDumper to check requested strings etc */
-		SwarmDump_Execute( swarmDumper, context );
-		Stg_Class_Delete( swarmDumper );
-	}
-
-	Memory_Free( swarmList );
-	Journal_Printf( debug, "%s: saving of swarms completed.\n", __func__ );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/Swarm_Register.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/Swarm_Register.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,256 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+**
+**
+** Assumptions:
+**
+** Comments:
+**
+** $Id: Swarm_Register.c 2745 2005-05-10 08:12:18Z RaquibulHassan $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Swarm_Register.h"
+
+#include "ParticleLayout.h"
+#include "SwarmClass.h"
+#include "SwarmDump.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+
+/* Textual name of this class */
+const Type Swarm_Register_Type = "Swarm_Register";
+Swarm_Register* stgSwarm_Register = NULL;
+
+Swarm_Register* _Swarm_Register_New(  SWARM_REGISTER_DEFARGS  )
+{
+	Swarm_Register* self = NULL;
+
+	assert( _sizeOfSelf >= sizeof(Swarm_Register) );
+	self = (Swarm_Register*) _Stg_Class_New(  STG_CLASS_PASSARGS  );
+	
+	return self;
+}
+	
+Swarm_Register* Swarm_Register_New(  )
+{
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(Swarm_Register);
+	Type                              type = Swarm_Register_Type;
+	Stg_Class_DeleteFunction*      _delete = _Swarm_Register_Delete;
+	Stg_Class_PrintFunction*        _print = _Swarm_Register_Print;
+
+	Swarm_Register* self = NULL;
+
+	/* The following terms are parameters that have been passed into or defined in this function but are being set before being passed onto the parent */
+	Stg_Class_CopyFunction*  _copy = NULL;
+
+	self = _Swarm_Register_New(  SWARM_REGISTER_PASSARGS  );
+
+	Swarm_Register_Init( self );
+
+	if ( !stgSwarm_Register ) {
+		stgSwarm_Register = self;
+	}
+	return self;
+}
+
+void _Swarm_Register_Init( Swarm_Register* self )
+{
+}
+	
+void Swarm_Register_Init( Swarm_Register* self )
+{
+	assert( self );
+
+	self->swarmList = Stg_ObjectList_New( );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Swarm_Register_Delete( void* swarmRegister )
+{
+	Swarm_Register* self = (Swarm_Register *) swarmRegister;
+
+	assert( self );
+
+	/** Actually, don't delete all swarms as they have already been deleted by the
+	live component register : or else leave it up to the user */
+	/* Stg_ObjectList_DeleteAllObjects( self->swarmList ); */
+
+	Stg_Class_Delete( self->swarmList );
+	if ( stgSwarm_Register == self ) {
+		stgSwarm_Register = NULL;
+	}
+	_Stg_Class_Delete( self );
+}
+
+void _Swarm_Register_Print( void* swarmRegister, Stream* stream )
+{
+	Swarm_Register* self = (Swarm_Register *) swarmRegister;
+
+	assert( self );
+	
+	/* General info */
+	Journal_Printf( (void*) stream, "Swarm_Register (ptr): %p\n", self );
+	
+	/* Print parent class */
+	_Stg_Class_Print( self, stream );
+	
+	Journal_Printf( (void*) stream, "swarmList (ptr): %p\n", self->swarmList );
+	Stg_Class_Print( self->swarmList, stream );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+Index Swarm_Register_Add( Swarm_Register* self, void* swarm )
+{
+	assert( self );
+	return Stg_ObjectList_Append( self->swarmList, swarm );
+}
+
+void Swarm_Register_RemoveIndex( Swarm_Register* self, unsigned int index )
+{
+   unsigned swarm_i = 0;
+	assert( self );
+	/* The third argument controls if the Delete phase is run or not in this function
+	 * KEEP = Don't run delete
+	 * DELETE = Run delete
+	 */
+	_Stg_ObjectList_RemoveByIndex( self->swarmList, index, KEEP );
+
+   /* decrement each swarms own index of where it is in swarm register,
+   this is done because the function _Stg_ObjectList_RemoveByIndex() memmoves
+   the block of memory in the list, with out altering the values within the memory */
+   for( swarm_i = index ; swarm_i < self->swarmList->count ; swarm_i++ ) {
+      ((Swarm*)self->swarmList->data[swarm_i])->swarmReg_I--;
+   }
+}
+	
+Swarm* Swarm_Register_Get( Swarm_Register* self, Name name )
+{
+	assert( self );
+	
+	return (Swarm*)Stg_ObjectList_Get( self->swarmList, (Name)name  );
+}
+
+Swarm* Swarm_Register_At( void* swarmRegister, Index index ) {
+	Swarm_Register* self      = (Swarm_Register *) swarmRegister;
+	assert( self );
+
+	return (Swarm*) Stg_ObjectList_At( self->swarmList, index );
+}
+	
+unsigned int Swarm_Register_GetCount( Swarm_Register* self )
+{
+	assert( self );
+
+	return self->swarmList->count;
+}
+
+Index Swarm_Register_GetIndexFromPointer( Swarm_Register* self, void* ptr ) {
+	Index i;
+
+	for ( i = 0; i < self->swarmList->count; ++i ) {
+		if ( (void*)self->swarmList->data[i] == ptr ) {
+			return i;
+		}
+	}
+
+	return (Index)-1;
+}
+
+
+Swarm_Register* Swarm_Register_GetSwarm_Register() {
+	return stgSwarm_Register;
+}
+
+
+void Swarm_Register_SaveAllRegisteredSwarms( Swarm_Register* self, void* context ) {
+	Index                     swarmCount = self->swarmList->count;
+	Swarm**                   swarmList = NULL;
+	Index                     swarm_I;
+	Index                     swarmsToDumpCount = 0;
+	SwarmDump*                swarmDumper;
+	Swarm*                    swarm;
+	Stream*                   debug = Journal_Register( DebugStream_Type, (Name)self->type );
+
+	if ( swarmCount == 0  ) {
+		return;
+	}	
+	
+	Journal_Printf( debug, "In %s(): about to save the swarms to disk:\n", __func__ );
+
+	swarmList = Memory_Alloc_Array_Unnamed( Swarm*, swarmCount ); 
+
+	for ( swarm_I=0 ; swarm_I < swarmCount; swarm_I++ ) {
+		swarm = Swarm_Register_At( self, swarm_I );
+		if ( swarm->isSwarmTypeToCheckPointAndReload == True ) {
+			swarmList[swarmsToDumpCount++] = swarm;
+		}
+	}
+	
+	if ( swarmsToDumpCount == 0 ) {
+		Journal_Printf( debug, "found 0 swarms that need to be checkpointed -> nothing to do\n",
+			swarmsToDumpCount );
+	}
+	else {
+		Journal_Printf( debug, "\t(found %u swarms that need to be checkpointed)\n",
+			swarmsToDumpCount );
+
+		/* Create new SwarmDump object to check point the swarms
+		 * We're not passing in the 'context' as the second argument because we don't need the swarm dumper to 
+		 * add a hook on the Save entrypoint - contexts can manually execute this function */ 
+		swarmDumper = SwarmDump_New( "swarmDumper", NULL, swarmList, swarmsToDumpCount, True );
+		/* Passing the context through allows the swarmDumper to check requested strings etc */
+		SwarmDump_Execute( swarmDumper, context );
+		Stg_Class_Delete( swarmDumper );
+	}
+
+	Memory_Free( swarmList );
+	Journal_Printf( debug, "%s: saving of swarms completed.\n", __func__ );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/TriGaussParticleLayout.c
--- a/Swarm/src/TriGaussParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,273 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TriGaussParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "PerCellParticleLayout.h"
-#include "TriGaussParticleLayout.h"
-
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-#include "IntegrationPoint.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include <assert.h>
-
-
-const Type TriGaussParticleLayout_Type = "TriGaussParticleLayout";
-
-TriGaussParticleLayout* TriGaussParticleLayout_New( 
-   Name name, 
-   AbstractContext* context,
-   CoordSystem      coordSystem,
-   Bool             weightsInitialisedAtStartup,
-   unsigned int dim, unsigned int particlesPerCell ) 
-{
-	TriGaussParticleLayout* self = (TriGaussParticleLayout*)_TriGaussParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _PerCellParticleLayout_Init( self );
-	_TriGaussParticleLayout_Init( self, dim, particlesPerCell );
-
-	return self;
-}
-
-TriGaussParticleLayout* _TriGaussParticleLayout_New(  TRIGAUSSPARTICLELAYOUT_DEFARGS  )
-{
-	TriGaussParticleLayout* self;
-	
-   /* hard-wire here */
-   coordSystem = LocalCoordSystem;
-   weightsInitialisedAtStartup = True;
-	/* Allocate memory */
-	self = (TriGaussParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
-	
-	return self;
-}
-
-
-void _TriGaussParticleLayout_Init(
-		TriGaussParticleLayout* self,
-		unsigned int            dim,
-		unsigned int            particlesPerCell )
-{
-	self->isConstructed    = True;
-	self->dim              = dim;
-	self->particlesPerCell = particlesPerCell;
-}
-
-void _TriGaussParticleLayout_Delete( void* triGaussParticleLayout ) {
-	TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
-	
-	_PerCellParticleLayout_Delete( self );
-}
-
-void _TriGaussParticleLayout_Print( void* triGaussParticleLayout, Stream* stream ) {
-	TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
-	
-	/* Set the Journal for printing informations */
-	Stream* triGaussParticleLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( triGaussParticleLayoutStream, "TriGaussParticleLayout (ptr): %p:\n", self );
-	
-	/* Parent class info */
-	_PerCellParticleLayout_Print( self, stream );
-	
-	/* Virtual info */
-	
-	/* TriGaussParticleLayout */
-	Journal_Printf( triGaussParticleLayoutStream, "\tdim: %u\n", self->dim );
-	Journal_Printf( triGaussParticleLayoutStream, "\tparticlesPerCell: %u\n", self->particlesPerCell  );
-}
-
-
-void* _TriGaussParticleLayout_Copy( const void* triGaussParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	TriGaussParticleLayout*		self = (TriGaussParticleLayout*)triGaussParticleLayout;
-	TriGaussParticleLayout*		newTriGaussParticleLayout;
-	
-	newTriGaussParticleLayout = (TriGaussParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	return (void*)newTriGaussParticleLayout;
-}
-
-void* _TriGaussParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                     _sizeOfSelf = sizeof(TriGaussParticleLayout);
-	Type                                                                             type = TriGaussParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                     _delete = _TriGaussParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                       _print = _TriGaussParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                         _copy = _TriGaussParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _TriGaussParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                           _construct = _TriGaussParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                                   _build = _TriGaussParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                         _initialise = _TriGaussParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                               _execute = _TriGaussParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                               _destroy = _TriGaussParticleLayout_Destroy;
-	AllocationType                                                     nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
-	CoordSystem                                                               coordSystem = LocalCoordSystem;
-	Bool                                                      weightsInitialisedAtStartup = True;
-	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _TriGaussParticleLayout_InitialCount;
-	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _TriGaussParticleLayout_InitialiseParticlesOfCell;
-
-	return _TriGaussParticleLayout_New(  TRIGAUSSPARTICLELAYOUT_PASSARGS  );
-}
-
-void _TriGaussParticleLayout_AssignFromXML( void* triGaussParticleLayout, Stg_ComponentFactory* cf, void* data ){
-	TriGaussParticleLayout *self = (TriGaussParticleLayout*)triGaussParticleLayout;
-	unsigned int dim;
-	unsigned int particlesPerCell;
-
-   _PerCellParticleLayout_AssignFromXML( self, cf, data );
-	dim = Dictionary_Entry_Value_AsUnsignedInt(
-		Dictionary_GetDefault( cf->rootDict, "dim", Dictionary_Entry_Value_FromUnsignedInt( 3 ) ) );
-
-	particlesPerCell = Dictionary_Entry_Value_AsUnsignedInt(
-		Dictionary_GetDefault( cf->rootDict, "particlesPerCell", Dictionary_Entry_Value_FromUnsignedInt( 1 ) ) );
-
-	_TriGaussParticleLayout_Init( self, dim, particlesPerCell );
-}
-	
-void _TriGaussParticleLayout_Build( void* triGaussParticleLayout, void* data ) {
-}
-	
-void _TriGaussParticleLayout_Initialise( void* triGaussParticleLayout, void* data ) {
-}
-	
-void _TriGaussParticleLayout_Execute( void* triGaussParticleLayout, void* data ) {
-}
-	
-void _TriGaussParticleLayout_Destroy( void* triGaussParticleLayout, void* data ) {
-   TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
-   _PerCellParticleLayout_Destroy( self, data );
-}
-
-Particle_InCellIndex _TriGaussParticleLayout_InitialCount( void* triGaussParticleLayout, void* celllayout, Cell_Index cell_I )
-{
-	TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
-	Particle_InCellIndex count;
-	int dim;	
-	
-	dim = self->dim;
-	count = (Particle_InCellIndex)( self->particlesPerCell );
-	
-	return count;
-}
-
-
-/* remember this only has to initialise one cell of particles at a time */
-void _TriGaussParticleLayout_InitialiseParticlesOfCell( void* triGaussParticleLayout, void* _swarm, Cell_Index cell_I )
-{
-	#define MAX_DIM 3
-	#define MAX_GAUSS_POINTS_2D 1
-	#define MAX_GAUSS_POINTS_3D 1
-	TriGaussParticleLayout*   self = (TriGaussParticleLayout*)triGaussParticleLayout;
-	Swarm*                    swarm = (Swarm*)_swarm;
-	IntegrationPoint*         integrationPoint = NULL;
-
-	Particle_InCellIndex      cParticle_I = 0;
-
-	Particle_InCellIndex ppc;
-	int dim;
-	static double weight[20];
-	static double xi[20][3];
-	static int beenHere = 0;
-	int d;
-	
-	dim = self->dim;
-	ppc = self->particlesPerCell;
-	
-	if( dim == 2 ) {
-		if( ppc == 1 ) {
-			weight[0] = 0.5;
-
-			xi[0][0] = 0.333333333333;
-			xi[0][1] = 0.333333333333;				
-		}
-		if( ppc > MAX_GAUSS_POINTS_2D ) {
-			Journal_Firewall(
-				ppc > MAX_GAUSS_POINTS_2D,
-				Journal_MyStream( Error_Type, self ),
-				"In %s(), error: particlesPerCell greater than implementated tabulated gauss values of %d\n",
-				__func__,
-				MAX_GAUSS_POINTS_2D );
-		}
-	}
-	else if ( dim == 3 ) {
-		if( ppc == 1 ) {
-			weight[0] = 0.5;			
-
-			xi[0][0] = 0.333333333333;
-			xi[0][1] = 0.333333333333;				
-			xi[0][2] = 0.333333333333;				
-		}
-		if( ppc > MAX_GAUSS_POINTS_3D ) {
-			Journal_Firewall(
-				ppc > MAX_GAUSS_POINTS_3D,
-				Journal_MyStream( Error_Type, self ),
-				"In %s(), error: particlesPerCell greater than implementated tabulated gauss values of %d\n",
-				__func__,
-				MAX_GAUSS_POINTS_3D );
-		}
-	}
-
-	assert( ppc <= swarm->cellParticleCountTbl[cell_I] );
-	
-	for ( cParticle_I = 0; cParticle_I < ppc; cParticle_I++ ) {
-		integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		integrationPoint->owningCell = cell_I;
-			
-		for( d = 0; d < dim; d++ ) {
-			/*integrationPoint->coord[d] = xi[cParticle_I][d];*/
-			integrationPoint->xi[d] = xi[cParticle_I][d];
-		}
-		
-		integrationPoint->weight = weight[cParticle_I];
-		
-		beenHere = 1;
-	}	
-	
-	
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/TriGaussParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/TriGaussParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,273 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TriGaussParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "PerCellParticleLayout.h"
+#include "TriGaussParticleLayout.h"
+
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+#include "IntegrationPoint.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <assert.h>
+
+
+const Type TriGaussParticleLayout_Type = "TriGaussParticleLayout";
+
+TriGaussParticleLayout* TriGaussParticleLayout_New( 
+   Name name, 
+   AbstractContext* context,
+   CoordSystem      coordSystem,
+   Bool             weightsInitialisedAtStartup,
+   unsigned int dim, unsigned int particlesPerCell ) 
+{
+	TriGaussParticleLayout* self = (TriGaussParticleLayout*)_TriGaussParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _PerCellParticleLayout_Init( self );
+	_TriGaussParticleLayout_Init( self, dim, particlesPerCell );
+
+	return self;
+}
+
+TriGaussParticleLayout* _TriGaussParticleLayout_New(  TRIGAUSSPARTICLELAYOUT_DEFARGS  )
+{
+	TriGaussParticleLayout* self;
+	
+   /* hard-wire here */
+   coordSystem = LocalCoordSystem;
+   weightsInitialisedAtStartup = True;
+	/* Allocate memory */
+	self = (TriGaussParticleLayout*)_PerCellParticleLayout_New(  PERCELLPARTICLELAYOUT_PASSARGS  );
+	
+	return self;
+}
+
+
+void _TriGaussParticleLayout_Init(
+		TriGaussParticleLayout* self,
+		unsigned int            dim,
+		unsigned int            particlesPerCell )
+{
+	self->isConstructed    = True;
+	self->dim              = dim;
+	self->particlesPerCell = particlesPerCell;
+}
+
+void _TriGaussParticleLayout_Delete( void* triGaussParticleLayout ) {
+	TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
+	
+	_PerCellParticleLayout_Delete( self );
+}
+
+void _TriGaussParticleLayout_Print( void* triGaussParticleLayout, Stream* stream ) {
+	TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
+	
+	/* Set the Journal for printing informations */
+	Stream* triGaussParticleLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( triGaussParticleLayoutStream, "TriGaussParticleLayout (ptr): %p:\n", self );
+	
+	/* Parent class info */
+	_PerCellParticleLayout_Print( self, stream );
+	
+	/* Virtual info */
+	
+	/* TriGaussParticleLayout */
+	Journal_Printf( triGaussParticleLayoutStream, "\tdim: %u\n", self->dim );
+	Journal_Printf( triGaussParticleLayoutStream, "\tparticlesPerCell: %u\n", self->particlesPerCell  );
+}
+
+
+void* _TriGaussParticleLayout_Copy( const void* triGaussParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	TriGaussParticleLayout*		self = (TriGaussParticleLayout*)triGaussParticleLayout;
+	TriGaussParticleLayout*		newTriGaussParticleLayout;
+	
+	newTriGaussParticleLayout = (TriGaussParticleLayout*)_PerCellParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	return (void*)newTriGaussParticleLayout;
+}
+
+void* _TriGaussParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                     _sizeOfSelf = sizeof(TriGaussParticleLayout);
+	Type                                                                             type = TriGaussParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                     _delete = _TriGaussParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                       _print = _TriGaussParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                         _copy = _TriGaussParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                         _defaultConstructor = _TriGaussParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                           _construct = _TriGaussParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                                   _build = _TriGaussParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                         _initialise = _TriGaussParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                               _execute = _TriGaussParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                               _destroy = _TriGaussParticleLayout_Destroy;
+	AllocationType                                                     nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                            _setInitialCounts = _PerCellParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                      _initialiseParticles = _PerCellParticleLayout_InitialiseParticles;
+	CoordSystem                                                               coordSystem = LocalCoordSystem;
+	Bool                                                      weightsInitialisedAtStartup = True;
+	PerCellParticleLayout_InitialCountFunction*                             _initialCount = _TriGaussParticleLayout_InitialCount;
+	PerCellParticleLayout_InitialiseParticlesOfCellFunction*   _initialiseParticlesOfCell = _TriGaussParticleLayout_InitialiseParticlesOfCell;
+
+	return _TriGaussParticleLayout_New(  TRIGAUSSPARTICLELAYOUT_PASSARGS  );
+}
+
+void _TriGaussParticleLayout_AssignFromXML( void* triGaussParticleLayout, Stg_ComponentFactory* cf, void* data ){
+	TriGaussParticleLayout *self = (TriGaussParticleLayout*)triGaussParticleLayout;
+	unsigned int dim;
+	unsigned int particlesPerCell;
+
+   _PerCellParticleLayout_AssignFromXML( self, cf, data );
+	dim = Dictionary_Entry_Value_AsUnsignedInt(
+		Dictionary_GetDefault( cf->rootDict, "dim", Dictionary_Entry_Value_FromUnsignedInt( 3 ) ) );
+
+	particlesPerCell = Dictionary_Entry_Value_AsUnsignedInt(
+		Dictionary_GetDefault( cf->rootDict, "particlesPerCell", Dictionary_Entry_Value_FromUnsignedInt( 1 ) ) );
+
+	_TriGaussParticleLayout_Init( self, dim, particlesPerCell );
+}
+	
+void _TriGaussParticleLayout_Build( void* triGaussParticleLayout, void* data ) {
+}
+	
+void _TriGaussParticleLayout_Initialise( void* triGaussParticleLayout, void* data ) {
+}
+	
+void _TriGaussParticleLayout_Execute( void* triGaussParticleLayout, void* data ) {
+}
+	
+void _TriGaussParticleLayout_Destroy( void* triGaussParticleLayout, void* data ) {
+   TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
+   _PerCellParticleLayout_Destroy( self, data );
+}
+
+Particle_InCellIndex _TriGaussParticleLayout_InitialCount( void* triGaussParticleLayout, void* celllayout, Cell_Index cell_I )
+{
+	TriGaussParticleLayout* self = (TriGaussParticleLayout*)triGaussParticleLayout;
+	Particle_InCellIndex count;
+	int dim;	
+	
+	dim = self->dim;
+	count = (Particle_InCellIndex)( self->particlesPerCell );
+	
+	return count;
+}
+
+
+/* remember this only has to initialise one cell of particles at a time */
+void _TriGaussParticleLayout_InitialiseParticlesOfCell( void* triGaussParticleLayout, void* _swarm, Cell_Index cell_I )
+{
+	#define MAX_DIM 3
+	#define MAX_GAUSS_POINTS_2D 1
+	#define MAX_GAUSS_POINTS_3D 1
+	TriGaussParticleLayout*   self = (TriGaussParticleLayout*)triGaussParticleLayout;
+	Swarm*                    swarm = (Swarm*)_swarm;
+	IntegrationPoint*         integrationPoint = NULL;
+
+	Particle_InCellIndex      cParticle_I = 0;
+
+	Particle_InCellIndex ppc;
+	int dim;
+	static double weight[20];
+	static double xi[20][3];
+	static int beenHere = 0;
+	int d;
+	
+	dim = self->dim;
+	ppc = self->particlesPerCell;
+	
+	if( dim == 2 ) {
+		if( ppc == 1 ) {
+			weight[0] = 0.5;
+
+			xi[0][0] = 0.333333333333;
+			xi[0][1] = 0.333333333333;				
+		}
+		if( ppc > MAX_GAUSS_POINTS_2D ) {
+			Journal_Firewall(
+				ppc > MAX_GAUSS_POINTS_2D,
+				Journal_MyStream( Error_Type, self ),
+				"In %s(), error: particlesPerCell greater than implementated tabulated gauss values of %d\n",
+				__func__,
+				MAX_GAUSS_POINTS_2D );
+		}
+	}
+	else if ( dim == 3 ) {
+		if( ppc == 1 ) {
+			weight[0] = 0.5;			
+
+			xi[0][0] = 0.333333333333;
+			xi[0][1] = 0.333333333333;				
+			xi[0][2] = 0.333333333333;				
+		}
+		if( ppc > MAX_GAUSS_POINTS_3D ) {
+			Journal_Firewall(
+				ppc > MAX_GAUSS_POINTS_3D,
+				Journal_MyStream( Error_Type, self ),
+				"In %s(), error: particlesPerCell greater than implementated tabulated gauss values of %d\n",
+				__func__,
+				MAX_GAUSS_POINTS_3D );
+		}
+	}
+
+	assert( ppc <= swarm->cellParticleCountTbl[cell_I] );
+	
+	for ( cParticle_I = 0; cParticle_I < ppc; cParticle_I++ ) {
+		integrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		integrationPoint->owningCell = cell_I;
+			
+		for( d = 0; d < dim; d++ ) {
+			/*integrationPoint->coord[d] = xi[cParticle_I][d];*/
+			integrationPoint->xi[d] = xi[cParticle_I][d];
+		}
+		
+		integrationPoint->weight = weight[cParticle_I];
+		
+		beenHere = 1;
+	}	
+	
+	
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/TriSingleCellLayout.c
--- a/Swarm/src/TriSingleCellLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,266 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TriSingleCellLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "CellLayout.h"
-#include "TriSingleCellLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-const Type TriSingleCellLayout_Type = "TriSingleCellLayout";
-
-
-TriSingleCellLayout* TriSingleCellLayout_New( Name name, AbstractContext* context, int dim, Dictionary* dictionary ) { 
-	TriSingleCellLayout* self = _TriSingleCellLayout_DefaultNew( name );
-
-	self->isConstructed = True;
-	_CellLayout_Init( (CellLayout*)self, context );
-	_TriSingleCellLayout_Init( self, dictionary, dim );
-
-	return self;
-}
-
-TriSingleCellLayout* _TriSingleCellLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                _sizeOfSelf = sizeof(TriSingleCellLayout);
-	Type                                                        type = TriSingleCellLayout_Type;
-	Stg_Class_DeleteFunction*                                _delete = _TriSingleCellLayout_Delete;
-	Stg_Class_PrintFunction*                                  _print = _TriSingleCellLayout_Print;
-	Stg_Class_CopyFunction*                                    _copy = _TriSingleCellLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_TriSingleCellLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                      _construct = _TriSingleCellLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                              _build = _TriSingleCellLayout_Build;
-	Stg_Component_InitialiseFunction*                    _initialise = _TriSingleCellLayout_Initialise;
-	Stg_Component_ExecuteFunction*                          _execute = _TriSingleCellLayout_Execute;
-	Stg_Component_DestroyFunction*                          _destroy = _TriSingleCellLayout_Destroy;
-	AllocationType                                nameAllocationType = NON_GLOBAL;
-	CellLayout_CellCountFunction*                    _cellLocalCount = _TriSingleCellLayout_CellLocalCount;
-	CellLayout_CellCountFunction*                   _cellShadowCount = _TriSingleCellLayout_CellShadowCount;
-	CellLayout_PointCountFunction*                       _pointCount = _TriSingleCellLayout_PointCount;
-	CellLayout_InitialisePointsFunction*           _initialisePoints = _TriSingleCellLayout_InitialisePoints;
-	CellLayout_MapElementIdToCellIdFunction*   _mapElementIdToCellId = _TriSingleCellLayout_MapElementIdToCellId;
-	CellLayout_IsInCellFunction*                           _isInCell = _TriSingleCellLayout_IsInCell;
-	CellLayout_CellOfFunction*                               _cellOf = _TriSingleCellLayout_CellOf;
-	CellLayout_GetShadowInfoFunction*                 _getShadowInfo = _TriSingleCellLayout_GetShadowInfo;
-	Dictionary*                                           dictionary = NULL;
-
-	return (TriSingleCellLayout*)_TriSingleCellLayout_New(  TRISINGLECELLLAYOUT_PASSARGS  );
-}
-
-TriSingleCellLayout* _TriSingleCellLayout_New(  TRISINGLECELLLAYOUT_DEFARGS  ) {
-	TriSingleCellLayout* self;
-	
-	/* Allocate memory */
-	self = (TriSingleCellLayout*)_CellLayout_New(  CELLLAYOUT_PASSARGS  );
-	
-	/* General info */
-	self->dictionary = dictionary;
-	
-	/* Virtual info */
-	
-	/* TriSingleCellLayout info */
-	
-	return self;
-}
-
-void _TriSingleCellLayout_Init( TriSingleCellLayout* self, Dictionary* dictionary, int dim ) { 
-	/* General and Virtual info should already be set */
-	
-	/* SingleCellInfo info */
-	self->dictionary = dictionary;
-	self->dim = dim;
-}
-
-void _TriSingleCellLayout_Delete( void* triSingleCellLayout ) {
-	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
-	
-	/* Stg_Class_Delete parent class */
-	_CellLayout_Delete( self );
-}
-
-void _TriSingleCellLayout_Print( void* triSingleCellLayout, Stream* stream ) {
-	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
-	
-	/* Set the Journal for printing informations */
-	Stream* triSingleCellLayoutStream = stream;
-	
-	/* General info */
-	Journal_Printf( triSingleCellLayoutStream, "TriSingleCellLayout (ptr): %p\n", self ); 
-	
-	/* Parent class info */
-	_CellLayout_Print( self, stream );
-	
-	/* Virtual info */
-	
-	/* TriSingleCellLayout info */
-	Journal_Printf( triSingleCellLayoutStream, "self->dim: %u", self->dim );
-}
-
-
-void* _TriSingleCellLayout_Copy( const void* triSingleCellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	TriSingleCellLayout*	self = (TriSingleCellLayout*)triSingleCellLayout;
-	TriSingleCellLayout*	newTriSingleCellLayout;
-	
-	newTriSingleCellLayout = (TriSingleCellLayout*)_CellLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newTriSingleCellLayout->dictionary = self->dictionary;
-	newTriSingleCellLayout->dim = self->dim;
-	
-	return (void*)newTriSingleCellLayout;
-}
-	
-void _TriSingleCellLayout_AssignFromXML( void *triSingleCellLayout, Stg_ComponentFactory *cf, void* data ){
-	TriSingleCellLayout	*self = (TriSingleCellLayout*)triSingleCellLayout;
-	Dimension_Index		dim = 0;
-
-	_CellLayout_AssignFromXML( self, cf, data );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0 );
-	assert( dim );
-
-	_TriSingleCellLayout_Init( (TriSingleCellLayout* )self, cf->rootDict, dim );
-}
-	
-void _TriSingleCellLayout_Build( void* triSingleCellLayout, void* data ){
-	
-}
-	
-void _TriSingleCellLayout_Initialise( void* triSingleCellLayout, void* data ){
-	
-}
-	
-void _TriSingleCellLayout_Execute( void* triSingleCellLayout, void* data ){
-	
-}
-	
-void _TriSingleCellLayout_Destroy( void* triSingleCellLayout, void* data ){
-	TriSingleCellLayout	*self = (TriSingleCellLayout*)triSingleCellLayout;
-
-	_CellLayout_Destroy( self, data );	
-}
-
-Cell_Index _TriSingleCellLayout_CellLocalCount( void* triSingleCellLayout ) {
-	/* There is only one cell... */
-	return 1;
-}
-
-
-Cell_Index _TriSingleCellLayout_CellShadowCount( void* triSingleCellLayout ) {
-	/* No shadow cells */
-	return 0;
-}
-
-
-Cell_PointIndex _TriSingleCellLayout_PointCount( void* triSingleCellLayout, Cell_Index cellIndex ) {
-	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
-	
-	switch( self->dim ) {
-		case 1:
-			return 2;
-		case 2:
-			return 3;
-		case 3:
-			return 4;
-		default:
-			assert( 0 );
-	}
-	return 0;
-}
-
-
-void _TriSingleCellLayout_InitialisePoints( 
-		void*			triSingleCellLayout, 
-		Cell_Index		cellIndex, 
-		Cell_PointIndex		pointCount, 
-		Cell_Points		points ) 
-{
-	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
-	
-	switch( self->dim ) {
-		case 1:
-			assert( 0 );
-		case 2:
-			*points[0] = Memory_Alloc_Array( double, self->dim, "points[0]" );
-			*points[1] = Memory_Alloc_Array( double, self->dim, "points[1]" );
-			*points[2] = Memory_Alloc_Array( double, self->dim, "points[2]" );
-			
-			(*points[0])[0] = 0.0f;
-			(*points[0])[1] = 0.0f;
-			(*points[1])[0] = 1.0f;
-			(*points[1])[1] = 0.0f;
-			(*points[2])[0] = 0.0f;
-			(*points[2])[1] = 1.0f;
-			break;
-		case 3:
-			assert( 0 );
-		default:
-			assert( 0 );
-	}
-}
-
-
-Cell_Index _TriSingleCellLayout_MapElementIdToCellId( void* cellLayout, Element_DomainIndex element_dI ) {
-	
-	/* Always 0: see the header comment */
-	return 0;
-}
-
-
-Bool _TriSingleCellLayout_IsInCell( void* triSingleCellLayout, Cell_Index cellIndex, void* particle ) {
-	assert( 0 );
-	return False;
-}
-
-
-Cell_Index _TriSingleCellLayout_CellOf( void* triSingleCellLayout, void* particle ) {
-	assert( 0 );
-	return 0;
-}
-
-
-ShadowInfo* _TriSingleCellLayout_GetShadowInfo( void* triSingleCellLayout ) {
-  /*TriSingleCellLayout*      self = (TriSingleCellLayout*)triSingleCellLayout; */
-
-	/* TODO: this should return a shadow info with at least nbr info for my processors */
-	Journal_Firewall( 0, Swarm_Warning, "Error: %s not implemented yet!\n", __func__ );
-	return NULL;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/TriSingleCellLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/TriSingleCellLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,266 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TriSingleCellLayout.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "CellLayout.h"
+#include "TriSingleCellLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+const Type TriSingleCellLayout_Type = "TriSingleCellLayout";
+
+
+TriSingleCellLayout* TriSingleCellLayout_New( Name name, AbstractContext* context, int dim, Dictionary* dictionary ) { 
+	TriSingleCellLayout* self = _TriSingleCellLayout_DefaultNew( name );
+
+	self->isConstructed = True;
+	_CellLayout_Init( (CellLayout*)self, context );
+	_TriSingleCellLayout_Init( self, dictionary, dim );
+
+	return self;
+}
+
+TriSingleCellLayout* _TriSingleCellLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                _sizeOfSelf = sizeof(TriSingleCellLayout);
+	Type                                                        type = TriSingleCellLayout_Type;
+	Stg_Class_DeleteFunction*                                _delete = _TriSingleCellLayout_Delete;
+	Stg_Class_PrintFunction*                                  _print = _TriSingleCellLayout_Print;
+	Stg_Class_CopyFunction*                                    _copy = _TriSingleCellLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*    _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_TriSingleCellLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                      _construct = _TriSingleCellLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                              _build = _TriSingleCellLayout_Build;
+	Stg_Component_InitialiseFunction*                    _initialise = _TriSingleCellLayout_Initialise;
+	Stg_Component_ExecuteFunction*                          _execute = _TriSingleCellLayout_Execute;
+	Stg_Component_DestroyFunction*                          _destroy = _TriSingleCellLayout_Destroy;
+	AllocationType                                nameAllocationType = NON_GLOBAL;
+	CellLayout_CellCountFunction*                    _cellLocalCount = _TriSingleCellLayout_CellLocalCount;
+	CellLayout_CellCountFunction*                   _cellShadowCount = _TriSingleCellLayout_CellShadowCount;
+	CellLayout_PointCountFunction*                       _pointCount = _TriSingleCellLayout_PointCount;
+	CellLayout_InitialisePointsFunction*           _initialisePoints = _TriSingleCellLayout_InitialisePoints;
+	CellLayout_MapElementIdToCellIdFunction*   _mapElementIdToCellId = _TriSingleCellLayout_MapElementIdToCellId;
+	CellLayout_IsInCellFunction*                           _isInCell = _TriSingleCellLayout_IsInCell;
+	CellLayout_CellOfFunction*                               _cellOf = _TriSingleCellLayout_CellOf;
+	CellLayout_GetShadowInfoFunction*                 _getShadowInfo = _TriSingleCellLayout_GetShadowInfo;
+	Dictionary*                                           dictionary = NULL;
+
+	return (TriSingleCellLayout*)_TriSingleCellLayout_New(  TRISINGLECELLLAYOUT_PASSARGS  );
+}
+
+TriSingleCellLayout* _TriSingleCellLayout_New(  TRISINGLECELLLAYOUT_DEFARGS  ) {
+	TriSingleCellLayout* self;
+	
+	/* Allocate memory */
+	self = (TriSingleCellLayout*)_CellLayout_New(  CELLLAYOUT_PASSARGS  );
+	
+	/* General info */
+	self->dictionary = dictionary;
+	
+	/* Virtual info */
+	
+	/* TriSingleCellLayout info */
+	
+	return self;
+}
+
+void _TriSingleCellLayout_Init( TriSingleCellLayout* self, Dictionary* dictionary, int dim ) { 
+	/* General and Virtual info should already be set */
+	
+	/* SingleCellInfo info */
+	self->dictionary = dictionary;
+	self->dim = dim;
+}
+
+void _TriSingleCellLayout_Delete( void* triSingleCellLayout ) {
+	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
+	
+	/* Stg_Class_Delete parent class */
+	_CellLayout_Delete( self );
+}
+
+void _TriSingleCellLayout_Print( void* triSingleCellLayout, Stream* stream ) {
+	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
+	
+	/* Set the Journal for printing informations */
+	Stream* triSingleCellLayoutStream = stream;
+	
+	/* General info */
+	Journal_Printf( triSingleCellLayoutStream, "TriSingleCellLayout (ptr): %p\n", self ); 
+	
+	/* Parent class info */
+	_CellLayout_Print( self, stream );
+	
+	/* Virtual info */
+	
+	/* TriSingleCellLayout info */
+	Journal_Printf( triSingleCellLayoutStream, "self->dim: %u", self->dim );
+}
+
+
+void* _TriSingleCellLayout_Copy( const void* triSingleCellLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	TriSingleCellLayout*	self = (TriSingleCellLayout*)triSingleCellLayout;
+	TriSingleCellLayout*	newTriSingleCellLayout;
+	
+	newTriSingleCellLayout = (TriSingleCellLayout*)_CellLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newTriSingleCellLayout->dictionary = self->dictionary;
+	newTriSingleCellLayout->dim = self->dim;
+	
+	return (void*)newTriSingleCellLayout;
+}
+	
+void _TriSingleCellLayout_AssignFromXML( void *triSingleCellLayout, Stg_ComponentFactory *cf, void* data ){
+	TriSingleCellLayout	*self = (TriSingleCellLayout*)triSingleCellLayout;
+	Dimension_Index		dim = 0;
+
+	_CellLayout_AssignFromXML( self, cf, data );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0 );
+	assert( dim );
+
+	_TriSingleCellLayout_Init( (TriSingleCellLayout* )self, cf->rootDict, dim );
+}
+	
+void _TriSingleCellLayout_Build( void* triSingleCellLayout, void* data ){
+	
+}
+	
+void _TriSingleCellLayout_Initialise( void* triSingleCellLayout, void* data ){
+	
+}
+	
+void _TriSingleCellLayout_Execute( void* triSingleCellLayout, void* data ){
+	
+}
+	
+void _TriSingleCellLayout_Destroy( void* triSingleCellLayout, void* data ){
+	TriSingleCellLayout	*self = (TriSingleCellLayout*)triSingleCellLayout;
+
+	_CellLayout_Destroy( self, data );	
+}
+
+Cell_Index _TriSingleCellLayout_CellLocalCount( void* triSingleCellLayout ) {
+	/* There is only one cell... */
+	return 1;
+}
+
+
+Cell_Index _TriSingleCellLayout_CellShadowCount( void* triSingleCellLayout ) {
+	/* No shadow cells */
+	return 0;
+}
+
+
+Cell_PointIndex _TriSingleCellLayout_PointCount( void* triSingleCellLayout, Cell_Index cellIndex ) {
+	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
+	
+	switch( self->dim ) {
+		case 1:
+			return 2;
+		case 2:
+			return 3;
+		case 3:
+			return 4;
+		default:
+			assert( 0 );
+	}
+	return 0;
+}
+
+
+void _TriSingleCellLayout_InitialisePoints( 
+		void*			triSingleCellLayout, 
+		Cell_Index		cellIndex, 
+		Cell_PointIndex		pointCount, 
+		Cell_Points		points ) 
+{
+	TriSingleCellLayout* self = (TriSingleCellLayout*)triSingleCellLayout;
+	
+	switch( self->dim ) {
+		case 1:
+			assert( 0 );
+		case 2:
+			*points[0] = Memory_Alloc_Array( double, self->dim, "points[0]" );
+			*points[1] = Memory_Alloc_Array( double, self->dim, "points[1]" );
+			*points[2] = Memory_Alloc_Array( double, self->dim, "points[2]" );
+			
+			(*points[0])[0] = 0.0f;
+			(*points[0])[1] = 0.0f;
+			(*points[1])[0] = 1.0f;
+			(*points[1])[1] = 0.0f;
+			(*points[2])[0] = 0.0f;
+			(*points[2])[1] = 1.0f;
+			break;
+		case 3:
+			assert( 0 );
+		default:
+			assert( 0 );
+	}
+}
+
+
+Cell_Index _TriSingleCellLayout_MapElementIdToCellId( void* cellLayout, Element_DomainIndex element_dI ) {
+	
+	/* Always 0: see the header comment */
+	return 0;
+}
+
+
+Bool _TriSingleCellLayout_IsInCell( void* triSingleCellLayout, Cell_Index cellIndex, void* particle ) {
+	assert( 0 );
+	return False;
+}
+
+
+Cell_Index _TriSingleCellLayout_CellOf( void* triSingleCellLayout, void* particle ) {
+	assert( 0 );
+	return 0;
+}
+
+
+ShadowInfo* _TriSingleCellLayout_GetShadowInfo( void* triSingleCellLayout ) {
+  /*TriSingleCellLayout*      self = (TriSingleCellLayout*)triSingleCellLayout; */
+
+	/* TODO: this should return a shadow info with at least nbr info for my processors */
+	Journal_Firewall( 0, Swarm_Warning, "Error: %s not implemented yet!\n", __func__ );
+	return NULL;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/UnionParticleLayout.c
--- a/Swarm/src/UnionParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,239 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: UnionParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "UnionParticleLayout.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-const Type UnionParticleLayout_Type = "UnionParticleLayout";
-
-UnionParticleLayout* UnionParticleLayout_New(
-		Name             name, 
-      AbstractContext* context, 
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles, 
-      double           averageInitialParticlesPerCell,
-		GlobalParticleLayout** particleLayoutList,
-		Index                  particleLayoutCount )
-{
-	UnionParticleLayout* self = (UnionParticleLayout*) _UnionParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-	_UnionParticleLayout_Init( self, particleLayoutList, particleLayoutCount );
-	return self;
-}
-
-UnionParticleLayout* _UnionParticleLayout_New(  UNIONPARTICLELAYOUT_DEFARGS  )
-{
-	UnionParticleLayout* self;
-	
-	/* Allocate memory */
-	self = (UnionParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
-
-   self->particleLayoutList = particleLayoutList;
-   self->particleLayoutCount = particleLayoutCount;
-
-	return self;
-}
-
-void _UnionParticleLayout_Init( 
-		void*                                            unionParticleLayout, 
-		GlobalParticleLayout**                           particleLayoutList,
-		Index                                            particleLayoutCount )
-{
-	UnionParticleLayout*	self = (UnionParticleLayout*) unionParticleLayout;
-	self->isConstructed = True;
-	
-	self->particleLayoutList = particleLayoutList;
-	self->particleLayoutCount = particleLayoutCount;
-}
-
-
-	
-void _UnionParticleLayout_Delete( void* unionParticleLayout ) {
-	UnionParticleLayout* self = (UnionParticleLayout*)unionParticleLayout;
-
-	_GlobalParticleLayout_Delete( self );
-}
-
-void _UnionParticleLayout_Print( void* unionParticleLayout, Stream* stream ) {
-	UnionParticleLayout* self  = (UnionParticleLayout*)unionParticleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "UnionParticleLayout (ptr): %p:\n", self );
-	Stream_Indent( stream );
-	
-	/* Parent class info */
-	_GlobalParticleLayout_Print( self, stream );
-	
-	/* UnionParticleLayout */
-	
-	Stream_UnIndent( stream );
-}
-
-void* _UnionParticleLayout_Copy( const void* unionParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	UnionParticleLayout*		self                    = (UnionParticleLayout*)unionParticleLayout;
-	UnionParticleLayout*		newUnionParticleLayout;
-	
-	newUnionParticleLayout = (UnionParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	return (void*)newUnionParticleLayout;
-}
-
-void* _UnionParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(UnionParticleLayout);
-	Type                                                                        type = UnionParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _UnionParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _UnionParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _UnionParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _UnionParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _UnionParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _UnionParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _UnionParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _UnionParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _UnionParticleLayout_Destroy;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _UnionParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _UnionParticleLayout_InitialiseParticles;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _UnionParticleLayout_InitialiseParticle;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	GlobalParticleLayout**                                        particleLayoutList = NULL;
-	Index                                                        particleLayoutCount = 0;
-
-	return (void*)_UnionParticleLayout_New(  UNIONPARTICLELAYOUT_PASSARGS  );
-}
-
-
-void _UnionParticleLayout_AssignFromXML( void* unionParticleLayout, Stg_ComponentFactory *cf, void* data ) {
-	UnionParticleLayout*   self = (UnionParticleLayout*) unionParticleLayout;
-	GlobalParticleLayout** particleLayoutList;
-	Index                  particleLayoutCount;
-
-   _GlobalParticleLayout_AssignFromXML( self, cf, data );
-	
-	particleLayoutList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"ParticleLayoutList", Stg_ComponentFactory_Unlimited, GlobalParticleLayout, True, &particleLayoutCount, data  );
-
-	_UnionParticleLayout_Init( self, particleLayoutList, particleLayoutCount );
-}
-	
-void _UnionParticleLayout_Build( void* unionParticleLayout, void* data ) {
-   UnionParticleLayout* self     = (UnionParticleLayout*)unionParticleLayout;
-   unsigned ii = 0;
-   for( ii = 0 ; ii < self->particleLayoutCount ; ii++ ) {
-      Stg_Component_Build( self->particleLayoutList[ii], data, False );
-   }
-}
-void _UnionParticleLayout_Initialise( void* unionParticleLayout, void* data ) {
-   UnionParticleLayout* self     = (UnionParticleLayout*)unionParticleLayout;
-   unsigned ii = 0;
-   for( ii = 0 ; ii < self->particleLayoutCount ; ii++ ) {
-      Stg_Component_Initialise( self->particleLayoutList[ii], data, False );
-   }
-}	
-void _UnionParticleLayout_Execute( void* unionParticleLayout, void* data ) {	
-}
-void _UnionParticleLayout_Destroy( void* unionParticleLayout, void* data ) {	
-	UnionParticleLayout* self     = (UnionParticleLayout*)unionParticleLayout;
-   unsigned ii = 0;
-
-   for( ii = 0 ; ii < self->particleLayoutCount ; ii++ ) {
-      Stg_Component_Destroy( self->particleLayoutList[ii], data, False );
-   }
-
-   _GlobalParticleLayout_Destroy( self, data );
-}
-
-void _UnionParticleLayout_SetInitialCounts( void* unionParticleLayout, void* _swarm ) {
-	UnionParticleLayout*        self     = (UnionParticleLayout*)unionParticleLayout;
-	Swarm*                      swarm    = (Swarm*)_swarm;
-	Index                       layout_I;
-
-	/* Get total number of particles from total number of layouts in the list */
-	self->totalInitialParticles = 0 ;
-	for ( layout_I = 0 ; layout_I < self->particleLayoutCount ; layout_I++ ) {
-		ParticleLayout_SetInitialCounts( self->particleLayoutList[ layout_I ], swarm );
-		self->totalInitialParticles += self->particleLayoutList[ layout_I ]->totalInitialParticles;
-	}
-
-	/* Call parent function */
-	_GlobalParticleLayout_SetInitialCounts( self, swarm );
-}
-void _UnionParticleLayout_InitialiseParticles( void* unionParticleLayout, void* swarm ) {
-	UnionParticleLayout*        self     = (UnionParticleLayout*)unionParticleLayout;
-
-	/* Call parent function */
-	_GlobalParticleLayout_InitialiseParticles( self, swarm );
-}
-
-void _UnionParticleLayout_InitialiseParticle( 
-		void*             unionParticleLayout, 
-		void*             swarm, 
-		Particle_Index    newParticle_I,
-		void*             particle )
-{
-	UnionParticleLayout*        self     = (UnionParticleLayout*)unionParticleLayout;
-	Index                       layout_I;
-
-	/* Loop over particle layouts until you find which layout should initialise this particle 
-	 * When one particle layout finishes initialises all its particles, then the next one begins. */
-	for ( layout_I = 0 ; layout_I < self->particleLayoutCount ; layout_I++ ) {
-		/* See if this particle belongs to this particle layout */
-		if ( newParticle_I < self->particleLayoutList[ layout_I ]->totalInitialParticles ) {
-			GlobalParticleLayout_InitialiseParticle( self->particleLayoutList[ layout_I ], swarm, newParticle_I, particle );
-			return;
-		}
-
-		/* Decrement particle number */
-		newParticle_I -= self->particleLayoutList[ layout_I ]->totalInitialParticles;
-	}
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/UnionParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/UnionParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,239 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: UnionParticleLayout.c 3851 2006-10-12 08:57:22Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "UnionParticleLayout.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+const Type UnionParticleLayout_Type = "UnionParticleLayout";
+
+UnionParticleLayout* UnionParticleLayout_New(
+		Name             name, 
+      AbstractContext* context, 
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles, 
+      double           averageInitialParticlesPerCell,
+		GlobalParticleLayout** particleLayoutList,
+		Index                  particleLayoutCount )
+{
+	UnionParticleLayout* self = (UnionParticleLayout*) _UnionParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+	_UnionParticleLayout_Init( self, particleLayoutList, particleLayoutCount );
+	return self;
+}
+
+UnionParticleLayout* _UnionParticleLayout_New(  UNIONPARTICLELAYOUT_DEFARGS  )
+{
+	UnionParticleLayout* self;
+	
+	/* Allocate memory */
+	self = (UnionParticleLayout*)_GlobalParticleLayout_New(  GLOBALPARTICLELAYOUT_PASSARGS  );
+
+   self->particleLayoutList = particleLayoutList;
+   self->particleLayoutCount = particleLayoutCount;
+
+	return self;
+}
+
+void _UnionParticleLayout_Init( 
+		void*                                            unionParticleLayout, 
+		GlobalParticleLayout**                           particleLayoutList,
+		Index                                            particleLayoutCount )
+{
+	UnionParticleLayout*	self = (UnionParticleLayout*) unionParticleLayout;
+	self->isConstructed = True;
+	
+	self->particleLayoutList = particleLayoutList;
+	self->particleLayoutCount = particleLayoutCount;
+}
+
+
+	
+void _UnionParticleLayout_Delete( void* unionParticleLayout ) {
+	UnionParticleLayout* self = (UnionParticleLayout*)unionParticleLayout;
+
+	_GlobalParticleLayout_Delete( self );
+}
+
+void _UnionParticleLayout_Print( void* unionParticleLayout, Stream* stream ) {
+	UnionParticleLayout* self  = (UnionParticleLayout*)unionParticleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "UnionParticleLayout (ptr): %p:\n", self );
+	Stream_Indent( stream );
+	
+	/* Parent class info */
+	_GlobalParticleLayout_Print( self, stream );
+	
+	/* UnionParticleLayout */
+	
+	Stream_UnIndent( stream );
+}
+
+void* _UnionParticleLayout_Copy( const void* unionParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	UnionParticleLayout*		self                    = (UnionParticleLayout*)unionParticleLayout;
+	UnionParticleLayout*		newUnionParticleLayout;
+	
+	newUnionParticleLayout = (UnionParticleLayout*)_GlobalParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	return (void*)newUnionParticleLayout;
+}
+
+void* _UnionParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(UnionParticleLayout);
+	Type                                                                        type = UnionParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _UnionParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _UnionParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _UnionParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _UnionParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _UnionParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _UnionParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _UnionParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _UnionParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _UnionParticleLayout_Destroy;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _UnionParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _UnionParticleLayout_InitialiseParticles;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _UnionParticleLayout_InitialiseParticle;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	GlobalParticleLayout**                                        particleLayoutList = NULL;
+	Index                                                        particleLayoutCount = 0;
+
+	return (void*)_UnionParticleLayout_New(  UNIONPARTICLELAYOUT_PASSARGS  );
+}
+
+
+void _UnionParticleLayout_AssignFromXML( void* unionParticleLayout, Stg_ComponentFactory *cf, void* data ) {
+	UnionParticleLayout*   self = (UnionParticleLayout*) unionParticleLayout;
+	GlobalParticleLayout** particleLayoutList;
+	Index                  particleLayoutCount;
+
+   _GlobalParticleLayout_AssignFromXML( self, cf, data );
+	
+	particleLayoutList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"ParticleLayoutList", Stg_ComponentFactory_Unlimited, GlobalParticleLayout, True, &particleLayoutCount, data  );
+
+	_UnionParticleLayout_Init( self, particleLayoutList, particleLayoutCount );
+}
+	
+void _UnionParticleLayout_Build( void* unionParticleLayout, void* data ) {
+   UnionParticleLayout* self     = (UnionParticleLayout*)unionParticleLayout;
+   unsigned ii = 0;
+   for( ii = 0 ; ii < self->particleLayoutCount ; ii++ ) {
+      Stg_Component_Build( self->particleLayoutList[ii], data, False );
+   }
+}
+void _UnionParticleLayout_Initialise( void* unionParticleLayout, void* data ) {
+   UnionParticleLayout* self     = (UnionParticleLayout*)unionParticleLayout;
+   unsigned ii = 0;
+   for( ii = 0 ; ii < self->particleLayoutCount ; ii++ ) {
+      Stg_Component_Initialise( self->particleLayoutList[ii], data, False );
+   }
+}	
+void _UnionParticleLayout_Execute( void* unionParticleLayout, void* data ) {	
+}
+void _UnionParticleLayout_Destroy( void* unionParticleLayout, void* data ) {	
+	UnionParticleLayout* self     = (UnionParticleLayout*)unionParticleLayout;
+   unsigned ii = 0;
+
+   for( ii = 0 ; ii < self->particleLayoutCount ; ii++ ) {
+      Stg_Component_Destroy( self->particleLayoutList[ii], data, False );
+   }
+
+   _GlobalParticleLayout_Destroy( self, data );
+}
+
+void _UnionParticleLayout_SetInitialCounts( void* unionParticleLayout, void* _swarm ) {
+	UnionParticleLayout*        self     = (UnionParticleLayout*)unionParticleLayout;
+	Swarm*                      swarm    = (Swarm*)_swarm;
+	Index                       layout_I;
+
+	/* Get total number of particles from total number of layouts in the list */
+	self->totalInitialParticles = 0 ;
+	for ( layout_I = 0 ; layout_I < self->particleLayoutCount ; layout_I++ ) {
+		ParticleLayout_SetInitialCounts( self->particleLayoutList[ layout_I ], swarm );
+		self->totalInitialParticles += self->particleLayoutList[ layout_I ]->totalInitialParticles;
+	}
+
+	/* Call parent function */
+	_GlobalParticleLayout_SetInitialCounts( self, swarm );
+}
+void _UnionParticleLayout_InitialiseParticles( void* unionParticleLayout, void* swarm ) {
+	UnionParticleLayout*        self     = (UnionParticleLayout*)unionParticleLayout;
+
+	/* Call parent function */
+	_GlobalParticleLayout_InitialiseParticles( self, swarm );
+}
+
+void _UnionParticleLayout_InitialiseParticle( 
+		void*             unionParticleLayout, 
+		void*             swarm, 
+		Particle_Index    newParticle_I,
+		void*             particle )
+{
+	UnionParticleLayout*        self     = (UnionParticleLayout*)unionParticleLayout;
+	Index                       layout_I;
+
+	/* Loop over particle layouts until you find which layout should initialise this particle 
+	 * When one particle layout finishes initialises all its particles, then the next one begins. */
+	for ( layout_I = 0 ; layout_I < self->particleLayoutCount ; layout_I++ ) {
+		/* See if this particle belongs to this particle layout */
+		if ( newParticle_I < self->particleLayoutList[ layout_I ]->totalInitialParticles ) {
+			GlobalParticleLayout_InitialiseParticle( self->particleLayoutList[ layout_I ], swarm, newParticle_I, particle );
+			return;
+		}
+
+		/* Decrement particle number */
+		newParticle_I -= self->particleLayoutList[ layout_I ]->totalInitialParticles;
+	}
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/WithinShapeParticleLayout.c
--- a/Swarm/src/WithinShapeParticleLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,236 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: WithinShapeParticleLayout.c 4102 2007-05-16 01:09:00Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-
-#include "types.h"
-#include "shortcuts.h"
-#include "ParticleLayout.h"
-#include "GlobalParticleLayout.h"
-#include "SpaceFillerParticleLayout.h"
-#include "WithinShapeParticleLayout.h"
-#include "CellLayout.h"
-#include "SwarmClass.h"
-#include "StandardParticle.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-
-const Type WithinShapeParticleLayout_Type = "WithinShapeParticleLayout";
-
-const Index WithinShapeParticleLayout_Invalid = (Index) 0;
-
-WithinShapeParticleLayout* WithinShapeParticleLayout_New(
-      Name             name,
-      AbstractContext* context, 
-      CoordSystem      coordSystem,
-      Bool             weightsInitialisedAtStartup,
-      unsigned int     totalInitialParticles, 
-      double           averageInitialParticlesPerCell,
-      Dimension_Index  dim,
-		Stg_Shape*       shape )
-{
-	WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) _WithinShapeParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
-	_SpaceFillerParticleLayout_Init( self, dim );
-	_WithinShapeParticleLayout_Init( self, shape );
-
-	return self;
-}
-
-WithinShapeParticleLayout* _WithinShapeParticleLayout_New(  WITHINSHAPEPARTICLELAYOUT_DEFARGS  )
-{
-	WithinShapeParticleLayout* self;
-	
-	/* Allocate memory */
-	self = (WithinShapeParticleLayout*)_SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_PASSARGS  );  /* dim */
-
-   self->shape = shape;
-
-	return self;
-}
-
-void _WithinShapeParticleLayout_Init(
-		void*                   withinShapeParticleLayout,
-		Stg_Shape*              shape )
-{
-	WithinShapeParticleLayout*	self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
-
-	self->isConstructed = True;
-	self->shape         = shape;
-}
-
-
-
-	
-void _WithinShapeParticleLayout_Delete( void* withinShapeParticleLayout ) {
-	WithinShapeParticleLayout* self = (WithinShapeParticleLayout*)withinShapeParticleLayout;
-
-	/* Stg_Class_Delete parent class */
-	_SpaceFillerParticleLayout_Delete( self );
-
-}
-
-void _WithinShapeParticleLayout_Print( void* withinShapeParticleLayout, Stream* stream ) {
-	WithinShapeParticleLayout* self  = (WithinShapeParticleLayout*)withinShapeParticleLayout;
-	
-	/* General info */
-	Journal_Printf( stream, "WithinShapeParticleLayout (ptr): %p:\n", self );
-	Stream_Indent( stream );
-	
-	/* Parent class info */
-	_SpaceFillerParticleLayout_Print( self, stream );
-	
-	/* WithinShapeParticleLayout */
-	Stg_Class_Print( self->shape, stream );
-	
-	Stream_UnIndent( stream );
-}
-
-
-void* _WithinShapeParticleLayout_Copy( const void* withinShapeParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	WithinShapeParticleLayout*		self                    = (WithinShapeParticleLayout*)withinShapeParticleLayout;
-	WithinShapeParticleLayout*		newWithinShapeParticleLayout;
-	
-	newWithinShapeParticleLayout = (WithinShapeParticleLayout*)_SpaceFillerParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	if ( deep ) {
-		newWithinShapeParticleLayout->shape = (Stg_Shape*)Stg_Class_Copy( self->shape, NULL, deep, nameExt, ptrMap );
-	}
-	else {
-		newWithinShapeParticleLayout->shape = self->shape;
-	}
-
-	return (void*)newWithinShapeParticleLayout;
-}
-
-void* _WithinShapeParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                _sizeOfSelf = sizeof(WithinShapeParticleLayout);
-	Type                                                                        type = WithinShapeParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                                _delete = _WithinShapeParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                                  _print = _WithinShapeParticleLayout_Print;
-	Stg_Class_CopyFunction*                                                    _copy = _WithinShapeParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _WithinShapeParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                                      _construct = _WithinShapeParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                              _build = _WithinShapeParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                                    _initialise = _WithinShapeParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                          _execute = _WithinShapeParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                          _destroy = _WithinShapeParticleLayout_Destroy;
-	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _WithinShapeParticleLayout_InitialiseParticles;
-	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _SpaceFillerParticleLayout_InitialiseParticle;
-	AllocationType                                                nameAllocationType = NON_GLOBAL;
-	CoordSystem                                                          coordSystem = GlobalCoordSystem;
-	Bool                                                 weightsInitialisedAtStartup = False;
-	Particle_Index                                             totalInitialParticles = 0;
-	double                                            averageInitialParticlesPerCell = 0.0;
-	Dimension_Index                                                              dim = 0;
-	Stg_Shape*                                                                 shape = NULL;
-
-   return (void*)_WithinShapeParticleLayout_New(  WITHINSHAPEPARTICLELAYOUT_PASSARGS  );
-}
-
-void _WithinShapeParticleLayout_AssignFromXML( void* withinShapeParticleLayout, Stg_ComponentFactory *cf, void* data ) {
-	WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
-	Stg_Shape*      shape;
-	
-	_SpaceFillerParticleLayout_AssignFromXML( self, cf, data );
-
-	shape = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"shape", Stg_Shape, True, data  ) ;
-
-	_WithinShapeParticleLayout_Init( self, shape );
-}
-	
-void _WithinShapeParticleLayout_Build( void* withinShapeParticleLayout, void* data ) {
-   WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
-   _SpaceFillerParticleLayout_Build( self, data );
-}
-void _WithinShapeParticleLayout_Initialise( void* withinShapeParticleLayout, void* data ) {
-   WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
-   _SpaceFillerParticleLayout_Initialise( self, data );
-}
-void _WithinShapeParticleLayout_Execute( void* withinShapeParticleLayout, void* data ) {
-}
-void _WithinShapeParticleLayout_Destroy( void* withinShapeParticleLayout, void* data ) {
-   WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
-
-   Stg_Component_Destroy( self->shape, data, False );
-
-   _SpaceFillerParticleLayout_Destroy( self, data );
-}
-
-void _WithinShapeParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
-{
-	WithinShapeParticleLayout*	self          = (WithinShapeParticleLayout*)particleLayout;
-	Swarm*			        swarm         = (Swarm*)_swarm;
-	GlobalParticle*                 particle      = NULL;
-	Particle_Index		        lParticle_I   = 0;
-	Particle_Index		        newParticle_I = 0;
-	Cell_Index		        cell_I;
-	
-	/* Go through and init particles */
-	while( newParticle_I < self->totalInitialParticles ) {
-		
-		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-
-		GlobalParticleLayout_InitialiseParticle( self, swarm, newParticle_I, particle );
-
-		/* Test the particle is inside our desired shape */
-		if ( Stg_Shape_IsCoordInside( self->shape, particle->coord ) ) {
-			
-			newParticle_I++;
-			/* Work out which cell the new particle is in */
-			/* First specify the particle doesn't have an owning cell yet, so as
-			not to confuse the search algorithm */
-			particle->owningCell = swarm->cellDomainCount;
-			cell_I = CellLayout_CellOf( swarm->cellLayout, particle );
-
-			/* If we found a further particle inside our domain add it to a cell */
-			if ( cell_I < swarm->cellLocalCount ) {
-				/* Add it to that cell */
-				Swarm_AddParticleToCell( swarm, cell_I, lParticle_I );
-				lParticle_I++;
-				swarm->particleLocalCount++;
-				Swarm_Realloc( swarm );
-			}
-		}
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/src/WithinShapeParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/src/WithinShapeParticleLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,236 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: WithinShapeParticleLayout.c 4102 2007-05-16 01:09:00Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+
+#include "types.h"
+#include "shortcuts.h"
+#include "ParticleLayout.h"
+#include "GlobalParticleLayout.h"
+#include "SpaceFillerParticleLayout.h"
+#include "WithinShapeParticleLayout.h"
+#include "CellLayout.h"
+#include "SwarmClass.h"
+#include "StandardParticle.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+const Type WithinShapeParticleLayout_Type = "WithinShapeParticleLayout";
+
+const Index WithinShapeParticleLayout_Invalid = (Index) 0;
+
+WithinShapeParticleLayout* WithinShapeParticleLayout_New(
+      Name             name,
+      AbstractContext* context, 
+      CoordSystem      coordSystem,
+      Bool             weightsInitialisedAtStartup,
+      unsigned int     totalInitialParticles, 
+      double           averageInitialParticlesPerCell,
+      Dimension_Index  dim,
+		Stg_Shape*       shape )
+{
+	WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) _WithinShapeParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _GlobalParticleLayout_Init( self, totalInitialParticles, averageInitialParticlesPerCell );
+	_SpaceFillerParticleLayout_Init( self, dim );
+	_WithinShapeParticleLayout_Init( self, shape );
+
+	return self;
+}
+
+WithinShapeParticleLayout* _WithinShapeParticleLayout_New(  WITHINSHAPEPARTICLELAYOUT_DEFARGS  )
+{
+	WithinShapeParticleLayout* self;
+	
+	/* Allocate memory */
+	self = (WithinShapeParticleLayout*)_SpaceFillerParticleLayout_New(  SPACEFILLERPARTICLELAYOUT_PASSARGS  );  /* dim */
+
+   self->shape = shape;
+
+	return self;
+}
+
+void _WithinShapeParticleLayout_Init(
+		void*                   withinShapeParticleLayout,
+		Stg_Shape*              shape )
+{
+	WithinShapeParticleLayout*	self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
+
+	self->isConstructed = True;
+	self->shape         = shape;
+}
+
+
+
+	
+void _WithinShapeParticleLayout_Delete( void* withinShapeParticleLayout ) {
+	WithinShapeParticleLayout* self = (WithinShapeParticleLayout*)withinShapeParticleLayout;
+
+	/* Stg_Class_Delete parent class */
+	_SpaceFillerParticleLayout_Delete( self );
+
+}
+
+void _WithinShapeParticleLayout_Print( void* withinShapeParticleLayout, Stream* stream ) {
+	WithinShapeParticleLayout* self  = (WithinShapeParticleLayout*)withinShapeParticleLayout;
+	
+	/* General info */
+	Journal_Printf( stream, "WithinShapeParticleLayout (ptr): %p:\n", self );
+	Stream_Indent( stream );
+	
+	/* Parent class info */
+	_SpaceFillerParticleLayout_Print( self, stream );
+	
+	/* WithinShapeParticleLayout */
+	Stg_Class_Print( self->shape, stream );
+	
+	Stream_UnIndent( stream );
+}
+
+
+void* _WithinShapeParticleLayout_Copy( const void* withinShapeParticleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	WithinShapeParticleLayout*		self                    = (WithinShapeParticleLayout*)withinShapeParticleLayout;
+	WithinShapeParticleLayout*		newWithinShapeParticleLayout;
+	
+	newWithinShapeParticleLayout = (WithinShapeParticleLayout*)_SpaceFillerParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	if ( deep ) {
+		newWithinShapeParticleLayout->shape = (Stg_Shape*)Stg_Class_Copy( self->shape, NULL, deep, nameExt, ptrMap );
+	}
+	else {
+		newWithinShapeParticleLayout->shape = self->shape;
+	}
+
+	return (void*)newWithinShapeParticleLayout;
+}
+
+void* _WithinShapeParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                _sizeOfSelf = sizeof(WithinShapeParticleLayout);
+	Type                                                                        type = WithinShapeParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                                _delete = _WithinShapeParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                                  _print = _WithinShapeParticleLayout_Print;
+	Stg_Class_CopyFunction*                                                    _copy = _WithinShapeParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*                    _defaultConstructor = _WithinShapeParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                                      _construct = _WithinShapeParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                              _build = _WithinShapeParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                                    _initialise = _WithinShapeParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                          _execute = _WithinShapeParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                          _destroy = _WithinShapeParticleLayout_Destroy;
+	ParticleLayout_SetInitialCountsFunction*                       _setInitialCounts = _GlobalParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*                 _initialiseParticles = _WithinShapeParticleLayout_InitialiseParticles;
+	GlobalParticleLayout_InitialiseParticleFunction*             _initialiseParticle = _SpaceFillerParticleLayout_InitialiseParticle;
+	AllocationType                                                nameAllocationType = NON_GLOBAL;
+	CoordSystem                                                          coordSystem = GlobalCoordSystem;
+	Bool                                                 weightsInitialisedAtStartup = False;
+	Particle_Index                                             totalInitialParticles = 0;
+	double                                            averageInitialParticlesPerCell = 0.0;
+	Dimension_Index                                                              dim = 0;
+	Stg_Shape*                                                                 shape = NULL;
+
+   return (void*)_WithinShapeParticleLayout_New(  WITHINSHAPEPARTICLELAYOUT_PASSARGS  );
+}
+
+void _WithinShapeParticleLayout_AssignFromXML( void* withinShapeParticleLayout, Stg_ComponentFactory *cf, void* data ) {
+	WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
+	Stg_Shape*      shape;
+	
+	_SpaceFillerParticleLayout_AssignFromXML( self, cf, data );
+
+	shape = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"shape", Stg_Shape, True, data  ) ;
+
+	_WithinShapeParticleLayout_Init( self, shape );
+}
+	
+void _WithinShapeParticleLayout_Build( void* withinShapeParticleLayout, void* data ) {
+   WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
+   _SpaceFillerParticleLayout_Build( self, data );
+}
+void _WithinShapeParticleLayout_Initialise( void* withinShapeParticleLayout, void* data ) {
+   WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
+   _SpaceFillerParticleLayout_Initialise( self, data );
+}
+void _WithinShapeParticleLayout_Execute( void* withinShapeParticleLayout, void* data ) {
+}
+void _WithinShapeParticleLayout_Destroy( void* withinShapeParticleLayout, void* data ) {
+   WithinShapeParticleLayout* self = (WithinShapeParticleLayout*) withinShapeParticleLayout;
+
+   Stg_Component_Destroy( self->shape, data, False );
+
+   _SpaceFillerParticleLayout_Destroy( self, data );
+}
+
+void _WithinShapeParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
+{
+	WithinShapeParticleLayout*	self          = (WithinShapeParticleLayout*)particleLayout;
+	Swarm*			        swarm         = (Swarm*)_swarm;
+	GlobalParticle*                 particle      = NULL;
+	Particle_Index		        lParticle_I   = 0;
+	Particle_Index		        newParticle_I = 0;
+	Cell_Index		        cell_I;
+	
+	/* Go through and init particles */
+	while( newParticle_I < self->totalInitialParticles ) {
+		
+		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+
+		GlobalParticleLayout_InitialiseParticle( self, swarm, newParticle_I, particle );
+
+		/* Test the particle is inside our desired shape */
+		if ( Stg_Shape_IsCoordInside( self->shape, particle->coord ) ) {
+			
+			newParticle_I++;
+			/* Work out which cell the new particle is in */
+			/* First specify the particle doesn't have an owning cell yet, so as
+			not to confuse the search algorithm */
+			particle->owningCell = swarm->cellDomainCount;
+			cell_I = CellLayout_CellOf( swarm->cellLayout, particle );
+
+			/* If we found a further particle inside our domain add it to a cell */
+			if ( cell_I < swarm->cellLocalCount ) {
+				/* Add it to that cell */
+				Swarm_AddParticleToCell( swarm, cell_I, lParticle_I );
+				lParticle_I++;
+				swarm->particleLocalCount++;
+				Swarm_Realloc( swarm );
+			}
+		}
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/Bouncer/Bouncer.c
--- a/Swarm/tests/Bouncer/Bouncer.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include <StgDomain/Swarm/Swarm.h>
-
-#include <assert.h>
-#include <string.h>
-
-const Type StGermain_Bouncer_Type = "StGermain_Bouncer";
-
-typedef struct {
-	__Codelet
-} StGermain_Bouncer;
-
-struct _Particle {
-	__GlobalParticle
-	double  velocity[3];
-	double  randomColour;
-};
-
-void StGermain_Bouncer_UpdatePositions( DomainContext* context ) {
-	Cell_LocalIndex			lCell_I;
-	Particle_InCellIndex		cParticle_I;
-	Particle* 	        	currParticle;
-	Index				dim_I;
-	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	BlockGeometry*                  blockGeom;
-	Stream*                         stream = Journal_Register( Debug_Type, (Name)"particleUpdate"  );
-	unsigned int                    movementSpeedDivisor = 5;
-	Particle_Index                  lParticle_I = 0;
-
-	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
-	
-	blockGeom = (BlockGeometry*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"geometry" );
-
-	if ( context->timeStep == 1  ) {
-		/* for each particle, set a random velocity */
-		for ( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-			currParticle = (Particle*)Swarm_ParticleAt( swarm, lParticle_I );
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				currParticle->velocity[dim_I] = ((double) ( rand() - (double)(RAND_MAX)/2 )) / RAND_MAX * 0.1;
-			}	
-		}
-	}
-	
-	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
-		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
-		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-			Coord movementVector = {0,0,0};
-			Coord newParticleCoord = {0,0,0};
-			Coord* oldCoord;
-
-			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			oldCoord = &currParticle->coord;
-			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				movementVector[dim_I] = currParticle->velocity[dim_I] / movementSpeedDivisor;
-				if ( ( currParticle->velocity[dim_I] < 0 ) 
-					&& ( fabs(currParticle->velocity[dim_I] ) > ((*oldCoord)[dim_I] - blockGeom->min[dim_I]) ) )
-				{
-					Journal_Printf( stream, "\t\tFlipping vel in %d dir\n", dim_I );
-					movementVector[dim_I] *= -1;
-					currParticle->velocity[dim_I] *= -1;
-				}	
-				if ( ( currParticle->velocity[dim_I] > 0 ) 
-					&& ( fabs(currParticle->velocity[dim_I] ) > ( blockGeom->max[dim_I] - (*oldCoord)[dim_I] ) ) )
-				{
-					Journal_Printf( stream, "\t\tFlipping vel in %d dir\n", dim_I );
-					movementVector[dim_I] *= -1;
-					currParticle->velocity[dim_I] *= -1;
-				}	
-				
-				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-			}
-
-			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
-				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
-				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				currParticle->coord[dim_I] = newParticleCoord[dim_I];
-			}
-		}
-	}
-
-	Swarm_UpdateAllParticleOwners( swarm );
-}
-
-
-void _StGermain_Bouncer_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	DomainContext*   context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-	
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_Bouncer_UpdatePositions );
-}
-
-
-void* _StGermain_Bouncer_DefaultNew( Name name ) {
-	return Codelet_New(
-			StGermain_Bouncer_Type,
-			_StGermain_Bouncer_DefaultNew,
-			_StGermain_Bouncer_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-	}
-
-Index StGermain_Bouncer_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, StGermain_Bouncer_Type, (Name)"0", _StGermain_Bouncer_DefaultNew  );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/Bouncer/Bouncer.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/Bouncer/Bouncer.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,121 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include <StgDomain/Swarm/Swarm.h>
+
+#include <assert.h>
+#include <string.h>
+
+const Type StGermain_Bouncer_Type = "StGermain_Bouncer";
+
+typedef struct {
+	__Codelet
+} StGermain_Bouncer;
+
+struct _Particle {
+	__GlobalParticle
+	double  velocity[3];
+	double  randomColour;
+};
+
+void StGermain_Bouncer_UpdatePositions( DomainContext* context ) {
+	Cell_LocalIndex			lCell_I;
+	Particle_InCellIndex		cParticle_I;
+	Particle* 	        	currParticle;
+	Index				dim_I;
+	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	BlockGeometry*                  blockGeom;
+	Stream*                         stream = Journal_Register( Debug_Type, (Name)"particleUpdate"  );
+	unsigned int                    movementSpeedDivisor = 5;
+	Particle_Index                  lParticle_I = 0;
+
+	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
+	
+	blockGeom = (BlockGeometry*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"geometry" );
+
+	if ( context->timeStep == 1  ) {
+		/* for each particle, set a random velocity */
+		for ( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+			currParticle = (Particle*)Swarm_ParticleAt( swarm, lParticle_I );
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				currParticle->velocity[dim_I] = ((double) ( rand() - (double)(RAND_MAX)/2 )) / RAND_MAX * 0.1;
+			}	
+		}
+	}
+	
+	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
+		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
+		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+			Coord movementVector = {0,0,0};
+			Coord newParticleCoord = {0,0,0};
+			Coord* oldCoord;
+
+			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			oldCoord = &currParticle->coord;
+			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				movementVector[dim_I] = currParticle->velocity[dim_I] / movementSpeedDivisor;
+				if ( ( currParticle->velocity[dim_I] < 0 ) 
+					&& ( fabs(currParticle->velocity[dim_I] ) > ((*oldCoord)[dim_I] - blockGeom->min[dim_I]) ) )
+				{
+					Journal_Printf( stream, "\t\tFlipping vel in %d dir\n", dim_I );
+					movementVector[dim_I] *= -1;
+					currParticle->velocity[dim_I] *= -1;
+				}	
+				if ( ( currParticle->velocity[dim_I] > 0 ) 
+					&& ( fabs(currParticle->velocity[dim_I] ) > ( blockGeom->max[dim_I] - (*oldCoord)[dim_I] ) ) )
+				{
+					Journal_Printf( stream, "\t\tFlipping vel in %d dir\n", dim_I );
+					movementVector[dim_I] *= -1;
+					currParticle->velocity[dim_I] *= -1;
+				}	
+				
+				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+			}
+
+			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
+				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
+				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				currParticle->coord[dim_I] = newParticleCoord[dim_I];
+			}
+		}
+	}
+
+	Swarm_UpdateAllParticleOwners( swarm );
+}
+
+
+void _StGermain_Bouncer_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	DomainContext*   context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+	
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_Bouncer_UpdatePositions );
+}
+
+
+void* _StGermain_Bouncer_DefaultNew( Name name ) {
+	return Codelet_New(
+			StGermain_Bouncer_Type,
+			_StGermain_Bouncer_DefaultNew,
+			_StGermain_Bouncer_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+	}
+
+Index StGermain_Bouncer_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, StGermain_Bouncer_Type, (Name)"0", _StGermain_Bouncer_DefaultNew  );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ElementCellLayoutSuite.c
--- a/Swarm/tests/ElementCellLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,163 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ElementCellLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <mpi.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "ElementCellLayoutSuite.h"
-
-typedef struct {
-	unsigned							nDims;
-	unsigned							meshSize[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	ExtensionManager_Register*	extensionMgr_Register;
-	Mesh*								mesh;
-	ElementCellLayout*			elementCellLayout;
-	MPI_Comm							comm;
-	int								rank;
-	int								nProcs;
-} ElementCellLayoutSuiteData;
-
-Mesh* ElementCellLayout_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	unsigned					maxDecomp[3] = {1, 0, 1};
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void ElementCellLayoutSuite_Setup( ElementCellLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */	
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-
-	data->nDims = 3;
-	data->meshSize[0] = 2;
-	data->meshSize[1] = 3;
-	data->meshSize[2] = 2;
-	data->minCrds[0] = 0.0;
-	data->minCrds[1] = 0.0;
-	data->minCrds[2] = 0.0;
-	data->maxCrds[0] = 300.0;
-	data->maxCrds[1] = 12.0;
-	data->maxCrds[2] = 300.0;
-
-	/* Init mesh */
-	data->extensionMgr_Register = ExtensionManager_Register_New();
-	data->mesh = ElementCellLayout_BuildMesh( data->nDims, data->meshSize, data->minCrds, data->maxCrds, data->extensionMgr_Register );
-	
-	/* Configure the element-cell-layout */
-	data->elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, data->mesh );
-   Stg_Component_Build( data->elementCellLayout, NULL, False );
-   Stg_Component_Initialise( data->elementCellLayout, NULL, False );
-}
-
-void ElementCellLayoutSuite_Teardown( ElementCellLayoutSuiteData* data ) {
-	/* Destroy stuff */
-	Stg_Class_Delete( data->extensionMgr_Register );
-	Stg_Component_Destroy( data->elementCellLayout, NULL, True );
-	/*Stg_Component_Destroy( data->mesh, NULL, True );*/
-
-	Journal_Enable_AllTypedStream( True );
-}
-
-void ElementCellLayoutSuite_TestElementCellLayout( ElementCellLayoutSuiteData* data ) {
-	int						procToWatch = data->nProcs > 1 ? 1 : 0;
-	Cell_Index				cell;
-	Element_DomainIndex	element;
-	GlobalParticle			testParticle;
-		
-	if( data->rank == procToWatch ) {
-          for( element = 0; element < Mesh_GetLocalSize( data->mesh, (MeshTopology_Dim)(data->nDims) ); element++ ) {
-			Cell_PointIndex	count;
-			double***			cellPoints;
-	
-			cell = CellLayout_MapElementIdToCellId( data->elementCellLayout, element );
-
-			pcu_check_true( cell == element );
-
-			count = data->elementCellLayout->_pointCount( data->elementCellLayout, cell );
-			cellPoints = Memory_Alloc_Array( double**, count, "cellPoints" );
-			/* for the element cell layout, the elements map to cells as 1:1, as such the "points" which define the cell as the
-			 * same as the "nodes" which define the element */
-			data->elementCellLayout->_initialisePoints( data->elementCellLayout, cell, count, cellPoints );
-
-			testParticle.coord[0] = ( (*cellPoints[0])[0] + (*cellPoints[1])[0] ) / 2;
-			testParticle.coord[1] = ( (*cellPoints[0])[1] + (*cellPoints[2])[1] ) / 2;
-			testParticle.coord[2] = ( (*cellPoints[0])[2] + (*cellPoints[4])[2] ) / 2;
-			pcu_check_true( CellLayout_IsInCell( data->elementCellLayout, cell, &testParticle ) );
-
-			testParticle.coord[0] = (*cellPoints[count-2])[0] + 1;
-			testParticle.coord[1] = (*cellPoints[count-2])[1] + 1;
-			testParticle.coord[2] = (*cellPoints[count-2])[2] + 1;
-			pcu_check_true( !CellLayout_IsInCell( data->elementCellLayout, cell, &testParticle ) );
-
-			Memory_Free( cellPoints );
-		}
-	}
-}
-
-void ElementCellLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, ElementCellLayoutSuiteData );
-	pcu_suite_setFixtures( suite, ElementCellLayoutSuite_Setup, ElementCellLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, ElementCellLayoutSuite_TestElementCellLayout );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ElementCellLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/ElementCellLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,163 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ElementCellLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "ElementCellLayoutSuite.h"
+
+typedef struct {
+	unsigned							nDims;
+	unsigned							meshSize[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	ExtensionManager_Register*	extensionMgr_Register;
+	Mesh*								mesh;
+	ElementCellLayout*			elementCellLayout;
+	MPI_Comm							comm;
+	int								rank;
+	int								nProcs;
+} ElementCellLayoutSuiteData;
+
+Mesh* ElementCellLayout_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	unsigned					maxDecomp[3] = {1, 0, 1};
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void ElementCellLayoutSuite_Setup( ElementCellLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */	
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+
+	data->nDims = 3;
+	data->meshSize[0] = 2;
+	data->meshSize[1] = 3;
+	data->meshSize[2] = 2;
+	data->minCrds[0] = 0.0;
+	data->minCrds[1] = 0.0;
+	data->minCrds[2] = 0.0;
+	data->maxCrds[0] = 300.0;
+	data->maxCrds[1] = 12.0;
+	data->maxCrds[2] = 300.0;
+
+	/* Init mesh */
+	data->extensionMgr_Register = ExtensionManager_Register_New();
+	data->mesh = ElementCellLayout_BuildMesh( data->nDims, data->meshSize, data->minCrds, data->maxCrds, data->extensionMgr_Register );
+	
+	/* Configure the element-cell-layout */
+	data->elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, data->mesh );
+   Stg_Component_Build( data->elementCellLayout, NULL, False );
+   Stg_Component_Initialise( data->elementCellLayout, NULL, False );
+}
+
+void ElementCellLayoutSuite_Teardown( ElementCellLayoutSuiteData* data ) {
+	/* Destroy stuff */
+	Stg_Class_Delete( data->extensionMgr_Register );
+	Stg_Component_Destroy( data->elementCellLayout, NULL, True );
+	/*Stg_Component_Destroy( data->mesh, NULL, True );*/
+
+	Journal_Enable_AllTypedStream( True );
+}
+
+void ElementCellLayoutSuite_TestElementCellLayout( ElementCellLayoutSuiteData* data ) {
+	int						procToWatch = data->nProcs > 1 ? 1 : 0;
+	Cell_Index				cell;
+	Element_DomainIndex	element;
+	GlobalParticle			testParticle;
+		
+	if( data->rank == procToWatch ) {
+          for( element = 0; element < Mesh_GetLocalSize( data->mesh, (MeshTopology_Dim)(data->nDims) ); element++ ) {
+			Cell_PointIndex	count;
+			double***			cellPoints;
+	
+			cell = CellLayout_MapElementIdToCellId( data->elementCellLayout, element );
+
+			pcu_check_true( cell == element );
+
+			count = data->elementCellLayout->_pointCount( data->elementCellLayout, cell );
+			cellPoints = Memory_Alloc_Array( double**, count, "cellPoints" );
+			/* for the element cell layout, the elements map to cells as 1:1, as such the "points" which define the cell as the
+			 * same as the "nodes" which define the element */
+			data->elementCellLayout->_initialisePoints( data->elementCellLayout, cell, count, cellPoints );
+
+			testParticle.coord[0] = ( (*cellPoints[0])[0] + (*cellPoints[1])[0] ) / 2;
+			testParticle.coord[1] = ( (*cellPoints[0])[1] + (*cellPoints[2])[1] ) / 2;
+			testParticle.coord[2] = ( (*cellPoints[0])[2] + (*cellPoints[4])[2] ) / 2;
+			pcu_check_true( CellLayout_IsInCell( data->elementCellLayout, cell, &testParticle ) );
+
+			testParticle.coord[0] = (*cellPoints[count-2])[0] + 1;
+			testParticle.coord[1] = (*cellPoints[count-2])[1] + 1;
+			testParticle.coord[2] = (*cellPoints[count-2])[2] + 1;
+			pcu_check_true( !CellLayout_IsInCell( data->elementCellLayout, cell, &testParticle ) );
+
+			Memory_Free( cellPoints );
+		}
+	}
+}
+
+void ElementCellLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, ElementCellLayoutSuiteData );
+	pcu_suite_setFixtures( suite, ElementCellLayoutSuite_Setup, ElementCellLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, ElementCellLayoutSuite_TestElementCellLayout );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/GaussLayoutSingleCellSuite.c
--- a/Swarm/tests/GaussLayoutSingleCellSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,269 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the GaussLayoutSingleCellSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "GaussLayoutSingleCellSuite.h"
-
-struct _Particle {
-	__IntegrationPoint
-};
-
-typedef struct {
-	MPI_Comm comm;
-	int rank;
-	int nProcs;
-} GaussLayoutSingleCellSuiteData;
-
-void GaussLayoutSingleCellSuite_Setup( GaussLayoutSingleCellSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void GaussLayoutSingleCellSuite_Teardown( GaussLayoutSingleCellSuiteData* data ) {
-}
-
-void GaussLayoutSingleCellSuite_Test1ParticlePerDim_3D( GaussLayoutSingleCellSuiteData* data ) {
-	unsigned							nDims;
-	unsigned							gaussParticles[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	ExtensionManager_Register*	extensionMgr_Register;
-	GaussParticleLayout*			gaussParticleLayout;
-	SingleCellLayout*				singleCellLayout;
-	Swarm*							swarm;
-	int								procToWatch = data->nProcs > 1 ? 1 : 0;
-	Cell_PointIndex				count;
-	double							x,y,z,w;
-	unsigned int					p;
-	Stream*							stream;
-	Particle_InCellIndex			particlesPerDim[3] = {1, 1, 1};
-	Bool								dimExists[] = { True, True, True };	
-	char								expected_file[PCU_PATH_MAX];
-	
-	if( data->rank == procToWatch ) {	
-		stream = Journal_Register( Info_Type, (Name)"1ParticlePerDim_3D"  );
-		Stream_RedirectFile( stream, "1ParticlePerDim_3D.dat" );
-
-		nDims = 3;
-		gaussParticles[0] = 2; gaussParticles[1] = 1; gaussParticles[2] = 3;
-		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
-		maxCrds[0] = 300.0; maxCrds[1] = 12.0; maxCrds[2] = 300.0;
-	
-		extensionMgr_Register = ExtensionManager_Register_New();
-
-		/* Configure the element-cell-layout */
-		singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, dimExists, NULL, NULL );
-	
-		/* Configure the gauss-particle-layout */
-		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL,
-           LocalCoordSystem, True, nDims, particlesPerDim );
-
-		swarm = Swarm_New( "testGaussSwarmSingleCell", NULL, singleCellLayout, gaussParticleLayout, nDims,
-			sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
-		
-		/* Build the swarm */
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-
-		count = swarm->cellParticleCountTbl[0];
-	 
-		for( p = 0; p < count; p++ ) {
-			x = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[0]; 
-			y = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[1]; 
-			z = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[2]; 	
-			w = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->weight;
-			Journal_Printf( stream, "pId=%d : xi = { %f, %f, %f } weight = %f\n",p,x,y,z,w );	
-		}	
-		pcu_filename_expected( "testGaussLayoutSingleCell1ParticlePerDimOutput.expected", expected_file );
-		pcu_check_fileEq( "1ParticlePerDim_3D.dat", expected_file );
-		remove( "1ParticlePerDim_3D.dat" );
-
-		Stg_Class_Delete( extensionMgr_Register );
-		Stg_Component_Destroy( singleCellLayout, NULL, True );
-		Stg_Component_Destroy( gaussParticleLayout, NULL, True );
-		Stg_Component_Destroy( swarm, NULL, True );
-	}
-}
-
-
-void GaussLayoutSingleCellSuite_Test2ParticlesPerDim_3D( GaussLayoutSingleCellSuiteData* data ) {
-	unsigned							nDims;
-	unsigned							gaussParticles[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	ExtensionManager_Register*	extensionMgr_Register;
-	GaussParticleLayout*			gaussParticleLayout;
-	SingleCellLayout*				singleCellLayout;
-	Swarm*							swarm;
-	int								procToWatch = data->nProcs > 1 ? 1 : 0;
-	Cell_PointIndex				count;
-	double							x,y,z,w;
-	unsigned int					p;
-	Stream*							stream;
-	Particle_InCellIndex			particlesPerDim[3] = {2, 2, 2};
-	Bool								dimExists[] = { True, True, True };	
-	char								expected_file[PCU_PATH_MAX];
-	
-	if( data->rank == procToWatch ) {	
-		stream = Journal_Register( Info_Type, (Name)"2ParticlesPerDim_3D"  );
-		Stream_RedirectFile( stream, "2ParticlesPerDim_3D.dat" );
-
-		nDims = 3;
-		gaussParticles[0] = 2; gaussParticles[1] = 1; gaussParticles[2] = 3;
-		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
-		maxCrds[0] = 300.0; maxCrds[1] = 12.0; maxCrds[2] = 300.0;
-	
-		extensionMgr_Register = ExtensionManager_Register_New();
-
-		/* Configure the element-cell-layout */
-		singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, dimExists, NULL, NULL );
-	
-		/* Configure the gauss-particle-layout */
-		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL,
-           LocalCoordSystem, True, nDims, particlesPerDim );
-		
-		/* Configure the swarm */
-		swarm = Swarm_New( "testGaussSwarmSingleCell", NULL, singleCellLayout, gaussParticleLayout, nDims,
-			sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
-		
-		/* Build the swarm */
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-
-		count = swarm->cellParticleCountTbl[0];
-		 
-		for( p = 0; p < count; p++ ) {
-			x = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[0]; 
-			y = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[1]; 
-			z = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[2]; 	
-			w = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->weight;
-			Journal_Printf( stream, "pId=%d : xi = { %f, %f, %f } weight = %f\n",p,x,y,z,w );	
-		}	
-		pcu_filename_expected( "testGaussLayoutSingleCell2ParticlesPerDimOutput.expected", expected_file );
-		pcu_check_fileEq( "2ParticlesPerDim_3D.dat", expected_file );
-		remove( "2ParticlesPerDim_3D.dat" );
-
-		Stg_Class_Delete( extensionMgr_Register );
-		Stg_Component_Destroy( singleCellLayout, NULL, True );
-		Stg_Component_Destroy( gaussParticleLayout, NULL, True );
-		Stg_Component_Destroy( swarm, NULL, True );
-	}
-}
-
-void GaussLayoutSingleCellSuite_Test3ParticlesPerDim_3D( GaussLayoutSingleCellSuiteData* data ) {
-	unsigned							nDims;
-	unsigned							gaussParticles[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	ExtensionManager_Register*	extensionMgr_Register;
-	GaussParticleLayout*			gaussParticleLayout;
-	SingleCellLayout*				singleCellLayout;
-	Swarm*							swarm;
-	int								procToWatch = data->nProcs > 1 ? 1 : 0;
-	Cell_PointIndex				count;
-	double							x,y,z,w;
-	unsigned int					p;
-	Stream*							stream;
-	Particle_InCellIndex			particlesPerDim[3] = {3, 3, 3};
-	Bool								dimExists[] = { True, True, True };	
-	char								expected_file[PCU_PATH_MAX];
-
-	if( data->rank == procToWatch ) {	
-		stream = Journal_Register( Info_Type, (Name)"3ParticlesPerDim_3D"  );
-		Stream_RedirectFile( stream, "3ParticlesPerDim_3D.dat" );
-
-		nDims = 3;
-		gaussParticles[0] = 2; gaussParticles[1] = 1; gaussParticles[2] = 3;
-		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
-		maxCrds[0] = 300.0; maxCrds[1] = 12.0; maxCrds[2] = 300.0;
-	
-		extensionMgr_Register = ExtensionManager_Register_New();
-
-		/* Configure the element-cell-layout */
-		singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, dimExists, NULL, NULL );
-	
-		/* Configure the gauss-particle-layout */
-		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL,
-           LocalCoordSystem, True, nDims, particlesPerDim );
-	
-		/* Configure the swarm */
-		swarm = Swarm_New( "testGaussSwarmSingleCell", NULL, singleCellLayout, gaussParticleLayout, nDims,
-			sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
-		
-		/* Build the swarm */
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-	
-		count = swarm->cellParticleCountTbl[0];
-	 
-		for( p = 0; p < count; p++ ) {
-			x = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[0]; 
-			y = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[1]; 
-			z = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[2]; 	
-			w = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->weight;
-			Journal_Printf( stream, "pId=%d : xi = { %f, %f, %f } weight = %f\n",p,x,y,z,w );	
-		}	
-		pcu_filename_expected( "testGaussLayoutSingleCell3ParticlesPerDimOutput.expected", expected_file );
-		pcu_check_fileEq( "3ParticlesPerDim_3D.dat", expected_file );
-		remove( "3ParticlesPerDim_3D.dat" );
-
-		Stg_Class_Delete( extensionMgr_Register );
-		Stg_Component_Destroy( singleCellLayout, NULL, True );
-		Stg_Component_Destroy( gaussParticleLayout, NULL, True );
-		Stg_Component_Destroy( swarm, NULL, True );
-	}
-}
-
-
-void GaussLayoutSingleCellSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, GaussLayoutSingleCellSuiteData );
-	pcu_suite_setFixtures( suite, GaussLayoutSingleCellSuite_Setup, GaussLayoutSingleCellSuite_Teardown );
-	pcu_suite_addTest( suite, GaussLayoutSingleCellSuite_Test1ParticlePerDim_3D );
-	pcu_suite_addTest( suite, GaussLayoutSingleCellSuite_Test2ParticlesPerDim_3D );
-	pcu_suite_addTest( suite, GaussLayoutSingleCellSuite_Test3ParticlesPerDim_3D );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/GaussLayoutSingleCellSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/GaussLayoutSingleCellSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,269 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the GaussLayoutSingleCellSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "GaussLayoutSingleCellSuite.h"
+
+struct _Particle {
+	__IntegrationPoint
+};
+
+typedef struct {
+	MPI_Comm comm;
+	int rank;
+	int nProcs;
+} GaussLayoutSingleCellSuiteData;
+
+void GaussLayoutSingleCellSuite_Setup( GaussLayoutSingleCellSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void GaussLayoutSingleCellSuite_Teardown( GaussLayoutSingleCellSuiteData* data ) {
+}
+
+void GaussLayoutSingleCellSuite_Test1ParticlePerDim_3D( GaussLayoutSingleCellSuiteData* data ) {
+	unsigned							nDims;
+	unsigned							gaussParticles[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	ExtensionManager_Register*	extensionMgr_Register;
+	GaussParticleLayout*			gaussParticleLayout;
+	SingleCellLayout*				singleCellLayout;
+	Swarm*							swarm;
+	int								procToWatch = data->nProcs > 1 ? 1 : 0;
+	Cell_PointIndex				count;
+	double							x,y,z,w;
+	unsigned int					p;
+	Stream*							stream;
+	Particle_InCellIndex			particlesPerDim[3] = {1, 1, 1};
+	Bool								dimExists[] = { True, True, True };	
+	char								expected_file[PCU_PATH_MAX];
+	
+	if( data->rank == procToWatch ) {	
+		stream = Journal_Register( Info_Type, (Name)"1ParticlePerDim_3D"  );
+		Stream_RedirectFile( stream, "1ParticlePerDim_3D.dat" );
+
+		nDims = 3;
+		gaussParticles[0] = 2; gaussParticles[1] = 1; gaussParticles[2] = 3;
+		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
+		maxCrds[0] = 300.0; maxCrds[1] = 12.0; maxCrds[2] = 300.0;
+	
+		extensionMgr_Register = ExtensionManager_Register_New();
+
+		/* Configure the element-cell-layout */
+		singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, dimExists, NULL, NULL );
+	
+		/* Configure the gauss-particle-layout */
+		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL,
+           LocalCoordSystem, True, nDims, particlesPerDim );
+
+		swarm = Swarm_New( "testGaussSwarmSingleCell", NULL, singleCellLayout, gaussParticleLayout, nDims,
+			sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
+		
+		/* Build the swarm */
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+
+		count = swarm->cellParticleCountTbl[0];
+	 
+		for( p = 0; p < count; p++ ) {
+			x = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[0]; 
+			y = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[1]; 
+			z = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[2]; 	
+			w = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->weight;
+			Journal_Printf( stream, "pId=%d : xi = { %f, %f, %f } weight = %f\n",p,x,y,z,w );	
+		}	
+		pcu_filename_expected( "testGaussLayoutSingleCell1ParticlePerDimOutput.expected", expected_file );
+		pcu_check_fileEq( "1ParticlePerDim_3D.dat", expected_file );
+		remove( "1ParticlePerDim_3D.dat" );
+
+		Stg_Class_Delete( extensionMgr_Register );
+		Stg_Component_Destroy( singleCellLayout, NULL, True );
+		Stg_Component_Destroy( gaussParticleLayout, NULL, True );
+		Stg_Component_Destroy( swarm, NULL, True );
+	}
+}
+
+
+void GaussLayoutSingleCellSuite_Test2ParticlesPerDim_3D( GaussLayoutSingleCellSuiteData* data ) {
+	unsigned							nDims;
+	unsigned							gaussParticles[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	ExtensionManager_Register*	extensionMgr_Register;
+	GaussParticleLayout*			gaussParticleLayout;
+	SingleCellLayout*				singleCellLayout;
+	Swarm*							swarm;
+	int								procToWatch = data->nProcs > 1 ? 1 : 0;
+	Cell_PointIndex				count;
+	double							x,y,z,w;
+	unsigned int					p;
+	Stream*							stream;
+	Particle_InCellIndex			particlesPerDim[3] = {2, 2, 2};
+	Bool								dimExists[] = { True, True, True };	
+	char								expected_file[PCU_PATH_MAX];
+	
+	if( data->rank == procToWatch ) {	
+		stream = Journal_Register( Info_Type, (Name)"2ParticlesPerDim_3D"  );
+		Stream_RedirectFile( stream, "2ParticlesPerDim_3D.dat" );
+
+		nDims = 3;
+		gaussParticles[0] = 2; gaussParticles[1] = 1; gaussParticles[2] = 3;
+		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
+		maxCrds[0] = 300.0; maxCrds[1] = 12.0; maxCrds[2] = 300.0;
+	
+		extensionMgr_Register = ExtensionManager_Register_New();
+
+		/* Configure the element-cell-layout */
+		singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, dimExists, NULL, NULL );
+	
+		/* Configure the gauss-particle-layout */
+		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL,
+           LocalCoordSystem, True, nDims, particlesPerDim );
+		
+		/* Configure the swarm */
+		swarm = Swarm_New( "testGaussSwarmSingleCell", NULL, singleCellLayout, gaussParticleLayout, nDims,
+			sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
+		
+		/* Build the swarm */
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+
+		count = swarm->cellParticleCountTbl[0];
+		 
+		for( p = 0; p < count; p++ ) {
+			x = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[0]; 
+			y = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[1]; 
+			z = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[2]; 	
+			w = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->weight;
+			Journal_Printf( stream, "pId=%d : xi = { %f, %f, %f } weight = %f\n",p,x,y,z,w );	
+		}	
+		pcu_filename_expected( "testGaussLayoutSingleCell2ParticlesPerDimOutput.expected", expected_file );
+		pcu_check_fileEq( "2ParticlesPerDim_3D.dat", expected_file );
+		remove( "2ParticlesPerDim_3D.dat" );
+
+		Stg_Class_Delete( extensionMgr_Register );
+		Stg_Component_Destroy( singleCellLayout, NULL, True );
+		Stg_Component_Destroy( gaussParticleLayout, NULL, True );
+		Stg_Component_Destroy( swarm, NULL, True );
+	}
+}
+
+void GaussLayoutSingleCellSuite_Test3ParticlesPerDim_3D( GaussLayoutSingleCellSuiteData* data ) {
+	unsigned							nDims;
+	unsigned							gaussParticles[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	ExtensionManager_Register*	extensionMgr_Register;
+	GaussParticleLayout*			gaussParticleLayout;
+	SingleCellLayout*				singleCellLayout;
+	Swarm*							swarm;
+	int								procToWatch = data->nProcs > 1 ? 1 : 0;
+	Cell_PointIndex				count;
+	double							x,y,z,w;
+	unsigned int					p;
+	Stream*							stream;
+	Particle_InCellIndex			particlesPerDim[3] = {3, 3, 3};
+	Bool								dimExists[] = { True, True, True };	
+	char								expected_file[PCU_PATH_MAX];
+
+	if( data->rank == procToWatch ) {	
+		stream = Journal_Register( Info_Type, (Name)"3ParticlesPerDim_3D"  );
+		Stream_RedirectFile( stream, "3ParticlesPerDim_3D.dat" );
+
+		nDims = 3;
+		gaussParticles[0] = 2; gaussParticles[1] = 1; gaussParticles[2] = 3;
+		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
+		maxCrds[0] = 300.0; maxCrds[1] = 12.0; maxCrds[2] = 300.0;
+	
+		extensionMgr_Register = ExtensionManager_Register_New();
+
+		/* Configure the element-cell-layout */
+		singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, dimExists, NULL, NULL );
+	
+		/* Configure the gauss-particle-layout */
+		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL,
+           LocalCoordSystem, True, nDims, particlesPerDim );
+	
+		/* Configure the swarm */
+		swarm = Swarm_New( "testGaussSwarmSingleCell", NULL, singleCellLayout, gaussParticleLayout, nDims,
+			sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
+		
+		/* Build the swarm */
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+	
+		count = swarm->cellParticleCountTbl[0];
+	 
+		for( p = 0; p < count; p++ ) {
+			x = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[0]; 
+			y = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[1]; 
+			z = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->xi[2]; 	
+			w = ((IntegrationPoint*)Swarm_ParticleInCellAt( swarm, 0, p ))->weight;
+			Journal_Printf( stream, "pId=%d : xi = { %f, %f, %f } weight = %f\n",p,x,y,z,w );	
+		}	
+		pcu_filename_expected( "testGaussLayoutSingleCell3ParticlesPerDimOutput.expected", expected_file );
+		pcu_check_fileEq( "3ParticlesPerDim_3D.dat", expected_file );
+		remove( "3ParticlesPerDim_3D.dat" );
+
+		Stg_Class_Delete( extensionMgr_Register );
+		Stg_Component_Destroy( singleCellLayout, NULL, True );
+		Stg_Component_Destroy( gaussParticleLayout, NULL, True );
+		Stg_Component_Destroy( swarm, NULL, True );
+	}
+}
+
+
+void GaussLayoutSingleCellSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, GaussLayoutSingleCellSuiteData );
+	pcu_suite_setFixtures( suite, GaussLayoutSingleCellSuite_Setup, GaussLayoutSingleCellSuite_Teardown );
+	pcu_suite_addTest( suite, GaussLayoutSingleCellSuite_Test1ParticlePerDim_3D );
+	pcu_suite_addTest( suite, GaussLayoutSingleCellSuite_Test2ParticlesPerDim_3D );
+	pcu_suite_addTest( suite, GaussLayoutSingleCellSuite_Test3ParticlesPerDim_3D );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/GaussLayoutSuite.c
--- a/Swarm/tests/GaussLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,204 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the GaussLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "GaussLayoutSuite.h"
-
-struct _Particle {
-	__IntegrationPoint
-};
-
-typedef struct {
-	unsigned nDims;
-	unsigned meshSize[3];
-	double minCrds[3];
-	double maxCrds[3];
-	MPI_Comm comm;
-	int		 rank;
-	int		 nProcs;
-} GaussLayoutSuiteData;
-
-Mesh* GaussLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	unsigned					maxDecomp[3] = {1, 0, 1};
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void GaussLayoutSuite_Setup( GaussLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-   
-	data->nDims = 3;
-	data->meshSize[0] = 2;	data->meshSize[1] = 3;	data->meshSize[2] = 2;
-	data->minCrds[0] = 0.0; data->minCrds[1] = 0.0; data->minCrds[2] = 0.0;
-	data->maxCrds[0] = 300.0; data->maxCrds[1] = 12.0; data->maxCrds[2] = 300.0;
-}
-
-void GaussLayoutSuite_Teardown( GaussLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void GaussLayoutSuite_TestDriver( GaussLayoutSuiteData* data, Name name,  const char* expected, const char* output, Particle_InCellIndex particlesPerDim[], int totalParticleCount ) {
-	int procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {	
-		ExtensionManager_Register*	extensionMgr_Register;
-		Mesh*								mesh;
-		GaussParticleLayout*			gaussParticleLayout;
-		ElementCellLayout*			elementCellLayout;
-		Swarm*							swarm;
-		Cell_PointIndex				count;
-		double							x,y,z;
-		unsigned int					p, i, len;
-		LocalParticle*					particle;
-		Coord								minCell;
-		Coord								maxCell;
-		Stream*							stream;
-		char								expected_file[PCU_PATH_MAX];
-
-		/* Init mesh */
-		extensionMgr_Register = ExtensionManager_Register_New();
-		mesh = GaussLayoutSuite_BuildMesh( data->nDims, data->meshSize, data->minCrds, data->maxCrds, extensionMgr_Register );
-	
-		/* Configure the element-cell-layout */
-		elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, mesh );
-		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL, LocalCoordSystem, True, data->nDims, particlesPerDim );
-
-		/* Configure the swarm */
-		swarm = Swarm_New( "testGaussSwarm", NULL, elementCellLayout, gaussParticleLayout, data->nDims, sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
-		
-		/* Build the swarm */
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-			
-		len = (int) sizeof( swarm->cellParticleCountTbl );
-		count = 0;
-
-		Journal_Enable_AllTypedStream( True );
-		stream = Journal_Register( Info_Type, (Name)name  );
-		Stream_RedirectFile( stream, output );
-
-		/* Checks that the particule count on each cell are the same. */
-		for( i = 0; i < len; i++ ) {
-			count = swarm->cellParticleCountTbl[i];
-			pcu_check_true( count == (unsigned)totalParticleCount  );
-		}	
-		Swarm_GetCellMinMaxCoords( swarm, 4, minCell, maxCell );
-		Journal_Printf( stream, "Particle per dim: %d %d %d\n", particlesPerDim[0], particlesPerDim[1], particlesPerDim[2]);	
-				
-		for( p = 0; p < count; p++ ) {
-			particle = (LocalParticle*)Swarm_ParticleInCellAt( swarm, 4, p );
-	
-			/* convert to global coords */
-			x = 0.5 * ( maxCell[0] - minCell[0] ) * ( particle->xi[0] + 1.0 ) + minCell[0];
-			y = 0.5 * ( maxCell[1] - minCell[1] ) * ( particle->xi[1] + 1.0 ) + minCell[1];
-			z = 0.5 * ( maxCell[2] - minCell[2] ) * ( particle->xi[2] + 1.0 ) + minCell[2];
-			
-			Journal_Printf( stream, "pId=%d : coords = { %.12f, %.12f, %.12f }, xi = { %.12f, %.12f, %.12f }\n", 
-				p, x, y, z, particle->xi[0], particle->xi[1], particle->xi[2] );	
-		}
-		pcu_filename_expected( expected, expected_file );
-		pcu_check_fileEq( output, expected_file );
-
-		/* Destroy stuff */
-		Stg_Class_Delete( extensionMgr_Register );
-		_Stg_Component_Delete( gaussParticleLayout );
-		_Stg_Component_Delete( elementCellLayout );
-		_Stg_Component_Delete( swarm );
-		remove( output );
-	}
-}
-
-void GaussLayoutSuite_Test1ParticlePerDim_3D( GaussLayoutSuiteData* data ) {
-	Particle_InCellIndex particlesPerDim[3] = {1, 1, 1};
-
-	GaussLayoutSuite_TestDriver( data, "GaussLayoutSuite1Particle",
-		 "testGaussLayout1ParticlePerDimOutput.expected",
-		 "testGaussLayoutSuite1Particle.dat", particlesPerDim, 1 );
-}
-
-void GaussLayoutSuite_Test2ParticlesPerDim_3D( GaussLayoutSuiteData* data ) {
-	Particle_InCellIndex particlesPerDim[3] = {2, 2, 2};
-
-	GaussLayoutSuite_TestDriver( data, "GaussLayoutSuite2Particles",
-		 "testGaussLayout2ParticlesPerDimOutput.expected",
-		 "testGaussLayoutSuite2Particles.dat", particlesPerDim, 8 );
-}
-
-void GaussLayoutSuite_Test3ParticlesPerDim_3D( GaussLayoutSuiteData* data ) {
-	Particle_InCellIndex particlesPerDim[3] = {3, 3, 3};
-
-	GaussLayoutSuite_TestDriver( data, "GaussLayoutSuite3Particles",
-		 "testGaussLayout3ParticlesPerDimOutput.expected",
-		 "testGaussLayoutSuite3Particles.dat", particlesPerDim, 27 );
-}
-
-void GaussLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, GaussLayoutSuiteData );
-	pcu_suite_setFixtures( suite, GaussLayoutSuite_Setup, GaussLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, GaussLayoutSuite_Test1ParticlePerDim_3D );
-	pcu_suite_addTest( suite, GaussLayoutSuite_Test2ParticlesPerDim_3D );
-	pcu_suite_addTest( suite, GaussLayoutSuite_Test3ParticlesPerDim_3D );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/GaussLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/GaussLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,204 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the GaussLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "GaussLayoutSuite.h"
+
+struct _Particle {
+	__IntegrationPoint
+};
+
+typedef struct {
+	unsigned nDims;
+	unsigned meshSize[3];
+	double minCrds[3];
+	double maxCrds[3];
+	MPI_Comm comm;
+	int		 rank;
+	int		 nProcs;
+} GaussLayoutSuiteData;
+
+Mesh* GaussLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	unsigned					maxDecomp[3] = {1, 0, 1};
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void GaussLayoutSuite_Setup( GaussLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+   
+	data->nDims = 3;
+	data->meshSize[0] = 2;	data->meshSize[1] = 3;	data->meshSize[2] = 2;
+	data->minCrds[0] = 0.0; data->minCrds[1] = 0.0; data->minCrds[2] = 0.0;
+	data->maxCrds[0] = 300.0; data->maxCrds[1] = 12.0; data->maxCrds[2] = 300.0;
+}
+
+void GaussLayoutSuite_Teardown( GaussLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void GaussLayoutSuite_TestDriver( GaussLayoutSuiteData* data, Name name,  const char* expected, const char* output, Particle_InCellIndex particlesPerDim[], int totalParticleCount ) {
+	int procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {	
+		ExtensionManager_Register*	extensionMgr_Register;
+		Mesh*								mesh;
+		GaussParticleLayout*			gaussParticleLayout;
+		ElementCellLayout*			elementCellLayout;
+		Swarm*							swarm;
+		Cell_PointIndex				count;
+		double							x,y,z;
+		unsigned int					p, i, len;
+		LocalParticle*					particle;
+		Coord								minCell;
+		Coord								maxCell;
+		Stream*							stream;
+		char								expected_file[PCU_PATH_MAX];
+
+		/* Init mesh */
+		extensionMgr_Register = ExtensionManager_Register_New();
+		mesh = GaussLayoutSuite_BuildMesh( data->nDims, data->meshSize, data->minCrds, data->maxCrds, extensionMgr_Register );
+	
+		/* Configure the element-cell-layout */
+		elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, mesh );
+		gaussParticleLayout = GaussParticleLayout_New( "gaussParticleLayout", NULL, LocalCoordSystem, True, data->nDims, particlesPerDim );
+
+		/* Configure the swarm */
+		swarm = Swarm_New( "testGaussSwarm", NULL, elementCellLayout, gaussParticleLayout, data->nDims, sizeof(Particle), extensionMgr_Register, NULL, data->comm, NULL );
+		
+		/* Build the swarm */
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+			
+		len = (int) sizeof( swarm->cellParticleCountTbl );
+		count = 0;
+
+		Journal_Enable_AllTypedStream( True );
+		stream = Journal_Register( Info_Type, (Name)name  );
+		Stream_RedirectFile( stream, output );
+
+		/* Checks that the particule count on each cell are the same. */
+		for( i = 0; i < len; i++ ) {
+			count = swarm->cellParticleCountTbl[i];
+			pcu_check_true( count == (unsigned)totalParticleCount  );
+		}	
+		Swarm_GetCellMinMaxCoords( swarm, 4, minCell, maxCell );
+		Journal_Printf( stream, "Particle per dim: %d %d %d\n", particlesPerDim[0], particlesPerDim[1], particlesPerDim[2]);	
+				
+		for( p = 0; p < count; p++ ) {
+			particle = (LocalParticle*)Swarm_ParticleInCellAt( swarm, 4, p );
+	
+			/* convert to global coords */
+			x = 0.5 * ( maxCell[0] - minCell[0] ) * ( particle->xi[0] + 1.0 ) + minCell[0];
+			y = 0.5 * ( maxCell[1] - minCell[1] ) * ( particle->xi[1] + 1.0 ) + minCell[1];
+			z = 0.5 * ( maxCell[2] - minCell[2] ) * ( particle->xi[2] + 1.0 ) + minCell[2];
+			
+			Journal_Printf( stream, "pId=%d : coords = { %.12f, %.12f, %.12f }, xi = { %.12f, %.12f, %.12f }\n", 
+				p, x, y, z, particle->xi[0], particle->xi[1], particle->xi[2] );	
+		}
+		pcu_filename_expected( expected, expected_file );
+		pcu_check_fileEq( output, expected_file );
+
+		/* Destroy stuff */
+		Stg_Class_Delete( extensionMgr_Register );
+		_Stg_Component_Delete( gaussParticleLayout );
+		_Stg_Component_Delete( elementCellLayout );
+		_Stg_Component_Delete( swarm );
+		remove( output );
+	}
+}
+
+void GaussLayoutSuite_Test1ParticlePerDim_3D( GaussLayoutSuiteData* data ) {
+	Particle_InCellIndex particlesPerDim[3] = {1, 1, 1};
+
+	GaussLayoutSuite_TestDriver( data, "GaussLayoutSuite1Particle",
+		 "testGaussLayout1ParticlePerDimOutput.expected",
+		 "testGaussLayoutSuite1Particle.dat", particlesPerDim, 1 );
+}
+
+void GaussLayoutSuite_Test2ParticlesPerDim_3D( GaussLayoutSuiteData* data ) {
+	Particle_InCellIndex particlesPerDim[3] = {2, 2, 2};
+
+	GaussLayoutSuite_TestDriver( data, "GaussLayoutSuite2Particles",
+		 "testGaussLayout2ParticlesPerDimOutput.expected",
+		 "testGaussLayoutSuite2Particles.dat", particlesPerDim, 8 );
+}
+
+void GaussLayoutSuite_Test3ParticlesPerDim_3D( GaussLayoutSuiteData* data ) {
+	Particle_InCellIndex particlesPerDim[3] = {3, 3, 3};
+
+	GaussLayoutSuite_TestDriver( data, "GaussLayoutSuite3Particles",
+		 "testGaussLayout3ParticlesPerDimOutput.expected",
+		 "testGaussLayoutSuite3Particles.dat", particlesPerDim, 27 );
+}
+
+void GaussLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, GaussLayoutSuiteData );
+	pcu_suite_setFixtures( suite, GaussLayoutSuite_Setup, GaussLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, GaussLayoutSuite_Test1ParticlePerDim_3D );
+	pcu_suite_addTest( suite, GaussLayoutSuite_Test2ParticlesPerDim_3D );
+	pcu_suite_addTest( suite, GaussLayoutSuite_Test3ParticlesPerDim_3D );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ManualParticleLayoutSuite.c
--- a/Swarm/tests/ManualParticleLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ManualParticleLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "ManualParticleLayoutSuite.h"
-
-struct _Particle {
-	__IntegrationPoint
-};
-
-typedef struct {
-	MPI_Comm comm;
-	int rank;
-	int nProcs;
-} ManualParticleLayoutSuiteData;
-
-Mesh* ManualParticleLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void ManualParticleLayoutSuite_Setup( ManualParticleLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void ManualParticleLayoutSuite_Teardown( ManualParticleLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void ManualParticleLayoutSuite_TestManualParticle( ManualParticleLayoutSuiteData* data ) {
-	unsigned							nDims = 3;
-	unsigned							meshSize[3] = {4, 2, 1};
-	double							minCrds[3] = {0.0, 0.0, 0.0};
-	double							maxCrds[3] = {1.0, 1.0, 1.0};
-	ExtensionManager_Register*	extensionMgr_Register;
-	Mesh*								mesh;
-	ElementCellLayout*			elementCellLayout;
-	Swarm*							swarm;
-	Dictionary*						dictionary;
-	Dictionary_Entry_Value*		particlePositionsList;
-	Dictionary_Entry_Value*		particlePositionEntry;
-	Dimension_Index				dim;
-	ManualParticleLayout*		particleLayout;
-	int								procToWatch = data->nProcs > 1 ? 1 : 0;
-	Stream*							stream;
-	char								expected_file[PCU_PATH_MAX];
-	
-	if( data->rank == procToWatch ) {
-		/* Dictionary Initialization */
-		dictionary = Dictionary_New();
-		particlePositionsList = Dictionary_Entry_Value_NewList();
-		Dictionary_Add( dictionary, (Dictionary_Entry_Key)"manualParticlePositions", particlePositionsList );
-	
-		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
-		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.4 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.3 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.2 ) );
-	
-		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
-		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.7 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.6 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.5 ) );
-	
-		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
-		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.8 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.1 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.3 ) );
-	
-		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
-		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.9 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.4 )  );
-		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.1 ) );
-	
-		/* Init mesh */
-		extensionMgr_Register = ExtensionManager_Register_New( );
-		mesh = ManualParticleLayoutSuite_BuildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-	
-		/* Configure the element-cell-layout */
-		elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, mesh );
-	
-		/* Build the mesh */
-		Stg_Component_Build( mesh, 0, False );
-		Stg_Component_Initialise( mesh, 0, False );
-	
-		/* Configure the gauss-particle-layout */
-		particleLayout = ManualParticleLayout_New( "manualParticleLayout", NULL, GlobalCoordSystem, False,
-         0, 0.0, dictionary );
-	
-		swarm = Swarm_New( "manualParticleSwarm", NULL, elementCellLayout, particleLayout, dim, sizeof(Particle),
-			extensionMgr_Register, NULL, data->comm, NULL );
-	
-		/* Build the swarm */
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-
-		Journal_Enable_AllTypedStream( True );
-		stream = Journal_Register( Info_Type, (Name)"ManualParticle"  );
-
-		/* Print out the particles on all cells */
-		Stream_RedirectFile( stream, "testManualParticle.dat" );
-		Swarm_PrintParticleCoords_ByCell( swarm, stream );
-		Journal_Enable_AllTypedStream( False );
-
-		pcu_filename_expected( "testManualParticleLayoutOutput.expected", expected_file );
-		pcu_check_fileEq( "testManualParticle.dat", expected_file );
-
-		Stg_Class_Delete( extensionMgr_Register );
-		_Stg_Component_Delete( particleLayout );
-		_Stg_Component_Delete( elementCellLayout );
-		_Stg_Component_Delete( swarm );
-		Stg_Class_Delete( dictionary );	
-		remove( "testManualParticle.dat" );
-	}
-}
-
-void ManualParticleLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, ManualParticleLayoutSuiteData );
-	pcu_suite_setFixtures( suite, ManualParticleLayoutSuite_Setup, ManualParticleLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, ManualParticleLayoutSuite_TestManualParticle );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ManualParticleLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/ManualParticleLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,187 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ManualParticleLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "ManualParticleLayoutSuite.h"
+
+struct _Particle {
+	__IntegrationPoint
+};
+
+typedef struct {
+	MPI_Comm comm;
+	int rank;
+	int nProcs;
+} ManualParticleLayoutSuiteData;
+
+Mesh* ManualParticleLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void ManualParticleLayoutSuite_Setup( ManualParticleLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void ManualParticleLayoutSuite_Teardown( ManualParticleLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void ManualParticleLayoutSuite_TestManualParticle( ManualParticleLayoutSuiteData* data ) {
+	unsigned							nDims = 3;
+	unsigned							meshSize[3] = {4, 2, 1};
+	double							minCrds[3] = {0.0, 0.0, 0.0};
+	double							maxCrds[3] = {1.0, 1.0, 1.0};
+	ExtensionManager_Register*	extensionMgr_Register;
+	Mesh*								mesh;
+	ElementCellLayout*			elementCellLayout;
+	Swarm*							swarm;
+	Dictionary*						dictionary;
+	Dictionary_Entry_Value*		particlePositionsList;
+	Dictionary_Entry_Value*		particlePositionEntry;
+	Dimension_Index				dim;
+	ManualParticleLayout*		particleLayout;
+	int								procToWatch = data->nProcs > 1 ? 1 : 0;
+	Stream*							stream;
+	char								expected_file[PCU_PATH_MAX];
+	
+	if( data->rank == procToWatch ) {
+		/* Dictionary Initialization */
+		dictionary = Dictionary_New();
+		particlePositionsList = Dictionary_Entry_Value_NewList();
+		Dictionary_Add( dictionary, (Dictionary_Entry_Key)"manualParticlePositions", particlePositionsList );
+	
+		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
+		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.4 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.3 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.2 ) );
+	
+		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
+		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.7 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.6 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.5 ) );
+	
+		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
+		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.8 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.1 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.3 ) );
+	
+		particlePositionEntry = Dictionary_Entry_Value_NewStruct( );
+		Dictionary_Entry_Value_AddElement( particlePositionsList, particlePositionEntry );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"x", Dictionary_Entry_Value_FromDouble( 0.9 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"y", Dictionary_Entry_Value_FromDouble( 0.4 )  );
+		Dictionary_Entry_Value_AddMember( particlePositionEntry, (Dictionary_Entry_Key)"z", Dictionary_Entry_Value_FromDouble( 0.1 ) );
+	
+		/* Init mesh */
+		extensionMgr_Register = ExtensionManager_Register_New( );
+		mesh = ManualParticleLayoutSuite_BuildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+	
+		/* Configure the element-cell-layout */
+		elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, mesh );
+	
+		/* Build the mesh */
+		Stg_Component_Build( mesh, 0, False );
+		Stg_Component_Initialise( mesh, 0, False );
+	
+		/* Configure the gauss-particle-layout */
+		particleLayout = ManualParticleLayout_New( "manualParticleLayout", NULL, GlobalCoordSystem, False,
+         0, 0.0, dictionary );
+	
+		swarm = Swarm_New( "manualParticleSwarm", NULL, elementCellLayout, particleLayout, dim, sizeof(Particle),
+			extensionMgr_Register, NULL, data->comm, NULL );
+	
+		/* Build the swarm */
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+
+		Journal_Enable_AllTypedStream( True );
+		stream = Journal_Register( Info_Type, (Name)"ManualParticle"  );
+
+		/* Print out the particles on all cells */
+		Stream_RedirectFile( stream, "testManualParticle.dat" );
+		Swarm_PrintParticleCoords_ByCell( swarm, stream );
+		Journal_Enable_AllTypedStream( False );
+
+		pcu_filename_expected( "testManualParticleLayoutOutput.expected", expected_file );
+		pcu_check_fileEq( "testManualParticle.dat", expected_file );
+
+		Stg_Class_Delete( extensionMgr_Register );
+		_Stg_Component_Delete( particleLayout );
+		_Stg_Component_Delete( elementCellLayout );
+		_Stg_Component_Delete( swarm );
+		Stg_Class_Delete( dictionary );	
+		remove( "testManualParticle.dat" );
+	}
+}
+
+void ManualParticleLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, ManualParticleLayoutSuiteData );
+	pcu_suite_setFixtures( suite, ManualParticleLayoutSuite_Setup, ManualParticleLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, ManualParticleLayoutSuite_TestManualParticle );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ParticleCoordsSuite.c
--- a/Swarm/tests/ParticleCoordsSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ParticleCoordsSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "ParticleCoordsSuite.h"
-
-struct _Particle {
-	__IntegrationPoint
-};
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} ParticleCoordsSuiteData;
-
-void ParticleCoordsSuite_Setup( ParticleCoordsSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void ParticleCoordsSuite_Teardown( ParticleCoordsSuiteData* data ) {
-}
-
-void ParticleCoordsSuite_TestLineParticle( ParticleCoordsSuiteData* data ) {
-	ExtensionManager_Register*	extensionMgr_Register;
-	Variable_Register*			variable_Register;
-	Swarm*							swarm;
-	Stream*							stream;
-	Dictionary*						dictionary;
-	DomainContext*					context;
-	int								procToWatch = data->nProcs > 1 ? 1 : 0;
-	char								input_file[PCU_PATH_MAX];
-	char								expected_file[PCU_PATH_MAX];
-	Stg_ComponentFactory*		cf;
-
-	if( data->rank == procToWatch ) {
-		Journal_Enable_AllTypedStream( False );
-		/* Registers */
-		extensionMgr_Register = ExtensionManager_Register_New();   
-		variable_Register = Variable_Register_New();
-
-		/* read in the xml input file */
-		pcu_filename_input( "testLineParticleLayout.xml", input_file );
-		cf = stgMainInitFromXML( input_file, data->comm, NULL );
-		stgMainBuildAndInitialise( cf );
-		context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-		dictionary = context->dictionary;
-
-		swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );
-		pcu_check_true( swarm );
-
-		Journal_Enable_AllTypedStream( True  );
-		stream = Journal_Register( Info_Type, (Name)"LinearParticleStream"  );
-		Stream_RedirectFile( stream, "linearParticle.dat" );
-		Swarm_PrintParticleCoords( swarm, stream );
-		Journal_Enable_AllTypedStream( False );
-
-		pcu_filename_expected( "testLineParticleLayoutOutput.expected", expected_file );
-		pcu_check_fileEq( "linearParticle.dat", expected_file );
-
-		/* Destroy stuff */
-		Stg_Class_Delete( extensionMgr_Register );
-		Stg_Class_Delete( variable_Register );
-
-		remove( "linearParticle.dat" );
-	}
-
-	stgMainDestroy( cf );
-}
-
-void ParticleCoordsSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, ParticleCoordsSuiteData );
-	pcu_suite_setFixtures( suite, ParticleCoordsSuite_Setup, ParticleCoordsSuite_Teardown );
-	pcu_suite_addTest( suite, ParticleCoordsSuite_TestLineParticle );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ParticleCoordsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/ParticleCoordsSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,120 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ParticleCoordsSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "ParticleCoordsSuite.h"
+
+struct _Particle {
+	__IntegrationPoint
+};
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} ParticleCoordsSuiteData;
+
+void ParticleCoordsSuite_Setup( ParticleCoordsSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void ParticleCoordsSuite_Teardown( ParticleCoordsSuiteData* data ) {
+}
+
+void ParticleCoordsSuite_TestLineParticle( ParticleCoordsSuiteData* data ) {
+	ExtensionManager_Register*	extensionMgr_Register;
+	Variable_Register*			variable_Register;
+	Swarm*							swarm;
+	Stream*							stream;
+	Dictionary*						dictionary;
+	DomainContext*					context;
+	int								procToWatch = data->nProcs > 1 ? 1 : 0;
+	char								input_file[PCU_PATH_MAX];
+	char								expected_file[PCU_PATH_MAX];
+	Stg_ComponentFactory*		cf;
+
+	if( data->rank == procToWatch ) {
+		Journal_Enable_AllTypedStream( False );
+		/* Registers */
+		extensionMgr_Register = ExtensionManager_Register_New();   
+		variable_Register = Variable_Register_New();
+
+		/* read in the xml input file */
+		pcu_filename_input( "testLineParticleLayout.xml", input_file );
+		cf = stgMainInitFromXML( input_file, data->comm, NULL );
+		stgMainBuildAndInitialise( cf );
+		context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+		dictionary = context->dictionary;
+
+		swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );
+		pcu_check_true( swarm );
+
+		Journal_Enable_AllTypedStream( True  );
+		stream = Journal_Register( Info_Type, (Name)"LinearParticleStream"  );
+		Stream_RedirectFile( stream, "linearParticle.dat" );
+		Swarm_PrintParticleCoords( swarm, stream );
+		Journal_Enable_AllTypedStream( False );
+
+		pcu_filename_expected( "testLineParticleLayoutOutput.expected", expected_file );
+		pcu_check_fileEq( "linearParticle.dat", expected_file );
+
+		/* Destroy stuff */
+		Stg_Class_Delete( extensionMgr_Register );
+		Stg_Class_Delete( variable_Register );
+
+		remove( "linearParticle.dat" );
+	}
+
+	stgMainDestroy( cf );
+}
+
+void ParticleCoordsSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, ParticleCoordsSuiteData );
+	pcu_suite_setFixtures( suite, ParticleCoordsSuite_Setup, ParticleCoordsSuite_Teardown );
+	pcu_suite_addTest( suite, ParticleCoordsSuite_TestLineParticle );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ShadowSyncSuite.c
--- a/Swarm/tests/ShadowSyncSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,294 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the ShadowSyncSuite
-**
-** $Id: testSwarm.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "ShadowSyncSuite.h"
-
-/* silly stgermain, I must define this */
-#define CURR_MODULE_NAME "DomainContext.c"
-
-struct _Particle {
-	__GlobalParticle
-	double  velocity[3];
-	double  randomColour;
-};
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} ShadowSyncSuiteData;
-
-void ShadowSyncSuite_ValidateShadowing( DomainContext* context );
-
-double ShadowSyncSuite_Dt( void* context ) {
-   return 2.0;
-}
-
-void ShadowSyncSuite_Setup( ShadowSyncSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void ShadowSyncSuite_Teardown( ShadowSyncSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void ShadowSyncSuite_TestShadowSync( ShadowSyncSuiteData* data ) {
-	DomainContext*					context = NULL;
-	Dictionary*						dictionary;
-	Dictionary*						componentDict;
-	Stg_ComponentFactory*		cf;
-	Swarm*							swarm = NULL;
-	Particle							particle;
-	Particle*						currParticle = NULL;
-	Particle_Index					lParticle_I = 0;
-	Dimension_Index				dim_I = 0;
-	char								input_file[PCU_PATH_MAX];
-	unsigned							procToWatch;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	pcu_filename_input( "testSwarmParticleShadowSync.xml", input_file );
-
-	cf = stgMainInitFromXML( input_file, data->comm, NULL );
-	context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( cf->infoStream, False );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->debug, False );
-	Stream_Enable( context->verbose, False );
-
-	dictionary = context->dictionary;
-	Journal_ReadFromDictionary( dictionary );
-	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"procToWatch", Dictionary_Entry_Value_FromUnsignedInt( procToWatch )  );
-	componentDict = Dictionary_GetDictionary( dictionary, "components" );
-	assert( componentDict );
-
-	KeyCall( context, context->constructExtensionsK, EntryPoint_VoidPtr_CallCast* )( KeyHandle(context,context->constructExtensionsK), context );
-
-	swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleVelocity", sizeof(double[3])  );
-	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleColour", sizeof(double)  );
-
-	Swarm_NewVectorVariable(
-		swarm,
-		"Velocity",
-		(ArithPointer) &particle.velocity - (ArithPointer) &particle,
-		Variable_DataType_Double,
-		swarm->dim,
-		"VelocityX",
-		"VelocityY",
-		"VelocityZ" );
-
-	Swarm_NewScalarVariable(
-		swarm,
-		"RandomColour",
-		(ArithPointer) &particle.randomColour - (ArithPointer) &particle,
-		Variable_DataType_Double );
-
-	stgMainBuildAndInitialise( cf );
-
-	/* for each particle, set a random colour */
-	for ( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-		currParticle = (Particle*)Swarm_ParticleAt( swarm, lParticle_I );
-		for ( dim_I=0; dim_I < 3; dim_I++ ) {
-			currParticle->velocity[dim_I] = 0;
-		}	
-		currParticle->randomColour = ( (double)  rand() ) / RAND_MAX;
-	}
-	
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Dt, ShadowSyncSuite_Dt );
-	ContextEP_Append( context, AbstractContext_EP_Sync, ShadowSyncSuite_ValidateShadowing );
-
-	Stg_Component_Execute( context, 0, False );
-	Stg_Component_Destroy( context, 0, False );
-
-	stgMainDestroy( cf );
-}
-
-void ShadowSyncSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, ShadowSyncSuiteData );
-	pcu_suite_setFixtures( suite, ShadowSyncSuite_Setup, ShadowSyncSuite_Teardown );
-	pcu_suite_addTest( suite, ShadowSyncSuite_TestShadowSync );
-}
-
-int ShadowSyncSuite_listCompareFunction( void *a, void *b ){
-   if( a>b )
-      return 1;
-   else if( a<b )
-      return -1;
-   else
-      return 0;
-}
-
-void ShadowSyncSuite_listDeleteFunction( void *a ){
-}
-
-void ShadowSyncSuite_ValidateShadowing( DomainContext* context ) {
-	DomainContext	*self = context;
-	Swarm*			swarm = (Swarm*) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"swarm" );
-
-	Swarm_UpdateAllParticleOwners( swarm );
-
-	if(swarm->nProc > 1 ) {
-		unsigned ii = 0, jj = 0;
-		ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( swarm->cellLayout );
-		ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
-		
-		{
-			MemoryPool *requestPool = MemoryPool_New( MPI_Request, 100, 10 );
-			MemoryPool *particlePool = MemoryPool_NewFunc( swarm->particleExtensionMgr->finalSize, 100, 10 );
-			LinkedList *list = LinkedList_New( ShadowSyncSuite_listCompareFunction, NULL, NULL, ShadowSyncSuite_listDeleteFunction, LINKEDLIST_UNSORTED );
-			LinkedList *particleList = LinkedList_New( ShadowSyncSuite_listCompareFunction, NULL, NULL, ShadowSyncSuite_listDeleteFunction, LINKEDLIST_UNSORTED );
-			LinkedListIterator *iter = LinkedListIterator_New( list );
-			void *data = NULL;
-
-			{
-				Neighbour_Index		        nbr_I;
-				unsigned i = 0, j = 0;
-				int shadowCell = 0;
-
-				for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-					for( i=0; i<cellShadowInfo->procShadowCnt[nbr_I]; i++ ){
-						MPI_Request *req;
-						char *particle = NULL;
-						int proc = 0;
-					
-						proc = procNbrInfo->procNbrTbl[nbr_I];
-
-						shadowCell = cellShadowInfo->procShadowTbl[nbr_I][i];
-						for( j=0; j<swarm->shadowCellParticleCountTbl[shadowCell]; j++ ){
-							
-							req = MemoryPool_NewObject( MPI_Request, requestPool );
-							particle = (char*)MemoryPool_NewObjectFunc( swarm->particleExtensionMgr->finalSize, particlePool );
-							LinkedList_InsertNode( list, req, sizeof(void*) );
-							LinkedList_InsertNode( particleList, particle, sizeof(void*) );
-						
-							MPI_Irecv( particle, swarm->particleExtensionMgr->finalSize, MPI_BYTE, proc, 2001, MPI_COMM_WORLD, req );
-						}
-					}
-				}
-			
-			}
-
-			{
-				Neighbour_Index		        nbr_I;
-				unsigned i = 0, j = 0;
-				int shadowedCell = 0;
-				char *array = (char*)malloc( swarm->particleExtensionMgr->finalSize );
-
-				for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
-					for( i=0; i<cellShadowInfo->procShadowedCnt[nbr_I]; i++ ){
-						MPI_Request *req;
-						int proc = 0;
-
-						proc = procNbrInfo->procNbrTbl[nbr_I];
-
-						shadowedCell = cellShadowInfo->procShadowedTbl[nbr_I][i];
-						for( j=0; j<swarm->cellParticleCountTbl[shadowedCell]; j++ ){
-							int pIndex = 0;
-
-							pIndex = swarm->cellParticleTbl[shadowedCell][j];
-							Swarm_CopyParticleOffSwarm( swarm,
-								array, 0,
-								pIndex );
-
-							req = MemoryPool_NewObject( MPI_Request, requestPool );
-							LinkedList_InsertNode( list, req, sizeof(void*) );
-							MPI_Isend( array, swarm->particleExtensionMgr->finalSize, MPI_BYTE, proc, 2001, MPI_COMM_WORLD, req );
-						}
-					}
-				}
-				free( array );
-			}
-
-			for( data=LinkedListIterator_First(iter); data!=NULL; data=LinkedListIterator_Next(iter) ){
-				MPI_Status s;
-				MPI_Wait( ((MPI_Request*)data), &s );
-			}
-
-			{
-				LinkedListIterator *pIter = LinkedListIterator_New( particleList );
-				for( data=LinkedListIterator_First(pIter); data!=NULL; data=LinkedListIterator_Next(pIter) ){
-					Particle *p = (Particle*)data;
-					int found = 0;
-					double epsilon=1e-5;
-
-					for( ii=0; ii<procNbrInfo->procNbrCnt; ii++ ){
-						for( jj=0; jj<cellShadowInfo->procShadowCnt[ii]; jj++ ){
-							int shadowCell = 0;
-							unsigned kk = 0;
-
-							shadowCell = cellShadowInfo->procShadowTbl[ii][jj];
-							for( kk=0; kk<swarm->shadowCellParticleCountTbl[shadowCell]; kk++ ){
-								int shadowParticleIdx = 0;
-								GlobalParticle *gp = NULL;
-
-								shadowParticleIdx = swarm->shadowCellParticleTbl[shadowCell][kk];
-								gp = ((GlobalParticle*)Swarm_ShadowParticleAt( swarm, shadowParticleIdx));
-								if( (fabs(p->coord[0]-gp->coord[0])<epsilon) && (fabs(p->coord[1]-gp->coord[1])<epsilon) && (fabs(p->coord[2]-gp->coord[2])<epsilon) ){
-									found = 1;
-								}
-							}
-						}
-					}
-					pcu_check_true( found == 1 );
-					pcu_check_true( Journal_Firewall( found, swarm->debug, "Shadow particle validation failed" ) );
-				}
-			}
-			Stg_Class_Delete( list );
-			Stg_Class_Delete( iter );
-			Stg_Class_Delete( requestPool );
-			Stg_Class_Delete( particlePool );
-			Stg_Class_Delete( particleList );
-		}
-	}
-}
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/ShadowSyncSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/ShadowSyncSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,294 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the ShadowSyncSuite
+**
+** $Id: testSwarm.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "ShadowSyncSuite.h"
+
+/* silly stgermain, I must define this */
+#define CURR_MODULE_NAME "DomainContext.c"
+
+struct _Particle {
+	__GlobalParticle
+	double  velocity[3];
+	double  randomColour;
+};
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} ShadowSyncSuiteData;
+
+void ShadowSyncSuite_ValidateShadowing( DomainContext* context );
+
+double ShadowSyncSuite_Dt( void* context ) {
+   return 2.0;
+}
+
+void ShadowSyncSuite_Setup( ShadowSyncSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void ShadowSyncSuite_Teardown( ShadowSyncSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void ShadowSyncSuite_TestShadowSync( ShadowSyncSuiteData* data ) {
+	DomainContext*					context = NULL;
+	Dictionary*						dictionary;
+	Dictionary*						componentDict;
+	Stg_ComponentFactory*		cf;
+	Swarm*							swarm = NULL;
+	Particle							particle;
+	Particle*						currParticle = NULL;
+	Particle_Index					lParticle_I = 0;
+	Dimension_Index				dim_I = 0;
+	char								input_file[PCU_PATH_MAX];
+	unsigned							procToWatch;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	pcu_filename_input( "testSwarmParticleShadowSync.xml", input_file );
+
+	cf = stgMainInitFromXML( input_file, data->comm, NULL );
+	context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( cf->infoStream, False );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->debug, False );
+	Stream_Enable( context->verbose, False );
+
+	dictionary = context->dictionary;
+	Journal_ReadFromDictionary( dictionary );
+	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"procToWatch", Dictionary_Entry_Value_FromUnsignedInt( procToWatch )  );
+	componentDict = Dictionary_GetDictionary( dictionary, "components" );
+	assert( componentDict );
+
+	KeyCall( context, context->constructExtensionsK, EntryPoint_VoidPtr_CallCast* )( KeyHandle(context,context->constructExtensionsK), context );
+
+	swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleVelocity", sizeof(double[3])  );
+	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleColour", sizeof(double)  );
+
+	Swarm_NewVectorVariable(
+		swarm,
+		"Velocity",
+		(ArithPointer) &particle.velocity - (ArithPointer) &particle,
+		Variable_DataType_Double,
+		swarm->dim,
+		"VelocityX",
+		"VelocityY",
+		"VelocityZ" );
+
+	Swarm_NewScalarVariable(
+		swarm,
+		"RandomColour",
+		(ArithPointer) &particle.randomColour - (ArithPointer) &particle,
+		Variable_DataType_Double );
+
+	stgMainBuildAndInitialise( cf );
+
+	/* for each particle, set a random colour */
+	for ( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+		currParticle = (Particle*)Swarm_ParticleAt( swarm, lParticle_I );
+		for ( dim_I=0; dim_I < 3; dim_I++ ) {
+			currParticle->velocity[dim_I] = 0;
+		}	
+		currParticle->randomColour = ( (double)  rand() ) / RAND_MAX;
+	}
+	
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Dt, ShadowSyncSuite_Dt );
+	ContextEP_Append( context, AbstractContext_EP_Sync, ShadowSyncSuite_ValidateShadowing );
+
+	Stg_Component_Execute( context, 0, False );
+	Stg_Component_Destroy( context, 0, False );
+
+	stgMainDestroy( cf );
+}
+
+void ShadowSyncSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, ShadowSyncSuiteData );
+	pcu_suite_setFixtures( suite, ShadowSyncSuite_Setup, ShadowSyncSuite_Teardown );
+	pcu_suite_addTest( suite, ShadowSyncSuite_TestShadowSync );
+}
+
+int ShadowSyncSuite_listCompareFunction( void *a, void *b ){
+   if( a>b )
+      return 1;
+   else if( a<b )
+      return -1;
+   else
+      return 0;
+}
+
+void ShadowSyncSuite_listDeleteFunction( void *a ){
+}
+
+void ShadowSyncSuite_ValidateShadowing( DomainContext* context ) {
+	DomainContext	*self = context;
+	Swarm*			swarm = (Swarm*) LiveComponentRegister_Get( self->CF->LCRegister, (Name)"swarm" );
+
+	Swarm_UpdateAllParticleOwners( swarm );
+
+	if(swarm->nProc > 1 ) {
+		unsigned ii = 0, jj = 0;
+		ShadowInfo*			cellShadowInfo = CellLayout_GetShadowInfo( swarm->cellLayout );
+		ProcNbrInfo*		procNbrInfo = cellShadowInfo->procNbrInfo;
+		
+		{
+			MemoryPool *requestPool = MemoryPool_New( MPI_Request, 100, 10 );
+			MemoryPool *particlePool = MemoryPool_NewFunc( swarm->particleExtensionMgr->finalSize, 100, 10 );
+			LinkedList *list = LinkedList_New( ShadowSyncSuite_listCompareFunction, NULL, NULL, ShadowSyncSuite_listDeleteFunction, LINKEDLIST_UNSORTED );
+			LinkedList *particleList = LinkedList_New( ShadowSyncSuite_listCompareFunction, NULL, NULL, ShadowSyncSuite_listDeleteFunction, LINKEDLIST_UNSORTED );
+			LinkedListIterator *iter = LinkedListIterator_New( list );
+			void *data = NULL;
+
+			{
+				Neighbour_Index		        nbr_I;
+				unsigned i = 0, j = 0;
+				int shadowCell = 0;
+
+				for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+					for( i=0; i<cellShadowInfo->procShadowCnt[nbr_I]; i++ ){
+						MPI_Request *req;
+						char *particle = NULL;
+						int proc = 0;
+					
+						proc = procNbrInfo->procNbrTbl[nbr_I];
+
+						shadowCell = cellShadowInfo->procShadowTbl[nbr_I][i];
+						for( j=0; j<swarm->shadowCellParticleCountTbl[shadowCell]; j++ ){
+							
+							req = MemoryPool_NewObject( MPI_Request, requestPool );
+							particle = (char*)MemoryPool_NewObjectFunc( swarm->particleExtensionMgr->finalSize, particlePool );
+							LinkedList_InsertNode( list, req, sizeof(void*) );
+							LinkedList_InsertNode( particleList, particle, sizeof(void*) );
+						
+							MPI_Irecv( particle, swarm->particleExtensionMgr->finalSize, MPI_BYTE, proc, 2001, MPI_COMM_WORLD, req );
+						}
+					}
+				}
+			
+			}
+
+			{
+				Neighbour_Index		        nbr_I;
+				unsigned i = 0, j = 0;
+				int shadowedCell = 0;
+				char *array = (char*)malloc( swarm->particleExtensionMgr->finalSize );
+
+				for ( nbr_I=0; nbr_I < procNbrInfo->procNbrCnt; nbr_I++ ) {
+					for( i=0; i<cellShadowInfo->procShadowedCnt[nbr_I]; i++ ){
+						MPI_Request *req;
+						int proc = 0;
+
+						proc = procNbrInfo->procNbrTbl[nbr_I];
+
+						shadowedCell = cellShadowInfo->procShadowedTbl[nbr_I][i];
+						for( j=0; j<swarm->cellParticleCountTbl[shadowedCell]; j++ ){
+							int pIndex = 0;
+
+							pIndex = swarm->cellParticleTbl[shadowedCell][j];
+							Swarm_CopyParticleOffSwarm( swarm,
+								array, 0,
+								pIndex );
+
+							req = MemoryPool_NewObject( MPI_Request, requestPool );
+							LinkedList_InsertNode( list, req, sizeof(void*) );
+							MPI_Isend( array, swarm->particleExtensionMgr->finalSize, MPI_BYTE, proc, 2001, MPI_COMM_WORLD, req );
+						}
+					}
+				}
+				free( array );
+			}
+
+			for( data=LinkedListIterator_First(iter); data!=NULL; data=LinkedListIterator_Next(iter) ){
+				MPI_Status s;
+				MPI_Wait( ((MPI_Request*)data), &s );
+			}
+
+			{
+				LinkedListIterator *pIter = LinkedListIterator_New( particleList );
+				for( data=LinkedListIterator_First(pIter); data!=NULL; data=LinkedListIterator_Next(pIter) ){
+					Particle *p = (Particle*)data;
+					int found = 0;
+					double epsilon=1e-5;
+
+					for( ii=0; ii<procNbrInfo->procNbrCnt; ii++ ){
+						for( jj=0; jj<cellShadowInfo->procShadowCnt[ii]; jj++ ){
+							int shadowCell = 0;
+							unsigned kk = 0;
+
+							shadowCell = cellShadowInfo->procShadowTbl[ii][jj];
+							for( kk=0; kk<swarm->shadowCellParticleCountTbl[shadowCell]; kk++ ){
+								int shadowParticleIdx = 0;
+								GlobalParticle *gp = NULL;
+
+								shadowParticleIdx = swarm->shadowCellParticleTbl[shadowCell][kk];
+								gp = ((GlobalParticle*)Swarm_ShadowParticleAt( swarm, shadowParticleIdx));
+								if( (fabs(p->coord[0]-gp->coord[0])<epsilon) && (fabs(p->coord[1]-gp->coord[1])<epsilon) && (fabs(p->coord[2]-gp->coord[2])<epsilon) ){
+									found = 1;
+								}
+							}
+						}
+					}
+					pcu_check_true( found == 1 );
+					pcu_check_true( Journal_Firewall( found, swarm->debug, "Shadow particle validation failed" ) );
+				}
+			}
+			Stg_Class_Delete( list );
+			Stg_Class_Delete( iter );
+			Stg_Class_Delete( requestPool );
+			Stg_Class_Delete( particlePool );
+			Stg_Class_Delete( particleList );
+		}
+	}
+}
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SingleAttractor/SingleAttractor.c
--- a/Swarm/tests/SingleAttractor/SingleAttractor.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include <StgDomain/Swarm/Swarm.h>
-
-#include <assert.h>
-#include <string.h>
-
-const Type StGermain_SingleAttractor_Type = "StGermain_SingleAttractor";
-
-typedef struct {
-	__Codelet
-} StGermain_SingleAttractor;
-
-struct _Particle {
-	__GlobalParticle
-	double  velocity[3];
-	double  randomColour;
-};
-
-void StGermain_SingleAttractor_UpdatePositions( DomainContext* context ) {
-	Cell_LocalIndex			lCell_I;
-	Particle_InCellIndex		cParticle_I;
-	Particle* 	        	currParticle;
-	Index				dim_I;
-	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	Coord                           attractorPoint;
-	Mesh*				mesh;
-	Stream*                         stream = Journal_Register( Info_Type, (Name)"particleUpdate"  );
-	unsigned int                    movementSpeedDivisor = 0;
-	int                             movementSign = 1;
-	unsigned int                    explosionPeriod = 20;
-	double				minCrd[3], maxCrd[3];
-
-	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
-	movementSpeedDivisor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"movementSpeedDivisor", 10 );
-	
-	mesh = (Mesh* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear"  );
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	for ( dim_I=0; dim_I < 3; dim_I++ ) {
-		attractorPoint[dim_I] = (maxCrd[dim_I] - minCrd[dim_I]) / 3;
-	}
-	Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] );
-	
-	/* Now decide if we are attracting or repelling */
-	if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) {
-		Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep );
-		movementSign = 1;
-	}
-	else {
-		Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep );
-		movementSign = -1;
-	}	
-
-	
-	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
-		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
-		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-			Coord movementVector = {0,0,0};
-			Coord newParticleCoord = {0,0,0};
-			Coord* oldCoord;
-
-			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			oldCoord = &currParticle->coord;
-			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) /
-					movementSpeedDivisor;
-				movementVector[dim_I] *= movementSign;	
-				if ( movementSign == -1 ) {
-					movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); 
-				}
-				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-			}
-			memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); 
-
-			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
-				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
-				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				currParticle->coord[dim_I] = newParticleCoord[dim_I];
-			}
-		}
-	}
-
-	Swarm_UpdateAllParticleOwners( swarm );
-}
-
-
-void _StGermain_SingleAttractor_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	DomainContext*   context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-	Stream_SetPrintingRank( 
-		Journal_Register( Info_Type, (Name)"Context"  ),
-		Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
-	
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_SingleAttractor_UpdatePositions );
-}
-
-
-void* _StGermain_SingleAttractor_DefaultNew( Name name ) {
-	return Codelet_New(
-			StGermain_SingleAttractor_Type,
-			_StGermain_SingleAttractor_DefaultNew,
-			_StGermain_SingleAttractor_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-	}
-
-Index StGermain_SingleAttractor_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, StGermain_SingleAttractor_Type, (Name)"0", _StGermain_SingleAttractor_DefaultNew  );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SingleAttractor/SingleAttractor.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SingleAttractor/SingleAttractor.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,125 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include <StgDomain/Swarm/Swarm.h>
+
+#include <assert.h>
+#include <string.h>
+
+const Type StGermain_SingleAttractor_Type = "StGermain_SingleAttractor";
+
+typedef struct {
+	__Codelet
+} StGermain_SingleAttractor;
+
+struct _Particle {
+	__GlobalParticle
+	double  velocity[3];
+	double  randomColour;
+};
+
+void StGermain_SingleAttractor_UpdatePositions( DomainContext* context ) {
+	Cell_LocalIndex			lCell_I;
+	Particle_InCellIndex		cParticle_I;
+	Particle* 	        	currParticle;
+	Index				dim_I;
+	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	Coord                           attractorPoint;
+	Mesh*				mesh;
+	Stream*                         stream = Journal_Register( Info_Type, (Name)"particleUpdate"  );
+	unsigned int                    movementSpeedDivisor = 0;
+	int                             movementSign = 1;
+	unsigned int                    explosionPeriod = 20;
+	double				minCrd[3], maxCrd[3];
+
+	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
+	movementSpeedDivisor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"movementSpeedDivisor", 10 );
+	
+	mesh = (Mesh* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear"  );
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	for ( dim_I=0; dim_I < 3; dim_I++ ) {
+		attractorPoint[dim_I] = (maxCrd[dim_I] - minCrd[dim_I]) / 3;
+	}
+	Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] );
+	
+	/* Now decide if we are attracting or repelling */
+	if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) {
+		Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep );
+		movementSign = 1;
+	}
+	else {
+		Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep );
+		movementSign = -1;
+	}	
+
+	
+	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
+		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
+		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+			Coord movementVector = {0,0,0};
+			Coord newParticleCoord = {0,0,0};
+			Coord* oldCoord;
+
+			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			oldCoord = &currParticle->coord;
+			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) /
+					movementSpeedDivisor;
+				movementVector[dim_I] *= movementSign;	
+				if ( movementSign == -1 ) {
+					movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); 
+				}
+				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+			}
+			memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); 
+
+			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
+				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
+				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				currParticle->coord[dim_I] = newParticleCoord[dim_I];
+			}
+		}
+	}
+
+	Swarm_UpdateAllParticleOwners( swarm );
+}
+
+
+void _StGermain_SingleAttractor_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	DomainContext*   context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+	Stream_SetPrintingRank( 
+		Journal_Register( Info_Type, (Name)"Context"  ),
+		Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
+	
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_SingleAttractor_UpdatePositions );
+}
+
+
+void* _StGermain_SingleAttractor_DefaultNew( Name name ) {
+	return Codelet_New(
+			StGermain_SingleAttractor_Type,
+			_StGermain_SingleAttractor_DefaultNew,
+			_StGermain_SingleAttractor_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+	}
+
+Index StGermain_SingleAttractor_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, StGermain_SingleAttractor_Type, (Name)"0", _StGermain_SingleAttractor_DefaultNew  );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SingleAttractorSuite.c
--- a/Swarm/tests/SingleAttractorSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,233 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the SingleAttractorSuite
-**
-** $Id: testSwarm.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SingleAttractorSuite.h"
-
-/* silly stgermain, I must define this */
-#define CURR_MODULE_NAME "DomainContext.c"
-
-struct _Particle {
-	__GlobalParticle
-	double velocity[3];
-	double randomColour;
-};
-
-void SingleAttractorSuite_SaveSwarms( void* context );
-void SingleAttractorSuite_SingleAttractor( DomainContext* context );
-double SingleAttractorSuite_Dt( void* context ) {
-	return 2.0;
-}
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} SingleAttractorSuiteData;
-
-void SingleAttractorSuite_Setup( SingleAttractorSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void SingleAttractorSuite_Teardown( SingleAttractorSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void SingleAttractorSuite_TestSingleAttractor( SingleAttractorSuiteData* data ) {
-	Dictionary*					dictionary;
-	Dictionary*					componentDict;
-	Stg_ComponentFactory*	cf;
-	Swarm*						swarm = NULL;
-	Particle						particle;
-	Particle*					currParticle = NULL;
-	Particle_Index				lParticle_I = 0;
-	Dimension_Index			dim_I = 0;
-	DomainContext*				context;
-	char							input_file[PCU_PATH_MAX];
-	char							expected_file[PCU_PATH_MAX];
-
-	pcu_filename_input( "testSwarmParticleAdvectionSingleAttractor.xml", input_file );
-
-	cf = stgMainInitFromXML( input_file, data->comm, NULL );
-	context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
-	Stream_Enable( cf->infoStream, False );
-	Stream_Enable( context->info, False );
-	Stream_Enable( context->verbose, False );
-	Stream_Enable( context->debug, False );
-
-	dictionary = context->dictionary;
-	Journal_ReadFromDictionary( dictionary );
-	componentDict = Dictionary_GetDictionary( dictionary, "components" );
-	assert( componentDict );
-
-	KeyCall( context, context->constructExtensionsK, EntryPoint_VoidPtr_CallCast* )( KeyHandle(context,context->constructExtensionsK), context );
-
-	swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleVelocity", sizeof(double[3])  );
-	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleColour", sizeof(double)  );
-
-	Swarm_NewVectorVariable(
-		swarm,
-		"Velocity",
-		(ArithPointer) &particle.velocity - (ArithPointer) &particle,
-		Variable_DataType_Double,
-		swarm->dim,
-		"VelocityX",
-		"VelocityY",
-		"VelocityZ" );
-
-	Swarm_NewScalarVariable(
-		swarm,
-		"RandomColour",
-		(ArithPointer) &particle.randomColour - (ArithPointer) &particle,
-		Variable_DataType_Double );
-
-	stgMainBuildAndInitialise( cf );
-
-	/* for each particle, set a random colour */
-	for ( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-		currParticle = (Particle*)Swarm_ParticleAt( swarm, lParticle_I );
-		for ( dim_I=0; dim_I < 3; dim_I++ ) {
-			currParticle->velocity[dim_I] = 0;
-		}	
-		currParticle->randomColour = ( (double)  rand() ) / RAND_MAX;
-	}
-	
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Dt, SingleAttractorSuite_Dt );
-	ContextEP_Append( context, AbstractContext_EP_Save, SingleAttractorSuite_SaveSwarms );
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, SingleAttractorSuite_SingleAttractor );
-
-	Stg_Component_Execute( context, 0, False );
-	Stg_Component_Destroy( context, 0, False );
-
-	pcu_filename_expected( "testSwarmParticleAdvectionSingleAttractor.expected", expected_file );
-	pcu_check_fileEq( "testSingleAttractor.dat", expected_file );
-	remove( "testSingleAttractor.dat" );
-
-   stgMainDestroy( cf );
-}
-
-void SingleAttractorSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, SingleAttractorSuiteData );
-	pcu_suite_setFixtures( suite, SingleAttractorSuite_Setup, SingleAttractorSuite_Teardown );
-	pcu_suite_addTest( suite, SingleAttractorSuite_TestSingleAttractor );
-}
-
-void SingleAttractorSuite_SaveSwarms( void* context ) {
-   Swarm_Register_SaveAllRegisteredSwarms( Swarm_Register_GetSwarm_Register(), context );
-}
-
-void SingleAttractorSuite_SingleAttractor( DomainContext* context ) {
-	Cell_LocalIndex		lCell_I;
-	Particle_InCellIndex	cParticle_I;
-	Particle*				currParticle;
-	Index						dim_I;
-	Swarm*					swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	Coord						attractorPoint;
-	Mesh*						mesh;
-	Stream*					stream = Journal_Register( Info_Type, (Name)"particleUpdate"  );
-	unsigned int			movementSpeedDivisor = 0;
-	int						movementSign = 1;
-	unsigned int			explosionPeriod = 20;
-	double					minCrd[3], maxCrd[3];
-
-	Stream_RedirectFile( stream, "testSingleAttractor.dat" );
-
-	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
-	movementSpeedDivisor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"movementSpeedDivisor", 10 );
-	
-	mesh = (Mesh* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear"  );
-	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
-	for ( dim_I=0; dim_I < 3; dim_I++ ) {
-		attractorPoint[dim_I] = (maxCrd[dim_I] - minCrd[dim_I]) / 3;
-	}
-	Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] );
-	
-	/* Now decide if we are attracting or repelling */
-	if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) {
-		Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep );
-		movementSign = 1;
-	}
-	else {
-		Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep );
-		movementSign = -1;
-	}	
-
-	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
-		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
-		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-			Coord movementVector = {0,0,0};
-			Coord newParticleCoord = {0,0,0};
-			Coord* oldCoord;
-
-			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			oldCoord = &currParticle->coord;
-			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) / movementSpeedDivisor;
-				movementVector[dim_I] *= movementSign;	
-				if ( movementSign == -1 ) {
-					movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); 
-				}
-				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-			}
-			memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); 
-
-			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
-				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
-				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				currParticle->coord[dim_I] = newParticleCoord[dim_I];
-			}
-		}
-	}
-	Swarm_UpdateAllParticleOwners( swarm );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SingleAttractorSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SingleAttractorSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,233 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the SingleAttractorSuite
+**
+** $Id: testSwarm.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SingleAttractorSuite.h"
+
+/* silly stgermain, I must define this */
+#define CURR_MODULE_NAME "DomainContext.c"
+
+struct _Particle {
+	__GlobalParticle
+	double velocity[3];
+	double randomColour;
+};
+
+void SingleAttractorSuite_SaveSwarms( void* context );
+void SingleAttractorSuite_SingleAttractor( DomainContext* context );
+double SingleAttractorSuite_Dt( void* context ) {
+	return 2.0;
+}
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} SingleAttractorSuiteData;
+
+void SingleAttractorSuite_Setup( SingleAttractorSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void SingleAttractorSuite_Teardown( SingleAttractorSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void SingleAttractorSuite_TestSingleAttractor( SingleAttractorSuiteData* data ) {
+	Dictionary*					dictionary;
+	Dictionary*					componentDict;
+	Stg_ComponentFactory*	cf;
+	Swarm*						swarm = NULL;
+	Particle						particle;
+	Particle*					currParticle = NULL;
+	Particle_Index				lParticle_I = 0;
+	Dimension_Index			dim_I = 0;
+	DomainContext*				context;
+	char							input_file[PCU_PATH_MAX];
+	char							expected_file[PCU_PATH_MAX];
+
+	pcu_filename_input( "testSwarmParticleAdvectionSingleAttractor.xml", input_file );
+
+	cf = stgMainInitFromXML( input_file, data->comm, NULL );
+	context = (DomainContext*)LiveComponentRegister_Get( cf->LCRegister, (Name)"context"  );
+	Stream_Enable( cf->infoStream, False );
+	Stream_Enable( context->info, False );
+	Stream_Enable( context->verbose, False );
+	Stream_Enable( context->debug, False );
+
+	dictionary = context->dictionary;
+	Journal_ReadFromDictionary( dictionary );
+	componentDict = Dictionary_GetDictionary( dictionary, "components" );
+	assert( componentDict );
+
+	KeyCall( context, context->constructExtensionsK, EntryPoint_VoidPtr_CallCast* )( KeyHandle(context,context->constructExtensionsK), context );
+
+	swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleVelocity", sizeof(double[3])  );
+	ExtensionManager_Add( swarm->particleExtensionMgr, (Name)"ParticleColour", sizeof(double)  );
+
+	Swarm_NewVectorVariable(
+		swarm,
+		"Velocity",
+		(ArithPointer) &particle.velocity - (ArithPointer) &particle,
+		Variable_DataType_Double,
+		swarm->dim,
+		"VelocityX",
+		"VelocityY",
+		"VelocityZ" );
+
+	Swarm_NewScalarVariable(
+		swarm,
+		"RandomColour",
+		(ArithPointer) &particle.randomColour - (ArithPointer) &particle,
+		Variable_DataType_Double );
+
+	stgMainBuildAndInitialise( cf );
+
+	/* for each particle, set a random colour */
+	for ( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+		currParticle = (Particle*)Swarm_ParticleAt( swarm, lParticle_I );
+		for ( dim_I=0; dim_I < 3; dim_I++ ) {
+			currParticle->velocity[dim_I] = 0;
+		}	
+		currParticle->randomColour = ( (double)  rand() ) / RAND_MAX;
+	}
+	
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Dt, SingleAttractorSuite_Dt );
+	ContextEP_Append( context, AbstractContext_EP_Save, SingleAttractorSuite_SaveSwarms );
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, SingleAttractorSuite_SingleAttractor );
+
+	Stg_Component_Execute( context, 0, False );
+	Stg_Component_Destroy( context, 0, False );
+
+	pcu_filename_expected( "testSwarmParticleAdvectionSingleAttractor.expected", expected_file );
+	pcu_check_fileEq( "testSingleAttractor.dat", expected_file );
+	remove( "testSingleAttractor.dat" );
+
+   stgMainDestroy( cf );
+}
+
+void SingleAttractorSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, SingleAttractorSuiteData );
+	pcu_suite_setFixtures( suite, SingleAttractorSuite_Setup, SingleAttractorSuite_Teardown );
+	pcu_suite_addTest( suite, SingleAttractorSuite_TestSingleAttractor );
+}
+
+void SingleAttractorSuite_SaveSwarms( void* context ) {
+   Swarm_Register_SaveAllRegisteredSwarms( Swarm_Register_GetSwarm_Register(), context );
+}
+
+void SingleAttractorSuite_SingleAttractor( DomainContext* context ) {
+	Cell_LocalIndex		lCell_I;
+	Particle_InCellIndex	cParticle_I;
+	Particle*				currParticle;
+	Index						dim_I;
+	Swarm*					swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	Coord						attractorPoint;
+	Mesh*						mesh;
+	Stream*					stream = Journal_Register( Info_Type, (Name)"particleUpdate"  );
+	unsigned int			movementSpeedDivisor = 0;
+	int						movementSign = 1;
+	unsigned int			explosionPeriod = 20;
+	double					minCrd[3], maxCrd[3];
+
+	Stream_RedirectFile( stream, "testSingleAttractor.dat" );
+
+	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
+	movementSpeedDivisor = Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"movementSpeedDivisor", 10 );
+	
+	mesh = (Mesh* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear"  );
+	Mesh_GetGlobalCoordRange( mesh, minCrd, maxCrd );
+	for ( dim_I=0; dim_I < 3; dim_I++ ) {
+		attractorPoint[dim_I] = (maxCrd[dim_I] - minCrd[dim_I]) / 3;
+	}
+	Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] );
+	
+	/* Now decide if we are attracting or repelling */
+	if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) {
+		Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep );
+		movementSign = 1;
+	}
+	else {
+		Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep );
+		movementSign = -1;
+	}	
+
+	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
+		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
+		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+			Coord movementVector = {0,0,0};
+			Coord newParticleCoord = {0,0,0};
+			Coord* oldCoord;
+
+			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			oldCoord = &currParticle->coord;
+			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) / movementSpeedDivisor;
+				movementVector[dim_I] *= movementSign;	
+				if ( movementSign == -1 ) {
+					movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); 
+				}
+				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+			}
+			memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); 
+
+			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
+				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
+				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				currParticle->coord[dim_I] = newParticleCoord[dim_I];
+			}
+		}
+	}
+	Swarm_UpdateAllParticleOwners( swarm );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SingleCellLayoutSuite.c
--- a/Swarm/tests/SingleCellLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the SingleCellLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SingleCellLayoutSuite.h"
-
-typedef struct {
-	SingleCellLayout*	singleCellLayout;
-	unsigned int		dimExists[3];
-	double***			cellPoints;
-	MPI_Comm				comm;
-	int					rank;
-	int					nProcs;
-} SingleCellLayoutSuiteData;
-
-
-void SingleCellLayoutSuite_Setup( SingleCellLayoutSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-
-	data->dimExists[0] = True; data->dimExists[1] = True; data->dimExists[2] = True;
-	/* Configure the single-cell-layout */
-	data->singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, (Bool*)(data->dimExists), NULL, NULL );
-}
-
-void SingleCellLayoutSuite_Teardown( SingleCellLayoutSuiteData* data ) {
-}
-
-void SingleCellLayoutSuite_Driver( SingleCellLayoutSuiteData* data ) {
-	Cell_Index  cell;
-
-	for( cell = 0; cell < data->singleCellLayout->_cellLocalCount( data->singleCellLayout ); cell++ ) {
-		Cell_PointIndex count;
-
-		count = data->singleCellLayout->_pointCount( data->singleCellLayout, cell );
-		data->cellPoints = Memory_Alloc_Array( double**, count, "cellsPoints" );
-		data->singleCellLayout->_initialisePoints( data->singleCellLayout, cell, count, data->cellPoints );
-	}
-}
-
-void SingleCellLayoutSuite_TestMapElement( SingleCellLayoutSuiteData* data ) {
-	int procToWatch;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		SingleCellLayoutSuite_Driver( data );
-		
-		pcu_check_true( CellLayout_MapElementIdToCellId( data->singleCellLayout, 0 ) == 0 );
-      pcu_check_true( CellLayout_MapElementIdToCellId( data->singleCellLayout, 5 ) == 0 );
-      pcu_check_true( CellLayout_MapElementIdToCellId( data->singleCellLayout, 100 ) == 0 );
-      pcu_check_true( CellLayout_CellOf( data->singleCellLayout, data->cellPoints[0] ) == 0 );
-
-		Memory_Free( data->cellPoints );
-		Stg_Class_Delete( data->singleCellLayout );	
-	}
-}
-
-void SingleCellLayoutSuite_TestIsInCell( SingleCellLayoutSuiteData* data ) {
-	int		procToWatch;
-	double*	testCoord;		
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		SingleCellLayoutSuite_Driver( data );
-		testCoord = Memory_Alloc_Array_Unnamed( double, 3 );
-		
-		testCoord[0] = testCoord[1] = testCoord[2] = 0;
-		pcu_check_true( CellLayout_IsInCell( data->singleCellLayout, 0, &testCoord ) );
-		testCoord[0] = testCoord[1] = testCoord[2] = 1;
-		pcu_check_true( CellLayout_IsInCell( data->singleCellLayout, 0, &testCoord ) );
-		testCoord[0] = testCoord[1] = testCoord[2] = 2;
-		pcu_check_true( !CellLayout_IsInCell( data->singleCellLayout, 0, &testCoord ) );
-	
-		Memory_Free( testCoord );
-		Memory_Free( data->cellPoints );
-		Stg_Class_Delete( data->singleCellLayout );	
-	}
-}
-
-void SingleCellLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, SingleCellLayoutSuiteData );
-	pcu_suite_setFixtures( suite, SingleCellLayoutSuite_Setup, SingleCellLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, SingleCellLayoutSuite_TestMapElement );
-	pcu_suite_addTest( suite, SingleCellLayoutSuite_TestIsInCell );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SingleCellLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SingleCellLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,131 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the SingleCellLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SingleCellLayoutSuite.h"
+
+typedef struct {
+	SingleCellLayout*	singleCellLayout;
+	unsigned int		dimExists[3];
+	double***			cellPoints;
+	MPI_Comm				comm;
+	int					rank;
+	int					nProcs;
+} SingleCellLayoutSuiteData;
+
+
+void SingleCellLayoutSuite_Setup( SingleCellLayoutSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+
+	data->dimExists[0] = True; data->dimExists[1] = True; data->dimExists[2] = True;
+	/* Configure the single-cell-layout */
+	data->singleCellLayout = SingleCellLayout_New( "singleCellLayout", NULL, (Bool*)(data->dimExists), NULL, NULL );
+}
+
+void SingleCellLayoutSuite_Teardown( SingleCellLayoutSuiteData* data ) {
+}
+
+void SingleCellLayoutSuite_Driver( SingleCellLayoutSuiteData* data ) {
+	Cell_Index  cell;
+
+	for( cell = 0; cell < data->singleCellLayout->_cellLocalCount( data->singleCellLayout ); cell++ ) {
+		Cell_PointIndex count;
+
+		count = data->singleCellLayout->_pointCount( data->singleCellLayout, cell );
+		data->cellPoints = Memory_Alloc_Array( double**, count, "cellsPoints" );
+		data->singleCellLayout->_initialisePoints( data->singleCellLayout, cell, count, data->cellPoints );
+	}
+}
+
+void SingleCellLayoutSuite_TestMapElement( SingleCellLayoutSuiteData* data ) {
+	int procToWatch;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		SingleCellLayoutSuite_Driver( data );
+		
+		pcu_check_true( CellLayout_MapElementIdToCellId( data->singleCellLayout, 0 ) == 0 );
+      pcu_check_true( CellLayout_MapElementIdToCellId( data->singleCellLayout, 5 ) == 0 );
+      pcu_check_true( CellLayout_MapElementIdToCellId( data->singleCellLayout, 100 ) == 0 );
+      pcu_check_true( CellLayout_CellOf( data->singleCellLayout, data->cellPoints[0] ) == 0 );
+
+		Memory_Free( data->cellPoints );
+		Stg_Class_Delete( data->singleCellLayout );	
+	}
+}
+
+void SingleCellLayoutSuite_TestIsInCell( SingleCellLayoutSuiteData* data ) {
+	int		procToWatch;
+	double*	testCoord;		
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		SingleCellLayoutSuite_Driver( data );
+		testCoord = Memory_Alloc_Array_Unnamed( double, 3 );
+		
+		testCoord[0] = testCoord[1] = testCoord[2] = 0;
+		pcu_check_true( CellLayout_IsInCell( data->singleCellLayout, 0, &testCoord ) );
+		testCoord[0] = testCoord[1] = testCoord[2] = 1;
+		pcu_check_true( CellLayout_IsInCell( data->singleCellLayout, 0, &testCoord ) );
+		testCoord[0] = testCoord[1] = testCoord[2] = 2;
+		pcu_check_true( !CellLayout_IsInCell( data->singleCellLayout, 0, &testCoord ) );
+	
+		Memory_Free( testCoord );
+		Memory_Free( data->cellPoints );
+		Stg_Class_Delete( data->singleCellLayout );	
+	}
+}
+
+void SingleCellLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, SingleCellLayoutSuiteData );
+	pcu_suite_setFixtures( suite, SingleCellLayoutSuite_Setup, SingleCellLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, SingleCellLayoutSuite_TestMapElement );
+	pcu_suite_addTest( suite, SingleCellLayoutSuite_TestIsInCell );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SpaceFillerParticleLayoutSuite.c
--- a/Swarm/tests/SpaceFillerParticleLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,151 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the SpaceFillerParticleLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SpaceFillerParticleLayoutSuite.h"
-
-struct _Particle {
-	__IntegrationPoint
-};
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} SpaceFillerParticleLayoutSuiteData;
-
-Mesh* SpaceFillerParticleLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator* gen;
-	Mesh*						mesh;
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-	Mesh_SetAlgorithms( mesh, Mesh_RegularAlgorithms_New( "", NULL ) );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void SpaceFillerParticleLayoutSuite_Setup( SpaceFillerParticleLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-   
-}
-
-void SpaceFillerParticleLayoutSuite_Teardown( SpaceFillerParticleLayoutSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void SpaceFillerParticleLayoutSuite_TestSpaceFillerParticle( SpaceFillerParticleLayoutSuiteData* data ) {
-	ExtensionManager_Register*	extensionMgr_Register;
-	SpaceFillerParticleLayout*	particleLayout;
-	ElementCellLayout*			elementCellLayout;
-	Dimension_Index				dim;
-	Mesh*								mesh;
-	Swarm*							swarm;
-	Stream*							stream;
-	unsigned							nDims;
-	unsigned							meshSize[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	int								procToWatch = data->nProcs > 1 ? 1 : 0;
-	char								expected_file[PCU_PATH_MAX];
-
-	if( data->rank == procToWatch ) {
-
-		nDims = 3;
-		meshSize[0] = 4;	meshSize[1] = 2;	meshSize[2] = 1;
-		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
-		maxCrds[0] = 400.0; maxCrds[1] = 200.0; maxCrds[2] = 100.0;
-
-		extensionMgr_Register = ExtensionManager_Register_New();
-		mesh = SpaceFillerParticleLayoutSuite_BuildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-		
-		elementCellLayout = ElementCellLayout_New( "spaceFillerParticlElementCellLayout", NULL, mesh );
-		particleLayout = SpaceFillerParticleLayout_New( "spaceFillerParticleLayout", NULL, GlobalCoordSystem, False, SpaceFillerParticleLayout_Invalid, 20, nDims );
-	
-		swarm = Swarm_New( "testSpaceFIllerParticle", NULL, elementCellLayout, particleLayout, dim, sizeof(Particle),
-			extensionMgr_Register, NULL, data->comm, NULL );
- 
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-
-		Journal_Enable_AllTypedStream( True );
-		stream = Journal_Register( Info_Type, (Name)"TestSpaceFillerParticle"  );
-		Stream_RedirectFile( stream, "spaceFillerParticle.dat" );
-		Swarm_PrintParticleCoords_ByCell( swarm, stream );
-		Journal_Enable_AllTypedStream( False );
-
-		pcu_filename_expected( "testSpaceFillerParticleLayoutOutput.expected", expected_file );
-		pcu_check_fileEq( "spaceFillerParticle.dat", expected_file );
-		remove( "spaceFillerParticle.dat" );
-
-		Stg_Class_Delete( extensionMgr_Register );
-		/*Stg_Component_Destroy( mesh, NULL, True );*/
-		Stg_Component_Destroy( elementCellLayout, NULL, True );
-		Stg_Component_Destroy( particleLayout, NULL, True );
-		Stg_Component_Destroy( swarm, NULL, True );
-	}
-}
-
-void SpaceFillerParticleLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, SpaceFillerParticleLayoutSuiteData );
-	pcu_suite_setFixtures( suite, SpaceFillerParticleLayoutSuite_Setup, SpaceFillerParticleLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, SpaceFillerParticleLayoutSuite_TestSpaceFillerParticle );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SpaceFillerParticleLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SpaceFillerParticleLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,151 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the SpaceFillerParticleLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SpaceFillerParticleLayoutSuite.h"
+
+struct _Particle {
+	__IntegrationPoint
+};
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} SpaceFillerParticleLayoutSuiteData;
+
+Mesh* SpaceFillerParticleLayoutSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator* gen;
+	Mesh*						mesh;
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+	Mesh_SetAlgorithms( mesh, Mesh_RegularAlgorithms_New( "", NULL ) );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void SpaceFillerParticleLayoutSuite_Setup( SpaceFillerParticleLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+   
+}
+
+void SpaceFillerParticleLayoutSuite_Teardown( SpaceFillerParticleLayoutSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void SpaceFillerParticleLayoutSuite_TestSpaceFillerParticle( SpaceFillerParticleLayoutSuiteData* data ) {
+	ExtensionManager_Register*	extensionMgr_Register;
+	SpaceFillerParticleLayout*	particleLayout;
+	ElementCellLayout*			elementCellLayout;
+	Dimension_Index				dim;
+	Mesh*								mesh;
+	Swarm*							swarm;
+	Stream*							stream;
+	unsigned							nDims;
+	unsigned							meshSize[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	int								procToWatch = data->nProcs > 1 ? 1 : 0;
+	char								expected_file[PCU_PATH_MAX];
+
+	if( data->rank == procToWatch ) {
+
+		nDims = 3;
+		meshSize[0] = 4;	meshSize[1] = 2;	meshSize[2] = 1;
+		minCrds[0] = 0.0; minCrds[1] = 0.0; minCrds[2] = 0.0;
+		maxCrds[0] = 400.0; maxCrds[1] = 200.0; maxCrds[2] = 100.0;
+
+		extensionMgr_Register = ExtensionManager_Register_New();
+		mesh = SpaceFillerParticleLayoutSuite_BuildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+		
+		elementCellLayout = ElementCellLayout_New( "spaceFillerParticlElementCellLayout", NULL, mesh );
+		particleLayout = SpaceFillerParticleLayout_New( "spaceFillerParticleLayout", NULL, GlobalCoordSystem, False, SpaceFillerParticleLayout_Invalid, 20, nDims );
+	
+		swarm = Swarm_New( "testSpaceFIllerParticle", NULL, elementCellLayout, particleLayout, dim, sizeof(Particle),
+			extensionMgr_Register, NULL, data->comm, NULL );
+ 
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+
+		Journal_Enable_AllTypedStream( True );
+		stream = Journal_Register( Info_Type, (Name)"TestSpaceFillerParticle"  );
+		Stream_RedirectFile( stream, "spaceFillerParticle.dat" );
+		Swarm_PrintParticleCoords_ByCell( swarm, stream );
+		Journal_Enable_AllTypedStream( False );
+
+		pcu_filename_expected( "testSpaceFillerParticleLayoutOutput.expected", expected_file );
+		pcu_check_fileEq( "spaceFillerParticle.dat", expected_file );
+		remove( "spaceFillerParticle.dat" );
+
+		Stg_Class_Delete( extensionMgr_Register );
+		/*Stg_Component_Destroy( mesh, NULL, True );*/
+		Stg_Component_Destroy( elementCellLayout, NULL, True );
+		Stg_Component_Destroy( particleLayout, NULL, True );
+		Stg_Component_Destroy( swarm, NULL, True );
+	}
+}
+
+void SpaceFillerParticleLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, SpaceFillerParticleLayoutSuiteData );
+	pcu_suite_setFixtures( suite, SpaceFillerParticleLayoutSuite_Setup, SpaceFillerParticleLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, SpaceFillerParticleLayoutSuite_TestSpaceFillerParticle );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/Spinner/Spinner.c
--- a/Swarm/tests/Spinner/Spinner.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include <StgDomain/Swarm/Swarm.h>
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-#define PI 3.1415926535897931
-
-const Type StGermain_Spinner_Type = "StGermain_Spinner";
-
-typedef struct {
-	__Codelet
-} StGermain_Spinner;
-
-struct _Particle {
-	__GlobalParticle
-	double  velocity[3];
-	double  randomColour;
-};
-
-void StGermain_Spinner_UpdatePositions( DomainContext* context ) {
-	Cell_LocalIndex			lCell_I;
-	Particle_InCellIndex		cParticle_I;
-	Particle* 	        	currParticle;
-	Index				dim_I;
-	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	BlockGeometry*                  blockGeom;
-	Stream*                         stream = Journal_Register( Debug_Type, (Name)"particleUpdate"  );
-	unsigned int                    movementSpeedDivisor = 100;
-	double                          x, y;
-	Bool                            reverseMode = False;
-	Index                           reverseTimeStep;
-	
-	reverseTimeStep = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "reverseTimeStep", 100 );
-	if ( context->timeStep >= reverseTimeStep ) {
-		Journal_Printf( stream, "Current timestep %d >= reverse step -> reversing flow field.\n",
-			context->timeStep );
-		reverseMode = True;	
-	}	
-
-	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
-	
-	blockGeom = (BlockGeometry*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"geometry" );
-
-	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++  ) {
-		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
-		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-			Coord movementVector = {0,0,0};
-			Coord newParticleCoord = {0,0,0};
-			Coord* oldCoord;
-
-			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			oldCoord = &currParticle->coord;
-			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
-
-			x = currParticle->coord[0];
-			y = currParticle->coord[1];
-			movementVector[0] = 2 * -1 * pow( sin( PI * x ), 2 ) * sin( PI * y ) * cos( PI * y );
-			movementVector[1] = 2 *  1 * pow( sin( PI * y ), 2 ) * sin( PI * x ) * cos( PI * x );
-			movementVector[2] = 0;
-
-			if ( reverseMode ) {
-				movementVector[0] *= -1;
-				movementVector[1] *= -1;
-			}
-			
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				movementVector[dim_I] /= movementSpeedDivisor;
-				currParticle->velocity[dim_I] = movementVector[dim_I];
-				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-			}
-
-			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
-				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
-				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				currParticle->coord[dim_I] = newParticleCoord[dim_I];
-			}
-		}
-	}
-
-	Swarm_UpdateAllParticleOwners( swarm );
-}
-
-
-void _StGermain_Spinner_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	DomainContext*   context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-	
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_Spinner_UpdatePositions );
-}
-
-
-void* _StGermain_Spinner_DefaultNew( Name name ) {
-	return Codelet_New(
-			StGermain_Spinner_Type,
-			_StGermain_Spinner_DefaultNew,
-			_StGermain_Spinner_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-	}
-
-Index StGermain_Spinner_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, StGermain_Spinner_Type, (Name)"0", _StGermain_Spinner_DefaultNew  );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/Spinner/Spinner.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/Spinner/Spinner.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,120 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include <StgDomain/Swarm/Swarm.h>
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+#define PI 3.1415926535897931
+
+const Type StGermain_Spinner_Type = "StGermain_Spinner";
+
+typedef struct {
+	__Codelet
+} StGermain_Spinner;
+
+struct _Particle {
+	__GlobalParticle
+	double  velocity[3];
+	double  randomColour;
+};
+
+void StGermain_Spinner_UpdatePositions( DomainContext* context ) {
+	Cell_LocalIndex			lCell_I;
+	Particle_InCellIndex		cParticle_I;
+	Particle* 	        	currParticle;
+	Index				dim_I;
+	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	BlockGeometry*                  blockGeom;
+	Stream*                         stream = Journal_Register( Debug_Type, (Name)"particleUpdate"  );
+	unsigned int                    movementSpeedDivisor = 100;
+	double                          x, y;
+	Bool                            reverseMode = False;
+	Index                           reverseTimeStep;
+	
+	reverseTimeStep = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "reverseTimeStep", 100 );
+	if ( context->timeStep >= reverseTimeStep ) {
+		Journal_Printf( stream, "Current timestep %d >= reverse step -> reversing flow field.\n",
+			context->timeStep );
+		reverseMode = True;	
+	}	
+
+	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
+	
+	blockGeom = (BlockGeometry*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"geometry" );
+
+	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++  ) {
+		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
+		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+			Coord movementVector = {0,0,0};
+			Coord newParticleCoord = {0,0,0};
+			Coord* oldCoord;
+
+			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			oldCoord = &currParticle->coord;
+			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
+
+			x = currParticle->coord[0];
+			y = currParticle->coord[1];
+			movementVector[0] = 2 * -1 * pow( sin( PI * x ), 2 ) * sin( PI * y ) * cos( PI * y );
+			movementVector[1] = 2 *  1 * pow( sin( PI * y ), 2 ) * sin( PI * x ) * cos( PI * x );
+			movementVector[2] = 0;
+
+			if ( reverseMode ) {
+				movementVector[0] *= -1;
+				movementVector[1] *= -1;
+			}
+			
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				movementVector[dim_I] /= movementSpeedDivisor;
+				currParticle->velocity[dim_I] = movementVector[dim_I];
+				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+			}
+
+			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
+				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
+				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				currParticle->coord[dim_I] = newParticleCoord[dim_I];
+			}
+		}
+	}
+
+	Swarm_UpdateAllParticleOwners( swarm );
+}
+
+
+void _StGermain_Spinner_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	DomainContext*   context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+	
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_Spinner_UpdatePositions );
+}
+
+
+void* _StGermain_Spinner_DefaultNew( Name name ) {
+	return Codelet_New(
+			StGermain_Spinner_Type,
+			_StGermain_Spinner_DefaultNew,
+			_StGermain_Spinner_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+	}
+
+Index StGermain_Spinner_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, StGermain_Spinner_Type, (Name)"0", _StGermain_Spinner_DefaultNew  );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SwarmDumpAndLoadSuite.c
--- a/Swarm/tests/SwarmDumpAndLoadSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,250 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**      Tests that particles can be saved to file, then re-loaded onto a new context with exactly
-**      the same positions and values.
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SwarmDumpAndLoadSuite.h"
-
-#define CURR_MODULE_NAME "DomainContext.c"
-
-struct _Particle {
-        __IntegrationPoint;
-};
-
-typedef struct {
-   MPI_Comm comm;
-   int rank;
-   int nProcs;
-} SwarmDumpAndLoadSuiteData;
-
-void SwarmDumpAndLoadSuite_UpdateParticlePositionsTowardsAttractor( DomainContext* context );
-
-void SwarmDumpAndLoadSuite_Setup( SwarmDumpAndLoadSuiteData* data ) {
-   /* MPI Initializations */
-   data->comm = MPI_COMM_WORLD;  
-   MPI_Comm_rank( data->comm, &data->rank );
-   MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void SwarmDumpAndLoadSuite_Teardown( SwarmDumpAndLoadSuiteData* data ) {   
-}
-
-void SwarmDumpAndLoadSuite_TestSwarmDumpAndLoad( SwarmDumpAndLoadSuiteData* data ) {
-   int                     ii;
-   Swarm*                  swarm;
-   Swarm*                  newSwarm = NULL;
-   Swarm*                  swarmList[1];
-   SwarmDump*              swarmDumper = NULL;
-   DomainContext*          context;
-   Dictionary*             dictionary;
-   Stg_ComponentFactory*   cf;
-   Stream*                 stream;
-   FileParticleLayout*     fileParticleLayout = NULL;
-   char                    input_file[PCU_PATH_MAX];
-   char                    output_file[PCU_PATH_MAX];
-   char                    filenameTemp[PCU_PATH_MAX];   
-   double                  diffSumX, diffSumY, diffSumZ;
-   double                  totSumX, totSumY, totSumZ;
-   double                  gdiffSumX, gdiffSumY, gdiffSumZ;
-   double                  gtotSumX, gtotSumY, gtotSumZ;
-   double                  tolerance = 1e-5;
-   Particle_InCellIndex    cParticle_I;
-   IntegrationPoint integrationPoint;
-   SwarmVariable* posVariable;
-   SwarmVariable* posVariableNew;
-   Variable_Register* varReg = Variable_Register_New();
-   stream = Journal_Register( Info_Type, (Name)"SwarmDumpStream" );
-   
-   Journal_Enable_TypedStream( DebugStream_Type, False );
-   Stream_EnableBranch( Swarm_Debug, False );
-   
-   Stream_Enable( Journal_Register( Info_Type, (Name)ParticleCommHandler_Type  ), False );
-   Stream_Enable( Journal_Register( Info_Type, (Name)SwarmDump_Type  ), False );
-   
-   pcu_filename_input( "testSwarmDump.xml", input_file );
-   /* setup from XML */
-   cf = stgMainInitFromXML( input_file, data->comm, NULL );
-   context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-   
-   dictionary = context->dictionary;
-
-   swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-   /* create a swarmVariable, as this will be required for the HDF5 checkpointing (else it doesn't know about the required variable to save) */   
-   posVariable = Swarm_NewVectorVariable(swarm, "Position", GetOffsetOfMember( integrationPoint, xi ),Variable_DataType_Double, swarm->dim, "PositionX", "PositionY", "PositionZ" );
-   posVariable->isCheckpointedAndReloaded = True;
-   Stg_Component_Build( posVariable, data, False );
-   
-   stgMainBuildAndInitialise( cf );
-   /* advect particles */
-   SwarmDumpAndLoadSuite_UpdateParticlePositionsTowardsAttractor(context);
-   Swarm_UpdateAllParticleOwners( swarm );
-   swarmList[0] = swarm;
-   swarmDumper = SwarmDump_New( "SwarmDumpSuiteDumper", context, swarmList, 1, True );
-   /* dump swarm */
-   SwarmDump_Execute( swarmDumper, context );
-   /* create a barrier, as other procs may try to read from files even though they are not created yet */
-   MPI_Barrier( data->comm );
-#ifdef READ_HDF5
-   sprintf( output_file, "%s/%s.%05d", context->outputPath, swarm->name, context->timeStep );
-#else
-   sprintf( output_file, "%s/%s.%05d.dat", context->outputPath, swarm->name, context->timeStep );
-#endif
-   /* create a fileParticleLayout to load files from file */
-   fileParticleLayout = FileParticleLayout_New( "fileParticleLayout", NULL, GlobalCoordSystem, False, 0, 0.0, output_file, data->nProcs );
-   Stg_Component_AssignFromXML( fileParticleLayout, cf, 0, False );
-   
-   newSwarm = Swarm_New( "testSwarm2", (AbstractContext*)context, (ElementCellLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"elementCellLayout"  ),
-		fileParticleLayout, 3, sizeof(Particle), extensionMgr_Register, varReg, data->comm, NULL );
-   /* as with for the swarmDump,  create a swarmVariable, as this will be required for the HDF5 checkpointing (else it doesn't know about the required variable to save) */   
-   posVariableNew = Swarm_NewVectorVariable( newSwarm, "Position", GetOffsetOfMember( integrationPoint, xi ), Variable_DataType_Double, newSwarm->dim, "PositionX", "PositionY", "PositionZ" );
-   posVariableNew->isCheckpointedAndReloaded = True;
-   Stg_Component_Build( posVariableNew, data, False );
-   
-   Stg_Component_Build( newSwarm, 0, False );
-   Stg_Component_Initialise( newSwarm, 0, False );
-   
-   /* now check that two swarms coincide */
-   diffSumX = 0;
-   diffSumY = 0;
-   diffSumZ = 0;
-   totSumX  = 0;
-   totSumY  = 0;
-   totSumZ  = 0;
-   pcu_check_true(swarm->particleLocalCount == newSwarm->particleLocalCount);
-
-   for ( cParticle_I=0; cParticle_I < swarm->particleLocalCount; cParticle_I++ ) {
-      pcu_check_true( swarm->particles[cParticle_I].owningCell == newSwarm->particles[cParticle_I].owningCell);
-      diffSumX += pow(swarm->particles[cParticle_I].xi[0] - newSwarm->particles[cParticle_I].xi[0], 2);
-      diffSumY += pow(swarm->particles[cParticle_I].xi[1] - newSwarm->particles[cParticle_I].xi[1], 2);
-      diffSumZ += pow(swarm->particles[cParticle_I].xi[2] - newSwarm->particles[cParticle_I].xi[2], 2);
-      totSumX  += pow(swarm->particles[cParticle_I].xi[0], 2);
-      totSumY  += pow(swarm->particles[cParticle_I].xi[1], 2);
-      totSumZ  += pow(swarm->particles[cParticle_I].xi[2], 2);
-   }
-
-   MPI_Allreduce( &diffSumX, &gdiffSumX, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
-   MPI_Allreduce( &diffSumY, &gdiffSumY, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
-   MPI_Allreduce( &diffSumZ, &gdiffSumZ, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
-   MPI_Allreduce(  &totSumX,  &gtotSumX, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
-   MPI_Allreduce(  &totSumY,  &gtotSumY, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
-   MPI_Allreduce(  &totSumZ,  &gtotSumZ, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
-   
-   pcu_check_true( gdiffSumX/gtotSumX < tolerance );
-   pcu_check_true( gdiffSumY/gtotSumY < tolerance );
-   pcu_check_true( gdiffSumZ/gtotSumZ < tolerance );
-
-   /* remove files */
-   if( data->rank == 0 ){
-#ifdef READ_HDF5
-         for(ii = 0 ; ii < data->nProcs ; ii++){
-            /* get the swarm checkpointing filename */
-            if(data->nProcs == 1)
-               sprintf( filenameTemp, "%s.h5", output_file );
-            else 
-               sprintf( filenameTemp, "%s.%dof%d.h5", output_file, ii+1, data->nProcs );
-            remove(filenameTemp);
-         }
-#else
-      remove(output_file);
-#endif   
-      remove(context->outputPath);
-   }
-   
-   Stg_Class_Delete( varReg );
-
-   Stg_Component_Build( posVariable, NULL, False );
-   Stg_Component_Destroy( fileParticleLayout, NULL, False );
-   Stg_Component_Destroy( posVariableNew, NULL, False );
-   Stg_Component_Destroy( newSwarm, NULL, False );
-
-   Stg_Class_Delete( posVariable );
-   Stg_Class_Delete( fileParticleLayout );
-   Stg_Class_Delete( posVariableNew );
-   Stg_Class_Delete( newSwarm );
-   stgMainDestroy( cf );
-
-}
-
-void SwarmDumpAndLoadSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, SwarmDumpAndLoadSuiteData );
-   pcu_suite_setFixtures( suite, SwarmDumpAndLoadSuite_Setup, SwarmDumpAndLoadSuite_Teardown );
-   pcu_suite_addTest( suite, SwarmDumpAndLoadSuite_TestSwarmDumpAndLoad );
-}
-
-void SwarmDumpAndLoadSuite_UpdateParticlePositionsTowardsAttractor( DomainContext* context ) {
-   Cell_LocalIndex         lCell_I;
-   Particle_InCellIndex    cParticle_I;
-   Particle*               currParticle;
-   Index                   dim_I;
-   Mesh*                   mesh = (Mesh*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear" );
-   Swarm*                  swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-   Coord                   attractorPoint;
-   double                  minCrds[3], maxCrds[3];
-
-   Mesh_GetGlobalCoordRange( mesh, minCrds, maxCrds );
-
-   for ( dim_I=0; dim_I < 3; dim_I++ ) 
-      attractorPoint[dim_I] = ( maxCrds[dim_I] - minCrds[dim_I] ) / 3;
-
-   for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
-      for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-         Coord movementVector = {0,0,0};
-         Coord newParticleCoord = {0,0,0};
-         Coord* oldCoord;
-         
-         currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-         oldCoord = &currParticle->xi;
-         
-         for ( dim_I=0; dim_I < 3; dim_I++ ) {
-            movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) / 3;
-            newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-         }
-
-         for ( dim_I=0; dim_I < 3; dim_I++ ) {
-            currParticle->xi[dim_I] = newParticleCoord[dim_I];
-         }
-      }
-   }
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SwarmDumpAndLoadSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SwarmDumpAndLoadSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,250 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**      Tests that particles can be saved to file, then re-loaded onto a new context with exactly
+**      the same positions and values.
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SwarmDumpAndLoadSuite.h"
+
+#define CURR_MODULE_NAME "DomainContext.c"
+
+struct _Particle {
+        __IntegrationPoint;
+};
+
+typedef struct {
+   MPI_Comm comm;
+   int rank;
+   int nProcs;
+} SwarmDumpAndLoadSuiteData;
+
+void SwarmDumpAndLoadSuite_UpdateParticlePositionsTowardsAttractor( DomainContext* context );
+
+void SwarmDumpAndLoadSuite_Setup( SwarmDumpAndLoadSuiteData* data ) {
+   /* MPI Initializations */
+   data->comm = MPI_COMM_WORLD;  
+   MPI_Comm_rank( data->comm, &data->rank );
+   MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void SwarmDumpAndLoadSuite_Teardown( SwarmDumpAndLoadSuiteData* data ) {   
+}
+
+void SwarmDumpAndLoadSuite_TestSwarmDumpAndLoad( SwarmDumpAndLoadSuiteData* data ) {
+   int                     ii;
+   Swarm*                  swarm;
+   Swarm*                  newSwarm = NULL;
+   Swarm*                  swarmList[1];
+   SwarmDump*              swarmDumper = NULL;
+   DomainContext*          context;
+   Dictionary*             dictionary;
+   Stg_ComponentFactory*   cf;
+   Stream*                 stream;
+   FileParticleLayout*     fileParticleLayout = NULL;
+   char                    input_file[PCU_PATH_MAX];
+   char                    output_file[PCU_PATH_MAX];
+   char                    filenameTemp[PCU_PATH_MAX];   
+   double                  diffSumX, diffSumY, diffSumZ;
+   double                  totSumX, totSumY, totSumZ;
+   double                  gdiffSumX, gdiffSumY, gdiffSumZ;
+   double                  gtotSumX, gtotSumY, gtotSumZ;
+   double                  tolerance = 1e-5;
+   Particle_InCellIndex    cParticle_I;
+   IntegrationPoint integrationPoint;
+   SwarmVariable* posVariable;
+   SwarmVariable* posVariableNew;
+   Variable_Register* varReg = Variable_Register_New();
+   stream = Journal_Register( Info_Type, (Name)"SwarmDumpStream" );
+   
+   Journal_Enable_TypedStream( DebugStream_Type, False );
+   Stream_EnableBranch( Swarm_Debug, False );
+   
+   Stream_Enable( Journal_Register( Info_Type, (Name)ParticleCommHandler_Type  ), False );
+   Stream_Enable( Journal_Register( Info_Type, (Name)SwarmDump_Type  ), False );
+   
+   pcu_filename_input( "testSwarmDump.xml", input_file );
+   /* setup from XML */
+   cf = stgMainInitFromXML( input_file, data->comm, NULL );
+   context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+   
+   dictionary = context->dictionary;
+
+   swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+   /* create a swarmVariable, as this will be required for the HDF5 checkpointing (else it doesn't know about the required variable to save) */   
+   posVariable = Swarm_NewVectorVariable(swarm, "Position", GetOffsetOfMember( integrationPoint, xi ),Variable_DataType_Double, swarm->dim, "PositionX", "PositionY", "PositionZ" );
+   posVariable->isCheckpointedAndReloaded = True;
+   Stg_Component_Build( posVariable, data, False );
+   
+   stgMainBuildAndInitialise( cf );
+   /* advect particles */
+   SwarmDumpAndLoadSuite_UpdateParticlePositionsTowardsAttractor(context);
+   Swarm_UpdateAllParticleOwners( swarm );
+   swarmList[0] = swarm;
+   swarmDumper = SwarmDump_New( "SwarmDumpSuiteDumper", context, swarmList, 1, True );
+   /* dump swarm */
+   SwarmDump_Execute( swarmDumper, context );
+   /* create a barrier, as other procs may try to read from files even though they are not created yet */
+   MPI_Barrier( data->comm );
+#ifdef READ_HDF5
+   sprintf( output_file, "%s/%s.%05d", context->outputPath, swarm->name, context->timeStep );
+#else
+   sprintf( output_file, "%s/%s.%05d.dat", context->outputPath, swarm->name, context->timeStep );
+#endif
+   /* create a fileParticleLayout to load files from file */
+   fileParticleLayout = FileParticleLayout_New( "fileParticleLayout", NULL, GlobalCoordSystem, False, 0, 0.0, output_file, data->nProcs );
+   Stg_Component_AssignFromXML( fileParticleLayout, cf, 0, False );
+   
+   newSwarm = Swarm_New( "testSwarm2", (AbstractContext*)context, (ElementCellLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"elementCellLayout"  ),
+		fileParticleLayout, 3, sizeof(Particle), extensionMgr_Register, varReg, data->comm, NULL );
+   /* as with for the swarmDump,  create a swarmVariable, as this will be required for the HDF5 checkpointing (else it doesn't know about the required variable to save) */   
+   posVariableNew = Swarm_NewVectorVariable( newSwarm, "Position", GetOffsetOfMember( integrationPoint, xi ), Variable_DataType_Double, newSwarm->dim, "PositionX", "PositionY", "PositionZ" );
+   posVariableNew->isCheckpointedAndReloaded = True;
+   Stg_Component_Build( posVariableNew, data, False );
+   
+   Stg_Component_Build( newSwarm, 0, False );
+   Stg_Component_Initialise( newSwarm, 0, False );
+   
+   /* now check that two swarms coincide */
+   diffSumX = 0;
+   diffSumY = 0;
+   diffSumZ = 0;
+   totSumX  = 0;
+   totSumY  = 0;
+   totSumZ  = 0;
+   pcu_check_true(swarm->particleLocalCount == newSwarm->particleLocalCount);
+
+   for ( cParticle_I=0; cParticle_I < swarm->particleLocalCount; cParticle_I++ ) {
+      pcu_check_true( swarm->particles[cParticle_I].owningCell == newSwarm->particles[cParticle_I].owningCell);
+      diffSumX += pow(swarm->particles[cParticle_I].xi[0] - newSwarm->particles[cParticle_I].xi[0], 2);
+      diffSumY += pow(swarm->particles[cParticle_I].xi[1] - newSwarm->particles[cParticle_I].xi[1], 2);
+      diffSumZ += pow(swarm->particles[cParticle_I].xi[2] - newSwarm->particles[cParticle_I].xi[2], 2);
+      totSumX  += pow(swarm->particles[cParticle_I].xi[0], 2);
+      totSumY  += pow(swarm->particles[cParticle_I].xi[1], 2);
+      totSumZ  += pow(swarm->particles[cParticle_I].xi[2], 2);
+   }
+
+   MPI_Allreduce( &diffSumX, &gdiffSumX, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
+   MPI_Allreduce( &diffSumY, &gdiffSumY, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
+   MPI_Allreduce( &diffSumZ, &gdiffSumZ, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
+   MPI_Allreduce(  &totSumX,  &gtotSumX, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
+   MPI_Allreduce(  &totSumY,  &gtotSumY, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
+   MPI_Allreduce(  &totSumZ,  &gtotSumZ, 1, MPI_DOUBLE, MPI_SUM, swarm->comm );
+   
+   pcu_check_true( gdiffSumX/gtotSumX < tolerance );
+   pcu_check_true( gdiffSumY/gtotSumY < tolerance );
+   pcu_check_true( gdiffSumZ/gtotSumZ < tolerance );
+
+   /* remove files */
+   if( data->rank == 0 ){
+#ifdef READ_HDF5
+         for(ii = 0 ; ii < data->nProcs ; ii++){
+            /* get the swarm checkpointing filename */
+            if(data->nProcs == 1)
+               sprintf( filenameTemp, "%s.h5", output_file );
+            else 
+               sprintf( filenameTemp, "%s.%dof%d.h5", output_file, ii+1, data->nProcs );
+            remove(filenameTemp);
+         }
+#else
+      remove(output_file);
+#endif   
+      remove(context->outputPath);
+   }
+   
+   Stg_Class_Delete( varReg );
+
+   Stg_Component_Build( posVariable, NULL, False );
+   Stg_Component_Destroy( fileParticleLayout, NULL, False );
+   Stg_Component_Destroy( posVariableNew, NULL, False );
+   Stg_Component_Destroy( newSwarm, NULL, False );
+
+   Stg_Class_Delete( posVariable );
+   Stg_Class_Delete( fileParticleLayout );
+   Stg_Class_Delete( posVariableNew );
+   Stg_Class_Delete( newSwarm );
+   stgMainDestroy( cf );
+
+}
+
+void SwarmDumpAndLoadSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, SwarmDumpAndLoadSuiteData );
+   pcu_suite_setFixtures( suite, SwarmDumpAndLoadSuite_Setup, SwarmDumpAndLoadSuite_Teardown );
+   pcu_suite_addTest( suite, SwarmDumpAndLoadSuite_TestSwarmDumpAndLoad );
+}
+
+void SwarmDumpAndLoadSuite_UpdateParticlePositionsTowardsAttractor( DomainContext* context ) {
+   Cell_LocalIndex         lCell_I;
+   Particle_InCellIndex    cParticle_I;
+   Particle*               currParticle;
+   Index                   dim_I;
+   Mesh*                   mesh = (Mesh*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"mesh-linear" );
+   Swarm*                  swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+   Coord                   attractorPoint;
+   double                  minCrds[3], maxCrds[3];
+
+   Mesh_GetGlobalCoordRange( mesh, minCrds, maxCrds );
+
+   for ( dim_I=0; dim_I < 3; dim_I++ ) 
+      attractorPoint[dim_I] = ( maxCrds[dim_I] - minCrds[dim_I] ) / 3;
+
+   for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
+      for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+         Coord movementVector = {0,0,0};
+         Coord newParticleCoord = {0,0,0};
+         Coord* oldCoord;
+         
+         currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+         oldCoord = &currParticle->xi;
+         
+         for ( dim_I=0; dim_I < 3; dim_I++ ) {
+            movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) / 3;
+            newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+         }
+
+         for ( dim_I=0; dim_I < 3; dim_I++ ) {
+            currParticle->xi[dim_I] = newParticleCoord[dim_I];
+         }
+      }
+   }
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SwarmOutputSuite.c
--- a/Swarm/tests/SwarmOutputSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**	Tests that particles can be saved to file, then re-loaded onto a new context with exactly
-**	the same positions and values.
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SwarmOutputSuite.h"
-
-#define CURR_MODULE_NAME "SwarmOutputSuite"
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} SwarmOutputSuiteData;
-
-double SwarmOutputSuite_Dt( void* context ) {
-	return 2.0;
-}
-
-void _SwarmOutputSuite_SetDt( void* context, double dt ) {
-}
-
-void SwarmOutputSuite_MoveParticles( DomainContext* context ) {
-	Swarm*				swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	Particle_Index		lParticle_I;
-	GlobalParticle*	particle;
-	double				x,y;
-
-	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-
-		x = particle->coord[ I_AXIS ];
-		y = particle->coord[ J_AXIS ];
-		particle->coord[ I_AXIS ] = 1.0 - y;
-		particle->coord[ J_AXIS ] = x;
-	}
-
-	Swarm_UpdateAllParticleOwners( swarm );
-}
-
-void SwarmOutputSuite_Setup( SwarmOutputSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void SwarmOutputSuite_Teardown( SwarmOutputSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void SwarmOutputSuite_TestSwarmOutput( SwarmOutputSuiteData* data ) {
-	int procToWatch = data->nProcs > 1 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		Dictionary*					dictionary;
-		Dictionary*					componentDict;
-		Stg_ComponentFactory*	cf;
-		DomainContext*				context;
-		char							input_file[PCU_PATH_MAX];
-		Swarm*						swarm;
-		SwarmOutput*				swarmOutput;
-		SpaceFillerParticleLayout* particleLayout;
-
-		pcu_filename_input( "testSwarmOutput.xml", input_file );
-		cf = stgMainInitFromXML( input_file, data->comm, NULL );
-		context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
-		dictionary = context->dictionary;
-
-		Journal_ReadFromDictionary( dictionary );
-		stgMainBuildAndInitialise( cf  );
-
-		ContextEP_Append( context, AbstractContext_EP_Dt, SwarmOutputSuite_Dt );
-		ContextEP_Append( context, AbstractContext_EP_Step, SwarmOutputSuite_MoveParticles );
-
-		componentDict = Dictionary_GetDictionary( dictionary, "components" );
-		assert( componentDict );
-
-		AbstractContext_Dump( context );
-		Stg_Component_Execute( context, 0, False );
-
-		particleLayout = (SpaceFillerParticleLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"particleLayout" );
-		swarmOutput = (SwarmOutput* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarmOutput" );
-		swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );
-
-		pcu_check_true( particleLayout->isConstructed && particleLayout->isBuilt && particleLayout->isInitialised );
-		pcu_check_true( swarmOutput->isConstructed && swarmOutput->isBuilt && swarmOutput->isInitialised );
-		pcu_check_true( swarm->isConstructed && swarm->isBuilt && swarm->isInitialised  );
-
-		pcu_check_streq( swarm->name, swarmOutput->swarm->name );
-
-		stgMainDestroy( cf );
-	}
-}
-
-void SwarmOutputSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, SwarmOutputSuiteData );
-	pcu_suite_setFixtures( suite, SwarmOutputSuite_Setup, SwarmOutputSuite_Teardown );
-	pcu_suite_addTest( suite, SwarmOutputSuite_TestSwarmOutput );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SwarmOutputSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SwarmOutputSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,144 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**	Tests that particles can be saved to file, then re-loaded onto a new context with exactly
+**	the same positions and values.
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SwarmOutputSuite.h"
+
+#define CURR_MODULE_NAME "SwarmOutputSuite"
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} SwarmOutputSuiteData;
+
+double SwarmOutputSuite_Dt( void* context ) {
+	return 2.0;
+}
+
+void _SwarmOutputSuite_SetDt( void* context, double dt ) {
+}
+
+void SwarmOutputSuite_MoveParticles( DomainContext* context ) {
+	Swarm*				swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	Particle_Index		lParticle_I;
+	GlobalParticle*	particle;
+	double				x,y;
+
+	for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+
+		x = particle->coord[ I_AXIS ];
+		y = particle->coord[ J_AXIS ];
+		particle->coord[ I_AXIS ] = 1.0 - y;
+		particle->coord[ J_AXIS ] = x;
+	}
+
+	Swarm_UpdateAllParticleOwners( swarm );
+}
+
+void SwarmOutputSuite_Setup( SwarmOutputSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void SwarmOutputSuite_Teardown( SwarmOutputSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void SwarmOutputSuite_TestSwarmOutput( SwarmOutputSuiteData* data ) {
+	int procToWatch = data->nProcs > 1 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		Dictionary*					dictionary;
+		Dictionary*					componentDict;
+		Stg_ComponentFactory*	cf;
+		DomainContext*				context;
+		char							input_file[PCU_PATH_MAX];
+		Swarm*						swarm;
+		SwarmOutput*				swarmOutput;
+		SpaceFillerParticleLayout* particleLayout;
+
+		pcu_filename_input( "testSwarmOutput.xml", input_file );
+		cf = stgMainInitFromXML( input_file, data->comm, NULL );
+		context = (DomainContext*) LiveComponentRegister_Get( cf->LCRegister, (Name)"context" );
+		dictionary = context->dictionary;
+
+		Journal_ReadFromDictionary( dictionary );
+		stgMainBuildAndInitialise( cf  );
+
+		ContextEP_Append( context, AbstractContext_EP_Dt, SwarmOutputSuite_Dt );
+		ContextEP_Append( context, AbstractContext_EP_Step, SwarmOutputSuite_MoveParticles );
+
+		componentDict = Dictionary_GetDictionary( dictionary, "components" );
+		assert( componentDict );
+
+		AbstractContext_Dump( context );
+		Stg_Component_Execute( context, 0, False );
+
+		particleLayout = (SpaceFillerParticleLayout*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"particleLayout" );
+		swarmOutput = (SwarmOutput* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarmOutput" );
+		swarm = (Swarm* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm" );
+
+		pcu_check_true( particleLayout->isConstructed && particleLayout->isBuilt && particleLayout->isInitialised );
+		pcu_check_true( swarmOutput->isConstructed && swarmOutput->isBuilt && swarmOutput->isInitialised );
+		pcu_check_true( swarm->isConstructed && swarm->isBuilt && swarm->isInitialised  );
+
+		pcu_check_streq( swarm->name, swarmOutput->swarm->name );
+
+		stgMainDestroy( cf );
+	}
+}
+
+void SwarmOutputSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, SwarmOutputSuiteData );
+	pcu_suite_setFixtures( suite, SwarmOutputSuite_Setup, SwarmOutputSuite_Teardown );
+	pcu_suite_addTest( suite, SwarmOutputSuite_TestSwarmOutput );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SwarmSuite.c
--- a/Swarm/tests/SwarmSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,211 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the SwarmSuite
-**
-** $Id: testSwarm.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SwarmSuite.h"
-
-struct _Particle {
-	__GlobalParticle
-};
-
-typedef struct {
-	unsigned							nDims;
-	unsigned							meshSize[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	ExtensionManager_Register*	extensionMgr_Register;
-	Mesh*								mesh;
-	ElementCellLayout*			elementCellLayout;
-	RandomParticleLayout*		randomParticleLayout;
-	Swarm*							swarm;
-	MPI_Comm							comm;
-	int								rank;
-	int								nProcs;
-} SwarmSuiteData;
-
-Mesh* SwarmSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-	MeshGenerator_SetIncidenceState( gen, nDims, nDims, True );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-Bool SwarmSuite_TestParticleSearchFunc( Swarm* swarm, Coord coord, Stream* stream ) {
-	double				distance;
-	Particle_Index		closestParticle_I;
-	Particle_Index		lParticle_I;
-	GlobalParticle*	particle;
-
-	Journal_Printf( stream, "Testing coord %g %g %g\n", coord[ I_AXIS ], coord[ J_AXIS ], coord[ K_AXIS ] );
-
-	closestParticle_I = Swarm_FindClosestParticle( swarm, 3, coord, &distance );
-
-	if ( closestParticle_I < swarm->particleLocalCount ) {
-		Journal_Printf( stream, "Closest Particle is %u with distance %g\n", closestParticle_I, distance );
-
-		for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
-			/* don't bother with testing same particle */
-			if (lParticle_I == closestParticle_I)
-				continue;
-
-			particle = (GlobalParticle*)Swarm_ParticleAt( swarm , lParticle_I );
-
-			/* Test if particle is closer */
-			if (distance > StGermain_DistanceBetweenPoints( coord, particle->coord, 3 ) ) {
-				Journal_Printf( stream, "Particle %u is closer to coord and has distance %g.\n" , 
-						lParticle_I, StGermain_DistanceBetweenPoints( coord, particle->coord, 3 ) );
-
-				return False;
-			}
-		}
-	}
-	else
-		Journal_Printf( stream, "Coord not found on this processor.\n" );
- 
-	return True;
-}
-	
-void SwarmSuite_Setup( SwarmSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-
-	data->nDims = 3;
-	data->meshSize[0] = 2; data->meshSize[1] =  3; data->meshSize[2] = 2;
-	data->minCrds[0] = 0.0; data->minCrds[1] = 0.0; data->minCrds[2] = 0.0;
-	data->maxCrds[0] = 300.0; data->maxCrds[1] = 12.0; data->maxCrds[2] = 300.0;
-
-	/* Init mesh */
-	data->extensionMgr_Register = ExtensionManager_Register_New();
-	data->mesh = SwarmSuite_BuildMesh( data->nDims, data->meshSize, data->minCrds, data->maxCrds, data->extensionMgr_Register );
-	
-	/* Configure the random-particle-layout */
-	data->randomParticleLayout = RandomParticleLayout_New( "randomParticleCellLayout", NULL, GlobalCoordSystem, False, 4, 13 );
-	
-	/* Configure the element-cell-layout */
-	data->elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, data->mesh );
-	
-	/* Configure the swarm */
-	data->swarm = Swarm_New( "testSwarm", NULL, data->elementCellLayout, data->randomParticleLayout, 3, sizeof(Particle),
-		data->extensionMgr_Register, NULL, MPI_COMM_WORLD, NULL );
-	
-	/* Build the swarm */
-	Stg_Component_Build( data->swarm, 0, False );
-	Stg_Component_Initialise( data->swarm, 0, False );
-}
-
-void SwarmSuite_Teardown( SwarmSuiteData* data ) {
-	/* Destroy stuff */
-	_Stg_Component_Delete( data->swarm );
-	_Stg_Component_Delete( data->randomParticleLayout );
-	_Stg_Component_Delete( data->elementCellLayout );
-	Stg_Class_Delete( data->extensionMgr_Register );
-
-	Journal_Enable_AllTypedStream( True );
-}
-
-void SwarmSuite_TestParticleSearch( SwarmSuiteData* data ) {
-	double	coord[3];
-	int		procToWatch = data->nProcs > 1 ? 1 : 0;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"TestParticleSearch");
-	
-	if( data->rank == procToWatch ) {
-		if( data->nProcs == 1 ) {
-			coord[0] = 0.60*( data->maxCrds[0] - data->minCrds[0] );
-			coord[1] = 0.20*( data->maxCrds[1] - data->minCrds[1] );
-			coord[2] = 0.82*( data->maxCrds[2] - data->minCrds[2]  );
-			pcu_check_true( SwarmSuite_TestParticleSearchFunc( data->swarm, coord, stream ) );
-		
-			coord[0] = 0.20*( data->maxCrds[0] - data->minCrds[0] );
-			coord[1] = 0.90*( data->maxCrds[1] - data->minCrds[1] );
-			coord[2] = 0.12*( data->maxCrds[2] - data->minCrds[2] );
-			pcu_check_true( SwarmSuite_TestParticleSearchFunc( data->swarm, coord, stream ) );
-		}	
-	}
-}
-
-void SwarmSuite_TestParticleCoords( SwarmSuiteData* data ) {
-	char		expected_file[PCU_PATH_MAX];
-	int		procToWatch = data->nProcs > 1 ? 1 : 0;
-	Stream*	stream; 
-
-	if( data->rank == procToWatch ) {
-		Journal_Enable_AllTypedStream( True );
-		stream = Journal_Register( Info_Type, (Name)"TestParticleCorrds" ); 
-		Stream_RedirectFile( stream, "testParticleCoords.dat" );
-		Swarm_PrintParticleCoords( data->swarm, stream );
-		Journal_Printf( stream, "\n" );
-		Swarm_PrintParticleCoords_ByCell( data->swarm, stream );
-		Journal_Enable_AllTypedStream( False );	
-		pcu_filename_expected( "testSwarmOutput.expected", expected_file );
-		pcu_check_fileEq( "testParticleCoords.dat", expected_file );
-		remove( "testParticleCoords.dat" );
-	}
-}
-
-void SwarmSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, SwarmSuiteData );
-	pcu_suite_setFixtures( suite, SwarmSuite_Setup, SwarmSuite_Teardown );
-	pcu_suite_addTest( suite, SwarmSuite_TestParticleSearch );
-	pcu_suite_addTest( suite, SwarmSuite_TestParticleCoords );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/SwarmSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/SwarmSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,211 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the SwarmSuite
+**
+** $Id: testSwarm.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SwarmSuite.h"
+
+struct _Particle {
+	__GlobalParticle
+};
+
+typedef struct {
+	unsigned							nDims;
+	unsigned							meshSize[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	ExtensionManager_Register*	extensionMgr_Register;
+	Mesh*								mesh;
+	ElementCellLayout*			elementCellLayout;
+	RandomParticleLayout*		randomParticleLayout;
+	Swarm*							swarm;
+	MPI_Comm							comm;
+	int								rank;
+	int								nProcs;
+} SwarmSuiteData;
+
+Mesh* SwarmSuite_BuildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+	MeshGenerator_SetIncidenceState( gen, nDims, nDims, True );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+Bool SwarmSuite_TestParticleSearchFunc( Swarm* swarm, Coord coord, Stream* stream ) {
+	double				distance;
+	Particle_Index		closestParticle_I;
+	Particle_Index		lParticle_I;
+	GlobalParticle*	particle;
+
+	Journal_Printf( stream, "Testing coord %g %g %g\n", coord[ I_AXIS ], coord[ J_AXIS ], coord[ K_AXIS ] );
+
+	closestParticle_I = Swarm_FindClosestParticle( swarm, 3, coord, &distance );
+
+	if ( closestParticle_I < swarm->particleLocalCount ) {
+		Journal_Printf( stream, "Closest Particle is %u with distance %g\n", closestParticle_I, distance );
+
+		for ( lParticle_I = 0 ; lParticle_I < swarm->particleLocalCount ; lParticle_I++ ) {
+			/* don't bother with testing same particle */
+			if (lParticle_I == closestParticle_I)
+				continue;
+
+			particle = (GlobalParticle*)Swarm_ParticleAt( swarm , lParticle_I );
+
+			/* Test if particle is closer */
+			if (distance > StGermain_DistanceBetweenPoints( coord, particle->coord, 3 ) ) {
+				Journal_Printf( stream, "Particle %u is closer to coord and has distance %g.\n" , 
+						lParticle_I, StGermain_DistanceBetweenPoints( coord, particle->coord, 3 ) );
+
+				return False;
+			}
+		}
+	}
+	else
+		Journal_Printf( stream, "Coord not found on this processor.\n" );
+ 
+	return True;
+}
+	
+void SwarmSuite_Setup( SwarmSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+
+	data->nDims = 3;
+	data->meshSize[0] = 2; data->meshSize[1] =  3; data->meshSize[2] = 2;
+	data->minCrds[0] = 0.0; data->minCrds[1] = 0.0; data->minCrds[2] = 0.0;
+	data->maxCrds[0] = 300.0; data->maxCrds[1] = 12.0; data->maxCrds[2] = 300.0;
+
+	/* Init mesh */
+	data->extensionMgr_Register = ExtensionManager_Register_New();
+	data->mesh = SwarmSuite_BuildMesh( data->nDims, data->meshSize, data->minCrds, data->maxCrds, data->extensionMgr_Register );
+	
+	/* Configure the random-particle-layout */
+	data->randomParticleLayout = RandomParticleLayout_New( "randomParticleCellLayout", NULL, GlobalCoordSystem, False, 4, 13 );
+	
+	/* Configure the element-cell-layout */
+	data->elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, data->mesh );
+	
+	/* Configure the swarm */
+	data->swarm = Swarm_New( "testSwarm", NULL, data->elementCellLayout, data->randomParticleLayout, 3, sizeof(Particle),
+		data->extensionMgr_Register, NULL, MPI_COMM_WORLD, NULL );
+	
+	/* Build the swarm */
+	Stg_Component_Build( data->swarm, 0, False );
+	Stg_Component_Initialise( data->swarm, 0, False );
+}
+
+void SwarmSuite_Teardown( SwarmSuiteData* data ) {
+	/* Destroy stuff */
+	_Stg_Component_Delete( data->swarm );
+	_Stg_Component_Delete( data->randomParticleLayout );
+	_Stg_Component_Delete( data->elementCellLayout );
+	Stg_Class_Delete( data->extensionMgr_Register );
+
+	Journal_Enable_AllTypedStream( True );
+}
+
+void SwarmSuite_TestParticleSearch( SwarmSuiteData* data ) {
+	double	coord[3];
+	int		procToWatch = data->nProcs > 1 ? 1 : 0;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"TestParticleSearch");
+	
+	if( data->rank == procToWatch ) {
+		if( data->nProcs == 1 ) {
+			coord[0] = 0.60*( data->maxCrds[0] - data->minCrds[0] );
+			coord[1] = 0.20*( data->maxCrds[1] - data->minCrds[1] );
+			coord[2] = 0.82*( data->maxCrds[2] - data->minCrds[2]  );
+			pcu_check_true( SwarmSuite_TestParticleSearchFunc( data->swarm, coord, stream ) );
+		
+			coord[0] = 0.20*( data->maxCrds[0] - data->minCrds[0] );
+			coord[1] = 0.90*( data->maxCrds[1] - data->minCrds[1] );
+			coord[2] = 0.12*( data->maxCrds[2] - data->minCrds[2] );
+			pcu_check_true( SwarmSuite_TestParticleSearchFunc( data->swarm, coord, stream ) );
+		}	
+	}
+}
+
+void SwarmSuite_TestParticleCoords( SwarmSuiteData* data ) {
+	char		expected_file[PCU_PATH_MAX];
+	int		procToWatch = data->nProcs > 1 ? 1 : 0;
+	Stream*	stream; 
+
+	if( data->rank == procToWatch ) {
+		Journal_Enable_AllTypedStream( True );
+		stream = Journal_Register( Info_Type, (Name)"TestParticleCorrds" ); 
+		Stream_RedirectFile( stream, "testParticleCoords.dat" );
+		Swarm_PrintParticleCoords( data->swarm, stream );
+		Journal_Printf( stream, "\n" );
+		Swarm_PrintParticleCoords_ByCell( data->swarm, stream );
+		Journal_Enable_AllTypedStream( False );	
+		pcu_filename_expected( "testSwarmOutput.expected", expected_file );
+		pcu_check_fileEq( "testParticleCoords.dat", expected_file );
+		remove( "testParticleCoords.dat" );
+	}
+}
+
+void SwarmSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, SwarmSuiteData );
+	pcu_suite_setFixtures( suite, SwarmSuite_Setup, SwarmSuite_Teardown );
+	pcu_suite_addTest( suite, SwarmSuite_TestParticleSearch );
+	pcu_suite_addTest( suite, SwarmSuite_TestParticleCoords );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/VaryingCornerAttractors/VaryingCornerAttractors.c
--- a/Swarm/tests/VaryingCornerAttractors/VaryingCornerAttractors.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,162 +0,0 @@
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include <StgDomain/Swarm/Swarm.h>
-
-#include <assert.h>
-#include <string.h>
-
-const Type StGermain_VaryingCornerAttractors_Type = "StGermain_VaryingCornerAttractors";
-
-typedef struct {
-	__Codelet
-} StGermain_VaryingCornerAttractors;
-
-struct _Particle {
-	__GlobalParticle
-	double  velocity[3];
-	double  randomColour;
-};
-
-void StGermain_VaryingCornerAttractors_UpdatePositions( DomainContext* context ) {
-	Cell_LocalIndex			lCell_I;
-	Particle_InCellIndex		cParticle_I;
-	Particle* 	        	currParticle;
-	Index				dim_I;
-	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
-	Coord                           attractorPoint;
-	BlockGeometry*                  blockGeometry;
-	Stream*                         stream = Journal_Register( Debug_Type, (Name)"particleUpdate" );
-	unsigned int                    movementSpeedDivisor = 10;
-	int                             movementSign = 1;
-	unsigned int                    cornerPeriod = 10;
-	unsigned int                    numCorners = (swarm->dim-1 )*4;
-	unsigned int                    explosionPeriod = numCorners*cornerPeriod;
-	Coord                           cornerCoords[8];
-	int                             modValue = 0;
-	int                             cornerIndex = 0;
-
-	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
-	
-	blockGeometry = (BlockGeometry*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"geometry" );
-
-		/* Bottom left corner */
-	cornerCoords[0][I_AXIS] = blockGeometry->min[I_AXIS];
-	cornerCoords[0][J_AXIS] = blockGeometry->min[J_AXIS];
-	cornerCoords[0][K_AXIS] = blockGeometry->min[K_AXIS];
-	/* Bottom right corner */
-	cornerCoords[1][I_AXIS] = blockGeometry->max[I_AXIS];
-	cornerCoords[1][J_AXIS] = blockGeometry->min[J_AXIS];
-	cornerCoords[1][K_AXIS] = blockGeometry->min[K_AXIS];
-	/* Top right corner */
-	cornerCoords[2][I_AXIS] = blockGeometry->max[I_AXIS];
-	cornerCoords[2][J_AXIS] = blockGeometry->max[J_AXIS];
-	cornerCoords[2][K_AXIS] = blockGeometry->min[K_AXIS];
-	/* Top left corner */
-	cornerCoords[3][I_AXIS] = blockGeometry->min[I_AXIS];
-	cornerCoords[3][J_AXIS] = blockGeometry->max[J_AXIS];
-	cornerCoords[3][K_AXIS] = blockGeometry->min[K_AXIS];
-	/* Bottom left corner */
-	cornerCoords[4][I_AXIS] = blockGeometry->min[I_AXIS];
-	cornerCoords[4][J_AXIS] = blockGeometry->max[J_AXIS];
-	cornerCoords[4][K_AXIS] = blockGeometry->max[K_AXIS];
-	/* Bottom right corner */
-	cornerCoords[5][I_AXIS] = blockGeometry->min[I_AXIS];
-	cornerCoords[5][J_AXIS] = blockGeometry->min[J_AXIS];
-	cornerCoords[5][K_AXIS] = blockGeometry->max[K_AXIS];
-	/* Top right corner */
-	cornerCoords[6][I_AXIS] = blockGeometry->max[I_AXIS];
-	cornerCoords[6][J_AXIS] = blockGeometry->min[J_AXIS];
-	cornerCoords[6][K_AXIS] = blockGeometry->max[K_AXIS];
-	/* Top left corner */
-	cornerCoords[7][I_AXIS] = blockGeometry->max[I_AXIS];
-	cornerCoords[7][J_AXIS] = blockGeometry->max[J_AXIS];
-	cornerCoords[7][K_AXIS] = blockGeometry->max[K_AXIS];
-
-	/* calculate which corner */
-	modValue = (context->timeStep - 1) % (numCorners * cornerPeriod );
-	cornerIndex = modValue / cornerPeriod;
-	memcpy( attractorPoint, cornerCoords[cornerIndex], 3 * sizeof(double) );
-	Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] );
-	
-	/* Can't really explode in this test as particles go out of box */
-	#if 0
-	/* Now decide if we are attracting or repelling */
-	if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) {
-		Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep );
-		movementSign = 1;
-	}
-	else {
-		Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep );
-		movementSign = -1;
-	}	
-	#endif
-
-	
-	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
-		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
-		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-			Coord movementVector = {0,0,0};
-			Coord newParticleCoord = {0,0,0};
-			Coord* oldCoord;
-
-			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			oldCoord = &currParticle->coord;
-			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) /
-					movementSpeedDivisor;
-				movementVector[dim_I] *= movementSign;	
-				if ( movementSign == -1 ) {
-					movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); 
-				}
-				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-			}
-			memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); 
-
-			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
-				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
-				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
-
-			for ( dim_I=0; dim_I < 3; dim_I++ ) {
-				currParticle->coord[dim_I] = newParticleCoord[dim_I];
-			}
-		}
-	}
-
-	Swarm_UpdateAllParticleOwners( swarm );
-}
-
-
-void _StGermain_VaryingCornerAttractors_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	DomainContext*   context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-	
-	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_VaryingCornerAttractors_UpdatePositions );
-}
-
-
-void* _StGermain_VaryingCornerAttractors_DefaultNew( Name name ) {
-	return Codelet_New(
-			StGermain_VaryingCornerAttractors_Type,
-			_StGermain_VaryingCornerAttractors_DefaultNew,
-			_StGermain_VaryingCornerAttractors_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-	}
-
-Index StGermain_VaryingCornerAttractors_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, StGermain_VaryingCornerAttractors_Type, (Name)"0", _StGermain_VaryingCornerAttractors_DefaultNew  );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/VaryingCornerAttractors/VaryingCornerAttractors.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/VaryingCornerAttractors/VaryingCornerAttractors.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,162 @@
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include <StgDomain/Swarm/Swarm.h>
+
+#include <assert.h>
+#include <string.h>
+
+const Type StGermain_VaryingCornerAttractors_Type = "StGermain_VaryingCornerAttractors";
+
+typedef struct {
+	__Codelet
+} StGermain_VaryingCornerAttractors;
+
+struct _Particle {
+	__GlobalParticle
+	double  velocity[3];
+	double  randomColour;
+};
+
+void StGermain_VaryingCornerAttractors_UpdatePositions( DomainContext* context ) {
+	Cell_LocalIndex			lCell_I;
+	Particle_InCellIndex		cParticle_I;
+	Particle* 	        	currParticle;
+	Index				dim_I;
+	Swarm*                          swarm = (Swarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"swarm"  );
+	Coord                           attractorPoint;
+	BlockGeometry*                  blockGeometry;
+	Stream*                         stream = Journal_Register( Debug_Type, (Name)"particleUpdate" );
+	unsigned int                    movementSpeedDivisor = 10;
+	int                             movementSign = 1;
+	unsigned int                    cornerPeriod = 10;
+	unsigned int                    numCorners = (swarm->dim-1 )*4;
+	unsigned int                    explosionPeriod = numCorners*cornerPeriod;
+	Coord                           cornerCoords[8];
+	int                             modValue = 0;
+	int                             cornerIndex = 0;
+
+	Stream_SetPrintingRank( stream, Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "procToWatch", 0 ) );
+	
+	blockGeometry = (BlockGeometry*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"geometry" );
+
+		/* Bottom left corner */
+	cornerCoords[0][I_AXIS] = blockGeometry->min[I_AXIS];
+	cornerCoords[0][J_AXIS] = blockGeometry->min[J_AXIS];
+	cornerCoords[0][K_AXIS] = blockGeometry->min[K_AXIS];
+	/* Bottom right corner */
+	cornerCoords[1][I_AXIS] = blockGeometry->max[I_AXIS];
+	cornerCoords[1][J_AXIS] = blockGeometry->min[J_AXIS];
+	cornerCoords[1][K_AXIS] = blockGeometry->min[K_AXIS];
+	/* Top right corner */
+	cornerCoords[2][I_AXIS] = blockGeometry->max[I_AXIS];
+	cornerCoords[2][J_AXIS] = blockGeometry->max[J_AXIS];
+	cornerCoords[2][K_AXIS] = blockGeometry->min[K_AXIS];
+	/* Top left corner */
+	cornerCoords[3][I_AXIS] = blockGeometry->min[I_AXIS];
+	cornerCoords[3][J_AXIS] = blockGeometry->max[J_AXIS];
+	cornerCoords[3][K_AXIS] = blockGeometry->min[K_AXIS];
+	/* Bottom left corner */
+	cornerCoords[4][I_AXIS] = blockGeometry->min[I_AXIS];
+	cornerCoords[4][J_AXIS] = blockGeometry->max[J_AXIS];
+	cornerCoords[4][K_AXIS] = blockGeometry->max[K_AXIS];
+	/* Bottom right corner */
+	cornerCoords[5][I_AXIS] = blockGeometry->min[I_AXIS];
+	cornerCoords[5][J_AXIS] = blockGeometry->min[J_AXIS];
+	cornerCoords[5][K_AXIS] = blockGeometry->max[K_AXIS];
+	/* Top right corner */
+	cornerCoords[6][I_AXIS] = blockGeometry->max[I_AXIS];
+	cornerCoords[6][J_AXIS] = blockGeometry->min[J_AXIS];
+	cornerCoords[6][K_AXIS] = blockGeometry->max[K_AXIS];
+	/* Top left corner */
+	cornerCoords[7][I_AXIS] = blockGeometry->max[I_AXIS];
+	cornerCoords[7][J_AXIS] = blockGeometry->max[J_AXIS];
+	cornerCoords[7][K_AXIS] = blockGeometry->max[K_AXIS];
+
+	/* calculate which corner */
+	modValue = (context->timeStep - 1) % (numCorners * cornerPeriod );
+	cornerIndex = modValue / cornerPeriod;
+	memcpy( attractorPoint, cornerCoords[cornerIndex], 3 * sizeof(double) );
+	Journal_Printf( stream, "Calculated attractor point is at (%f,%f,%f):\n", attractorPoint[0], attractorPoint[1], attractorPoint[2] );
+	
+	/* Can't really explode in this test as particles go out of box */
+	#if 0
+	/* Now decide if we are attracting or repelling */
+	if ( ( ( (context->timeStep - 1) / explosionPeriod ) % 2 ) == 0 ) {
+		Journal_Printf( stream, "Timestep %d - Implosive mode\n", context->timeStep );
+		movementSign = 1;
+	}
+	else {
+		Journal_Printf( stream, "Timestep %d - Explosive mode\n", context->timeStep );
+		movementSign = -1;
+	}	
+	#endif
+
+	
+	for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++ ) {
+		Journal_Printf( stream, "\tUpdating Particles positions in local cell %d:\n", lCell_I );
+		for ( cParticle_I=0; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+			Coord movementVector = {0,0,0};
+			Coord newParticleCoord = {0,0,0};
+			Coord* oldCoord;
+
+			currParticle = (Particle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			oldCoord = &currParticle->coord;
+			Journal_Printf( stream, "\t\tUpdating particleInCell %d:\n", cParticle_I );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				movementVector[dim_I] = ( attractorPoint[dim_I] - (*oldCoord)[dim_I] ) /
+					movementSpeedDivisor;
+				movementVector[dim_I] *= movementSign;	
+				if ( movementSign == -1 ) {
+					movementVector[dim_I] *= (float)movementSpeedDivisor / (movementSpeedDivisor-1); 
+				}
+				newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+			}
+			memcpy( currParticle->velocity, movementVector, 3*sizeof(double) ); 
+
+			Journal_Printf( stream, "\t\tChanging its coords from (%f,%f,%f) to (%f,%f,%f):\n",
+				(*oldCoord)[0], (*oldCoord)[1], (*oldCoord)[2],
+				newParticleCoord[0], newParticleCoord[1], newParticleCoord[2] );
+
+			for ( dim_I=0; dim_I < 3; dim_I++ ) {
+				currParticle->coord[dim_I] = newParticleCoord[dim_I];
+			}
+		}
+	}
+
+	Swarm_UpdateAllParticleOwners( swarm );
+}
+
+
+void _StGermain_VaryingCornerAttractors_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	DomainContext*   context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+	
+	ContextEP_ReplaceAll( context, AbstractContext_EP_Solve, StGermain_VaryingCornerAttractors_UpdatePositions );
+}
+
+
+void* _StGermain_VaryingCornerAttractors_DefaultNew( Name name ) {
+	return Codelet_New(
+			StGermain_VaryingCornerAttractors_Type,
+			_StGermain_VaryingCornerAttractors_DefaultNew,
+			_StGermain_VaryingCornerAttractors_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+	}
+
+Index StGermain_VaryingCornerAttractors_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, StGermain_VaryingCornerAttractors_Type, (Name)"0", _StGermain_VaryingCornerAttractors_DefaultNew  );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/WithinShapeParticleLayoutSuite.c
--- a/Swarm/tests/WithinShapeParticleLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,168 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the WithinShapeParticleLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <mpi.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h"
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "WithinShapeParticleLayoutSuite.h"
-
-struct _Particle {
-	__GlobalParticle
-};
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} WithinShapeParticleLayoutSuiteData;
-
-Mesh* WithinShapeParticleLayoutSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-
-void WithinShapeParticleLayoutSuite_Setup( WithinShapeParticleLayoutSuiteData* data ) {
-	/* MPI Initializations */	
-	data->comm = MPI_COMM_WORLD;  
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-
-}
-
-void WithinShapeParticleLayoutSuite_Teardown( WithinShapeParticleLayoutSuiteData* data ) {
-}
-
-void WithinShapeParticleLayoutSuite_TestWithinShapeSphere( WithinShapeParticleLayoutSuiteData* data ) {
-	ExtensionManager_Register*	extensionMgr_Register;
-	WithinShapeParticleLayout*	particleLayout;
-	ElementCellLayout*			elementCellLayout;
-	Mesh*								mesh;
-	Swarm*							swarm;
-	unsigned							nDims;
-	unsigned							meshSize[3];
-	double							minCrds[3];
-	double							maxCrds[3];
-	XYZ								centre;
-	Stg_Shape*						shape;
-	int								procToWatch;
-	int								particleCount = 10;
-
-	procToWatch = data->nProcs > 1 ? 1 : 0;	
-
-	if( data->rank == procToWatch ) {
-		nDims = 3;
-		meshSize[0] = 5; meshSize[1] = 3; meshSize[2] = 2;
-		minCrds[0] = 0; minCrds[1] = 0; minCrds[2] = 0;
-		maxCrds[0] = 1; maxCrds[1] = 1; maxCrds[2] = 1;	
-
-		/* Init mesh */
-		extensionMgr_Register = ExtensionManager_Register_New();
-		mesh = WithinShapeParticleLayoutSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-
-		/* Configure the element-cell-layout */
-		elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, mesh );
-
-		/* Build the mesh */
-		Stg_Component_Build( mesh, 0, False );
-		Stg_Component_Initialise( mesh, 0, False );	
-
-		centre[I_AXIS] = centre[J_AXIS] = centre[K_AXIS] = 0.5;
-		shape = (Stg_Shape*)Sphere_New( "testSphere", nDims, centre, 0, 0, 0, 0.05 );
-
-		/* Configure the gauss-particle-layout */
-		particleLayout = WithinShapeParticleLayout_New( "withinShapeParticleLayoutSphere", NULL, 
-			GlobalCoordSystem, False, particleCount, 0.0, nDims, shape );
-
-		/* Configure the swarm */
-		swarm = Swarm_New( "testSwarm", NULL, elementCellLayout, particleLayout, nDims, sizeof(Particle),
-		extensionMgr_Register, NULL, data->comm, NULL );
-	
-		/* Build the swarm */
-		Stg_Component_Build( swarm, 0, False );
-		Stg_Component_Initialise( swarm, 0, False );
-
-		pcu_check_true( swarm->cellDomainCount == 30 );
-		pcu_check_true( swarm->cellLocalCount == 30 );
-		pcu_check_true( swarm->particleLocalCount == 10 );
-		pcu_check_true( swarm->particles[0].owningCell );
-		pcu_check_true( swarm->particles[1].owningCell );
-		pcu_check_true( swarm->particles[3].owningCell );
-		pcu_check_true( swarm->particles[4].owningCell );
-		pcu_check_true( swarm->particles[7].owningCell );
-		pcu_check_true( swarm->particles[8].owningCell );
-		pcu_check_true( swarm->particles[2].owningCell );
-		pcu_check_true( swarm->particles[5].owningCell );
-		pcu_check_true( swarm->particles[6].owningCell );
-		pcu_check_true( swarm->particles[9].owningCell );
-
-		Stg_Class_Delete( extensionMgr_Register );
-		Stg_Component_Destroy( elementCellLayout, NULL, True );
-		Stg_Component_Destroy( particleLayout, NULL, True );
-		/*Stg_Component_Destroy( mesh, NULL, True );*/
-		Stg_Component_Destroy( swarm, NULL, True );	
-	}
-}
-
-void WithinShapeParticleLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, WithinShapeParticleLayoutSuiteData );
-	pcu_suite_setFixtures( suite, WithinShapeParticleLayoutSuite_Setup, WithinShapeParticleLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, WithinShapeParticleLayoutSuite_TestWithinShapeSphere );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Swarm/tests/WithinShapeParticleLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Swarm/tests/WithinShapeParticleLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,168 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the WithinShapeParticleLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h"
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "WithinShapeParticleLayoutSuite.h"
+
+struct _Particle {
+	__GlobalParticle
+};
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} WithinShapeParticleLayoutSuiteData;
+
+Mesh* WithinShapeParticleLayoutSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+
+void WithinShapeParticleLayoutSuite_Setup( WithinShapeParticleLayoutSuiteData* data ) {
+	/* MPI Initializations */	
+	data->comm = MPI_COMM_WORLD;  
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+
+}
+
+void WithinShapeParticleLayoutSuite_Teardown( WithinShapeParticleLayoutSuiteData* data ) {
+}
+
+void WithinShapeParticleLayoutSuite_TestWithinShapeSphere( WithinShapeParticleLayoutSuiteData* data ) {
+	ExtensionManager_Register*	extensionMgr_Register;
+	WithinShapeParticleLayout*	particleLayout;
+	ElementCellLayout*			elementCellLayout;
+	Mesh*								mesh;
+	Swarm*							swarm;
+	unsigned							nDims;
+	unsigned							meshSize[3];
+	double							minCrds[3];
+	double							maxCrds[3];
+	XYZ								centre;
+	Stg_Shape*						shape;
+	int								procToWatch;
+	int								particleCount = 10;
+
+	procToWatch = data->nProcs > 1 ? 1 : 0;	
+
+	if( data->rank == procToWatch ) {
+		nDims = 3;
+		meshSize[0] = 5; meshSize[1] = 3; meshSize[2] = 2;
+		minCrds[0] = 0; minCrds[1] = 0; minCrds[2] = 0;
+		maxCrds[0] = 1; maxCrds[1] = 1; maxCrds[2] = 1;	
+
+		/* Init mesh */
+		extensionMgr_Register = ExtensionManager_Register_New();
+		mesh = WithinShapeParticleLayoutSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+
+		/* Configure the element-cell-layout */
+		elementCellLayout = ElementCellLayout_New( "elementCellLayout", NULL, mesh );
+
+		/* Build the mesh */
+		Stg_Component_Build( mesh, 0, False );
+		Stg_Component_Initialise( mesh, 0, False );	
+
+		centre[I_AXIS] = centre[J_AXIS] = centre[K_AXIS] = 0.5;
+		shape = (Stg_Shape*)Sphere_New( "testSphere", nDims, centre, 0, 0, 0, 0.05 );
+
+		/* Configure the gauss-particle-layout */
+		particleLayout = WithinShapeParticleLayout_New( "withinShapeParticleLayoutSphere", NULL, 
+			GlobalCoordSystem, False, particleCount, 0.0, nDims, shape );
+
+		/* Configure the swarm */
+		swarm = Swarm_New( "testSwarm", NULL, elementCellLayout, particleLayout, nDims, sizeof(Particle),
+		extensionMgr_Register, NULL, data->comm, NULL );
+	
+		/* Build the swarm */
+		Stg_Component_Build( swarm, 0, False );
+		Stg_Component_Initialise( swarm, 0, False );
+
+		pcu_check_true( swarm->cellDomainCount == 30 );
+		pcu_check_true( swarm->cellLocalCount == 30 );
+		pcu_check_true( swarm->particleLocalCount == 10 );
+		pcu_check_true( swarm->particles[0].owningCell );
+		pcu_check_true( swarm->particles[1].owningCell );
+		pcu_check_true( swarm->particles[3].owningCell );
+		pcu_check_true( swarm->particles[4].owningCell );
+		pcu_check_true( swarm->particles[7].owningCell );
+		pcu_check_true( swarm->particles[8].owningCell );
+		pcu_check_true( swarm->particles[2].owningCell );
+		pcu_check_true( swarm->particles[5].owningCell );
+		pcu_check_true( swarm->particles[6].owningCell );
+		pcu_check_true( swarm->particles[9].owningCell );
+
+		Stg_Class_Delete( extensionMgr_Register );
+		Stg_Component_Destroy( elementCellLayout, NULL, True );
+		Stg_Component_Destroy( particleLayout, NULL, True );
+		/*Stg_Component_Destroy( mesh, NULL, True );*/
+		Stg_Component_Destroy( swarm, NULL, True );	
+	}
+}
+
+void WithinShapeParticleLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, WithinShapeParticleLayoutSuiteData );
+	pcu_suite_setFixtures( suite, WithinShapeParticleLayoutSuite_Setup, WithinShapeParticleLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, WithinShapeParticleLayoutSuite_TestWithinShapeSphere );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/AllElementsVC.c
--- a/Utils/src/AllElementsVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,470 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: AllElementsVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "AllElementsVC.h"
-#include "RegularMeshUtils.h"
-
-#include <string.h>
-#include <assert.h>
-
-
-const Type AllElementsVC_Type = "AllElementsVC";
-const Name defaultAllElementsVCName = "defaultAllElementsVCName";
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-VariableCondition* AllElementsVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									data )
-{
-	return (VariableCondition*)AllElementsVC_New( defaultAllElementsVCName, context, NULL, variable_Register, conFunc_Register, dictionary, data );
-}
-
-AllElementsVC*	AllElementsVC_New(
-	Name									name,
-	AbstractContext*					context,
-	Name									_dictionaryEntryName, 
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register,
-	Dictionary*							dictionary,
-	void*									mesh )
-{
-	AllElementsVC*	self = _AllElementsVC_DefaultNew( name );
-	
-	self->isConstructed = True;
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
-	_AllElementsVC_Init( self, _dictionaryEntryName, mesh );
-
-	return self;
-}
-
-AllElementsVC* _AllElementsVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(AllElementsVC);
-	Type                                                       type = AllElementsVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _AllElementsVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _AllElementsVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _AllElementsVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_AllElementsVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _AllElementsVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _AllElementsVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _AllElementsVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _AllElementsVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _AllElementsVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _AllElementsVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _AllElementsVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _AllElementsVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _AllElementsVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _AllElementsVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _AllElementsVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _AllElementsVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return _AllElementsVC_New(  ALLELEMENTSVC_PASSARGS  );
-}
-
-AllElementsVC* _AllElementsVC_New(  ALLELEMENTSVC_DEFARGS  ) {
-	AllElementsVC*	self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(AllElementsVC) );
-	self = (AllElementsVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	
-	return self;
-}
-
-
-void _AllElementsVC_Init( void* allElementsVC, Name _dictionaryEntryName, void* mesh ) {
-	AllElementsVC* self = (AllElementsVC*)allElementsVC;
-
-	self->_dictionaryEntryName = _dictionaryEntryName;
-	self->mesh = (Mesh*)mesh;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-void _AllElementsVC_AssignFromXML( void* allElementsVC, Stg_ComponentFactory *cf, void* data ) { 
-}
-
-void _AllElementsVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-	AllElementsVC*					self = (AllElementsVC*)variableCondition;
-	Dictionary_Entry_Value*		vcDictVal;
-	Dictionary_Entry_Value		_vcDictVal;
-	Dictionary_Entry_Value*		varsVal;
-	AllElementsVC_Entry_Index	entry_I;
-	
-	/* Find dictionary entry */
-	if (self->_dictionaryEntryName)
-		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName  );
-	else {
-		vcDictVal = &_vcDictVal;
-		Dictionary_Entry_Value_InitFromStruct( vcDictVal, dictionary );
-	}
-	
-	if (vcDictVal) {
-		/* Obtain the variable entries */
-		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-		self->_entryTbl = Memory_Alloc_Array( AllElementsVC_Entry, self->_entryCount, "AllElementsVC->_entryTbl" );
-		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
-			char*							valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-
-			if (0 == strcasecmp(valType, "func")) {
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-
-				if ( cfIndex == (unsigned)-1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-						"definition of allElementsVC \"%s\", the cond. func. applied to "
-						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-						__func__, self->_dictionaryEntryName, 
-						self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}			
-			else if (!strcasecmp(valType, "array")) {
-				Dictionary_Entry_Value*	valueElement;
-				Index			i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
-					self->_entryTbl[entry_I].value.as.typeArray.size,"AllElementsVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++) {
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
-						Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( !strcasecmp( valType, "double" ) || !strcasecmp( valType, "d" ) || !strcasecmp( valType, "float" ) || !strcasecmp( valType, "f" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( !strcasecmp( valType, "integer" ) || !strcasecmp( valType, "int" ) || !strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( !strcasecmp( valType, "short" ) || !strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( !strcasecmp( valType, "char" ) || !strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( !strcasecmp( valType, "pointer" ) || !strcasecmp( valType, "ptr" ) || !strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*)((ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_DPrintf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else
-	{
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-	}
-}
-
-void _AllElementsVC_Delete( void* allElementsVC ) {
-	AllElementsVC* self = (AllElementsVC*)allElementsVC;
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Delete(self);
-}
-
-void _AllElementsVC_Destroy( void* allElementsVC, void* data ) {
-	AllElementsVC* self = (AllElementsVC*)allElementsVC;
-
-	if (self->_entryTbl) Memory_Free(self->_entryTbl);
-	
-	_VariableCondition_Destroy( self, data );
-}
-
-void _AllElementsVC_Print( void* allElementsVC, Stream* stream ) {
-	AllElementsVC*					self = (AllElementsVC*)allElementsVC;
-	AllElementsVC_Entry_Index	entry_I;
-	Index								i;
-	
-	/* Set the Journal for printing informations */
-	Stream* info = stream;
-	
-	/* General info */
-	Journal_Printf( info, "AllElementsVC (ptr): %p\n", self);
-	
-	/* Print parent */
-	_VariableCondition_Print(self);
-
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
-	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-	if (self->_dictionaryEntryName)
-		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
-	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-	if( self->_entryTbl ) {
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
-		{
-			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
-			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-			if (self->_entryTbl[entry_I].varName)
-				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-			Journal_Printf( info, "\t\t\tvalue:\n");
-			switch (self->_entryTbl[entry_I].value.type)
-			{
-				case VC_ValueType_Double:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
-					Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-					break;
-					
-				case VC_ValueType_Int:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
-					Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-					break;
-					
-				case VC_ValueType_Short:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
-					Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-					break;
-					
-				case VC_ValueType_Char:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
-					Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-					break;
-					
-				case VC_ValueType_Ptr:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-					Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-					break;
-					
-				case VC_ValueType_DoubleArray:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-					Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-					Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
-						self->_entryTbl[entry_I].value.as.typeArray.array);
-					if (self->_entryTbl[entry_I].value.as.typeArray.array)
-						for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-							Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
-								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
-					break;
-					
-				case VC_ValueType_CFIndex:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-					Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-					break;
-			}
-		}
-	}
-}
-
-
-void* _AllElementsVC_Copy( const void* allElementsVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-	AllElementsVC*		self = (AllElementsVC*)allElementsVC;
-	AllElementsVC*		newAllElementsVC;
-	PtrMap*			map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newAllElementsVC = (AllElementsVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-	newAllElementsVC->_dictionaryEntryName = self->_dictionaryEntryName;
-	newAllElementsVC->_entryCount = self->_entryCount;
-	
-	if( deep ) {
-		newAllElementsVC->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
-		
-		if( (newAllElementsVC->_entryTbl = (AllElementsVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-			newAllElementsVC->_entryTbl = Memory_Alloc_Array( AllElementsVC_Entry, newAllElementsVC->_entryCount, "AllElementsVC->_entryTbl");
-			memcpy( newAllElementsVC->_entryTbl, self->_entryTbl, sizeof(AllElementsVC_Entry) * newAllElementsVC->_entryCount );
-			PtrMap_Append( map, newAllElementsVC->_entryTbl, self->_entryTbl );
-		}
-	}
-	else {
-		newAllElementsVC->mesh = self->mesh;
-		newAllElementsVC->_entryTbl = self->_entryTbl;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newAllElementsVC;
-}
-
-
-void _AllElementsVC_Build( void* allElementsVC, void* data ) {
-	AllElementsVC*		self = (AllElementsVC*)allElementsVC;
-	
-	_AllElementsVC_BuildSelf( self, data );
-	
-	_VariableCondition_Build( self, data );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _AllElementsVC_BuildSelf( void* allElementsVC, void* data ) {
-	AllElementsVC*		self = (AllElementsVC*)allElementsVC;
-	
-	if( self->mesh ) {
-		Stg_Component_Build( self->mesh, data, False );
-	}
-}
-
-
-IndexSet* _AllElementsVC_GetSet( void* variableCondition ) {
-	AllElementsVC*				self = (AllElementsVC*)variableCondition;
-	IndexSet*				set;
-
-	set = IndexSet_New( Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
-	IndexSet_AddAll( set );
-	
-	return set;
-}
-
-
-VariableCondition_VariableIndex _AllElementsVC_GetVariableCount( void* variableCondition, Index globalIndex ) {
-	AllElementsVC*	self = (AllElementsVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-Variable_Index _AllElementsVC_GetVariableIndex(
-		void*				variableCondition, 
-		Index				globalIndex, 
-		VariableCondition_VariableIndex	varIndex) 
-{
-	AllElementsVC*	self = (AllElementsVC*)variableCondition;
-	
-	return Variable_Register_GetIndex(self->variable_Register, self->_entryTbl[varIndex].varName);
-}
-
-
-VariableCondition_ValueIndex _AllElementsVC_GetValueIndex(
-		void*				variableCondition, 
-		Index				globalIndex, 
-		VariableCondition_VariableIndex	varIndex)
-{
-	return varIndex;
-}
-
-
-VariableCondition_ValueIndex _AllElementsVC_GetValueCount( void* variableCondition ) {
-	AllElementsVC*	self = (AllElementsVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-VariableCondition_Value _AllElementsVC_GetValue( void* variableCondition, VariableCondition_ValueIndex valIndex ) {
-	AllElementsVC*	self = (AllElementsVC*)variableCondition;
-
-	return self->_entryTbl[valIndex].value;
-}
-
-void _AllElementsVC_PrintConcise( void* variableCondition, Stream* stream ) {
-	AllElementsVC*		self = (AllElementsVC*)variableCondition;
-	
-	Journal_Printf( stream, "\ttype: %s, set: all\n", self->type );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Build functions
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/AllElementsVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/AllElementsVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,470 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: AllElementsVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "AllElementsVC.h"
+#include "RegularMeshUtils.h"
+
+#include <string.h>
+#include <assert.h>
+
+
+const Type AllElementsVC_Type = "AllElementsVC";
+const Name defaultAllElementsVCName = "defaultAllElementsVCName";
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+VariableCondition* AllElementsVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									data )
+{
+	return (VariableCondition*)AllElementsVC_New( defaultAllElementsVCName, context, NULL, variable_Register, conFunc_Register, dictionary, data );
+}
+
+AllElementsVC*	AllElementsVC_New(
+	Name									name,
+	AbstractContext*					context,
+	Name									_dictionaryEntryName, 
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register,
+	Dictionary*							dictionary,
+	void*									mesh )
+{
+	AllElementsVC*	self = _AllElementsVC_DefaultNew( name );
+	
+	self->isConstructed = True;
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
+	_AllElementsVC_Init( self, _dictionaryEntryName, mesh );
+
+	return self;
+}
+
+AllElementsVC* _AllElementsVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(AllElementsVC);
+	Type                                                       type = AllElementsVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _AllElementsVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _AllElementsVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _AllElementsVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_AllElementsVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _AllElementsVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _AllElementsVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _AllElementsVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _AllElementsVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _AllElementsVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _AllElementsVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _AllElementsVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _AllElementsVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _AllElementsVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _AllElementsVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _AllElementsVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _AllElementsVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return _AllElementsVC_New(  ALLELEMENTSVC_PASSARGS  );
+}
+
+AllElementsVC* _AllElementsVC_New(  ALLELEMENTSVC_DEFARGS  ) {
+	AllElementsVC*	self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(AllElementsVC) );
+	self = (AllElementsVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	
+	return self;
+}
+
+
+void _AllElementsVC_Init( void* allElementsVC, Name _dictionaryEntryName, void* mesh ) {
+	AllElementsVC* self = (AllElementsVC*)allElementsVC;
+
+	self->_dictionaryEntryName = _dictionaryEntryName;
+	self->mesh = (Mesh*)mesh;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+void _AllElementsVC_AssignFromXML( void* allElementsVC, Stg_ComponentFactory *cf, void* data ) { 
+}
+
+void _AllElementsVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+	AllElementsVC*					self = (AllElementsVC*)variableCondition;
+	Dictionary_Entry_Value*		vcDictVal;
+	Dictionary_Entry_Value		_vcDictVal;
+	Dictionary_Entry_Value*		varsVal;
+	AllElementsVC_Entry_Index	entry_I;
+	
+	/* Find dictionary entry */
+	if (self->_dictionaryEntryName)
+		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName  );
+	else {
+		vcDictVal = &_vcDictVal;
+		Dictionary_Entry_Value_InitFromStruct( vcDictVal, dictionary );
+	}
+	
+	if (vcDictVal) {
+		/* Obtain the variable entries */
+		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+		self->_entryTbl = Memory_Alloc_Array( AllElementsVC_Entry, self->_entryCount, "AllElementsVC->_entryTbl" );
+		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
+			char*							valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+
+			if (0 == strcasecmp(valType, "func")) {
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+
+				if ( cfIndex == (unsigned)-1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+						"definition of allElementsVC \"%s\", the cond. func. applied to "
+						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+						__func__, self->_dictionaryEntryName, 
+						self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}			
+			else if (!strcasecmp(valType, "array")) {
+				Dictionary_Entry_Value*	valueElement;
+				Index			i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
+					self->_entryTbl[entry_I].value.as.typeArray.size,"AllElementsVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++) {
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
+						Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( !strcasecmp( valType, "double" ) || !strcasecmp( valType, "d" ) || !strcasecmp( valType, "float" ) || !strcasecmp( valType, "f" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( !strcasecmp( valType, "integer" ) || !strcasecmp( valType, "int" ) || !strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( !strcasecmp( valType, "short" ) || !strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( !strcasecmp( valType, "char" ) || !strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( !strcasecmp( valType, "pointer" ) || !strcasecmp( valType, "ptr" ) || !strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*)((ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_DPrintf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else
+	{
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+	}
+}
+
+void _AllElementsVC_Delete( void* allElementsVC ) {
+	AllElementsVC* self = (AllElementsVC*)allElementsVC;
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Delete(self);
+}
+
+void _AllElementsVC_Destroy( void* allElementsVC, void* data ) {
+	AllElementsVC* self = (AllElementsVC*)allElementsVC;
+
+	if (self->_entryTbl) Memory_Free(self->_entryTbl);
+	
+	_VariableCondition_Destroy( self, data );
+}
+
+void _AllElementsVC_Print( void* allElementsVC, Stream* stream ) {
+	AllElementsVC*					self = (AllElementsVC*)allElementsVC;
+	AllElementsVC_Entry_Index	entry_I;
+	Index								i;
+	
+	/* Set the Journal for printing informations */
+	Stream* info = stream;
+	
+	/* General info */
+	Journal_Printf( info, "AllElementsVC (ptr): %p\n", self);
+	
+	/* Print parent */
+	_VariableCondition_Print(self);
+
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
+	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+	if (self->_dictionaryEntryName)
+		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
+	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+	if( self->_entryTbl ) {
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
+		{
+			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
+			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+			if (self->_entryTbl[entry_I].varName)
+				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+			Journal_Printf( info, "\t\t\tvalue:\n");
+			switch (self->_entryTbl[entry_I].value.type)
+			{
+				case VC_ValueType_Double:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
+					Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+					break;
+					
+				case VC_ValueType_Int:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
+					Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+					break;
+					
+				case VC_ValueType_Short:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
+					Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+					break;
+					
+				case VC_ValueType_Char:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
+					Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+					break;
+					
+				case VC_ValueType_Ptr:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+					Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+					break;
+					
+				case VC_ValueType_DoubleArray:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+					Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+					Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
+						self->_entryTbl[entry_I].value.as.typeArray.array);
+					if (self->_entryTbl[entry_I].value.as.typeArray.array)
+						for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+							Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
+								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
+					break;
+					
+				case VC_ValueType_CFIndex:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+					Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+					break;
+			}
+		}
+	}
+}
+
+
+void* _AllElementsVC_Copy( const void* allElementsVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+	AllElementsVC*		self = (AllElementsVC*)allElementsVC;
+	AllElementsVC*		newAllElementsVC;
+	PtrMap*			map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newAllElementsVC = (AllElementsVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+	newAllElementsVC->_dictionaryEntryName = self->_dictionaryEntryName;
+	newAllElementsVC->_entryCount = self->_entryCount;
+	
+	if( deep ) {
+		newAllElementsVC->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
+		
+		if( (newAllElementsVC->_entryTbl = (AllElementsVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+			newAllElementsVC->_entryTbl = Memory_Alloc_Array( AllElementsVC_Entry, newAllElementsVC->_entryCount, "AllElementsVC->_entryTbl");
+			memcpy( newAllElementsVC->_entryTbl, self->_entryTbl, sizeof(AllElementsVC_Entry) * newAllElementsVC->_entryCount );
+			PtrMap_Append( map, newAllElementsVC->_entryTbl, self->_entryTbl );
+		}
+	}
+	else {
+		newAllElementsVC->mesh = self->mesh;
+		newAllElementsVC->_entryTbl = self->_entryTbl;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newAllElementsVC;
+}
+
+
+void _AllElementsVC_Build( void* allElementsVC, void* data ) {
+	AllElementsVC*		self = (AllElementsVC*)allElementsVC;
+	
+	_AllElementsVC_BuildSelf( self, data );
+	
+	_VariableCondition_Build( self, data );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _AllElementsVC_BuildSelf( void* allElementsVC, void* data ) {
+	AllElementsVC*		self = (AllElementsVC*)allElementsVC;
+	
+	if( self->mesh ) {
+		Stg_Component_Build( self->mesh, data, False );
+	}
+}
+
+
+IndexSet* _AllElementsVC_GetSet( void* variableCondition ) {
+	AllElementsVC*				self = (AllElementsVC*)variableCondition;
+	IndexSet*				set;
+
+	set = IndexSet_New( Mesh_GetDomainSize( self->mesh, Mesh_GetDimSize( self->mesh ) ) );
+	IndexSet_AddAll( set );
+	
+	return set;
+}
+
+
+VariableCondition_VariableIndex _AllElementsVC_GetVariableCount( void* variableCondition, Index globalIndex ) {
+	AllElementsVC*	self = (AllElementsVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+Variable_Index _AllElementsVC_GetVariableIndex(
+		void*				variableCondition, 
+		Index				globalIndex, 
+		VariableCondition_VariableIndex	varIndex) 
+{
+	AllElementsVC*	self = (AllElementsVC*)variableCondition;
+	
+	return Variable_Register_GetIndex(self->variable_Register, self->_entryTbl[varIndex].varName);
+}
+
+
+VariableCondition_ValueIndex _AllElementsVC_GetValueIndex(
+		void*				variableCondition, 
+		Index				globalIndex, 
+		VariableCondition_VariableIndex	varIndex)
+{
+	return varIndex;
+}
+
+
+VariableCondition_ValueIndex _AllElementsVC_GetValueCount( void* variableCondition ) {
+	AllElementsVC*	self = (AllElementsVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+VariableCondition_Value _AllElementsVC_GetValue( void* variableCondition, VariableCondition_ValueIndex valIndex ) {
+	AllElementsVC*	self = (AllElementsVC*)variableCondition;
+
+	return self->_entryTbl[valIndex].value;
+}
+
+void _AllElementsVC_PrintConcise( void* variableCondition, Stream* stream ) {
+	AllElementsVC*		self = (AllElementsVC*)variableCondition;
+	
+	Journal_Printf( stream, "\ttype: %s, set: all\n", self->type );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Build functions
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/AllNodesVC.c
--- a/Utils/src/AllNodesVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,478 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: AllNodesVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "AllNodesVC.h"
-#include "RegularMeshUtils.h"
-
-#include <string.h>
-#include <assert.h>
-
-
-const Type AllNodesVC_Type = "AllNodesVC";
-const Name defaultAllNodesVCName = "defaultAllNodesVCName";
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-VariableCondition* AllNodesVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									data )
-{
-	return (VariableCondition*)AllNodesVC_New( defaultAllNodesVCName, context, NULL, variable_Register, conFunc_Register, dictionary, data );
-}
-
-
-AllNodesVC*	AllNodesVC_New(
-	Name									name,
-	AbstractContext*					context,
-	Name									_dictionaryEntryName, 
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register,
-	Dictionary*							dictionary,
-	void*									mesh )
-{
-	AllNodesVC* self = _AllNodesVC_DefaultNew( name );
-
-	self->isConstructed = True;
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );	
-	_AllNodesVC_Init( self, _dictionaryEntryName, mesh );
-
-	return self;
-}
-
-AllNodesVC* _AllNodesVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(AllNodesVC);
-	Type                                                       type = AllNodesVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _AllNodesVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _AllNodesVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _AllNodesVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_AllNodesVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _AllNodesVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _AllNodesVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _AllNodesVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _AllNodesVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _AllNodesVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _AllNodesVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _AllNodesVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _AllNodesVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _AllNodesVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _AllNodesVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _AllNodesVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _AllNodesVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return _AllNodesVC_New(  ALLNODESVC_PASSARGS  );
-}
-
-AllNodesVC* _AllNodesVC_New(  ALLNODESVC_DEFARGS  ) {
-	AllNodesVC*	self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(AllNodesVC) );
-	self = (AllNodesVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	
-	return self;
-}
-
-void _AllNodesVC_Init(
-	void*	allNodesVC, 
-	Name	_dictionaryEntryName, 
-	void*	mesh )
-{
-	AllNodesVC* self = (AllNodesVC*)allNodesVC;
-	
-	self->isConstructed = True;
-	self->_dictionaryEntryName = _dictionaryEntryName;
-	self->mesh = (Mesh*)mesh;
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-void _AllNodesVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-	AllNodesVC*					self = (AllNodesVC*)variableCondition;
-	Dictionary_Entry_Value*	vcDictVal;
-	Dictionary_Entry_Value	_vcDictVal;
-	Dictionary_Entry_Value*	varsVal;
-	AllNodesVC_Entry_Index	entry_I;
-	
-	/* Find dictionary entry */
-	if (self->_dictionaryEntryName)
-		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName  );
-	else {
-		vcDictVal = &_vcDictVal;
-		Dictionary_Entry_Value_InitFromStruct( vcDictVal, dictionary );
-	}
-	
-	if (vcDictVal) {
-		/* Obtain the variable entries */
-		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-		self->_entryTbl = Memory_Alloc_Array( AllNodesVC_Entry, self->_entryCount, "AllNodesVC->_entryTbl" );
-		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
-			char*							valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-
-			if (0 == strcasecmp(valType, "func")) {
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-
-				if ( cfIndex == (unsigned)-1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-						"definition of %s \"%s\", the cond. func. applied to "
-						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-						__func__, self->type, self->_dictionaryEntryName, 
-						self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}	
-			else if (!strcasecmp(valType, "array")) {
-				Dictionary_Entry_Value*	valueElement;
-				Index			i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double, 
-					self->_entryTbl[entry_I].value.as.typeArray.size, "AllNodesVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++) {
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
-						Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( !strcasecmp( valType, "double" ) || !strcasecmp( valType, "d" ) || !strcasecmp( valType, "float" ) || !strcasecmp( valType, "f" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( !strcasecmp( valType, "integer" ) || !strcasecmp( valType, "int" ) || !strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( !strcasecmp( valType, "short" ) || !strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( !strcasecmp( valType, "char" ) || !strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( !strcasecmp( valType, "pointer" ) || !strcasecmp( valType, "ptr" ) || !strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*) ((ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_Printf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else
-	{
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-	}
-}
-
-void _AllNodesVC_Delete( void* allNodesVC ) {
-	AllNodesVC* self = (AllNodesVC*)allNodesVC;
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Delete(self);
-}
-
-void _AllNodesVC_Destroy( void* allNodesVC, void* data ) {
-	AllNodesVC* self = (AllNodesVC*)allNodesVC;
-
-	if (self->_entryTbl) Memory_Free(self->_entryTbl);
-
-	_VariableCondition_Destroy( self, data );
-}
-
-void _AllNodesVC_Print( void* allNodesVC, Stream* stream ) {
-	AllNodesVC*					self = (AllNodesVC*)allNodesVC;
-	AllNodesVC_Entry_Index	entry_I;
-	Index							i;
-	
-	/* Set the Journal for printing informations */
-	Stream* info = stream;
-	
-	/* General info */
-	Journal_Printf( info, "AllNodesVC (ptr): %p\n", self);
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
-	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-
-	if (self->_dictionaryEntryName)
-		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-
-	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
-	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-
-	if (self->_entryTbl)
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++) {
-			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
-			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-
-			if (self->_entryTbl[entry_I].varName)
-				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-			Journal_Printf( info, "\t\t\tvalue:\n");
-
-			switch (self->_entryTbl[entry_I].value.type) {
-				case VC_ValueType_Double:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
-					Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-					break;
-					
-				case VC_ValueType_Int:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
-					Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-					break;
-					
-				case VC_ValueType_Short:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
-					Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-					break;
-					
-				case VC_ValueType_Char:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
-					Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-					break;
-					
-				case VC_ValueType_Ptr:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-					Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-					break;
-					
-				case VC_ValueType_DoubleArray:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-					Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-					Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", self->_entryTbl[entry_I].value.as.typeArray.array);
-
-					if (self->_entryTbl[entry_I].value.as.typeArray.array)
-						for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-							Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
-								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
-					break;
-					
-				case VC_ValueType_CFIndex:
-					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-					Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-					break;
-			}
-		}
-	
-	/* Print parent */
-	_VariableCondition_Print(self);
-}
-
-
-void* _AllNodesVC_Copy( const void* allNodesVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-	AllNodesVC*		self = (AllNodesVC*)allNodesVC;
-	AllNodesVC*		newAllNodesVC;
-	PtrMap*			map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newAllNodesVC = (AllNodesVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-	newAllNodesVC->_dictionaryEntryName = self->_dictionaryEntryName;
-	newAllNodesVC->_entryCount = self->_entryCount;
-	
-	if( deep ) {
-		newAllNodesVC->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
-		
-		if( (newAllNodesVC->_entryTbl = (AllNodesVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-			newAllNodesVC->_entryTbl = Memory_Alloc_Array( AllNodesVC_Entry, newAllNodesVC->_entryCount, "AllNodesVC->_entryTbl");
-			memcpy( newAllNodesVC->_entryTbl, self->_entryTbl, sizeof(AllNodesVC_Entry) * newAllNodesVC->_entryCount );
-			PtrMap_Append( map, newAllNodesVC->_entryTbl, self->_entryTbl );
-		}
-	}
-	else {
-		newAllNodesVC->mesh = self->mesh;
-		newAllNodesVC->_entryTbl = self->_entryTbl;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newAllNodesVC;
-}
-
-
-void _AllNodesVC_Build( void* allNodesVC, void* data ) {
-	AllNodesVC*		self = (AllNodesVC*)allNodesVC;
-	
-	_AllNodesVC_BuildSelf( self, data );
-	
-	_VariableCondition_Build( self, data );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _AllNodesVC_AssignFromXML( void* allNodesVC, Stg_ComponentFactory* cf, void* data ) { 
-}
-
-void _AllNodesVC_BuildSelf( void* allNodesVC, void* data ) {
-	AllNodesVC*		self = (AllNodesVC*)allNodesVC;
-	
-	if( self->mesh ) {
-		Stg_Component_Build( self->mesh, data, False );
-	}
-}
-
-
-IndexSet* _AllNodesVC_GetSet( void* variableCondition ) {
-	AllNodesVC*		self = (AllNodesVC*)variableCondition;
-	IndexSet*		set;
-
-	set = IndexSet_New( Mesh_GetDomainSize( self->mesh, MT_VERTEX ) );
-	IndexSet_AddAll( set );
-	
-	return set;
-}
-
-
-VariableCondition_VariableIndex _AllNodesVC_GetVariableCount( void* variableCondition, Index globalIndex ) {
-	AllNodesVC*	self = (AllNodesVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-Variable_Index _AllNodesVC_GetVariableIndex(
-		void*				variableCondition, 
-		Index				globalIndex, 
-		VariableCondition_VariableIndex varIndex )
-{
-	AllNodesVC*	self = (AllNodesVC*)variableCondition;
-	
-	return Variable_Register_GetIndex(self->variable_Register, self->_entryTbl[varIndex].varName);
-}
-
-
-VariableCondition_ValueIndex _AllNodesVC_GetValueIndex(
-		void*				variableCondition, 
-		Index				globalIndex, 
-		VariableCondition_VariableIndex	varIndex )
-{
-	return varIndex;
-}
-
-
-VariableCondition_ValueIndex _AllNodesVC_GetValueCount( void* variableCondition ) {
-	AllNodesVC*	self = (AllNodesVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-VariableCondition_Value _AllNodesVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex) {
-	AllNodesVC*	self = (AllNodesVC*)variableCondition;
-
-	return self->_entryTbl[valIndex].value;
-}
-
-void _AllNodesVC_PrintConcise( void* variableCondition, Stream* stream ) {
-	AllNodesVC*		self = (AllNodesVC*)variableCondition;
-	
-	Journal_Printf( stream, "\ttype: %s, set: all\n", self->type );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Build functions
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/AllNodesVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/AllNodesVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,478 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: AllNodesVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "AllNodesVC.h"
+#include "RegularMeshUtils.h"
+
+#include <string.h>
+#include <assert.h>
+
+
+const Type AllNodesVC_Type = "AllNodesVC";
+const Name defaultAllNodesVCName = "defaultAllNodesVCName";
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+VariableCondition* AllNodesVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									data )
+{
+	return (VariableCondition*)AllNodesVC_New( defaultAllNodesVCName, context, NULL, variable_Register, conFunc_Register, dictionary, data );
+}
+
+
+AllNodesVC*	AllNodesVC_New(
+	Name									name,
+	AbstractContext*					context,
+	Name									_dictionaryEntryName, 
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register,
+	Dictionary*							dictionary,
+	void*									mesh )
+{
+	AllNodesVC* self = _AllNodesVC_DefaultNew( name );
+
+	self->isConstructed = True;
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );	
+	_AllNodesVC_Init( self, _dictionaryEntryName, mesh );
+
+	return self;
+}
+
+AllNodesVC* _AllNodesVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(AllNodesVC);
+	Type                                                       type = AllNodesVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _AllNodesVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _AllNodesVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _AllNodesVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_AllNodesVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _AllNodesVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _AllNodesVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _AllNodesVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _AllNodesVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _AllNodesVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _AllNodesVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _AllNodesVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _AllNodesVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _AllNodesVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _AllNodesVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _AllNodesVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _AllNodesVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return _AllNodesVC_New(  ALLNODESVC_PASSARGS  );
+}
+
+AllNodesVC* _AllNodesVC_New(  ALLNODESVC_DEFARGS  ) {
+	AllNodesVC*	self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(AllNodesVC) );
+	self = (AllNodesVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	
+	return self;
+}
+
+void _AllNodesVC_Init(
+	void*	allNodesVC, 
+	Name	_dictionaryEntryName, 
+	void*	mesh )
+{
+	AllNodesVC* self = (AllNodesVC*)allNodesVC;
+	
+	self->isConstructed = True;
+	self->_dictionaryEntryName = _dictionaryEntryName;
+	self->mesh = (Mesh*)mesh;
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+void _AllNodesVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+	AllNodesVC*					self = (AllNodesVC*)variableCondition;
+	Dictionary_Entry_Value*	vcDictVal;
+	Dictionary_Entry_Value	_vcDictVal;
+	Dictionary_Entry_Value*	varsVal;
+	AllNodesVC_Entry_Index	entry_I;
+	
+	/* Find dictionary entry */
+	if (self->_dictionaryEntryName)
+		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName  );
+	else {
+		vcDictVal = &_vcDictVal;
+		Dictionary_Entry_Value_InitFromStruct( vcDictVal, dictionary );
+	}
+	
+	if (vcDictVal) {
+		/* Obtain the variable entries */
+		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+		self->_entryTbl = Memory_Alloc_Array( AllNodesVC_Entry, self->_entryCount, "AllNodesVC->_entryTbl" );
+		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
+			char*							valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+
+			if (0 == strcasecmp(valType, "func")) {
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+
+				if ( cfIndex == (unsigned)-1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+						"definition of %s \"%s\", the cond. func. applied to "
+						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+						__func__, self->type, self->_dictionaryEntryName, 
+						self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}	
+			else if (!strcasecmp(valType, "array")) {
+				Dictionary_Entry_Value*	valueElement;
+				Index			i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double, 
+					self->_entryTbl[entry_I].value.as.typeArray.size, "AllNodesVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++) {
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
+						Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( !strcasecmp( valType, "double" ) || !strcasecmp( valType, "d" ) || !strcasecmp( valType, "float" ) || !strcasecmp( valType, "f" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( !strcasecmp( valType, "integer" ) || !strcasecmp( valType, "int" ) || !strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( !strcasecmp( valType, "short" ) || !strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( !strcasecmp( valType, "char" ) || !strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( !strcasecmp( valType, "pointer" ) || !strcasecmp( valType, "ptr" ) || !strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*) ((ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_Printf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else
+	{
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+	}
+}
+
+void _AllNodesVC_Delete( void* allNodesVC ) {
+	AllNodesVC* self = (AllNodesVC*)allNodesVC;
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Delete(self);
+}
+
+void _AllNodesVC_Destroy( void* allNodesVC, void* data ) {
+	AllNodesVC* self = (AllNodesVC*)allNodesVC;
+
+	if (self->_entryTbl) Memory_Free(self->_entryTbl);
+
+	_VariableCondition_Destroy( self, data );
+}
+
+void _AllNodesVC_Print( void* allNodesVC, Stream* stream ) {
+	AllNodesVC*					self = (AllNodesVC*)allNodesVC;
+	AllNodesVC_Entry_Index	entry_I;
+	Index							i;
+	
+	/* Set the Journal for printing informations */
+	Stream* info = stream;
+	
+	/* General info */
+	Journal_Printf( info, "AllNodesVC (ptr): %p\n", self);
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
+	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+
+	if (self->_dictionaryEntryName)
+		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+
+	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
+	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+
+	if (self->_entryTbl)
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++) {
+			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
+			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+
+			if (self->_entryTbl[entry_I].varName)
+				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+			Journal_Printf( info, "\t\t\tvalue:\n");
+
+			switch (self->_entryTbl[entry_I].value.type) {
+				case VC_ValueType_Double:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
+					Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+					break;
+					
+				case VC_ValueType_Int:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
+					Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+					break;
+					
+				case VC_ValueType_Short:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
+					Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+					break;
+					
+				case VC_ValueType_Char:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
+					Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+					break;
+					
+				case VC_ValueType_Ptr:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+					Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+					break;
+					
+				case VC_ValueType_DoubleArray:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+					Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+					Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", self->_entryTbl[entry_I].value.as.typeArray.array);
+
+					if (self->_entryTbl[entry_I].value.as.typeArray.array)
+						for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+							Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
+								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
+					break;
+					
+				case VC_ValueType_CFIndex:
+					Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+					Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+					break;
+			}
+		}
+	
+	/* Print parent */
+	_VariableCondition_Print(self);
+}
+
+
+void* _AllNodesVC_Copy( const void* allNodesVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+	AllNodesVC*		self = (AllNodesVC*)allNodesVC;
+	AllNodesVC*		newAllNodesVC;
+	PtrMap*			map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newAllNodesVC = (AllNodesVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+	newAllNodesVC->_dictionaryEntryName = self->_dictionaryEntryName;
+	newAllNodesVC->_entryCount = self->_entryCount;
+	
+	if( deep ) {
+		newAllNodesVC->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
+		
+		if( (newAllNodesVC->_entryTbl = (AllNodesVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+			newAllNodesVC->_entryTbl = Memory_Alloc_Array( AllNodesVC_Entry, newAllNodesVC->_entryCount, "AllNodesVC->_entryTbl");
+			memcpy( newAllNodesVC->_entryTbl, self->_entryTbl, sizeof(AllNodesVC_Entry) * newAllNodesVC->_entryCount );
+			PtrMap_Append( map, newAllNodesVC->_entryTbl, self->_entryTbl );
+		}
+	}
+	else {
+		newAllNodesVC->mesh = self->mesh;
+		newAllNodesVC->_entryTbl = self->_entryTbl;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newAllNodesVC;
+}
+
+
+void _AllNodesVC_Build( void* allNodesVC, void* data ) {
+	AllNodesVC*		self = (AllNodesVC*)allNodesVC;
+	
+	_AllNodesVC_BuildSelf( self, data );
+	
+	_VariableCondition_Build( self, data );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _AllNodesVC_AssignFromXML( void* allNodesVC, Stg_ComponentFactory* cf, void* data ) { 
+}
+
+void _AllNodesVC_BuildSelf( void* allNodesVC, void* data ) {
+	AllNodesVC*		self = (AllNodesVC*)allNodesVC;
+	
+	if( self->mesh ) {
+		Stg_Component_Build( self->mesh, data, False );
+	}
+}
+
+
+IndexSet* _AllNodesVC_GetSet( void* variableCondition ) {
+	AllNodesVC*		self = (AllNodesVC*)variableCondition;
+	IndexSet*		set;
+
+	set = IndexSet_New( Mesh_GetDomainSize( self->mesh, MT_VERTEX ) );
+	IndexSet_AddAll( set );
+	
+	return set;
+}
+
+
+VariableCondition_VariableIndex _AllNodesVC_GetVariableCount( void* variableCondition, Index globalIndex ) {
+	AllNodesVC*	self = (AllNodesVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+Variable_Index _AllNodesVC_GetVariableIndex(
+		void*				variableCondition, 
+		Index				globalIndex, 
+		VariableCondition_VariableIndex varIndex )
+{
+	AllNodesVC*	self = (AllNodesVC*)variableCondition;
+	
+	return Variable_Register_GetIndex(self->variable_Register, self->_entryTbl[varIndex].varName);
+}
+
+
+VariableCondition_ValueIndex _AllNodesVC_GetValueIndex(
+		void*				variableCondition, 
+		Index				globalIndex, 
+		VariableCondition_VariableIndex	varIndex )
+{
+	return varIndex;
+}
+
+
+VariableCondition_ValueIndex _AllNodesVC_GetValueCount( void* variableCondition ) {
+	AllNodesVC*	self = (AllNodesVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+VariableCondition_Value _AllNodesVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex) {
+	AllNodesVC*	self = (AllNodesVC*)variableCondition;
+
+	return self->_entryTbl[valIndex].value;
+}
+
+void _AllNodesVC_PrintConcise( void* variableCondition, Stream* stream ) {
+	AllNodesVC*		self = (AllNodesVC*)variableCondition;
+	
+	Journal_Printf( stream, "\ttype: %s, set: all\n", self->type );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Build functions
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/ContactVC.c
--- a/Utils/src/ContactVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,318 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ContactVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "WallVC.h"
-#include "ContactVC.h"
-#include "RegularMeshUtils.h"
-
-#include <string.h>
-#include <assert.h>
-
-
-const Type ContactVC_Type = "ContactVC";
-const Name defaultContactVCName = "defaultContactVCName";
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-VariableCondition* ContactVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-   ConditionFunction_Register*	conFunc_Register, 
-   Dictionary*							dictionary,
-   void*									data )
-{
-   return (VariableCondition*)ContactVC_New( defaultContactVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
-}
-
-ContactVC*	ContactVC_New(
-   Name									name,
-	AbstractContext*					context,
-   Name									_dictionaryEntryName, 
-   Variable_Register*				variable_Register, 
-   ConditionFunction_Register*	conFunc_Register, 
-   Dictionary*							dictionary,
-   void*									_mesh )
-{
-   ContactVC* self = _ContactVC_DefaultNew( name );
-	
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
-   _WallVC_Init( self, _dictionaryEntryName, _mesh );
-	_ContactVC_Init( self, _dictionaryEntryName, _mesh );
-
-	return self;
-}
-
-ContactVC* _ContactVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(ContactVC);
-	Type                                                       type = ContactVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _ContactVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _WallVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _WallVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_ContactVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _ContactVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _ContactVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _WallVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _WallVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _WallVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _ContactVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _ContactVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _WallVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _WallVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _WallVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _WallVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _WallVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-   return _ContactVC_New(  CONTACTVC_PASSARGS  );
-}
-
-ContactVC* _ContactVC_New(  CONTACTVC_DEFARGS  ) {
-   ContactVC* self;
-	
-   /* Allocate memory/General info */
-   assert( _sizeOfSelf >= sizeof(ContactVC) );
-   self = (ContactVC*)_WallVC_New(  WALLVC_PASSARGS  );
-	
-   /* Virtual info */
-	
-   /* Stg_Class info */
-	
-   return self;
-}
-
-
-void _ContactVC_Init( void* wallVC, Name _dictionaryEntryName, void* _mesh ) {
-   ContactVC* self = (ContactVC*)wallVC;
-
-   self->deep = False;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-void _ContactVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-   ContactVC* self = (ContactVC*)variableCondition;
-   Dictionary_Entry_Value *vcDictVal, _vcDictVal, *entryVal;
-
-   _WallVC_ReadDictionary( variableCondition, dictionary );
-
-   /* Find dictionary entry */
-   if (self->_dictionaryEntryName)
-      vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
-   else
-   {
-      vcDictVal = &_vcDictVal;
-      Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
-   }
-
-   if (vcDictVal) {
-      entryVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"deep" );
-      if( entryVal )
-         self->deep = Dictionary_Entry_Value_AsBool( entryVal );
-   }
-   else {
-      self->deep = False;
-   }
-}
-
-
-void _ContactVC_Delete(void* wallVC) {
-   ContactVC*	self = (ContactVC*)wallVC;
-	
-   /* Stg_Class_Delete parent */
-   _WallVC_Delete( self  );
-}
-
-void _ContactVC_Destroy(void* wallVC, void* data) {
-   ContactVC*	self = (ContactVC*)wallVC;
-	
-   /* Stg_Class_Delete parent */
-   _WallVC_Destroy( self, data);
-}
-
-void _ContactVC_Build(  void* wallVC, void* data ) {
-   ContactVC*			self = (ContactVC*)wallVC;
-	
-   _WallVC_Build( self, data );
-}
-	
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _ContactVC_AssignFromXML( void* wallVC, Stg_ComponentFactory* cf, void* data ) { 
-}
-
-IndexSet* _ContactVC_GetSet(void* variableCondition) {
-   ContactVC*				self = (ContactVC*)variableCondition;
-   IndexSet*				set = NULL;
-   Stream*					warningStr = Journal_Register( Error_Type, (Name)self->type );
-   unsigned					nDims;
-   Grid*						vertGrid;
-   CartesianGenerator*	gen;
-
-   nDims = Mesh_GetDimSize( self->_mesh );
-   gen = (CartesianGenerator* )self->_mesh->generator;
-
-   if( strcmp( gen->type, CartesianGenerator_Type ) )
-      abort();
-   vertGrid = *(Grid**)ExtensionManager_Get( self->_mesh->info, self->_mesh, ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
-
-   switch (self->_wall) {
-      case WallVC_Wall_Front:
-         if ( nDims < 3 || !vertGrid->sizes[2]  ) {
-            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-                            WallVC_WallEnumToStr[self->_wall], "K" );
-            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-         }
-         else {
-            abort();
-            /*set = RegularMeshUtils_CreateContactFrontSet( self->_mesh );*/
-         }
-         break;
-			
-      case WallVC_Wall_Back:
-         if ( nDims < 3 || !vertGrid->sizes[2] ) {
-            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-                            WallVC_WallEnumToStr[self->_wall], "K" );
-            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-         }
-         else {
-            abort();
-            /*set = RegularMeshUtils_CreateContactBackSet( self->_mesh );*/
-         }	
-         break;
-			
-      case WallVC_Wall_Top:
-         if ( nDims < 2 || !vertGrid->sizes[1] ) {
-            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-                            WallVC_WallEnumToStr[self->_wall], "J" );
-            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-         }
-         else {
-            set = RegularMeshUtils_CreateContactTopSet(self->_mesh, gen->contactDepth[0][0], gen->contactDepth[0][1]);
-         }	
-         break;
-			
-      case WallVC_Wall_Bottom:
-         if ( nDims < 2 || !vertGrid->sizes[1] ) {
-            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-                            WallVC_WallEnumToStr[self->_wall], "J" );
-            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-         }
-         else {
-            if( self->deep ) {
-               set = RegularMeshUtils_CreateContactBottomSet(
-                  self->_mesh, 0, 0, gen->contactDepth[1][0] );
-            }
-            else {
-               set = RegularMeshUtils_CreateContactBottomSet(
-                  self->_mesh, gen->contactDepth[0][0], gen->contactDepth[0][1], 0 );
-            }
-         }	
-         break;
-			
-      case WallVC_Wall_Left:
-         if ( nDims < 1 ) {
-            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-                            WallVC_WallEnumToStr[self->_wall], "I" );
-            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-         }
-         else {
-            set = RegularMeshUtils_CreateContactLeftSet(self->_mesh, gen->contactDepth[1][0], gen->contactDepth[1][1]);
-         }	
-         break;
-			
-      case WallVC_Wall_Right:
-         if( nDims < 1 ) {
-            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-                            WallVC_WallEnumToStr[self->_wall], "I" );
-            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-         }
-         else {
-            if( self->deep ) {
-               set = RegularMeshUtils_CreateContactRightSet(
-                  self->_mesh, 0, 0, gen->contactDepth[0][1] );
-            }
-            else {
-               set = RegularMeshUtils_CreateContactRightSet(
-                  self->_mesh, gen->contactDepth[1][0], gen->contactDepth[1][1], 0 );
-            }
-         }
-         break;
-			
-      case WallVC_Wall_Size:
-      default:
-         assert(0);
-         break;
-   }
-	
-   return set;
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Build functions
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/ContactVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/ContactVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,318 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ContactVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "WallVC.h"
+#include "ContactVC.h"
+#include "RegularMeshUtils.h"
+
+#include <string.h>
+#include <assert.h>
+
+
+const Type ContactVC_Type = "ContactVC";
+const Name defaultContactVCName = "defaultContactVCName";
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+VariableCondition* ContactVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+   ConditionFunction_Register*	conFunc_Register, 
+   Dictionary*							dictionary,
+   void*									data )
+{
+   return (VariableCondition*)ContactVC_New( defaultContactVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
+}
+
+ContactVC*	ContactVC_New(
+   Name									name,
+	AbstractContext*					context,
+   Name									_dictionaryEntryName, 
+   Variable_Register*				variable_Register, 
+   ConditionFunction_Register*	conFunc_Register, 
+   Dictionary*							dictionary,
+   void*									_mesh )
+{
+   ContactVC* self = _ContactVC_DefaultNew( name );
+	
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
+   _WallVC_Init( self, _dictionaryEntryName, _mesh );
+	_ContactVC_Init( self, _dictionaryEntryName, _mesh );
+
+	return self;
+}
+
+ContactVC* _ContactVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(ContactVC);
+	Type                                                       type = ContactVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _ContactVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _WallVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _WallVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_ContactVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _ContactVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _ContactVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _WallVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _WallVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _WallVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _ContactVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _ContactVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _WallVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _WallVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _WallVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _WallVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _WallVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+   return _ContactVC_New(  CONTACTVC_PASSARGS  );
+}
+
+ContactVC* _ContactVC_New(  CONTACTVC_DEFARGS  ) {
+   ContactVC* self;
+	
+   /* Allocate memory/General info */
+   assert( _sizeOfSelf >= sizeof(ContactVC) );
+   self = (ContactVC*)_WallVC_New(  WALLVC_PASSARGS  );
+	
+   /* Virtual info */
+	
+   /* Stg_Class info */
+	
+   return self;
+}
+
+
+void _ContactVC_Init( void* wallVC, Name _dictionaryEntryName, void* _mesh ) {
+   ContactVC* self = (ContactVC*)wallVC;
+
+   self->deep = False;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+void _ContactVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+   ContactVC* self = (ContactVC*)variableCondition;
+   Dictionary_Entry_Value *vcDictVal, _vcDictVal, *entryVal;
+
+   _WallVC_ReadDictionary( variableCondition, dictionary );
+
+   /* Find dictionary entry */
+   if (self->_dictionaryEntryName)
+      vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
+   else
+   {
+      vcDictVal = &_vcDictVal;
+      Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
+   }
+
+   if (vcDictVal) {
+      entryVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"deep" );
+      if( entryVal )
+         self->deep = Dictionary_Entry_Value_AsBool( entryVal );
+   }
+   else {
+      self->deep = False;
+   }
+}
+
+
+void _ContactVC_Delete(void* wallVC) {
+   ContactVC*	self = (ContactVC*)wallVC;
+	
+   /* Stg_Class_Delete parent */
+   _WallVC_Delete( self  );
+}
+
+void _ContactVC_Destroy(void* wallVC, void* data) {
+   ContactVC*	self = (ContactVC*)wallVC;
+	
+   /* Stg_Class_Delete parent */
+   _WallVC_Destroy( self, data);
+}
+
+void _ContactVC_Build(  void* wallVC, void* data ) {
+   ContactVC*			self = (ContactVC*)wallVC;
+	
+   _WallVC_Build( self, data );
+}
+	
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _ContactVC_AssignFromXML( void* wallVC, Stg_ComponentFactory* cf, void* data ) { 
+}
+
+IndexSet* _ContactVC_GetSet(void* variableCondition) {
+   ContactVC*				self = (ContactVC*)variableCondition;
+   IndexSet*				set = NULL;
+   Stream*					warningStr = Journal_Register( Error_Type, (Name)self->type );
+   unsigned					nDims;
+   Grid*						vertGrid;
+   CartesianGenerator*	gen;
+
+   nDims = Mesh_GetDimSize( self->_mesh );
+   gen = (CartesianGenerator* )self->_mesh->generator;
+
+   if( strcmp( gen->type, CartesianGenerator_Type ) )
+      abort();
+   vertGrid = *(Grid**)ExtensionManager_Get( self->_mesh->info, self->_mesh, ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
+
+   switch (self->_wall) {
+      case WallVC_Wall_Front:
+         if ( nDims < 3 || !vertGrid->sizes[2]  ) {
+            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+                            WallVC_WallEnumToStr[self->_wall], "K" );
+            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+         }
+         else {
+            abort();
+            /*set = RegularMeshUtils_CreateContactFrontSet( self->_mesh );*/
+         }
+         break;
+			
+      case WallVC_Wall_Back:
+         if ( nDims < 3 || !vertGrid->sizes[2] ) {
+            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+                            WallVC_WallEnumToStr[self->_wall], "K" );
+            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+         }
+         else {
+            abort();
+            /*set = RegularMeshUtils_CreateContactBackSet( self->_mesh );*/
+         }	
+         break;
+			
+      case WallVC_Wall_Top:
+         if ( nDims < 2 || !vertGrid->sizes[1] ) {
+            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+                            WallVC_WallEnumToStr[self->_wall], "J" );
+            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+         }
+         else {
+            set = RegularMeshUtils_CreateContactTopSet(self->_mesh, gen->contactDepth[0][0], gen->contactDepth[0][1]);
+         }	
+         break;
+			
+      case WallVC_Wall_Bottom:
+         if ( nDims < 2 || !vertGrid->sizes[1] ) {
+            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+                            WallVC_WallEnumToStr[self->_wall], "J" );
+            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+         }
+         else {
+            if( self->deep ) {
+               set = RegularMeshUtils_CreateContactBottomSet(
+                  self->_mesh, 0, 0, gen->contactDepth[1][0] );
+            }
+            else {
+               set = RegularMeshUtils_CreateContactBottomSet(
+                  self->_mesh, gen->contactDepth[0][0], gen->contactDepth[0][1], 0 );
+            }
+         }	
+         break;
+			
+      case WallVC_Wall_Left:
+         if ( nDims < 1 ) {
+            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+                            WallVC_WallEnumToStr[self->_wall], "I" );
+            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+         }
+         else {
+            set = RegularMeshUtils_CreateContactLeftSet(self->_mesh, gen->contactDepth[1][0], gen->contactDepth[1][1]);
+         }	
+         break;
+			
+      case WallVC_Wall_Right:
+         if( nDims < 1 ) {
+            Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+                            "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+                            WallVC_WallEnumToStr[self->_wall], "I" );
+            set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+         }
+         else {
+            if( self->deep ) {
+               set = RegularMeshUtils_CreateContactRightSet(
+                  self->_mesh, 0, 0, gen->contactDepth[0][1] );
+            }
+            else {
+               set = RegularMeshUtils_CreateContactRightSet(
+                  self->_mesh, gen->contactDepth[1][0], gen->contactDepth[1][1], 0 );
+            }
+         }
+         break;
+			
+      case WallVC_Wall_Size:
+      default:
+         assert(0);
+         break;
+   }
+	
+   return set;
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Build functions
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/CornerVC.c
--- a/Utils/src/CornerVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,670 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: CornerVC.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "CornerVC.h"
-#include "RegularMeshUtils.h"
-
-#include <string.h>
-#include <assert.h>
-
-
-
-const Type CornerVC_Type = "CornerVC";
-const Name defaultCornerVCName = "defaultCornerVCName";
-/* List of corner names */
-Name CornerVC_CornerEnumToStr[CornerVC_Corner_Size] = {
-   "bottomLeftFront",
-   "bottomRightFront",
-   "topLeftFront",
-   "topRightFront",
-   "bottomLeftBack",
-   "bottomRightBack",
-   "topLeftBack",
-   "topRightBack" };
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-VariableCondition* CornerVC_Factory(
-	AbstractContext*					context,
-   Variable_Register*				variable_Register, 
-   ConditionFunction_Register*	conFunc_Register, 
-   Dictionary*							dictionary,
-   void*									data )
-{
-   return (VariableCondition*)CornerVC_New( defaultCornerVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
-}
-
-CornerVC* CornerVC_New(
-   Name									name,
-	AbstractContext*					context,
-   Name									_dictionaryEntryName, 
-   Variable_Register*				variable_Register, 
-   ConditionFunction_Register*	conFunc_Register, 
-   Dictionary*							dictionary,
-   void*									_mesh )
-{
-   CornerVC* self = _CornerVC_DefaultNew( name );
-
-	self->isConstructed = True;
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
-	_CornerVC_Init( self, _dictionaryEntryName, _mesh );
-
-	return self;
-}
-
-CornerVC* _CornerVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(CornerVC);
-	Type                                                       type = CornerVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _CornerVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _CornerVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _CornerVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_CornerVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _CornerVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _CornerVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _CornerVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _CornerVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _CornerVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _CornerVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _CornerVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _CornerVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _CornerVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _CornerVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _CornerVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _CornerVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return _CornerVC_New(  CORNERVC_PASSARGS  );
-}
-
-CornerVC* _CornerVC_New(  CORNERVC_DEFARGS  ) {
-   CornerVC* self;
-	
-   /* Allocate memory/General info */
-   assert(_sizeOfSelf >= sizeof(CornerVC));
-   self = (CornerVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-   /* Virtual info */
-	
-   /* Stg_Class info */
-	
-   return self;
-}
-
-
-void _CornerVC_Init( void*	cornerVC, Name	_dictionaryEntryName, void* _mesh ) {
-   CornerVC* self = (CornerVC*)cornerVC;
-
-   self->_dictionaryEntryName =  _dictionaryEntryName;
-   self->_mesh =                 (Mesh*)_mesh;
-   self->_corner =               CornerVC_Corner_Size;
-   self->_entryTbl =             0;
-   self->_entryCount =           0;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-void _CornerVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-   CornerVC*                 self = (CornerVC*)variableCondition;
-   Dictionary_Entry_Value*   vcDictVal;
-   Dictionary_Entry_Value    _vcDictVal;
-   Dictionary_Entry_Value*   varsVal;
-   CornerVC_Entry_Index      entry_I;
-	
-   /* Find dictionary entry */
-   if (self->_dictionaryEntryName) {
-      vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
-   }
-   else {
-      vcDictVal = &_vcDictVal;
-      Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
-   }
-
-   if (vcDictVal) {
-		char*	cornerStr;
-	
-		/* Obtain which corner */
-		cornerStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"corner" ) );
-
-		if (!strcasecmp(cornerStr, "bottomLeftFront")) 
-			self->_corner = CornerVC_Corner_BottomLeftFront;
-		else if (!strcasecmp(cornerStr, "bottomRightFront"))
-			self->_corner = CornerVC_Corner_BottomRightFront;
-		else if (!strcasecmp(cornerStr, "topLeftFront"))
-			self->_corner = CornerVC_Corner_TopLeftFront;
-		else if (!strcasecmp(cornerStr, "topRightFront"))
-			self->_corner = CornerVC_Corner_TopRightFront;
-		else if (!strcasecmp(cornerStr, "bottomLeftBack"))
-			self->_corner = CornerVC_Corner_BottomLeftBack;
-		else if (!strcasecmp(cornerStr, "bottomRightBack"))
-			self->_corner = CornerVC_Corner_BottomRightBack;
-		else if (!strcasecmp(cornerStr, "topLeftBack"))
-			self->_corner = CornerVC_Corner_TopLeftBack;
-		else if (!strcasecmp(cornerStr, "topRightBack"))
-			self->_corner = CornerVC_Corner_TopRightBack;
-      else {
-			assert( 0 );
-			self->_corner = CornerVC_Corner_Size; /* invalid entry */
-      }
-		
-      /* Obtain the variable entries */
-      self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-      self->_entryTbl = Memory_Alloc_Array( CornerVC_Entry, self->_entryCount, "CornerVC->_entryTbl" );
-      varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
-			char*							valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name")  );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-
-			if (0 == strcasecmp(valType, "func")) {
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-
-				if ( cfIndex == (unsigned)-1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-						"definition of cornerVC \"%s\" (applies to corner \"%s\"), the cond. func. applied to "
-						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-						__func__, self->_dictionaryEntryName, CornerVC_CornerEnumToStr[self->_corner],
-					self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}
-			else if (0 == strcasecmp(valType, "array")) {
-				Dictionary_Entry_Value*	valueElement;
-				Index							i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
-					self->_entryTbl[entry_I].value.as.typeArray.size, "CornerVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++) {
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
-				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
-			{
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_DPrintf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-					self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-					self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else {
-		self->_corner = CornerVC_Corner_Size;
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-   }
-}
-
-
-void _CornerVC_Delete(void* cornerVC) {
-   CornerVC* self = (CornerVC*)cornerVC;
-	
-   /* Stg_Class_Delete parent */
-   _VariableCondition_Delete(self);
-}
-
-void _CornerVC_Destroy(void* cornerVC, void* data) {
-   CornerVC* self = (CornerVC*)cornerVC;
-
-   if (self->_entryTbl) Memory_Free(self->_entryTbl);
-
-   _VariableCondition_Destroy(self, data);
-}
-
-void _CornerVC_Print(void* cornerVC, Stream* stream) {
-   CornerVC*				self = (CornerVC*)cornerVC;
-   CornerVC_Entry_Index	entry_I;
-   Index						i;
-	
-   /* Set the Journal for printing informations */
-   Stream* info = stream;
-	
-   /* General info */
-   Journal_Printf( info, "CornerVC (ptr): %p\n", self);
-	
-   /* Virtual info */
-	
-   /* Stg_Class info */
-   Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
-   Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-   if (self->_dictionaryEntryName)
-      Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-	
-   Journal_Printf( info, "\t_corner: %s\n", self->_corner == CornerVC_Corner_BottomLeftFront ? "BottomLeftFront" :
-		   self->_corner == CornerVC_Corner_BottomRightFront ? "BottomRightFront" : self->_corner == CornerVC_Corner_TopLeftFront ? "TopLeftFront" :
-		   self->_corner == CornerVC_Corner_TopRightFront ? "TopRightFront" : self->_corner == CornerVC_Corner_BottomLeftBack ? "BottomLeftBack" :
-		   self->_corner == CornerVC_Corner_BottomRightBack ? "BottomRightBack" : self->_corner == CornerVC_Corner_TopLeftBack ? "TopLeftBack" :
-		   self->_corner == CornerVC_Corner_TopRightBack ? "TopRightBack" : "None");
-   Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
-   Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-   if (self->_entryTbl)
-      for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
-      {
-	 Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
-	 Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-	 if (self->_entryTbl[entry_I].varName)
-	    Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-	 Journal_Printf( info, "\t\t\tvalue:\n");
-	 switch (self->_entryTbl[entry_I].value.type)
-	 {
-	    case VC_ValueType_Double:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
-	       Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-	       break;
-					
-	    case VC_ValueType_Int:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
-	       Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-	       break;
-					
-	    case VC_ValueType_Short:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
-	       Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-	       break;
-					
-	    case VC_ValueType_Char:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
-	       Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-	       break;
-					
-	    case VC_ValueType_Ptr:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-	       Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-	       break;
-					
-	    case VC_ValueType_DoubleArray:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-	       Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-	       Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
-			       self->_entryTbl[entry_I].value.as.typeArray.array);
-	       if (self->_entryTbl[entry_I].value.as.typeArray.array)
-		  for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-		     Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
-				     self->_entryTbl[entry_I].value.as.typeArray.array[i]);
-	       break;
-					
-	    case VC_ValueType_CFIndex:
-	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-	       Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-	       break;
-	 }
-      }
-   Journal_Printf( info, "\t_mesh (ptr): %p\n", self->_mesh);
-	
-   /* Print parent */
-   _VariableCondition_Print(self);
-}
-
-
-void* _CornerVC_Copy( const void* cornerVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-   CornerVC*       self = (CornerVC*)cornerVC;
-   CornerVC*       newCornerVC;
-   PtrMap*         map = ptrMap;
-   Bool            ownMap = False;
-	
-   if( !map ) {
-      map = PtrMap_New( 10 );
-      ownMap = True;
-   }
-	
-   newCornerVC = (CornerVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-   newCornerVC->_dictionaryEntryName = self->_dictionaryEntryName;
-   newCornerVC->_corner = self->_corner;
-   newCornerVC->_entryCount = self->_entryCount;
-	
-   if( deep ) {
-      newCornerVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
-		
-      if( (newCornerVC->_entryTbl = (CornerVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-	 newCornerVC->_entryTbl = Memory_Alloc_Array( CornerVC_Entry, newCornerVC->_entryCount, "CornerVC->_entryTbl");
-	 memcpy( newCornerVC->_entryTbl, self->_entryTbl, sizeof(CornerVC_Entry) * newCornerVC->_entryCount );
-	 PtrMap_Append( map, newCornerVC->_entryTbl, self->_entryTbl );
-      }
-   }
-   else {
-      newCornerVC->_mesh = self->_mesh;
-      newCornerVC->_entryTbl = self->_entryTbl;
-   }
-	
-   if( ownMap ) {
-      Stg_Class_Delete( map );
-   }
-	
-   return (void*)newCornerVC;
-}
-
-
-void _CornerVC_Build(  void* cornerVC, void* data ) {
-   CornerVC*         self = (CornerVC*)cornerVC;
-	
-   _CornerVC_BuildSelf( self, data );
-	
-   _VariableCondition_Build( self, data );
-}
-	
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _CornerVC_AssignFromXML( void* cornerVC, Stg_ComponentFactory* cf, void* data ) { 
-}
-
-void _CornerVC_BuildSelf(  void* cornerVC, void* data ) {
-   CornerVC*        self = (CornerVC*)cornerVC;
-	
-   if( self->_mesh ) {
-      Stg_Component_Build( self->_mesh, data, False );
-   }
-}
-
-IndexSet* _CornerVC_GetSet(void* variableCondition)
-{
-   CornerVC*   self = (CornerVC*)variableCondition;
-   IndexSet    *set = NULL;
-   Stream*     warningStr = Journal_Register( Error_Type, (Name)self->type );
-   unsigned	nDims;
-   Grid*	vertGrid;
-
-   nDims = Mesh_GetDimSize( self->_mesh );
-	vertGrid = *(Grid** )ExtensionManager_Get( self->_mesh->info, self->_mesh, 
-						  ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
-
-   switch (self->_corner) {
-      case CornerVC_Corner_BottomLeftFront:
-	 if ( nDims < 3 || !vertGrid->sizes[2]  ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "K" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalBottomLeftFrontSet(self->_mesh);
-	 }
-	 break;
-			
-      case CornerVC_Corner_BottomRightFront:
-	 if ( !vertGrid->sizes[0] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "I" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else if ( nDims < 3 || !vertGrid->sizes[2] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "K" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalBottomRightFrontSet(self->_mesh);
-	 }	
-	 break;
-			
-      case CornerVC_Corner_TopLeftFront:
-	 if ( nDims < 2 || !vertGrid->sizes[1] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "J" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ));	
-	 }
-	 else if ( nDims < 3 || !vertGrid->sizes[2] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "K" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalTopLeftFrontSet(self->_mesh);
-	 }	
-	 break;
-			
-      case CornerVC_Corner_TopRightFront:
-	 if ( nDims < 2 || !vertGrid->sizes[1] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "J" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else if ( nDims < 3 || !vertGrid->sizes[2] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "K" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else if ( !vertGrid->sizes[0] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "I" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalTopRightFrontSet(self->_mesh);
-	 }	
-	 break;
-			
-      case CornerVC_Corner_BottomLeftBack:
-	 set = RegularMeshUtils_CreateGlobalBottomLeftBackSet(self->_mesh);
-	 break;
-			
-      case CornerVC_Corner_BottomRightBack:
-	 if ( !vertGrid->sizes[0] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "I" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalBottomRightBackSet(self->_mesh);
-	 }
-	 break;
-			
-      case CornerVC_Corner_TopLeftBack:
-	 if ( nDims < 2 || !vertGrid->sizes[1] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "J" );
-	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalTopLeftBackSet(self->_mesh);
-	 }	
-	 break;
-			
-      case CornerVC_Corner_TopRightBack:
-	 if ( !vertGrid->sizes[0] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "I" );
-	    set = IndexSet_New(Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
-	 }
-	 else if ( nDims < 2 || !vertGrid->sizes[1] ) {
-	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
-			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-			    CornerVC_CornerEnumToStr[self->_corner], "J" );
-	    set = IndexSet_New(Mesh_GetDomainSize( self->_mesh, MT_VERTEX ));
-	 }
-	 else {
-	    set = RegularMeshUtils_CreateGlobalTopRightBackSet(self->_mesh);
-	 }
-	 break;
-		
-      case CornerVC_Corner_Size:
-      default:
-	 assert(0);
-	 break;
-   }
-
-   return set;
-}
-
-
-VariableCondition_VariableIndex _CornerVC_GetVariableCount(void* variableCondition, Index globalIndex)
-{
-   CornerVC*   self = (CornerVC*)variableCondition;
-	
-   return self->_entryCount;
-}
-
-
-Variable_Index _CornerVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex)
-{
-   CornerVC*       self = (CornerVC*)variableCondition;
-   Variable_Index  searchedIndex = 0;
-   Stream*         errorStr = Journal_Register( Error_Type, (Name)self->type  );
-   Name            varName;
-	
-   varName = self->_entryTbl[varIndex].varName;
-   searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
-	
-   Journal_Firewall( ( searchedIndex < self->variable_Register->count ), errorStr, "Error- in %s: searching for index of "
-		     "varIndex %u (\"%s\") at global node number %u failed - register returned index %u, greater than "
-		     "count %u.\n", __func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
-
-   return searchedIndex; 
-}
-
-
-VariableCondition_ValueIndex _CornerVC_GetValueIndex(
-   void*				variableCondition, 
-   Index				globalIndex, 
-   VariableCondition_VariableIndex	varIndex)
-{
-   return varIndex;
-}
-
-
-VariableCondition_ValueIndex _CornerVC_GetValueCount(void* variableCondition)
-{
-   CornerVC*	self = (CornerVC*)variableCondition;
-	
-   return self->_entryCount;
-}
-
-
-VariableCondition_Value _CornerVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex)
-{
-   CornerVC*	self = (CornerVC*)variableCondition;
-
-   return self->_entryTbl[valIndex].value;
-}
-
-void _CornerVC_PrintConcise( void* variableCondition, Stream* stream ) {
-   CornerVC*	self = (CornerVC*)variableCondition;
-	
-   Journal_Printf( stream, "\ttype: %s, set: ", self->type );
-   Journal_Printf( stream, "%s\n", 
-		   self->_corner == CornerVC_Corner_BottomLeftFront ? "BottomLeftFront" :
-		   self->_corner == CornerVC_Corner_BottomRightFront ? "BottomRightFront" : 
-		   self->_corner == CornerVC_Corner_TopLeftFront ? "TopLeftFront" :
-		   self->_corner == CornerVC_Corner_TopRightFront ? "TopRightFront" : 
-		   self->_corner == CornerVC_Corner_BottomLeftBack ? "BottomLeftBack" :
-		   self->_corner == CornerVC_Corner_BottomRightBack ? "BottomRightBack" : 
-		   self->_corner == CornerVC_Corner_TopLeftBack ? "TopLeftBack" :
-		   self->_corner == CornerVC_Corner_TopRightBack ? "TopRightBack" : "None" );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Build functions
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/CornerVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/CornerVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,670 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: CornerVC.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "CornerVC.h"
+#include "RegularMeshUtils.h"
+
+#include <string.h>
+#include <assert.h>
+
+
+
+const Type CornerVC_Type = "CornerVC";
+const Name defaultCornerVCName = "defaultCornerVCName";
+/* List of corner names */
+Name CornerVC_CornerEnumToStr[CornerVC_Corner_Size] = {
+   "bottomLeftFront",
+   "bottomRightFront",
+   "topLeftFront",
+   "topRightFront",
+   "bottomLeftBack",
+   "bottomRightBack",
+   "topLeftBack",
+   "topRightBack" };
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+VariableCondition* CornerVC_Factory(
+	AbstractContext*					context,
+   Variable_Register*				variable_Register, 
+   ConditionFunction_Register*	conFunc_Register, 
+   Dictionary*							dictionary,
+   void*									data )
+{
+   return (VariableCondition*)CornerVC_New( defaultCornerVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
+}
+
+CornerVC* CornerVC_New(
+   Name									name,
+	AbstractContext*					context,
+   Name									_dictionaryEntryName, 
+   Variable_Register*				variable_Register, 
+   ConditionFunction_Register*	conFunc_Register, 
+   Dictionary*							dictionary,
+   void*									_mesh )
+{
+   CornerVC* self = _CornerVC_DefaultNew( name );
+
+	self->isConstructed = True;
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
+	_CornerVC_Init( self, _dictionaryEntryName, _mesh );
+
+	return self;
+}
+
+CornerVC* _CornerVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(CornerVC);
+	Type                                                       type = CornerVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _CornerVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _CornerVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _CornerVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_CornerVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _CornerVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _CornerVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _CornerVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _CornerVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _CornerVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _CornerVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _CornerVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _CornerVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _CornerVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _CornerVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _CornerVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _CornerVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return _CornerVC_New(  CORNERVC_PASSARGS  );
+}
+
+CornerVC* _CornerVC_New(  CORNERVC_DEFARGS  ) {
+   CornerVC* self;
+	
+   /* Allocate memory/General info */
+   assert(_sizeOfSelf >= sizeof(CornerVC));
+   self = (CornerVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+   /* Virtual info */
+	
+   /* Stg_Class info */
+	
+   return self;
+}
+
+
+void _CornerVC_Init( void*	cornerVC, Name	_dictionaryEntryName, void* _mesh ) {
+   CornerVC* self = (CornerVC*)cornerVC;
+
+   self->_dictionaryEntryName =  _dictionaryEntryName;
+   self->_mesh =                 (Mesh*)_mesh;
+   self->_corner =               CornerVC_Corner_Size;
+   self->_entryTbl =             0;
+   self->_entryCount =           0;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+void _CornerVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+   CornerVC*                 self = (CornerVC*)variableCondition;
+   Dictionary_Entry_Value*   vcDictVal;
+   Dictionary_Entry_Value    _vcDictVal;
+   Dictionary_Entry_Value*   varsVal;
+   CornerVC_Entry_Index      entry_I;
+	
+   /* Find dictionary entry */
+   if (self->_dictionaryEntryName) {
+      vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
+   }
+   else {
+      vcDictVal = &_vcDictVal;
+      Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
+   }
+
+   if (vcDictVal) {
+		char*	cornerStr;
+	
+		/* Obtain which corner */
+		cornerStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"corner" ) );
+
+		if (!strcasecmp(cornerStr, "bottomLeftFront")) 
+			self->_corner = CornerVC_Corner_BottomLeftFront;
+		else if (!strcasecmp(cornerStr, "bottomRightFront"))
+			self->_corner = CornerVC_Corner_BottomRightFront;
+		else if (!strcasecmp(cornerStr, "topLeftFront"))
+			self->_corner = CornerVC_Corner_TopLeftFront;
+		else if (!strcasecmp(cornerStr, "topRightFront"))
+			self->_corner = CornerVC_Corner_TopRightFront;
+		else if (!strcasecmp(cornerStr, "bottomLeftBack"))
+			self->_corner = CornerVC_Corner_BottomLeftBack;
+		else if (!strcasecmp(cornerStr, "bottomRightBack"))
+			self->_corner = CornerVC_Corner_BottomRightBack;
+		else if (!strcasecmp(cornerStr, "topLeftBack"))
+			self->_corner = CornerVC_Corner_TopLeftBack;
+		else if (!strcasecmp(cornerStr, "topRightBack"))
+			self->_corner = CornerVC_Corner_TopRightBack;
+      else {
+			assert( 0 );
+			self->_corner = CornerVC_Corner_Size; /* invalid entry */
+      }
+		
+      /* Obtain the variable entries */
+      self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+      self->_entryTbl = Memory_Alloc_Array( CornerVC_Entry, self->_entryCount, "CornerVC->_entryTbl" );
+      varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
+			char*							valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name")  );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+
+			if (0 == strcasecmp(valType, "func")) {
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+
+				if ( cfIndex == (unsigned)-1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+						"definition of cornerVC \"%s\" (applies to corner \"%s\"), the cond. func. applied to "
+						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+						__func__, self->_dictionaryEntryName, CornerVC_CornerEnumToStr[self->_corner],
+					self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}
+			else if (0 == strcasecmp(valType, "array")) {
+				Dictionary_Entry_Value*	valueElement;
+				Index							i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
+					self->_entryTbl[entry_I].value.as.typeArray.size, "CornerVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++) {
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
+				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
+			{
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_DPrintf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+					self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+					self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else {
+		self->_corner = CornerVC_Corner_Size;
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+   }
+}
+
+
+void _CornerVC_Delete(void* cornerVC) {
+   CornerVC* self = (CornerVC*)cornerVC;
+	
+   /* Stg_Class_Delete parent */
+   _VariableCondition_Delete(self);
+}
+
+void _CornerVC_Destroy(void* cornerVC, void* data) {
+   CornerVC* self = (CornerVC*)cornerVC;
+
+   if (self->_entryTbl) Memory_Free(self->_entryTbl);
+
+   _VariableCondition_Destroy(self, data);
+}
+
+void _CornerVC_Print(void* cornerVC, Stream* stream) {
+   CornerVC*				self = (CornerVC*)cornerVC;
+   CornerVC_Entry_Index	entry_I;
+   Index						i;
+	
+   /* Set the Journal for printing informations */
+   Stream* info = stream;
+	
+   /* General info */
+   Journal_Printf( info, "CornerVC (ptr): %p\n", self);
+	
+   /* Virtual info */
+	
+   /* Stg_Class info */
+   Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
+   Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+   if (self->_dictionaryEntryName)
+      Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+	
+   Journal_Printf( info, "\t_corner: %s\n", self->_corner == CornerVC_Corner_BottomLeftFront ? "BottomLeftFront" :
+		   self->_corner == CornerVC_Corner_BottomRightFront ? "BottomRightFront" : self->_corner == CornerVC_Corner_TopLeftFront ? "TopLeftFront" :
+		   self->_corner == CornerVC_Corner_TopRightFront ? "TopRightFront" : self->_corner == CornerVC_Corner_BottomLeftBack ? "BottomLeftBack" :
+		   self->_corner == CornerVC_Corner_BottomRightBack ? "BottomRightBack" : self->_corner == CornerVC_Corner_TopLeftBack ? "TopLeftBack" :
+		   self->_corner == CornerVC_Corner_TopRightBack ? "TopRightBack" : "None");
+   Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
+   Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+   if (self->_entryTbl)
+      for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
+      {
+	 Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
+	 Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+	 if (self->_entryTbl[entry_I].varName)
+	    Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+	 Journal_Printf( info, "\t\t\tvalue:\n");
+	 switch (self->_entryTbl[entry_I].value.type)
+	 {
+	    case VC_ValueType_Double:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
+	       Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+	       break;
+					
+	    case VC_ValueType_Int:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
+	       Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+	       break;
+					
+	    case VC_ValueType_Short:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
+	       Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+	       break;
+					
+	    case VC_ValueType_Char:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
+	       Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+	       break;
+					
+	    case VC_ValueType_Ptr:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+	       Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+	       break;
+					
+	    case VC_ValueType_DoubleArray:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+	       Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+	       Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
+			       self->_entryTbl[entry_I].value.as.typeArray.array);
+	       if (self->_entryTbl[entry_I].value.as.typeArray.array)
+		  for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+		     Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
+				     self->_entryTbl[entry_I].value.as.typeArray.array[i]);
+	       break;
+					
+	    case VC_ValueType_CFIndex:
+	       Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+	       Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+	       break;
+	 }
+      }
+   Journal_Printf( info, "\t_mesh (ptr): %p\n", self->_mesh);
+	
+   /* Print parent */
+   _VariableCondition_Print(self);
+}
+
+
+void* _CornerVC_Copy( const void* cornerVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+   CornerVC*       self = (CornerVC*)cornerVC;
+   CornerVC*       newCornerVC;
+   PtrMap*         map = ptrMap;
+   Bool            ownMap = False;
+	
+   if( !map ) {
+      map = PtrMap_New( 10 );
+      ownMap = True;
+   }
+	
+   newCornerVC = (CornerVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+   newCornerVC->_dictionaryEntryName = self->_dictionaryEntryName;
+   newCornerVC->_corner = self->_corner;
+   newCornerVC->_entryCount = self->_entryCount;
+	
+   if( deep ) {
+      newCornerVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
+		
+      if( (newCornerVC->_entryTbl = (CornerVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+	 newCornerVC->_entryTbl = Memory_Alloc_Array( CornerVC_Entry, newCornerVC->_entryCount, "CornerVC->_entryTbl");
+	 memcpy( newCornerVC->_entryTbl, self->_entryTbl, sizeof(CornerVC_Entry) * newCornerVC->_entryCount );
+	 PtrMap_Append( map, newCornerVC->_entryTbl, self->_entryTbl );
+      }
+   }
+   else {
+      newCornerVC->_mesh = self->_mesh;
+      newCornerVC->_entryTbl = self->_entryTbl;
+   }
+	
+   if( ownMap ) {
+      Stg_Class_Delete( map );
+   }
+	
+   return (void*)newCornerVC;
+}
+
+
+void _CornerVC_Build(  void* cornerVC, void* data ) {
+   CornerVC*         self = (CornerVC*)cornerVC;
+	
+   _CornerVC_BuildSelf( self, data );
+	
+   _VariableCondition_Build( self, data );
+}
+	
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _CornerVC_AssignFromXML( void* cornerVC, Stg_ComponentFactory* cf, void* data ) { 
+}
+
+void _CornerVC_BuildSelf(  void* cornerVC, void* data ) {
+   CornerVC*        self = (CornerVC*)cornerVC;
+	
+   if( self->_mesh ) {
+      Stg_Component_Build( self->_mesh, data, False );
+   }
+}
+
+IndexSet* _CornerVC_GetSet(void* variableCondition)
+{
+   CornerVC*   self = (CornerVC*)variableCondition;
+   IndexSet    *set = NULL;
+   Stream*     warningStr = Journal_Register( Error_Type, (Name)self->type );
+   unsigned	nDims;
+   Grid*	vertGrid;
+
+   nDims = Mesh_GetDimSize( self->_mesh );
+	vertGrid = *(Grid** )ExtensionManager_Get( self->_mesh->info, self->_mesh, 
+						  ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
+
+   switch (self->_corner) {
+      case CornerVC_Corner_BottomLeftFront:
+	 if ( nDims < 3 || !vertGrid->sizes[2]  ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "K" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalBottomLeftFrontSet(self->_mesh);
+	 }
+	 break;
+			
+      case CornerVC_Corner_BottomRightFront:
+	 if ( !vertGrid->sizes[0] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "I" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else if ( nDims < 3 || !vertGrid->sizes[2] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "K" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalBottomRightFrontSet(self->_mesh);
+	 }	
+	 break;
+			
+      case CornerVC_Corner_TopLeftFront:
+	 if ( nDims < 2 || !vertGrid->sizes[1] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "J" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ));	
+	 }
+	 else if ( nDims < 3 || !vertGrid->sizes[2] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "K" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalTopLeftFrontSet(self->_mesh);
+	 }	
+	 break;
+			
+      case CornerVC_Corner_TopRightFront:
+	 if ( nDims < 2 || !vertGrid->sizes[1] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "J" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else if ( nDims < 3 || !vertGrid->sizes[2] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "K" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else if ( !vertGrid->sizes[0] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "I" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalTopRightFrontSet(self->_mesh);
+	 }	
+	 break;
+			
+      case CornerVC_Corner_BottomLeftBack:
+	 set = RegularMeshUtils_CreateGlobalBottomLeftBackSet(self->_mesh);
+	 break;
+			
+      case CornerVC_Corner_BottomRightBack:
+	 if ( !vertGrid->sizes[0] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "I" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalBottomRightBackSet(self->_mesh);
+	 }
+	 break;
+			
+      case CornerVC_Corner_TopLeftBack:
+	 if ( nDims < 2 || !vertGrid->sizes[1] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "J" );
+	    set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalTopLeftBackSet(self->_mesh);
+	 }	
+	 break;
+			
+      case CornerVC_Corner_TopRightBack:
+	 if ( !vertGrid->sizes[0] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "I" );
+	    set = IndexSet_New(Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );	
+	 }
+	 else if ( nDims < 2 || !vertGrid->sizes[1] ) {
+	    Journal_Printf( warningStr, "Warning - in %s: Can't build a %s corner VC "
+			    "when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+			    CornerVC_CornerEnumToStr[self->_corner], "J" );
+	    set = IndexSet_New(Mesh_GetDomainSize( self->_mesh, MT_VERTEX ));
+	 }
+	 else {
+	    set = RegularMeshUtils_CreateGlobalTopRightBackSet(self->_mesh);
+	 }
+	 break;
+		
+      case CornerVC_Corner_Size:
+      default:
+	 assert(0);
+	 break;
+   }
+
+   return set;
+}
+
+
+VariableCondition_VariableIndex _CornerVC_GetVariableCount(void* variableCondition, Index globalIndex)
+{
+   CornerVC*   self = (CornerVC*)variableCondition;
+	
+   return self->_entryCount;
+}
+
+
+Variable_Index _CornerVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex)
+{
+   CornerVC*       self = (CornerVC*)variableCondition;
+   Variable_Index  searchedIndex = 0;
+   Stream*         errorStr = Journal_Register( Error_Type, (Name)self->type  );
+   Name            varName;
+	
+   varName = self->_entryTbl[varIndex].varName;
+   searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
+	
+   Journal_Firewall( ( searchedIndex < self->variable_Register->count ), errorStr, "Error- in %s: searching for index of "
+		     "varIndex %u (\"%s\") at global node number %u failed - register returned index %u, greater than "
+		     "count %u.\n", __func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
+
+   return searchedIndex; 
+}
+
+
+VariableCondition_ValueIndex _CornerVC_GetValueIndex(
+   void*				variableCondition, 
+   Index				globalIndex, 
+   VariableCondition_VariableIndex	varIndex)
+{
+   return varIndex;
+}
+
+
+VariableCondition_ValueIndex _CornerVC_GetValueCount(void* variableCondition)
+{
+   CornerVC*	self = (CornerVC*)variableCondition;
+	
+   return self->_entryCount;
+}
+
+
+VariableCondition_Value _CornerVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex)
+{
+   CornerVC*	self = (CornerVC*)variableCondition;
+
+   return self->_entryTbl[valIndex].value;
+}
+
+void _CornerVC_PrintConcise( void* variableCondition, Stream* stream ) {
+   CornerVC*	self = (CornerVC*)variableCondition;
+	
+   Journal_Printf( stream, "\ttype: %s, set: ", self->type );
+   Journal_Printf( stream, "%s\n", 
+		   self->_corner == CornerVC_Corner_BottomLeftFront ? "BottomLeftFront" :
+		   self->_corner == CornerVC_Corner_BottomRightFront ? "BottomRightFront" : 
+		   self->_corner == CornerVC_Corner_TopLeftFront ? "TopLeftFront" :
+		   self->_corner == CornerVC_Corner_TopRightFront ? "TopRightFront" : 
+		   self->_corner == CornerVC_Corner_BottomLeftBack ? "BottomLeftBack" :
+		   self->_corner == CornerVC_Corner_BottomRightBack ? "BottomRightBack" : 
+		   self->_corner == CornerVC_Corner_TopLeftBack ? "TopLeftBack" :
+		   self->_corner == CornerVC_Corner_TopRightBack ? "TopRightBack" : "None" );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Build functions
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/DofLayout.c
--- a/Utils/src/DofLayout.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,632 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: DofLayout.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "DomainContext.h"
-#include "DofLayout.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-
-const Type DofLayout_Type = "DofLayout";
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Private function declarations
-*/
-
-/** Add a new Variable to the group that may be used as dofs, where varIndex is the index of the variable
-in the variable register. */
-Dof_Index	_DofLayout_AddVariable_ByIndex(void* dofLayout, Variable_Index varIndex);
-
-/** Add a new Variable to the group that may be used as dofs - by name. */
-Dof_Index	_DofLayout_AddVariable_ByName(void* dofLayout, Name varName);
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-DofLayout* DofLayout_New( Name name, DomainContext* context, Variable_Register* variableRegister, Index numItemsInLayout, void* mesh ) {
-	DofLayout* self = _DofLayout_DefaultNew( name );
-
-	self->isConstructed = True;
-	_DofLayout_Init( self, context, variableRegister, numItemsInLayout, 0, NULL, mesh );
-
-	return self;
-}
-
-DofLayout* _DofLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(DofLayout);
-	Type                                                      type = DofLayout_Type;
-	Stg_Class_DeleteFunction*                              _delete = _DofLayout_Delete;
-	Stg_Class_PrintFunction*                                _print = _DofLayout_Print;
-	Stg_Class_CopyFunction*                                  _copy = _DofLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_DofLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _DofLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _DofLayout_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _DofLayout_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _DofLayout_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _DofLayout_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-
-	return _DofLayout_New(  DOFLAYOUT_PASSARGS  );
-}
-
-DofLayout* _DofLayout_New(  DOFLAYOUT_DEFARGS  ) {
-	DofLayout* self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(DofLayout) );
-	self = (DofLayout*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* Virtual info */
-	self->_build = _build;
-	self->_initialise = _initialise;
-	
-	/* Stg_Class info */
-	
-	return self;
-}
-
-void _DofLayout_Init(
-	void*						dofLayout,
-	DomainContext*			context,
-	Variable_Register*	variableRegister, 
-	Index						numItemsInLayout,
-	Variable_Index			baseVariableCount,
-	Variable**				baseVariableArray,
-	void*						_mesh )
-{
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Mesh*			mesh = (Mesh*)_mesh;
-	
-	self->_variableRegister = variableRegister;
-
-	self->_numItemsInLayout = numItemsInLayout;
-	self->_variableEnabledSets = NULL;
-	self->_totalVarCount = 0;
-	self->_varIndicesMapping = NULL;
-	
-	self->dofCounts = NULL;
-
-	self->mesh = mesh;
-	self->nBaseVariables = baseVariableCount;
-	self->baseVariables = baseVariableArray;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-void _DofLayout_Delete(void* dofLayout) {
-	DofLayout* self = (DofLayout*)dofLayout;
-	
-	/* Stg_Class_Delete parent */
-	_Stg_Component_Delete( self );
-}
-
-
-void _DofLayout_Print(void* dofLayout, Stream* stream) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	
-	/* Set the Journal for printing informations */
-	Stream* compositeVCStream = stream;
-	
-	/* General info */
-	Journal_Printf( compositeVCStream, "DofLayout (ptr): %p\n", self);
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	
-	/* Print parent */
-	_Stg_Component_Print( self, compositeVCStream );
-}
-
-
-void* _DofLayout_Copy( const void* dofLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	DofLayout*	newDofLayout;
-	PtrMap*		map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newDofLayout = (DofLayout*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
-	
-	newDofLayout->_variableRegister = self->_variableRegister;
-	newDofLayout->_numItemsInLayout = self->_numItemsInLayout;
-	newDofLayout->_totalVarCount = self->_totalVarCount;
-	
-	if( deep ) {
-          if( (newDofLayout->_variableEnabledSets = (IndexSet**)PtrMap_Find( map, self->_variableEnabledSets )) == NULL && self->_variableEnabledSets ) {
-			Index	set_I;
-			
-			newDofLayout->_variableEnabledSets = Memory_Alloc_Array( IndexSet*, newDofLayout->_totalVarCount, "DofLayout->_variableEnabledSets" );
-			for( set_I = 0; set_I < newDofLayout->_totalVarCount; set_I++ ) {
-				newDofLayout->_variableEnabledSets[set_I] = (IndexSet*)Stg_Class_Copy( self->_variableEnabledSets[set_I], NULL, deep, nameExt, map );
-			}
-			PtrMap_Append( map, self->_variableEnabledSets, newDofLayout->_variableEnabledSets );
-		}
-		
-          if( (newDofLayout->_varIndicesMapping = (Variable_Index*)PtrMap_Find( map, self->_varIndicesMapping )) == NULL && self->_varIndicesMapping ) {
-			newDofLayout->_varIndicesMapping = Memory_Alloc_Array( Variable_Index, newDofLayout->_totalVarCount, "DofLayout->_varIndicesMapping" );
-			memcpy( newDofLayout->_varIndicesMapping, self->_varIndicesMapping, sizeof(Variable_Index) * newDofLayout->_totalVarCount );
-			PtrMap_Append( map, self->_varIndicesMapping, newDofLayout->_varIndicesMapping );
-		}
-		
-          if( (newDofLayout->dofCounts = (Dof_Index*)PtrMap_Find( map, self->dofCounts )) == NULL && self->dofCounts ) {
-			newDofLayout->dofCounts = Memory_Alloc_Array( Index, newDofLayout->_numItemsInLayout, "DofLayout->dofCounts" );
-			memcpy( newDofLayout->dofCounts, self->dofCounts, sizeof(Index) * newDofLayout->_numItemsInLayout );
-			PtrMap_Append( map, self->dofCounts, newDofLayout->dofCounts );
-		}
-		
-          if( (newDofLayout->varIndices = (Variable_Index**)PtrMap_Find( map, self->varIndices )) == NULL && self->varIndices ) {
-			Index	idx_I;
-			
-			newDofLayout->varIndices = Memory_Alloc_2DComplex( Variable_Index, newDofLayout->_numItemsInLayout, self->dofCounts, "DofLayout->varIndices" );
-			for( idx_I = 0; idx_I < newDofLayout->_numItemsInLayout; idx_I++ ) {
-				memcpy( newDofLayout->varIndices[idx_I], self->varIndices[idx_I], sizeof(Variable_Index) * newDofLayout->dofCounts[idx_I] );
-			}
-			PtrMap_Append( map, self->varIndices, newDofLayout->varIndices );
-		}
-	}
-	else {
-		newDofLayout->_variableEnabledSets = self->_variableEnabledSets;
-		newDofLayout->_varIndicesMapping = self->_varIndicesMapping;
-		newDofLayout->dofCounts = self->dofCounts;
-		newDofLayout->varIndices = self->varIndices;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newDofLayout;
-}
-
-void _DofLayout_AssignFromXML( void* dofLayout, Stg_ComponentFactory* cf, void* data ) {
-	DofLayout *             self = (DofLayout*)dofLayout;
-	Dictionary*             thisComponentDict = NULL;
-	void*                   variableRegister = NULL;
-	Dictionary_Entry_Value* list;
-	Variable_Index          baseVariableCount = 0;
-	Variable**              baseVariableList = NULL;
-	Mesh*							mesh;
-	DomainContext*				context;
-
-	/* Get component's dictionary setup */
-	assert( cf->componentDict );
-	thisComponentDict = Dictionary_GetDictionary( cf->componentDict, self->name );
-	assert( thisComponentDict );
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-
-	/* Get the mesh. */
-	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data );
-
-	variableRegister = context->variable_Register; 
-	assert( variableRegister  );
-
-	if (( list = Dictionary_Get( thisComponentDict, (Dictionary_Entry_Key)"BaseVariables" ) ) ) {
-		Variable_Index	baseVariable_I    = 0;
-		Name				variableName;
-
-		baseVariableCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"BaseVariableCount", Dictionary_Entry_Value_GetCount( list ) );
-		Journal_Firewall(
-			baseVariableCount <= Dictionary_Entry_Value_GetCount( list  ),
-			Journal_Register( Error_Type, (Name)self->type  ),
-			"BaseVariableCount %u is too large for list given.\n", baseVariableCount );
-
-		baseVariableList = Memory_Alloc_Array( Variable*, baseVariableCount, "baseVariableList" );
-		
-		for ( baseVariable_I = 0 ; baseVariable_I < baseVariableCount ; baseVariable_I++ ) {
-			variableName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, baseVariable_I ) );
-
-			Journal_PrintfL( cf->infoStream, 2, "Looking for Variable '%s' in Variable_Register\n", variableName );
-			baseVariableList[ baseVariable_I ] = Variable_Register_GetByName( variableRegister, variableName );
-
-			if ( !baseVariableList[ baseVariable_I ] )
-				baseVariableList[ baseVariable_I ] = Stg_ComponentFactory_ConstructByName( cf, (Name)variableName, Variable, True, data  );
-		}
-	}
-	
-	_DofLayout_Init( self, context, (Variable_Register*)variableRegister, 0, baseVariableCount, baseVariableList, mesh );
-}
-
-void _DofLayout_Build( void* dofLayout, void* data ) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Index			indexCount;
-	Index*		indices;
-	Index			set_I, i, pos;
-
-	assert( self );
-
-	/* Build mesh and extract domain size, if required. */
-	if( self->mesh ) {
-		Stg_Component_Build( self->mesh, data, False );
-		self->_numItemsInLayout = Mesh_GetDomainSize( self->mesh, MT_VERTEX );
-	}
-
-	/* Adds each variable in this list as a base degree of freedom to each item in DofLayout */
-	DofLayout_AddAllFromVariableArray( self, self->nBaseVariables, self->baseVariables );
-
-	/* ensure variables are built */
-	for( i = 0; i < self->_totalVarCount; i++ )
-		Stg_Component_Build( Variable_Register_GetByIndex( self->_variableRegister, self->_varIndicesMapping[i] ), data, False );
-	
-	self->dofCounts = Memory_Alloc_Array( Index, self->_numItemsInLayout, "DofLayout->dofCounts" );
-	memset(self->dofCounts, 0, sizeof(Index)*self->_numItemsInLayout);
-	
-	for (set_I = 0; set_I < self->_totalVarCount; set_I++) {
-		IndexSet_GetMembers(self->_variableEnabledSets[set_I], &indexCount, &indices);
-
-		for (i = 0; i < indexCount; i++) {
-			self->dofCounts[indices[i]]++;
-		}
-			
-		if (indices)
-			Memory_Free(indices);
-	}
-	
-	self->varIndices = Memory_Alloc_2DComplex( Variable_Index, self->_numItemsInLayout, self->dofCounts, "DofLayout->varIndices" );
-	for (i = 0; i < self->_numItemsInLayout; i++) {
-		pos = 0;
-
-		for (set_I = 0; set_I < self->_totalVarCount; set_I++) {
-			if (IndexSet_IsMember(self->_variableEnabledSets[set_I], i))
-				self->varIndices[i][pos++] = self->_varIndicesMapping[set_I];
-		}
-	}
-}
-
-
-void _DofLayout_Initialise( void* dofLayout, void* data ) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Index			var_I;
-
-	/* Initialise all the Variables used - in some cases they don't allocate themselves properly until
-		this is done */
-	for( var_I = 0; var_I < self->_totalVarCount; var_I++ ) {
-		Stg_Component_Initialise( Variable_Register_GetByIndex( self->_variableRegister, self->_varIndicesMapping[var_I] ),
-			data, False );
-	}	
-}
-
-
-void _DofLayout_Execute( void* dofLayout, void* data ) {
-}
-
-void _DofLayout_Destroy( void* dofLayout, void* data ) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-
-	if( self->baseVariables )
-		Memory_Free( self->baseVariables );
-
-	if( self->dofCounts )
-		Memory_Free( self->dofCounts );
-
-	if( self->varIndices )
-		Memory_Free( self->varIndices );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Private functions
-*/
-
-Dof_Index _DofLayout_AddVariable_ByIndex(void* dofLayout, Variable_Index varIndex) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Dof_Index	dof_I;
-	
-	for (dof_I = 0; dof_I < self->_totalVarCount; dof_I++)
-		if (varIndex == self->_varIndicesMapping[dof_I])
-			return dof_I;
-	
-	self->_totalVarCount++;
-	
-	/* Do an Alloc if array does not exist to register stats in memory module. Other times, just Realloc */
-	if ( self->_varIndicesMapping ) {
-		self->_varIndicesMapping = Memory_Realloc_Array( self->_varIndicesMapping, Variable_Index, self->_totalVarCount );
-	}
-	else {
-		self->_varIndicesMapping = Memory_Alloc_Array( Variable_Index, self->_totalVarCount,
-			"DofLayout->_varIndicesMapping" );
-	}
-	self->_varIndicesMapping[self->_totalVarCount - 1] = varIndex;
-
-	if ( self->_variableEnabledSets ) {
-		self->_variableEnabledSets = Memory_Realloc_Array( self->_variableEnabledSets, IndexSet*, self->_totalVarCount );
-	}
-	else {
-		self->_variableEnabledSets = Memory_Alloc_Array( IndexSet*, self->_totalVarCount,
-			"DofLayout->_variableEnabledSets" );
-	}
-	self->_variableEnabledSets[self->_totalVarCount - 1] = IndexSet_New(self->_numItemsInLayout);
-	
-	return self->_totalVarCount - 1;
-}
-
-
-Dof_Index _DofLayout_AddVariable_ByName(void* dofLayout, Name varName) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Dof_Index	dof_I;
-	
-	dof_I = Variable_Register_GetIndex( self->_variableRegister, varName );
-	Journal_Firewall( 
-		dof_I != (unsigned)-1,
-		Journal_Register( Error_Type, (Name)DofLayout_Type  ),
-		"Attempting to name a variable as a DOF that is not in the variable registry!\n" );
-	return _DofLayout_AddVariable_ByIndex( self, dof_I );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public functions
-*/
-
-void DofLayout_AddDof_ByVarIndex(void* dofLayout, Variable_Index varIndex, Index index) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	
-	IndexSet_Add(self->_variableEnabledSets[varIndex], index);
-}
-
-
-void DofLayout_AddDof_ByVarName(void* dofLayout, Name varName, Index index) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	
-	DofLayout_AddDof_ByVarIndex(self, _DofLayout_AddVariable_ByName(self, varName), index);
-}
-
-Variable* DofLayout_GetVariable(void* dofLayout, Index index, Dof_Index dofAtItemIndex ) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Variable_Index	var_I = self->varIndices[index][dofAtItemIndex];
-	
-	return Variable_Register_GetByIndex( self->_variableRegister, var_I );
-}
-
-
-void DofLayout_CopyValues( void* dofLayout, void* destDofLayout ) {
-	DofLayout*    self = (DofLayout*)dofLayout;
-	DofLayout*    dest = (DofLayout*)destDofLayout;
-	Index         ii = 0;
-	Dof_Index     dof_I = 0;
-	Stream*       error = Journal_Register( Error_Type, (Name)self->type );
-	
-	Journal_Firewall( (self->_numItemsInLayout == dest->_numItemsInLayout ), error,
-		"Error: Number of items in source dof layout (%d) not equal to number of "
-		"items in destination dof layout (%d).\n",
-		self->_numItemsInLayout, dest->_numItemsInLayout );
-
-	for ( ii=0; ii < self->_numItemsInLayout; ii++ ) {
-		#ifdef CAUTIOUS
-		Journal_Firewall( (self->dofCounts[ii] == dest->dofCounts[ii] ), error,
-			"Error: Number of dofs in source dof layout (item %d, %d dofs) not equal to "
-			"number of dofs in destination dof layout at same entry (%d).\n",
-			self->_numItemsInLayout, self->dofCounts[ii], dest->dofCounts[ii] );
-		#endif	
-
-		for ( dof_I = 0; dof_I < self->dofCounts[ii]; dof_I++ ) {
-			DofLayout_SetValueDouble( dest, ii, dof_I,
-				DofLayout_GetValueDouble( self, ii, dof_I ) );
-		}
-	}
-}
-
-
-void DofLayout_SetAllToZero( void* dofLayout ) {
-	DofLayout*    self = (DofLayout*)dofLayout;
-	Index         ii = 0;
-	Dof_Index     dof_I = 0;
-	
-	for ( ii=0; ii < self->_numItemsInLayout; ii++ ) {
-
-		for ( dof_I = 0; dof_I < self->dofCounts[ii]; dof_I++ ) {
-			DofLayout_SetValueDouble( self, ii, dof_I, 0 );
-		}
-	}
-}
-
-
-void DofLayout_Remap( void* dofLayout, Index newIndexCount, IndexMap* map ) {
-	DofLayout*	self = (DofLayout*)dofLayout;
-	Index		item_I;
-	
-	assert( newIndexCount && map ); /* TODO: change this to Journal commands */
-	
-	/*
-	** NOTE: it is possible that a remapping will eliminate some of the variables accessed
-	**	 by the DofLayout.  This will require a bit more effort to account for, but for
-	**	 the moment it shouldn't matter.
-	*/
-	
-	if( self->_variableEnabledSets ) {
-		IndexSet**	variableEnabledSets;
-		Index		set_I;
-		
-		variableEnabledSets = Memory_Alloc_Array( IndexSet*, self->_totalVarCount, "DofLayout->_variableEnabledSets" );
-		for( set_I = 0; set_I < self->_totalVarCount; set_I++ ) {
-			Index	itemCount;
-			Index*	items;
-			
-			variableEnabledSets[set_I] = IndexSet_New( newIndexCount );
-			
-			IndexSet_GetMembers( self->_variableEnabledSets[set_I], &itemCount, &items );
-			for( item_I = 0; item_I < itemCount; item_I++ ) {
-				Index	mappedValue = IndexMap_Find( map, items[item_I] );
-				
-				if( mappedValue < self->_numItemsInLayout ) {
-					IndexSet_Add( variableEnabledSets[set_I], mappedValue );
-				}
-			}
-			
-			Memory_Free( items );
-			Stg_Class_Delete( self->_variableEnabledSets[set_I] );
-		}
-		Memory_Free( self->_variableEnabledSets );
-		self->_variableEnabledSets = variableEnabledSets;
-	}
-	
-	/* Map dofCounts */
-	if( self->dofCounts ) {
-		Dof_Index*	dofCounts;
-		
-		dofCounts = Memory_Alloc_Array( Dof_Index, newIndexCount, "DofLayout->dofCounts" );
-		for( item_I = 0; item_I < self->_numItemsInLayout; item_I++ ) {
-			Index	mappedValue = IndexMap_Find( map, item_I );
-			
-			if( mappedValue < self->_numItemsInLayout ) {
-				dofCounts[mappedValue] = self->dofCounts[item_I];
-			}
-		}
-		Memory_Free( self->dofCounts );
-		self->dofCounts = dofCounts;
-	}
-	
-	/* Map varIndices */
-	if( self->varIndices ) {
-		Variable_Index**	varIndices;
-		
-		varIndices = Memory_Alloc_2DComplex( Variable_Index, newIndexCount, self->dofCounts, "DofLayout->varIndices" );
-		for( item_I = 0; item_I < self->_numItemsInLayout; item_I++ ) {
-			Index	mappedValue = IndexMap_Find( map, item_I );
-			
-			if( mappedValue < self->_numItemsInLayout ) {
-				memcpy( varIndices[mappedValue], 
-					self->varIndices[item_I], 
-					sizeof(Variable_Index) * self->dofCounts[mappedValue] );
-			}
-		}
-		Memory_Free( self->varIndices );
-		self->varIndices = varIndices;
-	}
-	
-	/* Overwrite old values */
-	self->_numItemsInLayout = newIndexCount;
-}
-
-void DofLayout_AddAllFromVariableArray( void* dofLayout, Variable_Index variableCount, Variable** variableArray ) {
-	DofLayout*      self        = (DofLayout*) dofLayout;
-	Index           item_I;
-	Index           itemCount   = self->_numItemsInLayout;
-	Variable_Index  variable_I;
-	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type );
-
-	for( variable_I = 0; variable_I < variableCount ; variable_I++  ) {
-		Journal_Firewall( variableArray[variable_I] != NULL, errorStream,
-				"In func %s for %s '%s' - Variable %d in array is NULL.\n", __func__, self->type, self->name, variable_I);
-		for( item_I = 0; item_I < itemCount ; item_I++ ) {
-			DofLayout_AddDof_ByVarName( self, variableArray[variable_I]->name, item_I );
-		}
-	}
-}
-
-
-void DofLayout_SaveAllVariablesToFiles( void* dofLayout, char* prefixString, unsigned rank ) {
-	DofLayout*  self = (DofLayout*) dofLayout;
-	Index       ownedVar_I, var_I;
-	Variable*   variable = NULL;
-	char*       varFileName;
-	int         prefixStringLength=0;
-
-	for ( ownedVar_I = 0; ownedVar_I < self->_totalVarCount; ownedVar_I++ ) {
-		var_I = self->_varIndicesMapping[ownedVar_I];
-		variable = Variable_Register_GetByIndex( self->_variableRegister, var_I );
-
-		if ( prefixString ) {
-			prefixStringLength = strlen(prefixString);
-		}
-		else {
-			prefixStringLength = 0;
-		}
-
-		varFileName = Memory_Alloc_Array_Unnamed( char, prefixStringLength + strlen( variable->name ) + 5 + 4 + 1 );
-		if ( prefixString ) {
-			sprintf( varFileName, "%s.%s.dat.%.4d", prefixString, variable->name, rank );
-		}
-		else {
-			sprintf( varFileName, "%s.dat.%.4d", variable->name, rank );
-		}
-		
-		Variable_SaveToFileAsDoubles( variable, varFileName );
-		Memory_Free( varFileName );
-	}
-}
-
-
-void DofLayout_LoadAllVariablesFromFiles( void* dofLayout, char* prefixString, unsigned rank ) {
-	DofLayout*  self = (DofLayout*) dofLayout;
-	Index       ownedVar_I, var_I;
-	Variable*   variable = NULL;
-	char*       varFileName;
-	int         prefixStringLength=0;
-
-	for ( ownedVar_I = 0; ownedVar_I < self->_totalVarCount; ownedVar_I++ ) {
-		var_I = self->_varIndicesMapping[ownedVar_I];
-		variable = Variable_Register_GetByIndex( self->_variableRegister, var_I );
-
-		if ( prefixString ) {
-			prefixStringLength = strlen(prefixString);
-		}
-		else {
-			prefixStringLength = 0;
-		}
-
-		varFileName = Memory_Alloc_Array_Unnamed( char, prefixStringLength + strlen( variable->name ) + 6 + 4 + 1 );
-		if ( prefixString ) {
-			sprintf( varFileName, "%s.%s.dat.%.4d", prefixString, variable->name, rank );
-		}
-		else {
-			sprintf( varFileName, "%s.dat.%.4d", variable->name, rank );
-		}
-		
-		Variable_ReadFromFileAsDoubles( variable, varFileName );
-		Memory_Free( varFileName );
-	}
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/DofLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/DofLayout.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,632 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: DofLayout.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "DomainContext.h"
+#include "DofLayout.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+
+const Type DofLayout_Type = "DofLayout";
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Private function declarations
+*/
+
+/** Add a new Variable to the group that may be used as dofs, where varIndex is the index of the variable
+in the variable register. */
+Dof_Index	_DofLayout_AddVariable_ByIndex(void* dofLayout, Variable_Index varIndex);
+
+/** Add a new Variable to the group that may be used as dofs - by name. */
+Dof_Index	_DofLayout_AddVariable_ByName(void* dofLayout, Name varName);
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+DofLayout* DofLayout_New( Name name, DomainContext* context, Variable_Register* variableRegister, Index numItemsInLayout, void* mesh ) {
+	DofLayout* self = _DofLayout_DefaultNew( name );
+
+	self->isConstructed = True;
+	_DofLayout_Init( self, context, variableRegister, numItemsInLayout, 0, NULL, mesh );
+
+	return self;
+}
+
+DofLayout* _DofLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(DofLayout);
+	Type                                                      type = DofLayout_Type;
+	Stg_Class_DeleteFunction*                              _delete = _DofLayout_Delete;
+	Stg_Class_PrintFunction*                                _print = _DofLayout_Print;
+	Stg_Class_CopyFunction*                                  _copy = _DofLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_DofLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _DofLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _DofLayout_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _DofLayout_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _DofLayout_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _DofLayout_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+
+	return _DofLayout_New(  DOFLAYOUT_PASSARGS  );
+}
+
+DofLayout* _DofLayout_New(  DOFLAYOUT_DEFARGS  ) {
+	DofLayout* self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(DofLayout) );
+	self = (DofLayout*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* Virtual info */
+	self->_build = _build;
+	self->_initialise = _initialise;
+	
+	/* Stg_Class info */
+	
+	return self;
+}
+
+void _DofLayout_Init(
+	void*						dofLayout,
+	DomainContext*			context,
+	Variable_Register*	variableRegister, 
+	Index						numItemsInLayout,
+	Variable_Index			baseVariableCount,
+	Variable**				baseVariableArray,
+	void*						_mesh )
+{
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Mesh*			mesh = (Mesh*)_mesh;
+	
+	self->_variableRegister = variableRegister;
+
+	self->_numItemsInLayout = numItemsInLayout;
+	self->_variableEnabledSets = NULL;
+	self->_totalVarCount = 0;
+	self->_varIndicesMapping = NULL;
+	
+	self->dofCounts = NULL;
+
+	self->mesh = mesh;
+	self->nBaseVariables = baseVariableCount;
+	self->baseVariables = baseVariableArray;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+void _DofLayout_Delete(void* dofLayout) {
+	DofLayout* self = (DofLayout*)dofLayout;
+	
+	/* Stg_Class_Delete parent */
+	_Stg_Component_Delete( self );
+}
+
+
+void _DofLayout_Print(void* dofLayout, Stream* stream) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	
+	/* Set the Journal for printing informations */
+	Stream* compositeVCStream = stream;
+	
+	/* General info */
+	Journal_Printf( compositeVCStream, "DofLayout (ptr): %p\n", self);
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	
+	/* Print parent */
+	_Stg_Component_Print( self, compositeVCStream );
+}
+
+
+void* _DofLayout_Copy( const void* dofLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	DofLayout*	newDofLayout;
+	PtrMap*		map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newDofLayout = (DofLayout*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
+	
+	newDofLayout->_variableRegister = self->_variableRegister;
+	newDofLayout->_numItemsInLayout = self->_numItemsInLayout;
+	newDofLayout->_totalVarCount = self->_totalVarCount;
+	
+	if( deep ) {
+          if( (newDofLayout->_variableEnabledSets = (IndexSet**)PtrMap_Find( map, self->_variableEnabledSets )) == NULL && self->_variableEnabledSets ) {
+			Index	set_I;
+			
+			newDofLayout->_variableEnabledSets = Memory_Alloc_Array( IndexSet*, newDofLayout->_totalVarCount, "DofLayout->_variableEnabledSets" );
+			for( set_I = 0; set_I < newDofLayout->_totalVarCount; set_I++ ) {
+				newDofLayout->_variableEnabledSets[set_I] = (IndexSet*)Stg_Class_Copy( self->_variableEnabledSets[set_I], NULL, deep, nameExt, map );
+			}
+			PtrMap_Append( map, self->_variableEnabledSets, newDofLayout->_variableEnabledSets );
+		}
+		
+          if( (newDofLayout->_varIndicesMapping = (Variable_Index*)PtrMap_Find( map, self->_varIndicesMapping )) == NULL && self->_varIndicesMapping ) {
+			newDofLayout->_varIndicesMapping = Memory_Alloc_Array( Variable_Index, newDofLayout->_totalVarCount, "DofLayout->_varIndicesMapping" );
+			memcpy( newDofLayout->_varIndicesMapping, self->_varIndicesMapping, sizeof(Variable_Index) * newDofLayout->_totalVarCount );
+			PtrMap_Append( map, self->_varIndicesMapping, newDofLayout->_varIndicesMapping );
+		}
+		
+          if( (newDofLayout->dofCounts = (Dof_Index*)PtrMap_Find( map, self->dofCounts )) == NULL && self->dofCounts ) {
+			newDofLayout->dofCounts = Memory_Alloc_Array( Index, newDofLayout->_numItemsInLayout, "DofLayout->dofCounts" );
+			memcpy( newDofLayout->dofCounts, self->dofCounts, sizeof(Index) * newDofLayout->_numItemsInLayout );
+			PtrMap_Append( map, self->dofCounts, newDofLayout->dofCounts );
+		}
+		
+          if( (newDofLayout->varIndices = (Variable_Index**)PtrMap_Find( map, self->varIndices )) == NULL && self->varIndices ) {
+			Index	idx_I;
+			
+			newDofLayout->varIndices = Memory_Alloc_2DComplex( Variable_Index, newDofLayout->_numItemsInLayout, self->dofCounts, "DofLayout->varIndices" );
+			for( idx_I = 0; idx_I < newDofLayout->_numItemsInLayout; idx_I++ ) {
+				memcpy( newDofLayout->varIndices[idx_I], self->varIndices[idx_I], sizeof(Variable_Index) * newDofLayout->dofCounts[idx_I] );
+			}
+			PtrMap_Append( map, self->varIndices, newDofLayout->varIndices );
+		}
+	}
+	else {
+		newDofLayout->_variableEnabledSets = self->_variableEnabledSets;
+		newDofLayout->_varIndicesMapping = self->_varIndicesMapping;
+		newDofLayout->dofCounts = self->dofCounts;
+		newDofLayout->varIndices = self->varIndices;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newDofLayout;
+}
+
+void _DofLayout_AssignFromXML( void* dofLayout, Stg_ComponentFactory* cf, void* data ) {
+	DofLayout *             self = (DofLayout*)dofLayout;
+	Dictionary*             thisComponentDict = NULL;
+	void*                   variableRegister = NULL;
+	Dictionary_Entry_Value* list;
+	Variable_Index          baseVariableCount = 0;
+	Variable**              baseVariableList = NULL;
+	Mesh*							mesh;
+	DomainContext*				context;
+
+	/* Get component's dictionary setup */
+	assert( cf->componentDict );
+	thisComponentDict = Dictionary_GetDictionary( cf->componentDict, self->name );
+	assert( thisComponentDict );
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+
+	/* Get the mesh. */
+	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data );
+
+	variableRegister = context->variable_Register; 
+	assert( variableRegister  );
+
+	if (( list = Dictionary_Get( thisComponentDict, (Dictionary_Entry_Key)"BaseVariables" ) ) ) {
+		Variable_Index	baseVariable_I    = 0;
+		Name				variableName;
+
+		baseVariableCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"BaseVariableCount", Dictionary_Entry_Value_GetCount( list ) );
+		Journal_Firewall(
+			baseVariableCount <= Dictionary_Entry_Value_GetCount( list  ),
+			Journal_Register( Error_Type, (Name)self->type  ),
+			"BaseVariableCount %u is too large for list given.\n", baseVariableCount );
+
+		baseVariableList = Memory_Alloc_Array( Variable*, baseVariableCount, "baseVariableList" );
+		
+		for ( baseVariable_I = 0 ; baseVariable_I < baseVariableCount ; baseVariable_I++ ) {
+			variableName = Dictionary_Entry_Value_AsString( Dictionary_Entry_Value_GetElement( list, baseVariable_I ) );
+
+			Journal_PrintfL( cf->infoStream, 2, "Looking for Variable '%s' in Variable_Register\n", variableName );
+			baseVariableList[ baseVariable_I ] = Variable_Register_GetByName( variableRegister, variableName );
+
+			if ( !baseVariableList[ baseVariable_I ] )
+				baseVariableList[ baseVariable_I ] = Stg_ComponentFactory_ConstructByName( cf, (Name)variableName, Variable, True, data  );
+		}
+	}
+	
+	_DofLayout_Init( self, context, (Variable_Register*)variableRegister, 0, baseVariableCount, baseVariableList, mesh );
+}
+
+void _DofLayout_Build( void* dofLayout, void* data ) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Index			indexCount;
+	Index*		indices;
+	Index			set_I, i, pos;
+
+	assert( self );
+
+	/* Build mesh and extract domain size, if required. */
+	if( self->mesh ) {
+		Stg_Component_Build( self->mesh, data, False );
+		self->_numItemsInLayout = Mesh_GetDomainSize( self->mesh, MT_VERTEX );
+	}
+
+	/* Adds each variable in this list as a base degree of freedom to each item in DofLayout */
+	DofLayout_AddAllFromVariableArray( self, self->nBaseVariables, self->baseVariables );
+
+	/* ensure variables are built */
+	for( i = 0; i < self->_totalVarCount; i++ )
+		Stg_Component_Build( Variable_Register_GetByIndex( self->_variableRegister, self->_varIndicesMapping[i] ), data, False );
+	
+	self->dofCounts = Memory_Alloc_Array( Index, self->_numItemsInLayout, "DofLayout->dofCounts" );
+	memset(self->dofCounts, 0, sizeof(Index)*self->_numItemsInLayout);
+	
+	for (set_I = 0; set_I < self->_totalVarCount; set_I++) {
+		IndexSet_GetMembers(self->_variableEnabledSets[set_I], &indexCount, &indices);
+
+		for (i = 0; i < indexCount; i++) {
+			self->dofCounts[indices[i]]++;
+		}
+			
+		if (indices)
+			Memory_Free(indices);
+	}
+	
+	self->varIndices = Memory_Alloc_2DComplex( Variable_Index, self->_numItemsInLayout, self->dofCounts, "DofLayout->varIndices" );
+	for (i = 0; i < self->_numItemsInLayout; i++) {
+		pos = 0;
+
+		for (set_I = 0; set_I < self->_totalVarCount; set_I++) {
+			if (IndexSet_IsMember(self->_variableEnabledSets[set_I], i))
+				self->varIndices[i][pos++] = self->_varIndicesMapping[set_I];
+		}
+	}
+}
+
+
+void _DofLayout_Initialise( void* dofLayout, void* data ) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Index			var_I;
+
+	/* Initialise all the Variables used - in some cases they don't allocate themselves properly until
+		this is done */
+	for( var_I = 0; var_I < self->_totalVarCount; var_I++ ) {
+		Stg_Component_Initialise( Variable_Register_GetByIndex( self->_variableRegister, self->_varIndicesMapping[var_I] ),
+			data, False );
+	}	
+}
+
+
+void _DofLayout_Execute( void* dofLayout, void* data ) {
+}
+
+void _DofLayout_Destroy( void* dofLayout, void* data ) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+
+	if( self->baseVariables )
+		Memory_Free( self->baseVariables );
+
+	if( self->dofCounts )
+		Memory_Free( self->dofCounts );
+
+	if( self->varIndices )
+		Memory_Free( self->varIndices );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Private functions
+*/
+
+Dof_Index _DofLayout_AddVariable_ByIndex(void* dofLayout, Variable_Index varIndex) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Dof_Index	dof_I;
+	
+	for (dof_I = 0; dof_I < self->_totalVarCount; dof_I++)
+		if (varIndex == self->_varIndicesMapping[dof_I])
+			return dof_I;
+	
+	self->_totalVarCount++;
+	
+	/* Do an Alloc if array does not exist to register stats in memory module. Other times, just Realloc */
+	if ( self->_varIndicesMapping ) {
+		self->_varIndicesMapping = Memory_Realloc_Array( self->_varIndicesMapping, Variable_Index, self->_totalVarCount );
+	}
+	else {
+		self->_varIndicesMapping = Memory_Alloc_Array( Variable_Index, self->_totalVarCount,
+			"DofLayout->_varIndicesMapping" );
+	}
+	self->_varIndicesMapping[self->_totalVarCount - 1] = varIndex;
+
+	if ( self->_variableEnabledSets ) {
+		self->_variableEnabledSets = Memory_Realloc_Array( self->_variableEnabledSets, IndexSet*, self->_totalVarCount );
+	}
+	else {
+		self->_variableEnabledSets = Memory_Alloc_Array( IndexSet*, self->_totalVarCount,
+			"DofLayout->_variableEnabledSets" );
+	}
+	self->_variableEnabledSets[self->_totalVarCount - 1] = IndexSet_New(self->_numItemsInLayout);
+	
+	return self->_totalVarCount - 1;
+}
+
+
+Dof_Index _DofLayout_AddVariable_ByName(void* dofLayout, Name varName) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Dof_Index	dof_I;
+	
+	dof_I = Variable_Register_GetIndex( self->_variableRegister, varName );
+	Journal_Firewall( 
+		dof_I != (unsigned)-1,
+		Journal_Register( Error_Type, (Name)DofLayout_Type  ),
+		"Attempting to name a variable as a DOF that is not in the variable registry!\n" );
+	return _DofLayout_AddVariable_ByIndex( self, dof_I );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public functions
+*/
+
+void DofLayout_AddDof_ByVarIndex(void* dofLayout, Variable_Index varIndex, Index index) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	
+	IndexSet_Add(self->_variableEnabledSets[varIndex], index);
+}
+
+
+void DofLayout_AddDof_ByVarName(void* dofLayout, Name varName, Index index) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	
+	DofLayout_AddDof_ByVarIndex(self, _DofLayout_AddVariable_ByName(self, varName), index);
+}
+
+Variable* DofLayout_GetVariable(void* dofLayout, Index index, Dof_Index dofAtItemIndex ) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Variable_Index	var_I = self->varIndices[index][dofAtItemIndex];
+	
+	return Variable_Register_GetByIndex( self->_variableRegister, var_I );
+}
+
+
+void DofLayout_CopyValues( void* dofLayout, void* destDofLayout ) {
+	DofLayout*    self = (DofLayout*)dofLayout;
+	DofLayout*    dest = (DofLayout*)destDofLayout;
+	Index         ii = 0;
+	Dof_Index     dof_I = 0;
+	Stream*       error = Journal_Register( Error_Type, (Name)self->type );
+	
+	Journal_Firewall( (self->_numItemsInLayout == dest->_numItemsInLayout ), error,
+		"Error: Number of items in source dof layout (%d) not equal to number of "
+		"items in destination dof layout (%d).\n",
+		self->_numItemsInLayout, dest->_numItemsInLayout );
+
+	for ( ii=0; ii < self->_numItemsInLayout; ii++ ) {
+		#ifdef CAUTIOUS
+		Journal_Firewall( (self->dofCounts[ii] == dest->dofCounts[ii] ), error,
+			"Error: Number of dofs in source dof layout (item %d, %d dofs) not equal to "
+			"number of dofs in destination dof layout at same entry (%d).\n",
+			self->_numItemsInLayout, self->dofCounts[ii], dest->dofCounts[ii] );
+		#endif	
+
+		for ( dof_I = 0; dof_I < self->dofCounts[ii]; dof_I++ ) {
+			DofLayout_SetValueDouble( dest, ii, dof_I,
+				DofLayout_GetValueDouble( self, ii, dof_I ) );
+		}
+	}
+}
+
+
+void DofLayout_SetAllToZero( void* dofLayout ) {
+	DofLayout*    self = (DofLayout*)dofLayout;
+	Index         ii = 0;
+	Dof_Index     dof_I = 0;
+	
+	for ( ii=0; ii < self->_numItemsInLayout; ii++ ) {
+
+		for ( dof_I = 0; dof_I < self->dofCounts[ii]; dof_I++ ) {
+			DofLayout_SetValueDouble( self, ii, dof_I, 0 );
+		}
+	}
+}
+
+
+void DofLayout_Remap( void* dofLayout, Index newIndexCount, IndexMap* map ) {
+	DofLayout*	self = (DofLayout*)dofLayout;
+	Index		item_I;
+	
+	assert( newIndexCount && map ); /* TODO: change this to Journal commands */
+	
+	/*
+	** NOTE: it is possible that a remapping will eliminate some of the variables accessed
+	**	 by the DofLayout.  This will require a bit more effort to account for, but for
+	**	 the moment it shouldn't matter.
+	*/
+	
+	if( self->_variableEnabledSets ) {
+		IndexSet**	variableEnabledSets;
+		Index		set_I;
+		
+		variableEnabledSets = Memory_Alloc_Array( IndexSet*, self->_totalVarCount, "DofLayout->_variableEnabledSets" );
+		for( set_I = 0; set_I < self->_totalVarCount; set_I++ ) {
+			Index	itemCount;
+			Index*	items;
+			
+			variableEnabledSets[set_I] = IndexSet_New( newIndexCount );
+			
+			IndexSet_GetMembers( self->_variableEnabledSets[set_I], &itemCount, &items );
+			for( item_I = 0; item_I < itemCount; item_I++ ) {
+				Index	mappedValue = IndexMap_Find( map, items[item_I] );
+				
+				if( mappedValue < self->_numItemsInLayout ) {
+					IndexSet_Add( variableEnabledSets[set_I], mappedValue );
+				}
+			}
+			
+			Memory_Free( items );
+			Stg_Class_Delete( self->_variableEnabledSets[set_I] );
+		}
+		Memory_Free( self->_variableEnabledSets );
+		self->_variableEnabledSets = variableEnabledSets;
+	}
+	
+	/* Map dofCounts */
+	if( self->dofCounts ) {
+		Dof_Index*	dofCounts;
+		
+		dofCounts = Memory_Alloc_Array( Dof_Index, newIndexCount, "DofLayout->dofCounts" );
+		for( item_I = 0; item_I < self->_numItemsInLayout; item_I++ ) {
+			Index	mappedValue = IndexMap_Find( map, item_I );
+			
+			if( mappedValue < self->_numItemsInLayout ) {
+				dofCounts[mappedValue] = self->dofCounts[item_I];
+			}
+		}
+		Memory_Free( self->dofCounts );
+		self->dofCounts = dofCounts;
+	}
+	
+	/* Map varIndices */
+	if( self->varIndices ) {
+		Variable_Index**	varIndices;
+		
+		varIndices = Memory_Alloc_2DComplex( Variable_Index, newIndexCount, self->dofCounts, "DofLayout->varIndices" );
+		for( item_I = 0; item_I < self->_numItemsInLayout; item_I++ ) {
+			Index	mappedValue = IndexMap_Find( map, item_I );
+			
+			if( mappedValue < self->_numItemsInLayout ) {
+				memcpy( varIndices[mappedValue], 
+					self->varIndices[item_I], 
+					sizeof(Variable_Index) * self->dofCounts[mappedValue] );
+			}
+		}
+		Memory_Free( self->varIndices );
+		self->varIndices = varIndices;
+	}
+	
+	/* Overwrite old values */
+	self->_numItemsInLayout = newIndexCount;
+}
+
+void DofLayout_AddAllFromVariableArray( void* dofLayout, Variable_Index variableCount, Variable** variableArray ) {
+	DofLayout*      self        = (DofLayout*) dofLayout;
+	Index           item_I;
+	Index           itemCount   = self->_numItemsInLayout;
+	Variable_Index  variable_I;
+	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type );
+
+	for( variable_I = 0; variable_I < variableCount ; variable_I++  ) {
+		Journal_Firewall( variableArray[variable_I] != NULL, errorStream,
+				"In func %s for %s '%s' - Variable %d in array is NULL.\n", __func__, self->type, self->name, variable_I);
+		for( item_I = 0; item_I < itemCount ; item_I++ ) {
+			DofLayout_AddDof_ByVarName( self, variableArray[variable_I]->name, item_I );
+		}
+	}
+}
+
+
+void DofLayout_SaveAllVariablesToFiles( void* dofLayout, char* prefixString, unsigned rank ) {
+	DofLayout*  self = (DofLayout*) dofLayout;
+	Index       ownedVar_I, var_I;
+	Variable*   variable = NULL;
+	char*       varFileName;
+	int         prefixStringLength=0;
+
+	for ( ownedVar_I = 0; ownedVar_I < self->_totalVarCount; ownedVar_I++ ) {
+		var_I = self->_varIndicesMapping[ownedVar_I];
+		variable = Variable_Register_GetByIndex( self->_variableRegister, var_I );
+
+		if ( prefixString ) {
+			prefixStringLength = strlen(prefixString);
+		}
+		else {
+			prefixStringLength = 0;
+		}
+
+		varFileName = Memory_Alloc_Array_Unnamed( char, prefixStringLength + strlen( variable->name ) + 5 + 4 + 1 );
+		if ( prefixString ) {
+			sprintf( varFileName, "%s.%s.dat.%.4d", prefixString, variable->name, rank );
+		}
+		else {
+			sprintf( varFileName, "%s.dat.%.4d", variable->name, rank );
+		}
+		
+		Variable_SaveToFileAsDoubles( variable, varFileName );
+		Memory_Free( varFileName );
+	}
+}
+
+
+void DofLayout_LoadAllVariablesFromFiles( void* dofLayout, char* prefixString, unsigned rank ) {
+	DofLayout*  self = (DofLayout*) dofLayout;
+	Index       ownedVar_I, var_I;
+	Variable*   variable = NULL;
+	char*       varFileName;
+	int         prefixStringLength=0;
+
+	for ( ownedVar_I = 0; ownedVar_I < self->_totalVarCount; ownedVar_I++ ) {
+		var_I = self->_varIndicesMapping[ownedVar_I];
+		variable = Variable_Register_GetByIndex( self->_variableRegister, var_I );
+
+		if ( prefixString ) {
+			prefixStringLength = strlen(prefixString);
+		}
+		else {
+			prefixStringLength = 0;
+		}
+
+		varFileName = Memory_Alloc_Array_Unnamed( char, prefixStringLength + strlen( variable->name ) + 6 + 4 + 1 );
+		if ( prefixString ) {
+			sprintf( varFileName, "%s.%s.dat.%.4d", prefixString, variable->name, rank );
+		}
+		else {
+			sprintf( varFileName, "%s.dat.%.4d", variable->name, rank );
+		}
+		
+		Variable_ReadFromFileAsDoubles( variable, varFileName );
+		Memory_Free( varFileName );
+	}
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/DomainContext.c
--- a/Utils/src/DomainContext.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,158 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Context.c 2454 2004-12-21 04:50:42Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-                                                                                                                                    
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-                                                                                                                                    
-#include "types.h"
-#include "FieldVariable.h"
-#include "FieldVariable_Register.h"
-#include "DomainContext.h"
-                                                                                                                                    
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-
-/* Textual name of this class */
-const Type DomainContext_Type = "DomainContext";
-
-DomainContext* DomainContext_New( 
-	Name			name,
-	double		start,
-	double		stop,
-	MPI_Comm		communicator,
-	Dictionary*	dictionary )
-{
-	DomainContext* self = _DomainContext_DefaultNew( name );
-
-	self->isConstructed = True;
-	_AbstractContext_Init( (AbstractContext*) self );
-	_DomainContext_Init( self );
-
-	return self;
-}
-
-DomainContext* _DomainContext_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(DomainContext);
-	Type                                                      type = DomainContext_Type;
-	Stg_Class_DeleteFunction*                              _delete = _DomainContext_Delete;
-	Stg_Class_PrintFunction*                                _print = _DomainContext_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = NULL;
-	Stg_Component_ConstructFunction*                    _construct = _DomainContext_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AbstractContext_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _AbstractContext_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _AbstractContext_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = (Stg_Component_DestroyFunction*)_DomainContext_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	AbstractContext_SetDt*                                  _setDt = _DomainContext_SetDt;
-	double                                               startTime = 0;
-	double                                                stopTime = 0;
-	MPI_Comm                                          communicator = MPI_COMM_WORLD;
-	Dictionary*                                         dictionary = NULL;
-
-	return _DomainContext_New(  DOMAINCONTEXT_PASSARGS  );
-}
-
-DomainContext* _DomainContext_New(  DOMAINCONTEXT_DEFARGS  ) {
-	DomainContext* self;
-	
-	/* Allocate memory */
-	self = (DomainContext*)_AbstractContext_New(  ABSTRACTCONTEXT_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual info */
-	
-	return self;
-}
-
-void _DomainContext_Init( DomainContext* self ) {
-
-	self->fieldVariable_Register = FieldVariable_Register_New();
-}
-
-
-/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
-
-void _DomainContext_AssignFromXML( void* context, Stg_ComponentFactory* cf, void* data ) {
-	DomainContext* self = (DomainContext*)context;
-
-	_AbstractContext_AssignFromXML( context, cf, data );
-
-	/* Check if we have been provided a constant to multiply our calculated dt values by. */
-	self->dtFactor = Dictionary_GetDouble_WithDefault( self->dictionary, (Dictionary_Entry_Key)"timestepFactor", 1.0  );
-	self->dim = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "dim", 2 );
-
-	_DomainContext_Init( self );
-}
-
-void _DomainContext_Delete( void* context ) {
-	DomainContext* self = (DomainContext*)context;
-	
-	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
-
-	Journal_DPrintfL( self->debug, 2, "Deleting the FieldVariable register (and hence all FieldVariables).\n" );
-
-	/* Stg_Class_Delete parent */
-	_AbstractContext_Delete( self );
-}
-
-void _DomainContext_Destroy( void* context ) {
-	DomainContext* self = (DomainContext*)context;
-	
-	Stg_Class_Delete( self->fieldVariable_Register ); 
-	_AbstractContext_Destroy( self, 0 );
-}
-
-void _DomainContext_Print( void* context, Stream* stream ) {
-	DomainContext* self = (DomainContext*)context;
-	
-	/* General info */
-	Journal_Printf( (void*) stream, "DomainContext (ptr): %p\n", self );
-	
-	/* Print parent */
-	_AbstractContext_Print( self, stream );
-
-	Journal_Printf( (void*) stream, "\tfieldVariables (ptr): %p\n", self->fieldVariable_Register );
-	Stg_Class_Print( self->fieldVariable_Register, stream );
-}
-
-
-void _DomainContext_SetDt( void* context, double dt ) {
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/DomainContext.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/DomainContext.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,158 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Context.c 2454 2004-12-21 04:50:42Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+                                                                                                                                    
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+                                                                                                                                    
+#include "types.h"
+#include "FieldVariable.h"
+#include "FieldVariable_Register.h"
+#include "DomainContext.h"
+                                                                                                                                    
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+
+/* Textual name of this class */
+const Type DomainContext_Type = "DomainContext";
+
+DomainContext* DomainContext_New( 
+	Name			name,
+	double		start,
+	double		stop,
+	MPI_Comm		communicator,
+	Dictionary*	dictionary )
+{
+	DomainContext* self = _DomainContext_DefaultNew( name );
+
+	self->isConstructed = True;
+	_AbstractContext_Init( (AbstractContext*) self );
+	_DomainContext_Init( self );
+
+	return self;
+}
+
+DomainContext* _DomainContext_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(DomainContext);
+	Type                                                      type = DomainContext_Type;
+	Stg_Class_DeleteFunction*                              _delete = _DomainContext_Delete;
+	Stg_Class_PrintFunction*                                _print = _DomainContext_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = NULL;
+	Stg_Component_ConstructFunction*                    _construct = _DomainContext_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AbstractContext_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _AbstractContext_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _AbstractContext_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = (Stg_Component_DestroyFunction*)_DomainContext_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	AbstractContext_SetDt*                                  _setDt = _DomainContext_SetDt;
+	double                                               startTime = 0;
+	double                                                stopTime = 0;
+	MPI_Comm                                          communicator = MPI_COMM_WORLD;
+	Dictionary*                                         dictionary = NULL;
+
+	return _DomainContext_New(  DOMAINCONTEXT_PASSARGS  );
+}
+
+DomainContext* _DomainContext_New(  DOMAINCONTEXT_DEFARGS  ) {
+	DomainContext* self;
+	
+	/* Allocate memory */
+	self = (DomainContext*)_AbstractContext_New(  ABSTRACTCONTEXT_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual info */
+	
+	return self;
+}
+
+void _DomainContext_Init( DomainContext* self ) {
+
+	self->fieldVariable_Register = FieldVariable_Register_New();
+}
+
+
+/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
+
+void _DomainContext_AssignFromXML( void* context, Stg_ComponentFactory* cf, void* data ) {
+	DomainContext* self = (DomainContext*)context;
+
+	_AbstractContext_AssignFromXML( context, cf, data );
+
+	/* Check if we have been provided a constant to multiply our calculated dt values by. */
+	self->dtFactor = Dictionary_GetDouble_WithDefault( self->dictionary, (Dictionary_Entry_Key)"timestepFactor", 1.0  );
+	self->dim = Dictionary_GetUnsignedInt_WithDefault( self->dictionary, "dim", 2 );
+
+	_DomainContext_Init( self );
+}
+
+void _DomainContext_Delete( void* context ) {
+	DomainContext* self = (DomainContext*)context;
+	
+	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
+
+	Journal_DPrintfL( self->debug, 2, "Deleting the FieldVariable register (and hence all FieldVariables).\n" );
+
+	/* Stg_Class_Delete parent */
+	_AbstractContext_Delete( self );
+}
+
+void _DomainContext_Destroy( void* context ) {
+	DomainContext* self = (DomainContext*)context;
+	
+	Stg_Class_Delete( self->fieldVariable_Register ); 
+	_AbstractContext_Destroy( self, 0 );
+}
+
+void _DomainContext_Print( void* context, Stream* stream ) {
+	DomainContext* self = (DomainContext*)context;
+	
+	/* General info */
+	Journal_Printf( (void*) stream, "DomainContext (ptr): %p\n", self );
+	
+	/* Print parent */
+	_AbstractContext_Print( self, stream );
+
+	Journal_Printf( (void*) stream, "\tfieldVariables (ptr): %p\n", self->fieldVariable_Register );
+	Stg_Class_Print( self->fieldVariable_Register, stream );
+}
+
+
+void _DomainContext_SetDt( void* context, double dt ) {
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/FieldVariable.c
--- a/Utils/src/FieldVariable.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,342 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: FieldVariable.c 4076 2007-04-24 04:37:28Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "FieldVariable.h"
-#include "DomainContext.h"
-#include "FieldVariable_Register.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type FieldVariable_Type = "FieldVariable";
-
-Name InterpolationResultToStringMap[4] = { "OTHER_PROC", "LOCAL", "SHADOW", "OUTSIDE_GLOBAL" };
-
-FieldVariable* FieldVariable_New(		
-	Name													name,
-	DomainContext*										context,
-	Index													fieldComponentCount,
-	Dimension_Index									dim,
-	Bool													isCheckpointedAndReloaded,
-	MPI_Comm												communicator,
-	FieldVariable_Register*							fieldVariable_Register ) 
-{
-	FieldVariable* self = _FieldVariable_DefaultNew( name );
-
-	self->isConstructed = True;
-	_FieldVariable_Init( self, context, fieldComponentCount, dim, isCheckpointedAndReloaded, communicator, fieldVariable_Register );
-
-	return self;
-}
-
-FieldVariable* _FieldVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                      _sizeOfSelf = sizeof(FieldVariable);
-	Type                                                              type = FieldVariable_Type;
-	Stg_Class_DeleteFunction*                                      _delete = _FieldVariable_Delete;
-	Stg_Class_PrintFunction*                                        _print = _FieldVariable_Print;
-	Stg_Class_CopyFunction*                                          _copy = _FieldVariable_Copy;
-	Stg_Component_DefaultConstructorFunction*          _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_FieldVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                            _construct = _FieldVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                                    _build = _FieldVariable_Build;
-	Stg_Component_InitialiseFunction*                          _initialise = _FieldVariable_Initialise;
-	Stg_Component_ExecuteFunction*                                _execute = _FieldVariable_Execute;
-	Stg_Component_DestroyFunction*                                _destroy = _FieldVariable_Destroy;
-	AllocationType                                      nameAllocationType = NON_GLOBAL;
-	FieldVariable_InterpolateValueAtFunction*          _interpolateValueAt = NULL;
-	FieldVariable_GetValueFunction*            _getMinGlobalFieldMagnitude = NULL;
-	FieldVariable_GetValueFunction*            _getMaxGlobalFieldMagnitude = NULL;
-	FieldVariable_GetCoordFunction*               _getMinAndMaxLocalCoords = NULL;
-	FieldVariable_GetCoordFunction*              _getMinAndMaxGlobalCoords = NULL;
-
-	return _FieldVariable_New(  FIELDVARIABLE_PASSARGS  );
-}
-
-FieldVariable* _FieldVariable_New(  FIELDVARIABLE_DEFARGS  ) {
-	FieldVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(FieldVariable) );
-	self = (FieldVariable*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* Virtual functions */
-	self->_interpolateValueAt         = _interpolateValueAt;
-	self->_getMinGlobalFieldMagnitude = _getMinGlobalFieldMagnitude;
-	self->_getMaxGlobalFieldMagnitude = _getMaxGlobalFieldMagnitude;
-	self->_getMinAndMaxLocalCoords    = _getMinAndMaxLocalCoords;
-	self->_getMinAndMaxGlobalCoords   = _getMinAndMaxGlobalCoords;
-
-	/* General info */
-
-	/* FieldVariable info */
-	
-	return self;
-}
-
-void _FieldVariable_Delete( void* fieldVariable ) {
-	FieldVariable* self = (FieldVariable*) fieldVariable;
-
-	_Stg_Component_Delete( self );
-}
-
-void _FieldVariable_Print( void* _fieldVariable, Stream* stream ) {
-	FieldVariable* self = (FieldVariable*) _fieldVariable;
-
-	Journal_Printf( stream, "FieldVariable - '%s'\n", self->name );
-	Stream_Indent( stream );
-	_Stg_Component_Print( self, stream );
-
-	Journal_PrintPointer( stream, self->_interpolateValueAt );
-	Journal_PrintPointer( stream, self->_getMinGlobalFieldMagnitude );
-	Journal_PrintPointer( stream, self->_getMaxGlobalFieldMagnitude );
-	Journal_PrintPointer( stream, self->_getMinAndMaxLocalCoords );
-	Journal_PrintPointer( stream, self->_getMinAndMaxGlobalCoords );
-
-	Journal_PrintValue( stream, self->fieldComponentCount );
-	Journal_PrintValue( stream, self->dim );
-	Journal_PrintBool( stream, self->isCheckpointedAndReloaded);
-	#ifdef LAM_MPI
-		Journal_PrintPointer( stream, self->communicator );
-	#elif  defined( OPEN_MPI )
-		Journal_PrintPointer( stream, self->communicator );
-	#else
-		Journal_PrintValue( stream, self->communicator );
-	#endif
-	Journal_PrintPointer( stream, self->fieldVariable_Register );
-	Stream_UnIndent( stream );
-}
-
-void _FieldVariable_Init( 
-	FieldVariable*				self, 
-	DomainContext*				context,
-	Index							fieldComponentCount, 
-	Dimension_Index			dim,
-	Bool							isCheckpointedAndReloaded,
-	MPI_Comm						communicator, 
-	FieldVariable_Register*	fV_Register ) {
-	/* Add ourselves to the register for later retrieval by clients */
-	
-	self->context							= context;
-	self->fieldComponentCount			= fieldComponentCount;
-	self->dim								= dim;
-	self->communicator					= communicator;
-	self->fieldVariable_Register		= fV_Register;
-	self->isCheckpointedAndReloaded	= isCheckpointedAndReloaded;
-
-	if (self != NULL && fV_Register != NULL) {	
-	   /* Prevent the same field from being added more than once */
-          if( NamedObject_Register_GetIndex( fV_Register, self->name ) == (Index)(-1) )
-	      FieldVariable_Register_Add( fV_Register, self );
-	}	
-
-	self->extensionMgr = ExtensionManager_New_OfExistingObject( self->name, self );
-}
-
-void* _FieldVariable_Copy( const void* fieldVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-	FieldVariable*	newFieldVariable;
-	PtrMap*			map = ptrMap;
-	Bool			ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newFieldVariable = (FieldVariable*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
-	
-	newFieldVariable->_interpolateValueAt        = self->_interpolateValueAt;
-	newFieldVariable->_getMinAndMaxLocalCoords   = self->_getMinAndMaxLocalCoords;
-	newFieldVariable->_getMinAndMaxGlobalCoords  = self->_getMinAndMaxGlobalCoords;
-
-	newFieldVariable->fieldComponentCount        = self->fieldComponentCount;
-	newFieldVariable->dim                        = self->dim;
-	newFieldVariable->isCheckpointedAndReloaded  = self->isCheckpointedAndReloaded;
-	newFieldVariable->communicator               = self->communicator;
-	newFieldVariable->fieldVariable_Register     =  self->fieldVariable_Register;
-
-	newFieldVariable->extensionMgr               = (ExtensionManager*)Stg_Class_Copy( self->extensionMgr, NULL, deep, nameExt, map );
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-				
-	return (void*)newFieldVariable;
-}
-
-void _FieldVariable_AssignFromXML( void* fieldVariable, Stg_ComponentFactory* cf, void* data ) {
-	FieldVariable*	        self         = (FieldVariable*)fieldVariable;
-	FieldVariable_Register* fV_Register;
-	Dimension_Index         dim;
-	Index                   fieldComponentCount;
-	Bool                    isCheckpointedAndReloaded;
-	Dictionary_Entry_Value* feVarsList = NULL;
-	DomainContext*				context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data );
-	
-	fV_Register = context->fieldVariable_Register; 
-	assert( fV_Register  );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-	fieldComponentCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"fieldComponentCount", 0  );
-
-	/* Decide whether this FieldVariable will be checkpointed & reloaded, based on the dictionary list 
-	   "fieldVariableToCheckpoint". NB may want to put this in the XML component definintion of a
-	   FieldVariable itself, but for now prefer list so it can be centrally set.
-	   -- Pat, Jules, Kath - 29 November 2006 
-	 */
-
-	/* Case insensitive search */
-	feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"fieldVariablesToCheckpoint" );
-	if ( NULL == feVarsList  ) {
-		feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"FieldVariablesToCheckpoint" );
-	}
-
-	if (feVarsList != NULL ) {
-		Index                    listLength = Dictionary_Entry_Value_GetCount( feVarsList );
-		Index                    var_I = 0;
-		Dictionary_Entry_Value*  feVarDictValue = NULL;
-		char*                    fieldVariableName;
-	
-		isCheckpointedAndReloaded = False;
-		for ( var_I = 0; var_I < listLength; var_I++  ) {
-			feVarDictValue = Dictionary_Entry_Value_GetElement( feVarsList, var_I );
-			fieldVariableName = Dictionary_Entry_Value_AsString( feVarDictValue ); 
-			if ( 0 == strcmp( self->name, fieldVariableName ) ) {
-				isCheckpointedAndReloaded = True;
-				break;
-			}
-		}
-	}
-	else {
-		/* If there's no special list, just checkpoint/reload everything. */
-		isCheckpointedAndReloaded = True;
-	}
-   feVarsList = NULL;
-   /** also include check to see if this fevariable should be saved for analysis purposes */ 
-   feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"fieldVariablesToSave" );
-   if ( NULL == feVarsList  ) {
-      feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"FieldVariablesToSave" );
-   }
-   if (feVarsList != NULL ) {
-      Index                    listLength = Dictionary_Entry_Value_GetCount( feVarsList );
-      Index                    var_I = 0;
-      Dictionary_Entry_Value*  feVarDictValue = NULL;
-      char*                    fieldVariableName;
-   
-      for ( var_I = 0; var_I < listLength; var_I++  ) {
-         feVarDictValue = Dictionary_Entry_Value_GetElement( feVarsList, var_I );
-         fieldVariableName = Dictionary_Entry_Value_AsString( feVarDictValue ); 
-         if ( 0 == strcmp( self->name, fieldVariableName ) ) {
-            self->isSavedData = True;
-            break;
-         }
-      }
-   }
-
-	_FieldVariable_Init( self, context, fieldComponentCount, dim, isCheckpointedAndReloaded, MPI_COMM_WORLD, fV_Register );
-	
-}
-
-void _FieldVariable_Build( void* fieldVariable, void* data ) {
-
-}
-
-void _FieldVariable_Initialise( void* fieldVariable, void* data ) {
-
-}
-
-void _FieldVariable_Execute( void* fieldVariable, void* data ) {
-
-}
-
-void _FieldVariable_Destroy( void* fieldVariable, void* data ) {
-	FieldVariable* self = (FieldVariable*) fieldVariable;
-
-	if( self->extensionMgr ) {
-		Stg_Class_Delete( self->extensionMgr );
-	}
-
-	Stg_Component_Destroy( self, data, False );
-}
-
-InterpolationResult FieldVariable_InterpolateValueAt( void* fieldVariable, Coord coord, double* value ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-
-	return self->_interpolateValueAt( self, coord, value );
-}
-
-double FieldVariable_GetMinGlobalFieldMagnitude( void* fieldVariable ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-	return self->_getMinGlobalFieldMagnitude( self );
-}
-
-
-double FieldVariable_GetMaxGlobalFieldMagnitude( void* fieldVariable ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-	return self->_getMaxGlobalFieldMagnitude( self );
-}
-
-
-void FieldVariable_GetMinAndMaxLocalCoords( void* fieldVariable, Coord min, Coord max ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-
-	self->_getMinAndMaxLocalCoords( self, min, max );
-}
-
-void FieldVariable_GetMinAndMaxGlobalCoords( void* fieldVariable, Coord min, Coord max ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-
-	self->_getMinAndMaxGlobalCoords( self, min, max );
-}
-
-void _FieldVariable_GetMinAndMaxGlobalCoords( void* fieldVariable, Coord globalMin, Coord globalMax ) {
-	FieldVariable*	self = (FieldVariable*)fieldVariable;
-	Coord localMin, localMax;
-
-	self->_getMinAndMaxLocalCoords( self, localMin, localMax );
-
-	MPI_Allreduce( localMin, globalMin, self->dim, MPI_DOUBLE, MPI_MIN, self->communicator );
-	MPI_Allreduce( localMax, globalMax, self->dim, MPI_DOUBLE, MPI_MAX, self->communicator );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/FieldVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/FieldVariable.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,342 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: FieldVariable.c 4076 2007-04-24 04:37:28Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "FieldVariable.h"
+#include "DomainContext.h"
+#include "FieldVariable_Register.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type FieldVariable_Type = "FieldVariable";
+
+Name InterpolationResultToStringMap[4] = { "OTHER_PROC", "LOCAL", "SHADOW", "OUTSIDE_GLOBAL" };
+
+FieldVariable* FieldVariable_New(		
+	Name													name,
+	DomainContext*										context,
+	Index													fieldComponentCount,
+	Dimension_Index									dim,
+	Bool													isCheckpointedAndReloaded,
+	MPI_Comm												communicator,
+	FieldVariable_Register*							fieldVariable_Register ) 
+{
+	FieldVariable* self = _FieldVariable_DefaultNew( name );
+
+	self->isConstructed = True;
+	_FieldVariable_Init( self, context, fieldComponentCount, dim, isCheckpointedAndReloaded, communicator, fieldVariable_Register );
+
+	return self;
+}
+
+FieldVariable* _FieldVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                      _sizeOfSelf = sizeof(FieldVariable);
+	Type                                                              type = FieldVariable_Type;
+	Stg_Class_DeleteFunction*                                      _delete = _FieldVariable_Delete;
+	Stg_Class_PrintFunction*                                        _print = _FieldVariable_Print;
+	Stg_Class_CopyFunction*                                          _copy = _FieldVariable_Copy;
+	Stg_Component_DefaultConstructorFunction*          _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_FieldVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                            _construct = _FieldVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                                    _build = _FieldVariable_Build;
+	Stg_Component_InitialiseFunction*                          _initialise = _FieldVariable_Initialise;
+	Stg_Component_ExecuteFunction*                                _execute = _FieldVariable_Execute;
+	Stg_Component_DestroyFunction*                                _destroy = _FieldVariable_Destroy;
+	AllocationType                                      nameAllocationType = NON_GLOBAL;
+	FieldVariable_InterpolateValueAtFunction*          _interpolateValueAt = NULL;
+	FieldVariable_GetValueFunction*            _getMinGlobalFieldMagnitude = NULL;
+	FieldVariable_GetValueFunction*            _getMaxGlobalFieldMagnitude = NULL;
+	FieldVariable_GetCoordFunction*               _getMinAndMaxLocalCoords = NULL;
+	FieldVariable_GetCoordFunction*              _getMinAndMaxGlobalCoords = NULL;
+
+	return _FieldVariable_New(  FIELDVARIABLE_PASSARGS  );
+}
+
+FieldVariable* _FieldVariable_New(  FIELDVARIABLE_DEFARGS  ) {
+	FieldVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(FieldVariable) );
+	self = (FieldVariable*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* Virtual functions */
+	self->_interpolateValueAt         = _interpolateValueAt;
+	self->_getMinGlobalFieldMagnitude = _getMinGlobalFieldMagnitude;
+	self->_getMaxGlobalFieldMagnitude = _getMaxGlobalFieldMagnitude;
+	self->_getMinAndMaxLocalCoords    = _getMinAndMaxLocalCoords;
+	self->_getMinAndMaxGlobalCoords   = _getMinAndMaxGlobalCoords;
+
+	/* General info */
+
+	/* FieldVariable info */
+	
+	return self;
+}
+
+void _FieldVariable_Delete( void* fieldVariable ) {
+	FieldVariable* self = (FieldVariable*) fieldVariable;
+
+	_Stg_Component_Delete( self );
+}
+
+void _FieldVariable_Print( void* _fieldVariable, Stream* stream ) {
+	FieldVariable* self = (FieldVariable*) _fieldVariable;
+
+	Journal_Printf( stream, "FieldVariable - '%s'\n", self->name );
+	Stream_Indent( stream );
+	_Stg_Component_Print( self, stream );
+
+	Journal_PrintPointer( stream, self->_interpolateValueAt );
+	Journal_PrintPointer( stream, self->_getMinGlobalFieldMagnitude );
+	Journal_PrintPointer( stream, self->_getMaxGlobalFieldMagnitude );
+	Journal_PrintPointer( stream, self->_getMinAndMaxLocalCoords );
+	Journal_PrintPointer( stream, self->_getMinAndMaxGlobalCoords );
+
+	Journal_PrintValue( stream, self->fieldComponentCount );
+	Journal_PrintValue( stream, self->dim );
+	Journal_PrintBool( stream, self->isCheckpointedAndReloaded);
+	#ifdef LAM_MPI
+		Journal_PrintPointer( stream, self->communicator );
+	#elif  defined( OPEN_MPI )
+		Journal_PrintPointer( stream, self->communicator );
+	#else
+		Journal_PrintValue( stream, self->communicator );
+	#endif
+	Journal_PrintPointer( stream, self->fieldVariable_Register );
+	Stream_UnIndent( stream );
+}
+
+void _FieldVariable_Init( 
+	FieldVariable*				self, 
+	DomainContext*				context,
+	Index							fieldComponentCount, 
+	Dimension_Index			dim,
+	Bool							isCheckpointedAndReloaded,
+	MPI_Comm						communicator, 
+	FieldVariable_Register*	fV_Register ) {
+	/* Add ourselves to the register for later retrieval by clients */
+	
+	self->context							= context;
+	self->fieldComponentCount			= fieldComponentCount;
+	self->dim								= dim;
+	self->communicator					= communicator;
+	self->fieldVariable_Register		= fV_Register;
+	self->isCheckpointedAndReloaded	= isCheckpointedAndReloaded;
+
+	if (self != NULL && fV_Register != NULL) {	
+	   /* Prevent the same field from being added more than once */
+          if( NamedObject_Register_GetIndex( fV_Register, self->name ) == (Index)(-1) )
+	      FieldVariable_Register_Add( fV_Register, self );
+	}	
+
+	self->extensionMgr = ExtensionManager_New_OfExistingObject( self->name, self );
+}
+
+void* _FieldVariable_Copy( const void* fieldVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+	FieldVariable*	newFieldVariable;
+	PtrMap*			map = ptrMap;
+	Bool			ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newFieldVariable = (FieldVariable*)_Stg_Component_Copy( self, dest, deep, nameExt, map );
+	
+	newFieldVariable->_interpolateValueAt        = self->_interpolateValueAt;
+	newFieldVariable->_getMinAndMaxLocalCoords   = self->_getMinAndMaxLocalCoords;
+	newFieldVariable->_getMinAndMaxGlobalCoords  = self->_getMinAndMaxGlobalCoords;
+
+	newFieldVariable->fieldComponentCount        = self->fieldComponentCount;
+	newFieldVariable->dim                        = self->dim;
+	newFieldVariable->isCheckpointedAndReloaded  = self->isCheckpointedAndReloaded;
+	newFieldVariable->communicator               = self->communicator;
+	newFieldVariable->fieldVariable_Register     =  self->fieldVariable_Register;
+
+	newFieldVariable->extensionMgr               = (ExtensionManager*)Stg_Class_Copy( self->extensionMgr, NULL, deep, nameExt, map );
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+				
+	return (void*)newFieldVariable;
+}
+
+void _FieldVariable_AssignFromXML( void* fieldVariable, Stg_ComponentFactory* cf, void* data ) {
+	FieldVariable*	        self         = (FieldVariable*)fieldVariable;
+	FieldVariable_Register* fV_Register;
+	Dimension_Index         dim;
+	Index                   fieldComponentCount;
+	Bool                    isCheckpointedAndReloaded;
+	Dictionary_Entry_Value* feVarsList = NULL;
+	DomainContext*				context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data );
+	
+	fV_Register = context->fieldVariable_Register; 
+	assert( fV_Register  );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+	fieldComponentCount = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"fieldComponentCount", 0  );
+
+	/* Decide whether this FieldVariable will be checkpointed & reloaded, based on the dictionary list 
+	   "fieldVariableToCheckpoint". NB may want to put this in the XML component definintion of a
+	   FieldVariable itself, but for now prefer list so it can be centrally set.
+	   -- Pat, Jules, Kath - 29 November 2006 
+	 */
+
+	/* Case insensitive search */
+	feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"fieldVariablesToCheckpoint" );
+	if ( NULL == feVarsList  ) {
+		feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"FieldVariablesToCheckpoint" );
+	}
+
+	if (feVarsList != NULL ) {
+		Index                    listLength = Dictionary_Entry_Value_GetCount( feVarsList );
+		Index                    var_I = 0;
+		Dictionary_Entry_Value*  feVarDictValue = NULL;
+		char*                    fieldVariableName;
+	
+		isCheckpointedAndReloaded = False;
+		for ( var_I = 0; var_I < listLength; var_I++  ) {
+			feVarDictValue = Dictionary_Entry_Value_GetElement( feVarsList, var_I );
+			fieldVariableName = Dictionary_Entry_Value_AsString( feVarDictValue ); 
+			if ( 0 == strcmp( self->name, fieldVariableName ) ) {
+				isCheckpointedAndReloaded = True;
+				break;
+			}
+		}
+	}
+	else {
+		/* If there's no special list, just checkpoint/reload everything. */
+		isCheckpointedAndReloaded = True;
+	}
+   feVarsList = NULL;
+   /** also include check to see if this fevariable should be saved for analysis purposes */ 
+   feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"fieldVariablesToSave" );
+   if ( NULL == feVarsList  ) {
+      feVarsList = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)"FieldVariablesToSave" );
+   }
+   if (feVarsList != NULL ) {
+      Index                    listLength = Dictionary_Entry_Value_GetCount( feVarsList );
+      Index                    var_I = 0;
+      Dictionary_Entry_Value*  feVarDictValue = NULL;
+      char*                    fieldVariableName;
+   
+      for ( var_I = 0; var_I < listLength; var_I++  ) {
+         feVarDictValue = Dictionary_Entry_Value_GetElement( feVarsList, var_I );
+         fieldVariableName = Dictionary_Entry_Value_AsString( feVarDictValue ); 
+         if ( 0 == strcmp( self->name, fieldVariableName ) ) {
+            self->isSavedData = True;
+            break;
+         }
+      }
+   }
+
+	_FieldVariable_Init( self, context, fieldComponentCount, dim, isCheckpointedAndReloaded, MPI_COMM_WORLD, fV_Register );
+	
+}
+
+void _FieldVariable_Build( void* fieldVariable, void* data ) {
+
+}
+
+void _FieldVariable_Initialise( void* fieldVariable, void* data ) {
+
+}
+
+void _FieldVariable_Execute( void* fieldVariable, void* data ) {
+
+}
+
+void _FieldVariable_Destroy( void* fieldVariable, void* data ) {
+	FieldVariable* self = (FieldVariable*) fieldVariable;
+
+	if( self->extensionMgr ) {
+		Stg_Class_Delete( self->extensionMgr );
+	}
+
+	Stg_Component_Destroy( self, data, False );
+}
+
+InterpolationResult FieldVariable_InterpolateValueAt( void* fieldVariable, Coord coord, double* value ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+
+	return self->_interpolateValueAt( self, coord, value );
+}
+
+double FieldVariable_GetMinGlobalFieldMagnitude( void* fieldVariable ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+	return self->_getMinGlobalFieldMagnitude( self );
+}
+
+
+double FieldVariable_GetMaxGlobalFieldMagnitude( void* fieldVariable ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+	return self->_getMaxGlobalFieldMagnitude( self );
+}
+
+
+void FieldVariable_GetMinAndMaxLocalCoords( void* fieldVariable, Coord min, Coord max ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+
+	self->_getMinAndMaxLocalCoords( self, min, max );
+}
+
+void FieldVariable_GetMinAndMaxGlobalCoords( void* fieldVariable, Coord min, Coord max ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+
+	self->_getMinAndMaxGlobalCoords( self, min, max );
+}
+
+void _FieldVariable_GetMinAndMaxGlobalCoords( void* fieldVariable, Coord globalMin, Coord globalMax ) {
+	FieldVariable*	self = (FieldVariable*)fieldVariable;
+	Coord localMin, localMax;
+
+	self->_getMinAndMaxLocalCoords( self, localMin, localMax );
+
+	MPI_Allreduce( localMin, globalMin, self->dim, MPI_DOUBLE, MPI_MIN, self->communicator );
+	MPI_Allreduce( localMax, globalMax, self->dim, MPI_DOUBLE, MPI_MAX, self->communicator );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/FieldVariable_Register.c
--- a/Utils/src/FieldVariable_Register.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: FieldVariable_Register.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "FieldVariable_Register.h"
-
-#include <assert.h>
-
-
-const Type FieldVariable_Register_Type = "FieldVariable_Register_Type";
-
-FieldVariable_Register*	FieldVariable_Register_New( void ) {
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(FieldVariable_Register);
-	Type                              type = FieldVariable_Register_Type;
-	Stg_Class_DeleteFunction*      _delete = _NamedObject_Register_Delete;
-	Stg_Class_PrintFunction*        _print = _NamedObject_Register_Print;
-	Stg_Class_CopyFunction*          _copy = NULL;
-
-	return (FieldVariable_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/FieldVariable_Register.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/FieldVariable_Register.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,58 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: FieldVariable_Register.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "FieldVariable_Register.h"
+
+#include <assert.h>
+
+
+const Type FieldVariable_Register_Type = "FieldVariable_Register_Type";
+
+FieldVariable_Register*	FieldVariable_Register_New( void ) {
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(FieldVariable_Register);
+	Type                              type = FieldVariable_Register_Type;
+	Stg_Class_DeleteFunction*      _delete = _NamedObject_Register_Delete;
+	Stg_Class_PrintFunction*        _print = _NamedObject_Register_Print;
+	Stg_Class_CopyFunction*          _copy = NULL;
+
+	return (FieldVariable_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/Finalise.c
--- a/Utils/src/Finalise.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool StgDomainUtils_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Finalise.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,49 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool StgDomainUtils_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/Init.c
--- a/Utils/src/Init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,109 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Init.c 4160 2007-07-30 06:17:06Z DavidLee $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "Utils.h"
-
-
-Bool StgDomainUtils_Init( int* argc, char** argv[] ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	VariableCondition_Register_Add( variableCondition_Register, AllElementsVC_Type, AllElementsVC_Factory );
-	VariableCondition_Register_Add( variableCondition_Register, AllNodesVC_Type, AllNodesVC_Factory );
-	VariableCondition_Register_Add( variableCondition_Register, WallVC_Type, WallVC_Factory );
-	VariableCondition_Register_Add( variableCondition_Register, ContactVC_Type, ContactVC_Factory );
-	VariableCondition_Register_Add( variableCondition_Register, CornerVC_Type, CornerVC_Factory );
-	VariableCondition_Register_Add( variableCondition_Register, InnerWallVC_Type, InnerWallVC_Factory );
-	VariableCondition_Register_Add( variableCondition_Register, MeshShapeVC_Type, MeshShapeVC_Factory );
-	
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), DomainContext_Type, (Name)"0", (void* (*)(Name))_DomainContext_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), AllElementsVC_Type, "0", (void* (*)(Name))_AllElementsVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), AllNodesVC_Type, (Name)"0", (void* (*)(Name))_AllNodesVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), DofLayout_Type, "0", (void* (*)(Name))_DofLayout_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), FieldVariable_Type, (Name)"0", (void* (*)(Name))_FieldVariable_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), OperatorFieldVariable_Type, "0", (void* (*)(Name))_OperatorFieldVariable_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), WallVC_Type, (Name)"0", (void* (*)(Name))_WallVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ContactVC_Type, "0", (void* (*)(Name))_ContactVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), CornerVC_Type, (Name)"0", (void* (*)(Name))_CornerVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), InnerWallVC_Type, "0", (void* (*)(Name))_InnerWallVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshShapeVC_Type, (Name)"0", (void*  (*)(Name))_MeshShapeVC_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), MeshBoundaryShape_Type, "0", (void*  (*)(Name))MeshBoundaryShape_New );
-#ifdef HAVE_PETSC
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), RegularRemesherCmpt_Type, (Name)"0", (void* (*)(Name))_RegularRemesherCmpt_DefaultNew );
-#endif
-/*
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Remesher_Type, "0", (void* (*)(Name))_Remesher_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), StripRemesher_Type, (Name)"0", (void* (*)(Name))_StripRemesher_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), CellRemesher_Type, "0", (void* (*)(Name))_CellRemesher_DefaultNew );
-*/
-
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), TimeIntegrator_Type, (Name)"0", (void*  (*)(Name))_TimeIntegrator_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), TimeIntegrand_Type, "0", (void*  (*)(Name))_TimeIntegrand_DefaultNew );
-	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), ShapeAdvector_Type, (Name)"0", (void*  (*)(Name))_ShapeAdvector_DefaultNew  );
-
-	RegisterParent( DomainContext_Type, AbstractContext_Type );
-	RegisterParent( Operator_Type, Stg_Object_Type );
-	RegisterParent( AllElementsVC_Type, VariableCondition_Type );
-	RegisterParent( AllNodesVC_Type, VariableCondition_Type );
-	RegisterParent( WallVC_Type, VariableCondition_Type );
-	RegisterParent( ContactVC_Type, WallVC_Type );
-	RegisterParent( CornerVC_Type, VariableCondition_Type );
-	RegisterParent( InnerWallVC_Type, VariableCondition_Type );
-	RegisterParent( MeshShapeVC_Type, VariableCondition_Type );
-	RegisterParent( MeshBoundaryShape_Type, Stg_Shape_Type );
-	RegisterParent( DofLayout_Type, Stg_Component_Type );
-#ifdef HAVE_PETSC
-	RegisterParent( RegularRemesherCmpt_Type, Remesher_Type );
-#endif
-/*
-	RegisterParent( Remesher_Type, Stg_Component_Type );
-	RegisterParent( StripRemesher_Type, Remesher_Type );
-	RegisterParent( CellRemesher_Type, Remesher_Type );
-*/
-
-	RegisterParent( FieldVariable_Type, Stg_Component_Type );
-	RegisterParent( OperatorFieldVariable_Type, FieldVariable_Type );
-	RegisterParent( FieldVariable_Register_Type, NamedObject_Register_Type );
-	RegisterParent( LinearRegression_Type, Stg_Class_Type );
-	RegisterParent( TimeIntegrand_Type, Stg_Component_Type );
-	RegisterParent( TimeIntegrator_Type, Stg_Component_Type );
-	RegisterParent( ShapeAdvector_Type, Stg_Component_Type );
-	
-	return True;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,109 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Init.c 4160 2007-07-30 06:17:06Z DavidLee $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "Utils.h"
+
+
+Bool StgDomainUtils_Init( int* argc, char** argv[] ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	VariableCondition_Register_Add( variableCondition_Register, AllElementsVC_Type, AllElementsVC_Factory );
+	VariableCondition_Register_Add( variableCondition_Register, AllNodesVC_Type, AllNodesVC_Factory );
+	VariableCondition_Register_Add( variableCondition_Register, WallVC_Type, WallVC_Factory );
+	VariableCondition_Register_Add( variableCondition_Register, ContactVC_Type, ContactVC_Factory );
+	VariableCondition_Register_Add( variableCondition_Register, CornerVC_Type, CornerVC_Factory );
+	VariableCondition_Register_Add( variableCondition_Register, InnerWallVC_Type, InnerWallVC_Factory );
+	VariableCondition_Register_Add( variableCondition_Register, MeshShapeVC_Type, MeshShapeVC_Factory );
+	
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), DomainContext_Type, (Name)"0", (void* (*)(Name))_DomainContext_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), AllElementsVC_Type, "0", (void* (*)(Name))_AllElementsVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), AllNodesVC_Type, (Name)"0", (void* (*)(Name))_AllNodesVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), DofLayout_Type, "0", (void* (*)(Name))_DofLayout_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), FieldVariable_Type, (Name)"0", (void* (*)(Name))_FieldVariable_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), OperatorFieldVariable_Type, "0", (void* (*)(Name))_OperatorFieldVariable_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), WallVC_Type, (Name)"0", (void* (*)(Name))_WallVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), ContactVC_Type, "0", (void* (*)(Name))_ContactVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), CornerVC_Type, (Name)"0", (void* (*)(Name))_CornerVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), InnerWallVC_Type, "0", (void* (*)(Name))_InnerWallVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), MeshShapeVC_Type, (Name)"0", (void*  (*)(Name))_MeshShapeVC_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), MeshBoundaryShape_Type, "0", (void*  (*)(Name))MeshBoundaryShape_New );
+#ifdef HAVE_PETSC
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), RegularRemesherCmpt_Type, (Name)"0", (void* (*)(Name))_RegularRemesherCmpt_DefaultNew );
+#endif
+/*
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), Remesher_Type, "0", (void* (*)(Name))_Remesher_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), StripRemesher_Type, (Name)"0", (void* (*)(Name))_StripRemesher_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), CellRemesher_Type, "0", (void* (*)(Name))_CellRemesher_DefaultNew );
+*/
+
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), TimeIntegrator_Type, (Name)"0", (void*  (*)(Name))_TimeIntegrator_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister( ), TimeIntegrand_Type, "0", (void*  (*)(Name))_TimeIntegrand_DefaultNew );
+	Stg_ComponentRegister_Add( Stg_ComponentRegister_Get_ComponentRegister(), ShapeAdvector_Type, (Name)"0", (void*  (*)(Name))_ShapeAdvector_DefaultNew  );
+
+	RegisterParent( DomainContext_Type, AbstractContext_Type );
+	RegisterParent( Operator_Type, Stg_Object_Type );
+	RegisterParent( AllElementsVC_Type, VariableCondition_Type );
+	RegisterParent( AllNodesVC_Type, VariableCondition_Type );
+	RegisterParent( WallVC_Type, VariableCondition_Type );
+	RegisterParent( ContactVC_Type, WallVC_Type );
+	RegisterParent( CornerVC_Type, VariableCondition_Type );
+	RegisterParent( InnerWallVC_Type, VariableCondition_Type );
+	RegisterParent( MeshShapeVC_Type, VariableCondition_Type );
+	RegisterParent( MeshBoundaryShape_Type, Stg_Shape_Type );
+	RegisterParent( DofLayout_Type, Stg_Component_Type );
+#ifdef HAVE_PETSC
+	RegisterParent( RegularRemesherCmpt_Type, Remesher_Type );
+#endif
+/*
+	RegisterParent( Remesher_Type, Stg_Component_Type );
+	RegisterParent( StripRemesher_Type, Remesher_Type );
+	RegisterParent( CellRemesher_Type, Remesher_Type );
+*/
+
+	RegisterParent( FieldVariable_Type, Stg_Component_Type );
+	RegisterParent( OperatorFieldVariable_Type, FieldVariable_Type );
+	RegisterParent( FieldVariable_Register_Type, NamedObject_Register_Type );
+	RegisterParent( LinearRegression_Type, Stg_Class_Type );
+	RegisterParent( TimeIntegrand_Type, Stg_Component_Type );
+	RegisterParent( TimeIntegrator_Type, Stg_Component_Type );
+	RegisterParent( ShapeAdvector_Type, Stg_Component_Type );
+	
+	return True;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/InnerWallVC.c
--- a/Utils/src/InnerWallVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,623 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: InnerWallVC.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "InnerWallVC.h"
-#include "RegularMeshUtils.h"
-
-#include <string.h>
-#include <assert.h>
-
-
-const Type InnerWallVC_Type = "InnerWallVC";
-const Name defaultInnerWallVCName = "defaultInnerWallVCName";
-
-Name InnerWallVC_InnerWallEnumToStr[InnerWallVC_InnerWall_Size] = {
-	"back",
-	"left",
-	"bottom",
-	"right",
-	"top",
-	"front" };
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-VariableCondition* InnerWallVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									data )
-{
-	return (VariableCondition*)InnerWallVC_New( defaultInnerWallVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
-}
-
-InnerWallVC* InnerWallVC_New(
-	Name									name,
-	AbstractContext*					context,
-	Name									_dictionaryEntryName, 
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									_mesh )
-{
-	InnerWallVC* self = _InnerWallVC_DefaultNew( name );
-
-	self->isConstructed = True;
-	_VariableCondition_Init( (VariableCondition*)self, context, variable_Register, conFunc_Register, dictionary );
-	_InnerWallVC_Init( self, _dictionaryEntryName, _mesh );
-
-	return self;
-}
-InnerWallVC* _InnerWallVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(InnerWallVC);
-	Type                                                       type = InnerWallVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _InnerWallVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _InnerWallVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _InnerWallVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_InnerWallVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _InnerWallVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _InnerWallVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _InnerWallVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _InnerWallVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _InnerWallVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _InnerWallVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _InnerWallVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _InnerWallVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _InnerWallVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _InnerWallVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _InnerWallVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _InnerWallVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return _InnerWallVC_New(  INNERWALLVC_PASSARGS  );
-}
-
-InnerWallVC* _InnerWallVC_New(  INNERWALLVC_DEFARGS  ) {
-	InnerWallVC* self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(InnerWallVC) );
-	self = (InnerWallVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	
-	return self;
-}
-
-
-void _InnerWallVC_Init(
-	void*	innerWallVC, 
-	Name	_dictionaryEntryName, 
-	void*	_mesh )
-{
-	InnerWallVC* self = (InnerWallVC*)innerWallVC;
-
-	self->isConstructed = True;
-	self->_dictionaryEntryName = _dictionaryEntryName;
-	self->_mesh = (Mesh*)_mesh;
-	self->_innerWall = InnerWallVC_InnerWall_Size;
-	self->_entryTbl = 0;
-	self->_entryCount = 0;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-void _InnerWallVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-	InnerWallVC*			self = (InnerWallVC*)variableCondition;
-	Dictionary_Entry_Value*	vcDictVal;
-	Dictionary_Entry_Value	_vcDictVal;
-	Dictionary_Entry_Value*	varsVal;
-	InnerWallVC_Entry_Index	entry_I;
-	
-	/* Find dictionary entry */
-	if (self->_dictionaryEntryName)
-		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
-	else
-	{
-		vcDictVal = &_vcDictVal;
-		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
-	}
-	
-	if (vcDictVal)
-	{
-		char*	innerWallStr;
-		
-		/* Obtain which innerWall */
-		innerWallStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"innerWall" ) );
-		if (!strcasecmp(innerWallStr, "back"))
-			self->_innerWall = InnerWallVC_InnerWall_Back;
-		else if (!strcasecmp(innerWallStr, "left"))
-			self->_innerWall = InnerWallVC_InnerWall_Left;
-		else if (!strcasecmp(innerWallStr, "bottom"))
-			self->_innerWall = InnerWallVC_InnerWall_Bottom;
-		else if (!strcasecmp(innerWallStr, "right"))
-			self->_innerWall = InnerWallVC_InnerWall_Right;
-		else if (!strcasecmp(innerWallStr, "top"))
-			self->_innerWall = InnerWallVC_InnerWall_Top;
-		else if (!strcasecmp(innerWallStr, "front"))
-			self->_innerWall = InnerWallVC_InnerWall_Front;
-		else {
-			assert( 0 );
-			self->_innerWall = InnerWallVC_InnerWall_Size; /* invalid entry */
-		}
-		
-		/* Obtain the variable entries */
-		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-		self->_entryTbl = Memory_Alloc_Array( InnerWallVC_Entry, self->_entryCount, "InnerWallVC->_entryTbl" );
-		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ )
-		{
-			char*			valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
-				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-			if (0 == strcasecmp(valType, "func"))
-			{
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-				if ( cfIndex == (unsigned)-1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-							"definition of innerWallVC \"%s\" (applies to innerWall \"%s\"), the cond. func. applied to "
-							"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-							__func__, self->_dictionaryEntryName, InnerWallVC_InnerWallEnumToStr[self->_innerWall],
-							self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}
-			else if (0 == strcasecmp(valType, "array"))
-			{
-				Dictionary_Entry_Value*	valueElement;
-				Index			i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
-													self->_entryTbl[entry_I].value.as.typeArray.size, "InnerWallVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-				{
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
-						Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
-				 0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
-			{
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_DPrintf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else
-	{
-		self->_innerWall = InnerWallVC_InnerWall_Size;
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-	}
-}
-
-
-void _InnerWallVC_Delete( void* innerWallVC ) {
-	InnerWallVC* self = (InnerWallVC*)innerWallVC;
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Delete( self );
-}
-
-void _InnerWallVC_Destroy( void* innerWallVC, void* data ) {
-	InnerWallVC* self = (InnerWallVC*)innerWallVC;
-	
-	if (self->_entryTbl) Memory_Free(self->_entryTbl);
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Destroy( self, data );
-}
-
-void _InnerWallVC_Print(void* innerWallVC, Stream* stream)
-{
-	InnerWallVC*				self = (InnerWallVC*)innerWallVC;
-	InnerWallVC_Entry_Index		entry_I;
-	Index				i;
-	
-	/* Set the Journal for printing informations */
-	Stream* info = stream;
-	
-	/* General info */
-	Journal_Printf( info, "InnerWallVC (ptr): %p\n", self);
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
-	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-	if (self->_dictionaryEntryName)
-		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-	Journal_Printf( info, "\t_innerWall: %s\n", self->_innerWall == InnerWallVC_InnerWall_Front ? "Front" :
-			self->_innerWall == InnerWallVC_InnerWall_Back ? "Back" : self->_innerWall == InnerWallVC_InnerWall_Left ? "Left" :
-			self->_innerWall == InnerWallVC_InnerWall_Right ? "Right" : self->_innerWall == InnerWallVC_InnerWall_Top ? "Top" :
-			self->_innerWall == InnerWallVC_InnerWall_Bottom ? "Bottom" : "None");
-	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
-	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-	if (self->_entryTbl)
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
-		{
-			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
-			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-			if (self->_entryTbl[entry_I].varName)
-				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-			Journal_Printf( info, "\t\t\tvalue:\n");
-			switch (self->_entryTbl[entry_I].value.type)
-			{
-			case VC_ValueType_Double:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
-				Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-				break;
-					
-			case VC_ValueType_Int:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
-				Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-				break;
-					
-			case VC_ValueType_Short:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
-				Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-				break;
-					
-			case VC_ValueType_Char:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
-				Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-				break;
-					
-			case VC_ValueType_Ptr:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-				Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-				break;
-					
-			case VC_ValueType_DoubleArray:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-				Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-				Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
-						self->_entryTbl[entry_I].value.as.typeArray.array);
-				if (self->_entryTbl[entry_I].value.as.typeArray.array)
-					for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-						Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
-								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
-				break;
-					
-			case VC_ValueType_CFIndex:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-				Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-				break;
-			}
-		}
-	Journal_Printf( info, "\t_mesh (ptr): %p\n", self->_mesh);
-	
-	/* Print parent */
-	_VariableCondition_Print(self);
-}
-
-
-void* _InnerWallVC_Copy( const void* innerWallVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-	InnerWallVC*		self = (InnerWallVC*)innerWallVC;
-	InnerWallVC*		newInnerWallVC;
-	PtrMap*		map = ptrMap;
-	Bool		ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newInnerWallVC = (InnerWallVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-	newInnerWallVC->_dictionaryEntryName = self->_dictionaryEntryName;
-	newInnerWallVC->_innerWall = self->_innerWall;
-	newInnerWallVC->_entryCount = self->_entryCount;
-	
-	if( deep ) {
-		newInnerWallVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
-		
-		if( (newInnerWallVC->_entryTbl = (InnerWallVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-			newInnerWallVC->_entryTbl = Memory_Alloc_Array( InnerWallVC_Entry, newInnerWallVC->_entryCount, "InnerWallVC->_entryTbl");
-			memcpy( newInnerWallVC->_entryTbl, self->_entryTbl, sizeof(InnerWallVC_Entry) * newInnerWallVC->_entryCount );
-			PtrMap_Append( map, newInnerWallVC->_entryTbl, self->_entryTbl );
-		}
-	}
-	else {
-		newInnerWallVC->_mesh = self->_mesh;
-		newInnerWallVC->_entryTbl = self->_entryTbl;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newInnerWallVC;
-}
-
-
-void _InnerWallVC_Build(  void* innerWallVC, void* data ) {
-	InnerWallVC*			self = (InnerWallVC*)innerWallVC;
-	
-	_InnerWallVC_BuildSelf( self, data );
-	
-	_VariableCondition_Build( self, data );
-}
-	
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _InnerWallVC_AssignFromXML( void* innerWallVC, Stg_ComponentFactory* cf, void* data ) { 
-}
-
-void _InnerWallVC_BuildSelf(  void* innerWallVC, void* data ) {
-	InnerWallVC* self = (InnerWallVC*)innerWallVC;
-	
-	if( self->_mesh ) {
-		Stg_Component_Build( self->_mesh, data, False );
-	}
-}
-
-
-IndexSet* _InnerWallVC_GetSet(void* variableCondition) {
-	InnerWallVC*	self = (InnerWallVC*)variableCondition;
-	IndexSet			*set = NULL;
-	Stream*			warningStr = Journal_Register( Error_Type, (Name)self->type );
-	unsigned			nDims;
-	Grid*				vertGrid;
-
-	nDims = Mesh_GetDimSize( self->_mesh );
-	vertGrid = *(Grid** )ExtensionManager_Get( self->_mesh->info, self->_mesh, ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
-	
-	switch (self->_innerWall) {
-	case InnerWallVC_InnerWall_Front:
-		if ( nDims < 3 || !vertGrid->sizes[2]  ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "K" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalInnerFrontSet( self->_mesh );
-		}
-		break;
-			
-	case InnerWallVC_InnerWall_Back:
-		if ( nDims < 3 || !vertGrid->sizes[2] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "K" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalInnerBackSet( self->_mesh );
-		}	
-		break;
-			
-	case InnerWallVC_InnerWall_Top:
-		if ( nDims < 2 || !vertGrid->sizes[1] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "J" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalInnerTopSet(self->_mesh);
-		}	
-		break;
-			
-	case InnerWallVC_InnerWall_Bottom:
-		if ( nDims < 2 || !vertGrid->sizes[1] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "J" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalInnerBottomSet(self->_mesh);
-		}	
-		break;
-			
-	case InnerWallVC_InnerWall_Left:
-		if ( nDims < 1 ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "I" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalInnerLeftSet(self->_mesh);
-		}	
-		break;
-			
-	case InnerWallVC_InnerWall_Right:
-		if( nDims < 1 ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "I" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalInnerRightSet(self->_mesh);
-		}
-		break;
-			
-	case InnerWallVC_InnerWall_Size:
-	default:
-		assert(0);
-		break;
-	}
-	
-	return set;
-}
-
-
-VariableCondition_VariableIndex _InnerWallVC_GetVariableCount(void* variableCondition, Index globalIndex)
-{
-	InnerWallVC*	self = (InnerWallVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-Variable_Index _InnerWallVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex)
-{
-	InnerWallVC*		self = (InnerWallVC*)variableCondition;
-	Variable_Index	searchedIndex = 0;
-	Stream*		errorStr = Journal_Register( Error_Type, (Name)self->type  );
-	Name		varName;
-	
-	varName = self->_entryTbl[varIndex].varName;
-	searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
-	
-	Journal_Firewall( ( searchedIndex < self->variable_Register->count ), errorStr, "Error- in %s: searching for index of "
-			  "varIndex %u (\"%s\") at global node number %u failed - register returned index %u, greater than "
-			  "count %u.\n", __func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
-
-	return searchedIndex; 
-}
-
-
-VariableCondition_ValueIndex _InnerWallVC_GetValueIndex(
-	void*				variableCondition, 
-	Index				globalIndex, 
-	VariableCondition_VariableIndex	varIndex)
-{
-	return varIndex;
-}
-
-
-VariableCondition_ValueIndex _InnerWallVC_GetValueCount(void* variableCondition)
-{
-	InnerWallVC*	self = (InnerWallVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-VariableCondition_Value _InnerWallVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex)
-{
-	InnerWallVC*	self = (InnerWallVC*)variableCondition;
-
-	return self->_entryTbl[valIndex].value;
-}
-
-void _InnerWallVC_PrintConcise( void* variableCondition, Stream* stream ) {
-	InnerWallVC*		self = (InnerWallVC*)variableCondition;
-	
-	Journal_Printf( stream, "\ttype: %s, set: ", self->type );
-	Journal_Printf( stream, "%s\n", 
-			self->_innerWall == InnerWallVC_InnerWall_Front ? "Front" :
-			self->_innerWall == InnerWallVC_InnerWall_Back ? "Back" : 
-			self->_innerWall == InnerWallVC_InnerWall_Left ? "Left" :
-			self->_innerWall == InnerWallVC_InnerWall_Right ? "Right" : 
-			self->_innerWall == InnerWallVC_InnerWall_Top ? "Top" :
-			self->_innerWall == InnerWallVC_InnerWall_Bottom ? "Bottom" : "None" );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Build functions
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/InnerWallVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/InnerWallVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,623 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: InnerWallVC.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "InnerWallVC.h"
+#include "RegularMeshUtils.h"
+
+#include <string.h>
+#include <assert.h>
+
+
+const Type InnerWallVC_Type = "InnerWallVC";
+const Name defaultInnerWallVCName = "defaultInnerWallVCName";
+
+Name InnerWallVC_InnerWallEnumToStr[InnerWallVC_InnerWall_Size] = {
+	"back",
+	"left",
+	"bottom",
+	"right",
+	"top",
+	"front" };
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+VariableCondition* InnerWallVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									data )
+{
+	return (VariableCondition*)InnerWallVC_New( defaultInnerWallVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
+}
+
+InnerWallVC* InnerWallVC_New(
+	Name									name,
+	AbstractContext*					context,
+	Name									_dictionaryEntryName, 
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									_mesh )
+{
+	InnerWallVC* self = _InnerWallVC_DefaultNew( name );
+
+	self->isConstructed = True;
+	_VariableCondition_Init( (VariableCondition*)self, context, variable_Register, conFunc_Register, dictionary );
+	_InnerWallVC_Init( self, _dictionaryEntryName, _mesh );
+
+	return self;
+}
+InnerWallVC* _InnerWallVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(InnerWallVC);
+	Type                                                       type = InnerWallVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _InnerWallVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _InnerWallVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _InnerWallVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_InnerWallVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _InnerWallVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _InnerWallVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _InnerWallVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _InnerWallVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _InnerWallVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _InnerWallVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _InnerWallVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _InnerWallVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _InnerWallVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _InnerWallVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _InnerWallVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _InnerWallVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return _InnerWallVC_New(  INNERWALLVC_PASSARGS  );
+}
+
+InnerWallVC* _InnerWallVC_New(  INNERWALLVC_DEFARGS  ) {
+	InnerWallVC* self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(InnerWallVC) );
+	self = (InnerWallVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	
+	return self;
+}
+
+
+void _InnerWallVC_Init(
+	void*	innerWallVC, 
+	Name	_dictionaryEntryName, 
+	void*	_mesh )
+{
+	InnerWallVC* self = (InnerWallVC*)innerWallVC;
+
+	self->isConstructed = True;
+	self->_dictionaryEntryName = _dictionaryEntryName;
+	self->_mesh = (Mesh*)_mesh;
+	self->_innerWall = InnerWallVC_InnerWall_Size;
+	self->_entryTbl = 0;
+	self->_entryCount = 0;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+void _InnerWallVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+	InnerWallVC*			self = (InnerWallVC*)variableCondition;
+	Dictionary_Entry_Value*	vcDictVal;
+	Dictionary_Entry_Value	_vcDictVal;
+	Dictionary_Entry_Value*	varsVal;
+	InnerWallVC_Entry_Index	entry_I;
+	
+	/* Find dictionary entry */
+	if (self->_dictionaryEntryName)
+		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
+	else
+	{
+		vcDictVal = &_vcDictVal;
+		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
+	}
+	
+	if (vcDictVal)
+	{
+		char*	innerWallStr;
+		
+		/* Obtain which innerWall */
+		innerWallStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"innerWall" ) );
+		if (!strcasecmp(innerWallStr, "back"))
+			self->_innerWall = InnerWallVC_InnerWall_Back;
+		else if (!strcasecmp(innerWallStr, "left"))
+			self->_innerWall = InnerWallVC_InnerWall_Left;
+		else if (!strcasecmp(innerWallStr, "bottom"))
+			self->_innerWall = InnerWallVC_InnerWall_Bottom;
+		else if (!strcasecmp(innerWallStr, "right"))
+			self->_innerWall = InnerWallVC_InnerWall_Right;
+		else if (!strcasecmp(innerWallStr, "top"))
+			self->_innerWall = InnerWallVC_InnerWall_Top;
+		else if (!strcasecmp(innerWallStr, "front"))
+			self->_innerWall = InnerWallVC_InnerWall_Front;
+		else {
+			assert( 0 );
+			self->_innerWall = InnerWallVC_InnerWall_Size; /* invalid entry */
+		}
+		
+		/* Obtain the variable entries */
+		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+		self->_entryTbl = Memory_Alloc_Array( InnerWallVC_Entry, self->_entryCount, "InnerWallVC->_entryTbl" );
+		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ )
+		{
+			char*			valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
+				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+			if (0 == strcasecmp(valType, "func"))
+			{
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+				if ( cfIndex == (unsigned)-1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+							"definition of innerWallVC \"%s\" (applies to innerWall \"%s\"), the cond. func. applied to "
+							"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+							__func__, self->_dictionaryEntryName, InnerWallVC_InnerWallEnumToStr[self->_innerWall],
+							self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}
+			else if (0 == strcasecmp(valType, "array"))
+			{
+				Dictionary_Entry_Value*	valueElement;
+				Index			i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
+													self->_entryTbl[entry_I].value.as.typeArray.size, "InnerWallVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+				{
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
+						Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
+				 0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
+			{
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_DPrintf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else
+	{
+		self->_innerWall = InnerWallVC_InnerWall_Size;
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+	}
+}
+
+
+void _InnerWallVC_Delete( void* innerWallVC ) {
+	InnerWallVC* self = (InnerWallVC*)innerWallVC;
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Delete( self );
+}
+
+void _InnerWallVC_Destroy( void* innerWallVC, void* data ) {
+	InnerWallVC* self = (InnerWallVC*)innerWallVC;
+	
+	if (self->_entryTbl) Memory_Free(self->_entryTbl);
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Destroy( self, data );
+}
+
+void _InnerWallVC_Print(void* innerWallVC, Stream* stream)
+{
+	InnerWallVC*				self = (InnerWallVC*)innerWallVC;
+	InnerWallVC_Entry_Index		entry_I;
+	Index				i;
+	
+	/* Set the Journal for printing informations */
+	Stream* info = stream;
+	
+	/* General info */
+	Journal_Printf( info, "InnerWallVC (ptr): %p\n", self);
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
+	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+	if (self->_dictionaryEntryName)
+		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+	Journal_Printf( info, "\t_innerWall: %s\n", self->_innerWall == InnerWallVC_InnerWall_Front ? "Front" :
+			self->_innerWall == InnerWallVC_InnerWall_Back ? "Back" : self->_innerWall == InnerWallVC_InnerWall_Left ? "Left" :
+			self->_innerWall == InnerWallVC_InnerWall_Right ? "Right" : self->_innerWall == InnerWallVC_InnerWall_Top ? "Top" :
+			self->_innerWall == InnerWallVC_InnerWall_Bottom ? "Bottom" : "None");
+	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
+	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+	if (self->_entryTbl)
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
+		{
+			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
+			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+			if (self->_entryTbl[entry_I].varName)
+				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+			Journal_Printf( info, "\t\t\tvalue:\n");
+			switch (self->_entryTbl[entry_I].value.type)
+			{
+			case VC_ValueType_Double:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
+				Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+				break;
+					
+			case VC_ValueType_Int:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
+				Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+				break;
+					
+			case VC_ValueType_Short:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
+				Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+				break;
+					
+			case VC_ValueType_Char:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
+				Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+				break;
+					
+			case VC_ValueType_Ptr:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+				Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+				break;
+					
+			case VC_ValueType_DoubleArray:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+				Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+				Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
+						self->_entryTbl[entry_I].value.as.typeArray.array);
+				if (self->_entryTbl[entry_I].value.as.typeArray.array)
+					for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+						Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
+								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
+				break;
+					
+			case VC_ValueType_CFIndex:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+				Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+				break;
+			}
+		}
+	Journal_Printf( info, "\t_mesh (ptr): %p\n", self->_mesh);
+	
+	/* Print parent */
+	_VariableCondition_Print(self);
+}
+
+
+void* _InnerWallVC_Copy( const void* innerWallVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+	InnerWallVC*		self = (InnerWallVC*)innerWallVC;
+	InnerWallVC*		newInnerWallVC;
+	PtrMap*		map = ptrMap;
+	Bool		ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newInnerWallVC = (InnerWallVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+	newInnerWallVC->_dictionaryEntryName = self->_dictionaryEntryName;
+	newInnerWallVC->_innerWall = self->_innerWall;
+	newInnerWallVC->_entryCount = self->_entryCount;
+	
+	if( deep ) {
+		newInnerWallVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
+		
+		if( (newInnerWallVC->_entryTbl = (InnerWallVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+			newInnerWallVC->_entryTbl = Memory_Alloc_Array( InnerWallVC_Entry, newInnerWallVC->_entryCount, "InnerWallVC->_entryTbl");
+			memcpy( newInnerWallVC->_entryTbl, self->_entryTbl, sizeof(InnerWallVC_Entry) * newInnerWallVC->_entryCount );
+			PtrMap_Append( map, newInnerWallVC->_entryTbl, self->_entryTbl );
+		}
+	}
+	else {
+		newInnerWallVC->_mesh = self->_mesh;
+		newInnerWallVC->_entryTbl = self->_entryTbl;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newInnerWallVC;
+}
+
+
+void _InnerWallVC_Build(  void* innerWallVC, void* data ) {
+	InnerWallVC*			self = (InnerWallVC*)innerWallVC;
+	
+	_InnerWallVC_BuildSelf( self, data );
+	
+	_VariableCondition_Build( self, data );
+}
+	
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _InnerWallVC_AssignFromXML( void* innerWallVC, Stg_ComponentFactory* cf, void* data ) { 
+}
+
+void _InnerWallVC_BuildSelf(  void* innerWallVC, void* data ) {
+	InnerWallVC* self = (InnerWallVC*)innerWallVC;
+	
+	if( self->_mesh ) {
+		Stg_Component_Build( self->_mesh, data, False );
+	}
+}
+
+
+IndexSet* _InnerWallVC_GetSet(void* variableCondition) {
+	InnerWallVC*	self = (InnerWallVC*)variableCondition;
+	IndexSet			*set = NULL;
+	Stream*			warningStr = Journal_Register( Error_Type, (Name)self->type );
+	unsigned			nDims;
+	Grid*				vertGrid;
+
+	nDims = Mesh_GetDimSize( self->_mesh );
+	vertGrid = *(Grid** )ExtensionManager_Get( self->_mesh->info, self->_mesh, ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
+	
+	switch (self->_innerWall) {
+	case InnerWallVC_InnerWall_Front:
+		if ( nDims < 3 || !vertGrid->sizes[2]  ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "K" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalInnerFrontSet( self->_mesh );
+		}
+		break;
+			
+	case InnerWallVC_InnerWall_Back:
+		if ( nDims < 3 || !vertGrid->sizes[2] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "K" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalInnerBackSet( self->_mesh );
+		}	
+		break;
+			
+	case InnerWallVC_InnerWall_Top:
+		if ( nDims < 2 || !vertGrid->sizes[1] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "J" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalInnerTopSet(self->_mesh);
+		}	
+		break;
+			
+	case InnerWallVC_InnerWall_Bottom:
+		if ( nDims < 2 || !vertGrid->sizes[1] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "J" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalInnerBottomSet(self->_mesh);
+		}	
+		break;
+			
+	case InnerWallVC_InnerWall_Left:
+		if ( nDims < 1 ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "I" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalInnerLeftSet(self->_mesh);
+		}	
+		break;
+			
+	case InnerWallVC_InnerWall_Right:
+		if( nDims < 1 ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					InnerWallVC_InnerWallEnumToStr[self->_innerWall], "I" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalInnerRightSet(self->_mesh);
+		}
+		break;
+			
+	case InnerWallVC_InnerWall_Size:
+	default:
+		assert(0);
+		break;
+	}
+	
+	return set;
+}
+
+
+VariableCondition_VariableIndex _InnerWallVC_GetVariableCount(void* variableCondition, Index globalIndex)
+{
+	InnerWallVC*	self = (InnerWallVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+Variable_Index _InnerWallVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex)
+{
+	InnerWallVC*		self = (InnerWallVC*)variableCondition;
+	Variable_Index	searchedIndex = 0;
+	Stream*		errorStr = Journal_Register( Error_Type, (Name)self->type  );
+	Name		varName;
+	
+	varName = self->_entryTbl[varIndex].varName;
+	searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
+	
+	Journal_Firewall( ( searchedIndex < self->variable_Register->count ), errorStr, "Error- in %s: searching for index of "
+			  "varIndex %u (\"%s\") at global node number %u failed - register returned index %u, greater than "
+			  "count %u.\n", __func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
+
+	return searchedIndex; 
+}
+
+
+VariableCondition_ValueIndex _InnerWallVC_GetValueIndex(
+	void*				variableCondition, 
+	Index				globalIndex, 
+	VariableCondition_VariableIndex	varIndex)
+{
+	return varIndex;
+}
+
+
+VariableCondition_ValueIndex _InnerWallVC_GetValueCount(void* variableCondition)
+{
+	InnerWallVC*	self = (InnerWallVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+VariableCondition_Value _InnerWallVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex)
+{
+	InnerWallVC*	self = (InnerWallVC*)variableCondition;
+
+	return self->_entryTbl[valIndex].value;
+}
+
+void _InnerWallVC_PrintConcise( void* variableCondition, Stream* stream ) {
+	InnerWallVC*		self = (InnerWallVC*)variableCondition;
+	
+	Journal_Printf( stream, "\ttype: %s, set: ", self->type );
+	Journal_Printf( stream, "%s\n", 
+			self->_innerWall == InnerWallVC_InnerWall_Front ? "Front" :
+			self->_innerWall == InnerWallVC_InnerWall_Back ? "Back" : 
+			self->_innerWall == InnerWallVC_InnerWall_Left ? "Left" :
+			self->_innerWall == InnerWallVC_InnerWall_Right ? "Right" : 
+			self->_innerWall == InnerWallVC_InnerWall_Top ? "Top" :
+			self->_innerWall == InnerWallVC_InnerWall_Bottom ? "Bottom" : "None" );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Build functions
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/LinearRegression.c
--- a/Utils/src/LinearRegression.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: LinearRegression.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "LinearRegression.h"
-
-#include <assert.h>
-
-const Type LinearRegression_Type = "LinearRegression";
-
-LinearRegression* LinearRegression_New(Variable* xVariable, Variable* yVariable) {
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(LinearRegression);
-	Type                              type = LinearRegression_Type;
-	Stg_Class_DeleteFunction*      _delete = _LinearRegression_Delete;
-	Stg_Class_PrintFunction*        _print = _LinearRegression_Print;
-	Stg_Class_CopyFunction*          _copy = _LinearRegression_Copy;
-
-	return _LinearRegression_New(  LINEARREGRESSION_PASSARGS  );
-}
-
-LinearRegression* _LinearRegression_New(  LINEARREGRESSION_DEFARGS  )		
-{
-	LinearRegression*		self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(LinearRegression) );
-	self = (LinearRegression*)_Stg_Class_New(  STG_CLASS_PASSARGS  );
-	
-	self->xVariable = xVariable;
-	self->yVariable = yVariable;
-	
-	return self;
-}
-
-void _LinearRegression_Delete( void* linearRegression ) {
-	LinearRegression* self = (LinearRegression*) linearRegression;
-	_Stg_Class_Delete( self );
-}
-
-void _LinearRegression_Print( void* _linearRegression, Stream* stream ) {
-	LinearRegression* self = (LinearRegression*) _linearRegression;
-	Journal_Printf( stream, "LinearRegression\n" );
-
-	Journal_PrintValue( stream, self->xMean );
-	Journal_PrintValue( stream, self->yMean );
-	Journal_PrintValue( stream, self->slope );
-	Journal_PrintValue( stream, self->interceptor );
-	Journal_PrintValue( stream, self->slopeStandardError );
-	Journal_PrintValue( stream, self->interceptorStandardError );
-	Journal_PrintValue( stream, self->correlationCoefficient );
-}
-
-void* _LinearRegression_Copy( const void* linearRegression, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	LinearRegression*	self = (LinearRegression*)linearRegression;
-	LinearRegression*	newLinearRegression;
-	
-	newLinearRegression = (LinearRegression*)_Stg_Class_Copy( self, dest, deep, nameExt, ptrMap );
-				
-	return (void*)newLinearRegression;
-}
-
-/* Based on least squares proceedure described in 
- * Eric W. Weisstein. "Least Squares Fitting." From MathWorld--A Wolfram Web Resource.
- * http://mathworld.wolfram.com/LeastSquaresFitting.html */
-void LinearRegression_Calculate( void* linearRegression ) {
-	LinearRegression*	self      = (LinearRegression*)linearRegression;
-	Variable*           xVariable = self->xVariable;
-	Variable*           yVariable = self->yVariable;
-	Index               array_I;
-	Index               arraySize;
-	double              xMean     = 0.0;
-	double              yMean     = 0.0;
-	double              xValue;
-	double              yValue;
-	double              SS_xx     = 0.0;
-	double              SS_yy     = 0.0;
-	double              SS_xy     = 0.0;
-	double              slope;
-	double              errorVariance;
-
-	Variable_Update( xVariable );
-	Variable_Update( yVariable );
-
-	arraySize = self->xVariable->arraySize;
-	assert( arraySize == yVariable->arraySize );
-
-	for ( array_I = 0 ; array_I < arraySize ; array_I++ ) {
-		xValue = Variable_GetValueDouble( xVariable, array_I );
-		yValue = Variable_GetValueDouble( yVariable, array_I );
-
-		xMean += xValue;
-		yMean += yValue;
-
-		/* Sum intermediate values - Equations 17, 19, 21 */
-		SS_xx += xValue * xValue;
-		SS_yy += yValue * yValue;
-		SS_xy += xValue * yValue;
-	}
-
-	/* Divide by array size to obtain true mean */
-	xMean /= (double) arraySize;
-	yMean /= (double) arraySize;
-	self->xMean = xMean;
-	self->yMean = yMean;
-
-	/* Calculate intermediate values - Equations 17, 19, 21 */
-	SS_xx -= (double) arraySize * xMean * xMean;
-	SS_yy -= (double) arraySize * yMean * yMean;
-	SS_xy -= (double) arraySize * xMean * yMean;
-
-	/* Finalise calculation coefficients of linear equations y ~= slope * x + interceptor - Equation 27 - 28 */
-	self->slope = slope = SS_xy / SS_xx;
-	self->interceptor   =         yMean - slope * xMean;
-
-	/* Calculate the correlation coefficient r^2 - Equation 29 */
-	self->correlationCoefficient = SS_xy * SS_xy / ( SS_xx * SS_yy );
-
-	/* Calculate Standard errors - Equations 33-35 */
-	errorVariance = sqrt( ( SS_yy - slope * SS_xy ) / (double) (arraySize - 2 ) );
-	self->interceptorStandardError = errorVariance * sqrt( 1.0/(double)arraySize + xMean*xMean/SS_xx );
-	self->slopeStandardError       = errorVariance / sqrt( SS_xx );
-}
-
-
-
-
-	
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/LinearRegression.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/LinearRegression.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,164 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: LinearRegression.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "LinearRegression.h"
+
+#include <assert.h>
+
+const Type LinearRegression_Type = "LinearRegression";
+
+LinearRegression* LinearRegression_New(Variable* xVariable, Variable* yVariable) {
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(LinearRegression);
+	Type                              type = LinearRegression_Type;
+	Stg_Class_DeleteFunction*      _delete = _LinearRegression_Delete;
+	Stg_Class_PrintFunction*        _print = _LinearRegression_Print;
+	Stg_Class_CopyFunction*          _copy = _LinearRegression_Copy;
+
+	return _LinearRegression_New(  LINEARREGRESSION_PASSARGS  );
+}
+
+LinearRegression* _LinearRegression_New(  LINEARREGRESSION_DEFARGS  )		
+{
+	LinearRegression*		self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(LinearRegression) );
+	self = (LinearRegression*)_Stg_Class_New(  STG_CLASS_PASSARGS  );
+	
+	self->xVariable = xVariable;
+	self->yVariable = yVariable;
+	
+	return self;
+}
+
+void _LinearRegression_Delete( void* linearRegression ) {
+	LinearRegression* self = (LinearRegression*) linearRegression;
+	_Stg_Class_Delete( self );
+}
+
+void _LinearRegression_Print( void* _linearRegression, Stream* stream ) {
+	LinearRegression* self = (LinearRegression*) _linearRegression;
+	Journal_Printf( stream, "LinearRegression\n" );
+
+	Journal_PrintValue( stream, self->xMean );
+	Journal_PrintValue( stream, self->yMean );
+	Journal_PrintValue( stream, self->slope );
+	Journal_PrintValue( stream, self->interceptor );
+	Journal_PrintValue( stream, self->slopeStandardError );
+	Journal_PrintValue( stream, self->interceptorStandardError );
+	Journal_PrintValue( stream, self->correlationCoefficient );
+}
+
+void* _LinearRegression_Copy( const void* linearRegression, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	LinearRegression*	self = (LinearRegression*)linearRegression;
+	LinearRegression*	newLinearRegression;
+	
+	newLinearRegression = (LinearRegression*)_Stg_Class_Copy( self, dest, deep, nameExt, ptrMap );
+				
+	return (void*)newLinearRegression;
+}
+
+/* Based on least squares proceedure described in 
+ * Eric W. Weisstein. "Least Squares Fitting." From MathWorld--A Wolfram Web Resource.
+ * http://mathworld.wolfram.com/LeastSquaresFitting.html */
+void LinearRegression_Calculate( void* linearRegression ) {
+	LinearRegression*	self      = (LinearRegression*)linearRegression;
+	Variable*           xVariable = self->xVariable;
+	Variable*           yVariable = self->yVariable;
+	Index               array_I;
+	Index               arraySize;
+	double              xMean     = 0.0;
+	double              yMean     = 0.0;
+	double              xValue;
+	double              yValue;
+	double              SS_xx     = 0.0;
+	double              SS_yy     = 0.0;
+	double              SS_xy     = 0.0;
+	double              slope;
+	double              errorVariance;
+
+	Variable_Update( xVariable );
+	Variable_Update( yVariable );
+
+	arraySize = self->xVariable->arraySize;
+	assert( arraySize == yVariable->arraySize );
+
+	for ( array_I = 0 ; array_I < arraySize ; array_I++ ) {
+		xValue = Variable_GetValueDouble( xVariable, array_I );
+		yValue = Variable_GetValueDouble( yVariable, array_I );
+
+		xMean += xValue;
+		yMean += yValue;
+
+		/* Sum intermediate values - Equations 17, 19, 21 */
+		SS_xx += xValue * xValue;
+		SS_yy += yValue * yValue;
+		SS_xy += xValue * yValue;
+	}
+
+	/* Divide by array size to obtain true mean */
+	xMean /= (double) arraySize;
+	yMean /= (double) arraySize;
+	self->xMean = xMean;
+	self->yMean = yMean;
+
+	/* Calculate intermediate values - Equations 17, 19, 21 */
+	SS_xx -= (double) arraySize * xMean * xMean;
+	SS_yy -= (double) arraySize * yMean * yMean;
+	SS_xy -= (double) arraySize * xMean * yMean;
+
+	/* Finalise calculation coefficients of linear equations y ~= slope * x + interceptor - Equation 27 - 28 */
+	self->slope = slope = SS_xy / SS_xx;
+	self->interceptor   =         yMean - slope * xMean;
+
+	/* Calculate the correlation coefficient r^2 - Equation 29 */
+	self->correlationCoefficient = SS_xy * SS_xy / ( SS_xx * SS_yy );
+
+	/* Calculate Standard errors - Equations 33-35 */
+	errorVariance = sqrt( ( SS_yy - slope * SS_xy ) / (double) (arraySize - 2 ) );
+	self->interceptorStandardError = errorVariance * sqrt( 1.0/(double)arraySize + xMean*xMean/SS_xx );
+	self->slopeStandardError       = errorVariance / sqrt( SS_xx );
+}
+
+
+
+
+	
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/MeshBoundaryShape.c
--- a/Utils/src/MeshBoundaryShape.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,254 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd,
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshBoundaryShape.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "MeshBoundaryShape.h"
-
-
-/* Textual name of this class */
-const Type MeshBoundaryShape_Type = "MeshBoundaryShape";
-
-
-/*
-** Constructors */
-
-MeshBoundaryShape* MeshBoundaryShape_New( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                  _sizeOfSelf = sizeof(MeshBoundaryShape);
-	Type                                                          type = MeshBoundaryShape_Type;
-	Stg_Class_DeleteFunction*                                  _delete = _MeshBoundaryShape_Delete;
-	Stg_Class_PrintFunction*                                    _print = _Stg_Shape_Print;
-	Stg_Class_CopyFunction*                                      _copy = _Stg_Shape_Copy;
-	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = (void*(*)(Name))MeshBoundaryShape_New;
-	Stg_Component_ConstructFunction*                        _construct = _MeshBoundaryShape_AssignFromXML;
-	Stg_Component_BuildFunction*                                _build = _MeshBoundaryShape_Build;
-	Stg_Component_InitialiseFunction*                      _initialise = _MeshBoundaryShape_Initialise;
-	Stg_Component_ExecuteFunction*                            _execute = _Stg_Shape_Execute;
-	Stg_Component_DestroyFunction*                            _destroy = _Stg_Shape_Destroy;
-	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _MeshBoundaryShape_IsCoordInside;
-	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _MeshBoundaryShape_CalculateVolume;
-	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _MeshBoundaryShape_DistanceFromCenterAxis;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-   return _MeshBoundaryShape_New(  MESHBOUNDARYSHAPE_PASSARGS  );
-}
-
-MeshBoundaryShape* _MeshBoundaryShape_New(  MESHBOUNDARYSHAPE_DEFARGS  ) {
-   MeshBoundaryShape* self;
-
-   /* Allocate memory */
-   assert( _sizeOfSelf >= sizeof(MeshBoundaryShape) );
-   self = (MeshBoundaryShape*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
-
-   _MeshBoundaryShape_Init( self );
-
-   return self;
-}
-
-void _MeshBoundaryShape_Init( MeshBoundaryShape* self ) {
-   self->mesh = NULL;
-   self->depth = 0;
-   memset( self->walls, 0, 6 * sizeof(Bool) );
-}
-
-
-/*
-** Virtual functions */
-
-void _MeshBoundaryShape_Delete( void* _self ) {
-   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
-
-   /* Delete parent */
-   _Stg_Shape_Delete( self );
-}
-
-void _MeshBoundaryShape_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
-   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
-   Dictionary_Entry_Value* wallList;
-   int ii;
-
-   _Stg_Shape_AssignFromXML( self, cf, data );
-   _MeshBoundaryShape_Init( self );
-
-   /* Need a mesh with a cartesian generator. */
-   self->mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
-
-   /* Read in the walls to have friction applied. */
-   wallList = _Stg_ComponentFactory_GetDictionaryValue( cf, self->name, "walls", NULL );
-   if( wallList ) {
-      int nWalls, curWall;
-      char* name;
-
-      /* List exists, use it. Extract the number of walls specified. */
-      nWalls = Dictionary_Entry_Value_GetCount( wallList );
-
-      /* Read in each wall's name. */
-      curWall = 0;
-      for( ii = 0; ii < nWalls; ii++ ) {
-
-         /* Rip out the name from the list. */
-         name = Dictionary_Entry_Value_AsString(
-            Dictionary_Entry_Value_GetElement( wallList, ii ) );
-
-         /* Store enabled wall. */
-         if( !strcasecmp( name, "left" ) )
-            self->walls[0] = True;
-         else if( !strcasecmp( name, "right" ) )
-            self->walls[1] = True;
-         else if( !strcasecmp( name, "bottom" ) )
-            self->walls[2] = True;
-         else if( !strcasecmp( name, "top" ) )
-            self->walls[3] = True;
-         else if( !strcasecmp( name, "back" ) )
-            self->walls[4] = True;
-         else if( !strcasecmp( name, "front" ) )
-            self->walls[5] = True;
-         else
-            abort();
-      }
-   }
-
-   /* If no wall list, assume all walls. */
-   else {
-      for( ii = 0; ii < 6; ii++ )
-         self->walls[ii] = True;
-   }
-
-}
-
-
-/*
-** Virtual functions */
-
-void _MeshBoundaryShape_Build( void* _self, void* data ) {
-   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
-
-   _Stg_Shape_Build( self, data );
-   Stg_Component_Build( self->mesh, data, False );
-   Stg_Component_Build( self->gen, data, False );
-   if( !self->mesh->generator || strcmp( self->mesh->generator->type, CartesianGenerator_Type ) )
-      abort();
-   self->gen = (CartesianGenerator*)self->mesh->generator;
-}
-
-void _MeshBoundaryShape_Destroy( void* _self, void* data ) {
-   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
-
-   Stg_Component_Destroy( self->mesh, data, False );
-   Stg_Component_Destroy( self->gen, data, False );
-   _Stg_Shape_Destroy( self, data );
-}
-
-void _MeshBoundaryShape_Initialise( void* _self, void* data ) {
-   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
-
-   _Stg_Shape_Initialise( self, data );
-   Stg_Component_Initialise( self->mesh, data, False );
-   Stg_Component_Initialise( self->gen, data, False );
-}
-
-Bool _MeshBoundaryShape_IsCoordInside( void* _self, Coord coord ) {
-   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
-   Coord newCoord;
-#if 0
-   Grid* grid;
-   int inds[3], element, nDims, wallInd;
-#endif
-   int ii;
-
-   /* Transform coordinate into canonical reference frame */
-   Stg_Shape_TransformCoord( self, coord, newCoord );
-
-   /* Easy, just check if the coord is in the boundary region. */
-   for( ii = 0; ii < Mesh_GetDimSize( self->mesh ); ii++ ) {
-      if( (self->walls[2 * ii] && coord[ii] < self->gen->crdMin[ii] + self->gen->contactGeom[ii]) ||
-          (self->walls[2 * ii + 1] && coord[ii] > self->gen->crdMax[ii] - self->gen->contactGeom[ii]) )
-      {
-         return True;
-      }
-   }
-   return False;
-
-#if 0
-   /* Get the element grid from the mesh. */
-   grid = *(Grid**)Mesh_GetExtension( self->mesh, Grid**, "elementGrid" );
-   assert( grid );
-
-   /* Find which element the current coordinate is in. */
-   if( !Mesh_SearchElements( self->mesh, newCoord, &element ) ) {
-
-      /* Couldn't find the point inside the mesh. */
-      return False;
-   }
-
-   /* Convert the element into n-dimensional indices. */
-   Grid_Lift( grid, element, inds );
-
-   /* Check if we're on any of the specified boundaries. */
-   nDims = Mesh_GetDimSize( self->mesh );
-   for( ii = 0; ii < nDims; ii++ ) {
-      wallInd = 2 * ii;
-      if( (self->walls[wallInd] && inds[ii] < self->depth) ||
-          (self->walls[wallInd + 1] && inds[ii] > (grid->sizes[ii] - self->depth - 1)) )
-      {
-         if( coords[
-         return True;
-      }
-   }
-
-   return False;
-#endif
-}
-
-double _MeshBoundaryShape_CalculateVolume( void* _self ) {
-   abort();
-   return 0.0;
-}
-
-void _MeshBoundaryShape_DistanceFromCenterAxis( void* _self, Coord coord, double* disVec ) {
-   abort();
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/MeshBoundaryShape.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/MeshBoundaryShape.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,254 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd,
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshBoundaryShape.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "MeshBoundaryShape.h"
+
+
+/* Textual name of this class */
+const Type MeshBoundaryShape_Type = "MeshBoundaryShape";
+
+
+/*
+** Constructors */
+
+MeshBoundaryShape* MeshBoundaryShape_New( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                  _sizeOfSelf = sizeof(MeshBoundaryShape);
+	Type                                                          type = MeshBoundaryShape_Type;
+	Stg_Class_DeleteFunction*                                  _delete = _MeshBoundaryShape_Delete;
+	Stg_Class_PrintFunction*                                    _print = _Stg_Shape_Print;
+	Stg_Class_CopyFunction*                                      _copy = _Stg_Shape_Copy;
+	Stg_Component_DefaultConstructorFunction*      _defaultConstructor = (void*(*)(Name))MeshBoundaryShape_New;
+	Stg_Component_ConstructFunction*                        _construct = _MeshBoundaryShape_AssignFromXML;
+	Stg_Component_BuildFunction*                                _build = _MeshBoundaryShape_Build;
+	Stg_Component_InitialiseFunction*                      _initialise = _MeshBoundaryShape_Initialise;
+	Stg_Component_ExecuteFunction*                            _execute = _Stg_Shape_Execute;
+	Stg_Component_DestroyFunction*                            _destroy = _Stg_Shape_Destroy;
+	Stg_Shape_IsCoordInsideFunction*                    _isCoordInside = _MeshBoundaryShape_IsCoordInside;
+	Stg_Shape_CalculateVolumeFunction*                _calculateVolume = _MeshBoundaryShape_CalculateVolume;
+	Stg_Shape_DistanceFromCenterAxisFunction*  _distanceFromCenterAxis = _MeshBoundaryShape_DistanceFromCenterAxis;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+   return _MeshBoundaryShape_New(  MESHBOUNDARYSHAPE_PASSARGS  );
+}
+
+MeshBoundaryShape* _MeshBoundaryShape_New(  MESHBOUNDARYSHAPE_DEFARGS  ) {
+   MeshBoundaryShape* self;
+
+   /* Allocate memory */
+   assert( _sizeOfSelf >= sizeof(MeshBoundaryShape) );
+   self = (MeshBoundaryShape*)_Stg_Shape_New(  STG_SHAPE_PASSARGS  );
+
+   _MeshBoundaryShape_Init( self );
+
+   return self;
+}
+
+void _MeshBoundaryShape_Init( MeshBoundaryShape* self ) {
+   self->mesh = NULL;
+   self->depth = 0;
+   memset( self->walls, 0, 6 * sizeof(Bool) );
+}
+
+
+/*
+** Virtual functions */
+
+void _MeshBoundaryShape_Delete( void* _self ) {
+   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
+
+   /* Delete parent */
+   _Stg_Shape_Delete( self );
+}
+
+void _MeshBoundaryShape_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
+   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
+   Dictionary_Entry_Value* wallList;
+   int ii;
+
+   _Stg_Shape_AssignFromXML( self, cf, data );
+   _MeshBoundaryShape_Init( self );
+
+   /* Need a mesh with a cartesian generator. */
+   self->mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
+
+   /* Read in the walls to have friction applied. */
+   wallList = _Stg_ComponentFactory_GetDictionaryValue( cf, self->name, "walls", NULL );
+   if( wallList ) {
+      int nWalls, curWall;
+      char* name;
+
+      /* List exists, use it. Extract the number of walls specified. */
+      nWalls = Dictionary_Entry_Value_GetCount( wallList );
+
+      /* Read in each wall's name. */
+      curWall = 0;
+      for( ii = 0; ii < nWalls; ii++ ) {
+
+         /* Rip out the name from the list. */
+         name = Dictionary_Entry_Value_AsString(
+            Dictionary_Entry_Value_GetElement( wallList, ii ) );
+
+         /* Store enabled wall. */
+         if( !strcasecmp( name, "left" ) )
+            self->walls[0] = True;
+         else if( !strcasecmp( name, "right" ) )
+            self->walls[1] = True;
+         else if( !strcasecmp( name, "bottom" ) )
+            self->walls[2] = True;
+         else if( !strcasecmp( name, "top" ) )
+            self->walls[3] = True;
+         else if( !strcasecmp( name, "back" ) )
+            self->walls[4] = True;
+         else if( !strcasecmp( name, "front" ) )
+            self->walls[5] = True;
+         else
+            abort();
+      }
+   }
+
+   /* If no wall list, assume all walls. */
+   else {
+      for( ii = 0; ii < 6; ii++ )
+         self->walls[ii] = True;
+   }
+
+}
+
+
+/*
+** Virtual functions */
+
+void _MeshBoundaryShape_Build( void* _self, void* data ) {
+   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
+
+   _Stg_Shape_Build( self, data );
+   Stg_Component_Build( self->mesh, data, False );
+   Stg_Component_Build( self->gen, data, False );
+   if( !self->mesh->generator || strcmp( self->mesh->generator->type, CartesianGenerator_Type ) )
+      abort();
+   self->gen = (CartesianGenerator*)self->mesh->generator;
+}
+
+void _MeshBoundaryShape_Destroy( void* _self, void* data ) {
+   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
+
+   Stg_Component_Destroy( self->mesh, data, False );
+   Stg_Component_Destroy( self->gen, data, False );
+   _Stg_Shape_Destroy( self, data );
+}
+
+void _MeshBoundaryShape_Initialise( void* _self, void* data ) {
+   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
+
+   _Stg_Shape_Initialise( self, data );
+   Stg_Component_Initialise( self->mesh, data, False );
+   Stg_Component_Initialise( self->gen, data, False );
+}
+
+Bool _MeshBoundaryShape_IsCoordInside( void* _self, Coord coord ) {
+   MeshBoundaryShape* self = (MeshBoundaryShape*)_self;
+   Coord newCoord;
+#if 0
+   Grid* grid;
+   int inds[3], element, nDims, wallInd;
+#endif
+   int ii;
+
+   /* Transform coordinate into canonical reference frame */
+   Stg_Shape_TransformCoord( self, coord, newCoord );
+
+   /* Easy, just check if the coord is in the boundary region. */
+   for( ii = 0; ii < Mesh_GetDimSize( self->mesh ); ii++ ) {
+      if( (self->walls[2 * ii] && coord[ii] < self->gen->crdMin[ii] + self->gen->contactGeom[ii]) ||
+          (self->walls[2 * ii + 1] && coord[ii] > self->gen->crdMax[ii] - self->gen->contactGeom[ii]) )
+      {
+         return True;
+      }
+   }
+   return False;
+
+#if 0
+   /* Get the element grid from the mesh. */
+   grid = *(Grid**)Mesh_GetExtension( self->mesh, Grid**, "elementGrid" );
+   assert( grid );
+
+   /* Find which element the current coordinate is in. */
+   if( !Mesh_SearchElements( self->mesh, newCoord, &element ) ) {
+
+      /* Couldn't find the point inside the mesh. */
+      return False;
+   }
+
+   /* Convert the element into n-dimensional indices. */
+   Grid_Lift( grid, element, inds );
+
+   /* Check if we're on any of the specified boundaries. */
+   nDims = Mesh_GetDimSize( self->mesh );
+   for( ii = 0; ii < nDims; ii++ ) {
+      wallInd = 2 * ii;
+      if( (self->walls[wallInd] && inds[ii] < self->depth) ||
+          (self->walls[wallInd + 1] && inds[ii] > (grid->sizes[ii] - self->depth - 1)) )
+      {
+         if( coords[
+         return True;
+      }
+   }
+
+   return False;
+#endif
+}
+
+double _MeshBoundaryShape_CalculateVolume( void* _self ) {
+   abort();
+   return 0.0;
+}
+
+void _MeshBoundaryShape_DistanceFromCenterAxis( void* _self, Coord coord, double* disVec ) {
+   abort();
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/MeshShapeVC.c
--- a/Utils/src/MeshShapeVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,485 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: MeshShapeVC.c 4160 2007-07-30 06:17:06Z DavidLee $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "MeshShapeVC.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type MeshShapeVC_Type = "MeshShapeVC";
-const Name defaultMeshShapeVCName = "defaultMeshShapeVCName";
-
-/*-----------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-VariableCondition* MeshShapeVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									data )
-{
-	return (VariableCondition*) MeshShapeVC_New( defaultMeshShapeVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
-}
-
-MeshShapeVC* MeshShapeVC_New(
-	Name									name,
-	AbstractContext*					context,
-	Name									_dictionaryEntryName, 
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									_mesh )
-{
-	MeshShapeVC* self = (MeshShapeVC*) _MeshShapeVC_DefaultNew( name );
-
-	self->isConstructed = True;
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
-	_MeshShapeVC_Init( self, _dictionaryEntryName, _mesh );
-
-	return self;
-}
-
-void* _MeshShapeVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(MeshShapeVC);
-	Type                                                       type = MeshShapeVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _MeshShapeVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _MeshShapeVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _MeshShapeVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _MeshShapeVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _MeshShapeVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _MeshShapeVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _MeshShapeVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _MeshShapeVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _MeshShapeVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _MeshShapeVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _MeshShapeVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _MeshShapeVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _MeshShapeVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _MeshShapeVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _MeshShapeVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _MeshShapeVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return (void*) _MeshShapeVC_New(  MESHSHAPEVC_PASSARGS  );
-}
-
-MeshShapeVC* _MeshShapeVC_New(  MESHSHAPEVC_DEFARGS  ) {
-	MeshShapeVC* self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(MeshShapeVC) );
-	self = (MeshShapeVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-	/* Virtual info */
-	
-	return self;
-}
-
-void _MeshShapeVC_Init( void* variableCondition, Name _dictionaryEntryName, void* _mesh ) {
-	MeshShapeVC* self = (MeshShapeVC*) variableCondition;
-
-	self->_dictionaryEntryName = _dictionaryEntryName;
-	self->_mesh                = (Mesh*)_mesh;
-	self->_entryTbl            = 0;
-	self->_entryCount          = 0;
-
-	assert( _mesh && Stg_Class_IsInstance( _mesh, Mesh_Type ) );
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-
-void _MeshShapeVC_Delete( void* variableCondition ) {
-	MeshShapeVC* self = (MeshShapeVC*)variableCondition;
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Delete(self);
-}
-
-void _MeshShapeVC_Destroy( void* variableCondition, void* data ) {
-	MeshShapeVC* self = (MeshShapeVC*)variableCondition;
-	
-	if ( self->_entryTbl ) 
-		Memory_Free(self->_entryTbl);
-
-	if ( self->shapeName )
-          Memory_Free( self->shapeName );
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Destroy( self, data );
-}
-
-void _MeshShapeVC_Print(void* variableCondition, Stream* stream) {
-	MeshShapeVC*                self = (MeshShapeVC*)variableCondition;
-	MeshShapeVC_Entry_Index     entry_I;
-	Index                   array_I;
-	
-	/* General info */
-	Journal_Printf( stream, "MeshShapeVC (ptr): %p\n", self);
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	Journal_Printf( stream, "\tdictionary (ptr): %p\n", self->dictionary);
-	Journal_Printf( stream, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-	if (self->_dictionaryEntryName)
-		Journal_Printf( stream, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-	if ( self->_shape )
-		Journal_Printf( stream, "\t_shape: %s '%s'\n", self->_shape->type, self->_shape->name );
-	
-	Journal_Printf( stream, "\t_entryCount: %u\n", self->_entryCount);
-	Journal_Printf( stream, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-	if (self->_entryTbl) {
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++) {
-			Journal_Printf( stream, "\t\t_entryTbl[%u]:\n", entry_I);
-			Journal_Printf( stream, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-			if (self->_entryTbl[entry_I].varName)
-				Journal_Printf( stream, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-			Journal_Printf( stream, "\t\t\tvalue:\n");
-			switch (self->_entryTbl[entry_I].value.type) {
-				case VC_ValueType_Double:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Double\n" );
-					Journal_Printf( stream, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-					break;
-					
-				case VC_ValueType_Int:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Int\n" );
-					Journal_Printf( stream, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-					break;
-					
-				case VC_ValueType_Short:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Short\n" );
-					Journal_Printf( stream, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-					break;
-					
-				case VC_ValueType_Char:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Char\n");
-					Journal_Printf( stream, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-					break;
-					
-				case VC_ValueType_Ptr:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-					Journal_Printf( stream, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-					break;
-					
-				case VC_ValueType_DoubleArray:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-					Journal_Printf( stream, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-					Journal_Printf( stream, "\t\t\t\tasDoubleArray (ptr): %p\n", 
-						self->_entryTbl[entry_I].value.as.typeArray.array);
-					if (self->_entryTbl[entry_I].value.as.typeArray.array)
-						for ( array_I = 0;  array_I < self->_entryTbl[entry_I].value.as.typeArray.size;  array_I++)
-							Journal_Printf( stream, "\t\t\t\tasDoubleArray[%u]: %g\n",  array_I,
-								self->_entryTbl[entry_I].value.as.typeArray.array[ array_I]);
-					break;
-					
-				case VC_ValueType_CFIndex:
-					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-					Journal_Printf( stream, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-					break;
-			}
-		}
-	}
-	Journal_Printf( stream, "\t_mesh (ptr): %p\n", self->_mesh);
-	
-	/* Print parent */
-	_VariableCondition_Print( self );
-}
-
-
-void* _MeshShapeVC_Copy( const void* variableCondition, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-	MeshShapeVC*        self           = (MeshShapeVC*)variableCondition;
-	MeshShapeVC*        newMeshShapeVC;
-	PtrMap*         map            = ptrMap;
-	Bool            ownMap         = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newMeshShapeVC = (MeshShapeVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-	newMeshShapeVC->_dictionaryEntryName = self->_dictionaryEntryName;
-	newMeshShapeVC->_shape = self->_shape;
-	newMeshShapeVC->_entryCount = self->_entryCount;
-	
-	if( deep ) {
-		newMeshShapeVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
-		
-		if( (newMeshShapeVC->_entryTbl = (MeshShapeVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-			newMeshShapeVC->_entryTbl = Memory_Alloc_Array( MeshShapeVC_Entry, newMeshShapeVC->_entryCount, "MeshShapeVC->_entryTbl");
-			memcpy( newMeshShapeVC->_entryTbl, self->_entryTbl, sizeof(MeshShapeVC_Entry) * newMeshShapeVC->_entryCount );
-			PtrMap_Append( map, newMeshShapeVC->_entryTbl, self->_entryTbl );
-		}
-	}
-	else {
-		newMeshShapeVC->_mesh = self->_mesh;
-		newMeshShapeVC->_entryTbl = self->_entryTbl;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newMeshShapeVC;
-}
-	
-void _MeshShapeVC_AssignFromXML( void* variableCondition, Stg_ComponentFactory* cf, void* data ) {
-}
-
-void _MeshShapeVC_Build(  void* variableCondition, void* data ) {
-	MeshShapeVC*			self = (MeshShapeVC*)variableCondition;
-
-	_MeshShapeVC_BuildSelf( self, data );
-	_VariableCondition_Build( self, data );
-}
-	
-/****************** VariableCondition Virtual Functions ******************/
-void _MeshShapeVC_BuildSelf(  void* variableCondition, void* data /* for build phase */ ) {
-	MeshShapeVC*         self    = (MeshShapeVC*)variableCondition;
-	AbstractContext* context = (AbstractContext*) self->context;
-
-	assert( context && Stg_Class_IsInstance( context, AbstractContext_Type ) );
-	assert( self->shapeName );
-	Journal_Firewall( strlen( self->shapeName ) > 0, Journal_MyStream( Error_Type, self ),
-			"You need to fill out the 'Shape' dictionary entry for this MeshShapeVC.\n" );
-	assert( self->_mesh );
-
-	self->_shape =  Stg_ComponentFactory_ConstructByName( context->CF, (Name)self->shapeName, Stg_Shape, True, 0 /* dummy */   ) ;
-	
-	Stg_Component_Build( self->_mesh, data, False );
-	Stg_Component_Build( self->_shape, data, False );
-}
-
-void _MeshShapeVC_PrintConcise( void* variableCondition, Stream* stream ) {
-	MeshShapeVC* self = (MeshShapeVC*) variableCondition;
-	
-	Journal_Printf( stream, "\ttype: %s, Shape: %s '%s'", self->type, self->_shape->type, self->_shape->name );
-}
-
-void _MeshShapeVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-	MeshShapeVC*                  self = (MeshShapeVC*)variableCondition;
-	Dictionary_Entry_Value*   vcDictVal;
-	Dictionary_Entry_Value    _vcDictVal;
-	Dictionary_Entry_Value*   varsVal;
-	MeshShapeVC_Entry_Index	      entry_I;
-	
-	/* Find dictionary entry */
-	if (self->_dictionaryEntryName)
-		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
-	else {
-		vcDictVal = &_vcDictVal;
-		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
-	}
-	
-	if (vcDictVal) {
-		/* Get Name of Shape from dictionary - Grab pointer to shape later on */
-		self->shapeName = StG_Strdup( 
-				Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"Shape" ))  );
-
-		/* Obtain the variable entries */
-		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-		self->_entryTbl = Memory_Alloc_Array( MeshShapeVC_Entry, self->_entryCount, "MeshShapeVC->_entryTbl" );
-		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
-			char*			valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
-				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-			if (0 == strcasecmp(valType, "func")) {
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-				if ( cfIndex == (Index) -1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-						"definition of MeshShapeVC \"%s\" (applies to shape \"%s\"), the cond. func. applied to "
-						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-						__func__, self->_dictionaryEntryName, self->shapeName,
-						self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}
-			else if (0 == strcasecmp(valType, "array"))
-			{
-				Dictionary_Entry_Value*	valueElement;
-				Index			i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
-					self->_entryTbl[entry_I].value.as.typeArray.size, "MeshShapeVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-				{
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
-						Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
-				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
-			{
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_DPrintf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else
-	{
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-	}
-}
-
-IndexSet* _MeshShapeVC_GetSet(void* variableCondition) {
-	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
-	Mesh*		mesh = self->_mesh;
-	IndexSet*	set;
-	unsigned	v_i;
-
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	set = IndexSet_New( Mesh_GetDomainSize( mesh, MT_VERTEX ) );
-
-	for( v_i = 0; v_i < Mesh_GetDomainSize( mesh, MT_VERTEX ); v_i++ ) {
-		if( Stg_Shape_IsCoordInside( self->_shape, Mesh_GetVertex( mesh, v_i ) ) )
-			IndexSet_Add( set, v_i );
-	}
-
-	return set;
-}
-
-VariableCondition_VariableIndex _MeshShapeVC_GetVariableCount(void* variableCondition, Index globalIndex) {
-	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
-
-	return self->_entryCount;
-}
-
-Variable_Index _MeshShapeVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex) {
-	MeshShapeVC*        self          = (MeshShapeVC*)variableCondition;
-	Variable_Index  searchedIndex = 0;
-	Stream*         errorStr      = Journal_Register( Error_Type, (Name)self->type  );
-	Name            varName;
-	
-	varName = self->_entryTbl[varIndex].varName;
-	searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
-	
-	Journal_Firewall( 
-			( searchedIndex < self->variable_Register->count ),
-			errorStr,
-			"Error- in %s: searching for index of varIndex %u (\"%s\") at global node number %u failed"
-			" - register returned index %u, greater than count %u.\n",
-			__func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
-
-	return searchedIndex; 
-}
-
-
-VariableCondition_ValueIndex _MeshShapeVC_GetValueIndex(
-		void*                                       variableCondition, 
-		Index                                       globalIndex, 
-		VariableCondition_VariableIndex             varIndex )
-{
-	return varIndex;
-}
-
-
-VariableCondition_ValueIndex _MeshShapeVC_GetValueCount(void* variableCondition) {
-	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-VariableCondition_Value _MeshShapeVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex) {
-	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
-
-	return self->_entryTbl[valIndex].value;
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/MeshShapeVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/MeshShapeVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,485 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: MeshShapeVC.c 4160 2007-07-30 06:17:06Z DavidLee $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "MeshShapeVC.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type MeshShapeVC_Type = "MeshShapeVC";
+const Name defaultMeshShapeVCName = "defaultMeshShapeVCName";
+
+/*-----------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+VariableCondition* MeshShapeVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									data )
+{
+	return (VariableCondition*) MeshShapeVC_New( defaultMeshShapeVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
+}
+
+MeshShapeVC* MeshShapeVC_New(
+	Name									name,
+	AbstractContext*					context,
+	Name									_dictionaryEntryName, 
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									_mesh )
+{
+	MeshShapeVC* self = (MeshShapeVC*) _MeshShapeVC_DefaultNew( name );
+
+	self->isConstructed = True;
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
+	_MeshShapeVC_Init( self, _dictionaryEntryName, _mesh );
+
+	return self;
+}
+
+void* _MeshShapeVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(MeshShapeVC);
+	Type                                                       type = MeshShapeVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _MeshShapeVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _MeshShapeVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _MeshShapeVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _MeshShapeVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _MeshShapeVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _MeshShapeVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _MeshShapeVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _MeshShapeVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _MeshShapeVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _MeshShapeVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _MeshShapeVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _MeshShapeVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _MeshShapeVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _MeshShapeVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _MeshShapeVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _MeshShapeVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return (void*) _MeshShapeVC_New(  MESHSHAPEVC_PASSARGS  );
+}
+
+MeshShapeVC* _MeshShapeVC_New(  MESHSHAPEVC_DEFARGS  ) {
+	MeshShapeVC* self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(MeshShapeVC) );
+	self = (MeshShapeVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+	/* Virtual info */
+	
+	return self;
+}
+
+void _MeshShapeVC_Init( void* variableCondition, Name _dictionaryEntryName, void* _mesh ) {
+	MeshShapeVC* self = (MeshShapeVC*) variableCondition;
+
+	self->_dictionaryEntryName = _dictionaryEntryName;
+	self->_mesh                = (Mesh*)_mesh;
+	self->_entryTbl            = 0;
+	self->_entryCount          = 0;
+
+	assert( _mesh && Stg_Class_IsInstance( _mesh, Mesh_Type ) );
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+
+void _MeshShapeVC_Delete( void* variableCondition ) {
+	MeshShapeVC* self = (MeshShapeVC*)variableCondition;
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Delete(self);
+}
+
+void _MeshShapeVC_Destroy( void* variableCondition, void* data ) {
+	MeshShapeVC* self = (MeshShapeVC*)variableCondition;
+	
+	if ( self->_entryTbl ) 
+		Memory_Free(self->_entryTbl);
+
+	if ( self->shapeName )
+          Memory_Free( self->shapeName );
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Destroy( self, data );
+}
+
+void _MeshShapeVC_Print(void* variableCondition, Stream* stream) {
+	MeshShapeVC*                self = (MeshShapeVC*)variableCondition;
+	MeshShapeVC_Entry_Index     entry_I;
+	Index                   array_I;
+	
+	/* General info */
+	Journal_Printf( stream, "MeshShapeVC (ptr): %p\n", self);
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	Journal_Printf( stream, "\tdictionary (ptr): %p\n", self->dictionary);
+	Journal_Printf( stream, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+	if (self->_dictionaryEntryName)
+		Journal_Printf( stream, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+	if ( self->_shape )
+		Journal_Printf( stream, "\t_shape: %s '%s'\n", self->_shape->type, self->_shape->name );
+	
+	Journal_Printf( stream, "\t_entryCount: %u\n", self->_entryCount);
+	Journal_Printf( stream, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+	if (self->_entryTbl) {
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++) {
+			Journal_Printf( stream, "\t\t_entryTbl[%u]:\n", entry_I);
+			Journal_Printf( stream, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+			if (self->_entryTbl[entry_I].varName)
+				Journal_Printf( stream, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+			Journal_Printf( stream, "\t\t\tvalue:\n");
+			switch (self->_entryTbl[entry_I].value.type) {
+				case VC_ValueType_Double:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Double\n" );
+					Journal_Printf( stream, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+					break;
+					
+				case VC_ValueType_Int:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Int\n" );
+					Journal_Printf( stream, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+					break;
+					
+				case VC_ValueType_Short:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Short\n" );
+					Journal_Printf( stream, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+					break;
+					
+				case VC_ValueType_Char:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Char\n");
+					Journal_Printf( stream, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+					break;
+					
+				case VC_ValueType_Ptr:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+					Journal_Printf( stream, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+					break;
+					
+				case VC_ValueType_DoubleArray:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+					Journal_Printf( stream, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+					Journal_Printf( stream, "\t\t\t\tasDoubleArray (ptr): %p\n", 
+						self->_entryTbl[entry_I].value.as.typeArray.array);
+					if (self->_entryTbl[entry_I].value.as.typeArray.array)
+						for ( array_I = 0;  array_I < self->_entryTbl[entry_I].value.as.typeArray.size;  array_I++)
+							Journal_Printf( stream, "\t\t\t\tasDoubleArray[%u]: %g\n",  array_I,
+								self->_entryTbl[entry_I].value.as.typeArray.array[ array_I]);
+					break;
+					
+				case VC_ValueType_CFIndex:
+					Journal_Printf( stream, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+					Journal_Printf( stream, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+					break;
+			}
+		}
+	}
+	Journal_Printf( stream, "\t_mesh (ptr): %p\n", self->_mesh);
+	
+	/* Print parent */
+	_VariableCondition_Print( self );
+}
+
+
+void* _MeshShapeVC_Copy( const void* variableCondition, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+	MeshShapeVC*        self           = (MeshShapeVC*)variableCondition;
+	MeshShapeVC*        newMeshShapeVC;
+	PtrMap*         map            = ptrMap;
+	Bool            ownMap         = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newMeshShapeVC = (MeshShapeVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+	newMeshShapeVC->_dictionaryEntryName = self->_dictionaryEntryName;
+	newMeshShapeVC->_shape = self->_shape;
+	newMeshShapeVC->_entryCount = self->_entryCount;
+	
+	if( deep ) {
+		newMeshShapeVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
+		
+		if( (newMeshShapeVC->_entryTbl = (MeshShapeVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+			newMeshShapeVC->_entryTbl = Memory_Alloc_Array( MeshShapeVC_Entry, newMeshShapeVC->_entryCount, "MeshShapeVC->_entryTbl");
+			memcpy( newMeshShapeVC->_entryTbl, self->_entryTbl, sizeof(MeshShapeVC_Entry) * newMeshShapeVC->_entryCount );
+			PtrMap_Append( map, newMeshShapeVC->_entryTbl, self->_entryTbl );
+		}
+	}
+	else {
+		newMeshShapeVC->_mesh = self->_mesh;
+		newMeshShapeVC->_entryTbl = self->_entryTbl;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newMeshShapeVC;
+}
+	
+void _MeshShapeVC_AssignFromXML( void* variableCondition, Stg_ComponentFactory* cf, void* data ) {
+}
+
+void _MeshShapeVC_Build(  void* variableCondition, void* data ) {
+	MeshShapeVC*			self = (MeshShapeVC*)variableCondition;
+
+	_MeshShapeVC_BuildSelf( self, data );
+	_VariableCondition_Build( self, data );
+}
+	
+/****************** VariableCondition Virtual Functions ******************/
+void _MeshShapeVC_BuildSelf(  void* variableCondition, void* data /* for build phase */ ) {
+	MeshShapeVC*         self    = (MeshShapeVC*)variableCondition;
+	AbstractContext* context = (AbstractContext*) self->context;
+
+	assert( context && Stg_Class_IsInstance( context, AbstractContext_Type ) );
+	assert( self->shapeName );
+	Journal_Firewall( strlen( self->shapeName ) > 0, Journal_MyStream( Error_Type, self ),
+			"You need to fill out the 'Shape' dictionary entry for this MeshShapeVC.\n" );
+	assert( self->_mesh );
+
+	self->_shape =  Stg_ComponentFactory_ConstructByName( context->CF, (Name)self->shapeName, Stg_Shape, True, 0 /* dummy */   ) ;
+	
+	Stg_Component_Build( self->_mesh, data, False );
+	Stg_Component_Build( self->_shape, data, False );
+}
+
+void _MeshShapeVC_PrintConcise( void* variableCondition, Stream* stream ) {
+	MeshShapeVC* self = (MeshShapeVC*) variableCondition;
+	
+	Journal_Printf( stream, "\ttype: %s, Shape: %s '%s'", self->type, self->_shape->type, self->_shape->name );
+}
+
+void _MeshShapeVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+	MeshShapeVC*                  self = (MeshShapeVC*)variableCondition;
+	Dictionary_Entry_Value*   vcDictVal;
+	Dictionary_Entry_Value    _vcDictVal;
+	Dictionary_Entry_Value*   varsVal;
+	MeshShapeVC_Entry_Index	      entry_I;
+	
+	/* Find dictionary entry */
+	if (self->_dictionaryEntryName)
+		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
+	else {
+		vcDictVal = &_vcDictVal;
+		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
+	}
+	
+	if (vcDictVal) {
+		/* Get Name of Shape from dictionary - Grab pointer to shape later on */
+		self->shapeName = StG_Strdup( 
+				Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"Shape" ))  );
+
+		/* Obtain the variable entries */
+		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+		self->_entryTbl = Memory_Alloc_Array( MeshShapeVC_Entry, self->_entryCount, "MeshShapeVC->_entryTbl" );
+		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
+			char*			valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
+				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+			if (0 == strcasecmp(valType, "func")) {
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+				if ( cfIndex == (Index) -1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+						"definition of MeshShapeVC \"%s\" (applies to shape \"%s\"), the cond. func. applied to "
+						"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+						__func__, self->_dictionaryEntryName, self->shapeName,
+						self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}
+			else if (0 == strcasecmp(valType, "array"))
+			{
+				Dictionary_Entry_Value*	valueElement;
+				Index			i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
+					self->_entryTbl[entry_I].value.as.typeArray.size, "MeshShapeVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+				{
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
+						Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
+				0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
+			{
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_DPrintf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else
+	{
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+	}
+}
+
+IndexSet* _MeshShapeVC_GetSet(void* variableCondition) {
+	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
+	Mesh*		mesh = self->_mesh;
+	IndexSet*	set;
+	unsigned	v_i;
+
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	set = IndexSet_New( Mesh_GetDomainSize( mesh, MT_VERTEX ) );
+
+	for( v_i = 0; v_i < Mesh_GetDomainSize( mesh, MT_VERTEX ); v_i++ ) {
+		if( Stg_Shape_IsCoordInside( self->_shape, Mesh_GetVertex( mesh, v_i ) ) )
+			IndexSet_Add( set, v_i );
+	}
+
+	return set;
+}
+
+VariableCondition_VariableIndex _MeshShapeVC_GetVariableCount(void* variableCondition, Index globalIndex) {
+	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
+
+	return self->_entryCount;
+}
+
+Variable_Index _MeshShapeVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex) {
+	MeshShapeVC*        self          = (MeshShapeVC*)variableCondition;
+	Variable_Index  searchedIndex = 0;
+	Stream*         errorStr      = Journal_Register( Error_Type, (Name)self->type  );
+	Name            varName;
+	
+	varName = self->_entryTbl[varIndex].varName;
+	searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
+	
+	Journal_Firewall( 
+			( searchedIndex < self->variable_Register->count ),
+			errorStr,
+			"Error- in %s: searching for index of varIndex %u (\"%s\") at global node number %u failed"
+			" - register returned index %u, greater than count %u.\n",
+			__func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
+
+	return searchedIndex; 
+}
+
+
+VariableCondition_ValueIndex _MeshShapeVC_GetValueIndex(
+		void*                                       variableCondition, 
+		Index                                       globalIndex, 
+		VariableCondition_VariableIndex             varIndex )
+{
+	return varIndex;
+}
+
+
+VariableCondition_ValueIndex _MeshShapeVC_GetValueCount(void* variableCondition) {
+	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+VariableCondition_Value _MeshShapeVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex) {
+	MeshShapeVC*	self = (MeshShapeVC*)variableCondition;
+
+	return self->_entryTbl[valIndex].value;
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/NewRemesher.c
--- a/Utils/src/NewRemesher.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: NewRemesher.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdlib.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "NewRemesher.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-void _NewRemesher_Init( void* _self ) {
-   NewRemesher* self = Class_Cast( _self, NewRemesher );
-
-   _NewClass_Init( self );
-   self->mesh = NULL;
-}
-
-void _NewRemesher_Copy( void* _self, const void* _op ) {
-   NewRemesher* self = Class_Cast( _self, NewRemesher );
-   const NewRemesher* op = Class_Cast( _op, NewRemesher );
-
-   _NewClass_Copy( self, op );
-   self->mesh = op->mesh;
-}
-
-void _NewRemesher_Print( const void* _self, Stream* stream ) {
-   NewRemesher* self = Class_Cast( _self, NewRemesher );
-
-   _NewClass_Print( self, stream );
-}
-
-void NewRemesher_SetMesh( void* _self, void* mesh ) {
-   NewRemesher* self = Class_Cast( _self, NewRemesher );
-
-   /*assert( Class_IsSuper( mesh, Mesh ) );*/
-
-   self->mesh = (Mesh*)mesh;
-}
-
-Mesh* NewRemesher_GetMesh( const void* self ) {
-   assert( Class_IsSuper( self, NewRemesher ) );
-   return ((NewRemesher*)self)->mesh;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/NewRemesher.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/NewRemesher.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,78 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: NewRemesher.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdlib.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "NewRemesher.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+void _NewRemesher_Init( void* _self ) {
+   NewRemesher* self = Class_Cast( _self, NewRemesher );
+
+   _NewClass_Init( self );
+   self->mesh = NULL;
+}
+
+void _NewRemesher_Copy( void* _self, const void* _op ) {
+   NewRemesher* self = Class_Cast( _self, NewRemesher );
+   const NewRemesher* op = Class_Cast( _op, NewRemesher );
+
+   _NewClass_Copy( self, op );
+   self->mesh = op->mesh;
+}
+
+void _NewRemesher_Print( const void* _self, Stream* stream ) {
+   NewRemesher* self = Class_Cast( _self, NewRemesher );
+
+   _NewClass_Print( self, stream );
+}
+
+void NewRemesher_SetMesh( void* _self, void* mesh ) {
+   NewRemesher* self = Class_Cast( _self, NewRemesher );
+
+   /*assert( Class_IsSuper( mesh, Mesh ) );*/
+
+   self->mesh = (Mesh*)mesh;
+}
+
+Mesh* NewRemesher_GetMesh( const void* self ) {
+   assert( Class_IsSuper( self, NewRemesher ) );
+   return ((NewRemesher*)self)->mesh;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/Operator.c
--- a/Utils/src/Operator.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,624 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Operator.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <string.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "Operator.h"
-
-const Type Operator_Type = "Operator";
-
-Operator* Operator_New(		
-		Name                                       name, 		
-		Func_Ptr                                   _carryOut,
-		Index                                      numberOfOperands,
-		Dof_Index                                  operandDofs,
-		Dof_Index                                  resultDofs,
-		Dimension_Index                            dim ) 
-{
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof( Operator );
-	Type                              type = Operator_Type;
-	Stg_Class_DeleteFunction*      _delete = _Operator_Delete;
-	Stg_Class_PrintFunction*        _print = _Operator_Print;
-	Stg_Class_CopyFunction*          _copy = _Operator_Copy;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return _Operator_New(  OPERATOR_PASSARGS  );
-}
-
-Operator* _Operator_New(  OPERATOR_DEFARGS  )
-{
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	Operator* self = (Operator*) _Stg_Object_New(  STG_OBJECT_PASSARGS  );
-
-	/* Set values */
-	self->_carryOut        = _carryOut;
-	self->numberOfOperands = numberOfOperands;
-	self->operandDofs      = operandDofs;
-	self->resultDofs       = resultDofs;
-	self->dim              = dim;
-
-	/* Create Stream */
-	self->errorStream = Journal_MyStream( Error_Type, self );
-
-	return self;
-}
-
-
-void _Operator_Delete(void* op) {
-	Operator* self = (Operator*) op;
-	
-	/* Stg_Class_Delete parent class */
-	_Stg_Class_Delete( self );
-}
-
-void _Operator_Print(void* op, Stream* stream) {
-  /*Operator* self = (Operator*) operator; */
-
-	abort();
-}
-
-void* _Operator_Copy( const void* op, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-  /*Operator* self = (Operator*) operator; */
-	abort();
-}
-
-
-/* Carry Out Operators */
-void Operator_CarryOutUnaryOperation( void* op, double* operand0, double* result ) {
-	Operator* self            = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-			
-	(*(Operator_CarryOutUnaryOperationFunction*) (self->_carryOut))( self, operand0, result );
-}
-
-void Operator_CarryOutBinaryOperation( void* op, double* operand0, double* operand1, double* result ) {
-	Operator* self            = (Operator*) op;
-
-	Operator_FirewallBinary( self );
-
-	(*(Operator_CarryOutBinaryOperationFunction*) (self->_carryOut))( self, operand0, operand1, result );
-}
-
-/** Operator Functions */
-#define SQUARE_VECTOR2D( vector ) \
-	( vector[0] * vector[0] + vector[1] * vector[1] )
-#define SQUARE_VECTOR3D( vector ) \
-	( vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2] )
-
-void Operator_VectorSquare( void* op, double* operand0, double* result ) {
-	Operator* self            = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-
-	switch ( self->operandDofs ) {
-		case 2:
-			*result = SQUARE_VECTOR2D( operand0 ); break;
-		case 3:
-			*result = SQUARE_VECTOR3D( operand0 ); break;
-		default:
-			Journal_Printf( self->errorStream, 
-					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
-					__func__, self->type, self->name );
-			abort();
-	}
-}
-
-void Operator_Magnitude( void* op, double* operand0, double* result ) {
-	Operator* self            = (Operator*) op;
-	Index     val_I;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-
-	switch ( self->operandDofs ) {
-		
-		case 2:
-			*result = sqrt( SQUARE_VECTOR2D( operand0 ) ); break;
-		case 3:
-			*result = sqrt( SQUARE_VECTOR3D( operand0 ) ); break;
-		case 1:
-			*result = fabs( *operand0 ); break;
-		case 6:
-			*result = 0;
-			for( val_I = 0; val_I < self->operandDofs ; val_I++ ) 
-				*result += operand0[val_I]*operand0[val_I];
-
-			*result = sqrt( *result ); break;
-		default:
-			Journal_Printf( self->errorStream, 
-					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
-					__func__, self->type, self->name );
-			abort();			
-	}
-}
-
-void Operator_TensorSymmetricPart( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	
-	TensorArray_GetSymmetricPart( operand0, self->dim, result );
-}
-
-void Operator_SymmetricTensor_Invariant( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	
-	*result = SymmetricTensor_2ndInvariant( operand0, self->dim );
-}
-
-void Operator_TensorAntisymmetricPart( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-		
-	TensorArray_GetAntisymmetricPart( operand0, self->dim, result );
-}
-
-void Operator_SymmetricTensor_GetNegAverageTrace( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	
-	SymmetricTensor_GetTrace( operand0, self->dim, result ); 
-
-	*result = -1.0 * (*result) / self->dim ;
-}
-
-void Operator_SymmetricTensor_MakeDeviatoric( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-	double meanStress;
-	
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, self->operandDofs );
-	
-	SymmetricTensor_GetTrace( operand0, self->dim, &meanStress );
-	meanStress = meanStress / self->dim ;
-
-	if( self->dim == 2 ) {
-		result[0] = operand0[0] - meanStress;
-		result[1] = operand0[1] - meanStress;
-		result[2] = operand0[2];
-	} else {
-		result[0] = operand0[0] - meanStress;
-		result[1] = operand0[1] - meanStress;
-		result[2] = operand0[2] - meanStress;
-		result[3] = operand0[3];
-		result[4] = operand0[4];
-		result[5] = operand0[5];
-	}
-}
-
-void Operator_Tensor_GetNegAverageTrace( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	
-	TensorArray_GetTrace( operand0, self->dim, result ); 
-
-	*result = -1.0 * (*result) / self->dim ;
-}
-
-
-void Operator_Scalar_Negative( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	
-	*result = -1.0 * (*operand0);
-}
-	
-
-void Operator_TakeFirstComponent( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallMinimumOperandDofs( self, 1 );
-
-	*result = operand0[0];
-}
-void Operator_TakeSecondComponent( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallMinimumOperandDofs( self, 2 );
-
-	*result = operand0[1];
-}
-void Operator_TakeThirdComponent( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallMinimumOperandDofs( self, 3 );
-
-	*result = operand0[2];
-}
-void Operator_TakeFourthComponent( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallMinimumOperandDofs( self, 4 );
-
-	*result = operand0[3];
-}
-void Operator_TakeFifthComponent( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallMinimumOperandDofs( self, 5 );
-
-	*result = operand0[4];
-}
-
-/** Binary Operator Functions */
-void Operator_Addition( void* op, double* operand0, double* operand1, double* result){
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallBinary( self );
-	Operator_FirewallEqualOperandAndResultDofs( self );
-	
-	switch (self->operandDofs) {
-		case 6:
-			result[5] = operand0[5] + operand1[5];
-		case 5:
-			result[4] = operand0[4] + operand1[4];
-		case 4:
-			result[3] = operand0[3] + operand1[3];
-		case 3:
-			result[2] = operand0[2] + operand1[2];
-		case 2:
-			result[1] = operand0[1] + operand1[1];
-		case 1:
-			result[0] = operand0[0] + operand1[0]; break;
-		default:
-			Journal_Printf( self->errorStream, 
-					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
-					__func__, self->type, self->name );
-			abort();				
-	}
-}
-
-void Operator_Subtraction( void* op, double* operand0, double* operand1, double* result){
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallBinary( self );
-	Operator_FirewallEqualOperandAndResultDofs( self );
-	
-	switch (self->operandDofs) {
-		case 6:
-			result[5] = operand0[5] - operand1[5];
-		case 5:
-			result[4] = operand0[4] - operand1[4];
-		case 4:
-			result[3] = operand0[3] - operand1[3];
-		case 3:
-			result[2] = operand0[2] - operand1[2];
-		case 2:
-			result[1] = operand0[1] - operand1[1];
-		case 1:
-			result[0] = operand0[0] - operand1[0]; break;
-		default:
-			Journal_Printf( self->errorStream, 
-					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
-					__func__, self->type, self->name );
-			abort();				
-	}
-}
-
-void Operator_ScalarMultiplication( void* op, double* operand0, double* operand1, double* result ) {
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallBinary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallEqualOperandAndResultDofs( self );
-
-	*result = (*operand0) * (*operand1);
-}
-
-
-void Operator_ScalarDivision( void* op, double* operand0, double* operand1, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallBinary( self );
-	Operator_FirewallResultDofs( self, 1 );
-	Operator_FirewallEqualOperandAndResultDofs( self );
-
-	*result = (*operand0) / (*operand1);
-}
-
-void Operator_VectorScale( void* op, double* operand0, double* operand1, double* result){
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallBinary( self );
-
-	switch (self->operandDofs) {
-		case 3:
-			result[2] = (*operand0) * operand1[2];
-		case 2:
-			result[1] = (*operand0) * operand1[1];
-		case 1:
-			result[0] = (*operand0) * operand1[0]; break;
-		default:
-			Journal_Printf( self->errorStream, 
-					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
-					__func__, self->type, self->name );
-			abort();				
-	}
-}
-
-void Operator_Rounding( void* op, double* operand0, double* result ) {
-	Operator*     self = (Operator*) op;
-	/* TODO: read this in from somewhere instead of just hard-coding it.... */
-	unsigned int  nSigFigsToRoundTo = 6;
-	Index         val_I;
-
-	Operator_FirewallUnary( self );
-
-	for( val_I = 0; val_I < self->operandDofs ; val_I++ ) {	
-		result[val_I] = StG_RoundDoubleToNSigFigs( operand0[val_I], nSigFigsToRoundTo );
-	}
-}
-
-
-void Operator_HorizontalDivergence( void* op, double* velocityGradient, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );
-
-	*result = velocityGradient[0] + velocityGradient[8];
-}
-
-void Operator_VerticalVorticity( void* op, double* velocityGradient, double* result ) {
-	Operator* self = (Operator*) op;
-
-	Operator_FirewallUnary( self );
-	Operator_FirewallResultDofs( self, 1 );	
-
-	*result = velocityGradient[2] - velocityGradient[6];
-}
-
-void Operator_Divergence( void* op, double* velocityGradient, double* result ) {
-	Operator* self = (Operator*) op;
-	
-	Operator_FirewallUnary( self );
-
-	TensorArray_GetTrace( velocityGradient, self->dim, result );
-}
-
-void Operator_SymmetricTensorInnerProduct( void* op, double* operand0, double* operand1, double* result ) {
-	Operator* self = (Operator*)op;
-	
-	Operator_FirewallBinary( self );
-
-	/* Must be symmetric Tensors */
-	if( self->dim == 2 ) {
-		*result = operand0[0] * operand1[0] + operand0[1] * operand1[1] + ( 2 * operand0[2] * operand1[2] );
-	} else {
-		*result = operand0[0] * operand1[0]
-		       	+ operand0[1] * operand1[1] 
-			+ operand0[2] * operand1[2] 
-			+ 2.0 * (operand0[3] * operand1[3] + operand0[4] * operand1[4] + operand0[5] * operand1[5] );
-	}
-}
-
-void Operator_TensorInvariant( void* op, double* operand0, double* result ) {
-	Operator* self = (Operator*)op;
-
-	Operator_FirewallUnary( self );
-
-	/* Must be a full Tensor */
-	*result = TensorArray_2ndInvariant( operand0, self->dim );
-}
-
-void Operator_ScalarByVectorMultiplication( void* op, double* operand0, double* operand1, double* result ) {
-	Operator*     self = (Operator*) op;
-	Index         val_I;
-
-	Operator_FirewallUnary( self );
-
-	for( val_I = 0; val_I < self->operandDofs ; val_I++ ) {	
-		result[val_I] = *operand0 * operand1[val_I];
-	}
-}
-
-/* HACK - This function isn't extensible */
-Operator* Operator_NewFromName( 
-		Name                                       name, 		
-		Dof_Index                                  operandDofs,
-		Dimension_Index                            dim ) 
-{
-	Func_Ptr                                   _carryOut;
-	Dof_Index                                  resultDofs;
-	Index                                      numberOfOperands;
-
-	if ( ! strcasecmp( name, "VectorSquare" ) ) {
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_VectorSquare;
-	}
-	else if ( ! strcasecmp( name, "Magnitude" ) ) {
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_Magnitude;
-	}
-	else if ( ! strcasecmp( name, "TensorSymmetricPart" ) ) {
-		resultDofs = StGermain_nSymmetricTensorVectorComponents( dim );
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_TensorSymmetricPart;
-	}
-	else if ( ! strcasecmp( name, "TensorAntisymmetricPart" ) ) { 
-		resultDofs = dim * dim;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_TensorAntisymmetricPart;
-	}
-	else if ( ! strcasecmp( name, "SymmetricTensor_Invariant" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_SymmetricTensor_Invariant;
-	}
-	else if ( ! strcasecmp( name, "SymmetricTensor_NegAverageTrace" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_SymmetricTensor_GetNegAverageTrace;
-	}
-	else if ( ! strcasecmp( name, "Scalar_Negative" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_Scalar_Negative;
-	}
-	else if ( ! strcasecmp( name, "Tensor_NegAverageTrace" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_Tensor_GetNegAverageTrace;
-	}
-	else if ( ! strcasecmp( name, "SymmetricTensor_MakeDeviatoric" ) ){ 
-		resultDofs = operandDofs;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_SymmetricTensor_MakeDeviatoric;
-	}
-	else if ( ! strcasecmp( name, "TakeFirstComponent" ) ) {
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_TakeFirstComponent;
-	}
-	else if ( ! strcasecmp( name, "TakeSecondComponent" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_TakeSecondComponent;
-	}
-	else if ( ! strcasecmp( name, "TakeThirdComponent" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_TakeThirdComponent;
-	}
-	else if ( ! strcasecmp( name, "Addition" ) ) {
-		resultDofs = operandDofs;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_Addition;
-	}
-	else if ( ! strcasecmp( name, "Subtraction" ) ){ 
-		resultDofs = operandDofs;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_Subtraction;
-	}
-	else if ( ! strcasecmp( name, "ScalarMultiplication" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_ScalarMultiplication;
-	}
-	else if ( ! strcasecmp( name, "ScalarDivision" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_ScalarDivision;
-	}
-	else if ( ! strcasecmp( name, "VectorScale" ) ){ 
-		resultDofs = dim;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_VectorScale;
-	} 
-	else if ( ! strcasecmp( name, "Rounding" ) ){ 
-		resultDofs = operandDofs;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_Rounding;
-	} 
-	else if ( ! strcasecmp( name, "TensorInnerProduct" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_SymmetricTensorInnerProduct;
-	}
-	else if ( ! strcasecmp( name, "TensorInvariant" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_TensorInvariant;
-	}
-	else if ( ! strcasecmp( name, "HorizontalDivergence" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_HorizontalDivergence;
-	}
-	else if ( ! strcasecmp( name, "VerticalVorticity" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_VerticalVorticity;
-	}
-	else if ( ! strcasecmp( name, "Divergence" ) ){ 
-		resultDofs = 1;
-		numberOfOperands = 1;
-		_carryOut = (Func_Ptr)Operator_Divergence;
-	}
-	else if ( ! strcasecmp( name, "ScalarByVectorMultiplication" ) ){
-		resultDofs = dim;
-		numberOfOperands = 2;
-		_carryOut = (Func_Ptr)Operator_ScalarByVectorMultiplication;
-	}
-	else {
-		resultDofs = 0;
-		numberOfOperands = 0;
-		_carryOut = NULL;
-		
-		Journal_Printf( Journal_Register( Error_Type, (Name)Operator_Type  ), 
-				"In func %s: Error trying to create operator from name '%s'.\n",
-				__func__, name );
-		abort();
-	}
-
-	return Operator_New( name, _carryOut, numberOfOperands, operandDofs, resultDofs, dim );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/Operator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Operator.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,624 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Operator.c 4081 2007-04-27 06:20:07Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <string.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "Operator.h"
+
+const Type Operator_Type = "Operator";
+
+Operator* Operator_New(		
+		Name                                       name, 		
+		Func_Ptr                                   _carryOut,
+		Index                                      numberOfOperands,
+		Dof_Index                                  operandDofs,
+		Dof_Index                                  resultDofs,
+		Dimension_Index                            dim ) 
+{
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof( Operator );
+	Type                              type = Operator_Type;
+	Stg_Class_DeleteFunction*      _delete = _Operator_Delete;
+	Stg_Class_PrintFunction*        _print = _Operator_Print;
+	Stg_Class_CopyFunction*          _copy = _Operator_Copy;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return _Operator_New(  OPERATOR_PASSARGS  );
+}
+
+Operator* _Operator_New(  OPERATOR_DEFARGS  )
+{
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	Operator* self = (Operator*) _Stg_Object_New(  STG_OBJECT_PASSARGS  );
+
+	/* Set values */
+	self->_carryOut        = _carryOut;
+	self->numberOfOperands = numberOfOperands;
+	self->operandDofs      = operandDofs;
+	self->resultDofs       = resultDofs;
+	self->dim              = dim;
+
+	/* Create Stream */
+	self->errorStream = Journal_MyStream( Error_Type, self );
+
+	return self;
+}
+
+
+void _Operator_Delete(void* op) {
+	Operator* self = (Operator*) op;
+	
+	/* Stg_Class_Delete parent class */
+	_Stg_Class_Delete( self );
+}
+
+void _Operator_Print(void* op, Stream* stream) {
+  /*Operator* self = (Operator*) operator; */
+
+	abort();
+}
+
+void* _Operator_Copy( const void* op, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+  /*Operator* self = (Operator*) operator; */
+	abort();
+}
+
+
+/* Carry Out Operators */
+void Operator_CarryOutUnaryOperation( void* op, double* operand0, double* result ) {
+	Operator* self            = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+			
+	(*(Operator_CarryOutUnaryOperationFunction*) (self->_carryOut))( self, operand0, result );
+}
+
+void Operator_CarryOutBinaryOperation( void* op, double* operand0, double* operand1, double* result ) {
+	Operator* self            = (Operator*) op;
+
+	Operator_FirewallBinary( self );
+
+	(*(Operator_CarryOutBinaryOperationFunction*) (self->_carryOut))( self, operand0, operand1, result );
+}
+
+/** Operator Functions */
+#define SQUARE_VECTOR2D( vector ) \
+	( vector[0] * vector[0] + vector[1] * vector[1] )
+#define SQUARE_VECTOR3D( vector ) \
+	( vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2] )
+
+void Operator_VectorSquare( void* op, double* operand0, double* result ) {
+	Operator* self            = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+
+	switch ( self->operandDofs ) {
+		case 2:
+			*result = SQUARE_VECTOR2D( operand0 ); break;
+		case 3:
+			*result = SQUARE_VECTOR3D( operand0 ); break;
+		default:
+			Journal_Printf( self->errorStream, 
+					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
+					__func__, self->type, self->name );
+			abort();
+	}
+}
+
+void Operator_Magnitude( void* op, double* operand0, double* result ) {
+	Operator* self            = (Operator*) op;
+	Index     val_I;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+
+	switch ( self->operandDofs ) {
+		
+		case 2:
+			*result = sqrt( SQUARE_VECTOR2D( operand0 ) ); break;
+		case 3:
+			*result = sqrt( SQUARE_VECTOR3D( operand0 ) ); break;
+		case 1:
+			*result = fabs( *operand0 ); break;
+		case 6:
+			*result = 0;
+			for( val_I = 0; val_I < self->operandDofs ; val_I++ ) 
+				*result += operand0[val_I]*operand0[val_I];
+
+			*result = sqrt( *result ); break;
+		default:
+			Journal_Printf( self->errorStream, 
+					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
+					__func__, self->type, self->name );
+			abort();			
+	}
+}
+
+void Operator_TensorSymmetricPart( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	
+	TensorArray_GetSymmetricPart( operand0, self->dim, result );
+}
+
+void Operator_SymmetricTensor_Invariant( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	
+	*result = SymmetricTensor_2ndInvariant( operand0, self->dim );
+}
+
+void Operator_TensorAntisymmetricPart( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+		
+	TensorArray_GetAntisymmetricPart( operand0, self->dim, result );
+}
+
+void Operator_SymmetricTensor_GetNegAverageTrace( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	
+	SymmetricTensor_GetTrace( operand0, self->dim, result ); 
+
+	*result = -1.0 * (*result) / self->dim ;
+}
+
+void Operator_SymmetricTensor_MakeDeviatoric( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+	double meanStress;
+	
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, self->operandDofs );
+	
+	SymmetricTensor_GetTrace( operand0, self->dim, &meanStress );
+	meanStress = meanStress / self->dim ;
+
+	if( self->dim == 2 ) {
+		result[0] = operand0[0] - meanStress;
+		result[1] = operand0[1] - meanStress;
+		result[2] = operand0[2];
+	} else {
+		result[0] = operand0[0] - meanStress;
+		result[1] = operand0[1] - meanStress;
+		result[2] = operand0[2] - meanStress;
+		result[3] = operand0[3];
+		result[4] = operand0[4];
+		result[5] = operand0[5];
+	}
+}
+
+void Operator_Tensor_GetNegAverageTrace( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	
+	TensorArray_GetTrace( operand0, self->dim, result ); 
+
+	*result = -1.0 * (*result) / self->dim ;
+}
+
+
+void Operator_Scalar_Negative( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	
+	*result = -1.0 * (*operand0);
+}
+	
+
+void Operator_TakeFirstComponent( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallMinimumOperandDofs( self, 1 );
+
+	*result = operand0[0];
+}
+void Operator_TakeSecondComponent( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallMinimumOperandDofs( self, 2 );
+
+	*result = operand0[1];
+}
+void Operator_TakeThirdComponent( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallMinimumOperandDofs( self, 3 );
+
+	*result = operand0[2];
+}
+void Operator_TakeFourthComponent( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallMinimumOperandDofs( self, 4 );
+
+	*result = operand0[3];
+}
+void Operator_TakeFifthComponent( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallMinimumOperandDofs( self, 5 );
+
+	*result = operand0[4];
+}
+
+/** Binary Operator Functions */
+void Operator_Addition( void* op, double* operand0, double* operand1, double* result){
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallBinary( self );
+	Operator_FirewallEqualOperandAndResultDofs( self );
+	
+	switch (self->operandDofs) {
+		case 6:
+			result[5] = operand0[5] + operand1[5];
+		case 5:
+			result[4] = operand0[4] + operand1[4];
+		case 4:
+			result[3] = operand0[3] + operand1[3];
+		case 3:
+			result[2] = operand0[2] + operand1[2];
+		case 2:
+			result[1] = operand0[1] + operand1[1];
+		case 1:
+			result[0] = operand0[0] + operand1[0]; break;
+		default:
+			Journal_Printf( self->errorStream, 
+					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
+					__func__, self->type, self->name );
+			abort();				
+	}
+}
+
+void Operator_Subtraction( void* op, double* operand0, double* operand1, double* result){
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallBinary( self );
+	Operator_FirewallEqualOperandAndResultDofs( self );
+	
+	switch (self->operandDofs) {
+		case 6:
+			result[5] = operand0[5] - operand1[5];
+		case 5:
+			result[4] = operand0[4] - operand1[4];
+		case 4:
+			result[3] = operand0[3] - operand1[3];
+		case 3:
+			result[2] = operand0[2] - operand1[2];
+		case 2:
+			result[1] = operand0[1] - operand1[1];
+		case 1:
+			result[0] = operand0[0] - operand1[0]; break;
+		default:
+			Journal_Printf( self->errorStream, 
+					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
+					__func__, self->type, self->name );
+			abort();				
+	}
+}
+
+void Operator_ScalarMultiplication( void* op, double* operand0, double* operand1, double* result ) {
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallBinary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallEqualOperandAndResultDofs( self );
+
+	*result = (*operand0) * (*operand1);
+}
+
+
+void Operator_ScalarDivision( void* op, double* operand0, double* operand1, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallBinary( self );
+	Operator_FirewallResultDofs( self, 1 );
+	Operator_FirewallEqualOperandAndResultDofs( self );
+
+	*result = (*operand0) / (*operand1);
+}
+
+void Operator_VectorScale( void* op, double* operand0, double* operand1, double* result){
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallBinary( self );
+
+	switch (self->operandDofs) {
+		case 3:
+			result[2] = (*operand0) * operand1[2];
+		case 2:
+			result[1] = (*operand0) * operand1[1];
+		case 1:
+			result[0] = (*operand0) * operand1[0]; break;
+		default:
+			Journal_Printf( self->errorStream, 
+					"Error in %s for %s '%s': Incorrect number of degrees of freedom for what you are operating on.\n",
+					__func__, self->type, self->name );
+			abort();				
+	}
+}
+
+void Operator_Rounding( void* op, double* operand0, double* result ) {
+	Operator*     self = (Operator*) op;
+	/* TODO: read this in from somewhere instead of just hard-coding it.... */
+	unsigned int  nSigFigsToRoundTo = 6;
+	Index         val_I;
+
+	Operator_FirewallUnary( self );
+
+	for( val_I = 0; val_I < self->operandDofs ; val_I++ ) {	
+		result[val_I] = StG_RoundDoubleToNSigFigs( operand0[val_I], nSigFigsToRoundTo );
+	}
+}
+
+
+void Operator_HorizontalDivergence( void* op, double* velocityGradient, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );
+
+	*result = velocityGradient[0] + velocityGradient[8];
+}
+
+void Operator_VerticalVorticity( void* op, double* velocityGradient, double* result ) {
+	Operator* self = (Operator*) op;
+
+	Operator_FirewallUnary( self );
+	Operator_FirewallResultDofs( self, 1 );	
+
+	*result = velocityGradient[2] - velocityGradient[6];
+}
+
+void Operator_Divergence( void* op, double* velocityGradient, double* result ) {
+	Operator* self = (Operator*) op;
+	
+	Operator_FirewallUnary( self );
+
+	TensorArray_GetTrace( velocityGradient, self->dim, result );
+}
+
+void Operator_SymmetricTensorInnerProduct( void* op, double* operand0, double* operand1, double* result ) {
+	Operator* self = (Operator*)op;
+	
+	Operator_FirewallBinary( self );
+
+	/* Must be symmetric Tensors */
+	if( self->dim == 2 ) {
+		*result = operand0[0] * operand1[0] + operand0[1] * operand1[1] + ( 2 * operand0[2] * operand1[2] );
+	} else {
+		*result = operand0[0] * operand1[0]
+		       	+ operand0[1] * operand1[1] 
+			+ operand0[2] * operand1[2] 
+			+ 2.0 * (operand0[3] * operand1[3] + operand0[4] * operand1[4] + operand0[5] * operand1[5] );
+	}
+}
+
+void Operator_TensorInvariant( void* op, double* operand0, double* result ) {
+	Operator* self = (Operator*)op;
+
+	Operator_FirewallUnary( self );
+
+	/* Must be a full Tensor */
+	*result = TensorArray_2ndInvariant( operand0, self->dim );
+}
+
+void Operator_ScalarByVectorMultiplication( void* op, double* operand0, double* operand1, double* result ) {
+	Operator*     self = (Operator*) op;
+	Index         val_I;
+
+	Operator_FirewallUnary( self );
+
+	for( val_I = 0; val_I < self->operandDofs ; val_I++ ) {	
+		result[val_I] = *operand0 * operand1[val_I];
+	}
+}
+
+/* HACK - This function isn't extensible */
+Operator* Operator_NewFromName( 
+		Name                                       name, 		
+		Dof_Index                                  operandDofs,
+		Dimension_Index                            dim ) 
+{
+	Func_Ptr                                   _carryOut;
+	Dof_Index                                  resultDofs;
+	Index                                      numberOfOperands;
+
+	if ( ! strcasecmp( name, "VectorSquare" ) ) {
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_VectorSquare;
+	}
+	else if ( ! strcasecmp( name, "Magnitude" ) ) {
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_Magnitude;
+	}
+	else if ( ! strcasecmp( name, "TensorSymmetricPart" ) ) {
+		resultDofs = StGermain_nSymmetricTensorVectorComponents( dim );
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_TensorSymmetricPart;
+	}
+	else if ( ! strcasecmp( name, "TensorAntisymmetricPart" ) ) { 
+		resultDofs = dim * dim;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_TensorAntisymmetricPart;
+	}
+	else if ( ! strcasecmp( name, "SymmetricTensor_Invariant" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_SymmetricTensor_Invariant;
+	}
+	else if ( ! strcasecmp( name, "SymmetricTensor_NegAverageTrace" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_SymmetricTensor_GetNegAverageTrace;
+	}
+	else if ( ! strcasecmp( name, "Scalar_Negative" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_Scalar_Negative;
+	}
+	else if ( ! strcasecmp( name, "Tensor_NegAverageTrace" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_Tensor_GetNegAverageTrace;
+	}
+	else if ( ! strcasecmp( name, "SymmetricTensor_MakeDeviatoric" ) ){ 
+		resultDofs = operandDofs;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_SymmetricTensor_MakeDeviatoric;
+	}
+	else if ( ! strcasecmp( name, "TakeFirstComponent" ) ) {
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_TakeFirstComponent;
+	}
+	else if ( ! strcasecmp( name, "TakeSecondComponent" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_TakeSecondComponent;
+	}
+	else if ( ! strcasecmp( name, "TakeThirdComponent" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_TakeThirdComponent;
+	}
+	else if ( ! strcasecmp( name, "Addition" ) ) {
+		resultDofs = operandDofs;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_Addition;
+	}
+	else if ( ! strcasecmp( name, "Subtraction" ) ){ 
+		resultDofs = operandDofs;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_Subtraction;
+	}
+	else if ( ! strcasecmp( name, "ScalarMultiplication" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_ScalarMultiplication;
+	}
+	else if ( ! strcasecmp( name, "ScalarDivision" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_ScalarDivision;
+	}
+	else if ( ! strcasecmp( name, "VectorScale" ) ){ 
+		resultDofs = dim;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_VectorScale;
+	} 
+	else if ( ! strcasecmp( name, "Rounding" ) ){ 
+		resultDofs = operandDofs;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_Rounding;
+	} 
+	else if ( ! strcasecmp( name, "TensorInnerProduct" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_SymmetricTensorInnerProduct;
+	}
+	else if ( ! strcasecmp( name, "TensorInvariant" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_TensorInvariant;
+	}
+	else if ( ! strcasecmp( name, "HorizontalDivergence" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_HorizontalDivergence;
+	}
+	else if ( ! strcasecmp( name, "VerticalVorticity" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_VerticalVorticity;
+	}
+	else if ( ! strcasecmp( name, "Divergence" ) ){ 
+		resultDofs = 1;
+		numberOfOperands = 1;
+		_carryOut = (Func_Ptr)Operator_Divergence;
+	}
+	else if ( ! strcasecmp( name, "ScalarByVectorMultiplication" ) ){
+		resultDofs = dim;
+		numberOfOperands = 2;
+		_carryOut = (Func_Ptr)Operator_ScalarByVectorMultiplication;
+	}
+	else {
+		resultDofs = 0;
+		numberOfOperands = 0;
+		_carryOut = NULL;
+		
+		Journal_Printf( Journal_Register( Error_Type, (Name)Operator_Type  ), 
+				"In func %s: Error trying to create operator from name '%s'.\n",
+				__func__, name );
+		abort();
+	}
+
+	return Operator_New( name, _carryOut, numberOfOperands, operandDofs, resultDofs, dim );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/OperatorFieldVariable.c
--- a/Utils/src/OperatorFieldVariable.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,302 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: OperatorFieldVariable.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <string.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "FieldVariable.h"
-#include "Operator.h"
-#include "OperatorFieldVariable.h"
-#include "DomainContext.h"
-#include "FieldVariable_Register.h"
-
-#include <assert.h>
-
-const Type OperatorFieldVariable_Type = "OperatorFieldVariable";
-const Name defaultOperatorFieldVariableName = "defaultOperatorFieldVariableName";
-
-OperatorFieldVariable* OperatorFieldVariable_NewUnary( Name	name, DomainContext* context, void* _fieldVariable, Name operatorName ) {
-	FieldVariable* fieldVariable = (FieldVariable*) _fieldVariable;
-       	
-	return OperatorFieldVariable_New( 
-		name,
-		context,
-		OperatorFieldVariable_UnaryInterpolationFunc, 
-		operatorName,
-		1,
-		&fieldVariable, 
-		fieldVariable->dim,
-		fieldVariable->isCheckpointedAndReloaded,
-		fieldVariable->communicator,
-		fieldVariable->fieldVariable_Register );
-}
-
-OperatorFieldVariable* OperatorFieldVariable_NewBinary( Name name, DomainContext* context, void* _fieldVariable1, void* _fieldVariable2, Name operatorName ) {
-	FieldVariable* fieldVariableList[2];
-       
-	fieldVariableList[0] = (FieldVariable*) _fieldVariable1;
-	fieldVariableList[1] = (FieldVariable*) _fieldVariable2;
-	
-	return OperatorFieldVariable_New( 
-		name,
-		context,
-		OperatorFieldVariable_BinaryInterpolationFunc, 
-		operatorName,
-		2, 
-		fieldVariableList, 
-		fieldVariableList[0]->dim,
-		fieldVariableList[0]->isCheckpointedAndReloaded,
-		fieldVariableList[0]->communicator,
-		fieldVariableList[0]->fieldVariable_Register );
-}
-
-OperatorFieldVariable* OperatorFieldVariable_New( 
-	Name													name,
-	DomainContext*										context,
-	FieldVariable_InterpolateValueAtFunction*	interpolateValueAt,
-	Name													operatorName,
-	Index													fieldVariableCount,
-	FieldVariable**									fieldVariableList,
-	Dimension_Index									dim,
-	Bool													isCheckpointedAndReloaded,
-	MPI_Comm												communicator,
-	FieldVariable_Register*							fieldVariable_Register ) 
-{
-	OperatorFieldVariable* self = _OperatorFieldVariable_DefaultNew( name );
-
-	self->isConstructed = True;
-	_FieldVariable_Init( (FieldVariable*)self, context, fieldVariableCount, dim, isCheckpointedAndReloaded, communicator, fieldVariable_Register );
-	_OperatorFieldVariable_Init( self, operatorName, fieldVariableCount, fieldVariableList  );
-
-	return self;
-}
-
-OperatorFieldVariable* _OperatorFieldVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                      _sizeOfSelf = sizeof(OperatorFieldVariable);
-	Type                                                              type = OperatorFieldVariable_Type;
-	Stg_Class_DeleteFunction*                                      _delete = _OperatorFieldVariable_Delete;
-	Stg_Class_PrintFunction*                                        _print = _OperatorFieldVariable_Print;
-	Stg_Class_CopyFunction*                                          _copy = _OperatorFieldVariable_Copy;
-	Stg_Component_DefaultConstructorFunction*          _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_OperatorFieldVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                            _construct = _OperatorFieldVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                                    _build = _OperatorFieldVariable_Build;
-	Stg_Component_InitialiseFunction*                          _initialise = _OperatorFieldVariable_Initialise;
-	Stg_Component_ExecuteFunction*                                _execute = _OperatorFieldVariable_Execute;
-	Stg_Component_DestroyFunction*                                _destroy = _OperatorFieldVariable_Destroy;
-	AllocationType                                      nameAllocationType = NON_GLOBAL;
-	FieldVariable_InterpolateValueAtFunction*          _interpolateValueAt = _OperatorFieldVariable_InterpolateValueAt;
-	FieldVariable_GetValueFunction*            _getMinGlobalFieldMagnitude = _OperatorFieldVariable_GetMinLocalFieldMagnitude;
-	FieldVariable_GetValueFunction*            _getMaxGlobalFieldMagnitude = _OperatorFieldVariable_GetMaxLocalFieldMagnitude;
-	FieldVariable_GetCoordFunction*               _getMinAndMaxLocalCoords = _OperatorFieldVariable_GetMinAndMaxLocalCoords;
-	FieldVariable_GetCoordFunction*              _getMinAndMaxGlobalCoords = _OperatorFieldVariable_GetMinAndMaxGlobalCoords;
-
-	return _OperatorFieldVariable_New(  OPERATORFIELDVARIABLE_PASSARGS  );
-}
-
-OperatorFieldVariable* _OperatorFieldVariable_New(  OPERATORFIELDVARIABLE_DEFARGS  ) {
-	OperatorFieldVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(OperatorFieldVariable) );
-	self = (OperatorFieldVariable*) _FieldVariable_New(  FIELDVARIABLE_PASSARGS  );
-
-	return self;
-} 
-
-void _OperatorFieldVariable_Delete( void* _fieldVariable ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) _fieldVariable;
-
-	_FieldVariable_Delete( self );
-}
-
-void _OperatorFieldVariable_Print( void* _fieldVariable, Stream* stream ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) _fieldVariable;
-	Index                  fieldVariable_I;
-
-	_FieldVariable_Print( self, stream );
-
-	Journal_PrintValue( stream, self->fieldVariableCount );
-	for ( fieldVariable_I = 0 ; fieldVariable_I < self->fieldVariableCount ; fieldVariable_I++ ) 
-		Journal_Printf( stream, "\tFieldVariable %u - '%s'\n", fieldVariable_I, self->fieldVariableList[ fieldVariable_I ]->name );
-
-}
-
-void _OperatorFieldVariable_Init( void* ofv, Name operatorName, Index fieldVariableCount, FieldVariable** fieldVariableList ) {
-	OperatorFieldVariable*	self = (OperatorFieldVariable*)ofv;
-	FieldVariable*				fieldVariable;
-	Index							fieldVariable_I;
-	Stream*						errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	/* Create operator */
-	self->_operator = Operator_NewFromName( operatorName, fieldVariableList[0]->fieldComponentCount, self->dim );
-	self->fieldComponentCount = self->_operator->resultDofs; /* Reset this value from the one generated from the operator */
-	self->fieldVariableCount = fieldVariableCount;
-
-	/* Copy field variable list */
-	self->fieldVariableList = Memory_Alloc_Array( FieldVariable*, fieldVariableCount, "Array of Field Variables" );
-	memcpy( self->fieldVariableList, fieldVariableList, fieldVariableCount * sizeof( FieldVariable* ) );
-
-	for ( fieldVariable_I = 0 ; fieldVariable_I < fieldVariableCount ; fieldVariable_I++ ) {
-		fieldVariable = fieldVariableList[ fieldVariable_I ];
-		Journal_Firewall( fieldVariable != NULL, errorStream, "In func %s: FieldVariable %u in list is NULL\n", __func__, fieldVariable_I );
-		Journal_Firewall( fieldVariable->fieldComponentCount <= MAX_FIELD_COMPONENTS, errorStream,
-			"In func %s: Field Variable '%s' has too many components.\n", __func__, fieldVariable->name );
-	}
-}
-
-void* _OperatorFieldVariable_Copy( const void* fieldVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	OperatorFieldVariable*	self = (OperatorFieldVariable*)fieldVariable;
-	OperatorFieldVariable*	newOperatorFieldVariable;
-	
-	newOperatorFieldVariable = (OperatorFieldVariable*)_FieldVariable_Copy( self, dest, deep, nameExt, ptrMap );
-	newOperatorFieldVariable->_operator = self->_operator;
-	newOperatorFieldVariable->fieldVariableCount = self->fieldVariableCount;
-	
-	if (deep) {
-		newOperatorFieldVariable->fieldVariableList = Memory_Alloc_Array( FieldVariable*, self->fieldVariableCount, "Array of Field Variables" );
-		memcpy( newOperatorFieldVariable->fieldVariableList, self->fieldVariableList, self->fieldVariableCount * sizeof( FieldVariable* ) );
-	}
-	else 
-		newOperatorFieldVariable->fieldVariableList = self->fieldVariableList;
-	
-	return (void*)newOperatorFieldVariable;
-}
-
-void _OperatorFieldVariable_AssignFromXML( void* fieldVariable, Stg_ComponentFactory* cf, void* data ) {
-	OperatorFieldVariable*	self = (OperatorFieldVariable*) fieldVariable;
-	Index							fieldVariableCount = 0;
-	Name							operatorName;
-	FieldVariable**			fieldVariableList;
-	
-	/* Construct Parent */
-	_FieldVariable_AssignFromXML( self, cf, data );
-
-	operatorName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Operator", ""  );
-
-	fieldVariableList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"FieldVariables", Stg_ComponentFactory_Unlimited, FieldVariable, True, &fieldVariableCount, data  );
-
-	_OperatorFieldVariable_Init( self, operatorName, fieldVariableCount, fieldVariableList );
-
-	Memory_Free( fieldVariableList );
-}
-
-void _OperatorFieldVariable_Build( void* fieldVariable, void* data ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-	Index                  fieldVariable_I;
-
-	for ( fieldVariable_I = 0 ; fieldVariable_I < self->fieldVariableCount ; fieldVariable_I++ ) 
-		Stg_Component_Build( self->fieldVariableList[ fieldVariable_I ] , data, False );
-}
-
-void _OperatorFieldVariable_Execute( void* fieldVariable, void* data ) {}
-
-void _OperatorFieldVariable_Destroy( void* fieldVariable, void* data ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-
-	Memory_Free( self->fieldVariableList );
-	
-	_FieldVariable_Destroy( self, data );
-}
-
-void _OperatorFieldVariable_Initialise( void* fieldVariable, void* data ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-	Index                  fieldVariable_I;
-
-	for ( fieldVariable_I = 0 ; fieldVariable_I < self->fieldVariableCount ; fieldVariable_I++ ) 
-		Stg_Component_Initialise( self->fieldVariableList[ fieldVariable_I ] , data, False );
-}
-
-/* TODO - Think of something clever for these */
-double _OperatorFieldVariable_GetMinLocalFieldMagnitude( void* fieldVariable ) { return 0.0; }
-
-double _OperatorFieldVariable_GetMaxLocalFieldMagnitude( void* fieldVariable ) { return 0.0; }
-
-void  _OperatorFieldVariable_GetMinAndMaxLocalCoords( void* fieldVariable, Coord min, Coord max ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-
-	FieldVariable_GetMinAndMaxLocalCoords( self->fieldVariableList[0], min, max );
-}
-
-void  _OperatorFieldVariable_GetMinAndMaxGlobalCoords( void* fieldVariable, Coord min, Coord max ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-
-	FieldVariable_GetMinAndMaxGlobalCoords( self->fieldVariableList[0], min, max );
-}
-
-InterpolationResult _OperatorFieldVariable_InterpolateValueAt( void* fieldVariable, Coord coord, double* value ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-
-	switch ( self->fieldVariableCount ) {
-		case 1:
-			self->_interpolateValueAt = OperatorFieldVariable_UnaryInterpolationFunc; break;
-		case 2:
-			self->_interpolateValueAt = OperatorFieldVariable_BinaryInterpolationFunc; break;
-		default:
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-					"Can't use func '%s' with fieldVariableCount = %d\n", __func__, self->fieldVariableCount );
-	}
-
-	return FieldVariable_InterpolateValueAt( self, coord, value );
-}
-
-InterpolationResult OperatorFieldVariable_UnaryInterpolationFunc( void* fieldVariable, Coord coord, double* value ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-	FieldVariable*         field0 = self->fieldVariableList[0];
-	InterpolationResult    result;
-	double                 fieldValue[ MAX_FIELD_COMPONENTS ]; 
-
-	result = field0->_interpolateValueAt( field0, coord, fieldValue );
-	Operator_CarryOutUnaryOperation( self->_operator, fieldValue, value );
-	return result;
-}
-
-InterpolationResult OperatorFieldVariable_BinaryInterpolationFunc( void* fieldVariable, Coord coord, double* value ) {
-	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
-	FieldVariable*         field0 = self->fieldVariableList[0];
-	FieldVariable*         field1 = self->fieldVariableList[1];
-	double                 fieldValue0[ MAX_FIELD_COMPONENTS ]; 
-	double                 fieldValue1[ MAX_FIELD_COMPONENTS ]; 
-	InterpolationResult    result0;
-	InterpolationResult    result1;
-
-	result0 = field0->_interpolateValueAt( field0, coord, fieldValue0 );
-	result1 = field1->_interpolateValueAt( field1, coord, fieldValue1 );
-
-	Operator_CarryOutBinaryOperation( self->_operator, fieldValue0, fieldValue1, value ); 
-
-	return result0;
-}
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/OperatorFieldVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/OperatorFieldVariable.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,302 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: OperatorFieldVariable.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <string.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "FieldVariable.h"
+#include "Operator.h"
+#include "OperatorFieldVariable.h"
+#include "DomainContext.h"
+#include "FieldVariable_Register.h"
+
+#include <assert.h>
+
+const Type OperatorFieldVariable_Type = "OperatorFieldVariable";
+const Name defaultOperatorFieldVariableName = "defaultOperatorFieldVariableName";
+
+OperatorFieldVariable* OperatorFieldVariable_NewUnary( Name	name, DomainContext* context, void* _fieldVariable, Name operatorName ) {
+	FieldVariable* fieldVariable = (FieldVariable*) _fieldVariable;
+       	
+	return OperatorFieldVariable_New( 
+		name,
+		context,
+		OperatorFieldVariable_UnaryInterpolationFunc, 
+		operatorName,
+		1,
+		&fieldVariable, 
+		fieldVariable->dim,
+		fieldVariable->isCheckpointedAndReloaded,
+		fieldVariable->communicator,
+		fieldVariable->fieldVariable_Register );
+}
+
+OperatorFieldVariable* OperatorFieldVariable_NewBinary( Name name, DomainContext* context, void* _fieldVariable1, void* _fieldVariable2, Name operatorName ) {
+	FieldVariable* fieldVariableList[2];
+       
+	fieldVariableList[0] = (FieldVariable*) _fieldVariable1;
+	fieldVariableList[1] = (FieldVariable*) _fieldVariable2;
+	
+	return OperatorFieldVariable_New( 
+		name,
+		context,
+		OperatorFieldVariable_BinaryInterpolationFunc, 
+		operatorName,
+		2, 
+		fieldVariableList, 
+		fieldVariableList[0]->dim,
+		fieldVariableList[0]->isCheckpointedAndReloaded,
+		fieldVariableList[0]->communicator,
+		fieldVariableList[0]->fieldVariable_Register );
+}
+
+OperatorFieldVariable* OperatorFieldVariable_New( 
+	Name													name,
+	DomainContext*										context,
+	FieldVariable_InterpolateValueAtFunction*	interpolateValueAt,
+	Name													operatorName,
+	Index													fieldVariableCount,
+	FieldVariable**									fieldVariableList,
+	Dimension_Index									dim,
+	Bool													isCheckpointedAndReloaded,
+	MPI_Comm												communicator,
+	FieldVariable_Register*							fieldVariable_Register ) 
+{
+	OperatorFieldVariable* self = _OperatorFieldVariable_DefaultNew( name );
+
+	self->isConstructed = True;
+	_FieldVariable_Init( (FieldVariable*)self, context, fieldVariableCount, dim, isCheckpointedAndReloaded, communicator, fieldVariable_Register );
+	_OperatorFieldVariable_Init( self, operatorName, fieldVariableCount, fieldVariableList  );
+
+	return self;
+}
+
+OperatorFieldVariable* _OperatorFieldVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                      _sizeOfSelf = sizeof(OperatorFieldVariable);
+	Type                                                              type = OperatorFieldVariable_Type;
+	Stg_Class_DeleteFunction*                                      _delete = _OperatorFieldVariable_Delete;
+	Stg_Class_PrintFunction*                                        _print = _OperatorFieldVariable_Print;
+	Stg_Class_CopyFunction*                                          _copy = _OperatorFieldVariable_Copy;
+	Stg_Component_DefaultConstructorFunction*          _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_OperatorFieldVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                            _construct = _OperatorFieldVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                                    _build = _OperatorFieldVariable_Build;
+	Stg_Component_InitialiseFunction*                          _initialise = _OperatorFieldVariable_Initialise;
+	Stg_Component_ExecuteFunction*                                _execute = _OperatorFieldVariable_Execute;
+	Stg_Component_DestroyFunction*                                _destroy = _OperatorFieldVariable_Destroy;
+	AllocationType                                      nameAllocationType = NON_GLOBAL;
+	FieldVariable_InterpolateValueAtFunction*          _interpolateValueAt = _OperatorFieldVariable_InterpolateValueAt;
+	FieldVariable_GetValueFunction*            _getMinGlobalFieldMagnitude = _OperatorFieldVariable_GetMinLocalFieldMagnitude;
+	FieldVariable_GetValueFunction*            _getMaxGlobalFieldMagnitude = _OperatorFieldVariable_GetMaxLocalFieldMagnitude;
+	FieldVariable_GetCoordFunction*               _getMinAndMaxLocalCoords = _OperatorFieldVariable_GetMinAndMaxLocalCoords;
+	FieldVariable_GetCoordFunction*              _getMinAndMaxGlobalCoords = _OperatorFieldVariable_GetMinAndMaxGlobalCoords;
+
+	return _OperatorFieldVariable_New(  OPERATORFIELDVARIABLE_PASSARGS  );
+}
+
+OperatorFieldVariable* _OperatorFieldVariable_New(  OPERATORFIELDVARIABLE_DEFARGS  ) {
+	OperatorFieldVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(OperatorFieldVariable) );
+	self = (OperatorFieldVariable*) _FieldVariable_New(  FIELDVARIABLE_PASSARGS  );
+
+	return self;
+} 
+
+void _OperatorFieldVariable_Delete( void* _fieldVariable ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) _fieldVariable;
+
+	_FieldVariable_Delete( self );
+}
+
+void _OperatorFieldVariable_Print( void* _fieldVariable, Stream* stream ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) _fieldVariable;
+	Index                  fieldVariable_I;
+
+	_FieldVariable_Print( self, stream );
+
+	Journal_PrintValue( stream, self->fieldVariableCount );
+	for ( fieldVariable_I = 0 ; fieldVariable_I < self->fieldVariableCount ; fieldVariable_I++ ) 
+		Journal_Printf( stream, "\tFieldVariable %u - '%s'\n", fieldVariable_I, self->fieldVariableList[ fieldVariable_I ]->name );
+
+}
+
+void _OperatorFieldVariable_Init( void* ofv, Name operatorName, Index fieldVariableCount, FieldVariable** fieldVariableList ) {
+	OperatorFieldVariable*	self = (OperatorFieldVariable*)ofv;
+	FieldVariable*				fieldVariable;
+	Index							fieldVariable_I;
+	Stream*						errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	/* Create operator */
+	self->_operator = Operator_NewFromName( operatorName, fieldVariableList[0]->fieldComponentCount, self->dim );
+	self->fieldComponentCount = self->_operator->resultDofs; /* Reset this value from the one generated from the operator */
+	self->fieldVariableCount = fieldVariableCount;
+
+	/* Copy field variable list */
+	self->fieldVariableList = Memory_Alloc_Array( FieldVariable*, fieldVariableCount, "Array of Field Variables" );
+	memcpy( self->fieldVariableList, fieldVariableList, fieldVariableCount * sizeof( FieldVariable* ) );
+
+	for ( fieldVariable_I = 0 ; fieldVariable_I < fieldVariableCount ; fieldVariable_I++ ) {
+		fieldVariable = fieldVariableList[ fieldVariable_I ];
+		Journal_Firewall( fieldVariable != NULL, errorStream, "In func %s: FieldVariable %u in list is NULL\n", __func__, fieldVariable_I );
+		Journal_Firewall( fieldVariable->fieldComponentCount <= MAX_FIELD_COMPONENTS, errorStream,
+			"In func %s: Field Variable '%s' has too many components.\n", __func__, fieldVariable->name );
+	}
+}
+
+void* _OperatorFieldVariable_Copy( const void* fieldVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	OperatorFieldVariable*	self = (OperatorFieldVariable*)fieldVariable;
+	OperatorFieldVariable*	newOperatorFieldVariable;
+	
+	newOperatorFieldVariable = (OperatorFieldVariable*)_FieldVariable_Copy( self, dest, deep, nameExt, ptrMap );
+	newOperatorFieldVariable->_operator = self->_operator;
+	newOperatorFieldVariable->fieldVariableCount = self->fieldVariableCount;
+	
+	if (deep) {
+		newOperatorFieldVariable->fieldVariableList = Memory_Alloc_Array( FieldVariable*, self->fieldVariableCount, "Array of Field Variables" );
+		memcpy( newOperatorFieldVariable->fieldVariableList, self->fieldVariableList, self->fieldVariableCount * sizeof( FieldVariable* ) );
+	}
+	else 
+		newOperatorFieldVariable->fieldVariableList = self->fieldVariableList;
+	
+	return (void*)newOperatorFieldVariable;
+}
+
+void _OperatorFieldVariable_AssignFromXML( void* fieldVariable, Stg_ComponentFactory* cf, void* data ) {
+	OperatorFieldVariable*	self = (OperatorFieldVariable*) fieldVariable;
+	Index							fieldVariableCount = 0;
+	Name							operatorName;
+	FieldVariable**			fieldVariableList;
+	
+	/* Construct Parent */
+	_FieldVariable_AssignFromXML( self, cf, data );
+
+	operatorName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"Operator", ""  );
+
+	fieldVariableList = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"FieldVariables", Stg_ComponentFactory_Unlimited, FieldVariable, True, &fieldVariableCount, data  );
+
+	_OperatorFieldVariable_Init( self, operatorName, fieldVariableCount, fieldVariableList );
+
+	Memory_Free( fieldVariableList );
+}
+
+void _OperatorFieldVariable_Build( void* fieldVariable, void* data ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+	Index                  fieldVariable_I;
+
+	for ( fieldVariable_I = 0 ; fieldVariable_I < self->fieldVariableCount ; fieldVariable_I++ ) 
+		Stg_Component_Build( self->fieldVariableList[ fieldVariable_I ] , data, False );
+}
+
+void _OperatorFieldVariable_Execute( void* fieldVariable, void* data ) {}
+
+void _OperatorFieldVariable_Destroy( void* fieldVariable, void* data ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+
+	Memory_Free( self->fieldVariableList );
+	
+	_FieldVariable_Destroy( self, data );
+}
+
+void _OperatorFieldVariable_Initialise( void* fieldVariable, void* data ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+	Index                  fieldVariable_I;
+
+	for ( fieldVariable_I = 0 ; fieldVariable_I < self->fieldVariableCount ; fieldVariable_I++ ) 
+		Stg_Component_Initialise( self->fieldVariableList[ fieldVariable_I ] , data, False );
+}
+
+/* TODO - Think of something clever for these */
+double _OperatorFieldVariable_GetMinLocalFieldMagnitude( void* fieldVariable ) { return 0.0; }
+
+double _OperatorFieldVariable_GetMaxLocalFieldMagnitude( void* fieldVariable ) { return 0.0; }
+
+void  _OperatorFieldVariable_GetMinAndMaxLocalCoords( void* fieldVariable, Coord min, Coord max ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+
+	FieldVariable_GetMinAndMaxLocalCoords( self->fieldVariableList[0], min, max );
+}
+
+void  _OperatorFieldVariable_GetMinAndMaxGlobalCoords( void* fieldVariable, Coord min, Coord max ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+
+	FieldVariable_GetMinAndMaxGlobalCoords( self->fieldVariableList[0], min, max );
+}
+
+InterpolationResult _OperatorFieldVariable_InterpolateValueAt( void* fieldVariable, Coord coord, double* value ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+
+	switch ( self->fieldVariableCount ) {
+		case 1:
+			self->_interpolateValueAt = OperatorFieldVariable_UnaryInterpolationFunc; break;
+		case 2:
+			self->_interpolateValueAt = OperatorFieldVariable_BinaryInterpolationFunc; break;
+		default:
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+					"Can't use func '%s' with fieldVariableCount = %d\n", __func__, self->fieldVariableCount );
+	}
+
+	return FieldVariable_InterpolateValueAt( self, coord, value );
+}
+
+InterpolationResult OperatorFieldVariable_UnaryInterpolationFunc( void* fieldVariable, Coord coord, double* value ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+	FieldVariable*         field0 = self->fieldVariableList[0];
+	InterpolationResult    result;
+	double                 fieldValue[ MAX_FIELD_COMPONENTS ]; 
+
+	result = field0->_interpolateValueAt( field0, coord, fieldValue );
+	Operator_CarryOutUnaryOperation( self->_operator, fieldValue, value );
+	return result;
+}
+
+InterpolationResult OperatorFieldVariable_BinaryInterpolationFunc( void* fieldVariable, Coord coord, double* value ) {
+	OperatorFieldVariable* self = (OperatorFieldVariable*) fieldVariable;
+	FieldVariable*         field0 = self->fieldVariableList[0];
+	FieldVariable*         field1 = self->fieldVariableList[1];
+	double                 fieldValue0[ MAX_FIELD_COMPONENTS ]; 
+	double                 fieldValue1[ MAX_FIELD_COMPONENTS ]; 
+	InterpolationResult    result0;
+	InterpolationResult    result1;
+
+	result0 = field0->_interpolateValueAt( field0, coord, fieldValue0 );
+	result1 = field1->_interpolateValueAt( field1, coord, fieldValue1 );
+
+	Operator_CarryOutBinaryOperation( self->_operator, fieldValue0, fieldValue1, value ); 
+
+	return result0;
+}
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/RegularMeshUtils.c
--- a/Utils/src/RegularMeshUtils.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1099 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: RegularMeshUtils.c 4184 2007-09-25 07:54:17Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "RegularMeshUtils.h"
-
-
-Index RegularMeshUtils_ascendingIJK_ToHughesNodeNumberMap[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Mapping functions
-*/
-
-void RegularMeshUtils_Node_1DTo3D( void* _mesh, unsigned global, unsigned* inds ) {
-	Mesh*	mesh = (Mesh*)_mesh;
-	Grid**	grid;
-
-	assert( mesh );
-	assert( global < Mesh_GetGlobalSize( mesh, MT_VERTEX ) );
-	assert( inds );
-
-	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					     ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-	Grid_Lift( *grid, global, inds );
-}
-
-unsigned RegularMeshUtils_Node_3DTo1D( void* _mesh, unsigned* inds ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid**		grid;
-
-	assert( mesh );
-	assert( inds );
-
-	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					     ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	return Grid_Project( *grid, inds );
-}
-
-void RegularMeshUtils_Element_1DTo3D( void* _mesh, unsigned global, unsigned* inds ) {
-	Mesh*	mesh = (Mesh*)_mesh;
-	Grid**	grid;
-
-	assert( mesh );
-	assert( global < Mesh_GetGlobalSize( mesh, MT_VERTEX ) );
-	assert( inds );
-
-	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					     ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" )  );
-	Grid_Lift( *grid, global, inds );
-}
-
-unsigned RegularMeshUtils_Element_3DTo1D( void* _mesh, unsigned* inds ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid**		grid;
-
-	assert( mesh );
-	assert( inds );
-
-	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					     ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" )  );
-
-	return Grid_Project( *grid, inds );
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Set functions
-*/
-
-IndexSet* RegularMeshUtils_CreateGlobalTopSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == grid->sizes[1] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalLeftSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalRightSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 3 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[2] == grid->sizes[2] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 3 );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[2] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalInnerTopSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-        int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == grid->sizes[1] - 1 && 
-		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
-		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
-		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != 0)) && 
-		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != 0)) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalInnerBottomSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-        int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if(ijk[1] == 0 &&
-		   (ijk[0] != grid->sizes[0] - 1 && ijk[0] != 0) &&
-		   (nDims != 3 || (ijk[2] != grid->sizes[2] - 1 && ijk[2] != 0)))
-		{
-		    IndexSet_Add( set, n_i );
-		}
-/* 		if( ijk[1] == 0 &&  */
-/* 		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) &&  */
-/* 		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) &&  */
-/* 		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != 0)) &&  */
-/* 		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != 0)) ) */
-/* 		{ */
-/* 			IndexSet_Add( set, n_i ); */
-/* 		} */
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalInnerLeftSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-        int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 && 
-		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
-		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
-		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != 0)) && 
-		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != 0)) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalInnerRightSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-        int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 && 
-		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
-		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
-		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != 0)) && 
-		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != 0)) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalInnerFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[2] - 1 && 
-		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != grid->sizes[1] - 1 ) && 
-		    (ijk[0] != 0 || ijk[1] != grid->sizes[1] - 1 ) && 
-		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != 0 ) && 
-		    (ijk[0] != 0 || ijk[1] != 0 ) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalInnerBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 && 
-		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != grid->sizes[1] - 1 ) && 
-		    (ijk[0] != 0 || ijk[1] != grid->sizes[1] - 1 ) && 
-		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != 0 ) && 
-		    (ijk[0] != 0 || ijk[1] != 0 ) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomLeftFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 && 
-		    ijk[1] == 0 && 
-		    ijk[2] == grid->sizes[2] - 1 )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomRightFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 && 
-		    ijk[1] == 0 && 
-		    ijk[2] == grid->sizes[2] - 1 )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalTopLeftFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-	int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 && 
-		    ijk[1] == grid->sizes[1] - 1 && 
-		    (nDims != 3 || ijk[2] == grid->sizes[2] - 1) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalTopRightFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-	int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 && 
-		    ijk[1] == grid->sizes[1] - 1 && 
-		    (nDims != 3 || ijk[2] == grid->sizes[2] - 1) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomLeftBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	int nDims;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 && 
-		    ijk[1] == 0 && 
-		    (nDims != 3 || ijk[2] == 0))
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomRightBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	int nDims;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 && 
-		    ijk[1] == 0 && 
-		    (nDims != 3 || ijk[2] == 0) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalTopLeftBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-	int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 && 
-		    ijk[1] == grid->sizes[1] - 1 && 
-		    (nDims != 3 || ijk[2] == 0) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalTopRightBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-	int nDims;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 && 
-		    ijk[1] == grid->sizes[1] - 1 && 
-		    (nDims != 3 || ijk[2] == 0) )
-		{
-			IndexSet_Add( set, n_i );
-		}
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateLocalInGlobalTopSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == grid->sizes[1] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateLocalInGlobalBottomSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateLocalInGlobalLeftSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-
-	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateLocalInGlobalRightSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[0] == grid->sizes[0] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateLocalInGlobalFrontSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	Grid*		grid;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 3 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
-
-	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[2] == grid->sizes[2] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateLocalInGlobalBackSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 3 );
-
-	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[2] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateContactTopSet( void* _mesh, int lowDepth, int uppDepth ) {
-   Mesh* mesh = (Mesh*)_mesh;
-   Grid* grid;
-   int nNodes;
-   IndexSet* set;
-   int ijk[2], left, right, bottom, top;
-   int ii;
-
-   assert( mesh );
-   assert( Mesh_GetDimSize( mesh ) == 2 );
-
-   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
-   set = IndexSet_New( nNodes );
-
-/*
-   left = depth + 1;
-   right = grid->sizes[0] - (depth + 1) - 1;
-   bottom = 1;
-   top = depth;
-*/
-   left = lowDepth;
-   right = grid->sizes[0] - 1 - uppDepth;
-   bottom = grid->sizes[1] - 1;
-   top = grid->sizes[1] - 1;
-   for( ii = 0; ii < nNodes; ii++ ) {
-     Grid_Lift( grid, Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)0, ii ), (unsigned*)ijk );
-      if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top )
-	 IndexSet_Add( set, ii );
-   }
-
-   return set;
-}
-
-IndexSet* RegularMeshUtils_CreateContactBottomSet( void* _mesh, int lowDepth, int uppDepth, int inDepth ) {
-   Mesh* mesh = (Mesh*)_mesh;
-   Grid* grid;
-   int nNodes;
-   IndexSet* set;
-   int ijk[2], left, right, bottom, top;
-   int ii;
-
-   assert( mesh );
-   assert( Mesh_GetDimSize( mesh ) == 2 );
-
-   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
-   set = IndexSet_New( nNodes );
-
-/*
-   left = depth + 1;
-   right = grid->sizes[0] - (depth + 1) - 1;
-   bottom = 1;
-   top = depth;
-*/
-   left = lowDepth;
-   right = grid->sizes[0] - 1 - uppDepth;
-   bottom = 0;
-   top = inDepth;
-   for( ii = 0; ii < nNodes; ii++ ) {
-     Grid_Lift(grid,Mesh_DomainToGlobal(mesh,(MeshTopology_Dim)0,ii ),
-               (unsigned*)ijk );
-     if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top ) {
-       IndexSet_Add( set, ii );
-     }
-   }
-
-   return set;
-}
-
-IndexSet* RegularMeshUtils_CreateContactLeftSet( void* _mesh, int lowDepth, int uppDepth ) {
-   Mesh* mesh = (Mesh*)_mesh;
-   Grid* grid;
-   int nNodes;
-   IndexSet* set;
-   int ijk[2], left, right, bottom, top;
-   int ii;
-
-   assert( mesh );
-   assert( Mesh_GetDimSize( mesh ) == 2 );
-
-   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
-   set = IndexSet_New( nNodes );
-
-/*
-   left = 1;
-   right = depth;
-   bottom = depth + 1;
-   top = grid->sizes[1] - 2;
-*/
-   left = 0;
-   right = 0;
-   bottom = lowDepth;
-   top = grid->sizes[1] - 1 - uppDepth;
-   for( ii = 0; ii < nNodes; ii++ ) {
-     Grid_Lift( grid, Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)0, ii ),
-                (unsigned*)ijk );
-      if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top )
-	 IndexSet_Add( set, ii );
-   }
-
-   return set;
-}
-
-IndexSet* RegularMeshUtils_CreateContactRightSet( void* _mesh, int lowDepth, int uppDepth, int inDepth ) {
-   Mesh* mesh = (Mesh*)_mesh;
-   Grid* grid;
-   int nNodes;
-   IndexSet* set;
-   int ijk[2], left, right, bottom, top;
-   int ii;
-
-   assert( mesh );
-   assert( Mesh_GetDimSize( mesh ) == 2 );
-
-   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
-   set = IndexSet_New( nNodes );
-
-/*
-   left = grid->sizes[0] - depth - 1;
-   right = grid->sizes[0] - 2;
-   bottom = depth + 1;
-   top = grid->sizes[1] - 2;
-*/
-   left = grid->sizes[0] - 1 - inDepth;
-   right = grid->sizes[0] - 1;
-   bottom = lowDepth;
-   top = grid->sizes[1] - 1- uppDepth;
-   for( ii = 0; ii < nNodes; ii++ ) {
-     Grid_Lift( grid, Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)0, ii ),
-                (unsigned*)ijk );
-      if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top )
-	 IndexSet_Add( set, ii );
-   }
-
-   return set;
-}
-
-Node_DomainIndex RegularMeshUtils_GetDiagOppositeAcrossElementNodeIndex( void* _mesh, 
-									 Element_DomainIndex refElement_dI, 
-									 Node_DomainIndex refNode_dI )
-{
-	Mesh*              mesh = (Mesh*)_mesh;
-	const Node_Index   oppositeNodesMap2D[] = { 3, 2, 1, 0 };
-	Node_Index         oppositeNodesMap3D[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
-	Node_DomainIndex*  currElementNodes = NULL;
-	Node_Index         currElementNodeCount = 0;
-	Node_Index         refNode_eI = 0;
-	Node_DomainIndex   oppositeNode_dI = 0;
-	Node_Index         oppositeNode_eI = 0;
-	Stream*            errorStrm = Journal_Register( Error_Type, (Name)"RegularMeshUtils"  );
-	IArray*		   inc;
-
-	Journal_Firewall( Mesh_GetElementType( mesh, refElement_dI )->type == Mesh_HexType_Type, errorStrm, 
-			  "Error (%s:%s:%d):\n\tIncorrect element type (%s); require %s.\n", 
-			  __func__, __FILE__, __LINE__, Mesh_GetElementType( mesh, refElement_dI )->type, 
-			  Mesh_HexType_Type );
-
-#if 0
-	Journal_Firewall( CornerNL_Type == mesh->layout->nodeLayout->type , errorStr,
-		"Error- in %s: Given mesh has node layout of type \"%s\", different to "
-		"required type \"%s\".\n", __func__, mesh->layout->nodeLayout->type, CornerNL_Type );
-#endif
-
-	inc = IArray_New();
-	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), refElement_dI, MT_VERTEX, 
-			   inc );
-	currElementNodeCount = IArray_GetSize( inc );
-	currElementNodes = (Node_DomainIndex*)IArray_GetPtr( inc );
-
-	/* Find index of reference node within reference element */
-	for( refNode_eI = 0; refNode_eI < currElementNodeCount; refNode_eI++ ) {
-		if ( refNode_dI == currElementNodes[refNode_eI] )
-			break;
-	}
-	Journal_Firewall( refNode_eI < currElementNodeCount, errorStrm,
-		"Error - in %s(): Reference node %d (domain) not found within reference element %d (domain).\n",
-		__func__, refNode_dI, refElement_dI );
-
-	/* Use mapping table to get diagonally opposite node, then convert back to domain index */
-	
-	if ( Mesh_GetDimSize( mesh ) == 2 ) {
-		oppositeNode_eI = oppositeNodesMap2D[refNode_eI];
-	}
-	else {
-		oppositeNode_eI = oppositeNodesMap3D[refNode_eI];
-	}
-
-	oppositeNode_dI = currElementNodes[oppositeNode_eI];
-	NewClass_Delete( inc );
-	return oppositeNode_dI;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomLeftSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	int nDims;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-        nDims = Mesh_GetDimSize( mesh );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == 0 && ijk[0] == 0 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-IndexSet* RegularMeshUtils_CreateGlobalBottomRightSet( void* _mesh ) {
-	Mesh*		mesh = (Mesh*)_mesh;
-	unsigned	nNodes;
-	IndexSet*	set;
-	IJK		ijk;
-	Grid*	grid;
-	int nDims;
-	unsigned	n_i;
-
-	assert( mesh );
-	assert( Mesh_GetDimSize( mesh ) >= 2 );
-
-	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
-					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
-
-        nDims = Mesh_GetDimSize( mesh  );
-	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
-	set = IndexSet_New( nNodes );
-
-	for( n_i = 0; n_i < nNodes; n_i++ ) {
-		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
-		if( ijk[1] == 0 && ijk[0] == grid->sizes[0] - 1 )
-			IndexSet_Add( set, n_i );
-	}
-
-	return set;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/RegularMeshUtils.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/RegularMeshUtils.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,1099 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: RegularMeshUtils.c 4184 2007-09-25 07:54:17Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "RegularMeshUtils.h"
+
+
+Index RegularMeshUtils_ascendingIJK_ToHughesNodeNumberMap[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Mapping functions
+*/
+
+void RegularMeshUtils_Node_1DTo3D( void* _mesh, unsigned global, unsigned* inds ) {
+	Mesh*	mesh = (Mesh*)_mesh;
+	Grid**	grid;
+
+	assert( mesh );
+	assert( global < Mesh_GetGlobalSize( mesh, MT_VERTEX ) );
+	assert( inds );
+
+	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					     ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+	Grid_Lift( *grid, global, inds );
+}
+
+unsigned RegularMeshUtils_Node_3DTo1D( void* _mesh, unsigned* inds ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid**		grid;
+
+	assert( mesh );
+	assert( inds );
+
+	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					     ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	return Grid_Project( *grid, inds );
+}
+
+void RegularMeshUtils_Element_1DTo3D( void* _mesh, unsigned global, unsigned* inds ) {
+	Mesh*	mesh = (Mesh*)_mesh;
+	Grid**	grid;
+
+	assert( mesh );
+	assert( global < Mesh_GetGlobalSize( mesh, MT_VERTEX ) );
+	assert( inds );
+
+	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					     ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" )  );
+	Grid_Lift( *grid, global, inds );
+}
+
+unsigned RegularMeshUtils_Element_3DTo1D( void* _mesh, unsigned* inds ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid**		grid;
+
+	assert( mesh );
+	assert( inds );
+
+	grid = (Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					     ExtensionManager_GetHandle( mesh->info, (Name)"elementGrid" )  );
+
+	return Grid_Project( *grid, inds );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Set functions
+*/
+
+IndexSet* RegularMeshUtils_CreateGlobalTopSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == grid->sizes[1] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalLeftSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalRightSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 3 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[2] == grid->sizes[2] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 3 );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[2] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalInnerTopSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+        int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == grid->sizes[1] - 1 && 
+		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
+		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
+		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != 0)) && 
+		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != 0)) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalInnerBottomSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+        int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if(ijk[1] == 0 &&
+		   (ijk[0] != grid->sizes[0] - 1 && ijk[0] != 0) &&
+		   (nDims != 3 || (ijk[2] != grid->sizes[2] - 1 && ijk[2] != 0)))
+		{
+		    IndexSet_Add( set, n_i );
+		}
+/* 		if( ijk[1] == 0 &&  */
+/* 		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) &&  */
+/* 		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) &&  */
+/* 		    (ijk[0] != grid->sizes[0] - 1 || (nDims == 3 && ijk[2] != 0)) &&  */
+/* 		    (ijk[0] != 0 || (nDims == 3 && ijk[2] != 0)) ) */
+/* 		{ */
+/* 			IndexSet_Add( set, n_i ); */
+/* 		} */
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalInnerLeftSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+        int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 && 
+		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
+		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
+		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != 0)) && 
+		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != 0)) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalInnerRightSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+        int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 && 
+		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
+		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != grid->sizes[2] - 1)) && 
+		    (ijk[1] != grid->sizes[1] - 1 || (nDims == 3 && ijk[2] != 0)) && 
+		    (ijk[1] != 0 || (nDims == 3 && ijk[2] != 0)) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalInnerFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[2] - 1 && 
+		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != grid->sizes[1] - 1 ) && 
+		    (ijk[0] != 0 || ijk[1] != grid->sizes[1] - 1 ) && 
+		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != 0 ) && 
+		    (ijk[0] != 0 || ijk[1] != 0 ) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalInnerBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 && 
+		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != grid->sizes[1] - 1 ) && 
+		    (ijk[0] != 0 || ijk[1] != grid->sizes[1] - 1 ) && 
+		    (ijk[0] != grid->sizes[0] - 1 || ijk[1] != 0 ) && 
+		    (ijk[0] != 0 || ijk[1] != 0 ) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomLeftFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 && 
+		    ijk[1] == 0 && 
+		    ijk[2] == grid->sizes[2] - 1 )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomRightFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 && 
+		    ijk[1] == 0 && 
+		    ijk[2] == grid->sizes[2] - 1 )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalTopLeftFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+	int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 && 
+		    ijk[1] == grid->sizes[1] - 1 && 
+		    (nDims != 3 || ijk[2] == grid->sizes[2] - 1) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalTopRightFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+	int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 && 
+		    ijk[1] == grid->sizes[1] - 1 && 
+		    (nDims != 3 || ijk[2] == grid->sizes[2] - 1) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomLeftBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	int nDims;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 && 
+		    ijk[1] == 0 && 
+		    (nDims != 3 || ijk[2] == 0))
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomRightBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	int nDims;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 && 
+		    ijk[1] == 0 && 
+		    (nDims != 3 || ijk[2] == 0) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalTopLeftBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+	int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 && 
+		    ijk[1] == grid->sizes[1] - 1 && 
+		    (nDims != 3 || ijk[2] == 0) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalTopRightBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+	int nDims;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 && 
+		    ijk[1] == grid->sizes[1] - 1 && 
+		    (nDims != 3 || ijk[2] == 0) )
+		{
+			IndexSet_Add( set, n_i );
+		}
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateLocalInGlobalTopSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == grid->sizes[1] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateLocalInGlobalBottomSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateLocalInGlobalLeftSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+
+	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateLocalInGlobalRightSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[0] == grid->sizes[0] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateLocalInGlobalFrontSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	Grid*		grid;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 3 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" )  );
+
+	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[2] == grid->sizes[2] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateLocalInGlobalBackSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 3 );
+
+	nNodes = Mesh_GetLocalSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[2] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateContactTopSet( void* _mesh, int lowDepth, int uppDepth ) {
+   Mesh* mesh = (Mesh*)_mesh;
+   Grid* grid;
+   int nNodes;
+   IndexSet* set;
+   int ijk[2], left, right, bottom, top;
+   int ii;
+
+   assert( mesh );
+   assert( Mesh_GetDimSize( mesh ) == 2 );
+
+   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
+   set = IndexSet_New( nNodes );
+
+/*
+   left = depth + 1;
+   right = grid->sizes[0] - (depth + 1) - 1;
+   bottom = 1;
+   top = depth;
+*/
+   left = lowDepth;
+   right = grid->sizes[0] - 1 - uppDepth;
+   bottom = grid->sizes[1] - 1;
+   top = grid->sizes[1] - 1;
+   for( ii = 0; ii < nNodes; ii++ ) {
+     Grid_Lift( grid, Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)0, ii ), (unsigned*)ijk );
+      if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top )
+	 IndexSet_Add( set, ii );
+   }
+
+   return set;
+}
+
+IndexSet* RegularMeshUtils_CreateContactBottomSet( void* _mesh, int lowDepth, int uppDepth, int inDepth ) {
+   Mesh* mesh = (Mesh*)_mesh;
+   Grid* grid;
+   int nNodes;
+   IndexSet* set;
+   int ijk[2], left, right, bottom, top;
+   int ii;
+
+   assert( mesh );
+   assert( Mesh_GetDimSize( mesh ) == 2 );
+
+   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
+   set = IndexSet_New( nNodes );
+
+/*
+   left = depth + 1;
+   right = grid->sizes[0] - (depth + 1) - 1;
+   bottom = 1;
+   top = depth;
+*/
+   left = lowDepth;
+   right = grid->sizes[0] - 1 - uppDepth;
+   bottom = 0;
+   top = inDepth;
+   for( ii = 0; ii < nNodes; ii++ ) {
+     Grid_Lift(grid,Mesh_DomainToGlobal(mesh,(MeshTopology_Dim)0,ii ),
+               (unsigned*)ijk );
+     if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top ) {
+       IndexSet_Add( set, ii );
+     }
+   }
+
+   return set;
+}
+
+IndexSet* RegularMeshUtils_CreateContactLeftSet( void* _mesh, int lowDepth, int uppDepth ) {
+   Mesh* mesh = (Mesh*)_mesh;
+   Grid* grid;
+   int nNodes;
+   IndexSet* set;
+   int ijk[2], left, right, bottom, top;
+   int ii;
+
+   assert( mesh );
+   assert( Mesh_GetDimSize( mesh ) == 2 );
+
+   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
+   set = IndexSet_New( nNodes );
+
+/*
+   left = 1;
+   right = depth;
+   bottom = depth + 1;
+   top = grid->sizes[1] - 2;
+*/
+   left = 0;
+   right = 0;
+   bottom = lowDepth;
+   top = grid->sizes[1] - 1 - uppDepth;
+   for( ii = 0; ii < nNodes; ii++ ) {
+     Grid_Lift( grid, Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)0, ii ),
+                (unsigned*)ijk );
+      if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top )
+	 IndexSet_Add( set, ii );
+   }
+
+   return set;
+}
+
+IndexSet* RegularMeshUtils_CreateContactRightSet( void* _mesh, int lowDepth, int uppDepth, int inDepth ) {
+   Mesh* mesh = (Mesh*)_mesh;
+   Grid* grid;
+   int nNodes;
+   IndexSet* set;
+   int ijk[2], left, right, bottom, top;
+   int ii;
+
+   assert( mesh );
+   assert( Mesh_GetDimSize( mesh ) == 2 );
+
+   grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+   nNodes = Mesh_GetDomainSize( mesh, (MeshTopology_Dim)0 );
+   set = IndexSet_New( nNodes );
+
+/*
+   left = grid->sizes[0] - depth - 1;
+   right = grid->sizes[0] - 2;
+   bottom = depth + 1;
+   top = grid->sizes[1] - 2;
+*/
+   left = grid->sizes[0] - 1 - inDepth;
+   right = grid->sizes[0] - 1;
+   bottom = lowDepth;
+   top = grid->sizes[1] - 1- uppDepth;
+   for( ii = 0; ii < nNodes; ii++ ) {
+     Grid_Lift( grid, Mesh_DomainToGlobal( mesh, (MeshTopology_Dim)0, ii ),
+                (unsigned*)ijk );
+      if( ijk[0] >= left && ijk[0] <= right && ijk[1] >= bottom && ijk[1] <= top )
+	 IndexSet_Add( set, ii );
+   }
+
+   return set;
+}
+
+Node_DomainIndex RegularMeshUtils_GetDiagOppositeAcrossElementNodeIndex( void* _mesh, 
+									 Element_DomainIndex refElement_dI, 
+									 Node_DomainIndex refNode_dI )
+{
+	Mesh*              mesh = (Mesh*)_mesh;
+	const Node_Index   oppositeNodesMap2D[] = { 3, 2, 1, 0 };
+	Node_Index         oppositeNodesMap3D[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
+	Node_DomainIndex*  currElementNodes = NULL;
+	Node_Index         currElementNodeCount = 0;
+	Node_Index         refNode_eI = 0;
+	Node_DomainIndex   oppositeNode_dI = 0;
+	Node_Index         oppositeNode_eI = 0;
+	Stream*            errorStrm = Journal_Register( Error_Type, (Name)"RegularMeshUtils"  );
+	IArray*		   inc;
+
+	Journal_Firewall( Mesh_GetElementType( mesh, refElement_dI )->type == Mesh_HexType_Type, errorStrm, 
+			  "Error (%s:%s:%d):\n\tIncorrect element type (%s); require %s.\n", 
+			  __func__, __FILE__, __LINE__, Mesh_GetElementType( mesh, refElement_dI )->type, 
+			  Mesh_HexType_Type );
+
+#if 0
+	Journal_Firewall( CornerNL_Type == mesh->layout->nodeLayout->type , errorStr,
+		"Error- in %s: Given mesh has node layout of type \"%s\", different to "
+		"required type \"%s\".\n", __func__, mesh->layout->nodeLayout->type, CornerNL_Type );
+#endif
+
+	inc = IArray_New();
+	Mesh_GetIncidence( mesh, Mesh_GetDimSize( mesh ), refElement_dI, MT_VERTEX, 
+			   inc );
+	currElementNodeCount = IArray_GetSize( inc );
+	currElementNodes = (Node_DomainIndex*)IArray_GetPtr( inc );
+
+	/* Find index of reference node within reference element */
+	for( refNode_eI = 0; refNode_eI < currElementNodeCount; refNode_eI++ ) {
+		if ( refNode_dI == currElementNodes[refNode_eI] )
+			break;
+	}
+	Journal_Firewall( refNode_eI < currElementNodeCount, errorStrm,
+		"Error - in %s(): Reference node %d (domain) not found within reference element %d (domain).\n",
+		__func__, refNode_dI, refElement_dI );
+
+	/* Use mapping table to get diagonally opposite node, then convert back to domain index */
+	
+	if ( Mesh_GetDimSize( mesh ) == 2 ) {
+		oppositeNode_eI = oppositeNodesMap2D[refNode_eI];
+	}
+	else {
+		oppositeNode_eI = oppositeNodesMap3D[refNode_eI];
+	}
+
+	oppositeNode_dI = currElementNodes[oppositeNode_eI];
+	NewClass_Delete( inc );
+	return oppositeNode_dI;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomLeftSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	int nDims;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+        nDims = Mesh_GetDimSize( mesh );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == 0 && ijk[0] == 0 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+IndexSet* RegularMeshUtils_CreateGlobalBottomRightSet( void* _mesh ) {
+	Mesh*		mesh = (Mesh*)_mesh;
+	unsigned	nNodes;
+	IndexSet*	set;
+	IJK		ijk;
+	Grid*	grid;
+	int nDims;
+	unsigned	n_i;
+
+	assert( mesh );
+	assert( Mesh_GetDimSize( mesh ) >= 2 );
+
+	grid = *(Grid**)ExtensionManager_Get( mesh->info, mesh, 
+					      ExtensionManager_GetHandle( mesh->info, (Name)"vertexGrid" ) );
+
+        nDims = Mesh_GetDimSize( mesh  );
+	nNodes = Mesh_GetDomainSize( mesh, MT_VERTEX );
+	set = IndexSet_New( nNodes );
+
+	for( n_i = 0; n_i < nNodes; n_i++ ) {
+		RegularMeshUtils_Node_1DTo3D( mesh, Mesh_DomainToGlobal( mesh, MT_VERTEX, n_i ), ijk );
+		if( ijk[1] == 0 && ijk[0] == grid->sizes[0] - 1 )
+			IndexSet_Add( set, n_i );
+	}
+
+	return set;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/RegularRemesher.c
--- a/Utils/src/RegularRemesher.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,729 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
-** 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: RegularRemesher.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#ifdef HAVE_PETSC
-
-#include <stdlib.h>
-#include <string.h>
-#include <petsc.h>
-#include <petscvec.h>
-#include <petscmat.h>
-#include <petscksp.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "NewRemesher.h"
-#include "RegularRemesher.h"
-#include "StGermain/Base/Foundation/ClassDef.h"
-
-
-void _RegularRemesher_Init( void* _self ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-
-   _NewRemesher_Init( self );
-   self->remeshDims = ISet_New();
-   self->staticWalls = Class_Array( self, ISet*, 2 );
-   self->staticWalls[0] = ISet_New();
-   self->staticWalls[1] = ISet_New();
-   ISet_SetMaxSize( self->remeshDims, 10 );
-   ISet_SetMaxSize( self->staticWalls[0], 10 );
-   ISet_SetMaxSize( self->staticWalls[1], 10 );
-   self->syncs = NULL;
-   self->crds = NULL;
-   self->nWallVerts = NULL;
-   self->wallVerts = NULL;
-   self->wallCrds = NULL;
-}
-
-void _RegularRemesher_Copy( void* _self, const void* _op ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-   const RegularRemesher* op = Class_Cast( _op, RegularRemesher );
-
-   _NewRemesher_Copy( self, op );
-   /* TODO */
-}
-
-void _RegularRemesher_Destruct( void* _self ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-   int nDims;
-   int d_i;
-
-   if( self->syncs ) {
-      nDims = self->nDims;
-      for( d_i = 0; d_i < nDims; d_i++ ) {
-   	 NewClass_RemoveRef( self->syncs[d_i] );
-	 Class_Free( self, self->crds[d_i] );
-	 Class_Free( self, self->nWallVerts[d_i] );
-	 Class_Free( self, self->wallVerts[d_i][0] );
-	 Class_Free( self, self->wallVerts[d_i][1] );
-	 Class_Free( self, self->wallVerts[d_i] );
-	 Class_Free( self, self->wallCrds[d_i][0] );
-	 Class_Free( self, self->wallCrds[d_i][1] );
-	 Class_Free( self, self->wallCrds[d_i] );
-      }
-      Class_Free( self, self->syncs );
-      Class_Free( self, self->crds );
-      Class_Free( self, self->nWallVerts );
-      Class_Free( self, self->wallVerts );
-      Class_Free( self, self->wallCrds );
-   }
-   NewClass_Delete( self->remeshDims );
-   NewClass_Delete( self->staticWalls[0] );
-   NewClass_Delete( self->staticWalls[1] );
-   Class_Free( self, self->staticWalls );
-   _NewClass_Destruct( self );
-}
-
-void _RegularRemesher_Print( const void* _self, Stream* stream ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-
-   _NewRemesher_Print( self, stream );
-}
-
-void _RegularRemesher_Remesh( void* _self ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-   Mesh* mesh;
-   Grid *vGrid;
-   Sync* meshSync;
-   int nDims, nVerts;
-   int center, ind, *inds;
-   double leftCrd, rightCrd;
-   CartesianGenerator* gen;
-   int d_i, v_i, w_i;
-
-   assert( self->mesh );
-
-   mesh = self->mesh;
-   meshSync = Mesh_GetSync( mesh, (MeshTopology_Dim)0 );
-   nDims = Mesh_GetDimSize( mesh );
-   nVerts = Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 );
-   vGrid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-   inds = Class_Array( self, int, nDims );
-
-   for( d_i = 0; d_i < nDims; d_i++ ) {
-      for( w_i = 0; w_i < 2; w_i++ ) {
-	 if( !ISet_Has( self->staticWalls[w_i], d_i ) )
-	    continue;
-	 for( v_i = 0; v_i < self->nWallVerts[d_i][w_i]; v_i++ ) {
-	    mesh->verts[self->wallVerts[d_i][w_i][v_i]][d_i] = 
-	       self->wallCrds[d_i][w_i][v_i];
-	 }
-      }
-   }
-
-   /* If we have a contact depth set we'll need to manipulate the boundaries
-      a little. */
-   gen = (CartesianGenerator*)self->mesh->generator;
-   if( strcmp( gen->type, CartesianGenerator_Type ) )
-      gen = NULL;
-   if( gen && (gen->contactDepth[0][0] || gen->contactDepth[0][1] ||
-               gen->contactDepth[1][0] || gen->contactDepth[1][1] ||
-               gen->contactDepth[2][0] || gen->contactDepth[2][1]) )
-   {
-      /*int curInd;*/
-      int /*ii,*/ d_j;
-
-#if 0
-      /* Reset static depths. */
-      curInd = 0;
-      for( ii = 0; ii < nVerts; ii++ ) {
-         Grid_Lift( vGrid, ii, inds );
-         if( inds[1] != self->contactDepth ) continue;
-         Mesh_GetVertex( mesh, ii )[1] = self->contactVerts[curInd++];
-      }
-#endif
-
-      /* Also handle contact element boundaries. */
-      for( d_i = 0; d_i < nDims; d_i++ ) {
-         for( v_i = 0; v_i < nVerts; v_i++ ) {
-            ind = Sync_DomainToGlobal( meshSync, v_i );
-            Grid_Lift( vGrid, ind, (unsigned*)inds );
-            center = inds[d_i];
-            if( center == 0 || center == (int)(vGrid->sizes[d_i] - 1) ) {
-
-               /* If we're inside the contact depth range, we need to make
-                  sure the side coordinates are aligned. */
-	       if( d_i == 0 ) {
-		  d_j = 1;
-	       }
-               else if( d_i == 1 ) {
-		  d_j = 0;
-	       }
-               else if( d_i == 2 ) {
-		  d_j = 1;
-		  // TODO
-		  abort();
-	       }
-               if( inds[d_j] < gen->contactDepth[d_j][0] )
-                  inds[d_j] = gen->contactDepth[d_j][0];
-               else if( inds[d_j] > (int)(vGrid->sizes[d_j] - gen->contactDepth[d_j][1] - 1 ))
-                  inds[d_j] = vGrid->sizes[d_j] - gen->contactDepth[d_j][1] - 1;
-               Mesh_GetVertex( mesh, v_i )[d_i] =
-                 Mesh_GetVertex( mesh, Grid_Project( vGrid, (unsigned*)inds ) )[d_i];
-            }
-         }
-      }
-   }
-
-   for( d_i = 0; d_i < nDims; d_i++ ) {
-      if( !ISet_Has( self->remeshDims, d_i ) )
-	 continue;
-
-      Sync_SyncArray( self->syncs[d_i], 
-		      mesh->verts[0] + d_i, nDims * sizeof(double), 
-		      self->crds[d_i], sizeof(double), 
-		      sizeof(double) );
-
-      for( v_i = 0; v_i < nVerts; v_i++ ) {
-	 ind = Sync_DomainToGlobal( meshSync, v_i );
-	 Grid_Lift( vGrid, ind, (unsigned*)inds );
-	 center = inds[d_i];
-	 if( center == 0 || center == (int)(vGrid->sizes[d_i] - 1 ))
-	    continue;
-
-	 inds[d_i] = 0;
-	 ind = Grid_Project( vGrid, (unsigned*)inds );
-	 ind = Sync_GlobalToDomain( self->syncs[d_i], ind );
-	 if( ind >= nVerts )
-	    leftCrd = self->crds[d_i][ind - nVerts];
-	 else
-	    leftCrd = Mesh_GetVertex( mesh, ind)[d_i];
-
-	 inds[d_i] = vGrid->sizes[d_i] - 1;
-	 ind = Grid_Project( vGrid, (unsigned*)inds );
-	 ind = Sync_GlobalToDomain( self->syncs[d_i], ind );
-	 if( ind >= nVerts )
-	    rightCrd = self->crds[d_i][ind - nVerts];
-	 else
-	    rightCrd = Mesh_GetVertex( mesh, ind)[d_i];
-
-         /* Do interpolation. */
-         if( gen ) {
-            if( center <= gen->contactDepth[d_i][0] ) {
-               mesh->verts[v_i][d_i] = leftCrd;
-               if( gen->contactDepth[d_i][0] ) {
-                  mesh->verts[v_i][d_i] +=
-                     ((double)center / (double)gen->contactDepth[d_i][0]) *
-                     gen->contactGeom[d_i];
-               }
-            }
-            else if( center >= (int)(vGrid->sizes[d_i] - gen->contactDepth[d_i][1] - 1 )) {
-               mesh->verts[v_i][d_i] = rightCrd;
-               if( gen->contactDepth[d_i][1] ) {
-                  mesh->verts[v_i][d_i] -=
-                     ((double)(vGrid->sizes[d_i] - 1 - center) /
-                      (double)gen->contactDepth[d_i][1]) *
-                     gen->contactGeom[d_i];
-               }
-            }
-            else {
-               mesh->verts[v_i][d_i] = leftCrd + (gen->contactDepth[d_i][0] ? gen->contactGeom[d_i] : 0.0) +
-                  ((double)(center - gen->contactDepth[d_i][0]) / 
-                   (double)(vGrid->sizes[d_i] - (gen->contactDepth[d_i][0] + gen->contactDepth[d_i][1]) - 1)) *
-                  ((rightCrd - leftCrd) - ((gen->contactDepth[d_i][1] ? 1.0 : 0.0) + (gen->contactDepth[d_i][0] ? 1.0 : 0.0)) * gen->contactGeom[d_i]);
-            }
-         }
-         else {
-
-               /* Blend coordinate. */
-               mesh->verts[v_i][d_i] = leftCrd + 
-                  (double)center * (rightCrd - leftCrd) / 
-                  (double)(vGrid->sizes[d_i] - 1);
-
-         }
-
-#if 0
-         /* Account for contact depth. */
-         if( d_i == 1 ) {
-            if( center > self->contactDepth ) {
-
-               /* If we're past contact elements, adjust center to be
-                  properly smoothed. */
-               center -= self->contactDepth;
-               inds[1] = self->contactDepth;
-               leftCrd = Mesh_GetVertex( mesh, Grid_Project( vGrid, inds ) )[1];
-
-               /* Blend coordinate. */
-               mesh->verts[v_i][d_i] = leftCrd + 
-                  (double)center * (rightCrd - leftCrd) / 
-                  (double)(vGrid->sizes[d_i] - self->contactDepth - 1);
-
-            }
-            else if( center < self->contactDepth ) {
-
-               /* If we're inside the contact depth smooth within the
-                  contact range. */
-               inds[1] = self->contactDepth;
-               rightCrd = Mesh_GetVertex( mesh, Grid_Project( vGrid, inds ) )[1];
-               mesh->verts[v_i][d_i] = leftCrd + 
-                  (double)center * (rightCrd - leftCrd) / 
-                  (double)self->contactDepth;
-
-            }
-         }
-         else {
-
-               /* Blend coordinate. */
-               mesh->verts[v_i][d_i] = leftCrd + 
-                  (double)center * (rightCrd - leftCrd) / 
-                  (double)(vGrid->sizes[d_i] - 1);
-
-         }
-#endif
-      }
-   }
-
-   /* Meddle with the top right corner. */
-   if( self->diffuseCorners ) {
-      int nodeIndex, innerIndex, inner2Index;
-      double /*grad,*/ *nodeVert, *innerVert, *inner2Vert;
-
-      inds[0] = vGrid->sizes[0] - 1;
-      inds[1] = vGrid->sizes[1] - 1;
-      nodeIndex = Grid_Project( vGrid, (unsigned*)inds );
-      nodeVert = Mesh_GetVertex( mesh, nodeIndex );
-      inds[0]--;
-      innerIndex = Grid_Project( vGrid, (unsigned*)inds );
-      innerVert = Mesh_GetVertex( mesh, innerIndex );
-      inds[0]--;
-      inner2Index = Grid_Project( vGrid, (unsigned*)inds );
-      inner2Vert = Mesh_GetVertex( mesh, inner2Index );
-
-/*
-      grad = (innerVert[1] - inner2Vert[1]) / (innerVert[0] - inner2Vert[0]);
-      nodeVert[1] = innerVert[1] + grad * (innerVert[1] - nodeVert[1]);
-*/
-      nodeVert[1] = innerVert[1] - (inner2Vert[1] - innerVert[1]);
-   }
-   else if( self->diffuseSurface ) {
-#if 0
-      Mat A;
-      Vec b, x;
-      KSP ksp;
-      int nodeIndex, nDofs;
-      double *delta;
-      double dt, sep;
-      double elMat[2][2], elVec[2], Ni[2], Nx[2], GNx[2], xi;
-      double jacDet, weightJacDet;
-      int nodeInds[2], rows[2];
-      double leftCrd, rightCrd;
-      double weight = 1.0;
-      int ii, jj, kk, ll;
-
-      nDofs = vGrid->sizes[0];
-      VecCreateSeq( PETSC_COMM_SELF, nDofs, &x );
-      VecDuplicate( x, &b );
-      MatCreateSeqAIJ( PETSC_COMM_SELF, nDofs, nDofs, 3, PETSC_NULL, &A );
-
-      inds[1] = vGrid->sizes[1] - 1;
-
-      for( ii = 0; ii < nDofs - 1; ii++ ) {
-
-         inds[0] = ii;
-         nodeInds[0] = Grid_Project( vGrid, inds );
-         inds[0]++;
-         nodeInds[1] = Grid_Project( vGrid, inds );
-
-         mesh->verts[nodeInds[0]][1] = (double)(ii*ii);
-         mesh->verts[nodeInds[1]][1] = (double)((ii+1)*(ii+1));
-
-         memset( elMat[0], 0, 4 * sizeof(double) );
-         memset( elVec, 0, 2 * sizeof(double) );
-
-         for( jj = 0; jj < 2; jj++ ) {
-
-            xi = (jj == 0) ? -0.57735026919 : 0.57735026919;
-            leftCrd = Mesh_GetVertex( self->mesh, nodeInds[0] )[0];
-            rightCrd = Mesh_GetVertex( self->mesh, nodeInds[1] )[0];
-            jacDet = (rightCrd - leftCrd) * 0.5;
-            weightJacDet = weight * jacDet;
-            Ni[0] = 0.5 * (1.0 - xi);
-            Ni[1] = 0.5 * (1.0 + xi);
-            Nx[0] = -0.5;
-            Nx[1] = 0.5;
-            GNx[0] = Nx[0] / jacDet;
-            GNx[1] = Nx[1] / jacDet;
-
-            for( kk = 0; kk < 2; kk++ ) {
-               for ( ll = 0 ; ll < 2; ll++ ) {
-                  elMat[kk][ll] += weightJacDet * Ni[kk] * Ni[ll];
-                  elVec[kk] += -weightJacDet * GNx[kk] * GNx[ll] * (double)nodeInds[ll] * 2.0; /** GNx[kk] * GNx[ll] *
-                                                       Mesh_GetVertex( mesh, nodeInds[ll] )[1];*/
-               }
-
-               if( kk == 0 ) {
-                  elVec[kk] += -1.0 * (GNx[0] * (double)nodeInds[0] * 2.0 + GNx[1] * (double)nodeInds[1] * 2.0);
-/*
-                  elVec[kk] += -1.0 * (GNx[0] * Mesh_GetVertex( mesh, nodeInds[0] )[1] +
-                                       GNx[1] * Mesh_GetVertex( mesh, nodeInds[1] )[1]);
-*/
-               }
-               else {
-                  elVec[kk] += 1.0 * (GNx[0] * (double)nodeInds[0] * 2.0 + GNx[1] * (double)nodeInds[1] * 2.0);
-/*
-                  elVec[kk] += 1.0 * (GNx[0] * Mesh_GetVertex( mesh, nodeInds[0] )[1] +
-                                      GNx[1] * Mesh_GetVertex( mesh, nodeInds[1] )[1]);
-*/
-               }
-            }
-         }
-
-         rows[0] = ii; rows[1] = ii + 1;
-         MatSetValues( A, 2, rows, 2, rows, elMat[0], ADD_VALUES );
-         VecSetValues( b, 2, rows, elVec, ADD_VALUES );
-
-      }
-
-      MatAssemblyBegin( A, MAT_FINAL_ASSEMBLY );
-      VecAssemblyBegin( b );
-      MatAssemblyEnd( A, MAT_FINAL_ASSEMBLY );
-      VecAssemblyEnd( b );
-
-      KSPCreate( PETSC_COMM_SELF, &ksp );
-      KSPSetOperators( ksp, A, A, DIFFERENT_NONZERO_PATTERN );
-      KSPSolve( ksp, b, x );
-
-      VecGetArray( x, &delta );
-      for( inds[0] = 0; inds[0] < vGrid->sizes[0]; inds[0]++ ) {
-         nodeIndex = Grid_Project( vGrid, inds );
-         mesh->verts[nodeIndex][1] -= self->diffusionCoef * self->ctx->dt * delta[inds[0]];
-      }
-      VecRestoreArray( x, &delta );
-
-      KSPDestroy( ksp );
-      MatDestroy( A );
-      VecDestroy( b );
-      VecDestroy( x );
-#endif
-
-
-      Mat A;
-      Vec b, x;
-      KSP ksp;
-      int cols[3], nDofs, nodeIndex;
-      double rhs, coef, *soln;
-      double matVals[3], vecVals[3];
-      double d, dt, sep;
-      int ii;
-
-      nDofs = vGrid->sizes[0];
-      VecCreateSeq( PETSC_COMM_SELF, nDofs, &x );
-      VecDuplicate( x, &b );
-      MatCreateSeqAIJ( PETSC_COMM_SELF, nDofs, nDofs, 3, PETSC_NULL, &A );
-
-      d = self->diffusionCoef;
-      dt = self->ctx->dt;
-      sep = Mesh_GetVertex( mesh, 1 )[0] - Mesh_GetVertex( mesh, 0 )[0];
-      coef = d * dt / (2.0 * (sep * sep));
-      matVals[0] = -coef; matVals[1] = 1.0 + 2.0 * coef; matVals[2] = -coef;
-      vecVals[0] = coef;  vecVals[1] = 1.0 - 2.0 * coef; vecVals[2] = coef;
-      inds[1] = vGrid->sizes[1] - 1;
-
-      for( ii = 0; ii < nDofs; ii++ ) {
-         cols[0] = ii - 1; cols[1] = ii; cols[2] = ii + 1;
-         if( ii == 0 ) {
-            MatSetValues( A, 1, &ii, 2, cols + 1, matVals + 1, ADD_VALUES );
-            MatSetValues( A, 1, &ii, 1, &ii, matVals, ADD_VALUES );
-         }
-         else if( ii == nDofs - 1 ) {
-            MatSetValues( A, 1, &ii, 2, cols, matVals, ADD_VALUES );
-            MatSetValues( A, 1, &ii, 1, &ii, matVals + 2, ADD_VALUES );
-         }
-         else
-            MatSetValues( A, 1, &ii, 3, cols, matVals, ADD_VALUES );
-
-         inds[0] = ii;
-         nodeIndex = Grid_Project( vGrid, (unsigned*)inds );
-         if( ii == 0 ) {
-            rhs = vecVals[0] * Mesh_GetVertex( mesh, nodeIndex + 1 )[1] +
-               vecVals[1] * Mesh_GetVertex( mesh, nodeIndex )[1] + 
-               vecVals[2] * Mesh_GetVertex( mesh, nodeIndex )[1];
-         }
-         else if( ii == nDofs - 1 ) {
-            rhs = vecVals[0] * Mesh_GetVertex( mesh, nodeIndex )[1] +
-               vecVals[1] * Mesh_GetVertex( mesh, nodeIndex )[1] + 
-               vecVals[2] * Mesh_GetVertex( mesh, nodeIndex - 1 )[1];
-         }
-         else {
-            rhs = vecVals[0] * Mesh_GetVertex( mesh, nodeIndex + 1 )[1] +
-               vecVals[1] * Mesh_GetVertex( mesh, nodeIndex )[1] + 
-               vecVals[2] * Mesh_GetVertex( mesh, nodeIndex - 1 )[1];
-         }
-         VecSetValues( b, 1, &ii, &rhs, ADD_VALUES );
-      }
-
-      MatAssemblyBegin( A, MAT_FINAL_ASSEMBLY );
-      VecAssemblyBegin( b );
-      MatAssemblyEnd( A, MAT_FINAL_ASSEMBLY );
-      VecAssemblyEnd( b );
-
-      KSPCreate( PETSC_COMM_SELF, &ksp );
-      KSPSetOperators( ksp, A, A, DIFFERENT_NONZERO_PATTERN );
-      KSPSolve( ksp, b, x );
-
-      VecGetArray( x, &soln );
-      for( inds[0] = 0; inds[0] < (int)(vGrid->sizes[0]); inds[0]++ ) {
-         nodeIndex = Grid_Project( vGrid, (unsigned*)inds );
-         mesh->verts[nodeIndex][1] = soln[inds[0]];
-      }
-      VecRestoreArray( x, &soln );
-
-      KSPDestroy( ksp );
-      MatDestroy( A );
-      VecDestroy( b );
-      VecDestroy( x );
-
-
-#if 0
-      int nodeIndex, inds[2];
-      double *newHeights, sep, d, dt;
-      int ii;
-
-      newHeights = AllocArray( double, vGrid->sizes[0] );
-      d = self->diffusionCoef;
-      dt = self->ctx->dt;
-
-      inds[1] = vGrid->sizes[1] - 1;
-      inds[0] = 0;
-      nodeIndex = Grid_Project( vGrid, inds );
-      sep = Mesh_GetVertex( mesh, nodeIndex + 1 )[0] - Mesh_GetVertex( mesh, nodeIndex )[0];
-      newHeights[0] = Mesh_GetVertex( mesh, nodeIndex )[1] -
-         2.0 * Mesh_GetVertex( mesh, nodeIndex + 1 )[1] + 
-         Mesh_GetVertex( mesh, nodeIndex + 2 )[1];
-      newHeights[0] /= sep * sep;
-      newHeights[0] *= -d;
-
-      for( inds[0] = 1; inds[0] < vGrid->sizes[0] - 1; inds[0]++ ) {
-         nodeIndex = Grid_Project( vGrid, inds );
-         sep = (Mesh_GetVertex( mesh, nodeIndex + 1 )[0] - Mesh_GetVertex( mesh, nodeIndex - 1)[0]) * 0.5;
-         newHeights[inds[0]] = Mesh_GetVertex( mesh, nodeIndex - 1 )[1] -
-            2.0 * Mesh_GetVertex( mesh, nodeIndex )[1] + 
-            Mesh_GetVertex( mesh, nodeIndex + 1 )[1];
-         newHeights[inds[0]] /= sep * sep;
-         newHeights[inds[0]] *= -d;
-      }
-
-      nodeIndex = Grid_Project( vGrid, inds );
-      sep = -1.0 * (Mesh_GetVertex( mesh, nodeIndex - 1 )[0] - Mesh_GetVertex( mesh, nodeIndex )[0]);
-      newHeights[inds[0]] = Mesh_GetVertex( mesh, nodeIndex - 2 )[1] -
-         2.0 * Mesh_GetVertex( mesh, nodeIndex - 1 )[1] + 
-         Mesh_GetVertex( mesh, nodeIndex )[1];
-      newHeights[inds[0]] /= sep * sep;
-      newHeights[inds[0]] *= -d;
-
-      for( inds[0] = 0; inds[0] < vGrid->sizes[0]; inds[0]++ ) {
-         nodeIndex = Grid_Project( vGrid, inds );
-         mesh->verts[nodeIndex][1] += newHeights[inds[0]] * dt;
-      }
-
-      MemFree( newHeights );
-#endif
-   }
-
-   Class_Free( self, inds );
-   Mesh_Sync( mesh );
-   Mesh_DeformationUpdate( mesh );
-}
-
-void RegularRemesher_Build( void* _self ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-   Mesh* mesh;
-   Sync* meshSync;
-   const Decomp* meshDecomp;
-   ISet* wallSet;
-   Grid* vGrid;
-   int *inds, ind;
-   int nDims, nVerts;
-   int nRems, *rems;
-   int d_i, w_i, v_i;
-
-   mesh = self->mesh;
-   Stg_Component_Build( mesh, NULL, False );
-   meshSync = Mesh_GetSync( mesh, (MeshTopology_Dim)0 );
-   meshDecomp = Sync_GetDecomp( meshSync );
-   vGrid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-   nDims = Mesh_GetDimSize( mesh );
-   self->nDims = nDims;
-   nVerts = Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 );
-   inds = Class_Array( self, int, nDims );
-
-   if( !self->syncs ) {
-      self->syncs = Class_Array( self, Sync*, nDims );
-      self->crds = Class_Array( self, double*, nDims );
-      self->nWallVerts = Class_Array( self, int*, nDims );
-      self->wallVerts = Class_Array( self, int**, nDims );
-      self->wallCrds = Class_Array( self, double**, nDims );
-      for( d_i = 0; d_i < nDims; d_i++ ) {
-	 self->nWallVerts[d_i] = Class_Array( self, int, 2 );
-	 self->wallVerts[d_i] = Class_Array( self, int*, 2 );
-	 self->wallCrds[d_i] = Class_Array( self, double*, 2 );
-	 memset( self->nWallVerts[d_i], 0, 2 * sizeof(int) );
-	 memset( self->wallVerts[d_i], 0, 2 * sizeof(int*) );
-	 memset( self->wallCrds[d_i], 0, 2 * sizeof(double*) );
-      }
-      memset( self->syncs, 0, nDims * sizeof(Sync*) );
-      memset( self->crds, 0, nDims * sizeof(double*) );
-   }
-
-   wallSet = ISet_New();
-   ISet_SetMaxSize( wallSet, nVerts );
-   for( d_i = 0; d_i < nDims; d_i++ ) {
-      for( w_i = 0; w_i < 2; w_i++ ) {
-	 Class_Free( self, self->wallVerts[d_i][w_i] );
-	 Class_Free( self, self->wallCrds[d_i][w_i] );
-	 if( !ISet_Has( self->staticWalls[w_i], d_i ) ) {
-	    self->nWallVerts[d_i][w_i] = 0;
-	    self->wallVerts[d_i][w_i] = NULL;
-	    self->wallCrds[d_i][w_i] = NULL;
-	    continue;
-	 }
-
-	 for( v_i = 0; v_i < nVerts; v_i++ ) {
-	    ind = Sync_DomainToGlobal( meshSync, v_i );
-	    Grid_Lift( vGrid, ind, (unsigned*)inds );
-	    if( (w_i == 0 && inds[d_i] == 0) || 
-		(w_i == 1 && inds[d_i] == (int)(vGrid->sizes[d_i] - 1)) )
-	    {
-	       ISet_Insert( wallSet, v_i );
-	    }
-	 }
-
-	 self->nWallVerts[d_i][w_i] = ISet_GetSize( wallSet );
-	 self->wallVerts[d_i][w_i] = Class_Array( 
-	    self, int, self->nWallVerts[d_i][w_i] );
-	 self->wallCrds[d_i][w_i] = Class_Array( 
-	    self, double, self->nWallVerts[d_i][w_i] );
-	 ISet_GetArray( wallSet, self->wallVerts[d_i][w_i] );
-	 ISet_Clear( wallSet );
-	 for( v_i = 0; v_i < self->nWallVerts[d_i][w_i]; v_i++ ) {
-	    self->wallCrds[d_i][w_i][v_i] = 
-	       mesh->verts[self->wallVerts[d_i][w_i][v_i]][d_i];
-	 }
-      }
-   }
-
-   for( d_i = 0; d_i < nDims; d_i++ ) {
-      NewClass_RemoveRef( self->syncs[d_i] );
-      Class_Free( self, self->crds[d_i] );
-      if( !ISet_Has( self->remeshDims, d_i ) ) {
-	 self->syncs[d_i] = NULL;
-	 self->crds[d_i] = NULL;
-	 continue;
-      }
-
-      for( v_i = 0; v_i < nVerts; v_i++ ) {
-	 ind = Sync_DomainToGlobal( meshSync, v_i );
-	 Grid_Lift( vGrid, ind, (unsigned*)inds );
-	 inds[d_i] = 0;
-	 ind = Grid_Project( vGrid, (unsigned*)inds );
-	 if( !Sync_TryGlobalToDomain( meshSync, ind, &ind ) )
-	    ISet_TryInsert( wallSet, ind );
-
-	 inds[d_i] = vGrid->sizes[d_i] - 1;
-	 ind = Grid_Project( vGrid, (unsigned*)inds );
-	 if( !Sync_TryGlobalToDomain( meshSync, ind, &ind ) )
-	    ISet_TryInsert( wallSet, ind );
-      }
-
-      nRems = ISet_GetSize( wallSet );
-      rems = Class_Array( self, int, nRems );
-      ISet_GetArray( wallSet, rems );
-      ISet_Clear( wallSet );
-      self->syncs[d_i] = Sync_New();
-      NewClass_AddRef( self->syncs[d_i] );
-      Sync_SetDecomp( self->syncs[d_i], meshDecomp );
-      Sync_FindRemotes( self->syncs[d_i], nRems, rems );
-      Class_Free( self, rems );
-      self->crds[d_i] = Class_Array( self, double, nRems );
-   }
-
-   NewClass_Delete( wallSet );
-
-#if 0
-   /* If we have some contact depth, copy the relevant vertex offsets. */
-   if( self->contactDepth > 0 ) {
-      int curInd;
-      Grid* grid;
-      int ii;
-
-      /* Get the vertex grid from the mesh. */
-      grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
-      assert( grid );
-
-      /* Allocate for all the contact vertices. */
-      nVerts = grid->sizes[0];
-      if( nDims == 3 ) nVerts *= grid->sizes[1];
-      self->contactVerts = MemArray( double, nVerts, "" );
-
-      /* Copy upper strip. */
-      nVerts = Mesh_GetLocalSize( mesh, 0 );
-      curInd = 0;
-      for( ii = 0; ii < nVerts; ii++ ) {
-         Grid_Lift( grid, ii, inds );
-         if( inds[1] != self->contactDepth ) continue;
-
-	 /* If we were given a contact size, insert that instead. */
-	 if( self->contactSize > 0.0 )
-	   self->contactVerts[curInd++] = self->contactSize;
-	 else
-	   self->contactVerts[curInd++] = Mesh_GetVertex( mesh, ii )[1];
-      }
-
-   }
-#endif
-
-   Class_Free( self, inds );
-}
-
-void RegularRemesher_SetRemeshState( void* _self, int dim, Bool state ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-
-   if( state )
-      ISet_TryInsert( self->remeshDims, dim );
-   else if( ISet_Has( self->remeshDims, dim ) )
-      ISet_Remove( self->remeshDims, dim );
-}
-
-void RegularRemesher_SetStaticWall( void* _self, int dim, int wall, Bool state ) {
-   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
-
-   if( state )
-      ISet_TryInsert( self->staticWalls[wall], dim );
-   else if( ISet_Has( self->staticWalls[wall], dim ) )
-      ISet_Remove( self->staticWalls[wall], dim );
-}
-
-#endif
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/RegularRemesher.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/RegularRemesher.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,729 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 
+** 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: RegularRemesher.c 3952 2007-01-09 06:24:06Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifdef HAVE_PETSC
+
+#include <stdlib.h>
+#include <string.h>
+#include <petsc.h>
+#include <petscvec.h>
+#include <petscmat.h>
+#include <petscksp.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "NewRemesher.h"
+#include "RegularRemesher.h"
+#include "StGermain/Base/Foundation/ClassDef.h"
+
+
+void _RegularRemesher_Init( void* _self ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+
+   _NewRemesher_Init( self );
+   self->remeshDims = ISet_New();
+   self->staticWalls = Class_Array( self, ISet*, 2 );
+   self->staticWalls[0] = ISet_New();
+   self->staticWalls[1] = ISet_New();
+   ISet_SetMaxSize( self->remeshDims, 10 );
+   ISet_SetMaxSize( self->staticWalls[0], 10 );
+   ISet_SetMaxSize( self->staticWalls[1], 10 );
+   self->syncs = NULL;
+   self->crds = NULL;
+   self->nWallVerts = NULL;
+   self->wallVerts = NULL;
+   self->wallCrds = NULL;
+}
+
+void _RegularRemesher_Copy( void* _self, const void* _op ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+   const RegularRemesher* op = Class_Cast( _op, RegularRemesher );
+
+   _NewRemesher_Copy( self, op );
+   /* TODO */
+}
+
+void _RegularRemesher_Destruct( void* _self ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+   int nDims;
+   int d_i;
+
+   if( self->syncs ) {
+      nDims = self->nDims;
+      for( d_i = 0; d_i < nDims; d_i++ ) {
+   	 NewClass_RemoveRef( self->syncs[d_i] );
+	 Class_Free( self, self->crds[d_i] );
+	 Class_Free( self, self->nWallVerts[d_i] );
+	 Class_Free( self, self->wallVerts[d_i][0] );
+	 Class_Free( self, self->wallVerts[d_i][1] );
+	 Class_Free( self, self->wallVerts[d_i] );
+	 Class_Free( self, self->wallCrds[d_i][0] );
+	 Class_Free( self, self->wallCrds[d_i][1] );
+	 Class_Free( self, self->wallCrds[d_i] );
+      }
+      Class_Free( self, self->syncs );
+      Class_Free( self, self->crds );
+      Class_Free( self, self->nWallVerts );
+      Class_Free( self, self->wallVerts );
+      Class_Free( self, self->wallCrds );
+   }
+   NewClass_Delete( self->remeshDims );
+   NewClass_Delete( self->staticWalls[0] );
+   NewClass_Delete( self->staticWalls[1] );
+   Class_Free( self, self->staticWalls );
+   _NewClass_Destruct( self );
+}
+
+void _RegularRemesher_Print( const void* _self, Stream* stream ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+
+   _NewRemesher_Print( self, stream );
+}
+
+void _RegularRemesher_Remesh( void* _self ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+   Mesh* mesh;
+   Grid *vGrid;
+   Sync* meshSync;
+   int nDims, nVerts;
+   int center, ind, *inds;
+   double leftCrd, rightCrd;
+   CartesianGenerator* gen;
+   int d_i, v_i, w_i;
+
+   assert( self->mesh );
+
+   mesh = self->mesh;
+   meshSync = Mesh_GetSync( mesh, (MeshTopology_Dim)0 );
+   nDims = Mesh_GetDimSize( mesh );
+   nVerts = Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 );
+   vGrid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+   inds = Class_Array( self, int, nDims );
+
+   for( d_i = 0; d_i < nDims; d_i++ ) {
+      for( w_i = 0; w_i < 2; w_i++ ) {
+	 if( !ISet_Has( self->staticWalls[w_i], d_i ) )
+	    continue;
+	 for( v_i = 0; v_i < self->nWallVerts[d_i][w_i]; v_i++ ) {
+	    mesh->verts[self->wallVerts[d_i][w_i][v_i]][d_i] = 
+	       self->wallCrds[d_i][w_i][v_i];
+	 }
+      }
+   }
+
+   /* If we have a contact depth set we'll need to manipulate the boundaries
+      a little. */
+   gen = (CartesianGenerator*)self->mesh->generator;
+   if( strcmp( gen->type, CartesianGenerator_Type ) )
+      gen = NULL;
+   if( gen && (gen->contactDepth[0][0] || gen->contactDepth[0][1] ||
+               gen->contactDepth[1][0] || gen->contactDepth[1][1] ||
+               gen->contactDepth[2][0] || gen->contactDepth[2][1]) )
+   {
+      /*int curInd;*/
+      int /*ii,*/ d_j;
+
+#if 0
+      /* Reset static depths. */
+      curInd = 0;
+      for( ii = 0; ii < nVerts; ii++ ) {
+         Grid_Lift( vGrid, ii, inds );
+         if( inds[1] != self->contactDepth ) continue;
+         Mesh_GetVertex( mesh, ii )[1] = self->contactVerts[curInd++];
+      }
+#endif
+
+      /* Also handle contact element boundaries. */
+      for( d_i = 0; d_i < nDims; d_i++ ) {
+         for( v_i = 0; v_i < nVerts; v_i++ ) {
+            ind = Sync_DomainToGlobal( meshSync, v_i );
+            Grid_Lift( vGrid, ind, (unsigned*)inds );
+            center = inds[d_i];
+            if( center == 0 || center == (int)(vGrid->sizes[d_i] - 1) ) {
+
+               /* If we're inside the contact depth range, we need to make
+                  sure the side coordinates are aligned. */
+	       if( d_i == 0 ) {
+		  d_j = 1;
+	       }
+               else if( d_i == 1 ) {
+		  d_j = 0;
+	       }
+               else if( d_i == 2 ) {
+		  d_j = 1;
+		  // TODO
+		  abort();
+	       }
+               if( inds[d_j] < gen->contactDepth[d_j][0] )
+                  inds[d_j] = gen->contactDepth[d_j][0];
+               else if( inds[d_j] > (int)(vGrid->sizes[d_j] - gen->contactDepth[d_j][1] - 1 ))
+                  inds[d_j] = vGrid->sizes[d_j] - gen->contactDepth[d_j][1] - 1;
+               Mesh_GetVertex( mesh, v_i )[d_i] =
+                 Mesh_GetVertex( mesh, Grid_Project( vGrid, (unsigned*)inds ) )[d_i];
+            }
+         }
+      }
+   }
+
+   for( d_i = 0; d_i < nDims; d_i++ ) {
+      if( !ISet_Has( self->remeshDims, d_i ) )
+	 continue;
+
+      Sync_SyncArray( self->syncs[d_i], 
+		      mesh->verts[0] + d_i, nDims * sizeof(double), 
+		      self->crds[d_i], sizeof(double), 
+		      sizeof(double) );
+
+      for( v_i = 0; v_i < nVerts; v_i++ ) {
+	 ind = Sync_DomainToGlobal( meshSync, v_i );
+	 Grid_Lift( vGrid, ind, (unsigned*)inds );
+	 center = inds[d_i];
+	 if( center == 0 || center == (int)(vGrid->sizes[d_i] - 1 ))
+	    continue;
+
+	 inds[d_i] = 0;
+	 ind = Grid_Project( vGrid, (unsigned*)inds );
+	 ind = Sync_GlobalToDomain( self->syncs[d_i], ind );
+	 if( ind >= nVerts )
+	    leftCrd = self->crds[d_i][ind - nVerts];
+	 else
+	    leftCrd = Mesh_GetVertex( mesh, ind)[d_i];
+
+	 inds[d_i] = vGrid->sizes[d_i] - 1;
+	 ind = Grid_Project( vGrid, (unsigned*)inds );
+	 ind = Sync_GlobalToDomain( self->syncs[d_i], ind );
+	 if( ind >= nVerts )
+	    rightCrd = self->crds[d_i][ind - nVerts];
+	 else
+	    rightCrd = Mesh_GetVertex( mesh, ind)[d_i];
+
+         /* Do interpolation. */
+         if( gen ) {
+            if( center <= gen->contactDepth[d_i][0] ) {
+               mesh->verts[v_i][d_i] = leftCrd;
+               if( gen->contactDepth[d_i][0] ) {
+                  mesh->verts[v_i][d_i] +=
+                     ((double)center / (double)gen->contactDepth[d_i][0]) *
+                     gen->contactGeom[d_i];
+               }
+            }
+            else if( center >= (int)(vGrid->sizes[d_i] - gen->contactDepth[d_i][1] - 1 )) {
+               mesh->verts[v_i][d_i] = rightCrd;
+               if( gen->contactDepth[d_i][1] ) {
+                  mesh->verts[v_i][d_i] -=
+                     ((double)(vGrid->sizes[d_i] - 1 - center) /
+                      (double)gen->contactDepth[d_i][1]) *
+                     gen->contactGeom[d_i];
+               }
+            }
+            else {
+               mesh->verts[v_i][d_i] = leftCrd + (gen->contactDepth[d_i][0] ? gen->contactGeom[d_i] : 0.0) +
+                  ((double)(center - gen->contactDepth[d_i][0]) / 
+                   (double)(vGrid->sizes[d_i] - (gen->contactDepth[d_i][0] + gen->contactDepth[d_i][1]) - 1)) *
+                  ((rightCrd - leftCrd) - ((gen->contactDepth[d_i][1] ? 1.0 : 0.0) + (gen->contactDepth[d_i][0] ? 1.0 : 0.0)) * gen->contactGeom[d_i]);
+            }
+         }
+         else {
+
+               /* Blend coordinate. */
+               mesh->verts[v_i][d_i] = leftCrd + 
+                  (double)center * (rightCrd - leftCrd) / 
+                  (double)(vGrid->sizes[d_i] - 1);
+
+         }
+
+#if 0
+         /* Account for contact depth. */
+         if( d_i == 1 ) {
+            if( center > self->contactDepth ) {
+
+               /* If we're past contact elements, adjust center to be
+                  properly smoothed. */
+               center -= self->contactDepth;
+               inds[1] = self->contactDepth;
+               leftCrd = Mesh_GetVertex( mesh, Grid_Project( vGrid, inds ) )[1];
+
+               /* Blend coordinate. */
+               mesh->verts[v_i][d_i] = leftCrd + 
+                  (double)center * (rightCrd - leftCrd) / 
+                  (double)(vGrid->sizes[d_i] - self->contactDepth - 1);
+
+            }
+            else if( center < self->contactDepth ) {
+
+               /* If we're inside the contact depth smooth within the
+                  contact range. */
+               inds[1] = self->contactDepth;
+               rightCrd = Mesh_GetVertex( mesh, Grid_Project( vGrid, inds ) )[1];
+               mesh->verts[v_i][d_i] = leftCrd + 
+                  (double)center * (rightCrd - leftCrd) / 
+                  (double)self->contactDepth;
+
+            }
+         }
+         else {
+
+               /* Blend coordinate. */
+               mesh->verts[v_i][d_i] = leftCrd + 
+                  (double)center * (rightCrd - leftCrd) / 
+                  (double)(vGrid->sizes[d_i] - 1);
+
+         }
+#endif
+      }
+   }
+
+   /* Meddle with the top right corner. */
+   if( self->diffuseCorners ) {
+      int nodeIndex, innerIndex, inner2Index;
+      double /*grad,*/ *nodeVert, *innerVert, *inner2Vert;
+
+      inds[0] = vGrid->sizes[0] - 1;
+      inds[1] = vGrid->sizes[1] - 1;
+      nodeIndex = Grid_Project( vGrid, (unsigned*)inds );
+      nodeVert = Mesh_GetVertex( mesh, nodeIndex );
+      inds[0]--;
+      innerIndex = Grid_Project( vGrid, (unsigned*)inds );
+      innerVert = Mesh_GetVertex( mesh, innerIndex );
+      inds[0]--;
+      inner2Index = Grid_Project( vGrid, (unsigned*)inds );
+      inner2Vert = Mesh_GetVertex( mesh, inner2Index );
+
+/*
+      grad = (innerVert[1] - inner2Vert[1]) / (innerVert[0] - inner2Vert[0]);
+      nodeVert[1] = innerVert[1] + grad * (innerVert[1] - nodeVert[1]);
+*/
+      nodeVert[1] = innerVert[1] - (inner2Vert[1] - innerVert[1]);
+   }
+   else if( self->diffuseSurface ) {
+#if 0
+      Mat A;
+      Vec b, x;
+      KSP ksp;
+      int nodeIndex, nDofs;
+      double *delta;
+      double dt, sep;
+      double elMat[2][2], elVec[2], Ni[2], Nx[2], GNx[2], xi;
+      double jacDet, weightJacDet;
+      int nodeInds[2], rows[2];
+      double leftCrd, rightCrd;
+      double weight = 1.0;
+      int ii, jj, kk, ll;
+
+      nDofs = vGrid->sizes[0];
+      VecCreateSeq( PETSC_COMM_SELF, nDofs, &x );
+      VecDuplicate( x, &b );
+      MatCreateSeqAIJ( PETSC_COMM_SELF, nDofs, nDofs, 3, PETSC_NULL, &A );
+
+      inds[1] = vGrid->sizes[1] - 1;
+
+      for( ii = 0; ii < nDofs - 1; ii++ ) {
+
+         inds[0] = ii;
+         nodeInds[0] = Grid_Project( vGrid, inds );
+         inds[0]++;
+         nodeInds[1] = Grid_Project( vGrid, inds );
+
+         mesh->verts[nodeInds[0]][1] = (double)(ii*ii);
+         mesh->verts[nodeInds[1]][1] = (double)((ii+1)*(ii+1));
+
+         memset( elMat[0], 0, 4 * sizeof(double) );
+         memset( elVec, 0, 2 * sizeof(double) );
+
+         for( jj = 0; jj < 2; jj++ ) {
+
+            xi = (jj == 0) ? -0.57735026919 : 0.57735026919;
+            leftCrd = Mesh_GetVertex( self->mesh, nodeInds[0] )[0];
+            rightCrd = Mesh_GetVertex( self->mesh, nodeInds[1] )[0];
+            jacDet = (rightCrd - leftCrd) * 0.5;
+            weightJacDet = weight * jacDet;
+            Ni[0] = 0.5 * (1.0 - xi);
+            Ni[1] = 0.5 * (1.0 + xi);
+            Nx[0] = -0.5;
+            Nx[1] = 0.5;
+            GNx[0] = Nx[0] / jacDet;
+            GNx[1] = Nx[1] / jacDet;
+
+            for( kk = 0; kk < 2; kk++ ) {
+               for ( ll = 0 ; ll < 2; ll++ ) {
+                  elMat[kk][ll] += weightJacDet * Ni[kk] * Ni[ll];
+                  elVec[kk] += -weightJacDet * GNx[kk] * GNx[ll] * (double)nodeInds[ll] * 2.0; /** GNx[kk] * GNx[ll] *
+                                                       Mesh_GetVertex( mesh, nodeInds[ll] )[1];*/
+               }
+
+               if( kk == 0 ) {
+                  elVec[kk] += -1.0 * (GNx[0] * (double)nodeInds[0] * 2.0 + GNx[1] * (double)nodeInds[1] * 2.0);
+/*
+                  elVec[kk] += -1.0 * (GNx[0] * Mesh_GetVertex( mesh, nodeInds[0] )[1] +
+                                       GNx[1] * Mesh_GetVertex( mesh, nodeInds[1] )[1]);
+*/
+               }
+               else {
+                  elVec[kk] += 1.0 * (GNx[0] * (double)nodeInds[0] * 2.0 + GNx[1] * (double)nodeInds[1] * 2.0);
+/*
+                  elVec[kk] += 1.0 * (GNx[0] * Mesh_GetVertex( mesh, nodeInds[0] )[1] +
+                                      GNx[1] * Mesh_GetVertex( mesh, nodeInds[1] )[1]);
+*/
+               }
+            }
+         }
+
+         rows[0] = ii; rows[1] = ii + 1;
+         MatSetValues( A, 2, rows, 2, rows, elMat[0], ADD_VALUES );
+         VecSetValues( b, 2, rows, elVec, ADD_VALUES );
+
+      }
+
+      MatAssemblyBegin( A, MAT_FINAL_ASSEMBLY );
+      VecAssemblyBegin( b );
+      MatAssemblyEnd( A, MAT_FINAL_ASSEMBLY );
+      VecAssemblyEnd( b );
+
+      KSPCreate( PETSC_COMM_SELF, &ksp );
+      KSPSetOperators( ksp, A, A, DIFFERENT_NONZERO_PATTERN );
+      KSPSolve( ksp, b, x );
+
+      VecGetArray( x, &delta );
+      for( inds[0] = 0; inds[0] < vGrid->sizes[0]; inds[0]++ ) {
+         nodeIndex = Grid_Project( vGrid, inds );
+         mesh->verts[nodeIndex][1] -= self->diffusionCoef * self->ctx->dt * delta[inds[0]];
+      }
+      VecRestoreArray( x, &delta );
+
+      KSPDestroy( ksp );
+      MatDestroy( A );
+      VecDestroy( b );
+      VecDestroy( x );
+#endif
+
+
+      Mat A;
+      Vec b, x;
+      KSP ksp;
+      int cols[3], nDofs, nodeIndex;
+      double rhs, coef, *soln;
+      double matVals[3], vecVals[3];
+      double d, dt, sep;
+      int ii;
+
+      nDofs = vGrid->sizes[0];
+      VecCreateSeq( PETSC_COMM_SELF, nDofs, &x );
+      VecDuplicate( x, &b );
+      MatCreateSeqAIJ( PETSC_COMM_SELF, nDofs, nDofs, 3, PETSC_NULL, &A );
+
+      d = self->diffusionCoef;
+      dt = self->ctx->dt;
+      sep = Mesh_GetVertex( mesh, 1 )[0] - Mesh_GetVertex( mesh, 0 )[0];
+      coef = d * dt / (2.0 * (sep * sep));
+      matVals[0] = -coef; matVals[1] = 1.0 + 2.0 * coef; matVals[2] = -coef;
+      vecVals[0] = coef;  vecVals[1] = 1.0 - 2.0 * coef; vecVals[2] = coef;
+      inds[1] = vGrid->sizes[1] - 1;
+
+      for( ii = 0; ii < nDofs; ii++ ) {
+         cols[0] = ii - 1; cols[1] = ii; cols[2] = ii + 1;
+         if( ii == 0 ) {
+            MatSetValues( A, 1, &ii, 2, cols + 1, matVals + 1, ADD_VALUES );
+            MatSetValues( A, 1, &ii, 1, &ii, matVals, ADD_VALUES );
+         }
+         else if( ii == nDofs - 1 ) {
+            MatSetValues( A, 1, &ii, 2, cols, matVals, ADD_VALUES );
+            MatSetValues( A, 1, &ii, 1, &ii, matVals + 2, ADD_VALUES );
+         }
+         else
+            MatSetValues( A, 1, &ii, 3, cols, matVals, ADD_VALUES );
+
+         inds[0] = ii;
+         nodeIndex = Grid_Project( vGrid, (unsigned*)inds );
+         if( ii == 0 ) {
+            rhs = vecVals[0] * Mesh_GetVertex( mesh, nodeIndex + 1 )[1] +
+               vecVals[1] * Mesh_GetVertex( mesh, nodeIndex )[1] + 
+               vecVals[2] * Mesh_GetVertex( mesh, nodeIndex )[1];
+         }
+         else if( ii == nDofs - 1 ) {
+            rhs = vecVals[0] * Mesh_GetVertex( mesh, nodeIndex )[1] +
+               vecVals[1] * Mesh_GetVertex( mesh, nodeIndex )[1] + 
+               vecVals[2] * Mesh_GetVertex( mesh, nodeIndex - 1 )[1];
+         }
+         else {
+            rhs = vecVals[0] * Mesh_GetVertex( mesh, nodeIndex + 1 )[1] +
+               vecVals[1] * Mesh_GetVertex( mesh, nodeIndex )[1] + 
+               vecVals[2] * Mesh_GetVertex( mesh, nodeIndex - 1 )[1];
+         }
+         VecSetValues( b, 1, &ii, &rhs, ADD_VALUES );
+      }
+
+      MatAssemblyBegin( A, MAT_FINAL_ASSEMBLY );
+      VecAssemblyBegin( b );
+      MatAssemblyEnd( A, MAT_FINAL_ASSEMBLY );
+      VecAssemblyEnd( b );
+
+      KSPCreate( PETSC_COMM_SELF, &ksp );
+      KSPSetOperators( ksp, A, A, DIFFERENT_NONZERO_PATTERN );
+      KSPSolve( ksp, b, x );
+
+      VecGetArray( x, &soln );
+      for( inds[0] = 0; inds[0] < (int)(vGrid->sizes[0]); inds[0]++ ) {
+         nodeIndex = Grid_Project( vGrid, (unsigned*)inds );
+         mesh->verts[nodeIndex][1] = soln[inds[0]];
+      }
+      VecRestoreArray( x, &soln );
+
+      KSPDestroy( ksp );
+      MatDestroy( A );
+      VecDestroy( b );
+      VecDestroy( x );
+
+
+#if 0
+      int nodeIndex, inds[2];
+      double *newHeights, sep, d, dt;
+      int ii;
+
+      newHeights = AllocArray( double, vGrid->sizes[0] );
+      d = self->diffusionCoef;
+      dt = self->ctx->dt;
+
+      inds[1] = vGrid->sizes[1] - 1;
+      inds[0] = 0;
+      nodeIndex = Grid_Project( vGrid, inds );
+      sep = Mesh_GetVertex( mesh, nodeIndex + 1 )[0] - Mesh_GetVertex( mesh, nodeIndex )[0];
+      newHeights[0] = Mesh_GetVertex( mesh, nodeIndex )[1] -
+         2.0 * Mesh_GetVertex( mesh, nodeIndex + 1 )[1] + 
+         Mesh_GetVertex( mesh, nodeIndex + 2 )[1];
+      newHeights[0] /= sep * sep;
+      newHeights[0] *= -d;
+
+      for( inds[0] = 1; inds[0] < vGrid->sizes[0] - 1; inds[0]++ ) {
+         nodeIndex = Grid_Project( vGrid, inds );
+         sep = (Mesh_GetVertex( mesh, nodeIndex + 1 )[0] - Mesh_GetVertex( mesh, nodeIndex - 1)[0]) * 0.5;
+         newHeights[inds[0]] = Mesh_GetVertex( mesh, nodeIndex - 1 )[1] -
+            2.0 * Mesh_GetVertex( mesh, nodeIndex )[1] + 
+            Mesh_GetVertex( mesh, nodeIndex + 1 )[1];
+         newHeights[inds[0]] /= sep * sep;
+         newHeights[inds[0]] *= -d;
+      }
+
+      nodeIndex = Grid_Project( vGrid, inds );
+      sep = -1.0 * (Mesh_GetVertex( mesh, nodeIndex - 1 )[0] - Mesh_GetVertex( mesh, nodeIndex )[0]);
+      newHeights[inds[0]] = Mesh_GetVertex( mesh, nodeIndex - 2 )[1] -
+         2.0 * Mesh_GetVertex( mesh, nodeIndex - 1 )[1] + 
+         Mesh_GetVertex( mesh, nodeIndex )[1];
+      newHeights[inds[0]] /= sep * sep;
+      newHeights[inds[0]] *= -d;
+
+      for( inds[0] = 0; inds[0] < vGrid->sizes[0]; inds[0]++ ) {
+         nodeIndex = Grid_Project( vGrid, inds );
+         mesh->verts[nodeIndex][1] += newHeights[inds[0]] * dt;
+      }
+
+      MemFree( newHeights );
+#endif
+   }
+
+   Class_Free( self, inds );
+   Mesh_Sync( mesh );
+   Mesh_DeformationUpdate( mesh );
+}
+
+void RegularRemesher_Build( void* _self ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+   Mesh* mesh;
+   Sync* meshSync;
+   const Decomp* meshDecomp;
+   ISet* wallSet;
+   Grid* vGrid;
+   int *inds, ind;
+   int nDims, nVerts;
+   int nRems, *rems;
+   int d_i, w_i, v_i;
+
+   mesh = self->mesh;
+   Stg_Component_Build( mesh, NULL, False );
+   meshSync = Mesh_GetSync( mesh, (MeshTopology_Dim)0 );
+   meshDecomp = Sync_GetDecomp( meshSync );
+   vGrid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+   nDims = Mesh_GetDimSize( mesh );
+   self->nDims = nDims;
+   nVerts = Mesh_GetLocalSize( mesh, (MeshTopology_Dim)0 );
+   inds = Class_Array( self, int, nDims );
+
+   if( !self->syncs ) {
+      self->syncs = Class_Array( self, Sync*, nDims );
+      self->crds = Class_Array( self, double*, nDims );
+      self->nWallVerts = Class_Array( self, int*, nDims );
+      self->wallVerts = Class_Array( self, int**, nDims );
+      self->wallCrds = Class_Array( self, double**, nDims );
+      for( d_i = 0; d_i < nDims; d_i++ ) {
+	 self->nWallVerts[d_i] = Class_Array( self, int, 2 );
+	 self->wallVerts[d_i] = Class_Array( self, int*, 2 );
+	 self->wallCrds[d_i] = Class_Array( self, double*, 2 );
+	 memset( self->nWallVerts[d_i], 0, 2 * sizeof(int) );
+	 memset( self->wallVerts[d_i], 0, 2 * sizeof(int*) );
+	 memset( self->wallCrds[d_i], 0, 2 * sizeof(double*) );
+      }
+      memset( self->syncs, 0, nDims * sizeof(Sync*) );
+      memset( self->crds, 0, nDims * sizeof(double*) );
+   }
+
+   wallSet = ISet_New();
+   ISet_SetMaxSize( wallSet, nVerts );
+   for( d_i = 0; d_i < nDims; d_i++ ) {
+      for( w_i = 0; w_i < 2; w_i++ ) {
+	 Class_Free( self, self->wallVerts[d_i][w_i] );
+	 Class_Free( self, self->wallCrds[d_i][w_i] );
+	 if( !ISet_Has( self->staticWalls[w_i], d_i ) ) {
+	    self->nWallVerts[d_i][w_i] = 0;
+	    self->wallVerts[d_i][w_i] = NULL;
+	    self->wallCrds[d_i][w_i] = NULL;
+	    continue;
+	 }
+
+	 for( v_i = 0; v_i < nVerts; v_i++ ) {
+	    ind = Sync_DomainToGlobal( meshSync, v_i );
+	    Grid_Lift( vGrid, ind, (unsigned*)inds );
+	    if( (w_i == 0 && inds[d_i] == 0) || 
+		(w_i == 1 && inds[d_i] == (int)(vGrid->sizes[d_i] - 1)) )
+	    {
+	       ISet_Insert( wallSet, v_i );
+	    }
+	 }
+
+	 self->nWallVerts[d_i][w_i] = ISet_GetSize( wallSet );
+	 self->wallVerts[d_i][w_i] = Class_Array( 
+	    self, int, self->nWallVerts[d_i][w_i] );
+	 self->wallCrds[d_i][w_i] = Class_Array( 
+	    self, double, self->nWallVerts[d_i][w_i] );
+	 ISet_GetArray( wallSet, self->wallVerts[d_i][w_i] );
+	 ISet_Clear( wallSet );
+	 for( v_i = 0; v_i < self->nWallVerts[d_i][w_i]; v_i++ ) {
+	    self->wallCrds[d_i][w_i][v_i] = 
+	       mesh->verts[self->wallVerts[d_i][w_i][v_i]][d_i];
+	 }
+      }
+   }
+
+   for( d_i = 0; d_i < nDims; d_i++ ) {
+      NewClass_RemoveRef( self->syncs[d_i] );
+      Class_Free( self, self->crds[d_i] );
+      if( !ISet_Has( self->remeshDims, d_i ) ) {
+	 self->syncs[d_i] = NULL;
+	 self->crds[d_i] = NULL;
+	 continue;
+      }
+
+      for( v_i = 0; v_i < nVerts; v_i++ ) {
+	 ind = Sync_DomainToGlobal( meshSync, v_i );
+	 Grid_Lift( vGrid, ind, (unsigned*)inds );
+	 inds[d_i] = 0;
+	 ind = Grid_Project( vGrid, (unsigned*)inds );
+	 if( !Sync_TryGlobalToDomain( meshSync, ind, &ind ) )
+	    ISet_TryInsert( wallSet, ind );
+
+	 inds[d_i] = vGrid->sizes[d_i] - 1;
+	 ind = Grid_Project( vGrid, (unsigned*)inds );
+	 if( !Sync_TryGlobalToDomain( meshSync, ind, &ind ) )
+	    ISet_TryInsert( wallSet, ind );
+      }
+
+      nRems = ISet_GetSize( wallSet );
+      rems = Class_Array( self, int, nRems );
+      ISet_GetArray( wallSet, rems );
+      ISet_Clear( wallSet );
+      self->syncs[d_i] = Sync_New();
+      NewClass_AddRef( self->syncs[d_i] );
+      Sync_SetDecomp( self->syncs[d_i], meshDecomp );
+      Sync_FindRemotes( self->syncs[d_i], nRems, rems );
+      Class_Free( self, rems );
+      self->crds[d_i] = Class_Array( self, double, nRems );
+   }
+
+   NewClass_Delete( wallSet );
+
+#if 0
+   /* If we have some contact depth, copy the relevant vertex offsets. */
+   if( self->contactDepth > 0 ) {
+      int curInd;
+      Grid* grid;
+      int ii;
+
+      /* Get the vertex grid from the mesh. */
+      grid = *Mesh_GetExtension( mesh, Grid**, "vertexGrid" );
+      assert( grid );
+
+      /* Allocate for all the contact vertices. */
+      nVerts = grid->sizes[0];
+      if( nDims == 3 ) nVerts *= grid->sizes[1];
+      self->contactVerts = MemArray( double, nVerts, "" );
+
+      /* Copy upper strip. */
+      nVerts = Mesh_GetLocalSize( mesh, 0 );
+      curInd = 0;
+      for( ii = 0; ii < nVerts; ii++ ) {
+         Grid_Lift( grid, ii, inds );
+         if( inds[1] != self->contactDepth ) continue;
+
+	 /* If we were given a contact size, insert that instead. */
+	 if( self->contactSize > 0.0 )
+	   self->contactVerts[curInd++] = self->contactSize;
+	 else
+	   self->contactVerts[curInd++] = Mesh_GetVertex( mesh, ii )[1];
+      }
+
+   }
+#endif
+
+   Class_Free( self, inds );
+}
+
+void RegularRemesher_SetRemeshState( void* _self, int dim, Bool state ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+
+   if( state )
+      ISet_TryInsert( self->remeshDims, dim );
+   else if( ISet_Has( self->remeshDims, dim ) )
+      ISet_Remove( self->remeshDims, dim );
+}
+
+void RegularRemesher_SetStaticWall( void* _self, int dim, int wall, Bool state ) {
+   RegularRemesher* self = Class_Cast( _self, RegularRemesher );
+
+   if( state )
+      ISet_TryInsert( self->staticWalls[wall], dim );
+   else if( ISet_Has( self->staticWalls[wall], dim ) )
+      ISet_Remove( self->staticWalls[wall], dim );
+}
+
+#endif
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/RegularRemesherCmpt.c
--- a/Utils/src/RegularRemesherCmpt.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,230 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: RegularRemesherCmpt.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#ifdef HAVE_PETSC
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <assert.h>
-#include <mpi.h>
-
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "NewRemesher.h"
-#include "RegularRemesher.h"
-#include "RegularRemesherCmpt.h"
-
-
-/* Textual name of this class */
-const Type RegularRemesherCmpt_Type = "RegularRemesherCmpt";
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-RegularRemesherCmpt* RegularRemesherCmpt_New( Name name, AbstractContext* context, Mesh* mesh, RegularRemesher* regRemesh ) {
-   RegularRemesherCmpt*	self = _RegularRemesherCmpt_DefaultNew( name );
-
-	self->isConstructed = True;
-	_Remesher_Init( self, context, mesh );
-   _RegularRemesherCmpt_Init( self, regRemesh );
-
-	return self;
-}
-
-RegularRemesherCmpt* _RegularRemesherCmpt_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(RegularRemesherCmpt);
-	Type                                                      type = RegularRemesherCmpt_Type;
-	Stg_Class_DeleteFunction*                              _delete = _RegularRemesherCmpt_Delete;
-	Stg_Class_PrintFunction*                                _print = _RegularRemesherCmpt_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void*(*)(Name))_RegularRemesherCmpt_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _RegularRemesherCmpt_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _RegularRemesherCmpt_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _RegularRemesherCmpt_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _RegularRemesherCmpt_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _RegularRemesherCmpt_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	Remesher_RemeshFunc*                                remeshFunc = NULL;
-
-   return _RegularRemesherCmpt_New(  REGULARREMESHERCMPT_PASSARGS  );
-}
-
-RegularRemesherCmpt* _RegularRemesherCmpt_New(  REGULARREMESHERCMPT_DEFARGS  ) {
-   RegularRemesherCmpt*	self;
-
-   /* Allocate memory. */
-   self = (RegularRemesherCmpt*)_Remesher_New(  REMESHER_PASSARGS  );
-
-   /* RegularRemesherCmpt info */
-
-   return self;
-}
-
-void _RegularRemesherCmpt_Init( void* remesher, RegularRemesher* regRemesh ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-
-   /* RegularRemesherCmpt info */
-   self->regRemesh = regRemesh;
-}
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _RegularRemesherCmpt_Delete( void* remesher ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-
-   /* Delete parent */
-   _Stg_Component_Delete( self );
-}
-
-void _RegularRemesherCmpt_Print( void* remesher, Stream* stream ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-   Stream*					myStream;
-	
-   /* Set the Journal for printing informations */
-   myStream = Journal_Register( InfoStream_Type, (Name)"RegularRemesherCmptStream"  );
-
-   /* Print parent */
-   _Stg_Component_Print( self, stream );
-
-   /* General info */
-   Journal_Printf( myStream, "RegularRemesherCmpt (ptr): (%p)\n", self );
-
-   /* Virtual info */
-
-   /* RegularRemesherCmpt info */
-}
-
-void _RegularRemesherCmpt_AssignFromXML( void* remesher, Stg_ComponentFactory* cf, void* data ) {
-   RegularRemesherCmpt*		self = (RegularRemesherCmpt*)remesher;
-   Dictionary*					dict;
-   Dictionary_Entry_Value*	list;
-   Mesh*							mesh;
-   int							nItms, dim, wall;
-   int							i_i;
-	RegularRemesher*			regRemesh;
-
-   assert( self );
-   assert( cf );
-
-	regRemesh = RegularRemesher_New();
-   mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
-   NewRemesher_SetMesh( regRemesh, mesh );
-
-   regRemesh->contactDepth = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth", 0  );
-   regRemesh->contactSize = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactSize", 0.0  );
-   regRemesh->diffuseCorners = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"diffuseCorners", False  );
-   regRemesh->diffuseSurface = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"diffuseSurface", False  );
-   regRemesh->diffusionCoef = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"diffusionCoef", 1.0  );
-   regRemesh->ctx = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
-
-   dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
-   list = Dictionary_Get( dict, (Dictionary_Entry_Key)"remeshDims" );
-   if( list ) {
-		nItms = Dictionary_Entry_Value_GetCount( list );
-		for( i_i = 0; i_i < nItms; i_i++  ) {
-			dim = Dictionary_Entry_Value_AsInt( 
-			Dictionary_Entry_Value_GetElement( list, i_i ) );
-			RegularRemesher_SetRemeshState( regRemesh, dim, True );
-      }
-   }
-
-   list = Dictionary_Get( dict, (Dictionary_Entry_Key)"staticWalls" );
-   if( list ) {
-		nItms = Dictionary_Entry_Value_GetCount( list );
-		assert( nItms % 2 == 0 );
-		for( i_i = 0; i_i < nItms; i_i += 2  ) {
-			dim = Dictionary_Entry_Value_AsInt( 
-			Dictionary_Entry_Value_GetElement( list, i_i ) );
-			wall = Dictionary_Entry_Value_AsInt( 
-			Dictionary_Entry_Value_GetElement( list, i_i + 1 ) );
-			RegularRemesher_SetStaticWall( regRemesh, dim, wall, True );
-      }
-   }
-   _RegularRemesherCmpt_Init( self, regRemesh );
-}
-
-void _RegularRemesherCmpt_Build( void* remesher, void* data ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-
-   assert( self );
-
-   RegularRemesher_Build( self->regRemesh );
-}
-
-
-void _RegularRemesherCmpt_Initialise( void* remesher, void* data ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-
-   assert( self );
-}
-
-
-void _RegularRemesherCmpt_Execute( void* remesher, void* data ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-
-   assert( self );
-
-   RegularRemesher_Remesh( self->regRemesh );
-}
-
-
-void _RegularRemesherCmpt_Destroy( void* remesher, void* data ) {
-   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
-
-   assert( self );
-
-   /* Delete the class itself */
-   NewClass_Delete( self->regRemesh );
-}
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-#endif
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/RegularRemesherCmpt.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/RegularRemesherCmpt.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,230 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: RegularRemesherCmpt.c 2192 2004-10-15 02:45:38Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifdef HAVE_PETSC
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <assert.h>
+#include <mpi.h>
+
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "NewRemesher.h"
+#include "RegularRemesher.h"
+#include "RegularRemesherCmpt.h"
+
+
+/* Textual name of this class */
+const Type RegularRemesherCmpt_Type = "RegularRemesherCmpt";
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+RegularRemesherCmpt* RegularRemesherCmpt_New( Name name, AbstractContext* context, Mesh* mesh, RegularRemesher* regRemesh ) {
+   RegularRemesherCmpt*	self = _RegularRemesherCmpt_DefaultNew( name );
+
+	self->isConstructed = True;
+	_Remesher_Init( self, context, mesh );
+   _RegularRemesherCmpt_Init( self, regRemesh );
+
+	return self;
+}
+
+RegularRemesherCmpt* _RegularRemesherCmpt_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(RegularRemesherCmpt);
+	Type                                                      type = RegularRemesherCmpt_Type;
+	Stg_Class_DeleteFunction*                              _delete = _RegularRemesherCmpt_Delete;
+	Stg_Class_PrintFunction*                                _print = _RegularRemesherCmpt_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = (void*(*)(Name))_RegularRemesherCmpt_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _RegularRemesherCmpt_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _RegularRemesherCmpt_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _RegularRemesherCmpt_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _RegularRemesherCmpt_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _RegularRemesherCmpt_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	Remesher_RemeshFunc*                                remeshFunc = NULL;
+
+   return _RegularRemesherCmpt_New(  REGULARREMESHERCMPT_PASSARGS  );
+}
+
+RegularRemesherCmpt* _RegularRemesherCmpt_New(  REGULARREMESHERCMPT_DEFARGS  ) {
+   RegularRemesherCmpt*	self;
+
+   /* Allocate memory. */
+   self = (RegularRemesherCmpt*)_Remesher_New(  REMESHER_PASSARGS  );
+
+   /* RegularRemesherCmpt info */
+
+   return self;
+}
+
+void _RegularRemesherCmpt_Init( void* remesher, RegularRemesher* regRemesh ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+
+   /* RegularRemesherCmpt info */
+   self->regRemesh = regRemesh;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _RegularRemesherCmpt_Delete( void* remesher ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+
+   /* Delete parent */
+   _Stg_Component_Delete( self );
+}
+
+void _RegularRemesherCmpt_Print( void* remesher, Stream* stream ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+   Stream*					myStream;
+	
+   /* Set the Journal for printing informations */
+   myStream = Journal_Register( InfoStream_Type, (Name)"RegularRemesherCmptStream"  );
+
+   /* Print parent */
+   _Stg_Component_Print( self, stream );
+
+   /* General info */
+   Journal_Printf( myStream, "RegularRemesherCmpt (ptr): (%p)\n", self );
+
+   /* Virtual info */
+
+   /* RegularRemesherCmpt info */
+}
+
+void _RegularRemesherCmpt_AssignFromXML( void* remesher, Stg_ComponentFactory* cf, void* data ) {
+   RegularRemesherCmpt*		self = (RegularRemesherCmpt*)remesher;
+   Dictionary*					dict;
+   Dictionary_Entry_Value*	list;
+   Mesh*							mesh;
+   int							nItms, dim, wall;
+   int							i_i;
+	RegularRemesher*			regRemesh;
+
+   assert( self );
+   assert( cf );
+
+	regRemesh = RegularRemesher_New();
+   mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
+   NewRemesher_SetMesh( regRemesh, mesh );
+
+   regRemesh->contactDepth = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"contactDepth", 0  );
+   regRemesh->contactSize = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"contactSize", 0.0  );
+   regRemesh->diffuseCorners = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"diffuseCorners", False  );
+   regRemesh->diffuseSurface = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"diffuseSurface", False  );
+   regRemesh->diffusionCoef = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"diffusionCoef", 1.0  );
+   regRemesh->ctx = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  );
+
+   dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
+   list = Dictionary_Get( dict, (Dictionary_Entry_Key)"remeshDims" );
+   if( list ) {
+		nItms = Dictionary_Entry_Value_GetCount( list );
+		for( i_i = 0; i_i < nItms; i_i++  ) {
+			dim = Dictionary_Entry_Value_AsInt( 
+			Dictionary_Entry_Value_GetElement( list, i_i ) );
+			RegularRemesher_SetRemeshState( regRemesh, dim, True );
+      }
+   }
+
+   list = Dictionary_Get( dict, (Dictionary_Entry_Key)"staticWalls" );
+   if( list ) {
+		nItms = Dictionary_Entry_Value_GetCount( list );
+		assert( nItms % 2 == 0 );
+		for( i_i = 0; i_i < nItms; i_i += 2  ) {
+			dim = Dictionary_Entry_Value_AsInt( 
+			Dictionary_Entry_Value_GetElement( list, i_i ) );
+			wall = Dictionary_Entry_Value_AsInt( 
+			Dictionary_Entry_Value_GetElement( list, i_i + 1 ) );
+			RegularRemesher_SetStaticWall( regRemesh, dim, wall, True );
+      }
+   }
+   _RegularRemesherCmpt_Init( self, regRemesh );
+}
+
+void _RegularRemesherCmpt_Build( void* remesher, void* data ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+
+   assert( self );
+
+   RegularRemesher_Build( self->regRemesh );
+}
+
+
+void _RegularRemesherCmpt_Initialise( void* remesher, void* data ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+
+   assert( self );
+}
+
+
+void _RegularRemesherCmpt_Execute( void* remesher, void* data ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+
+   assert( self );
+
+   RegularRemesher_Remesh( self->regRemesh );
+}
+
+
+void _RegularRemesherCmpt_Destroy( void* remesher, void* data ) {
+   RegularRemesherCmpt*	self = (RegularRemesherCmpt*)remesher;
+
+   assert( self );
+
+   /* Delete the class itself */
+   NewClass_Delete( self->regRemesh );
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+#endif
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/ShapeAdvector.c
--- a/Utils/src/ShapeAdvector.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,202 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) {
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: ShapeAdvector.c 212 2005-11-08 23:50:02Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "DomainContext.h"
-#include "ShapeAdvector.h"
-#include "TimeIntegrator.h"
-#include "TimeIntegrand.h"
-#include "FieldVariable.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type ShapeAdvector_Type = "ShapeAdvector";
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-ShapeAdvector* ShapeAdvector_New(
-	Name					name,
-	DomainContext*		context,
-	TimeIntegrator*	timeIntegrator,
-	FieldVariable*		velocityField,
-	Stg_Shape*			shape,
-	Bool					allowFallbackToFirstOrder )
-{
-	ShapeAdvector* self = (ShapeAdvector*) _ShapeAdvector_DefaultNew( name );
-
-	self->isConstructed = True;
-	_ShapeAdvector_Init( self, context, timeIntegrator, velocityField, shape, allowFallbackToFirstOrder );
-
-	return self;
-}
-
-void* _ShapeAdvector_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(ShapeAdvector);
-	Type                                                      type = ShapeAdvector_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ShapeAdvector_Delete;
-	Stg_Class_PrintFunction*                                _print = _ShapeAdvector_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ShapeAdvector_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _ShapeAdvector_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ShapeAdvector_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ShapeAdvector_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ShapeAdvector_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ShapeAdvector_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ShapeAdvector_Destroy;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _ShapeAdvector_New(  SHAPEADVECTOR_PASSARGS  );
-}
-
-ShapeAdvector* _ShapeAdvector_New(  SHAPEADVECTOR_DEFARGS  )
-{
-	ShapeAdvector* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(ShapeAdvector) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (ShapeAdvector*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	
-	return self;
-}
-
-void _ShapeAdvector_Init( 
-	ShapeAdvector*		self,
-	DomainContext*		context,
-	TimeIntegrator*	timeIntegrator,
-	FieldVariable*		velocityField,
-	Stg_Shape*			shape,
-	Bool					allowFallbackToFirstOrder )
-{
-	self->context = context;
-	self->velocityField = velocityField;
-	self->shape = shape;
-	self->shapeCount = 1;
-	self->shapeCentrePtr = shape->centre;
-
-	self->shapeCentreVariable = Variable_NewVector( "shapeCentreVariable", (AbstractContext*)self->context,
-		Variable_DataType_Double, shape->dim, &self->shapeCount, NULL,  &self->shapeCentrePtr, NULL );
-	self->timeIntegrand = TimeIntegrand_New( "shapeTimeIntegrand", self->context, timeIntegrator, self->shapeCentreVariable, 1,
-		(Stg_Component**) &velocityField, allowFallbackToFirstOrder );
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _ShapeAdvector_Delete( void* shapeAdvector ) {
-	ShapeAdvector* self = (ShapeAdvector*)shapeAdvector;
-
-	/* Delete parent */
-	_Stg_Component_Delete( self );
-}
-
-
-void _ShapeAdvector_Print( void* shapeAdvector, Stream* stream ) {
-	ShapeAdvector* self = (ShapeAdvector*)shapeAdvector;
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-}
-
-
-void* _ShapeAdvector_Copy( const void* shapeAdvector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ShapeAdvector*	self = (ShapeAdvector*)shapeAdvector;
-	ShapeAdvector*	newShapeAdvector;
-	
-	newShapeAdvector = (ShapeAdvector*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newShapeAdvector->velocityField = self->velocityField;
-	newShapeAdvector->shape = self->shape;
-	
-	return (void*)newShapeAdvector;
-}
-
-void _ShapeAdvector_AssignFromXML( void* shapeAdvector, Stg_ComponentFactory* cf, void* data ) {
-	ShapeAdvector*		self = (ShapeAdvector*) shapeAdvector;
-	FieldVariable*		velocityField;
-	Stg_Shape*			shape;
-	TimeIntegrator*	timeIntegrator;
-	Bool					allowFallbackToFirstOrder = False;
-	DomainContext*		context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
-	if( !context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-
-	timeIntegrator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TimeIntegrator", TimeIntegrator, True, data   ) ;
-	velocityField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FieldVariable, True, data   ) ;
-	shape = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, data  ) ;
-	allowFallbackToFirstOrder = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"allowFallbackToFirstOrder", False  );
-
-	_ShapeAdvector_Init( self, context, timeIntegrator, velocityField, shape, allowFallbackToFirstOrder );
-}
-
-void _ShapeAdvector_Build( void* shapeAdvector, void* data ) {
-}
-
-void _ShapeAdvector_Initialise( void* shapeAdvector, void* data ) {
-}
-
-void _ShapeAdvector_Execute( void* shapeAdvector, void* data ) {
-}
-
-void _ShapeAdvector_Destroy( void* shapeAdvector, void* data ) {
-	ShapeAdvector* self = (ShapeAdvector*)shapeAdvector;
-
-	_Stg_Component_Delete( self->shapeCentreVariable );
-	_Stg_Component_Delete( self->timeIntegrand );
-}
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/ShapeAdvector.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/ShapeAdvector.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,202 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) {
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: ShapeAdvector.c 212 2005-11-08 23:50:02Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "DomainContext.h"
+#include "ShapeAdvector.h"
+#include "TimeIntegrator.h"
+#include "TimeIntegrand.h"
+#include "FieldVariable.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type ShapeAdvector_Type = "ShapeAdvector";
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+ShapeAdvector* ShapeAdvector_New(
+	Name					name,
+	DomainContext*		context,
+	TimeIntegrator*	timeIntegrator,
+	FieldVariable*		velocityField,
+	Stg_Shape*			shape,
+	Bool					allowFallbackToFirstOrder )
+{
+	ShapeAdvector* self = (ShapeAdvector*) _ShapeAdvector_DefaultNew( name );
+
+	self->isConstructed = True;
+	_ShapeAdvector_Init( self, context, timeIntegrator, velocityField, shape, allowFallbackToFirstOrder );
+
+	return self;
+}
+
+void* _ShapeAdvector_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(ShapeAdvector);
+	Type                                                      type = ShapeAdvector_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ShapeAdvector_Delete;
+	Stg_Class_PrintFunction*                                _print = _ShapeAdvector_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ShapeAdvector_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _ShapeAdvector_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ShapeAdvector_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ShapeAdvector_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ShapeAdvector_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ShapeAdvector_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ShapeAdvector_Destroy;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _ShapeAdvector_New(  SHAPEADVECTOR_PASSARGS  );
+}
+
+ShapeAdvector* _ShapeAdvector_New(  SHAPEADVECTOR_DEFARGS  )
+{
+	ShapeAdvector* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(ShapeAdvector) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (ShapeAdvector*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	
+	return self;
+}
+
+void _ShapeAdvector_Init( 
+	ShapeAdvector*		self,
+	DomainContext*		context,
+	TimeIntegrator*	timeIntegrator,
+	FieldVariable*		velocityField,
+	Stg_Shape*			shape,
+	Bool					allowFallbackToFirstOrder )
+{
+	self->context = context;
+	self->velocityField = velocityField;
+	self->shape = shape;
+	self->shapeCount = 1;
+	self->shapeCentrePtr = shape->centre;
+
+	self->shapeCentreVariable = Variable_NewVector( "shapeCentreVariable", (AbstractContext*)self->context,
+		Variable_DataType_Double, shape->dim, &self->shapeCount, NULL,  &self->shapeCentrePtr, NULL );
+	self->timeIntegrand = TimeIntegrand_New( "shapeTimeIntegrand", self->context, timeIntegrator, self->shapeCentreVariable, 1,
+		(Stg_Component**) &velocityField, allowFallbackToFirstOrder );
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _ShapeAdvector_Delete( void* shapeAdvector ) {
+	ShapeAdvector* self = (ShapeAdvector*)shapeAdvector;
+
+	/* Delete parent */
+	_Stg_Component_Delete( self );
+}
+
+
+void _ShapeAdvector_Print( void* shapeAdvector, Stream* stream ) {
+	ShapeAdvector* self = (ShapeAdvector*)shapeAdvector;
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+}
+
+
+void* _ShapeAdvector_Copy( const void* shapeAdvector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ShapeAdvector*	self = (ShapeAdvector*)shapeAdvector;
+	ShapeAdvector*	newShapeAdvector;
+	
+	newShapeAdvector = (ShapeAdvector*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newShapeAdvector->velocityField = self->velocityField;
+	newShapeAdvector->shape = self->shape;
+	
+	return (void*)newShapeAdvector;
+}
+
+void _ShapeAdvector_AssignFromXML( void* shapeAdvector, Stg_ComponentFactory* cf, void* data ) {
+	ShapeAdvector*		self = (ShapeAdvector*) shapeAdvector;
+	FieldVariable*		velocityField;
+	Stg_Shape*			shape;
+	TimeIntegrator*	timeIntegrator;
+	Bool					allowFallbackToFirstOrder = False;
+	DomainContext*		context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
+	if( !context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+
+	timeIntegrator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TimeIntegrator", TimeIntegrator, True, data   ) ;
+	velocityField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FieldVariable, True, data   ) ;
+	shape = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, data  ) ;
+	allowFallbackToFirstOrder = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"allowFallbackToFirstOrder", False  );
+
+	_ShapeAdvector_Init( self, context, timeIntegrator, velocityField, shape, allowFallbackToFirstOrder );
+}
+
+void _ShapeAdvector_Build( void* shapeAdvector, void* data ) {
+}
+
+void _ShapeAdvector_Initialise( void* shapeAdvector, void* data ) {
+}
+
+void _ShapeAdvector_Execute( void* shapeAdvector, void* data ) {
+}
+
+void _ShapeAdvector_Destroy( void* shapeAdvector, void* data ) {
+	ShapeAdvector* self = (ShapeAdvector*)shapeAdvector;
+
+	_Stg_Component_Delete( self->shapeCentreVariable );
+	_Stg_Component_Delete( self->timeIntegrand );
+}
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/SobolGenerator.c
--- a/Utils/src/SobolGenerator.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,496 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: SobolGenerator.c 3745 2006-08-03 10:10:21Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <string.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "SobolGenerator.h"
-#include "DomainContext.h"
-
-#include <assert.h>
-
-const Type SobolGenerator_Type = "SobolGenerator";
-
-/* Some macros for clarity */
-#define BITS_IN_A_BYTE 8
-
-SobolGenerator* SobolGenerator_New( 
-			Name                                               name,
-			unsigned int                                       polynomialDegree,
-			unsigned int                                       polynomialCoefficient,
-			const unsigned int *                               initialDirectionNumbers )
-{
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(SobolGenerator);
-	Type                              type = SobolGenerator_Type;
-	Stg_Class_DeleteFunction*      _delete = _SobolGenerator_Delete;
-	Stg_Class_PrintFunction*        _print = _SobolGenerator_Print;
-	Stg_Class_CopyFunction*          _copy = _SobolGenerator_Copy;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	SobolGenerator* self = _SobolGenerator_New(  SOBOLGENERATOR_PASSARGS  );
-	_SobolGenerator_Init( self, polynomialDegree, polynomialCoefficient, initialDirectionNumbers );
-
-	return self;
-}
-
-SobolGenerator* _SobolGenerator_New(  SOBOLGENERATOR_DEFARGS  )
-{
-	SobolGenerator*		self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SobolGenerator) );
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (SobolGenerator*)_Stg_Object_New(  STG_OBJECT_PASSARGS  );
-
-	return self;
-}
-
-void _SobolGenerator_Init( 
-		SobolGenerator*                                    self,
-		unsigned int                                       polynomialDegree,
-		unsigned int                                       polynomialCoefficient,
-		const unsigned int *                               initialDirectionNumbers ) 
-{
-	unsigned int        directionNum_I;
-
-	self->directionalNumbersAlloced = 20;
-
-	self->directionalNumberIsCalc = Memory_Alloc_Array( Bool, self->directionalNumbersAlloced, "Calculate Flag" );
-	self->directionalNumberList   = Memory_Alloc_Array( unsigned int , self->directionalNumbersAlloced, "DirectionalNumbers" );
-	memset( self->directionalNumberIsCalc, 0, sizeof( Bool ) * self->directionalNumbersAlloced );
-
-	self->polynomialDegree      = polynomialDegree;
-	self->polynomialCoefficient = polynomialCoefficient;
-
-	memcpy( self->directionalNumberList, initialDirectionNumbers, polynomialDegree * sizeof( unsigned int ) );
-
-	self->lastCalculated_I = 0;
-	self->lastCalculatedNumber = 0.5;
-		
-	for ( directionNum_I = 0 ; directionNum_I < polynomialDegree ; directionNum_I++ )
-		self->directionalNumberIsCalc[ directionNum_I ] = True;
-	
-}
-
-
-void _SobolGenerator_Delete( void* sobolGenerator ) {
-	SobolGenerator* self = (SobolGenerator*) sobolGenerator;
-
-	Memory_Free( self->directionalNumberIsCalc );
-	Memory_Free( self->directionalNumberList );
-
-	_Stg_Object_Delete( self );
-}
-
-void _SobolGenerator_Print( void* sobolGenerator, Stream* stream ) {
-	SobolGenerator* self  = (SobolGenerator*) sobolGenerator;
-	unsigned int    index;
-
-	Journal_Printf( stream, "Sobol Generator: '%s'\n", self->name );
-	Stream_Indent( stream );
-
-	_Stg_Object_Print( self, stream );
-
-	Journal_PrintValue( stream, self->polynomialDegree );
-	Journal_PrintValue( stream, self->polynomialCoefficient );
-	Journal_Printf( stream, "This leads to polynomial: x^%u + ", self->polynomialDegree );
-	for ( index = self->polynomialDegree - 1 ; index > 0 ; index-- ) {
-		if ( self->polynomialCoefficient & 1 << (index - 1) )
-			Journal_Printf( stream, "x^%u + ", index );
-	}
-	Journal_Printf( stream, "1\n" );
-
-	Journal_PrintValue( stream, self->directionalNumbersAlloced );
-	Journal_Printf( stream, "Directional Numbers Calculated:\n" );
-	for ( index = 0 ; index < self->directionalNumbersAlloced ; index++ ) {
-		if ( self->directionalNumberIsCalc[ index ] )
-			Journal_Printf( stream, "\tDirectional Number %u = %lu\n", index, self->directionalNumberList[ index ] );
-	}
-
-	Journal_PrintValue( stream, self->lastCalculated_I );
-	Journal_PrintValue( stream, self->lastCalculatedNumber );
-	
-	Stream_UnIndent( stream );
-}
-
-void* _SobolGenerator_Copy( const void* sobolGenerator, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SobolGenerator*	self = (SobolGenerator*)sobolGenerator;
-	SobolGenerator*	newSobolGenerator;
-	
-	newSobolGenerator = (SobolGenerator*) _Stg_Object_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	newSobolGenerator->lastCalculated_I          = self->lastCalculated_I;
-	newSobolGenerator->lastCalculatedNumber      = self->lastCalculatedNumber;
-	newSobolGenerator->directionalNumbersAlloced = self->directionalNumbersAlloced;
-	newSobolGenerator->polynomialDegree          = self->polynomialDegree;
-	newSobolGenerator->polynomialCoefficient     = self->polynomialCoefficient ;
-	
-	if (deep) {
-		newSobolGenerator->directionalNumberIsCalc = Memory_Alloc_Array( Bool, self->directionalNumbersAlloced, "Flag" );
-		memcpy( newSobolGenerator->directionalNumberIsCalc, self->directionalNumberIsCalc, 
-				self->directionalNumbersAlloced * sizeof( Bool ) );
-
-		newSobolGenerator->directionalNumberList = Memory_Alloc_Array( unsigned int, self->directionalNumbersAlloced, "V_i" );
-		memcpy( newSobolGenerator->directionalNumberList, self->directionalNumberList, 
-				self->directionalNumbersAlloced * sizeof( unsigned int ) );
-	}
-	else {
-		newSobolGenerator->directionalNumberIsCalc      = self->directionalNumberIsCalc;
-		newSobolGenerator->directionalNumberList        = self->directionalNumberList;
-	}
-	
-	return (void*)newSobolGenerator;
-}
-
-Bit_Index _SobolGenerator_FindRightmostZeroBit( unsigned int number ) {
-	Bit_Index bit = 0;
-
-	while ( number & 1 ) {
-		/* Shift All bits to right by one */
-		number >>= 1;
-
-		/* Increment counter to find bit */
-		bit++;
-		assert( bit < sizeof( unsigned int ) * BITS_IN_A_BYTE );
-	}
-	return bit;
-}
-
-unsigned int  SobolGenerator_GetDirectionalNumber( void* sobolGenerator, unsigned int directionalNum_I ) {
-	SobolGenerator*	     self          = (SobolGenerator*)sobolGenerator;
-	unsigned int         result;
-	unsigned int         coefficient_I;
-	unsigned int         powerOfTwo;
-	Bit_Index            bitToTest;
-	unsigned int         directionNumber = 0;
-
-	if ( directionalNum_I >= self->directionalNumbersAlloced ) {
-		unsigned int  difference       = 10;
-		unsigned int  newNumberToAlloc = directionalNum_I + difference;
-		
-		/* Allocate More Memory */
-		self->directionalNumberIsCalc = Memory_Realloc_Array( self->directionalNumberIsCalc, Bool, newNumberToAlloc );
-		self->directionalNumberList   = Memory_Realloc_Array( self->directionalNumberList, unsigned int , newNumberToAlloc );
-
-		/* Set Bools */
-		memset( &self->directionalNumberIsCalc[ self->directionalNumbersAlloced ], 0, sizeof(Bool) * difference );
-		
-		self->directionalNumbersAlloced = newNumberToAlloc;
-	}
-	/* Check to see whether the directional number has already been calculated */
-	else if ( self->directionalNumberIsCalc[ directionalNum_I ] )
-		return self->directionalNumberList[ directionalNum_I ];
-
-	/* If the code hasn't precalculated all the directional numbers up to polynomialDegree then there is something wrong */
-	assert( directionalNum_I >= self->polynomialDegree );
-
-	/* Calculate Directional Number */
-	result = 0;
-	for ( coefficient_I = 0 ; coefficient_I < self->polynomialDegree ; coefficient_I++ ) {
-		/* Test for this coefficient is 1 */
-		bitToTest = self->polynomialDegree - 2 - coefficient_I;
-		if ( coefficient_I == self->polynomialDegree - 1 || self->polynomialCoefficient & 1 << bitToTest ) {
-			powerOfTwo = 0;
-			powerOfTwo |= 1 << (coefficient_I + 1);
-			
-			directionNumber = SobolGenerator_GetDirectionalNumber( self, directionalNum_I - 1 - coefficient_I );
-			result ^= powerOfTwo * directionNumber;
-		}
-	}
-	result ^= directionNumber;
-
-	self->directionalNumberIsCalc[ directionalNum_I ] = True;
-
-	return self->directionalNumberList[ directionalNum_I ] = result;
-}
-
-#define WORDLENGTH 30
-double SobolGenerator_GetNextNumber( void* sobolGenerator ) {
-	SobolGenerator*   self          = (SobolGenerator*)sobolGenerator;
-	Bit_Index         differentBit;
-	unsigned int      directionalNumber;
-
-	/* The Gray Code of the index last calculated quasi-random number will differ by only one bit 
-	 * from the Gray Code of the index of the current quasi-random number to calculate
-	 * this bit is the right most zero bit in lastCalcuated_I */
-	differentBit = _SobolGenerator_FindRightmostZeroBit( self->lastCalculated_I );
-
-	/* This bit can be used to find the next quasi-random number in Sobol's sequence 
-	 * x_{n+1} = x_{n} ^ v_{c}, where
-	 * x_{j} is the j^{th} quasi-random number in the sequence
-	 * v_{j} is the j^{th} directional number
-	 * c is the single different bit between the Gray codes for n and n+1 */
-
-	self->lastCalculated_I++;
-	directionalNumber = SobolGenerator_GetDirectionalNumber( self, differentBit );
-	directionalNumber <<= (WORDLENGTH - differentBit - 1);
-	self->lastCalculatedNumber ^= directionalNumber;
-
-	return (double) self->lastCalculatedNumber / (double) (1L << (WORDLENGTH));
-}
-	
-double SobolGenerator_GetNumberByIndex( void* sobolGenerator, unsigned int index ) {
-	SobolGenerator*   self          = (SobolGenerator*)sobolGenerator;
-	unsigned int      grayCode;
-	Bit_Index         bit_I;
-	unsigned int      directionalNumber;
-	unsigned int      result   =  0;
-
-	/* have to shift index because index 0 is the initial zero for the sequence to begin */
-	index++;
-
-	/* Get Gray Code of 'index' */
-	grayCode = index ^ (index >> 1);
-
-	for ( bit_I = 0 ; bit_I < sizeof( unsigned int ) * BITS_IN_A_BYTE ; bit_I++ ) {
-		if ( grayCode & 1 << bit_I ) {
-			directionalNumber = SobolGenerator_GetDirectionalNumber( self, bit_I );
-			directionalNumber <<= (WORDLENGTH - bit_I - 1);
-
-			result ^= directionalNumber;
-		}
-	}
-
-	return (double) result / (double) (1L << (WORDLENGTH));
-}
-
-double SobolGenerator_GetNextNumber_WithMinMax( void* sobolGenerator, double min, double max ) {
-	return (max - min) * SobolGenerator_GetNextNumber( sobolGenerator ) + min;
-}
-
-double SobolGenerator_GetNumberByIndex_WithMinMax( void* sobolGenerator, unsigned int index, double min, double max ) {
-	return (max - min) * SobolGenerator_GetNumberByIndex( sobolGenerator, index ) + min;
-}
-
-/* Some global variables that drive the random number generator */
-/* These numbers for initialisation come  from:
- * Stephen Joe and Frances Y. Juo. Remark on Algorithm 659: Implementing Sobol¿s Quasirandom Sequence Generator. ACM Transactions on Mathematical Software, 29(1), March 2003.*/
-const unsigned int SobolGenerator_PolynomialDegree[] = {
-	1,2,3,3,4, 4,5,5,5,5,
-	5,5,6,6,6, 6,6,6,7,7,
-	7,7,7,7,7, 7,7,7,7,7,
-	7,7,7,7,7, 7,8,8,8,8,
-	8,8,8,8,8, 8,8,8,8,8,
-	
-	8,8,9,9,9, 9,9,9,9,9,
-	9,9,9,9,9, 9,9,9,9,9,
-	9,9,9,9,9, 9,9,9,9,9,
-	9,9,9,9,9, 9,9,9,9,9,
-	9,9,9,9,9, 9,9,9,9,9
-	};
-
-const unsigned int SobolGenerator_PolynomialCoefficient[] = {
-	0,1,1,2,1, 4,2,13,7,14,
-	11,4,1,16,13, 22,19,25,1,32,
-	4,8,7,56,14, 28,19,50,21,42,
-	31,62,37,41,55, 59,14,56,21,22,
-	38,47,49,50,52, 67,70,84,97,103,
-
-	115,122,8,13,16, 22,25,44,47,52,
-	55,59,62,67,74, 81,82,87,91,94,
-	103,104,109,122,124, 137,138,143,145,152,
-	157,167,173,176,181, 182,185,191,194,199,
-	218,220,227,229,230, 234,236,241,244,253
-	};
-
-const unsigned int SobolGenerator_InitialDirectionNumbers[][13] = {
-	 { 1 },
-	 { 1, 1 },
-	 { 1, 3, 7 },
-	 { 1, 1, 5 },
-	 { 1, 3, 1, 1 },
-
-	 { 1, 1, 3, 7 },
-	 { 1, 3, 3, 9, 9 },
-	 { 1, 3, 7, 13, 3 },
-	 { 1, 1, 5, 11, 27 },
-	 { 1, 3, 5, 1, 15 },
-
-	 /*10*/
-	 { 1, 1, 7, 3, 29 },
-	 { 1, 3, 7, 7, 21 },
-	 { 1, 1, 1, 9, 23, 37 },
-	 { 1, 3, 3, 5, 19, 33 },
-	 { 1, 1, 3, 13, 11, 7 },
-
-	 { 1, 1, 7, 13, 25, 5 },
-	 { 1, 3, 5, 11, 7, 11 },
-	 { 1, 1, 1, 3, 13, 39 },
-	 { 1, 3, 1, 15, 17, 63, 13 },
-	 { 1, 1, 5, 5, 1, 59, 33 },
-
-	 /*20*/
-	 { 1, 3, 3, 3, 25, 17, 115 },
-	 { 1, 1, 7, 15, 29, 15, 41 },
-	 { 1, 3, 1, 7, 3, 23, 79 },
-	 { 1, 3, 7, 9, 31, 29, 17 },
-	 { 1, 1, 5, 13, 11, 3, 29 },
-	 
-	 { 1, 1, 1, 9, 5, 21, 119 },
-	 { 1, 1, 3, 1, 23, 13, 75 },
-	 { 1, 3, 7, 11, 27, 31, 73 },
-	 { 1, 1, 7, 7, 19, 25, 105 },
-	 { 1, 3, 1, 5, 21, 9, 7 },
-	 
-	 /*30*/
-	 { 1, 1, 1, 15, 5, 49, 59 },
-	 { 1, 3, 1, 1, 1, 33, 65 },
-	 { 1, 3, 5, 15, 17, 19, 21 },
-	 { 1, 1, 7, 11, 13, 29, 3 },
-	 { 1, 3, 7, 5, 7, 11, 113 },
-	 
-	 { 1, 1, 5, 11, 15, 19, 61 },
-	 { 1, 1, 1, 1, 9, 27, 89, 7 },
-	 { 1, 1, 3, 7, 31, 15, 45, 23 },
-	 { 1, 3, 3, 9, 25, 25, 107, 39 },
-	 { 1, 1, 7, 7, 3, 63, 21, 217 },
-	 
-	 /*40*/
-	 { 1, 3, 5, 7, 5, 55, 71, 141 },
-	 { 1, 1, 5, 1, 23, 17, 79, 27 },
-	 { 1, 1, 5, 15, 7, 63, 19, 53 },
-	 { 1, 1, 3, 15, 3, 49, 71, 181 },
-	 { 1, 3, 3, 15, 17, 19, 61, 169 },
-	 
-	 { 1, 3, 3, 13, 23, 41, 41, 35 },
-	 { 1, 1, 1, 3, 3, 59, 57, 15 },
-	 { 1, 3, 1, 3, 3, 3, 121, 207 },
-	 { 1, 3, 5, 15, 21, 57, 87, 45 },
-	 { 1, 1, 1, 5, 25, 33, 119, 247 },
-	 
-	 /*50*/
-	 { 1, 1, 1, 9, 25, 49, 55, 185 },
-	 { 1, 3, 5, 7, 23, 53, 85, 117 },
-	 { 1, 3, 3, 13, 11, 57, 121, 41, 235 },
-	 { 1, 1, 3, 3, 19, 57, 119, 81, 307 },
-	 { 1, 3, 3, 7, 3, 39, 11, 223, 495 },
-	 
-	 { 1, 3, 3, 5, 11, 21, 23, 151, 417 },
-	 { 1, 3, 1, 11, 31, 7, 61, 81, 57 },
-	 { 1, 1, 3, 9, 7, 53, 11, 189, 151 },
-	 { 1, 3, 7, 1, 9, 9, 35, 61, 19 },
-	 { 1, 1, 5, 9, 5, 55, 33, 95, 119 },
-	 
-	 /*60*/
-	 { 1, 3, 7, 1, 17, 15, 43, 185, 375 },
-	 { 1, 1, 3, 5, 23, 59, 107, 23, 451 },
-	 { 1, 1, 7, 7, 17, 19, 113, 73, 55 },
-	 { 1, 3, 1, 13, 17, 49, 101, 113, 449 },
-	 { 1, 3, 3, 9, 25, 31, 29, 239, 501 },
-	 
-	 { 1, 1, 3, 9, 13, 3, 87, 85, 53 },
-	 { 1, 1, 5, 1, 11, 39, 119, 9, 185 },
-	 { 1, 1, 1, 7, 31, 5, 97, 201, 317 },
-	 { 1, 1, 3, 3, 27, 5, 29, 83, 17 },
-	 { 1, 3, 5, 5, 19, 41, 17, 53, 21 },
-	 
-	 /*70*/
-	 { 1, 1, 5, 1, 17, 9, 89, 183, 487 },
-	 { 1, 1, 7, 11, 23, 19, 5, 203, 13 },
-	 { 1, 3, 7, 11, 7, 9, 127, 91, 347 },
-	 { 1, 1, 7, 13, 5, 57, 89, 149, 393 },
-	 { 1, 1, 1, 7, 11, 25, 119, 101, 15 },
-	 
-	 { 1, 1, 1, 7, 19, 1, 117, 13, 391 },
-	 { 1, 3, 3, 9, 19, 15, 103, 111, 307 },
-	 { 1, 3, 3, 9, 7, 51, 105, 239, 189 },
-	 { 1, 1, 1, 1, 13, 11, 41, 3, 381 },
-	 { 1, 3, 1, 1, 21, 19, 83, 205, 71 },
-	 
-	 /*80*/
-	 { 1, 3, 5, 3, 21, 61, 25, 253, 163 },
-	 { 1, 1, 1, 9, 7, 53, 41, 247, 99 },
-	 { 1, 3, 5, 15, 9, 29, 55, 121, 467 },
-	 { 1, 3, 7, 1, 11, 19, 69, 189, 167 },
-	 { 1, 3, 5, 5, 1, 11, 117, 169, 433 },
-	 
-	 { 1, 1, 1, 13, 5, 9, 49, 179, 337 },
-	 { 1, 3, 7, 1, 21, 21, 127, 197, 257 },
-	 { 1, 3, 5, 9, 11, 19, 29, 175, 179 },
-	 { 1, 3, 3, 9, 13, 43, 1, 217, 47 },
-	 { 1, 1, 3, 9, 25, 13, 99, 249, 385 },
-	 
-	 /*90*/
-	 { 1, 3, 1, 9, 9, 13, 53, 195, 23 },
-	 { 1, 3, 5, 9, 7, 41, 83, 95, 117 },
-	 { 1, 1, 7, 13, 7, 25, 15, 63, 369 },
-	 { 1, 3, 1, 11, 27, 31, 31, 19, 425 },
-	 { 1, 3, 7, 3, 15, 9, 73, 7, 207 },
-	 
-	 { 1, 3, 5, 5, 25, 11, 115, 5, 433 },
-	 { 1, 1, 1, 11, 15, 19, 35, 75, 301 },
-	 { 1, 3, 7, 11, 21, 5, 21, 217, 147 },
-	 { 1, 1, 3, 13, 17, 53, 89, 245, 333 },
-	 { 1, 3, 1, 5, 19, 37, 5, 111, 85 }
-	 };
-
-
-SobolGenerator* SobolGenerator_NewFromTable( Name name ) {
-	static int        generatorCount                = 0;
-	Index             generatorIndex;
-
-	generatorIndex = generatorCount;
-
-	/* Make sure that the number generators used from this function is smaller than the number in the table */
-	Journal_Firewall(
-		generatorIndex < sizeof(SobolGenerator_PolynomialDegree)/sizeof(unsigned int),
-		Journal_Register( Error_Type, (Name)SobolGenerator_Type  ),
-		"Error in func '%s' - Trying to instantiate a %dth SobolGenerator ('%s') using table, "
-		"but only %d initial directional numbers have been implemented. Please contact developers.\n",
-		__func__, generatorIndex + 1, name, sizeof(SobolGenerator_PolynomialDegree)/sizeof(unsigned int) );
-	
-	generatorCount++;
-	/* If we reach the end of the array of generators, restart from the first one - PatrickSunter, 3 August 2006 */
-	if ( generatorCount >= (int)(sizeof(SobolGenerator_PolynomialDegree)/sizeof(unsigned int))) {
-		generatorCount = 0;
-	}
-		
-	return SobolGenerator_New( 
-			name,
-			SobolGenerator_PolynomialDegree[ generatorIndex ], 
-			SobolGenerator_PolynomialCoefficient[ generatorIndex ],
-			SobolGenerator_InitialDirectionNumbers[ generatorIndex ] );
-
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/SobolGenerator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/SobolGenerator.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,496 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: SobolGenerator.c 3745 2006-08-03 10:10:21Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <string.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "SobolGenerator.h"
+#include "DomainContext.h"
+
+#include <assert.h>
+
+const Type SobolGenerator_Type = "SobolGenerator";
+
+/* Some macros for clarity */
+#define BITS_IN_A_BYTE 8
+
+SobolGenerator* SobolGenerator_New( 
+			Name                                               name,
+			unsigned int                                       polynomialDegree,
+			unsigned int                                       polynomialCoefficient,
+			const unsigned int *                               initialDirectionNumbers )
+{
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(SobolGenerator);
+	Type                              type = SobolGenerator_Type;
+	Stg_Class_DeleteFunction*      _delete = _SobolGenerator_Delete;
+	Stg_Class_PrintFunction*        _print = _SobolGenerator_Print;
+	Stg_Class_CopyFunction*          _copy = _SobolGenerator_Copy;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	SobolGenerator* self = _SobolGenerator_New(  SOBOLGENERATOR_PASSARGS  );
+	_SobolGenerator_Init( self, polynomialDegree, polynomialCoefficient, initialDirectionNumbers );
+
+	return self;
+}
+
+SobolGenerator* _SobolGenerator_New(  SOBOLGENERATOR_DEFARGS  )
+{
+	SobolGenerator*		self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SobolGenerator) );
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (SobolGenerator*)_Stg_Object_New(  STG_OBJECT_PASSARGS  );
+
+	return self;
+}
+
+void _SobolGenerator_Init( 
+		SobolGenerator*                                    self,
+		unsigned int                                       polynomialDegree,
+		unsigned int                                       polynomialCoefficient,
+		const unsigned int *                               initialDirectionNumbers ) 
+{
+	unsigned int        directionNum_I;
+
+	self->directionalNumbersAlloced = 20;
+
+	self->directionalNumberIsCalc = Memory_Alloc_Array( Bool, self->directionalNumbersAlloced, "Calculate Flag" );
+	self->directionalNumberList   = Memory_Alloc_Array( unsigned int , self->directionalNumbersAlloced, "DirectionalNumbers" );
+	memset( self->directionalNumberIsCalc, 0, sizeof( Bool ) * self->directionalNumbersAlloced );
+
+	self->polynomialDegree      = polynomialDegree;
+	self->polynomialCoefficient = polynomialCoefficient;
+
+	memcpy( self->directionalNumberList, initialDirectionNumbers, polynomialDegree * sizeof( unsigned int ) );
+
+	self->lastCalculated_I = 0;
+	self->lastCalculatedNumber = 0.5;
+		
+	for ( directionNum_I = 0 ; directionNum_I < polynomialDegree ; directionNum_I++ )
+		self->directionalNumberIsCalc[ directionNum_I ] = True;
+	
+}
+
+
+void _SobolGenerator_Delete( void* sobolGenerator ) {
+	SobolGenerator* self = (SobolGenerator*) sobolGenerator;
+
+	Memory_Free( self->directionalNumberIsCalc );
+	Memory_Free( self->directionalNumberList );
+
+	_Stg_Object_Delete( self );
+}
+
+void _SobolGenerator_Print( void* sobolGenerator, Stream* stream ) {
+	SobolGenerator* self  = (SobolGenerator*) sobolGenerator;
+	unsigned int    index;
+
+	Journal_Printf( stream, "Sobol Generator: '%s'\n", self->name );
+	Stream_Indent( stream );
+
+	_Stg_Object_Print( self, stream );
+
+	Journal_PrintValue( stream, self->polynomialDegree );
+	Journal_PrintValue( stream, self->polynomialCoefficient );
+	Journal_Printf( stream, "This leads to polynomial: x^%u + ", self->polynomialDegree );
+	for ( index = self->polynomialDegree - 1 ; index > 0 ; index-- ) {
+		if ( self->polynomialCoefficient & 1 << (index - 1) )
+			Journal_Printf( stream, "x^%u + ", index );
+	}
+	Journal_Printf( stream, "1\n" );
+
+	Journal_PrintValue( stream, self->directionalNumbersAlloced );
+	Journal_Printf( stream, "Directional Numbers Calculated:\n" );
+	for ( index = 0 ; index < self->directionalNumbersAlloced ; index++ ) {
+		if ( self->directionalNumberIsCalc[ index ] )
+			Journal_Printf( stream, "\tDirectional Number %u = %lu\n", index, self->directionalNumberList[ index ] );
+	}
+
+	Journal_PrintValue( stream, self->lastCalculated_I );
+	Journal_PrintValue( stream, self->lastCalculatedNumber );
+	
+	Stream_UnIndent( stream );
+}
+
+void* _SobolGenerator_Copy( const void* sobolGenerator, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SobolGenerator*	self = (SobolGenerator*)sobolGenerator;
+	SobolGenerator*	newSobolGenerator;
+	
+	newSobolGenerator = (SobolGenerator*) _Stg_Object_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	newSobolGenerator->lastCalculated_I          = self->lastCalculated_I;
+	newSobolGenerator->lastCalculatedNumber      = self->lastCalculatedNumber;
+	newSobolGenerator->directionalNumbersAlloced = self->directionalNumbersAlloced;
+	newSobolGenerator->polynomialDegree          = self->polynomialDegree;
+	newSobolGenerator->polynomialCoefficient     = self->polynomialCoefficient ;
+	
+	if (deep) {
+		newSobolGenerator->directionalNumberIsCalc = Memory_Alloc_Array( Bool, self->directionalNumbersAlloced, "Flag" );
+		memcpy( newSobolGenerator->directionalNumberIsCalc, self->directionalNumberIsCalc, 
+				self->directionalNumbersAlloced * sizeof( Bool ) );
+
+		newSobolGenerator->directionalNumberList = Memory_Alloc_Array( unsigned int, self->directionalNumbersAlloced, "V_i" );
+		memcpy( newSobolGenerator->directionalNumberList, self->directionalNumberList, 
+				self->directionalNumbersAlloced * sizeof( unsigned int ) );
+	}
+	else {
+		newSobolGenerator->directionalNumberIsCalc      = self->directionalNumberIsCalc;
+		newSobolGenerator->directionalNumberList        = self->directionalNumberList;
+	}
+	
+	return (void*)newSobolGenerator;
+}
+
+Bit_Index _SobolGenerator_FindRightmostZeroBit( unsigned int number ) {
+	Bit_Index bit = 0;
+
+	while ( number & 1 ) {
+		/* Shift All bits to right by one */
+		number >>= 1;
+
+		/* Increment counter to find bit */
+		bit++;
+		assert( bit < sizeof( unsigned int ) * BITS_IN_A_BYTE );
+	}
+	return bit;
+}
+
+unsigned int  SobolGenerator_GetDirectionalNumber( void* sobolGenerator, unsigned int directionalNum_I ) {
+	SobolGenerator*	     self          = (SobolGenerator*)sobolGenerator;
+	unsigned int         result;
+	unsigned int         coefficient_I;
+	unsigned int         powerOfTwo;
+	Bit_Index            bitToTest;
+	unsigned int         directionNumber = 0;
+
+	if ( directionalNum_I >= self->directionalNumbersAlloced ) {
+		unsigned int  difference       = 10;
+		unsigned int  newNumberToAlloc = directionalNum_I + difference;
+		
+		/* Allocate More Memory */
+		self->directionalNumberIsCalc = Memory_Realloc_Array( self->directionalNumberIsCalc, Bool, newNumberToAlloc );
+		self->directionalNumberList   = Memory_Realloc_Array( self->directionalNumberList, unsigned int , newNumberToAlloc );
+
+		/* Set Bools */
+		memset( &self->directionalNumberIsCalc[ self->directionalNumbersAlloced ], 0, sizeof(Bool) * difference );
+		
+		self->directionalNumbersAlloced = newNumberToAlloc;
+	}
+	/* Check to see whether the directional number has already been calculated */
+	else if ( self->directionalNumberIsCalc[ directionalNum_I ] )
+		return self->directionalNumberList[ directionalNum_I ];
+
+	/* If the code hasn't precalculated all the directional numbers up to polynomialDegree then there is something wrong */
+	assert( directionalNum_I >= self->polynomialDegree );
+
+	/* Calculate Directional Number */
+	result = 0;
+	for ( coefficient_I = 0 ; coefficient_I < self->polynomialDegree ; coefficient_I++ ) {
+		/* Test for this coefficient is 1 */
+		bitToTest = self->polynomialDegree - 2 - coefficient_I;
+		if ( coefficient_I == self->polynomialDegree - 1 || self->polynomialCoefficient & 1 << bitToTest ) {
+			powerOfTwo = 0;
+			powerOfTwo |= 1 << (coefficient_I + 1);
+			
+			directionNumber = SobolGenerator_GetDirectionalNumber( self, directionalNum_I - 1 - coefficient_I );
+			result ^= powerOfTwo * directionNumber;
+		}
+	}
+	result ^= directionNumber;
+
+	self->directionalNumberIsCalc[ directionalNum_I ] = True;
+
+	return self->directionalNumberList[ directionalNum_I ] = result;
+}
+
+#define WORDLENGTH 30
+double SobolGenerator_GetNextNumber( void* sobolGenerator ) {
+	SobolGenerator*   self          = (SobolGenerator*)sobolGenerator;
+	Bit_Index         differentBit;
+	unsigned int      directionalNumber;
+
+	/* The Gray Code of the index last calculated quasi-random number will differ by only one bit 
+	 * from the Gray Code of the index of the current quasi-random number to calculate
+	 * this bit is the right most zero bit in lastCalcuated_I */
+	differentBit = _SobolGenerator_FindRightmostZeroBit( self->lastCalculated_I );
+
+	/* This bit can be used to find the next quasi-random number in Sobol's sequence 
+	 * x_{n+1} = x_{n} ^ v_{c}, where
+	 * x_{j} is the j^{th} quasi-random number in the sequence
+	 * v_{j} is the j^{th} directional number
+	 * c is the single different bit between the Gray codes for n and n+1 */
+
+	self->lastCalculated_I++;
+	directionalNumber = SobolGenerator_GetDirectionalNumber( self, differentBit );
+	directionalNumber <<= (WORDLENGTH - differentBit - 1);
+	self->lastCalculatedNumber ^= directionalNumber;
+
+	return (double) self->lastCalculatedNumber / (double) (1L << (WORDLENGTH));
+}
+	
+double SobolGenerator_GetNumberByIndex( void* sobolGenerator, unsigned int index ) {
+	SobolGenerator*   self          = (SobolGenerator*)sobolGenerator;
+	unsigned int      grayCode;
+	Bit_Index         bit_I;
+	unsigned int      directionalNumber;
+	unsigned int      result   =  0;
+
+	/* have to shift index because index 0 is the initial zero for the sequence to begin */
+	index++;
+
+	/* Get Gray Code of 'index' */
+	grayCode = index ^ (index >> 1);
+
+	for ( bit_I = 0 ; bit_I < sizeof( unsigned int ) * BITS_IN_A_BYTE ; bit_I++ ) {
+		if ( grayCode & 1 << bit_I ) {
+			directionalNumber = SobolGenerator_GetDirectionalNumber( self, bit_I );
+			directionalNumber <<= (WORDLENGTH - bit_I - 1);
+
+			result ^= directionalNumber;
+		}
+	}
+
+	return (double) result / (double) (1L << (WORDLENGTH));
+}
+
+double SobolGenerator_GetNextNumber_WithMinMax( void* sobolGenerator, double min, double max ) {
+	return (max - min) * SobolGenerator_GetNextNumber( sobolGenerator ) + min;
+}
+
+double SobolGenerator_GetNumberByIndex_WithMinMax( void* sobolGenerator, unsigned int index, double min, double max ) {
+	return (max - min) * SobolGenerator_GetNumberByIndex( sobolGenerator, index ) + min;
+}
+
+/* Some global variables that drive the random number generator */
+/* These numbers for initialisation come  from:
+ * Stephen Joe and Frances Y. Juo. Remark on Algorithm 659: Implementing Sobol¿s Quasirandom Sequence Generator. ACM Transactions on Mathematical Software, 29(1), March 2003.*/
+const unsigned int SobolGenerator_PolynomialDegree[] = {
+	1,2,3,3,4, 4,5,5,5,5,
+	5,5,6,6,6, 6,6,6,7,7,
+	7,7,7,7,7, 7,7,7,7,7,
+	7,7,7,7,7, 7,8,8,8,8,
+	8,8,8,8,8, 8,8,8,8,8,
+	
+	8,8,9,9,9, 9,9,9,9,9,
+	9,9,9,9,9, 9,9,9,9,9,
+	9,9,9,9,9, 9,9,9,9,9,
+	9,9,9,9,9, 9,9,9,9,9,
+	9,9,9,9,9, 9,9,9,9,9
+	};
+
+const unsigned int SobolGenerator_PolynomialCoefficient[] = {
+	0,1,1,2,1, 4,2,13,7,14,
+	11,4,1,16,13, 22,19,25,1,32,
+	4,8,7,56,14, 28,19,50,21,42,
+	31,62,37,41,55, 59,14,56,21,22,
+	38,47,49,50,52, 67,70,84,97,103,
+
+	115,122,8,13,16, 22,25,44,47,52,
+	55,59,62,67,74, 81,82,87,91,94,
+	103,104,109,122,124, 137,138,143,145,152,
+	157,167,173,176,181, 182,185,191,194,199,
+	218,220,227,229,230, 234,236,241,244,253
+	};
+
+const unsigned int SobolGenerator_InitialDirectionNumbers[][13] = {
+	 { 1 },
+	 { 1, 1 },
+	 { 1, 3, 7 },
+	 { 1, 1, 5 },
+	 { 1, 3, 1, 1 },
+
+	 { 1, 1, 3, 7 },
+	 { 1, 3, 3, 9, 9 },
+	 { 1, 3, 7, 13, 3 },
+	 { 1, 1, 5, 11, 27 },
+	 { 1, 3, 5, 1, 15 },
+
+	 /*10*/
+	 { 1, 1, 7, 3, 29 },
+	 { 1, 3, 7, 7, 21 },
+	 { 1, 1, 1, 9, 23, 37 },
+	 { 1, 3, 3, 5, 19, 33 },
+	 { 1, 1, 3, 13, 11, 7 },
+
+	 { 1, 1, 7, 13, 25, 5 },
+	 { 1, 3, 5, 11, 7, 11 },
+	 { 1, 1, 1, 3, 13, 39 },
+	 { 1, 3, 1, 15, 17, 63, 13 },
+	 { 1, 1, 5, 5, 1, 59, 33 },
+
+	 /*20*/
+	 { 1, 3, 3, 3, 25, 17, 115 },
+	 { 1, 1, 7, 15, 29, 15, 41 },
+	 { 1, 3, 1, 7, 3, 23, 79 },
+	 { 1, 3, 7, 9, 31, 29, 17 },
+	 { 1, 1, 5, 13, 11, 3, 29 },
+	 
+	 { 1, 1, 1, 9, 5, 21, 119 },
+	 { 1, 1, 3, 1, 23, 13, 75 },
+	 { 1, 3, 7, 11, 27, 31, 73 },
+	 { 1, 1, 7, 7, 19, 25, 105 },
+	 { 1, 3, 1, 5, 21, 9, 7 },
+	 
+	 /*30*/
+	 { 1, 1, 1, 15, 5, 49, 59 },
+	 { 1, 3, 1, 1, 1, 33, 65 },
+	 { 1, 3, 5, 15, 17, 19, 21 },
+	 { 1, 1, 7, 11, 13, 29, 3 },
+	 { 1, 3, 7, 5, 7, 11, 113 },
+	 
+	 { 1, 1, 5, 11, 15, 19, 61 },
+	 { 1, 1, 1, 1, 9, 27, 89, 7 },
+	 { 1, 1, 3, 7, 31, 15, 45, 23 },
+	 { 1, 3, 3, 9, 25, 25, 107, 39 },
+	 { 1, 1, 7, 7, 3, 63, 21, 217 },
+	 
+	 /*40*/
+	 { 1, 3, 5, 7, 5, 55, 71, 141 },
+	 { 1, 1, 5, 1, 23, 17, 79, 27 },
+	 { 1, 1, 5, 15, 7, 63, 19, 53 },
+	 { 1, 1, 3, 15, 3, 49, 71, 181 },
+	 { 1, 3, 3, 15, 17, 19, 61, 169 },
+	 
+	 { 1, 3, 3, 13, 23, 41, 41, 35 },
+	 { 1, 1, 1, 3, 3, 59, 57, 15 },
+	 { 1, 3, 1, 3, 3, 3, 121, 207 },
+	 { 1, 3, 5, 15, 21, 57, 87, 45 },
+	 { 1, 1, 1, 5, 25, 33, 119, 247 },
+	 
+	 /*50*/
+	 { 1, 1, 1, 9, 25, 49, 55, 185 },
+	 { 1, 3, 5, 7, 23, 53, 85, 117 },
+	 { 1, 3, 3, 13, 11, 57, 121, 41, 235 },
+	 { 1, 1, 3, 3, 19, 57, 119, 81, 307 },
+	 { 1, 3, 3, 7, 3, 39, 11, 223, 495 },
+	 
+	 { 1, 3, 3, 5, 11, 21, 23, 151, 417 },
+	 { 1, 3, 1, 11, 31, 7, 61, 81, 57 },
+	 { 1, 1, 3, 9, 7, 53, 11, 189, 151 },
+	 { 1, 3, 7, 1, 9, 9, 35, 61, 19 },
+	 { 1, 1, 5, 9, 5, 55, 33, 95, 119 },
+	 
+	 /*60*/
+	 { 1, 3, 7, 1, 17, 15, 43, 185, 375 },
+	 { 1, 1, 3, 5, 23, 59, 107, 23, 451 },
+	 { 1, 1, 7, 7, 17, 19, 113, 73, 55 },
+	 { 1, 3, 1, 13, 17, 49, 101, 113, 449 },
+	 { 1, 3, 3, 9, 25, 31, 29, 239, 501 },
+	 
+	 { 1, 1, 3, 9, 13, 3, 87, 85, 53 },
+	 { 1, 1, 5, 1, 11, 39, 119, 9, 185 },
+	 { 1, 1, 1, 7, 31, 5, 97, 201, 317 },
+	 { 1, 1, 3, 3, 27, 5, 29, 83, 17 },
+	 { 1, 3, 5, 5, 19, 41, 17, 53, 21 },
+	 
+	 /*70*/
+	 { 1, 1, 5, 1, 17, 9, 89, 183, 487 },
+	 { 1, 1, 7, 11, 23, 19, 5, 203, 13 },
+	 { 1, 3, 7, 11, 7, 9, 127, 91, 347 },
+	 { 1, 1, 7, 13, 5, 57, 89, 149, 393 },
+	 { 1, 1, 1, 7, 11, 25, 119, 101, 15 },
+	 
+	 { 1, 1, 1, 7, 19, 1, 117, 13, 391 },
+	 { 1, 3, 3, 9, 19, 15, 103, 111, 307 },
+	 { 1, 3, 3, 9, 7, 51, 105, 239, 189 },
+	 { 1, 1, 1, 1, 13, 11, 41, 3, 381 },
+	 { 1, 3, 1, 1, 21, 19, 83, 205, 71 },
+	 
+	 /*80*/
+	 { 1, 3, 5, 3, 21, 61, 25, 253, 163 },
+	 { 1, 1, 1, 9, 7, 53, 41, 247, 99 },
+	 { 1, 3, 5, 15, 9, 29, 55, 121, 467 },
+	 { 1, 3, 7, 1, 11, 19, 69, 189, 167 },
+	 { 1, 3, 5, 5, 1, 11, 117, 169, 433 },
+	 
+	 { 1, 1, 1, 13, 5, 9, 49, 179, 337 },
+	 { 1, 3, 7, 1, 21, 21, 127, 197, 257 },
+	 { 1, 3, 5, 9, 11, 19, 29, 175, 179 },
+	 { 1, 3, 3, 9, 13, 43, 1, 217, 47 },
+	 { 1, 1, 3, 9, 25, 13, 99, 249, 385 },
+	 
+	 /*90*/
+	 { 1, 3, 1, 9, 9, 13, 53, 195, 23 },
+	 { 1, 3, 5, 9, 7, 41, 83, 95, 117 },
+	 { 1, 1, 7, 13, 7, 25, 15, 63, 369 },
+	 { 1, 3, 1, 11, 27, 31, 31, 19, 425 },
+	 { 1, 3, 7, 3, 15, 9, 73, 7, 207 },
+	 
+	 { 1, 3, 5, 5, 25, 11, 115, 5, 433 },
+	 { 1, 1, 1, 11, 15, 19, 35, 75, 301 },
+	 { 1, 3, 7, 11, 21, 5, 21, 217, 147 },
+	 { 1, 1, 3, 13, 17, 53, 89, 245, 333 },
+	 { 1, 3, 1, 5, 19, 37, 5, 111, 85 }
+	 };
+
+
+SobolGenerator* SobolGenerator_NewFromTable( Name name ) {
+	static int        generatorCount                = 0;
+	Index             generatorIndex;
+
+	generatorIndex = generatorCount;
+
+	/* Make sure that the number generators used from this function is smaller than the number in the table */
+	Journal_Firewall(
+		generatorIndex < sizeof(SobolGenerator_PolynomialDegree)/sizeof(unsigned int),
+		Journal_Register( Error_Type, (Name)SobolGenerator_Type  ),
+		"Error in func '%s' - Trying to instantiate a %dth SobolGenerator ('%s') using table, "
+		"but only %d initial directional numbers have been implemented. Please contact developers.\n",
+		__func__, generatorIndex + 1, name, sizeof(SobolGenerator_PolynomialDegree)/sizeof(unsigned int) );
+	
+	generatorCount++;
+	/* If we reach the end of the array of generators, restart from the first one - PatrickSunter, 3 August 2006 */
+	if ( generatorCount >= (int)(sizeof(SobolGenerator_PolynomialDegree)/sizeof(unsigned int))) {
+		generatorCount = 0;
+	}
+		
+	return SobolGenerator_New( 
+			name,
+			SobolGenerator_PolynomialDegree[ generatorIndex ], 
+			SobolGenerator_PolynomialCoefficient[ generatorIndex ],
+			SobolGenerator_InitialDirectionNumbers[ generatorIndex ] );
+
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/TimeIntegrand.c
--- a/Utils/src/TimeIntegrand.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,612 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student Monash University, VPAC. (davidm at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TimeIntegrand.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "DomainContext.h"
-#include "TimeIntegrator.h"
-#include "TimeIntegrand.h"
-#include "FieldVariable.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type TimeIntegrand_Type = "TimeIntegrand";
-
-TimeIntegrand* TimeIntegrand_New( 
-		Name                                       name,
-		DomainContext*                             context,
-		TimeIntegrator*                            timeIntegrator, 
-		Variable*                                  variable,
-		Index                                      dataCount, 
-		Stg_Component**                            data,
-		Bool                                       allowFallbackToFirstOrder )
-{
-	TimeIntegrand*	self;
-
-	self = (TimeIntegrand*) _TimeIntegrand_DefaultNew( name );
-	_TimeIntegrand_Init( self, context, timeIntegrator, variable, dataCount, data, allowFallbackToFirstOrder );
-	return self;
-}
-
-TimeIntegrand* _TimeIntegrand_New(  TIMEINTEGRAND_DEFARGS  )
-{
-	TimeIntegrand*	self;
-	
-	assert( _sizeOfSelf >= sizeof(TimeIntegrand) );
-	
-	/* General info */
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (TimeIntegrand*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	/* virtual info */
-	self->_calculateTimeDeriv = _calculateTimeDeriv;
-	self->_intermediate = _intermediate;
-	
-	return self;
-}
-
-void _TimeIntegrand_Init( 
-		void*                                      timeIntegrand,
-		DomainContext*                             context,
-		TimeIntegrator*                            timeIntegrator, 
-		Variable*                                  variable, 
-		Index                                      dataCount, 
-		Stg_Component**                            data,
-		Bool                                       allowFallbackToFirstOrder )
-{
-	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
-
-   self->context        = context;
-	self->debug          = Journal_Register( Debug_Type, (Name)self->type  );
-	self->variable       = variable;
-	self->dataCount      = dataCount;
-	self->timeIntegrator = timeIntegrator;
-	self->data           = Memory_Alloc_Array( Stg_Component*, dataCount, "data" );
-	self->allowFallbackToFirstOrder = allowFallbackToFirstOrder;
-	memcpy( self->data, data, dataCount * sizeof(Stg_Component*) );
-
-	TimeIntegrator_Add( timeIntegrator, self );
-}
-
-void _TimeIntegrand_Delete( void* timeIntegrand ) {
-	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	_Stg_Component_Delete( self );
-}
-
-void _TimeIntegrand_Print( void* timeIntegrand, Stream* stream ) {
-	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
-
-	/* General info */
-	Journal_DPrintf( self->debug, "TimeIntegrand - '%s'\n", self->name );
-	Journal_PrintPointer( stream, self );
-	Stream_Indent( stream );
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-	
-	/* Virtual info */
-
-	/* Regular Info */
-	
-	Stream_UnIndent( stream );
-}
-
-void* _TimeIntegrand_Copy( const void* timeIntegrand, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	TimeIntegrand*	self = (TimeIntegrand*)timeIntegrand;
-	TimeIntegrand*	newTimeIntegrand;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-	/* TODO */ abort();
-
-	return (void*)newTimeIntegrand;
-}
-
-void* _TimeIntegrand_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(TimeIntegrand);
-	Type                                                       type = TimeIntegrand_Type;
-	Stg_Class_DeleteFunction*                               _delete = _TimeIntegrand_Delete;
-	Stg_Class_PrintFunction*                                 _print = _TimeIntegrand_Print;
-	Stg_Class_CopyFunction*                                   _copy = _TimeIntegrand_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _TimeIntegrand_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _TimeIntegrand_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _TimeIntegrand_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _TimeIntegrand_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _TimeIntegrand_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _TimeIntegrand_Destroy;
-	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _TimeIntegrand_AdvectionTimeDeriv;
-	TimeIntegrand_IntermediateFunction*              _intermediate = _TimeIntegrand_Intermediate;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
-}
-
-void _TimeIntegrand_AssignFromXML( void* timeIntegrand, Stg_ComponentFactory* cf, void* data ) {
-	TimeIntegrand*         self                    = (TimeIntegrand*)timeIntegrand;
-	Index                   dataCount               = 0;
-	Stg_Component**         initData                = NULL;
-	Variable*               variable                = NULL;
-	TimeIntegrator*         timeIntegrator          = NULL;
-	Bool                    allowFallbackToFirstOrder = False;
-	DomainContext*          context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
-	if( !self->context  )
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-	
-	variable       =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)Variable_Type, Variable, False, data  ) ;
-	timeIntegrator =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)TimeIntegrator_Type, TimeIntegrator, True, data  ) ;
-	initData = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"data", Stg_ComponentFactory_Unlimited, Stg_Component, False, &dataCount, data  );
-	allowFallbackToFirstOrder = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"allowFallbackToFirstOrder", False  );	
-
-	_TimeIntegrand_Init( self, context, timeIntegrator, variable, dataCount, initData, allowFallbackToFirstOrder );
-
-	if( initData != NULL )
-		Memory_Free( initData );
-}
-
-void _TimeIntegrand_Build( void* timeIntegrand, void* data ) {
-	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	Stg_Component_Build( self->variable, NULL, False );
-}
-
-void _TimeIntegrand_Initialise( void* timeIntegrand, void* data ) {
-	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-   if ( self->context->loadFromCheckPoint == False ) Stg_Component_Initialise( self->variable, NULL, False );
-}
-
-void _TimeIntegrand_Execute( void* timeIntegrand, void* data ) {
-	TimeIntegrand*	self = (TimeIntegrand*)timeIntegrand;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-}
-	
-void _TimeIntegrand_Destroy( void* timeIntegrand, void* data ) {
-	TimeIntegrand*	self = (TimeIntegrand*)timeIntegrand;
-   	
-	Memory_Free( self->data );
-
-}
-
-/* +++ Virtual Functions +++ */
-void TimeIntegrand_FirstOrder( void* timeIntegrand, Variable* startValue, double dt ) {
-	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
-	Variable*       variable       = self->variable;
-	double*         arrayDataPtr;
-	double*         startDataPtr;
-	double**        timeDeriv;
-	Index           component_I; 
-	Index           componentCount = *variable->dataTypeCounts;
-	Index           array_I; 
-	Index           arrayCount;
-	Bool            successFlag = False;
-	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	Journal_DPrintf( self->debug, "In func %s for %s '%s'\n", __func__, self->type, self->name );
-
-	/* Update Variables */
-	Variable_Update( variable );
-	Variable_Update( startValue );
-	arrayCount     = variable->arraySize;
-
-	timeDeriv = Memory_Alloc_2DArray( double, arrayCount, componentCount, (Name)"Time Deriv" );
-	for( array_I = 0; array_I < arrayCount; array_I++  ) {
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv[array_I] );
-		Journal_Firewall( True == successFlag, errorStream,
-			"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-			"deriv for item %u in step %u, *failed*.\n",
-			__func__, self->name, self->type, array_I, 1 );
-	}
-
-	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
-		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
-		
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-			arrayDataPtr[ component_I ] = startDataPtr[ component_I ] + dt * timeDeriv[array_I][ component_I ];
-		}
-	
-		TimeIntegrand_Intermediate( self, array_I );
-	}
-
-	Memory_Free( timeDeriv );
-}
-
-void TimeIntegrand_SecondOrder( void* timeIntegrand, Variable* startValue, double dt ) {
-	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
-	Variable*       variable       = self->variable;
-	double*         arrayDataPtr;
-	double*         startDataPtr;
-	double*         timeDeriv;
-	double*         startData;
-	Index           component_I; 
-	Index           componentCount = *variable->dataTypeCounts;
-	Index           array_I; 
-	Index           arrayCount;
-	double          startTime      = TimeIntegrator_GetTime( self->timeIntegrator );
-	Bool            successFlag = False;
-	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	timeDeriv = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
-	startData = Memory_Alloc_Array( double, componentCount, "StartData" );
-	memset( timeDeriv, 0, componentCount * sizeof( double ) );
-	memset( startData, 0, componentCount * sizeof( double ) );
-	
-	/* Update Variables */
-	Variable_Update( variable );
-	Variable_Update( startValue );
-	arrayCount     = variable->arraySize;
-	
-	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
-		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
-
-		TimeIntegrator_SetTime( self->timeIntegrator, startTime );
-
-		/* Store Original Value in case startValue == self->variable */
-		memcpy( startData, startDataPtr, sizeof( double ) * componentCount );
-
-		/* Do Predictor Step */
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-		Journal_Firewall( True == successFlag, errorStream,
-			"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-			"deriv for item %u in step %u, *failed*.\n",
-			__func__, self->name, self->type, array_I, 1 );
-		
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
-			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
-		TimeIntegrand_Intermediate( self, array_I );
-
-		TimeIntegrator_SetTime( self->timeIntegrator, startTime + 0.5 * dt );
-
-		/* Do Corrector Step */
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-
-		if ( True == successFlag ) {
-			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
-				arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
-			
-			TimeIntegrand_Intermediate( self, array_I );
-		}
-		else {
-			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
-				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
-				"not enabled.\n", __func__, self->name, self->type, array_I, 2 );
-				
-			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
-				arrayDataPtr, startData, startTime, dt,
-				timeDeriv, array_I );
-		}
-	}
-
-	Memory_Free( timeDeriv );
-	Memory_Free( startData );
-}
-
-void TimeIntegrand_FourthOrder( void* timeIntegrand, Variable* startValue, double dt ) {
-	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
-	Variable*       variable       = self->variable;
-	double*         arrayDataPtr;
-	double*         startDataPtr;
-	double*         timeDeriv;
-	double*         finalTimeDeriv;
-	double*         startData;
-	Index           component_I; 
-	Index           componentCount = *variable->dataTypeCounts;
-	Index           array_I; 
-	Index           arrayCount;
-	double          startTime      = TimeIntegrator_GetTime( self->timeIntegrator );
-	Bool            successFlag = False;
-	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type  );
-
-	timeDeriv      = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
-	startData      = Memory_Alloc_Array( double, componentCount, "StartData" );
-	finalTimeDeriv = Memory_Alloc_Array( double, componentCount, "StartData" );
-	memset( timeDeriv,      0, componentCount * sizeof( double ) );
-	memset( startData,      0, componentCount * sizeof( double ) );
-	memset( finalTimeDeriv, 0, componentCount * sizeof( double ) );
-	
-	/* Update Variables */
-	Variable_Update( variable );
-	Variable_Update( startValue );
-	arrayCount     = variable->arraySize;
-	
-	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
-		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
-		
-		TimeIntegrator_SetTime( self->timeIntegrator, startTime );
-
-		/* Store Original Value in case startValue == self->variable */
-		memcpy( startData, startDataPtr, sizeof( double ) * componentCount );
-
-		/* Do first Step - store K1 in finalTimeDeriv and update for next step */
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, finalTimeDeriv );
-		Journal_Firewall( True == successFlag, errorStream,
-			"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-			"deriv for item %u in step %u, *failed*.\n",
-			__func__, self->name, self->type, array_I, 1 );
-
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
-			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * finalTimeDeriv[ component_I ];
-		TimeIntegrand_Intermediate( self, array_I );
-
-		TimeIntegrator_SetTime( self->timeIntegrator, startTime + 0.5 * dt );
-
-		/* Do Second Step - add 2xK2 value to finalTimeDeriv and update for next step */
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-		if ( True == successFlag ) {
-			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-				arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
-				finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
-			}
-			TimeIntegrand_Intermediate( self, array_I );
-		}
-		else {
-			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
-				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
-				"not enabled.\n", __func__, self->name, self->type, array_I, 2 );
-				
-			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
-				arrayDataPtr, startData, startTime, dt,
-				timeDeriv, array_I );
-		}
-
-		/* Do Third Step - add 2xK3 value to finalTimeDeriv and update for next step */
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-		if ( True == successFlag ) {
-			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-				arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
-				finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
-			}
-			TimeIntegrand_Intermediate( self, array_I );
-		}
-		else {
-			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
-				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
-				"not enabled.\n", __func__, self->name, self->type, array_I, 3 );
-				
-			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
-				arrayDataPtr, startData, startTime, dt,
-				timeDeriv, array_I );
-		}
-
-		TimeIntegrator_SetTime( self->timeIntegrator, startTime + dt );
-
-		/* Do Fourth Step - 'K1 + 2K2 + 2K3' and K4 finalTimeDeriv to find final value */
-		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-		if ( True == successFlag ) {
-			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-				arrayDataPtr[ component_I ] = startData[ component_I ] + 
-					dt/6.0 * (timeDeriv[ component_I ] + finalTimeDeriv[ component_I ] );
-			}		
-			TimeIntegrand_Intermediate( self, array_I );
-		}
-		else {
-			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
-				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
-				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
-				"not enabled.\n", __func__, self->name, self->type, array_I, 4 );
-				
-			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
-				arrayDataPtr, startData, startTime, dt,
-				timeDeriv, array_I );
-		}
-	}
-
-	Memory_Free( timeDeriv );
-	Memory_Free( startData );
-	Memory_Free( finalTimeDeriv );
-}
-
-
-/* Note : this function is used to apply to just one item/particle - see the array_I parameter */
-void _TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( 
-		TimeIntegrand* self,
-		double*         arrayDataPtr,
-		double*         startData,
-		double          startTime,
-		double          dt,
-		double*         timeDeriv,
-		Index           array_I )
-{
-	Variable*       variable       = self->variable;
-	Index           component_I; 
-	Index           componentCount = *variable->dataTypeCounts;
-	Bool            successFlag = False;
-
-	/* First, go back to initial positions, so we can re-calculate the time derivative there */
-	for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-		arrayDataPtr[ component_I ] = startData[ component_I ];
-	}	
-	TimeIntegrand_Intermediate( self, array_I );
-
-	/* Now recalculate time deriv at start positions, then do a full dt first order update from
-	 * there */
-	TimeIntegrator_SetTime( self->timeIntegrator, startTime );
-	successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-	for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
-		arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
-	TimeIntegrand_Intermediate( self, array_I );
-}
-
-
-/** +++ Sample Time Deriv Functions +++ **/
-
-
-/** This function assumes that
- *            the ODE that we are solving is \dot \phi = u(x,y) 
- *            the velocity Field Variable is stored in data[0]
- *            the variable being updated is the global coordinate of the object */
-Bool _TimeIntegrand_AdvectionTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-	TimeIntegrand*	     self          = (TimeIntegrand*) timeIntegrand;
-	FieldVariable*       velocityField = (FieldVariable*)  self->data[0];
-	double*              coord;
-	InterpolationResult  result;
-
-	/* Get Coordinate of Object using Variable */
-	coord = Variable_GetPtrDouble( self->variable, array_I );
-
-	result = FieldVariable_InterpolateValueAt( velocityField, coord, timeDeriv );
-
-	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
-			( velocityField->dim == 3 && isinf(timeDeriv[2]) ) ) 
-	{
-		#if 0
-		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ),
-			"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelocity here is (%g, %g, %g)."
-			"\n\tInterpolation result is %s.\n",
-			__func__, array_I, coord[0], coord[1], coord[2], 
-			timeDeriv[0], timeDeriv[1], ( velocityField->dim == 3 ? timeDeriv[2] : 0.0 ),
-			InterpolationResultToStringMap[result]  );
-		return False;	
-		#endif
-	}
-
-	return True;
-}
-
-
-void _TimeIntegrand_Intermediate( void* timeIntegrand, Index array_I ) {}
-
-/* +++ Public Functions +++ */
-void TimeIntegrand_StoreTimeDeriv( void* timeIntegrand, Variable* timeDeriv ) {
-	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
-	double*         arrayDataPtr;
-	Index           array_I; 
-	Index           arrayCount;
-
-	/* Update Variable */
-	Variable_Update( timeDeriv );
-	arrayCount = timeDeriv->arraySize;
-
-	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		arrayDataPtr = Variable_GetPtrDouble( timeDeriv, array_I );
-		TimeIntegrand_CalculateTimeDeriv( self, array_I, arrayDataPtr );
-	}
-}
-
-void TimeIntegrand_Add2TimesTimeDeriv( void* timeIntegrand, Variable* timeDerivVariable ) {
-	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
-	Variable*       variable       = self->variable;
-	double*         timeDerivPtr;
-	double*         timeDeriv;
-	Index           component_I; 
-	Index           componentCount = *variable->dataTypeCounts;
-	Index           array_I; 
-	Index           arrayCount;
-
-	timeDeriv = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
-	memset( timeDeriv,      0, componentCount * sizeof( double ) );
-	
-	/* Update Variables */
-	Variable_Update( variable );
-	Variable_Update( timeDerivVariable );
-	arrayCount = variable->arraySize;
-	
-	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
-		timeDerivPtr = Variable_GetPtrDouble( timeDerivVariable, array_I );
-		
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-			timeDerivPtr[ component_I ] += 2.0 * timeDeriv[ component_I ];
-		}
-	}
-
-	Memory_Free( timeDeriv );
-}
-	
-
-void TimeIntegrand_FourthOrderFinalStep( void* timeIntegrand, Variable* startData, Variable* timeDerivVariable, double dt ) {
-	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
-	Variable*       variable       = self->variable;
-	double*         k4;
-	double*         k1_2k2_2k3;
-	double*         startPtr;
-	double*         arrayPtr;
-	Index           component_I; 
-	Index           componentCount = *variable->dataTypeCounts;
-	Index           array_I; 
-	Index           arrayCount;
-
-	k4 = Memory_Alloc_Array( double, componentCount, "k4 Time Deriv" );
-	memset( k4, 0, componentCount * sizeof( double ) );
-	
-	/* Update Variables */
-	Variable_Update( variable );
-	Variable_Update( startData );
-	Variable_Update( timeDerivVariable );
-	arrayCount     = variable->arraySize;
-	
-	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
-		TimeIntegrand_CalculateTimeDeriv( self, array_I, k4 );
-
-		k1_2k2_2k3 = Variable_GetPtrDouble( timeDerivVariable, array_I );
-		arrayPtr = Variable_GetPtrDouble( variable, array_I );
-		startPtr = Variable_GetPtrDouble( startData, array_I );
-		
-		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
-			arrayPtr[ component_I ] = startPtr[ component_I ] + dt/6.0 * ( k4[ component_I ] + k1_2k2_2k3[ component_I ] );
-		}
-		TimeIntegrand_Intermediate( self, array_I );
-	}
-
-	Memory_Free( k4 );
-}
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/TimeIntegrand.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/TimeIntegrand.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,612 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student Monash University, VPAC. (davidm at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TimeIntegrand.c 4137 2007-06-07 05:46:46Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "DomainContext.h"
+#include "TimeIntegrator.h"
+#include "TimeIntegrand.h"
+#include "FieldVariable.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type TimeIntegrand_Type = "TimeIntegrand";
+
+TimeIntegrand* TimeIntegrand_New( 
+		Name                                       name,
+		DomainContext*                             context,
+		TimeIntegrator*                            timeIntegrator, 
+		Variable*                                  variable,
+		Index                                      dataCount, 
+		Stg_Component**                            data,
+		Bool                                       allowFallbackToFirstOrder )
+{
+	TimeIntegrand*	self;
+
+	self = (TimeIntegrand*) _TimeIntegrand_DefaultNew( name );
+	_TimeIntegrand_Init( self, context, timeIntegrator, variable, dataCount, data, allowFallbackToFirstOrder );
+	return self;
+}
+
+TimeIntegrand* _TimeIntegrand_New(  TIMEINTEGRAND_DEFARGS  )
+{
+	TimeIntegrand*	self;
+	
+	assert( _sizeOfSelf >= sizeof(TimeIntegrand) );
+	
+	/* General info */
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (TimeIntegrand*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	/* virtual info */
+	self->_calculateTimeDeriv = _calculateTimeDeriv;
+	self->_intermediate = _intermediate;
+	
+	return self;
+}
+
+void _TimeIntegrand_Init( 
+		void*                                      timeIntegrand,
+		DomainContext*                             context,
+		TimeIntegrator*                            timeIntegrator, 
+		Variable*                                  variable, 
+		Index                                      dataCount, 
+		Stg_Component**                            data,
+		Bool                                       allowFallbackToFirstOrder )
+{
+	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
+
+   self->context        = context;
+	self->debug          = Journal_Register( Debug_Type, (Name)self->type  );
+	self->variable       = variable;
+	self->dataCount      = dataCount;
+	self->timeIntegrator = timeIntegrator;
+	self->data           = Memory_Alloc_Array( Stg_Component*, dataCount, "data" );
+	self->allowFallbackToFirstOrder = allowFallbackToFirstOrder;
+	memcpy( self->data, data, dataCount * sizeof(Stg_Component*) );
+
+	TimeIntegrator_Add( timeIntegrator, self );
+}
+
+void _TimeIntegrand_Delete( void* timeIntegrand ) {
+	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	_Stg_Component_Delete( self );
+}
+
+void _TimeIntegrand_Print( void* timeIntegrand, Stream* stream ) {
+	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
+
+	/* General info */
+	Journal_DPrintf( self->debug, "TimeIntegrand - '%s'\n", self->name );
+	Journal_PrintPointer( stream, self );
+	Stream_Indent( stream );
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+	
+	/* Virtual info */
+
+	/* Regular Info */
+	
+	Stream_UnIndent( stream );
+}
+
+void* _TimeIntegrand_Copy( const void* timeIntegrand, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	TimeIntegrand*	self = (TimeIntegrand*)timeIntegrand;
+	TimeIntegrand*	newTimeIntegrand;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+	/* TODO */ abort();
+
+	return (void*)newTimeIntegrand;
+}
+
+void* _TimeIntegrand_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(TimeIntegrand);
+	Type                                                       type = TimeIntegrand_Type;
+	Stg_Class_DeleteFunction*                               _delete = _TimeIntegrand_Delete;
+	Stg_Class_PrintFunction*                                 _print = _TimeIntegrand_Print;
+	Stg_Class_CopyFunction*                                   _copy = _TimeIntegrand_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _TimeIntegrand_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _TimeIntegrand_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _TimeIntegrand_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _TimeIntegrand_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _TimeIntegrand_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _TimeIntegrand_Destroy;
+	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _TimeIntegrand_AdvectionTimeDeriv;
+	TimeIntegrand_IntermediateFunction*              _intermediate = _TimeIntegrand_Intermediate;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
+}
+
+void _TimeIntegrand_AssignFromXML( void* timeIntegrand, Stg_ComponentFactory* cf, void* data ) {
+	TimeIntegrand*         self                    = (TimeIntegrand*)timeIntegrand;
+	Index                   dataCount               = 0;
+	Stg_Component**         initData                = NULL;
+	Variable*               variable                = NULL;
+	TimeIntegrator*         timeIntegrator          = NULL;
+	Bool                    allowFallbackToFirstOrder = False;
+	DomainContext*          context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
+	if( !self->context  )
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+	
+	variable       =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)Variable_Type, Variable, False, data  ) ;
+	timeIntegrator =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)TimeIntegrator_Type, TimeIntegrator, True, data  ) ;
+	initData = Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)"data", Stg_ComponentFactory_Unlimited, Stg_Component, False, &dataCount, data  );
+	allowFallbackToFirstOrder = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"allowFallbackToFirstOrder", False  );	
+
+	_TimeIntegrand_Init( self, context, timeIntegrator, variable, dataCount, initData, allowFallbackToFirstOrder );
+
+	if( initData != NULL )
+		Memory_Free( initData );
+}
+
+void _TimeIntegrand_Build( void* timeIntegrand, void* data ) {
+	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	Stg_Component_Build( self->variable, NULL, False );
+}
+
+void _TimeIntegrand_Initialise( void* timeIntegrand, void* data ) {
+	TimeIntegrand* self = (TimeIntegrand*)timeIntegrand;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+   if ( self->context->loadFromCheckPoint == False ) Stg_Component_Initialise( self->variable, NULL, False );
+}
+
+void _TimeIntegrand_Execute( void* timeIntegrand, void* data ) {
+	TimeIntegrand*	self = (TimeIntegrand*)timeIntegrand;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+}
+	
+void _TimeIntegrand_Destroy( void* timeIntegrand, void* data ) {
+	TimeIntegrand*	self = (TimeIntegrand*)timeIntegrand;
+   	
+	Memory_Free( self->data );
+
+}
+
+/* +++ Virtual Functions +++ */
+void TimeIntegrand_FirstOrder( void* timeIntegrand, Variable* startValue, double dt ) {
+	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
+	Variable*       variable       = self->variable;
+	double*         arrayDataPtr;
+	double*         startDataPtr;
+	double**        timeDeriv;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Index           array_I; 
+	Index           arrayCount;
+	Bool            successFlag = False;
+	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	Journal_DPrintf( self->debug, "In func %s for %s '%s'\n", __func__, self->type, self->name );
+
+	/* Update Variables */
+	Variable_Update( variable );
+	Variable_Update( startValue );
+	arrayCount     = variable->arraySize;
+
+	timeDeriv = Memory_Alloc_2DArray( double, arrayCount, componentCount, (Name)"Time Deriv" );
+	for( array_I = 0; array_I < arrayCount; array_I++  ) {
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv[array_I] );
+		Journal_Firewall( True == successFlag, errorStream,
+			"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+			"deriv for item %u in step %u, *failed*.\n",
+			__func__, self->name, self->type, array_I, 1 );
+	}
+
+	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
+		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
+		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
+		
+		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+			arrayDataPtr[ component_I ] = startDataPtr[ component_I ] + dt * timeDeriv[array_I][ component_I ];
+		}
+	
+		TimeIntegrand_Intermediate( self, array_I );
+	}
+
+	Memory_Free( timeDeriv );
+}
+
+void TimeIntegrand_SecondOrder( void* timeIntegrand, Variable* startValue, double dt ) {
+	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
+	Variable*       variable       = self->variable;
+	double*         arrayDataPtr;
+	double*         startDataPtr;
+	double*         timeDeriv;
+	double*         startData;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Index           array_I; 
+	Index           arrayCount;
+	double          startTime      = TimeIntegrator_GetTime( self->timeIntegrator );
+	Bool            successFlag = False;
+	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	timeDeriv = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
+	startData = Memory_Alloc_Array( double, componentCount, "StartData" );
+	memset( timeDeriv, 0, componentCount * sizeof( double ) );
+	memset( startData, 0, componentCount * sizeof( double ) );
+	
+	/* Update Variables */
+	Variable_Update( variable );
+	Variable_Update( startValue );
+	arrayCount     = variable->arraySize;
+	
+	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
+		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
+		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
+
+		TimeIntegrator_SetTime( self->timeIntegrator, startTime );
+
+		/* Store Original Value in case startValue == self->variable */
+		memcpy( startData, startDataPtr, sizeof( double ) * componentCount );
+
+		/* Do Predictor Step */
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+		Journal_Firewall( True == successFlag, errorStream,
+			"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+			"deriv for item %u in step %u, *failed*.\n",
+			__func__, self->name, self->type, array_I, 1 );
+		
+		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
+			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
+		TimeIntegrand_Intermediate( self, array_I );
+
+		TimeIntegrator_SetTime( self->timeIntegrator, startTime + 0.5 * dt );
+
+		/* Do Corrector Step */
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
+				arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
+			
+			TimeIntegrand_Intermediate( self, array_I );
+		}
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 2 );
+				
+			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
+	}
+
+	Memory_Free( timeDeriv );
+	Memory_Free( startData );
+}
+
+void TimeIntegrand_FourthOrder( void* timeIntegrand, Variable* startValue, double dt ) {
+	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
+	Variable*       variable       = self->variable;
+	double*         arrayDataPtr;
+	double*         startDataPtr;
+	double*         timeDeriv;
+	double*         finalTimeDeriv;
+	double*         startData;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Index           array_I; 
+	Index           arrayCount;
+	double          startTime      = TimeIntegrator_GetTime( self->timeIntegrator );
+	Bool            successFlag = False;
+	Stream*         errorStream = Journal_Register( Error_Type, (Name)self->type  );
+
+	timeDeriv      = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
+	startData      = Memory_Alloc_Array( double, componentCount, "StartData" );
+	finalTimeDeriv = Memory_Alloc_Array( double, componentCount, "StartData" );
+	memset( timeDeriv,      0, componentCount * sizeof( double ) );
+	memset( startData,      0, componentCount * sizeof( double ) );
+	memset( finalTimeDeriv, 0, componentCount * sizeof( double ) );
+	
+	/* Update Variables */
+	Variable_Update( variable );
+	Variable_Update( startValue );
+	arrayCount     = variable->arraySize;
+	
+	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
+		arrayDataPtr = Variable_GetPtrDouble( variable, array_I );
+		startDataPtr = Variable_GetPtrDouble( startValue, array_I );
+		
+		TimeIntegrator_SetTime( self->timeIntegrator, startTime );
+
+		/* Store Original Value in case startValue == self->variable */
+		memcpy( startData, startDataPtr, sizeof( double ) * componentCount );
+
+		/* Do first Step - store K1 in finalTimeDeriv and update for next step */
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, finalTimeDeriv );
+		Journal_Firewall( True == successFlag, errorStream,
+			"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+			"deriv for item %u in step %u, *failed*.\n",
+			__func__, self->name, self->type, array_I, 1 );
+
+		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
+			arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * finalTimeDeriv[ component_I ];
+		TimeIntegrand_Intermediate( self, array_I );
+
+		TimeIntegrator_SetTime( self->timeIntegrator, startTime + 0.5 * dt );
+
+		/* Do Second Step - add 2xK2 value to finalTimeDeriv and update for next step */
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+				arrayDataPtr[ component_I ] = startData[ component_I ] + 0.5 * dt * timeDeriv[ component_I ];
+				finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
+			}
+			TimeIntegrand_Intermediate( self, array_I );
+		}
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 2 );
+				
+			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
+
+		/* Do Third Step - add 2xK3 value to finalTimeDeriv and update for next step */
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+				arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
+				finalTimeDeriv[ component_I ] += 2.0 * timeDeriv[ component_I ];
+			}
+			TimeIntegrand_Intermediate( self, array_I );
+		}
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 3 );
+				
+			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
+
+		TimeIntegrator_SetTime( self->timeIntegrator, startTime + dt );
+
+		/* Do Fourth Step - 'K1 + 2K2 + 2K3' and K4 finalTimeDeriv to find final value */
+		successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+		if ( True == successFlag ) {
+			for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+				arrayDataPtr[ component_I ] = startData[ component_I ] + 
+					dt/6.0 * (timeDeriv[ component_I ] + finalTimeDeriv[ component_I ] );
+			}		
+			TimeIntegrand_Intermediate( self, array_I );
+		}
+		else {
+			Journal_Firewall( True == self->allowFallbackToFirstOrder, errorStream,
+				"Error - in %s(), for TimeIntegrand \"%s\" of type %s: When trying to find time "
+				"deriv for item %u in step %u, *failed*, and self->allowFallbackToFirstOrder "
+				"not enabled.\n", __func__, self->name, self->type, array_I, 4 );
+				
+			_TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( self,
+				arrayDataPtr, startData, startTime, dt,
+				timeDeriv, array_I );
+		}
+	}
+
+	Memory_Free( timeDeriv );
+	Memory_Free( startData );
+	Memory_Free( finalTimeDeriv );
+}
+
+
+/* Note : this function is used to apply to just one item/particle - see the array_I parameter */
+void _TimeIntegrand_RewindToStartAndApplyFirstOrderUpdate( 
+		TimeIntegrand* self,
+		double*         arrayDataPtr,
+		double*         startData,
+		double          startTime,
+		double          dt,
+		double*         timeDeriv,
+		Index           array_I )
+{
+	Variable*       variable       = self->variable;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Bool            successFlag = False;
+
+	/* First, go back to initial positions, so we can re-calculate the time derivative there */
+	for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+		arrayDataPtr[ component_I ] = startData[ component_I ];
+	}	
+	TimeIntegrand_Intermediate( self, array_I );
+
+	/* Now recalculate time deriv at start positions, then do a full dt first order update from
+	 * there */
+	TimeIntegrator_SetTime( self->timeIntegrator, startTime );
+	successFlag = TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+	for ( component_I = 0 ; component_I < componentCount ; component_I++ ) 
+		arrayDataPtr[ component_I ] = startData[ component_I ] + dt * timeDeriv[ component_I ];
+	TimeIntegrand_Intermediate( self, array_I );
+}
+
+
+/** +++ Sample Time Deriv Functions +++ **/
+
+
+/** This function assumes that
+ *            the ODE that we are solving is \dot \phi = u(x,y) 
+ *            the velocity Field Variable is stored in data[0]
+ *            the variable being updated is the global coordinate of the object */
+Bool _TimeIntegrand_AdvectionTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+	TimeIntegrand*	     self          = (TimeIntegrand*) timeIntegrand;
+	FieldVariable*       velocityField = (FieldVariable*)  self->data[0];
+	double*              coord;
+	InterpolationResult  result;
+
+	/* Get Coordinate of Object using Variable */
+	coord = Variable_GetPtrDouble( self->variable, array_I );
+
+	result = FieldVariable_InterpolateValueAt( velocityField, coord, timeDeriv );
+
+	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
+			( velocityField->dim == 3 && isinf(timeDeriv[2]) ) ) 
+	{
+		#if 0
+		Journal_Printf( Journal_Register( Error_Type, (Name)self->type  ),
+			"Error in func '%s' for particle with index %u.\n\tPosition (%g, %g, %g)\n\tVelocity here is (%g, %g, %g)."
+			"\n\tInterpolation result is %s.\n",
+			__func__, array_I, coord[0], coord[1], coord[2], 
+			timeDeriv[0], timeDeriv[1], ( velocityField->dim == 3 ? timeDeriv[2] : 0.0 ),
+			InterpolationResultToStringMap[result]  );
+		return False;	
+		#endif
+	}
+
+	return True;
+}
+
+
+void _TimeIntegrand_Intermediate( void* timeIntegrand, Index array_I ) {}
+
+/* +++ Public Functions +++ */
+void TimeIntegrand_StoreTimeDeriv( void* timeIntegrand, Variable* timeDeriv ) {
+	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
+	double*         arrayDataPtr;
+	Index           array_I; 
+	Index           arrayCount;
+
+	/* Update Variable */
+	Variable_Update( timeDeriv );
+	arrayCount = timeDeriv->arraySize;
+
+	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
+		arrayDataPtr = Variable_GetPtrDouble( timeDeriv, array_I );
+		TimeIntegrand_CalculateTimeDeriv( self, array_I, arrayDataPtr );
+	}
+}
+
+void TimeIntegrand_Add2TimesTimeDeriv( void* timeIntegrand, Variable* timeDerivVariable ) {
+	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
+	Variable*       variable       = self->variable;
+	double*         timeDerivPtr;
+	double*         timeDeriv;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Index           array_I; 
+	Index           arrayCount;
+
+	timeDeriv = Memory_Alloc_Array( double, componentCount, "Time Deriv" );
+	memset( timeDeriv,      0, componentCount * sizeof( double ) );
+	
+	/* Update Variables */
+	Variable_Update( variable );
+	Variable_Update( timeDerivVariable );
+	arrayCount = variable->arraySize;
+	
+	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
+		TimeIntegrand_CalculateTimeDeriv( self, array_I, timeDeriv );
+		timeDerivPtr = Variable_GetPtrDouble( timeDerivVariable, array_I );
+		
+		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+			timeDerivPtr[ component_I ] += 2.0 * timeDeriv[ component_I ];
+		}
+	}
+
+	Memory_Free( timeDeriv );
+}
+	
+
+void TimeIntegrand_FourthOrderFinalStep( void* timeIntegrand, Variable* startData, Variable* timeDerivVariable, double dt ) {
+	TimeIntegrand*	self           = (TimeIntegrand*)timeIntegrand;
+	Variable*       variable       = self->variable;
+	double*         k4;
+	double*         k1_2k2_2k3;
+	double*         startPtr;
+	double*         arrayPtr;
+	Index           component_I; 
+	Index           componentCount = *variable->dataTypeCounts;
+	Index           array_I; 
+	Index           arrayCount;
+
+	k4 = Memory_Alloc_Array( double, componentCount, "k4 Time Deriv" );
+	memset( k4, 0, componentCount * sizeof( double ) );
+	
+	/* Update Variables */
+	Variable_Update( variable );
+	Variable_Update( startData );
+	Variable_Update( timeDerivVariable );
+	arrayCount     = variable->arraySize;
+	
+	for ( array_I = 0 ; array_I < arrayCount ; array_I++ ) {
+		TimeIntegrand_CalculateTimeDeriv( self, array_I, k4 );
+
+		k1_2k2_2k3 = Variable_GetPtrDouble( timeDerivVariable, array_I );
+		arrayPtr = Variable_GetPtrDouble( variable, array_I );
+		startPtr = Variable_GetPtrDouble( startData, array_I );
+		
+		for ( component_I = 0 ; component_I < componentCount ; component_I++ ) {
+			arrayPtr[ component_I ] = startPtr[ component_I ] + dt/6.0 * ( k4[ component_I ] + k1_2k2_2k3[ component_I ] );
+		}
+		TimeIntegrand_Intermediate( self, array_I );
+	}
+
+	Memory_Free( k4 );
+}
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/TimeIntegrator.c
--- a/Utils/src/TimeIntegrator.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,683 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student Monash University, VPAC. (davidm at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: TimeIntegrator.c 4149 2007-06-29 06:59:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "DomainContext.h"
-#include "TimeIntegrator.h"
-#include "TimeIntegrand.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type TimeIntegrator_Type = "TimeIntegrator";
-
-TimeIntegrator* TimeIntegrator_New( 
-	Name						name,
-	unsigned int			order, 
-	Bool						simultaneous, 
-	EntryPoint_Register*	entryPoint_Register,
-	AbstractContext*		context )
-{
-  TimeIntegrator* self = (TimeIntegrator*)_TimeIntegrator_DefaultNew( name );
-
-	self->isConstructed = True;
-	_TimeIntegrator_Init( self, order, simultaneous, entryPoint_Register, context );
-
-	return self;
-}
-
-void* _TimeIntegrator_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(TimeIntegrator);
-	Type                                                      type = TimeIntegrator_Type;
-	Stg_Class_DeleteFunction*                              _delete = _TimeIntegrator_Delete;
-	Stg_Class_PrintFunction*                                _print = _TimeIntegrator_Print;
-	Stg_Class_CopyFunction*                                  _copy = _TimeIntegrator_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _TimeIntegrator_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _TimeIntegrator_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _TimeIntegrator_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _TimeIntegrator_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _TimeIntegrator_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _TimeIntegrator_Destroy;
-
-	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
-	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
-
-	return (void*) _TimeIntegrator_New(  TIMEINTEGRATOR_PASSARGS  );
-}
-
-TimeIntegrator* _TimeIntegrator_New(  TIMEINTEGRATOR_DEFARGS  )
-{
-	TimeIntegrator*	self;
-	
-	assert( _sizeOfSelf >= sizeof(TimeIntegrator) );
-	
-	/* General info */
-	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
-	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
-	   and so should be set to ZERO in any children of this class. */
-	nameAllocationType = NON_GLOBAL;
-
-	self = (TimeIntegrator*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	return self;
-}
-
-void _TimeIntegrator_Init( 
-	void*						timeIntegrator, 
-	unsigned int			order, 
-	Bool						simultaneous, 
-	EntryPoint_Register*	entryPoint_Register,
-	AbstractContext*		context )
-{
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-
-	self->context = (DomainContext*)context;
-	self->debug = Journal_Register( Debug_Type, (Name)self->type  );
-	self->info = Journal_Register( Info_Type, (Name)self->type );
-		
-	self->integrandRegister = NamedObject_Register_New( );
-	self->order = order;
-	self->simultaneous = simultaneous;
-
-	/* Entry Point Stuff */
-	Stg_asprintf( (char**)(&self->_setupEPName), "%s-Setup", self->name );
-	Stg_asprintf( (char**)(&self->_finishEPName), "%s-Finish", self->name );
-	self->setupEP  = EntryPoint_New( self->_setupEPName,  EntryPoint_VoidPtr_CastType );
-	self->finishEP = EntryPoint_New( self->_finishEPName, EntryPoint_VoidPtr_CastType );
-
-	if ( entryPoint_Register ) {
-		EntryPoint_Register_Add( entryPoint_Register, self->setupEP );
-		EntryPoint_Register_Add( entryPoint_Register, self->finishEP );
-	}
-
-	self->setupData = Stg_ObjectList_New();
-	self->finishData = Stg_ObjectList_New();
-
-	if ( context ) {
-		EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_UpdateClass ), TimeIntegrator_UpdateClass, self );
-	}
-}
-
-void _TimeIntegrator_Delete( void* timeIntegrator ) {
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-	Memory_Free( self->_setupEPName );
-	Memory_Free( self->_finishEPName );
-	
-	Stg_Class_Delete( self->setupData );
-	Stg_Class_Delete( self->finishData );
-	
-	/* Stg_Class_Delete parent*/
-	_Stg_Component_Delete( self );
-}
-
-void _TimeIntegrator_Print( void* timeIntegrator, Stream* stream ) {
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-
-	/* General info */
-	Journal_DPrintf( self->debug, "TimeIntegrator - '%s'\n", self->name );
-	Journal_PrintPointer( stream, self );
-	Stream_Indent( stream );
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-	
-	/* Virtual info */
-
-	/* Regular Info */
-	Stg_Class_Print( self->integrandRegister, stream );
-	
-	Stream_UnIndent( stream );
-}
-
-void* _TimeIntegrator_Copy( const void* timeIntegrator, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
-	TimeIntegrator*	newTimeIntegrator;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-	/* TODO */ abort();
-
-	return (void*)newTimeIntegrator;
-}
-
-
-void _TimeIntegrator_AssignFromXML( void* timeIntegrator, Stg_ComponentFactory* cf, void* data ) {
-	TimeIntegrator*          self        = (TimeIntegrator*)timeIntegrator;
-	unsigned int             order;
-	Bool                     simultaneous;
-	EntryPoint_Register*     entryPoint_Register;
-
-	/** Default for order changed to 2nd order (was 1st order) by Pat Sunter, 10 May 2006 */
-	order          = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"order", 2  );
-	simultaneous   = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"simultaneous", False  );
-
-	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
-	if( !self->context  )	
-		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data );
-
-	entryPoint_Register = self->context->entryPoint_Register; 
-	assert( entryPoint_Register  );
-
-	_TimeIntegrator_Init( self, order, simultaneous, entryPoint_Register, (AbstractContext*)self->context );
-}
-
-void _TimeIntegrator_Build( void* timeIntegrator, void* data ) {
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-}
-
-void _TimeIntegrator_Initialise( void* timeIntegrator, void* data ) {
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-}
-
-void _TimeIntegrator_Execute( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
-	double wallTime,tmin,tmax;
-
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	wallTime = MPI_Wtime();
-
-	/* Set function pointer */
-	switch (self->order) {
-		case 1:
-			self->_execute = _TimeIntegrator_ExecuteEuler; 
-			break;
-		case 2:
-			if (self->simultaneous) 
-				self->_execute = _TimeIntegrator_ExecuteRK2Simultaneous; 
-			else
-				self->_execute = _TimeIntegrator_ExecuteRK2; 
-			break;
-		case 4:
-			if (self->simultaneous) 
-				self->_execute = _TimeIntegrator_ExecuteRK4Simultaneous; 
-			else
-				self->_execute = _TimeIntegrator_ExecuteRK4; 
-			break;
-		default:
-			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
-					"%s '%s' cannot handle order %u\n", self->type, self->name, self->order );
-	}
-
-	/* Call real function */
-	
-	Journal_RPrintf( self->info, "Time Integration\n" );
-	self->_execute( self, data );
-
-	wallTime = MPI_Wtime()-wallTime;
-        MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-        MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-	Journal_RPrintf(self->info,"Time Integration - %.6g [min] / %.6g [max] (secs)\n", tmin, tmax);
-	
-}
-
-void _TimeIntegrator_Destroy( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-}
-
-void TimeIntegrator_UpdateClass( void* timeIntegrator, void* data ) {
-	TimeIntegrator*        self            = (TimeIntegrator*) timeIntegrator;
-	double wallTime,tmin,tmax;
-	
-	wallTime = MPI_Wtime();
-	Journal_RPrintf(self->info,"Time Integration\n");
-	self->_execute( self, data );
-
-	wallTime = MPI_Wtime()-wallTime;
-        MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-        MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-	Journal_RPrintf(self->info,"Time Integration - %.4g [min] / %.4g [max] (secs)\n", tmin,tmax);	
-}
-
-/* +++ Private Functions +++ */
-void _TimeIntegrator_ExecuteEuler( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*) timeIntegrator;
-	AbstractContext*	context = (AbstractContext*) data;
-	Index					integrand_I;   
-	Index					integrandCount = TimeIntegrator_GetCount( self );
-	double				dt = AbstractContext_Dt( context );
-	TimeIntegrand*	integrand;
-	double wallTime,tmin,tmax;
-	
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	/* Set Time */
-	TimeIntegrator_SetTime( self, context->currentTime );
-	
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-	
-		wallTime = MPI_Wtime();
-		TimeIntegrand_FirstOrder( integrand, integrand->variable, dt );
-
-		wallTime = MPI_Wtime() - wallTime;
-		MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-		MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-		Journal_RPrintf(self->info,"\t1st order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin,tmax);
-	}
-	TimeIntegrator_Finalise( self );
-}
-
-void _TimeIntegrator_ExecuteRK2( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*) timeIntegrator;
-	AbstractContext*	context = (AbstractContext*) self->context;
-	Index					integrand_I;   
-	Index					integrandCount = TimeIntegrator_GetCount( self );
-	double				dt = AbstractContext_Dt( context );
-	TimeIntegrand*	integrand;
-	double wallTime,tmin,tmax;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	
-	wallTime = MPI_Wtime();
-	TimeIntegrator_Setup( self );
-	
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-				
-		TimeIntegrator_SetTime( self, context->currentTime );
-		
-		wallTime = MPI_Wtime();
-		TimeIntegrand_SecondOrder( integrand, integrand->variable, dt );
-
-        	wallTime = MPI_Wtime()-wallTime;
-        	MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-        	MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-		Journal_RPrintf(self->info,"\t2nd order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin, tmax);
-		
-	}
-	
-	TimeIntegrator_Finalise( self );
-	
-}
-
-
-void _TimeIntegrator_ExecuteRK4( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*) timeIntegrator;
-	AbstractContext*	context = (AbstractContext*) data;
-	Index					integrand_I;   
-	Index					integrandCount = TimeIntegrator_GetCount( self );
-	double				dt = AbstractContext_Dt( context );
-	TimeIntegrand*	integrand;
-	double wallTime,tmin,tmax;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-
-		TimeIntegrator_SetTime( self, context->currentTime );
-		wallTime = MPI_Wtime();
-		TimeIntegrand_FourthOrder( integrand, integrand->variable, dt );
-       	
-		wallTime = MPI_Wtime()-wallTime;
-        	MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-        	MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-		Journal_RPrintf(self->info,"\t4th order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin, tmax);
-	}
-	TimeIntegrator_Finalise( self );
-}
-
-
-void _TimeIntegrator_ExecuteRK2Simultaneous( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
-	AbstractContext*	context = (AbstractContext*) data;
-	Index					integrand_I;   
-	Index					integrandCount = TimeIntegrator_GetCount( self );
-	double				dt = AbstractContext_Dt( context );
-	TimeIntegrand*	integrand;
-	Variable**			originalVariableList;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	Journal_Firewall( 
-		False,
-		Journal_MyStream( Error_Type, self ),
-		"Error in %s '%s' - This function is temporarily unavailable \n"
-		"Please only use non-simultaneous update or only first order update.\n", 
-		self->type, self->name );
-
-	/* Set Time */
-	TimeIntegrator_SetTime( self, context->currentTime );
-
-	originalVariableList = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" );
-	
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-		Journal_RPrintf(self->info,"\t2nd order (simultaneous): %s\n", integrand->name);
-		
-		/* Store Original */
-		originalVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "Original", True );
-
-		/* Predictor Step */
-		TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt );
-	}
-	TimeIntegrator_Finalise( self );
-	
-	/* Set Time */
-	TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt );
-
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-
-		/* Corrector Step */
-		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt );
-
-		/* Free Original */
-		Stg_Class_Delete( originalVariableList[ integrand_I ] );
-	}
-	TimeIntegrator_Finalise( self );
-	Memory_Free( originalVariableList );
-}
-
-void _TimeIntegrator_ExecuteRK4Simultaneous( void* timeIntegrator, void* data ) {
-	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
-	AbstractContext*	context = (AbstractContext*) data;
-	Index					integrand_I;   
-	Index					integrandCount = TimeIntegrator_GetCount( self );
-	double				dt = AbstractContext_Dt( context );
-	TimeIntegrand*	integrand;
-	Variable**			originalVariableList;
-	Variable**			timeDerivVariableList;
-
-	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
-
-	/* Set Time */
-	TimeIntegrator_SetTime( self, context->currentTime );
-	
-	originalVariableList  = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" );
-	timeDerivVariableList = Memory_Alloc_Array( Variable*, integrandCount, "timeDerivVariableList" );
-
-	/* First Step */
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-		Journal_RPrintf(self->info,"\t4nd order (simultaneous): %s\n", integrand->name);
-
-		/* Store Original Position Variable */
-		originalVariableList[ integrand_I ]  = Variable_NewFromOld( integrand->variable, "Original", True );
-		timeDerivVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "k1+2k2+2k3", False );
-
-		/* Store k1 */
-		TimeIntegrand_StoreTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] );
-
-		/* 1st Step */
-		TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt );
-	}
-	TimeIntegrator_Finalise( self );
-	
-	/* Set Time */
-	TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt );
-	
-	/* Second Step */
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-
-		/* Add k2 */
-		TimeIntegrand_Add2TimesTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] );
-
-		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], 0.5 * dt );
-	}
-	TimeIntegrator_Finalise( self );
-
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-		
-		/* Add k3 */
-		TimeIntegrand_Add2TimesTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] );
-
-		/* 3rd Step */
-		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt );
-	}
-	TimeIntegrator_Finalise( self );
-	
-	/* Set Time */
-	TimeIntegrator_SetTime( self, context->currentTime + dt );
-	
-	TimeIntegrator_Setup( self );
-	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
-
-		TimeIntegrand_FourthOrderFinalStep( integrand, originalVariableList[ integrand_I ], timeDerivVariableList[ integrand_I ], dt );
-
-		/* Free Original */
-		Stg_Class_Delete( timeDerivVariableList[ integrand_I ] );
-		Stg_Class_Delete( originalVariableList[ integrand_I ] );
-	}
-	TimeIntegrator_Finalise( self );
-
-	Memory_Free( originalVariableList );
-	Memory_Free( timeDerivVariableList );
-}
-
-
-
-/* +++ Public Functions +++ */
-
-void TimeIntegrator_Add( void* timeIntegrator, void* _timeIntegrand ) {
-	TimeIntegrator*	self           = (TimeIntegrator*) timeIntegrator;
-	TimeIntegrand*	timeIntegrand = (TimeIntegrand*)_timeIntegrand;
-
-	NamedObject_Register_Add( self->integrandRegister, timeIntegrand );
-}
-
-void TimeIntegrator_Setup( void* timeIntegrator ) {
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-	EntryPoint*            entryPoint      = self->setupEP;
-	Hook_Index             hookIndex;
-	double wallTime,tmin,tmax;
-	
-	/* Shouldn't this be using a call to a run function of the entry point class ? */ 
-	for( hookIndex = 0; hookIndex < entryPoint->hooks->count; hookIndex++ ) {
-		wallTime = MPI_Wtime();
-		
-		((EntryPoint_2VoidPtr_Cast*)((Hook*)entryPoint->hooks->data[hookIndex])->funcPtr)(
-			self, Stg_ObjectList_At( self->setupData, hookIndex ) );
-	
-			wallTime = MPI_Wtime()-wallTime;
-        	MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-        	MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-		Journal_RPrintf(self->info,"\t       EP: %35s - %9.4f [min] / %9.4f [max] (secs)\n",(entryPoint->hooks->data[hookIndex])->name,tmin,tmax);	
-	}		
-}
-
-void TimeIntegrator_AppendSetupEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-
-	EntryPoint_Append( self->setupEP, name, funcPtr, addedBy );
-	Stg_ObjectList_Append( self->setupData, data );
-}
-
-void TimeIntegrator_PrependSetupEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
-	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
-
-	EntryPoint_Prepend( self->setupEP, name, funcPtr, addedBy );
-	Stg_ObjectList_Prepend( self->setupData, data );
-}
-	
-void TimeIntegrator_Finalise( void* timeIntegrator ) {
-	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
-	EntryPoint*			entryPoint = self->finishEP;
-	Hook_Index			hookIndex;
-	double				wallTime,tmin,tmax;
-	
-	for( hookIndex = 0; hookIndex < entryPoint->hooks->count; hookIndex++ ) {
-		wallTime = MPI_Wtime();
-		
-		((EntryPoint_2VoidPtr_Cast*)((Hook*)entryPoint->hooks->data[hookIndex])->funcPtr)( self, Stg_ObjectList_At( self->finishData, hookIndex ) );
-
-   	wallTime = MPI_Wtime()-wallTime;
-		MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
-		MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
-		Journal_RPrintf(self->info,"\t       EP: %35s - %9.4f (secs)\n",(entryPoint->hooks->data[hookIndex])->name,tmin,tmax);	
-	}
-}
-
-void TimeIntegrator_AppendFinishEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-
-	EntryPoint_Append( self->finishEP, name, funcPtr, addedBy );
-	Stg_ObjectList_Append( self->finishData, data );
-}
-
-void TimeIntegrator_PrependFinishEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-
-	EntryPoint_Prepend( self->finishEP, name, funcPtr, addedBy );
-	Stg_ObjectList_Prepend( self->finishData, data );
-}
-
-void TimeIntegrator_InsertBeforeFinishEP( 
-	void* timeIntegrator, 
-	Name hookToInsertBefore,
-	Name name, 
-	Func_Ptr funcPtr, 
-	Name addedBy, 
-	void* data ) 
-{
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-
-	if ( Stg_ObjectList_GetIndex( self->finishEP->hooks, hookToInsertBefore ) != (unsigned int)-1 ) {
-		EntryPoint_InsertBefore( self->finishEP, hookToInsertBefore, name, funcPtr, addedBy );
-		Stg_ObjectList_InsertAtIndex( 
-				self->finishData,
-				Stg_ObjectList_GetIndex( self->finishEP->hooks, name ),
-				data );
-	}
-	else {
-		TimeIntegrator_AppendFinishEP( self, name, funcPtr, addedBy, data );
-	}
-}
-
-void TimeIntegrator_InsertAfterFinishEP( 
-	void* timeIntegrator, 
-	Name hookToInsertAfter, 
-	Name name, 
-	Func_Ptr funcPtr, 
-	Name addedBy, 
-	void* data ) 
-{
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-
-	if ( Stg_ObjectList_GetIndex( self->finishEP->hooks, hookToInsertAfter ) != (unsigned int)-1 ) {
-		EntryPoint_InsertAfter( self->finishEP, hookToInsertAfter, name, funcPtr, addedBy );
-		Stg_ObjectList_InsertAtIndex(
-				self->finishData,
-				Stg_ObjectList_GetIndex( self->finishEP->hooks, name ),
-				data );
-	}
-	else {
-		TimeIntegrator_AppendFinishEP( self, name, funcPtr, addedBy, data );
-	}
-}
-
-void TimeIntegrator_SetTime( void* timeIntegrator, double time ) {
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-
-	self->time = time;
-}
-
-double TimeIntegrator_GetTime( void* timeIntegrator ) {
-	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
-	return self->time;
-}
-
-Variable* Variable_NewFromOld( Variable* oldVariable, Name name, Bool copyValues ) {
-	Variable*         self;
-	Index             array_I;
-	SizeT             dataOffsets[] = { 0 };
-	void*             myPtr;
-	void*             oldPtr;
-
-	Variable_Update( oldVariable );
-
-	self = Variable_New(  
-		name,
-		self->context,
-		1,
-		dataOffsets,
-		oldVariable->dataTypes,
-		oldVariable->dataTypeCounts,
-		NULL,
-		0,
-		oldVariable->arraySizePtr,
-		oldVariable->arraySizeFunc,
-		NULL,
-		NULL );
-
-	self->allocateSelf = True;
-	self->arrayPtrPtr = &self->arrayPtr;
-	if ( oldVariable->isBuilt )
-		Stg_Component_Build( self, NULL, True );
-	if ( oldVariable->isInitialised )
-		Stg_Component_Initialise( self, NULL, True );
-
-	assert(self->offsetCount == 1);
-
-	if ( copyValues ) {
-		for ( array_I = 0 ; array_I < self->arraySize ; array_I++ ) {
-			myPtr = Variable_GetStructPtr( self, array_I );
-			oldPtr = Variable_GetStructPtr( oldVariable, array_I );
-			memcpy( myPtr, oldPtr, self->dataSizes[0] ); 
-		}
-	}
-
-	return self;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/TimeIntegrator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/TimeIntegrator.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,683 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student Monash University, VPAC. (davidm at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: TimeIntegrator.c 4149 2007-06-29 06:59:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "DomainContext.h"
+#include "TimeIntegrator.h"
+#include "TimeIntegrand.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type TimeIntegrator_Type = "TimeIntegrator";
+
+TimeIntegrator* TimeIntegrator_New( 
+	Name						name,
+	unsigned int			order, 
+	Bool						simultaneous, 
+	EntryPoint_Register*	entryPoint_Register,
+	AbstractContext*		context )
+{
+  TimeIntegrator* self = (TimeIntegrator*)_TimeIntegrator_DefaultNew( name );
+
+	self->isConstructed = True;
+	_TimeIntegrator_Init( self, order, simultaneous, entryPoint_Register, context );
+
+	return self;
+}
+
+void* _TimeIntegrator_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(TimeIntegrator);
+	Type                                                      type = TimeIntegrator_Type;
+	Stg_Class_DeleteFunction*                              _delete = _TimeIntegrator_Delete;
+	Stg_Class_PrintFunction*                                _print = _TimeIntegrator_Print;
+	Stg_Class_CopyFunction*                                  _copy = _TimeIntegrator_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _TimeIntegrator_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _TimeIntegrator_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _TimeIntegrator_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _TimeIntegrator_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _TimeIntegrator_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _TimeIntegrator_Destroy;
+
+	/* Variables that are set to ZERO are variables that will be set either by the current _New function or another parent _New function further up the hierachy */
+	AllocationType  nameAllocationType = NON_GLOBAL /* default value NON_GLOBAL */;
+
+	return (void*) _TimeIntegrator_New(  TIMEINTEGRATOR_PASSARGS  );
+}
+
+TimeIntegrator* _TimeIntegrator_New(  TIMEINTEGRATOR_DEFARGS  )
+{
+	TimeIntegrator*	self;
+	
+	assert( _sizeOfSelf >= sizeof(TimeIntegrator) );
+	
+	/* General info */
+	/* The following terms are parameters that have been passed into this function but are being set before being passed onto the parent */
+	/* This means that any values of these parameters that are passed into this function are not passed onto the parent function
+	   and so should be set to ZERO in any children of this class. */
+	nameAllocationType = NON_GLOBAL;
+
+	self = (TimeIntegrator*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	return self;
+}
+
+void _TimeIntegrator_Init( 
+	void*						timeIntegrator, 
+	unsigned int			order, 
+	Bool						simultaneous, 
+	EntryPoint_Register*	entryPoint_Register,
+	AbstractContext*		context )
+{
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+
+	self->context = (DomainContext*)context;
+	self->debug = Journal_Register( Debug_Type, (Name)self->type  );
+	self->info = Journal_Register( Info_Type, (Name)self->type );
+		
+	self->integrandRegister = NamedObject_Register_New( );
+	self->order = order;
+	self->simultaneous = simultaneous;
+
+	/* Entry Point Stuff */
+	Stg_asprintf( (char**)(&self->_setupEPName), "%s-Setup", self->name );
+	Stg_asprintf( (char**)(&self->_finishEPName), "%s-Finish", self->name );
+	self->setupEP  = EntryPoint_New( self->_setupEPName,  EntryPoint_VoidPtr_CastType );
+	self->finishEP = EntryPoint_New( self->_finishEPName, EntryPoint_VoidPtr_CastType );
+
+	if ( entryPoint_Register ) {
+		EntryPoint_Register_Add( entryPoint_Register, self->setupEP );
+		EntryPoint_Register_Add( entryPoint_Register, self->finishEP );
+	}
+
+	self->setupData = Stg_ObjectList_New();
+	self->finishData = Stg_ObjectList_New();
+
+	if ( context ) {
+		EP_AppendClassHook( Context_GetEntryPoint( context, AbstractContext_EP_UpdateClass ), TimeIntegrator_UpdateClass, self );
+	}
+}
+
+void _TimeIntegrator_Delete( void* timeIntegrator ) {
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+	Memory_Free( self->_setupEPName );
+	Memory_Free( self->_finishEPName );
+	
+	Stg_Class_Delete( self->setupData );
+	Stg_Class_Delete( self->finishData );
+	
+	/* Stg_Class_Delete parent*/
+	_Stg_Component_Delete( self );
+}
+
+void _TimeIntegrator_Print( void* timeIntegrator, Stream* stream ) {
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+
+	/* General info */
+	Journal_DPrintf( self->debug, "TimeIntegrator - '%s'\n", self->name );
+	Journal_PrintPointer( stream, self );
+	Stream_Indent( stream );
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+	
+	/* Virtual info */
+
+	/* Regular Info */
+	Stg_Class_Print( self->integrandRegister, stream );
+	
+	Stream_UnIndent( stream );
+}
+
+void* _TimeIntegrator_Copy( const void* timeIntegrator, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
+	TimeIntegrator*	newTimeIntegrator;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+	/* TODO */ abort();
+
+	return (void*)newTimeIntegrator;
+}
+
+
+void _TimeIntegrator_AssignFromXML( void* timeIntegrator, Stg_ComponentFactory* cf, void* data ) {
+	TimeIntegrator*          self        = (TimeIntegrator*)timeIntegrator;
+	unsigned int             order;
+	Bool                     simultaneous;
+	EntryPoint_Register*     entryPoint_Register;
+
+	/** Default for order changed to 2nd order (was 1st order) by Pat Sunter, 10 May 2006 */
+	order          = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"order", 2  );
+	simultaneous   = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"simultaneous", False  );
+
+	self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", DomainContext, False, data );
+	if( !self->context  )	
+		self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data );
+
+	entryPoint_Register = self->context->entryPoint_Register; 
+	assert( entryPoint_Register  );
+
+	_TimeIntegrator_Init( self, order, simultaneous, entryPoint_Register, (AbstractContext*)self->context );
+}
+
+void _TimeIntegrator_Build( void* timeIntegrator, void* data ) {
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+}
+
+void _TimeIntegrator_Initialise( void* timeIntegrator, void* data ) {
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+}
+
+void _TimeIntegrator_Execute( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
+	double wallTime,tmin,tmax;
+
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	wallTime = MPI_Wtime();
+
+	/* Set function pointer */
+	switch (self->order) {
+		case 1:
+			self->_execute = _TimeIntegrator_ExecuteEuler; 
+			break;
+		case 2:
+			if (self->simultaneous) 
+				self->_execute = _TimeIntegrator_ExecuteRK2Simultaneous; 
+			else
+				self->_execute = _TimeIntegrator_ExecuteRK2; 
+			break;
+		case 4:
+			if (self->simultaneous) 
+				self->_execute = _TimeIntegrator_ExecuteRK4Simultaneous; 
+			else
+				self->_execute = _TimeIntegrator_ExecuteRK4; 
+			break;
+		default:
+			Journal_Firewall( False, Journal_Register( Error_Type, (Name)self->type  ),
+					"%s '%s' cannot handle order %u\n", self->type, self->name, self->order );
+	}
+
+	/* Call real function */
+	
+	Journal_RPrintf( self->info, "Time Integration\n" );
+	self->_execute( self, data );
+
+	wallTime = MPI_Wtime()-wallTime;
+        MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+        MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+	Journal_RPrintf(self->info,"Time Integration - %.6g [min] / %.6g [max] (secs)\n", tmin, tmax);
+	
+}
+
+void _TimeIntegrator_Destroy( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+}
+
+void TimeIntegrator_UpdateClass( void* timeIntegrator, void* data ) {
+	TimeIntegrator*        self            = (TimeIntegrator*) timeIntegrator;
+	double wallTime,tmin,tmax;
+	
+	wallTime = MPI_Wtime();
+	Journal_RPrintf(self->info,"Time Integration\n");
+	self->_execute( self, data );
+
+	wallTime = MPI_Wtime()-wallTime;
+        MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+        MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+	Journal_RPrintf(self->info,"Time Integration - %.4g [min] / %.4g [max] (secs)\n", tmin,tmax);	
+}
+
+/* +++ Private Functions +++ */
+void _TimeIntegrator_ExecuteEuler( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*) timeIntegrator;
+	AbstractContext*	context = (AbstractContext*) data;
+	Index					integrand_I;   
+	Index					integrandCount = TimeIntegrator_GetCount( self );
+	double				dt = AbstractContext_Dt( context );
+	TimeIntegrand*	integrand;
+	double wallTime,tmin,tmax;
+	
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	/* Set Time */
+	TimeIntegrator_SetTime( self, context->currentTime );
+	
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+	
+		wallTime = MPI_Wtime();
+		TimeIntegrand_FirstOrder( integrand, integrand->variable, dt );
+
+		wallTime = MPI_Wtime() - wallTime;
+		MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+		MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+		Journal_RPrintf(self->info,"\t1st order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin,tmax);
+	}
+	TimeIntegrator_Finalise( self );
+}
+
+void _TimeIntegrator_ExecuteRK2( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*) timeIntegrator;
+	AbstractContext*	context = (AbstractContext*) self->context;
+	Index					integrand_I;   
+	Index					integrandCount = TimeIntegrator_GetCount( self );
+	double				dt = AbstractContext_Dt( context );
+	TimeIntegrand*	integrand;
+	double wallTime,tmin,tmax;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	
+	wallTime = MPI_Wtime();
+	TimeIntegrator_Setup( self );
+	
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+				
+		TimeIntegrator_SetTime( self, context->currentTime );
+		
+		wallTime = MPI_Wtime();
+		TimeIntegrand_SecondOrder( integrand, integrand->variable, dt );
+
+        	wallTime = MPI_Wtime()-wallTime;
+        	MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+        	MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+		Journal_RPrintf(self->info,"\t2nd order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin, tmax);
+		
+	}
+	
+	TimeIntegrator_Finalise( self );
+	
+}
+
+
+void _TimeIntegrator_ExecuteRK4( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*) timeIntegrator;
+	AbstractContext*	context = (AbstractContext*) data;
+	Index					integrand_I;   
+	Index					integrandCount = TimeIntegrator_GetCount( self );
+	double				dt = AbstractContext_Dt( context );
+	TimeIntegrand*	integrand;
+	double wallTime,tmin,tmax;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+
+		TimeIntegrator_SetTime( self, context->currentTime );
+		wallTime = MPI_Wtime();
+		TimeIntegrand_FourthOrder( integrand, integrand->variable, dt );
+       	
+		wallTime = MPI_Wtime()-wallTime;
+        	MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+        	MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+		Journal_RPrintf(self->info,"\t4th order: %35s - %9.4f [min] / %9.4f [max] (secs)\n", integrand->name, tmin, tmax);
+	}
+	TimeIntegrator_Finalise( self );
+}
+
+
+void _TimeIntegrator_ExecuteRK2Simultaneous( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
+	AbstractContext*	context = (AbstractContext*) data;
+	Index					integrand_I;   
+	Index					integrandCount = TimeIntegrator_GetCount( self );
+	double				dt = AbstractContext_Dt( context );
+	TimeIntegrand*	integrand;
+	Variable**			originalVariableList;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	Journal_Firewall( 
+		False,
+		Journal_MyStream( Error_Type, self ),
+		"Error in %s '%s' - This function is temporarily unavailable \n"
+		"Please only use non-simultaneous update or only first order update.\n", 
+		self->type, self->name );
+
+	/* Set Time */
+	TimeIntegrator_SetTime( self, context->currentTime );
+
+	originalVariableList = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" );
+	
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+		Journal_RPrintf(self->info,"\t2nd order (simultaneous): %s\n", integrand->name);
+		
+		/* Store Original */
+		originalVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "Original", True );
+
+		/* Predictor Step */
+		TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt );
+	}
+	TimeIntegrator_Finalise( self );
+	
+	/* Set Time */
+	TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt );
+
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+
+		/* Corrector Step */
+		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt );
+
+		/* Free Original */
+		Stg_Class_Delete( originalVariableList[ integrand_I ] );
+	}
+	TimeIntegrator_Finalise( self );
+	Memory_Free( originalVariableList );
+}
+
+void _TimeIntegrator_ExecuteRK4Simultaneous( void* timeIntegrator, void* data ) {
+	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
+	AbstractContext*	context = (AbstractContext*) data;
+	Index					integrand_I;   
+	Index					integrandCount = TimeIntegrator_GetCount( self );
+	double				dt = AbstractContext_Dt( context );
+	TimeIntegrand*	integrand;
+	Variable**			originalVariableList;
+	Variable**			timeDerivVariableList;
+
+	Journal_DPrintf( self->debug, "In %s for %s '%s'\n", __func__, self->type, self->name );
+
+	/* Set Time */
+	TimeIntegrator_SetTime( self, context->currentTime );
+	
+	originalVariableList  = Memory_Alloc_Array( Variable*, integrandCount, "originalVariableList" );
+	timeDerivVariableList = Memory_Alloc_Array( Variable*, integrandCount, "timeDerivVariableList" );
+
+	/* First Step */
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+		Journal_RPrintf(self->info,"\t4nd order (simultaneous): %s\n", integrand->name);
+
+		/* Store Original Position Variable */
+		originalVariableList[ integrand_I ]  = Variable_NewFromOld( integrand->variable, "Original", True );
+		timeDerivVariableList[ integrand_I ] = Variable_NewFromOld( integrand->variable, "k1+2k2+2k3", False );
+
+		/* Store k1 */
+		TimeIntegrand_StoreTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] );
+
+		/* 1st Step */
+		TimeIntegrand_FirstOrder( integrand, integrand->variable, 0.5 * dt );
+	}
+	TimeIntegrator_Finalise( self );
+	
+	/* Set Time */
+	TimeIntegrator_SetTime( self, context->currentTime + 0.5 * dt );
+	
+	/* Second Step */
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+
+		/* Add k2 */
+		TimeIntegrand_Add2TimesTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] );
+
+		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], 0.5 * dt );
+	}
+	TimeIntegrator_Finalise( self );
+
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+		
+		/* Add k3 */
+		TimeIntegrand_Add2TimesTimeDeriv( integrand, timeDerivVariableList[ integrand_I ] );
+
+		/* 3rd Step */
+		TimeIntegrand_FirstOrder( integrand, originalVariableList[ integrand_I ], dt );
+	}
+	TimeIntegrator_Finalise( self );
+	
+	/* Set Time */
+	TimeIntegrator_SetTime( self, context->currentTime + dt );
+	
+	TimeIntegrator_Setup( self );
+	for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+		integrand = TimeIntegrator_GetByIndex( self, integrand_I );
+
+		TimeIntegrand_FourthOrderFinalStep( integrand, originalVariableList[ integrand_I ], timeDerivVariableList[ integrand_I ], dt );
+
+		/* Free Original */
+		Stg_Class_Delete( timeDerivVariableList[ integrand_I ] );
+		Stg_Class_Delete( originalVariableList[ integrand_I ] );
+	}
+	TimeIntegrator_Finalise( self );
+
+	Memory_Free( originalVariableList );
+	Memory_Free( timeDerivVariableList );
+}
+
+
+
+/* +++ Public Functions +++ */
+
+void TimeIntegrator_Add( void* timeIntegrator, void* _timeIntegrand ) {
+	TimeIntegrator*	self           = (TimeIntegrator*) timeIntegrator;
+	TimeIntegrand*	timeIntegrand = (TimeIntegrand*)_timeIntegrand;
+
+	NamedObject_Register_Add( self->integrandRegister, timeIntegrand );
+}
+
+void TimeIntegrator_Setup( void* timeIntegrator ) {
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+	EntryPoint*            entryPoint      = self->setupEP;
+	Hook_Index             hookIndex;
+	double wallTime,tmin,tmax;
+	
+	/* Shouldn't this be using a call to a run function of the entry point class ? */ 
+	for( hookIndex = 0; hookIndex < entryPoint->hooks->count; hookIndex++ ) {
+		wallTime = MPI_Wtime();
+		
+		((EntryPoint_2VoidPtr_Cast*)((Hook*)entryPoint->hooks->data[hookIndex])->funcPtr)(
+			self, Stg_ObjectList_At( self->setupData, hookIndex ) );
+	
+			wallTime = MPI_Wtime()-wallTime;
+        	MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+        	MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+		Journal_RPrintf(self->info,"\t       EP: %35s - %9.4f [min] / %9.4f [max] (secs)\n",(entryPoint->hooks->data[hookIndex])->name,tmin,tmax);	
+	}		
+}
+
+void TimeIntegrator_AppendSetupEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+
+	EntryPoint_Append( self->setupEP, name, funcPtr, addedBy );
+	Stg_ObjectList_Append( self->setupData, data );
+}
+
+void TimeIntegrator_PrependSetupEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
+	TimeIntegrator* self = (TimeIntegrator*)timeIntegrator;
+
+	EntryPoint_Prepend( self->setupEP, name, funcPtr, addedBy );
+	Stg_ObjectList_Prepend( self->setupData, data );
+}
+	
+void TimeIntegrator_Finalise( void* timeIntegrator ) {
+	TimeIntegrator*	self = (TimeIntegrator*)timeIntegrator;
+	EntryPoint*			entryPoint = self->finishEP;
+	Hook_Index			hookIndex;
+	double				wallTime,tmin,tmax;
+	
+	for( hookIndex = 0; hookIndex < entryPoint->hooks->count; hookIndex++ ) {
+		wallTime = MPI_Wtime();
+		
+		((EntryPoint_2VoidPtr_Cast*)((Hook*)entryPoint->hooks->data[hookIndex])->funcPtr)( self, Stg_ObjectList_At( self->finishData, hookIndex ) );
+
+   	wallTime = MPI_Wtime()-wallTime;
+		MPI_Reduce( &wallTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD );
+		MPI_Reduce( &wallTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD );
+		Journal_RPrintf(self->info,"\t       EP: %35s - %9.4f (secs)\n",(entryPoint->hooks->data[hookIndex])->name,tmin,tmax);	
+	}
+}
+
+void TimeIntegrator_AppendFinishEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+
+	EntryPoint_Append( self->finishEP, name, funcPtr, addedBy );
+	Stg_ObjectList_Append( self->finishData, data );
+}
+
+void TimeIntegrator_PrependFinishEP( void* timeIntegrator, Name name, Func_Ptr funcPtr, Name addedBy, void* data ) {
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+
+	EntryPoint_Prepend( self->finishEP, name, funcPtr, addedBy );
+	Stg_ObjectList_Prepend( self->finishData, data );
+}
+
+void TimeIntegrator_InsertBeforeFinishEP( 
+	void* timeIntegrator, 
+	Name hookToInsertBefore,
+	Name name, 
+	Func_Ptr funcPtr, 
+	Name addedBy, 
+	void* data ) 
+{
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+
+	if ( Stg_ObjectList_GetIndex( self->finishEP->hooks, hookToInsertBefore ) != (unsigned int)-1 ) {
+		EntryPoint_InsertBefore( self->finishEP, hookToInsertBefore, name, funcPtr, addedBy );
+		Stg_ObjectList_InsertAtIndex( 
+				self->finishData,
+				Stg_ObjectList_GetIndex( self->finishEP->hooks, name ),
+				data );
+	}
+	else {
+		TimeIntegrator_AppendFinishEP( self, name, funcPtr, addedBy, data );
+	}
+}
+
+void TimeIntegrator_InsertAfterFinishEP( 
+	void* timeIntegrator, 
+	Name hookToInsertAfter, 
+	Name name, 
+	Func_Ptr funcPtr, 
+	Name addedBy, 
+	void* data ) 
+{
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+
+	if ( Stg_ObjectList_GetIndex( self->finishEP->hooks, hookToInsertAfter ) != (unsigned int)-1 ) {
+		EntryPoint_InsertAfter( self->finishEP, hookToInsertAfter, name, funcPtr, addedBy );
+		Stg_ObjectList_InsertAtIndex(
+				self->finishData,
+				Stg_ObjectList_GetIndex( self->finishEP->hooks, name ),
+				data );
+	}
+	else {
+		TimeIntegrator_AppendFinishEP( self, name, funcPtr, addedBy, data );
+	}
+}
+
+void TimeIntegrator_SetTime( void* timeIntegrator, double time ) {
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+
+	self->time = time;
+}
+
+double TimeIntegrator_GetTime( void* timeIntegrator ) {
+	TimeIntegrator*        self            = (TimeIntegrator*)timeIntegrator;
+	return self->time;
+}
+
+Variable* Variable_NewFromOld( Variable* oldVariable, Name name, Bool copyValues ) {
+	Variable*         self;
+	Index             array_I;
+	SizeT             dataOffsets[] = { 0 };
+	void*             myPtr;
+	void*             oldPtr;
+
+	Variable_Update( oldVariable );
+
+	self = Variable_New(  
+		name,
+		self->context,
+		1,
+		dataOffsets,
+		oldVariable->dataTypes,
+		oldVariable->dataTypeCounts,
+		NULL,
+		0,
+		oldVariable->arraySizePtr,
+		oldVariable->arraySizeFunc,
+		NULL,
+		NULL );
+
+	self->allocateSelf = True;
+	self->arrayPtrPtr = &self->arrayPtr;
+	if ( oldVariable->isBuilt )
+		Stg_Component_Build( self, NULL, True );
+	if ( oldVariable->isInitialised )
+		Stg_Component_Initialise( self, NULL, True );
+
+	assert(self->offsetCount == 1);
+
+	if ( copyValues ) {
+		for ( array_I = 0 ; array_I < self->arraySize ; array_I++ ) {
+			myPtr = Variable_GetStructPtr( self, array_I );
+			oldPtr = Variable_GetStructPtr( oldVariable, array_I );
+			memcpy( myPtr, oldPtr, self->dataSizes[0] ); 
+		}
+	}
+
+	return self;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/WallVC.c
--- a/Utils/src/WallVC.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,646 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: WallVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-
-#include "types.h"
-#include "DomainContext.h"
-#include "WallVC.h"
-#include "RegularMeshUtils.h"
-
-#include <string.h>
-#include <assert.h>
-
-
-const Type WallVC_Type = "WallVC";
-const Name defaultWallVCName = "defaultWallVCName";
-
-Name WallVC_WallEnumToStr[WallVC_Wall_Size] = {
-	"back",
-	"left",
-	"bottom",
-	"right",
-	"top",
-	"front" };
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Constructor
-*/
-
-VariableCondition* WallVC_Factory(
-	AbstractContext*					context,
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									data )
-{
-	return (VariableCondition*)WallVC_New( defaultWallVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
-}
-
-WallVC* WallVC_New(
-	Name									name,
-	AbstractContext*					context,
-	Name									_dictionaryEntryName, 
-	Variable_Register*				variable_Register, 
-	ConditionFunction_Register*	conFunc_Register, 
-	Dictionary*							dictionary,
-	void*									_mesh )
-{
-	WallVC* self = _WallVC_DefaultNew( name );
-
-	self->isConstructed = True;
-	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
-	_WallVC_Init( self, _dictionaryEntryName, _mesh );
-
-	return self;
-}
-
-WallVC* _WallVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(WallVC);
-	Type                                                       type = WallVC_Type;
-	Stg_Class_DeleteFunction*                               _delete = _WallVC_Delete;
-	Stg_Class_PrintFunction*                                 _print = _WallVC_Print;
-	Stg_Class_CopyFunction*                                   _copy = _WallVC_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_WallVC_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _WallVC_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _WallVC_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _WallVC_Destroy;
-	AllocationType                               nameAllocationType = NON_GLOBAL;
-	VariableCondition_BuildSelfFunc*                     _buildSelf = _WallVC_BuildSelf;
-	VariableCondition_PrintConciseFunc*               _printConcise = _WallVC_PrintConcise;
-	VariableCondition_ReadDictionaryFunc*           _readDictionary = _WallVC_ReadDictionary;
-	VariableCondition_GetSetFunc*                           _getSet = _WallVC_GetSet;
-	VariableCondition_GetVariableCountFunc*       _getVariableCount = _WallVC_GetVariableCount;
-	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _WallVC_GetVariableIndex;
-	VariableCondition_GetValueIndexFunc*             _getValueIndex = _WallVC_GetValueIndex;
-	VariableCondition_GetValueCountFunc*             _getValueCount = _WallVC_GetValueCount;
-	VariableCondition_GetValueFunc*                       _getValue = _WallVC_GetValue;
-	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
-
-	return _WallVC_New(  WALLVC_PASSARGS  );
-}
-
-WallVC* _WallVC_New(  WALLVC_DEFARGS  ) {
-	WallVC* self;
-	
-	/* Allocate memory/General info */
-	assert( _sizeOfSelf >= sizeof(WallVC) );
-	self = (WallVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	
-	return self;
-}
-
-void _WallVC_Init( void* wallVC, Name _dictionaryEntryName, void* _mesh ) {
-	WallVC* self = (WallVC*)wallVC;
-
-	self->_dictionaryEntryName = _dictionaryEntryName;
-	self->_mesh = (Mesh*)_mesh;
-	self->_wall = WallVC_Wall_Size;
-	self->_entryTbl = 0;
-	self->_entryCount = 0;
-}
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** General virtual functions
-*/
-
-void _WallVC_ReadDictionary( void* variableCondition, void* dictionary ) {
-	WallVC*			self = (WallVC*)variableCondition;
-	Dictionary_Entry_Value*	vcDictVal;
-	Dictionary_Entry_Value	_vcDictVal;
-	Dictionary_Entry_Value*	varsVal;
-	WallVC_Entry_Index	entry_I;
-	
-	/* Find dictionary entry */
-	if (self->_dictionaryEntryName)
-		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
-	else {
-		vcDictVal = &_vcDictVal;
-		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
-	}
-	
-	if (vcDictVal) {
-		char*	wallStr;
-		
-		/* Obtain which wall */
-		wallStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"wall" ) );
-		if (!strcasecmp(wallStr, "back"))
-			self->_wall = WallVC_Wall_Back;
-		else if (!strcasecmp(wallStr, "left"))
-			self->_wall = WallVC_Wall_Left;
-		else if (!strcasecmp(wallStr, "bottom"))
-			self->_wall = WallVC_Wall_Bottom;
-		else if (!strcasecmp(wallStr, "right"))
-			self->_wall = WallVC_Wall_Right;
-		else if (!strcasecmp(wallStr, "top"))
-			self->_wall = WallVC_Wall_Top;
-		else if (!strcasecmp(wallStr, "front"))
-			self->_wall = WallVC_Wall_Front;
-		else if (!strcasecmp(wallStr, "bottomLeft"))
-		    self->_wall = WallVC_Wall_BottomLeft;
-		else if (!strcasecmp(wallStr, "bottomRight"))
-		    self->_wall = WallVC_Wall_BottomRight;
-		else {
-			assert( 0 );
-			self->_wall = WallVC_Wall_Size; /* invalid entry */
-		}
-		
-		/* Obtain the variable entries */
-		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
-		self->_entryTbl = Memory_Alloc_Array( WallVC_Entry, self->_entryCount, "WallVC->_entryTbl" );
-		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
-		
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
-			char*			valType;
-			Dictionary_Entry_Value*	valueEntry;
-			Dictionary_Entry_Value*	varDictListVal;
-			
-			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
-			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
-			
-			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
-				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
-				
-			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
-			if (0 == strcasecmp(valType, "func"))
-			{
-				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
-				Index	cfIndex;
-				
-				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
-				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
-				if ( cfIndex == (unsigned)-1 ) {	
-					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
-
-					Journal_Printf( errorStr, "Error- in %s: While parsing "
-							"definition of wallVC \"%s\" (applies to wall \"%s\"), the cond. func. applied to "
-							"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
-							__func__, self->_dictionaryEntryName, WallVC_WallEnumToStr[self->_wall],
-							self->_entryTbl[entry_I].varName, funcName );
-					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
-					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
-					Journal_Printf( errorStr, ")\n");	
-					assert(0);
-				}	
-				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
-			}
-			else if (0 == strcasecmp(valType, "array"))
-			{
-				Dictionary_Entry_Value*	valueElement;
-				Index			i;
-
-				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
-				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
-				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
-													self->_entryTbl[entry_I].value.as.typeArray.size, "WallVC->_entryTbl[].value.as.typeArray.array" );
-					
-				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-				{
-					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
-					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
-						Dictionary_Entry_Value_AsDouble(valueElement);
-				}
-			}
-			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
-				 0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
-			{
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
-				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
-				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
-				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
-			}
-			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
-				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
-			}
-			else {
-				/* Assume double */
-				Journal_DPrintf( 
-					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
-					"Type to variable on variable condition not given, assuming double\n" );
-				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
-				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
-			}
-		}
-	}
-	else
-	{
-		self->_wall = WallVC_Wall_Size;
-		self->_entryCount = 0;
-		self->_entryTbl = NULL;
-	}
-}
-
-
-void _WallVC_Delete( void* wallVC ) {
-	WallVC* self = (WallVC*)wallVC;
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Delete(self);
-}
-
-void _WallVC_Destroy( void* wallVC, void* data ) {
-	WallVC* self = (WallVC*)wallVC;
-	
-	if (self->_entryTbl) Memory_Free(self->_entryTbl);
-	
-	/* Stg_Class_Delete parent */
-	_VariableCondition_Destroy( self, data );
-}
-
-void _WallVC_Print(void* wallVC, Stream* stream)
-{
-	WallVC*				self = (WallVC*)wallVC;
-	WallVC_Entry_Index		entry_I;
-	Index				i;
-	
-	/* Set the Journal for printing informations */
-	Stream* info = stream;
-	
-	/* General info */
-	Journal_Printf( info, "WallVC (ptr): %p\n", self);
-	
-	/* Virtual info */
-	
-	/* Stg_Class info */
-	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
-	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
-	if (self->_dictionaryEntryName)
-		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
-	Journal_Printf( info, "\t_wall: %s\n", self->_wall == WallVC_Wall_Front ? "Front" :
-			self->_wall == WallVC_Wall_Back ? "Back" : self->_wall == WallVC_Wall_Left ? "Left" :
-			self->_wall == WallVC_Wall_Right ? "Right" : self->_wall == WallVC_Wall_Top ? "Top" :
-			self->_wall == WallVC_Wall_Bottom ? "Bottom" : "None");
-	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
-	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
-	if (self->_entryTbl)
-		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
-		{
-			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
-			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
-			if (self->_entryTbl[entry_I].varName)
-				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
-			Journal_Printf( info, "\t\t\tvalue:\n");
-			switch (self->_entryTbl[entry_I].value.type)
-			{
-			case VC_ValueType_Double:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
-				Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
-				break;
-					
-			case VC_ValueType_Int:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
-				Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
-				break;
-					
-			case VC_ValueType_Short:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
-				Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
-				break;
-					
-			case VC_ValueType_Char:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
-				Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
-				break;
-					
-			case VC_ValueType_Ptr:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
-				Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
-				break;
-					
-			case VC_ValueType_DoubleArray:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
-				Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
-				Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
-						self->_entryTbl[entry_I].value.as.typeArray.array);
-				if (self->_entryTbl[entry_I].value.as.typeArray.array)
-					for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
-						Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
-								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
-				break;
-					
-			case VC_ValueType_CFIndex:
-				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
-				Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
-				break;
-			}
-		}
-	Journal_Printf( info, "\t_mesh (ptr): %p\n", self->_mesh);
-	
-	/* Print parent */
-	_VariableCondition_Print(self);
-}
-
-
-void* _WallVC_Copy( const void* wallVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
-	WallVC*		self = (WallVC*)wallVC;
-	WallVC*		newWallVC;
-	PtrMap*		map = ptrMap;
-	Bool		ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-	
-	newWallVC = (WallVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
-	
-	newWallVC->_dictionaryEntryName = self->_dictionaryEntryName;
-	newWallVC->_wall = self->_wall;
-	newWallVC->_entryCount = self->_entryCount;
-	
-	if( deep ) {
-		newWallVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
-		
-		if( (newWallVC->_entryTbl = (WallVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
-			newWallVC->_entryTbl = Memory_Alloc_Array( WallVC_Entry, newWallVC->_entryCount, "WallVC->_entryTbl");
-			memcpy( newWallVC->_entryTbl, self->_entryTbl, sizeof(WallVC_Entry) * newWallVC->_entryCount );
-			PtrMap_Append( map, newWallVC->_entryTbl, self->_entryTbl );
-		}
-	}
-	else {
-		newWallVC->_mesh = self->_mesh;
-		newWallVC->_entryTbl = self->_entryTbl;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newWallVC;
-}
-
-
-void _WallVC_Build(  void* wallVC, void* data ) {
-	WallVC*			self = (WallVC*)wallVC;
-	
-	_WallVC_BuildSelf( self, data );
-	
-	_VariableCondition_Build( self, data );
-}
-	
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Macros
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _WallVC_AssignFromXML( void* wallVC, Stg_ComponentFactory* cf, void* data ) {
-}
-
-void _WallVC_BuildSelf(  void* wallVC, void* data ) {
-	WallVC*			self = (WallVC*)wallVC;
-	
-	if( self->_mesh ) {
-		Stg_Component_Build( self->_mesh, data, False );
-	}
-}
-
-
-IndexSet* _WallVC_GetSet(void* variableCondition)
-{
-	WallVC*		self = (WallVC*)variableCondition;
-	IndexSet*	set = NULL;
-	Stream*		warningStr = Journal_Register( Error_Type, (Name)self->type );
-	unsigned	nDims;
-	Grid*		vertGrid;
-
-	nDims = Mesh_GetDimSize( self->_mesh );
-	vertGrid = *(Grid** )ExtensionManager_Get( self->_mesh->info, self->_mesh, 
-						  ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
-	
-	switch (self->_wall) {
-	case WallVC_Wall_Front:
-		if ( nDims < 3 || !vertGrid->sizes[2]  ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "K" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalFrontSet( self->_mesh );
-		}
-		break;
-			
-	case WallVC_Wall_Back:
-		if ( nDims < 3 || !vertGrid->sizes[2] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "K" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalBackSet( self->_mesh );
-		}	
-		break;
-			
-	case WallVC_Wall_Top:
-		if ( nDims < 2 || !vertGrid->sizes[1] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "J" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalTopSet(self->_mesh);
-		}	
-		break;
-			
-	case WallVC_Wall_Bottom:
-		if ( nDims < 2 || !vertGrid->sizes[1] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "J" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalBottomSet(self->_mesh);
-		}	
-		break;
-			
-	case WallVC_Wall_Left:
-		if ( nDims < 1 ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "I" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalLeftSet(self->_mesh);
-		}	
-		break;
-			
-	case WallVC_Wall_Right:
-		if( nDims < 1 ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "I" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalRightSet(self->_mesh);
-		}
-		break;
-
-	case WallVC_Wall_BottomLeft:
-		if ( nDims < 2 || !vertGrid->sizes[1] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "J" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalBottomLeftSet(self->_mesh);
-		}	
-		break;
-
-	case WallVC_Wall_BottomRight:
-		if ( nDims < 2 || !vertGrid->sizes[1] ) {
-			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
-					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
-					WallVC_WallEnumToStr[self->_wall], "J" );
-			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
-		}
-		else {
-			set = RegularMeshUtils_CreateGlobalBottomRightSet(self->_mesh);
-		}	
-		break;
-			
-	case WallVC_Wall_Size:
-	default:
-		assert(0);
-		break;
-	}
-	
-	return set;
-}
-
-
-VariableCondition_VariableIndex _WallVC_GetVariableCount(void* variableCondition, Index globalIndex)
-{
-	WallVC*	self = (WallVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-Variable_Index _WallVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex)
-{
-	WallVC*		self = (WallVC*)variableCondition;
-	Variable_Index	searchedIndex = 0;
-	Stream*		errorStr = Journal_Register( Error_Type, (Name)self->type  );
-	Name		varName;
-	
-	varName = self->_entryTbl[varIndex].varName;
-	searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
-	
-	Journal_Firewall( ( searchedIndex < self->variable_Register->count ), errorStr, "Error- in %s: searching for index of "
-			  "varIndex %u (\"%s\") at global node number %u failed - register returned index %u, greater than "
-			  "count %u.\n", __func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
-
-	return searchedIndex; 
-}
-
-
-VariableCondition_ValueIndex _WallVC_GetValueIndex(
-	void*				variableCondition, 
-	Index				globalIndex, 
-	VariableCondition_VariableIndex	varIndex)
-{
-	return varIndex;
-}
-
-
-VariableCondition_ValueIndex _WallVC_GetValueCount(void* variableCondition)
-{
-	WallVC*	self = (WallVC*)variableCondition;
-	
-	return self->_entryCount;
-}
-
-
-VariableCondition_Value _WallVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex)
-{
-	WallVC*	self = (WallVC*)variableCondition;
-
-	return self->_entryTbl[valIndex].value;
-}
-
-void _WallVC_PrintConcise( void* variableCondition, Stream* stream ) {
-	WallVC*		self = (WallVC*)variableCondition;
-	
-	Journal_Printf( stream, "\ttype: %s, set: ", self->type );
-	Journal_Printf( stream, "%s\n", 
-			self->_wall == WallVC_Wall_Front ? "Front" :
-			self->_wall == WallVC_Wall_Back ? "Back" : 
-			self->_wall == WallVC_Wall_Left ? "Left" :
-			self->_wall == WallVC_Wall_Right ? "Right" : 
-			self->_wall == WallVC_Wall_Top ? "Top" :
-			self->_wall == WallVC_Wall_Bottom ? "Bottom" : "None" );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Build functions
-*/
-
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Functions
-*/
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/src/WallVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/WallVC.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,646 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: WallVC.c 4153 2007-07-26 02:25:22Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+
+#include "types.h"
+#include "DomainContext.h"
+#include "WallVC.h"
+#include "RegularMeshUtils.h"
+
+#include <string.h>
+#include <assert.h>
+
+
+const Type WallVC_Type = "WallVC";
+const Name defaultWallVCName = "defaultWallVCName";
+
+Name WallVC_WallEnumToStr[WallVC_Wall_Size] = {
+	"back",
+	"left",
+	"bottom",
+	"right",
+	"top",
+	"front" };
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Constructor
+*/
+
+VariableCondition* WallVC_Factory(
+	AbstractContext*					context,
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									data )
+{
+	return (VariableCondition*)WallVC_New( defaultWallVCName, context, NULL, variable_Register, conFunc_Register, dictionary, (Mesh*)data );
+}
+
+WallVC* WallVC_New(
+	Name									name,
+	AbstractContext*					context,
+	Name									_dictionaryEntryName, 
+	Variable_Register*				variable_Register, 
+	ConditionFunction_Register*	conFunc_Register, 
+	Dictionary*							dictionary,
+	void*									_mesh )
+{
+	WallVC* self = _WallVC_DefaultNew( name );
+
+	self->isConstructed = True;
+	_VariableCondition_Init( self, context, variable_Register, conFunc_Register, dictionary );
+	_WallVC_Init( self, _dictionaryEntryName, _mesh );
+
+	return self;
+}
+
+WallVC* _WallVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(WallVC);
+	Type                                                       type = WallVC_Type;
+	Stg_Class_DeleteFunction*                               _delete = _WallVC_Delete;
+	Stg_Class_PrintFunction*                                 _print = _WallVC_Print;
+	Stg_Class_CopyFunction*                                   _copy = _WallVC_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = (Stg_Component_DefaultConstructorFunction*)_WallVC_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _WallVC_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _WallVC_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _VariableCondition_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _VariableCondition_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _WallVC_Destroy;
+	AllocationType                               nameAllocationType = NON_GLOBAL;
+	VariableCondition_BuildSelfFunc*                     _buildSelf = _WallVC_BuildSelf;
+	VariableCondition_PrintConciseFunc*               _printConcise = _WallVC_PrintConcise;
+	VariableCondition_ReadDictionaryFunc*           _readDictionary = _WallVC_ReadDictionary;
+	VariableCondition_GetSetFunc*                           _getSet = _WallVC_GetSet;
+	VariableCondition_GetVariableCountFunc*       _getVariableCount = _WallVC_GetVariableCount;
+	VariableCondition_GetVariableIndexFunc*       _getVariableIndex = _WallVC_GetVariableIndex;
+	VariableCondition_GetValueIndexFunc*             _getValueIndex = _WallVC_GetValueIndex;
+	VariableCondition_GetValueCountFunc*             _getValueCount = _WallVC_GetValueCount;
+	VariableCondition_GetValueFunc*                       _getValue = _WallVC_GetValue;
+	VariableCondition_ApplyFunc*                             _apply = _VariableCondition_Apply;
+
+	return _WallVC_New(  WALLVC_PASSARGS  );
+}
+
+WallVC* _WallVC_New(  WALLVC_DEFARGS  ) {
+	WallVC* self;
+	
+	/* Allocate memory/General info */
+	assert( _sizeOfSelf >= sizeof(WallVC) );
+	self = (WallVC*)_VariableCondition_New(  VARIABLECONDITION_PASSARGS  );
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	
+	return self;
+}
+
+void _WallVC_Init( void* wallVC, Name _dictionaryEntryName, void* _mesh ) {
+	WallVC* self = (WallVC*)wallVC;
+
+	self->_dictionaryEntryName = _dictionaryEntryName;
+	self->_mesh = (Mesh*)_mesh;
+	self->_wall = WallVC_Wall_Size;
+	self->_entryTbl = 0;
+	self->_entryCount = 0;
+}
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** General virtual functions
+*/
+
+void _WallVC_ReadDictionary( void* variableCondition, void* dictionary ) {
+	WallVC*			self = (WallVC*)variableCondition;
+	Dictionary_Entry_Value*	vcDictVal;
+	Dictionary_Entry_Value	_vcDictVal;
+	Dictionary_Entry_Value*	varsVal;
+	WallVC_Entry_Index	entry_I;
+	
+	/* Find dictionary entry */
+	if (self->_dictionaryEntryName)
+		vcDictVal = Dictionary_Get( dictionary, (Dictionary_Entry_Key)self->_dictionaryEntryName );
+	else {
+		vcDictVal = &_vcDictVal;
+		Dictionary_Entry_Value_InitFromStruct(vcDictVal, dictionary);
+	}
+	
+	if (vcDictVal) {
+		char*	wallStr;
+		
+		/* Obtain which wall */
+		wallStr = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"wall" ) );
+		if (!strcasecmp(wallStr, "back"))
+			self->_wall = WallVC_Wall_Back;
+		else if (!strcasecmp(wallStr, "left"))
+			self->_wall = WallVC_Wall_Left;
+		else if (!strcasecmp(wallStr, "bottom"))
+			self->_wall = WallVC_Wall_Bottom;
+		else if (!strcasecmp(wallStr, "right"))
+			self->_wall = WallVC_Wall_Right;
+		else if (!strcasecmp(wallStr, "top"))
+			self->_wall = WallVC_Wall_Top;
+		else if (!strcasecmp(wallStr, "front"))
+			self->_wall = WallVC_Wall_Front;
+		else if (!strcasecmp(wallStr, "bottomLeft"))
+		    self->_wall = WallVC_Wall_BottomLeft;
+		else if (!strcasecmp(wallStr, "bottomRight"))
+		    self->_wall = WallVC_Wall_BottomRight;
+		else {
+			assert( 0 );
+			self->_wall = WallVC_Wall_Size; /* invalid entry */
+		}
+		
+		/* Obtain the variable entries */
+		self->_entryCount = Dictionary_Entry_Value_GetCount(Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables") );
+		self->_entryTbl = Memory_Alloc_Array( WallVC_Entry, self->_entryCount, "WallVC->_entryTbl" );
+		varsVal = Dictionary_Entry_Value_GetMember( vcDictVal, (Dictionary_Entry_Key)"variables");
+		
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++ ) {
+			char*			valType;
+			Dictionary_Entry_Value*	valueEntry;
+			Dictionary_Entry_Value*	varDictListVal;
+			
+			varDictListVal = Dictionary_Entry_Value_GetElement(varsVal, entry_I);
+			valueEntry = Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"value" );
+			
+			self->_entryTbl[entry_I].varName = Dictionary_Entry_Value_AsString(
+				Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"name") );
+				
+			valType = Dictionary_Entry_Value_AsString(Dictionary_Entry_Value_GetMember( varDictListVal, (Dictionary_Entry_Key)"type") );
+			if (0 == strcasecmp(valType, "func"))
+			{
+				char*	funcName = Dictionary_Entry_Value_AsString(valueEntry);
+				Index	cfIndex;
+				
+				self->_entryTbl[entry_I].value.type = VC_ValueType_CFIndex;
+				cfIndex = ConditionFunction_Register_GetIndex( self->conFunc_Register, funcName);
+				if ( cfIndex == (unsigned)-1 ) {	
+					Stream*	errorStr = Journal_Register( Error_Type, (Name)self->type  );
+
+					Journal_Printf( errorStr, "Error- in %s: While parsing "
+							"definition of wallVC \"%s\" (applies to wall \"%s\"), the cond. func. applied to "
+							"variable \"%s\" - \"%s\" - wasn't found in the c.f. register.\n",
+							__func__, self->_dictionaryEntryName, WallVC_WallEnumToStr[self->_wall],
+							self->_entryTbl[entry_I].varName, funcName );
+					Journal_Printf( errorStr, "(Available functions in the C.F. register are: ");	
+					ConditionFunction_Register_PrintNameOfEachFunc( self->conFunc_Register, errorStr );
+					Journal_Printf( errorStr, ")\n");	
+					assert(0);
+				}	
+				self->_entryTbl[entry_I].value.as.typeCFIndex = cfIndex;
+			}
+			else if (0 == strcasecmp(valType, "array"))
+			{
+				Dictionary_Entry_Value*	valueElement;
+				Index			i;
+
+				self->_entryTbl[entry_I].value.type = VC_ValueType_DoubleArray;
+				self->_entryTbl[entry_I].value.as.typeArray.size = Dictionary_Entry_Value_GetCount(valueEntry);
+				self->_entryTbl[entry_I].value.as.typeArray.array = Memory_Alloc_Array( double,
+													self->_entryTbl[entry_I].value.as.typeArray.size, "WallVC->_entryTbl[].value.as.typeArray.array" );
+					
+				for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+				{
+					valueElement = Dictionary_Entry_Value_GetElement(valueEntry, i);
+					self->_entryTbl[entry_I].value.as.typeArray.array[i] = 
+						Dictionary_Entry_Value_AsDouble(valueElement);
+				}
+			}
+			else if( 0 == strcasecmp( valType, "double" ) || 0 == strcasecmp( valType, "d" ) ||
+				 0 == strcasecmp( valType, "float" ) || 0 == strcasecmp( valType, "f" ) )
+			{
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "integer" ) || 0 == strcasecmp( valType, "int" ) || 0 == strcasecmp( valType, "i" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Int;
+				self->_entryTbl[entry_I].value.as.typeInt = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "short" ) || 0 == strcasecmp( valType, "s" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Short;
+				self->_entryTbl[entry_I].value.as.typeShort = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "char" ) || 0 == strcasecmp( valType, "c" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Char;
+				self->_entryTbl[entry_I].value.as.typeChar = Dictionary_Entry_Value_AsUnsignedInt( valueEntry );
+			}
+			else if( 0 == strcasecmp( valType, "pointer" ) || 0 == strcasecmp( valType, "ptr" ) || 0 == strcasecmp( valType, "p" ) ) {
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Ptr;
+				self->_entryTbl[entry_I].value.as.typePtr = (void*) ( (ArithPointer)Dictionary_Entry_Value_AsUnsignedInt( valueEntry ));
+			}
+			else {
+				/* Assume double */
+				Journal_DPrintf( 
+					Journal_Register( InfoStream_Type, (Name)"myStream"  ), 
+					"Type to variable on variable condition not given, assuming double\n" );
+				self->_entryTbl[entry_I].value.type = VC_ValueType_Double;
+				self->_entryTbl[entry_I].value.as.typeDouble = Dictionary_Entry_Value_AsDouble( valueEntry );
+			}
+		}
+	}
+	else
+	{
+		self->_wall = WallVC_Wall_Size;
+		self->_entryCount = 0;
+		self->_entryTbl = NULL;
+	}
+}
+
+
+void _WallVC_Delete( void* wallVC ) {
+	WallVC* self = (WallVC*)wallVC;
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Delete(self);
+}
+
+void _WallVC_Destroy( void* wallVC, void* data ) {
+	WallVC* self = (WallVC*)wallVC;
+	
+	if (self->_entryTbl) Memory_Free(self->_entryTbl);
+	
+	/* Stg_Class_Delete parent */
+	_VariableCondition_Destroy( self, data );
+}
+
+void _WallVC_Print(void* wallVC, Stream* stream)
+{
+	WallVC*				self = (WallVC*)wallVC;
+	WallVC_Entry_Index		entry_I;
+	Index				i;
+	
+	/* Set the Journal for printing informations */
+	Stream* info = stream;
+	
+	/* General info */
+	Journal_Printf( info, "WallVC (ptr): %p\n", self);
+	
+	/* Virtual info */
+	
+	/* Stg_Class info */
+	Journal_Printf( info, "\tdictionary (ptr): %p\n", self->dictionary);
+	Journal_Printf( info, "\t_dictionaryEntryName (ptr): %p\n", self->_dictionaryEntryName);
+	if (self->_dictionaryEntryName)
+		Journal_Printf( info, "\t\t_dictionaryEntryName: %s\n", self->_dictionaryEntryName);
+	Journal_Printf( info, "\t_wall: %s\n", self->_wall == WallVC_Wall_Front ? "Front" :
+			self->_wall == WallVC_Wall_Back ? "Back" : self->_wall == WallVC_Wall_Left ? "Left" :
+			self->_wall == WallVC_Wall_Right ? "Right" : self->_wall == WallVC_Wall_Top ? "Top" :
+			self->_wall == WallVC_Wall_Bottom ? "Bottom" : "None");
+	Journal_Printf( info, "\t_entryCount: %u\n", self->_entryCount);
+	Journal_Printf( info, "\t_entryTbl (ptr): %p\n", self->_entryTbl);
+	if (self->_entryTbl)
+		for (entry_I = 0; entry_I < self->_entryCount; entry_I++)
+		{
+			Journal_Printf( info, "\t\t_entryTbl[%u]:\n", entry_I);
+			Journal_Printf( info, "\t\t\tvarName (ptr): %p\n", self->_entryTbl[entry_I].varName);
+			if (self->_entryTbl[entry_I].varName)
+				Journal_Printf( info, "\t\t\t\tvarName: %s\n", self->_entryTbl[entry_I].varName);
+			Journal_Printf( info, "\t\t\tvalue:\n");
+			switch (self->_entryTbl[entry_I].value.type)
+			{
+			case VC_ValueType_Double:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Double\n" );
+				Journal_Printf( info, "\t\t\t\tasDouble: %g\n", self->_entryTbl[entry_I].value.as.typeDouble );
+				break;
+					
+			case VC_ValueType_Int:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Int\n" );
+				Journal_Printf( info, "\t\t\t\tasInt: %i\n", self->_entryTbl[entry_I].value.as.typeInt );
+				break;
+					
+			case VC_ValueType_Short:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Short\n" );
+				Journal_Printf( info, "\t\t\t\tasShort: %i\n", self->_entryTbl[entry_I].value.as.typeShort );
+				break;
+					
+			case VC_ValueType_Char:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Char\n");
+				Journal_Printf( info, "\t\t\t\tasChar: %c\n", self->_entryTbl[entry_I].value.as.typeChar );
+				break;
+					
+			case VC_ValueType_Ptr:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_Ptr\n");
+				Journal_Printf( info, "\t\t\t\tasPtr: %g\n", self->_entryTbl[entry_I].value.as.typePtr );
+				break;
+					
+			case VC_ValueType_DoubleArray:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_DoubleArray\n");
+				Journal_Printf( info, "\t\t\t\tarraySize: %u\n", self->_entryTbl[entry_I].value.as.typeArray.size);
+				Journal_Printf( info, "\t\t\t\tasDoubleArray (ptr): %p\n", 
+						self->_entryTbl[entry_I].value.as.typeArray.array);
+				if (self->_entryTbl[entry_I].value.as.typeArray.array)
+					for (i = 0; i < self->_entryTbl[entry_I].value.as.typeArray.size; i++)
+						Journal_Printf( info, "\t\t\t\tasDoubleArray[%u]: %g\n", i,
+								self->_entryTbl[entry_I].value.as.typeArray.array[i]);
+				break;
+					
+			case VC_ValueType_CFIndex:
+				Journal_Printf( info, "\t\t\t\ttype: VC_ValueType_CFIndex\n");
+				Journal_Printf( info, "\t\t\t\tasCFIndex: %u\n", self->_entryTbl[entry_I].value.as.typeCFIndex);
+				break;
+			}
+		}
+	Journal_Printf( info, "\t_mesh (ptr): %p\n", self->_mesh);
+	
+	/* Print parent */
+	_VariableCondition_Print(self);
+}
+
+
+void* _WallVC_Copy( const void* wallVC, void* dest, Bool deep, Name nameExt, struct PtrMap* ptrMap ) {
+	WallVC*		self = (WallVC*)wallVC;
+	WallVC*		newWallVC;
+	PtrMap*		map = ptrMap;
+	Bool		ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+	
+	newWallVC = (WallVC*)_VariableCondition_Copy( self, dest, deep, nameExt, map );
+	
+	newWallVC->_dictionaryEntryName = self->_dictionaryEntryName;
+	newWallVC->_wall = self->_wall;
+	newWallVC->_entryCount = self->_entryCount;
+	
+	if( deep ) {
+		newWallVC->_mesh = (Mesh*)Stg_Class_Copy( self->_mesh, NULL, deep, nameExt, map );
+		
+		if( (newWallVC->_entryTbl = (WallVC_Entry*)PtrMap_Find( map, self->_entryTbl )) == NULL && self->_entryTbl ) {
+			newWallVC->_entryTbl = Memory_Alloc_Array( WallVC_Entry, newWallVC->_entryCount, "WallVC->_entryTbl");
+			memcpy( newWallVC->_entryTbl, self->_entryTbl, sizeof(WallVC_Entry) * newWallVC->_entryCount );
+			PtrMap_Append( map, newWallVC->_entryTbl, self->_entryTbl );
+		}
+	}
+	else {
+		newWallVC->_mesh = self->_mesh;
+		newWallVC->_entryTbl = self->_entryTbl;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newWallVC;
+}
+
+
+void _WallVC_Build(  void* wallVC, void* data ) {
+	WallVC*			self = (WallVC*)wallVC;
+	
+	_WallVC_BuildSelf( self, data );
+	
+	_VariableCondition_Build( self, data );
+}
+	
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Macros
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _WallVC_AssignFromXML( void* wallVC, Stg_ComponentFactory* cf, void* data ) {
+}
+
+void _WallVC_BuildSelf(  void* wallVC, void* data ) {
+	WallVC*			self = (WallVC*)wallVC;
+	
+	if( self->_mesh ) {
+		Stg_Component_Build( self->_mesh, data, False );
+	}
+}
+
+
+IndexSet* _WallVC_GetSet(void* variableCondition)
+{
+	WallVC*		self = (WallVC*)variableCondition;
+	IndexSet*	set = NULL;
+	Stream*		warningStr = Journal_Register( Error_Type, (Name)self->type );
+	unsigned	nDims;
+	Grid*		vertGrid;
+
+	nDims = Mesh_GetDimSize( self->_mesh );
+	vertGrid = *(Grid** )ExtensionManager_Get( self->_mesh->info, self->_mesh, 
+						  ExtensionManager_GetHandle( self->_mesh->info, (Name)"vertexGrid" ) );
+	
+	switch (self->_wall) {
+	case WallVC_Wall_Front:
+		if ( nDims < 3 || !vertGrid->sizes[2]  ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "K" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalFrontSet( self->_mesh );
+		}
+		break;
+			
+	case WallVC_Wall_Back:
+		if ( nDims < 3 || !vertGrid->sizes[2] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "K" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalBackSet( self->_mesh );
+		}	
+		break;
+			
+	case WallVC_Wall_Top:
+		if ( nDims < 2 || !vertGrid->sizes[1] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "J" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalTopSet(self->_mesh);
+		}	
+		break;
+			
+	case WallVC_Wall_Bottom:
+		if ( nDims < 2 || !vertGrid->sizes[1] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "J" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalBottomSet(self->_mesh);
+		}	
+		break;
+			
+	case WallVC_Wall_Left:
+		if ( nDims < 1 ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "I" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalLeftSet(self->_mesh);
+		}	
+		break;
+			
+	case WallVC_Wall_Right:
+		if( nDims < 1 ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "I" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalRightSet(self->_mesh);
+		}
+		break;
+
+	case WallVC_Wall_BottomLeft:
+		if ( nDims < 2 || !vertGrid->sizes[1] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "J" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalBottomLeftSet(self->_mesh);
+		}	
+		break;
+
+	case WallVC_Wall_BottomRight:
+		if ( nDims < 2 || !vertGrid->sizes[1] ) {
+			Journal_Printf( warningStr, "Warning - in %s: Can't build a %s wall VC "
+					"when mesh has no elements in the %s axis. Returning an empty set.\n", __func__,
+					WallVC_WallEnumToStr[self->_wall], "J" );
+			set = IndexSet_New( Mesh_GetDomainSize( self->_mesh, MT_VERTEX ) );
+		}
+		else {
+			set = RegularMeshUtils_CreateGlobalBottomRightSet(self->_mesh);
+		}	
+		break;
+			
+	case WallVC_Wall_Size:
+	default:
+		assert(0);
+		break;
+	}
+	
+	return set;
+}
+
+
+VariableCondition_VariableIndex _WallVC_GetVariableCount(void* variableCondition, Index globalIndex)
+{
+	WallVC*	self = (WallVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+Variable_Index _WallVC_GetVariableIndex(void* variableCondition, Index globalIndex, VariableCondition_VariableIndex varIndex)
+{
+	WallVC*		self = (WallVC*)variableCondition;
+	Variable_Index	searchedIndex = 0;
+	Stream*		errorStr = Journal_Register( Error_Type, (Name)self->type  );
+	Name		varName;
+	
+	varName = self->_entryTbl[varIndex].varName;
+	searchedIndex = Variable_Register_GetIndex(self->variable_Register, varName );
+	
+	Journal_Firewall( ( searchedIndex < self->variable_Register->count ), errorStr, "Error- in %s: searching for index of "
+			  "varIndex %u (\"%s\") at global node number %u failed - register returned index %u, greater than "
+			  "count %u.\n", __func__, varIndex, varName, globalIndex, searchedIndex, self->variable_Register->count );
+
+	return searchedIndex; 
+}
+
+
+VariableCondition_ValueIndex _WallVC_GetValueIndex(
+	void*				variableCondition, 
+	Index				globalIndex, 
+	VariableCondition_VariableIndex	varIndex)
+{
+	return varIndex;
+}
+
+
+VariableCondition_ValueIndex _WallVC_GetValueCount(void* variableCondition)
+{
+	WallVC*	self = (WallVC*)variableCondition;
+	
+	return self->_entryCount;
+}
+
+
+VariableCondition_Value _WallVC_GetValue(void* variableCondition, VariableCondition_ValueIndex valIndex)
+{
+	WallVC*	self = (WallVC*)variableCondition;
+
+	return self->_entryTbl[valIndex].value;
+}
+
+void _WallVC_PrintConcise( void* variableCondition, Stream* stream ) {
+	WallVC*		self = (WallVC*)variableCondition;
+	
+	Journal_Printf( stream, "\ttype: %s, set: ", self->type );
+	Journal_Printf( stream, "%s\n", 
+			self->_wall == WallVC_Wall_Front ? "Front" :
+			self->_wall == WallVC_Wall_Back ? "Back" : 
+			self->_wall == WallVC_Wall_Left ? "Left" :
+			self->_wall == WallVC_Wall_Right ? "Right" : 
+			self->_wall == WallVC_Wall_Top ? "Top" :
+			self->_wall == WallVC_Wall_Bottom ? "Bottom" : "None" );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Build functions
+*/
+
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Functions
+*/
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/AllNodesVCSuite.c
--- a/Utils/tests/AllNodesVCSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,221 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the AllNodesVCSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "AllNodesVCSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} AllNodesVCSuiteData;
-
-void AllNodesVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
-	*(double *)result = 20.0;
-}
-
-Mesh* AllNodesVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-
-	gen = CartesianGenerator_New( "", NULL );
-	gen->shadowDepth = 0;
-	CartesianGenerator_SetDimSize( gen, nDims ); 
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void AllNodesVCSuite_Setup( AllNodesVCSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void AllNodesVCSuite_Teardown( AllNodesVCSuiteData* data ) {
-}
-
-/* Prototype because I can not find the prototype in any headers. */
-Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
-
-void AllNodesVCSuite_TestAllNodesVC( AllNodesVCSuiteData* data ) {
-	unsigned								nDomains;
-	unsigned								nDims = 3;
-	unsigned								meshSize[3] = {3, 3, 3};
-	int									procToWatch;
-	double								minCrds[3] = {0.0, 0.0, 0.0};
-	double								maxCrds[3] = {1.0, 1.0, 1.0};
-	double*								array[7];
-	Name									vcKey = "AllNodesVC";
-	Name									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
-	char									input_file[PCU_PATH_MAX];
-	char									expected_file[PCU_PATH_MAX];
-	Mesh*									mesh;
-	Variable_Register*				variable_Register;
-	ConditionFunction*				quadCF;
-	ConditionFunction_Register*	conFunc_Register;
-	ExtensionManager_Register*		extensionMgr_Register;
-	Dictionary*							dictionary;
-	Stream*								stream;
-	XML_IO_Handler*					io_handler;
-	Variable*							var[7];
-	VariableCondition*				vc; 
-	Index									i, j, k;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   io_handler = XML_IO_Handler_New();
-
- 	stream = Journal_Register( Info_Type, (Name)"AllNodesVCStream"  );
-   Stream_RedirectFile( stream, "testAllNodesVC.dat" );
-
-   dictionary = Dictionary_New();
-   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
-
-	/* Input file */
-	pcu_filename_input( "allVC.xml", input_file );
-   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
-   fflush(stdout);
-
-   extensionMgr_Register = ExtensionManager_Register_New(); 
-
- 	/* Create a mesh. */
-   mesh = (Mesh*) AllNodesVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
-
-   /* Create CF stuff */
-   quadCF = ConditionFunction_New( AllNodesVCSuite_quadratic, (Name)"quadratic");
-   conFunc_Register = ConditionFunction_Register_New( );
-   ConditionFunction_Register_Add(conFunc_Register, quadCF);
-
-	/* Create variable register */
-   variable_Register = Variable_Register_New();
-
-   /* Create variables */
-   for (i = 0; i < 6; i++) {
-		array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
-      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
-      Variable_Register_Add(variable_Register, var[i]);
-   }
-   array[6] = Memory_Alloc_Array( double, nDomains*5, "array[6]" );
-   var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
-   Variable_Register_Add(variable_Register, var[6]);
-   Variable_Register_BuildAll(variable_Register);
-
-   /* Create AllVC */
-   vc = (VariableCondition*)AllNodesVC_New( "AllNodesVC", NULL, vcKey, variable_Register, conFunc_Register, dictionary, mesh );
-   Stg_Component_Build( vc, 0, False );
-
-   for (j = 0; j < 6; j++)
-      memset(array[j], 0, sizeof(double)*nDomains);
-   memset(array[6], 0, sizeof(double)*nDomains*5);
-   VariableCondition_Apply(vc, NULL);
-
-	if (data->rank == procToWatch) {
-		Journal_Printf( stream,"Testing for %s\n", vcKey);
-		for (j = 0; j < 6; j++) {
-			Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0]) ;
-			for (k = 1; k < nDomains; k++)
-				Journal_Printf( stream, ", %.2lf", array[j][k] );
-      }
-		Journal_Printf( stream, "\nvar[6]: %.2lf", array[6][0] );
-		for (j = 1; j < nDomains*5; j++)
-			Journal_Printf( stream, ", %.2lf", array[6][j] );
-		Journal_Printf( stream, "\n\n" );
-
-		for (j = 0; j < 7; j++) {
-			for (k = 0; k < nDomains; k++)
-				Journal_Printf( stream, "%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False" );
-			Journal_Printf( stream, "\n" );
-		} Journal_Printf( stream, "\n" );
-
-		for (j = 0; j < 7; j++) {
-			for (k = 0; k < nDomains; k++) {
-				VariableCondition_ValueIndex  valIndex;
-
-            valIndex = VariableCondition_GetValueIndex(vc, k, j);
-            if (valIndex != (unsigned)-1)
-					Journal_Printf( stream, "%03u ", valIndex);
-            else
-					Journal_Printf( stream, "XXX ");
-			} Journal_Printf( stream, "\n" );
-		} Journal_Printf( stream, "\n" );
-
-		pcu_filename_expected( "testAllNodesVC.expected", expected_file );
-		pcu_check_fileEq( "testAllNodesVC.dat", expected_file );
-		remove( "testAllNodesVC.dat" );
-	}
-
-   Stg_Class_Delete(vc);
-   Stg_Class_Delete(variable_Register);
-
-   for (i = 0; i < 7; i++) {
-      Stg_Class_Delete(var[i]);
-      if (array[i]) Memory_Free(array[i]);
-   }
-
-	Stg_Class_Delete(extensionMgr_Register);
-	Stg_Class_Delete(io_handler);
-   Stg_Class_Delete(conFunc_Register);
-   Stg_Class_Delete(dictionary);
-   FreeObject( mesh );
-}
-
-void AllNodesVCSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, AllNodesVCSuiteData );
-   pcu_suite_setFixtures( suite, AllNodesVCSuite_Setup, AllNodesVCSuite_Teardown );
-   pcu_suite_addTest( suite, AllNodesVCSuite_TestAllNodesVC );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/AllNodesVCSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/AllNodesVCSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,221 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the AllNodesVCSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "AllNodesVCSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} AllNodesVCSuiteData;
+
+void AllNodesVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
+	*(double *)result = 20.0;
+}
+
+Mesh* AllNodesVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+
+	gen = CartesianGenerator_New( "", NULL );
+	gen->shadowDepth = 0;
+	CartesianGenerator_SetDimSize( gen, nDims ); 
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void AllNodesVCSuite_Setup( AllNodesVCSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void AllNodesVCSuite_Teardown( AllNodesVCSuiteData* data ) {
+}
+
+/* Prototype because I can not find the prototype in any headers. */
+Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
+
+void AllNodesVCSuite_TestAllNodesVC( AllNodesVCSuiteData* data ) {
+	unsigned								nDomains;
+	unsigned								nDims = 3;
+	unsigned								meshSize[3] = {3, 3, 3};
+	int									procToWatch;
+	double								minCrds[3] = {0.0, 0.0, 0.0};
+	double								maxCrds[3] = {1.0, 1.0, 1.0};
+	double*								array[7];
+	Name									vcKey = "AllNodesVC";
+	Name									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
+	char									input_file[PCU_PATH_MAX];
+	char									expected_file[PCU_PATH_MAX];
+	Mesh*									mesh;
+	Variable_Register*				variable_Register;
+	ConditionFunction*				quadCF;
+	ConditionFunction_Register*	conFunc_Register;
+	ExtensionManager_Register*		extensionMgr_Register;
+	Dictionary*							dictionary;
+	Stream*								stream;
+	XML_IO_Handler*					io_handler;
+	Variable*							var[7];
+	VariableCondition*				vc; 
+	Index									i, j, k;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   io_handler = XML_IO_Handler_New();
+
+ 	stream = Journal_Register( Info_Type, (Name)"AllNodesVCStream"  );
+   Stream_RedirectFile( stream, "testAllNodesVC.dat" );
+
+   dictionary = Dictionary_New();
+   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
+
+	/* Input file */
+	pcu_filename_input( "allVC.xml", input_file );
+   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
+   fflush(stdout);
+
+   extensionMgr_Register = ExtensionManager_Register_New(); 
+
+ 	/* Create a mesh. */
+   mesh = (Mesh*) AllNodesVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
+
+   /* Create CF stuff */
+   quadCF = ConditionFunction_New( AllNodesVCSuite_quadratic, (Name)"quadratic");
+   conFunc_Register = ConditionFunction_Register_New( );
+   ConditionFunction_Register_Add(conFunc_Register, quadCF);
+
+	/* Create variable register */
+   variable_Register = Variable_Register_New();
+
+   /* Create variables */
+   for (i = 0; i < 6; i++) {
+		array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
+      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
+      Variable_Register_Add(variable_Register, var[i]);
+   }
+   array[6] = Memory_Alloc_Array( double, nDomains*5, "array[6]" );
+   var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
+   Variable_Register_Add(variable_Register, var[6]);
+   Variable_Register_BuildAll(variable_Register);
+
+   /* Create AllVC */
+   vc = (VariableCondition*)AllNodesVC_New( "AllNodesVC", NULL, vcKey, variable_Register, conFunc_Register, dictionary, mesh );
+   Stg_Component_Build( vc, 0, False );
+
+   for (j = 0; j < 6; j++)
+      memset(array[j], 0, sizeof(double)*nDomains);
+   memset(array[6], 0, sizeof(double)*nDomains*5);
+   VariableCondition_Apply(vc, NULL);
+
+	if (data->rank == procToWatch) {
+		Journal_Printf( stream,"Testing for %s\n", vcKey);
+		for (j = 0; j < 6; j++) {
+			Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0]) ;
+			for (k = 1; k < nDomains; k++)
+				Journal_Printf( stream, ", %.2lf", array[j][k] );
+      }
+		Journal_Printf( stream, "\nvar[6]: %.2lf", array[6][0] );
+		for (j = 1; j < nDomains*5; j++)
+			Journal_Printf( stream, ", %.2lf", array[6][j] );
+		Journal_Printf( stream, "\n\n" );
+
+		for (j = 0; j < 7; j++) {
+			for (k = 0; k < nDomains; k++)
+				Journal_Printf( stream, "%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False" );
+			Journal_Printf( stream, "\n" );
+		} Journal_Printf( stream, "\n" );
+
+		for (j = 0; j < 7; j++) {
+			for (k = 0; k < nDomains; k++) {
+				VariableCondition_ValueIndex  valIndex;
+
+            valIndex = VariableCondition_GetValueIndex(vc, k, j);
+            if (valIndex != (unsigned)-1)
+					Journal_Printf( stream, "%03u ", valIndex);
+            else
+					Journal_Printf( stream, "XXX ");
+			} Journal_Printf( stream, "\n" );
+		} Journal_Printf( stream, "\n" );
+
+		pcu_filename_expected( "testAllNodesVC.expected", expected_file );
+		pcu_check_fileEq( "testAllNodesVC.dat", expected_file );
+		remove( "testAllNodesVC.dat" );
+	}
+
+   Stg_Class_Delete(vc);
+   Stg_Class_Delete(variable_Register);
+
+   for (i = 0; i < 7; i++) {
+      Stg_Class_Delete(var[i]);
+      if (array[i]) Memory_Free(array[i]);
+   }
+
+	Stg_Class_Delete(extensionMgr_Register);
+	Stg_Class_Delete(io_handler);
+   Stg_Class_Delete(conFunc_Register);
+   Stg_Class_Delete(dictionary);
+   FreeObject( mesh );
+}
+
+void AllNodesVCSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, AllNodesVCSuiteData );
+   pcu_suite_setFixtures( suite, AllNodesVCSuite_Setup, AllNodesVCSuite_Teardown );
+   pcu_suite_addTest( suite, AllNodesVCSuite_TestAllNodesVC );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/CompositeVCSuite.c
--- a/Utils/tests/CompositeVCSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,361 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the CompositeVCSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "CompositeVCSuite.h"
-
-typedef struct {
-	MPI_Comm comm;
-	int		rank;
-	int		nProcs;
-} CompositeVCSuiteData;
-
-void CompositeVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
-   *(double *)result = 20.0;
-}
-
-void CompositeVCSuite_exponential(Index index, Variable_Index var_I, void* context, void* result) {
-   *(double *)result = 30.0;
-}
-
-
-Mesh* CompositeVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	unsigned					maxDecomp[3] = {0, 1, 1};
-
-	gen = CartesianGenerator_New( "", NULL );
-	gen->shadowDepth = 0;
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void CompositeVCSuite_Setup( CompositeVCSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void CompositeVCSuite_Teardown( CompositeVCSuiteData* data ) {
-}
-
-/* Prototype because I can not find the prototype in any headers. */
-Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
-
-void CompositeVCSuite_TestCompositeVC( CompositeVCSuiteData* data ) {
-	Stream*								stream;
-	Dictionary*							dictionary;
-	XML_IO_Handler*					io_handler;
-	unsigned								nDims = 3;
-	unsigned								meshSize[3] = {3, 3, 3};
-        int								procToWatch;
-	double								minCrds[3] = {0.0, 0.0, 0.0};
-	double								maxCrds[3] = {1.0, 1.0, 1.0};
-	Mesh*									mesh;
-	Variable*							var[7];
-	Variable_Register*				variable_Register;
-	WallVC*								vc;
-	CompositeVC*						cvc;
-	ConditionFunction*				quadCF;
-	ConditionFunction*				expCF;
-	ConditionFunction_Register*	conFunc_Register;
-	ExtensionManager_Register*		extensionMgr_Register;
-   double*								array[7];
-   Name									vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right", "WallVC_Top", "WallVC_Bottom"};
-   Name									vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName", "WallVC_TopName", "WallVC_BottomName"};
-   Name									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
-	char									input_file[PCU_PATH_MAX];
-	char									expected_file[PCU_PATH_MAX];
-   unsigned								nDomains;
-   Index									i, j, k;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   io_handler = XML_IO_Handler_New();
-
- 	stream = Journal_Register( Info_Type, (Name)"CompositeVCStream"  );
-   Stream_RedirectFile( stream, "testCompositeVC.dat" );
-
-   dictionary = Dictionary_New();
-   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
-
-	/* Input file */
-	pcu_filename_input( "wallVC.xml", input_file );
-   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
-   fflush(stdout);
-
-   extensionMgr_Register = ExtensionManager_Register_New(); 
-
- 	/* Create a mesh. */
-   mesh = (Mesh*) CompositeVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
-
-   /* Create CF stuff */
-	quadCF = ConditionFunction_New( CompositeVCSuite_quadratic, (Name)"quadratic" );
-	expCF = ConditionFunction_New( CompositeVCSuite_exponential, (Name)"exponential");
-	conFunc_Register = ConditionFunction_Register_New( );
-	ConditionFunction_Register_Add(conFunc_Register, quadCF);
-	ConditionFunction_Register_Add(conFunc_Register, expCF);
-
-	/* Create variable register */
-   variable_Register = Variable_Register_New();
-
-	/* Create variables */
-   for (i = 0; i < 6; i++) {
-      array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
-      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
-      Variable_Register_Add(variable_Register, var[i]);
-   }
-   array[6] = Memory_Alloc_Array( double, nDomains*5, "array[6]" );
-   var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
-   Variable_Register_Add(variable_Register, var[6]);
-   Variable_Register_BuildAll(variable_Register);
-
-   /* Create CompositeVC */
-   cvc = CompositeVC_New( "CompositeVC", NULL, variable_Register, conFunc_Register, dictionary, mesh );
-
-	for (i = 0; i < 6; i++) {
-		vc = WallVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
-		Stg_Component_Build( vc, 0, False );
-		CompositeVC_Add(cvc, vc, True);
-	}
-
-	Stg_Component_Build( cvc, 0, False );
-
-	for (j = 0; j < 6; j++)
-      memset(array[j], 0, sizeof(double)*nDomains);
-	memset(array[6], 0, sizeof(double)*nDomains*5);
-	VariableCondition_Apply(cvc, NULL);
-
-	if (data->rank == procToWatch) {
-      for (j = 0; j < 6; j++) {
-			Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0]);
-			for (k = 1; k < nDomains; k++)
-				Journal_Printf( stream, ", %.2lf", array[j][k]);
-		} Journal_Printf( stream, "\nvar[7]: %.2lf", array[6][0]);
-
-		for (j = 1; j < nDomains*5; j++)
-			Journal_Printf( stream, ", %.2lf", array[6][j]);
-		Journal_Printf( stream, "\n\n");
-
-		for (j = 0; j < 7; j++) {
-			for (k = 0; k < nDomains; k++)
-				Journal_Printf( stream, "%s ", VariableCondition_IsCondition(cvc, k, j) ? "True " : "False");
-			Journal_Printf( stream, "\n");
-		} Journal_Printf( stream, "\n");
-
-		for (j = 0; j < 7; j++) {
-			for (k = 0; k < nDomains; k++) {
-				VariableCondition_ValueIndex  valIndex;
-
-				valIndex = VariableCondition_GetValueIndex(cvc, k, j);
-				if (valIndex != (unsigned)-1)
-					Journal_Printf( stream, "%03u ", valIndex);
-				else
-					Journal_Printf( stream, "XXX ");
-			} Journal_Printf( stream, "\n");
-		} Journal_Printf( stream, "\n");
-
-		pcu_filename_expected( "testCompositeVC.expected", expected_file );
-		pcu_check_fileEq( "testCompositeVC.dat", expected_file );
-		remove( "testCompositeVC.dat" );
-   }
-
-	_Stg_Component_Delete(cvc);
-	Stg_Class_Delete(variable_Register);
-	for (i = 0; i < 7; i++) {
-		_Stg_Component_Delete(var[i]);
-		if (array[i]) Memory_Free(array[i]);
-	}
-	Stg_Class_Delete(extensionMgr_Register);
-	Stg_Class_Delete(io_handler);
-	Stg_Class_Delete(conFunc_Register);
-	Stg_Class_Delete(quadCF);
-	Stg_Class_Delete(expCF);
-	Stg_Class_Delete(dictionary);
-	FreeObject( mesh );
-}
-
-void CompositeVCSuite_TestCompositeVCDictionary( CompositeVCSuiteData* data ) {
-	Stream*								stream;
-	Dictionary*							dictionary;
-	XML_IO_Handler*					io_handler;
-	unsigned								nDims = 3;
-	unsigned								meshSize[3] = {2, 2, 2};
-	int								procToWatch;
-	double								minCrds[3] = {0.0, 0.0, 0.0};
-	double								maxCrds[3] = {1.0, 1.0, 1.0};
-	Mesh*									mesh;
-	Variable*							var[7];
-	Variable_Register*				variable_Register;
-	CompositeVC*						cvc;
-	ConditionFunction*				quadCF;
-	ConditionFunction*				expCF;
-	ConditionFunction_Register*	conFunc_Register;
-	ExtensionManager_Register*		extensionMgr_Register;
-	double*								array[7];
-	Name									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
-	char									input_file[PCU_PATH_MAX];
-	char									expected_file[PCU_PATH_MAX];
-	unsigned								nDomains;
-	Index									i, j, k;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   io_handler = XML_IO_Handler_New();
-
- 	stream = Journal_Register( Info_Type, (Name)"CompositeVCDictionaryStream"  );
-   Stream_RedirectFile( stream, "testCompositeVCDictionary.dat" );
-
-   dictionary = Dictionary_New();
-   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
-	
-	/* Input file */
-	pcu_filename_input( "compositeVC.xml", input_file );
-   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
-   fflush(stdout);
-
-	extensionMgr_Register = ExtensionManager_Register_New();
-
-	/* Create a mesh. */
-	mesh = (Mesh*) CompositeVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-	nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
-
-	/* Create CF stuff */
-	quadCF = ConditionFunction_New( CompositeVCSuite_quadratic, (Name)"quadratic" );
-	expCF = ConditionFunction_New( CompositeVCSuite_exponential, (Name)"exponential");
-	conFunc_Register = ConditionFunction_Register_New( );
-	ConditionFunction_Register_Add(conFunc_Register, quadCF);
-	ConditionFunction_Register_Add(conFunc_Register, expCF);
-
-	/* Create variable register */
-	variable_Register = Variable_Register_New();
-
-	/* Create variables */
-	for (i = 0; i < 6; i++) {
-		array[i] = Memory_Alloc_Array( double, 3*3*3, "array[i]" );
-		var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
- 		Variable_Register_Add(variable_Register, var[i]);
-	}
-	array[6] = Memory_Alloc_Array( double, 3*3*3*5, "array[6]" );
-	var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
-	Variable_Register_Add(variable_Register, var[6]);
-	Variable_Register_BuildAll(variable_Register);
-
-	/* Create CompositeVC */
-	cvc = CompositeVC_New( "CompositeVC", NULL, variable_Register, conFunc_Register, dictionary, mesh );
-	Stg_Component_Build( cvc, 0, False );
-
-	for (j = 0; j < 6; j++)
-		memset(array[j], 0, sizeof(double)*3*3*3);
-	memset(array[6], 0, sizeof(double)*3*3*3*5);
-	VariableCondition_Apply(cvc, NULL);
-
-	if (data->rank == procToWatch) {
-		for (j = 0; j < 6; j++) {
-			Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0] );
-			for (k = 1; k < 3*3*3; k++)
-				Journal_Printf( stream, ", %.2lf", array[j][k] );
-		}
-
-		Journal_Printf( stream, "\nvar[7]: %.2lf", array[6][0] );
-		for (j = 1; j < 3*3*3*5; j++)
-			Journal_Printf( stream, ", %.2lf", array[6][j] );
-		Journal_Printf( stream, "\n\n" );
-
-		for (j = 0; j < 7; j++) {
-			for (k = 0; k < 27; k++)
-				Journal_Printf( stream, "%s ", VariableCondition_IsCondition(cvc, k, j) ? "True " : "False" );
-			Journal_Printf( stream, "\n" );
-		} Journal_Printf( stream, "\n" );
-
-		for (j = 0; j < 7; j++) {
-			for (k = 0; k < 27; k++) {
-				VariableCondition_ValueIndex  valIndex;
-            valIndex = VariableCondition_GetValueIndex(cvc, k, j);
-				if (valIndex != (unsigned)-1)
-					Journal_Printf( stream, "%03u ", valIndex );
-				else
-               Journal_Printf( stream, "XXX " );
-			} Journal_Printf( stream, "\n" );
-		} Journal_Printf( stream, "\n" );
-
-		pcu_filename_expected( "testCompositeVC-dictionary.expected", expected_file );
-		pcu_check_fileEq( "testCompositeVCDictionary.dat", expected_file );
-		remove( "testCompositeVCDictionary.dat" );
-	}
-
-	_Stg_Component_Delete(cvc);
-	Stg_Class_Delete(variable_Register);
-	for (i = 0; i < 7; i++) {
-		_Stg_Component_Delete(var[i]);
- 		if (array[i]) Memory_Free(array[i]);
- 	}
-	Stg_Class_Delete(conFunc_Register);
-	Stg_Class_Delete(quadCF);
-	Stg_Class_Delete(expCF);
-	Stg_Class_Delete(dictionary);
-	FreeObject( mesh );
-}
-
-void CompositeVCSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, CompositeVCSuiteData );
-   pcu_suite_setFixtures( suite, CompositeVCSuite_Setup, CompositeVCSuite_Teardown );
-   pcu_suite_addTest( suite, CompositeVCSuite_TestCompositeVC );
-   pcu_suite_addTest( suite, CompositeVCSuite_TestCompositeVCDictionary );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/CompositeVCSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/CompositeVCSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,361 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the CompositeVCSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "CompositeVCSuite.h"
+
+typedef struct {
+	MPI_Comm comm;
+	int		rank;
+	int		nProcs;
+} CompositeVCSuiteData;
+
+void CompositeVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
+   *(double *)result = 20.0;
+}
+
+void CompositeVCSuite_exponential(Index index, Variable_Index var_I, void* context, void* result) {
+   *(double *)result = 30.0;
+}
+
+
+Mesh* CompositeVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	unsigned					maxDecomp[3] = {0, 1, 1};
+
+	gen = CartesianGenerator_New( "", NULL );
+	gen->shadowDepth = 0;
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void CompositeVCSuite_Setup( CompositeVCSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void CompositeVCSuite_Teardown( CompositeVCSuiteData* data ) {
+}
+
+/* Prototype because I can not find the prototype in any headers. */
+Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
+
+void CompositeVCSuite_TestCompositeVC( CompositeVCSuiteData* data ) {
+	Stream*								stream;
+	Dictionary*							dictionary;
+	XML_IO_Handler*					io_handler;
+	unsigned								nDims = 3;
+	unsigned								meshSize[3] = {3, 3, 3};
+        int								procToWatch;
+	double								minCrds[3] = {0.0, 0.0, 0.0};
+	double								maxCrds[3] = {1.0, 1.0, 1.0};
+	Mesh*									mesh;
+	Variable*							var[7];
+	Variable_Register*				variable_Register;
+	WallVC*								vc;
+	CompositeVC*						cvc;
+	ConditionFunction*				quadCF;
+	ConditionFunction*				expCF;
+	ConditionFunction_Register*	conFunc_Register;
+	ExtensionManager_Register*		extensionMgr_Register;
+   double*								array[7];
+   Name									vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right", "WallVC_Top", "WallVC_Bottom"};
+   Name									vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName", "WallVC_TopName", "WallVC_BottomName"};
+   Name									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
+	char									input_file[PCU_PATH_MAX];
+	char									expected_file[PCU_PATH_MAX];
+   unsigned								nDomains;
+   Index									i, j, k;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   io_handler = XML_IO_Handler_New();
+
+ 	stream = Journal_Register( Info_Type, (Name)"CompositeVCStream"  );
+   Stream_RedirectFile( stream, "testCompositeVC.dat" );
+
+   dictionary = Dictionary_New();
+   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
+
+	/* Input file */
+	pcu_filename_input( "wallVC.xml", input_file );
+   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
+   fflush(stdout);
+
+   extensionMgr_Register = ExtensionManager_Register_New(); 
+
+ 	/* Create a mesh. */
+   mesh = (Mesh*) CompositeVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
+
+   /* Create CF stuff */
+	quadCF = ConditionFunction_New( CompositeVCSuite_quadratic, (Name)"quadratic" );
+	expCF = ConditionFunction_New( CompositeVCSuite_exponential, (Name)"exponential");
+	conFunc_Register = ConditionFunction_Register_New( );
+	ConditionFunction_Register_Add(conFunc_Register, quadCF);
+	ConditionFunction_Register_Add(conFunc_Register, expCF);
+
+	/* Create variable register */
+   variable_Register = Variable_Register_New();
+
+	/* Create variables */
+   for (i = 0; i < 6; i++) {
+      array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
+      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
+      Variable_Register_Add(variable_Register, var[i]);
+   }
+   array[6] = Memory_Alloc_Array( double, nDomains*5, "array[6]" );
+   var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
+   Variable_Register_Add(variable_Register, var[6]);
+   Variable_Register_BuildAll(variable_Register);
+
+   /* Create CompositeVC */
+   cvc = CompositeVC_New( "CompositeVC", NULL, variable_Register, conFunc_Register, dictionary, mesh );
+
+	for (i = 0; i < 6; i++) {
+		vc = WallVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
+		Stg_Component_Build( vc, 0, False );
+		CompositeVC_Add(cvc, vc, True);
+	}
+
+	Stg_Component_Build( cvc, 0, False );
+
+	for (j = 0; j < 6; j++)
+      memset(array[j], 0, sizeof(double)*nDomains);
+	memset(array[6], 0, sizeof(double)*nDomains*5);
+	VariableCondition_Apply(cvc, NULL);
+
+	if (data->rank == procToWatch) {
+      for (j = 0; j < 6; j++) {
+			Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0]);
+			for (k = 1; k < nDomains; k++)
+				Journal_Printf( stream, ", %.2lf", array[j][k]);
+		} Journal_Printf( stream, "\nvar[7]: %.2lf", array[6][0]);
+
+		for (j = 1; j < nDomains*5; j++)
+			Journal_Printf( stream, ", %.2lf", array[6][j]);
+		Journal_Printf( stream, "\n\n");
+
+		for (j = 0; j < 7; j++) {
+			for (k = 0; k < nDomains; k++)
+				Journal_Printf( stream, "%s ", VariableCondition_IsCondition(cvc, k, j) ? "True " : "False");
+			Journal_Printf( stream, "\n");
+		} Journal_Printf( stream, "\n");
+
+		for (j = 0; j < 7; j++) {
+			for (k = 0; k < nDomains; k++) {
+				VariableCondition_ValueIndex  valIndex;
+
+				valIndex = VariableCondition_GetValueIndex(cvc, k, j);
+				if (valIndex != (unsigned)-1)
+					Journal_Printf( stream, "%03u ", valIndex);
+				else
+					Journal_Printf( stream, "XXX ");
+			} Journal_Printf( stream, "\n");
+		} Journal_Printf( stream, "\n");
+
+		pcu_filename_expected( "testCompositeVC.expected", expected_file );
+		pcu_check_fileEq( "testCompositeVC.dat", expected_file );
+		remove( "testCompositeVC.dat" );
+   }
+
+	_Stg_Component_Delete(cvc);
+	Stg_Class_Delete(variable_Register);
+	for (i = 0; i < 7; i++) {
+		_Stg_Component_Delete(var[i]);
+		if (array[i]) Memory_Free(array[i]);
+	}
+	Stg_Class_Delete(extensionMgr_Register);
+	Stg_Class_Delete(io_handler);
+	Stg_Class_Delete(conFunc_Register);
+	Stg_Class_Delete(quadCF);
+	Stg_Class_Delete(expCF);
+	Stg_Class_Delete(dictionary);
+	FreeObject( mesh );
+}
+
+void CompositeVCSuite_TestCompositeVCDictionary( CompositeVCSuiteData* data ) {
+	Stream*								stream;
+	Dictionary*							dictionary;
+	XML_IO_Handler*					io_handler;
+	unsigned								nDims = 3;
+	unsigned								meshSize[3] = {2, 2, 2};
+	int								procToWatch;
+	double								minCrds[3] = {0.0, 0.0, 0.0};
+	double								maxCrds[3] = {1.0, 1.0, 1.0};
+	Mesh*									mesh;
+	Variable*							var[7];
+	Variable_Register*				variable_Register;
+	CompositeVC*						cvc;
+	ConditionFunction*				quadCF;
+	ConditionFunction*				expCF;
+	ConditionFunction_Register*	conFunc_Register;
+	ExtensionManager_Register*		extensionMgr_Register;
+	double*								array[7];
+	Name									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
+	char									input_file[PCU_PATH_MAX];
+	char									expected_file[PCU_PATH_MAX];
+	unsigned								nDomains;
+	Index									i, j, k;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   io_handler = XML_IO_Handler_New();
+
+ 	stream = Journal_Register( Info_Type, (Name)"CompositeVCDictionaryStream"  );
+   Stream_RedirectFile( stream, "testCompositeVCDictionary.dat" );
+
+   dictionary = Dictionary_New();
+   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
+	
+	/* Input file */
+	pcu_filename_input( "compositeVC.xml", input_file );
+   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
+   fflush(stdout);
+
+	extensionMgr_Register = ExtensionManager_Register_New();
+
+	/* Create a mesh. */
+	mesh = (Mesh*) CompositeVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+	nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
+
+	/* Create CF stuff */
+	quadCF = ConditionFunction_New( CompositeVCSuite_quadratic, (Name)"quadratic" );
+	expCF = ConditionFunction_New( CompositeVCSuite_exponential, (Name)"exponential");
+	conFunc_Register = ConditionFunction_Register_New( );
+	ConditionFunction_Register_Add(conFunc_Register, quadCF);
+	ConditionFunction_Register_Add(conFunc_Register, expCF);
+
+	/* Create variable register */
+	variable_Register = Variable_Register_New();
+
+	/* Create variables */
+	for (i = 0; i < 6; i++) {
+		array[i] = Memory_Alloc_Array( double, 3*3*3, "array[i]" );
+		var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
+ 		Variable_Register_Add(variable_Register, var[i]);
+	}
+	array[6] = Memory_Alloc_Array( double, 3*3*3*5, "array[6]" );
+	var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
+	Variable_Register_Add(variable_Register, var[6]);
+	Variable_Register_BuildAll(variable_Register);
+
+	/* Create CompositeVC */
+	cvc = CompositeVC_New( "CompositeVC", NULL, variable_Register, conFunc_Register, dictionary, mesh );
+	Stg_Component_Build( cvc, 0, False );
+
+	for (j = 0; j < 6; j++)
+		memset(array[j], 0, sizeof(double)*3*3*3);
+	memset(array[6], 0, sizeof(double)*3*3*3*5);
+	VariableCondition_Apply(cvc, NULL);
+
+	if (data->rank == procToWatch) {
+		for (j = 0; j < 6; j++) {
+			Journal_Printf( stream, "\nvar[%u]: %.2lf", j, array[j][0] );
+			for (k = 1; k < 3*3*3; k++)
+				Journal_Printf( stream, ", %.2lf", array[j][k] );
+		}
+
+		Journal_Printf( stream, "\nvar[7]: %.2lf", array[6][0] );
+		for (j = 1; j < 3*3*3*5; j++)
+			Journal_Printf( stream, ", %.2lf", array[6][j] );
+		Journal_Printf( stream, "\n\n" );
+
+		for (j = 0; j < 7; j++) {
+			for (k = 0; k < 27; k++)
+				Journal_Printf( stream, "%s ", VariableCondition_IsCondition(cvc, k, j) ? "True " : "False" );
+			Journal_Printf( stream, "\n" );
+		} Journal_Printf( stream, "\n" );
+
+		for (j = 0; j < 7; j++) {
+			for (k = 0; k < 27; k++) {
+				VariableCondition_ValueIndex  valIndex;
+            valIndex = VariableCondition_GetValueIndex(cvc, k, j);
+				if (valIndex != (unsigned)-1)
+					Journal_Printf( stream, "%03u ", valIndex );
+				else
+               Journal_Printf( stream, "XXX " );
+			} Journal_Printf( stream, "\n" );
+		} Journal_Printf( stream, "\n" );
+
+		pcu_filename_expected( "testCompositeVC-dictionary.expected", expected_file );
+		pcu_check_fileEq( "testCompositeVCDictionary.dat", expected_file );
+		remove( "testCompositeVCDictionary.dat" );
+	}
+
+	_Stg_Component_Delete(cvc);
+	Stg_Class_Delete(variable_Register);
+	for (i = 0; i < 7; i++) {
+		_Stg_Component_Delete(var[i]);
+ 		if (array[i]) Memory_Free(array[i]);
+ 	}
+	Stg_Class_Delete(conFunc_Register);
+	Stg_Class_Delete(quadCF);
+	Stg_Class_Delete(expCF);
+	Stg_Class_Delete(dictionary);
+	FreeObject( mesh );
+}
+
+void CompositeVCSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, CompositeVCSuiteData );
+   pcu_suite_setFixtures( suite, CompositeVCSuite_Setup, CompositeVCSuite_Teardown );
+   pcu_suite_addTest( suite, CompositeVCSuite_TestCompositeVC );
+   pcu_suite_addTest( suite, CompositeVCSuite_TestCompositeVCDictionary );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/CornerVCSuite.c
--- a/Utils/tests/CornerVCSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,226 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the CornerVCSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "CornerVCSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} CornerVCSuiteData;
-
-void CornerVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
-	*(double *)result = 20.0;
-}
-
-void CornerVCSuite_exponential(Index index, Variable_Index var_I, void* context, void* result) {
-	*(double *)result = 30.0;
-}
-
-
-Mesh* CornerVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-
-	gen = CartesianGenerator_New( "", NULL );
-	gen->shadowDepth = 0;
-	CartesianGenerator_SetDimSize( gen, nDims ); 
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-void CornerVCSuite_Setup( CornerVCSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void CornerVCSuite_Teardown( CornerVCSuiteData* data ) {
-}
-/* Prototype because I can not find the prototype in any headers. */
-Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
-
-void CornerVCSuite_TestCornerVC( CornerVCSuiteData* data ) {
-	unsigned								nDomains;
-	unsigned								nDims = 3;
-	unsigned								meshSize[3] = {3, 3, 3};
-	int									procToWatch;
-	double								minCrds[3] = {0.0, 0.0, 0.0};
-	double								maxCrds[3] = {1.0, 1.0, 1.0};
-	double*								array[7];
-	char*									vcKey[] = { "CornerVC_BottomLeftFront", "CornerVC_BottomRightFront",
-															"CornerVC_TopLeftFront", "CornerVC_TopRightFront",
-															"CornerVC_BottomLeftBack", "CornerVC_BottomRightBack",
-															"CornerVC_TopLeftBack", "CornerVC_TopRightBack" };
-	char*									vcKeyName[] = { "CornerVC_BottomLeftFrontName", "CornerVC_BottomRightFrontName",
-															"CornerVC_TopLeftFrontName", "CornerVC_TopRightFrontName",
-															"CornerVC_BottomLeftBackName", "CornerVC_BottomRightBackName",
-															"CornerVC_TopLeftBackName", "CornerVC_TopRightBackName" };
-	char*									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
-	char									input_file[PCU_PATH_MAX];
-	char									expected_file[PCU_PATH_MAX];
-	Mesh*									mesh;
-	Variable_Register*				variable_Register;
-	ConditionFunction_Register*	conFunc_Register;
-	ExtensionManager_Register*		extensionMgr_Register;
-	Dictionary*							dictionary;
-	Stream*								stream;
-	XML_IO_Handler*					io_handler;
-	Variable*							var[9];
-	VariableCondition*				vc; 
-	Index									i;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   io_handler = XML_IO_Handler_New();
-
- 	stream = Journal_Register( Info_Type, (Name)"CornerVCStream"  );
-   Stream_RedirectFile( stream, "testCornerVC.dat" );
-
-   dictionary = Dictionary_New();
-   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
-
-	/* Input file */
-	pcu_filename_input( "cornerVC.xml", input_file );
-   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
-   fflush(stdout);
-
-   extensionMgr_Register = ExtensionManager_Register_New(); 
-
- 	/* Create a mesh. */
-   mesh = (Mesh*) CornerVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
-
-   /* Create CF stuff */
-   conFunc_Register = ConditionFunction_Register_New();
-
-	/* Create variable register */
-   variable_Register = Variable_Register_New();
-
-	/* Create variables */
-	for (i = 0; i < 7; i++) {
-		array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
-      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
-		Variable_Register_Add(variable_Register, var[i]);
-	}
-
-	Variable_Register_BuildAll(variable_Register);
-   /* Create CornerVC */
-	for (i = 0; i < 8; i++) {
- 		Index j, k;
-
-		vc = (VariableCondition*) CornerVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
-		//_CornerVC_ReadDictionary(vc, dictionary); //already done in build
-		Stg_Component_Build( vc, 0, False );
-		for (j = 0; j < 7; j++) { 
-			memset(array[j], 0, sizeof(double)* nDomains );
-		}
-		VariableCondition_Apply(vc, NULL);
-
-		if (data->rank == procToWatch) {
-			Journal_Printf( stream, "Testing for %s\n", vcKey[i] );
-			for (j = 0; j < 7; j++) {
-				Journal_Printf( stream,"\nvar[%u]: %.2lf", j, array[j][0]);
-				for (k = 1; k < nDomains; k++)
-					Journal_Printf( stream,", %.2lf", array[j][k]);
-			} Journal_Printf( stream,"\n\n");
-
-			for (j = 0; j < 6; j++) {
-				for (k = 0; k < nDomains; k++)
-					Journal_Printf( stream,"%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
-				Journal_Printf( stream,"\n");
-         } Journal_Printf( stream,"\n");
-
-			for (j = 0; j < 6; j++) {
-				for (k = 0; k < nDomains; k++) {
-					VariableCondition_ValueIndex  valIndex;
-					valIndex = VariableCondition_GetValueIndex(vc, k, j);
-					if (valIndex != (unsigned)-1)
-						Journal_Printf( stream,"%03u ", valIndex);
-					else
-						Journal_Printf( stream,"XXX ");
-				} Journal_Printf( stream,"\n");
-			} Journal_Printf( stream,"\n");
-	
-      }
-	   _Stg_Component_Delete(vc);
-	}
-	if (data->rank == procToWatch) {
-		pcu_filename_expected( "testCornerVC.expected", expected_file );
-		pcu_check_fileEq( "testCornerVC.dat", expected_file );
-		remove( "testCornerVC.dat" );
-	}
-
-	Stg_Class_Delete(variable_Register);
-	for (i = 0; i < 7; i++) {
-		Stg_Class_Delete(var[i]);
-		if (array[i]) Memory_Free(array[i]);
-	}
-	Stg_Class_Delete(extensionMgr_Register);
-	Stg_Class_Delete(io_handler);
-	Stg_Class_Delete(conFunc_Register);
-	Stg_Class_Delete(dictionary);
-
-	FreeObject( mesh );
-}
-
-void CornerVCSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, CornerVCSuiteData );
-   pcu_suite_setFixtures( suite, CornerVCSuite_Setup, CornerVCSuite_Teardown );
-   pcu_suite_addTest( suite, CornerVCSuite_TestCornerVC );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/CornerVCSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/CornerVCSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,226 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the CornerVCSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "CornerVCSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} CornerVCSuiteData;
+
+void CornerVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
+	*(double *)result = 20.0;
+}
+
+void CornerVCSuite_exponential(Index index, Variable_Index var_I, void* context, void* result) {
+	*(double *)result = 30.0;
+}
+
+
+Mesh* CornerVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+
+	gen = CartesianGenerator_New( "", NULL );
+	gen->shadowDepth = 0;
+	CartesianGenerator_SetDimSize( gen, nDims ); 
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, NULL );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+void CornerVCSuite_Setup( CornerVCSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void CornerVCSuite_Teardown( CornerVCSuiteData* data ) {
+}
+/* Prototype because I can not find the prototype in any headers. */
+Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
+
+void CornerVCSuite_TestCornerVC( CornerVCSuiteData* data ) {
+	unsigned								nDomains;
+	unsigned								nDims = 3;
+	unsigned								meshSize[3] = {3, 3, 3};
+	int									procToWatch;
+	double								minCrds[3] = {0.0, 0.0, 0.0};
+	double								maxCrds[3] = {1.0, 1.0, 1.0};
+	double*								array[7];
+	char*									vcKey[] = { "CornerVC_BottomLeftFront", "CornerVC_BottomRightFront",
+															"CornerVC_TopLeftFront", "CornerVC_TopRightFront",
+															"CornerVC_BottomLeftBack", "CornerVC_BottomRightBack",
+															"CornerVC_TopLeftBack", "CornerVC_TopRightBack" };
+	char*									vcKeyName[] = { "CornerVC_BottomLeftFrontName", "CornerVC_BottomRightFrontName",
+															"CornerVC_TopLeftFrontName", "CornerVC_TopRightFrontName",
+															"CornerVC_BottomLeftBackName", "CornerVC_BottomRightBackName",
+															"CornerVC_TopLeftBackName", "CornerVC_TopRightBackName" };
+	char*									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
+	char									input_file[PCU_PATH_MAX];
+	char									expected_file[PCU_PATH_MAX];
+	Mesh*									mesh;
+	Variable_Register*				variable_Register;
+	ConditionFunction_Register*	conFunc_Register;
+	ExtensionManager_Register*		extensionMgr_Register;
+	Dictionary*							dictionary;
+	Stream*								stream;
+	XML_IO_Handler*					io_handler;
+	Variable*							var[9];
+	VariableCondition*				vc; 
+	Index									i;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   io_handler = XML_IO_Handler_New();
+
+ 	stream = Journal_Register( Info_Type, (Name)"CornerVCStream"  );
+   Stream_RedirectFile( stream, "testCornerVC.dat" );
+
+   dictionary = Dictionary_New();
+   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
+
+	/* Input file */
+	pcu_filename_input( "cornerVC.xml", input_file );
+   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
+   fflush(stdout);
+
+   extensionMgr_Register = ExtensionManager_Register_New(); 
+
+ 	/* Create a mesh. */
+   mesh = (Mesh*) CornerVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
+
+   /* Create CF stuff */
+   conFunc_Register = ConditionFunction_Register_New();
+
+	/* Create variable register */
+   variable_Register = Variable_Register_New();
+
+	/* Create variables */
+	for (i = 0; i < 7; i++) {
+		array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
+      var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
+		Variable_Register_Add(variable_Register, var[i]);
+	}
+
+	Variable_Register_BuildAll(variable_Register);
+   /* Create CornerVC */
+	for (i = 0; i < 8; i++) {
+ 		Index j, k;
+
+		vc = (VariableCondition*) CornerVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
+		//_CornerVC_ReadDictionary(vc, dictionary); //already done in build
+		Stg_Component_Build( vc, 0, False );
+		for (j = 0; j < 7; j++) { 
+			memset(array[j], 0, sizeof(double)* nDomains );
+		}
+		VariableCondition_Apply(vc, NULL);
+
+		if (data->rank == procToWatch) {
+			Journal_Printf( stream, "Testing for %s\n", vcKey[i] );
+			for (j = 0; j < 7; j++) {
+				Journal_Printf( stream,"\nvar[%u]: %.2lf", j, array[j][0]);
+				for (k = 1; k < nDomains; k++)
+					Journal_Printf( stream,", %.2lf", array[j][k]);
+			} Journal_Printf( stream,"\n\n");
+
+			for (j = 0; j < 6; j++) {
+				for (k = 0; k < nDomains; k++)
+					Journal_Printf( stream,"%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
+				Journal_Printf( stream,"\n");
+         } Journal_Printf( stream,"\n");
+
+			for (j = 0; j < 6; j++) {
+				for (k = 0; k < nDomains; k++) {
+					VariableCondition_ValueIndex  valIndex;
+					valIndex = VariableCondition_GetValueIndex(vc, k, j);
+					if (valIndex != (unsigned)-1)
+						Journal_Printf( stream,"%03u ", valIndex);
+					else
+						Journal_Printf( stream,"XXX ");
+				} Journal_Printf( stream,"\n");
+			} Journal_Printf( stream,"\n");
+	
+      }
+	   _Stg_Component_Delete(vc);
+	}
+	if (data->rank == procToWatch) {
+		pcu_filename_expected( "testCornerVC.expected", expected_file );
+		pcu_check_fileEq( "testCornerVC.dat", expected_file );
+		remove( "testCornerVC.dat" );
+	}
+
+	Stg_Class_Delete(variable_Register);
+	for (i = 0; i < 7; i++) {
+		Stg_Class_Delete(var[i]);
+		if (array[i]) Memory_Free(array[i]);
+	}
+	Stg_Class_Delete(extensionMgr_Register);
+	Stg_Class_Delete(io_handler);
+	Stg_Class_Delete(conFunc_Register);
+	Stg_Class_Delete(dictionary);
+
+	FreeObject( mesh );
+}
+
+void CornerVCSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, CornerVCSuiteData );
+   pcu_suite_setFixtures( suite, CornerVCSuite_Setup, CornerVCSuite_Teardown );
+   pcu_suite_addTest( suite, CornerVCSuite_TestCornerVC );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/DofLayoutSuite.c
--- a/Utils/tests/DofLayoutSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,373 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the DofLayoutSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "DofLayoutSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} DofLayoutSuiteData;
-
-void DofLayoutSuite_Setup( DofLayoutSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void DofLayoutSuite_Teardown( DofLayoutSuiteData* data ) {
-}
-
-void DofLayoutSuite_TestBasic( DofLayoutSuiteData* data ) {
-	char		expected_file[PCU_PATH_MAX];
-	int		procToWatch;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"DofLayoutBasic" );	
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch  ) {
-		DofLayout*				dof;
-		DofLayout*				destDof;
-		Variable_Register*	variableRegister;
-		Variable*				var[6];
-		char*						varName[] = {"x", "y", "z", "vx", "vy", "vz"};
-		Index						ii, dof_I, var_I;
-		Index						arraySize = 27;
-		double*					varArrays[6];
-		int						counts[27];
-
-		Stream_RedirectFile( stream, "testBasic.dat" );
-
-		/* Create variable register */
-		variableRegister = Variable_Register_New();
-
-		/* Create variables */
-		for (var_I = 0; var_I < 6; var_I++) {
-			varArrays[var_I] = Memory_Alloc_Array_Unnamed( double, arraySize );
-			var[var_I] = Variable_NewScalar( varName[var_I], NULL, Variable_DataType_Double, (Index*)&arraySize, NULL, (void**)&(varArrays[var_I]), variableRegister  );
-			Stg_Component_Build( var[var_I], 0, False );
-			Stg_Component_Initialise( var[var_I], 0, False );
-		}
-
-		for (ii = 0; ii < arraySize; ii++) {
-			for (var_I = 0; var_I < 6; var_I++) {
-				Variable_SetValueDouble( var[var_I], ii, 0.0 );
-			}
-		}
-
-		/* Simple test */
-		dof = DofLayout_New( "dofLayout", NULL, variableRegister, arraySize, NULL );
-		for (ii = 0; ii < arraySize; ii++)
-			for (var_I = 0; var_I < 6; var_I++)
-				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
-
-		Stg_Component_Build(dof, 0, False);
-
-		Journal_Printf( stream, "Simple test:\n" );
-  		for (ii = 0; ii < arraySize; ii++) {
-			Journal_Printf( stream, "\t%u\n", dof->dofCounts[ii] );
-			pcu_check_true( dof->dofCounts[ii] == 6 );
-		}
-			
-		Stg_Class_Delete(dof);
-
-		/* Advanced test */
-		for (ii = 0; ii < 27; ii++) counts[ii] = 0;
-		dof = DofLayout_New( "dofLayout1", NULL, variableRegister, arraySize, NULL );
-		
-		for (ii = 0; ii < 12; ii++) {
-			for (var_I = 0; var_I < 2; var_I++) {
-				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
-				counts[ii]++;
-			}
-		}
- 
-		for (ii = 9; ii < 20; ii++) {
-			for (var_I = 2; var_I < 6; var_I++) {
-				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
-				counts[ii]++;
-			}
-		}
- 
-		Stg_Component_Build(dof, 0, False);
- 
-		Journal_Printf( stream, "\nAdvanced test:\n" );
-		for (ii = 0; ii < arraySize; ii++) {
-			Journal_Printf( stream, "\t%u\n", dof->dofCounts[ii] );
-			pcu_check_true( counts[ii] == dof->dofCounts[ii] );
-		}
-		Stg_Class_Delete(dof);
-
-		/* Copy test */
- 		dof = DofLayout_New( "dofLayout2", NULL, variableRegister, arraySize, NULL );
-		destDof = DofLayout_New( "dofLayout3", NULL, variableRegister, arraySize, NULL );
-		for (ii = 0; ii < arraySize; ii++) {
-			for (var_I = 0; var_I < 3; var_I++) {
-				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
-			}
-			for (var_I = 3; var_I < 6; var_I++) {
-				DofLayout_AddDof_ByVarName(destDof, varName[var_I], ii);
-			}
-		}
-
-		Stg_Component_Build(dof, NULL, False);
-		Stg_Component_Build(destDof, NULL, False);
-
-		for (ii = 0; ii < arraySize; ii++) {
-			for (dof_I = 0; dof_I < 3; dof_I++) {
-				DofLayout_SetValueDouble( dof, ii, dof_I, ii*10 );
-				DofLayout_SetValueDouble( destDof, ii, dof_I, 0 );
-			}
-		}
-
-		Journal_Printf( stream, "Copy Test: pre copy:\n" );
-		for (ii = 0; ii < arraySize; ii++) {
-			Journal_Printf( stream, "\tIndex %d - src %2g,%2g,%2g - dest %2g, %2g, %2g\n", ii,
-				DofLayout_GetValueDouble( dof, ii, 0 ),
-				DofLayout_GetValueDouble( dof, ii, 1 ),
-				DofLayout_GetValueDouble( dof, ii, 2 ),
-				DofLayout_GetValueDouble( destDof, ii, 0 ),
-				DofLayout_GetValueDouble( destDof, ii, 1 ),
-				DofLayout_GetValueDouble( destDof, ii, 2 ) );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 0 ) == ii * 10 );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 1 ) == ii * 10 );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 2 ) == ii * 10 );
-			pcu_check_true( DofLayout_GetValueDouble( destDof, ii, 0 ) == 0 );
-			pcu_check_true( DofLayout_GetValueDouble( destDof, ii, 1 ) == 0 );
-			pcu_check_true( DofLayout_GetValueDouble( destDof, ii, 2 ) == 0 );
-		}
-
-		DofLayout_CopyValues( dof, destDof );
-
-		Journal_Printf( stream, "Copy Test: post copy:\n" );
-		for (ii = 0; ii < arraySize; ii++) {
-			Journal_Printf( stream, "\tIndex %d - src %2g,%2g,%2g - dest %2g, %2g, %2g\n", ii,
-				DofLayout_GetValueDouble( dof, ii, 0 ),
-				DofLayout_GetValueDouble( dof, ii, 1 ),
-				DofLayout_GetValueDouble( dof, ii, 2 ),
-				DofLayout_GetValueDouble( destDof, ii, 0 ),
-				DofLayout_GetValueDouble( destDof, ii, 1 ),
-				DofLayout_GetValueDouble( destDof, ii, 2 ) );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 0 ) == DofLayout_GetValueDouble( destDof, ii, 0 ) );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 1 ) == DofLayout_GetValueDouble( destDof, ii, 1 ) );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 2 ) == DofLayout_GetValueDouble( destDof, ii, 2 ) );
-		}
-
-		Stg_Class_Delete(destDof);
-
-		Journal_Printf( stream, "Zero Test: all values in src dof should be zero again\n" );
-		DofLayout_SetAllToZero( dof );
-		for (ii = 0; ii < arraySize; ii++) {
-			Journal_Printf( stream,  "\tIndex %d - src %2g,%2g,%2g\n", ii,
-				DofLayout_GetValueDouble( dof, ii, 0 ),
-				DofLayout_GetValueDouble( dof, ii, 1 ),
-				DofLayout_GetValueDouble( dof, ii, 2 ) );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 0 ) == 0 );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 1 ) == 0 );
-			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 2 ) == 0 );
-		}
-
-		Stg_Class_Delete(dof);
-
-		/* Cleanup */
-
-		Stg_Class_Delete(variableRegister);
-
-		for (var_I = 0; var_I < 6; var_I++) {
-			if (var[var_I]) Stg_Class_Delete(var[var_I]);
-				Memory_Free( varArrays[var_I] );
-		}
-		pcu_filename_expected( "testDofLayoutBasicOutput.expected", expected_file );
-		pcu_check_fileEq( "testBasic.dat", expected_file );
-		remove( "testBasic.dat" );
-	}
-}
-
-void DofLayoutSuite_TestRemap( DofLayoutSuiteData* data ) {
-	char		expected_file[PCU_PATH_MAX];
-	int		procToWatch;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"DofLayoutRemap" );	
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch  ) {
-		DofLayout*				dof;
-		double					dummyVar;
-		double*					dummyPtr = &dummyVar;
-		Variable_Register*	variableRegister;
-		Variable*				var[6];
-		char*						varName[] = {"x", "y", "z", "vx", "vy", "vz"};
-		Index						i, j;
-		Index						arraySize = 1;
-		IndexMap*				map;
-
-		Stream_RedirectFile( stream, "testRemap.dat" );
-		
-		/* Create variable register */
-		variableRegister = Variable_Register_New();
-
-		/* Create variables */
-		for (i = 0; i < 6; i++) {
-			var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&arraySize, NULL, (void**)&dummyPtr, 0  );
-			Variable_Register_Add(variableRegister, var[i]);
-		}
-
-		/* Simple test */
-		dof = DofLayout_New( "dofLayout", NULL, variableRegister, 27, NULL );
-		for (i = 0; i < 6; i++) {
-			for (j = 0; j < 27; j++) {
-				DofLayout_AddDof_ByVarName(dof, varName[i], j);
-			}
-		}
-
-		/* Build the IndexMap */
-		map = IndexMap_New();
-		for( i = 0; i < 27; i++ ) {
-			if( i % 2 == 0 ) {
-				IndexMap_Append( map, i, i / 2 );
-			}
-			else {
-				IndexMap_Append( map, i, 27 );
-			}
-		}
-
-		/* Perform remap */
-		DofLayout_Remap( dof, 14, map );
-		Stg_Class_Delete( map );
-		Stg_Component_Build(dof, 0, False);
-
-		Journal_Printf( stream, "Simple test:\n" );
-		for (i = 0; i < 14; i++) {
-			Journal_Printf( stream, "\t%u\n", dof->dofCounts[i] );
-			pcu_check_true( dof->dofCounts[i] == 6 );
-		}
-
-		Stg_Class_Delete(dof);
-		Stg_Class_Delete(variableRegister);
-
-		for (i = 0; i < 6; i++)
-			if (var[i]) Stg_Class_Delete(var[i]);
-		
-		pcu_filename_expected( "testDofLayoutRemapOutput.expected", expected_file );
-		pcu_check_fileEq( "testRemap.dat", expected_file );
-		remove( "testRemap.dat" );
-	}
-}
-
-void DofLayoutSuite_TestSaveAndLoad( DofLayoutSuiteData* data ) {
-	char		expected_file[PCU_PATH_MAX];
-	int		procToWatch;
-	Stream*	stream = Journal_Register( Info_Type, (Name)"DofLayoutRemap" );	
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-	
-	if( data->rank == procToWatch  ) {
-		DofLayout*				dof;
-		Variable_Register*	variableRegister;
-		Variable*				var[6];
-		char*						varName[] = {"x", "y", "z", "vx", "vy", "vz"};
-		Index						ii, var_I;
-		Index						arraySize = 27;
-		double*					varArrays[6];
-	
-		Stream_RedirectFile( stream, "testSaveAndLoad.dat" );
-
-		/* Create variable register */
-		variableRegister = Variable_Register_New();
-
-		/* Create variables */
-		for (var_I = 0; var_I < 6; var_I++) {
-			varArrays[var_I] = Memory_Alloc_Array_Unnamed( double, arraySize );
-			var[var_I] = Variable_NewScalar( varName[var_I], NULL, Variable_DataType_Double, (Index*)&arraySize, NULL, (void**)&(varArrays[var_I]), variableRegister  );
-			Stg_Component_Build( var[var_I], 0, False );
-			Stg_Component_Initialise( var[var_I], 0, False );
-		}
-
-		for (ii = 0; ii < arraySize; ii++) {
-			for (var_I = 0; var_I < 6; var_I++) {
-				Variable_SetValueDouble( var[var_I], ii, (ii*10 + var_I) );
-			}
-		}
-
-		/* Simple test */
-		dof = DofLayout_New( "dofLayout", NULL, variableRegister, arraySize, NULL );
-		for (ii = 0; ii < arraySize; ii++) {
-			for (var_I = 0; var_I < 6; var_I++) {
-				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
-			}
-		}
-		Stg_Component_Build(dof, 0, False);
-
-		DofLayout_SaveAllVariablesToFiles( dof, "testDofSave", data->rank );
-		DofLayout_SetAllToZero( dof );
-		DofLayout_LoadAllVariablesFromFiles( dof, "testDofSave", data->rank );
-
-		for (ii = 0; ii < arraySize; ii++) {
-			Journal_Printf( stream, "\tIndex %d - %2g,%2g,%2g,%2g,%2g,%2g\n", ii,
-				DofLayout_GetValueDouble( dof, ii, 0 ),
-				DofLayout_GetValueDouble( dof, ii, 1 ),
-				DofLayout_GetValueDouble( dof, ii, 2 ),
-				DofLayout_GetValueDouble( dof, ii, 3 ),
-				DofLayout_GetValueDouble( dof, ii, 4 ),
-				DofLayout_GetValueDouble( dof, ii, 5 ) );
-		}
-		Stg_Class_Delete(dof);
-		Stg_Class_Delete(variableRegister);
-
-		pcu_filename_expected( "testDofLayoutSaveAndLoadOutput.expected", expected_file );
-		pcu_check_fileEq( "testSaveAndLoad.dat", expected_file );
-		remove( "testSaveAndLoad.dat" );
-	}
-}
-	
-void DofLayoutSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, DofLayoutSuiteData );
-	pcu_suite_setFixtures( suite, DofLayoutSuite_Setup, DofLayoutSuite_Teardown );
-	pcu_suite_addTest( suite, DofLayoutSuite_TestBasic );
-	pcu_suite_addTest( suite, DofLayoutSuite_TestRemap );
-	pcu_suite_addTest( suite, DofLayoutSuite_TestSaveAndLoad );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/DofLayoutSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/DofLayoutSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,373 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the DofLayoutSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "DofLayoutSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} DofLayoutSuiteData;
+
+void DofLayoutSuite_Setup( DofLayoutSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void DofLayoutSuite_Teardown( DofLayoutSuiteData* data ) {
+}
+
+void DofLayoutSuite_TestBasic( DofLayoutSuiteData* data ) {
+	char		expected_file[PCU_PATH_MAX];
+	int		procToWatch;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"DofLayoutBasic" );	
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch  ) {
+		DofLayout*				dof;
+		DofLayout*				destDof;
+		Variable_Register*	variableRegister;
+		Variable*				var[6];
+		char*						varName[] = {"x", "y", "z", "vx", "vy", "vz"};
+		Index						ii, dof_I, var_I;
+		Index						arraySize = 27;
+		double*					varArrays[6];
+		int						counts[27];
+
+		Stream_RedirectFile( stream, "testBasic.dat" );
+
+		/* Create variable register */
+		variableRegister = Variable_Register_New();
+
+		/* Create variables */
+		for (var_I = 0; var_I < 6; var_I++) {
+			varArrays[var_I] = Memory_Alloc_Array_Unnamed( double, arraySize );
+			var[var_I] = Variable_NewScalar( varName[var_I], NULL, Variable_DataType_Double, (Index*)&arraySize, NULL, (void**)&(varArrays[var_I]), variableRegister  );
+			Stg_Component_Build( var[var_I], 0, False );
+			Stg_Component_Initialise( var[var_I], 0, False );
+		}
+
+		for (ii = 0; ii < arraySize; ii++) {
+			for (var_I = 0; var_I < 6; var_I++) {
+				Variable_SetValueDouble( var[var_I], ii, 0.0 );
+			}
+		}
+
+		/* Simple test */
+		dof = DofLayout_New( "dofLayout", NULL, variableRegister, arraySize, NULL );
+		for (ii = 0; ii < arraySize; ii++)
+			for (var_I = 0; var_I < 6; var_I++)
+				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
+
+		Stg_Component_Build(dof, 0, False);
+
+		Journal_Printf( stream, "Simple test:\n" );
+  		for (ii = 0; ii < arraySize; ii++) {
+			Journal_Printf( stream, "\t%u\n", dof->dofCounts[ii] );
+			pcu_check_true( dof->dofCounts[ii] == 6 );
+		}
+			
+		Stg_Class_Delete(dof);
+
+		/* Advanced test */
+		for (ii = 0; ii < 27; ii++) counts[ii] = 0;
+		dof = DofLayout_New( "dofLayout1", NULL, variableRegister, arraySize, NULL );
+		
+		for (ii = 0; ii < 12; ii++) {
+			for (var_I = 0; var_I < 2; var_I++) {
+				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
+				counts[ii]++;
+			}
+		}
+ 
+		for (ii = 9; ii < 20; ii++) {
+			for (var_I = 2; var_I < 6; var_I++) {
+				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
+				counts[ii]++;
+			}
+		}
+ 
+		Stg_Component_Build(dof, 0, False);
+ 
+		Journal_Printf( stream, "\nAdvanced test:\n" );
+		for (ii = 0; ii < arraySize; ii++) {
+			Journal_Printf( stream, "\t%u\n", dof->dofCounts[ii] );
+			pcu_check_true( counts[ii] == dof->dofCounts[ii] );
+		}
+		Stg_Class_Delete(dof);
+
+		/* Copy test */
+ 		dof = DofLayout_New( "dofLayout2", NULL, variableRegister, arraySize, NULL );
+		destDof = DofLayout_New( "dofLayout3", NULL, variableRegister, arraySize, NULL );
+		for (ii = 0; ii < arraySize; ii++) {
+			for (var_I = 0; var_I < 3; var_I++) {
+				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
+			}
+			for (var_I = 3; var_I < 6; var_I++) {
+				DofLayout_AddDof_ByVarName(destDof, varName[var_I], ii);
+			}
+		}
+
+		Stg_Component_Build(dof, NULL, False);
+		Stg_Component_Build(destDof, NULL, False);
+
+		for (ii = 0; ii < arraySize; ii++) {
+			for (dof_I = 0; dof_I < 3; dof_I++) {
+				DofLayout_SetValueDouble( dof, ii, dof_I, ii*10 );
+				DofLayout_SetValueDouble( destDof, ii, dof_I, 0 );
+			}
+		}
+
+		Journal_Printf( stream, "Copy Test: pre copy:\n" );
+		for (ii = 0; ii < arraySize; ii++) {
+			Journal_Printf( stream, "\tIndex %d - src %2g,%2g,%2g - dest %2g, %2g, %2g\n", ii,
+				DofLayout_GetValueDouble( dof, ii, 0 ),
+				DofLayout_GetValueDouble( dof, ii, 1 ),
+				DofLayout_GetValueDouble( dof, ii, 2 ),
+				DofLayout_GetValueDouble( destDof, ii, 0 ),
+				DofLayout_GetValueDouble( destDof, ii, 1 ),
+				DofLayout_GetValueDouble( destDof, ii, 2 ) );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 0 ) == ii * 10 );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 1 ) == ii * 10 );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 2 ) == ii * 10 );
+			pcu_check_true( DofLayout_GetValueDouble( destDof, ii, 0 ) == 0 );
+			pcu_check_true( DofLayout_GetValueDouble( destDof, ii, 1 ) == 0 );
+			pcu_check_true( DofLayout_GetValueDouble( destDof, ii, 2 ) == 0 );
+		}
+
+		DofLayout_CopyValues( dof, destDof );
+
+		Journal_Printf( stream, "Copy Test: post copy:\n" );
+		for (ii = 0; ii < arraySize; ii++) {
+			Journal_Printf( stream, "\tIndex %d - src %2g,%2g,%2g - dest %2g, %2g, %2g\n", ii,
+				DofLayout_GetValueDouble( dof, ii, 0 ),
+				DofLayout_GetValueDouble( dof, ii, 1 ),
+				DofLayout_GetValueDouble( dof, ii, 2 ),
+				DofLayout_GetValueDouble( destDof, ii, 0 ),
+				DofLayout_GetValueDouble( destDof, ii, 1 ),
+				DofLayout_GetValueDouble( destDof, ii, 2 ) );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 0 ) == DofLayout_GetValueDouble( destDof, ii, 0 ) );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 1 ) == DofLayout_GetValueDouble( destDof, ii, 1 ) );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 2 ) == DofLayout_GetValueDouble( destDof, ii, 2 ) );
+		}
+
+		Stg_Class_Delete(destDof);
+
+		Journal_Printf( stream, "Zero Test: all values in src dof should be zero again\n" );
+		DofLayout_SetAllToZero( dof );
+		for (ii = 0; ii < arraySize; ii++) {
+			Journal_Printf( stream,  "\tIndex %d - src %2g,%2g,%2g\n", ii,
+				DofLayout_GetValueDouble( dof, ii, 0 ),
+				DofLayout_GetValueDouble( dof, ii, 1 ),
+				DofLayout_GetValueDouble( dof, ii, 2 ) );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 0 ) == 0 );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 1 ) == 0 );
+			pcu_check_true( DofLayout_GetValueDouble( dof, ii, 2 ) == 0 );
+		}
+
+		Stg_Class_Delete(dof);
+
+		/* Cleanup */
+
+		Stg_Class_Delete(variableRegister);
+
+		for (var_I = 0; var_I < 6; var_I++) {
+			if (var[var_I]) Stg_Class_Delete(var[var_I]);
+				Memory_Free( varArrays[var_I] );
+		}
+		pcu_filename_expected( "testDofLayoutBasicOutput.expected", expected_file );
+		pcu_check_fileEq( "testBasic.dat", expected_file );
+		remove( "testBasic.dat" );
+	}
+}
+
+void DofLayoutSuite_TestRemap( DofLayoutSuiteData* data ) {
+	char		expected_file[PCU_PATH_MAX];
+	int		procToWatch;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"DofLayoutRemap" );	
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch  ) {
+		DofLayout*				dof;
+		double					dummyVar;
+		double*					dummyPtr = &dummyVar;
+		Variable_Register*	variableRegister;
+		Variable*				var[6];
+		char*						varName[] = {"x", "y", "z", "vx", "vy", "vz"};
+		Index						i, j;
+		Index						arraySize = 1;
+		IndexMap*				map;
+
+		Stream_RedirectFile( stream, "testRemap.dat" );
+		
+		/* Create variable register */
+		variableRegister = Variable_Register_New();
+
+		/* Create variables */
+		for (i = 0; i < 6; i++) {
+			var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&arraySize, NULL, (void**)&dummyPtr, 0  );
+			Variable_Register_Add(variableRegister, var[i]);
+		}
+
+		/* Simple test */
+		dof = DofLayout_New( "dofLayout", NULL, variableRegister, 27, NULL );
+		for (i = 0; i < 6; i++) {
+			for (j = 0; j < 27; j++) {
+				DofLayout_AddDof_ByVarName(dof, varName[i], j);
+			}
+		}
+
+		/* Build the IndexMap */
+		map = IndexMap_New();
+		for( i = 0; i < 27; i++ ) {
+			if( i % 2 == 0 ) {
+				IndexMap_Append( map, i, i / 2 );
+			}
+			else {
+				IndexMap_Append( map, i, 27 );
+			}
+		}
+
+		/* Perform remap */
+		DofLayout_Remap( dof, 14, map );
+		Stg_Class_Delete( map );
+		Stg_Component_Build(dof, 0, False);
+
+		Journal_Printf( stream, "Simple test:\n" );
+		for (i = 0; i < 14; i++) {
+			Journal_Printf( stream, "\t%u\n", dof->dofCounts[i] );
+			pcu_check_true( dof->dofCounts[i] == 6 );
+		}
+
+		Stg_Class_Delete(dof);
+		Stg_Class_Delete(variableRegister);
+
+		for (i = 0; i < 6; i++)
+			if (var[i]) Stg_Class_Delete(var[i]);
+		
+		pcu_filename_expected( "testDofLayoutRemapOutput.expected", expected_file );
+		pcu_check_fileEq( "testRemap.dat", expected_file );
+		remove( "testRemap.dat" );
+	}
+}
+
+void DofLayoutSuite_TestSaveAndLoad( DofLayoutSuiteData* data ) {
+	char		expected_file[PCU_PATH_MAX];
+	int		procToWatch;
+	Stream*	stream = Journal_Register( Info_Type, (Name)"DofLayoutRemap" );	
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+	
+	if( data->rank == procToWatch  ) {
+		DofLayout*				dof;
+		Variable_Register*	variableRegister;
+		Variable*				var[6];
+		char*						varName[] = {"x", "y", "z", "vx", "vy", "vz"};
+		Index						ii, var_I;
+		Index						arraySize = 27;
+		double*					varArrays[6];
+	
+		Stream_RedirectFile( stream, "testSaveAndLoad.dat" );
+
+		/* Create variable register */
+		variableRegister = Variable_Register_New();
+
+		/* Create variables */
+		for (var_I = 0; var_I < 6; var_I++) {
+			varArrays[var_I] = Memory_Alloc_Array_Unnamed( double, arraySize );
+			var[var_I] = Variable_NewScalar( varName[var_I], NULL, Variable_DataType_Double, (Index*)&arraySize, NULL, (void**)&(varArrays[var_I]), variableRegister  );
+			Stg_Component_Build( var[var_I], 0, False );
+			Stg_Component_Initialise( var[var_I], 0, False );
+		}
+
+		for (ii = 0; ii < arraySize; ii++) {
+			for (var_I = 0; var_I < 6; var_I++) {
+				Variable_SetValueDouble( var[var_I], ii, (ii*10 + var_I) );
+			}
+		}
+
+		/* Simple test */
+		dof = DofLayout_New( "dofLayout", NULL, variableRegister, arraySize, NULL );
+		for (ii = 0; ii < arraySize; ii++) {
+			for (var_I = 0; var_I < 6; var_I++) {
+				DofLayout_AddDof_ByVarName(dof, varName[var_I], ii);
+			}
+		}
+		Stg_Component_Build(dof, 0, False);
+
+		DofLayout_SaveAllVariablesToFiles( dof, "testDofSave", data->rank );
+		DofLayout_SetAllToZero( dof );
+		DofLayout_LoadAllVariablesFromFiles( dof, "testDofSave", data->rank );
+
+		for (ii = 0; ii < arraySize; ii++) {
+			Journal_Printf( stream, "\tIndex %d - %2g,%2g,%2g,%2g,%2g,%2g\n", ii,
+				DofLayout_GetValueDouble( dof, ii, 0 ),
+				DofLayout_GetValueDouble( dof, ii, 1 ),
+				DofLayout_GetValueDouble( dof, ii, 2 ),
+				DofLayout_GetValueDouble( dof, ii, 3 ),
+				DofLayout_GetValueDouble( dof, ii, 4 ),
+				DofLayout_GetValueDouble( dof, ii, 5 ) );
+		}
+		Stg_Class_Delete(dof);
+		Stg_Class_Delete(variableRegister);
+
+		pcu_filename_expected( "testDofLayoutSaveAndLoadOutput.expected", expected_file );
+		pcu_check_fileEq( "testSaveAndLoad.dat", expected_file );
+		remove( "testSaveAndLoad.dat" );
+	}
+}
+	
+void DofLayoutSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, DofLayoutSuiteData );
+	pcu_suite_setFixtures( suite, DofLayoutSuite_Setup, DofLayoutSuite_Teardown );
+	pcu_suite_addTest( suite, DofLayoutSuite_TestBasic );
+	pcu_suite_addTest( suite, DofLayoutSuite_TestRemap );
+	pcu_suite_addTest( suite, DofLayoutSuite_TestSaveAndLoad );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/FieldVariableRegisterSuite.c
--- a/Utils/tests/FieldVariableRegisterSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the FieldVariableRegisterSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "FieldVariableRegisterSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} FieldVariableRegisterSuiteData;
-
-InterpolationResult FieldVariableRegisterSuite_dummyInterpolateValueAt( void* sdVariable, Coord coord, double* value ) { return OUTSIDE_GLOBAL; }
-void FieldVariableRegisterSuite_dummyWithinElement( void* sdVariable, Element_DomainIndex dEl_I, Coord coord, double* value ) { return ; }
-double FieldVariableRegisterSuite_dummyGetMinGlobalValue( void* sdVariable ) { return 0; }
-double FieldVariableRegisterSuite_dummyGetMaxGlobalValue( void* sdVariable ) { return 1; }
-void FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords( void* sdVariable, Coord min, Coord max ) { return ; }
-void FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords( void* sdVariable, Coord min, Coord max ) { return ; }
-
-void FieldVariableRegisterSuite_Setup( FieldVariableRegisterSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void FieldVariableRegisterSuite_Teardown( FieldVariableRegisterSuiteData* data ) {
-} 
-
-void FieldVariableRegisterSuite_TestGetByIndex( FieldVariableRegisterSuiteData* data ) {
-   int                     procToWatch;
-   FieldVariable_Register* fV_Register;
-   FieldVariable*          testFVs[] = { NULL, NULL, NULL };
-   Name                    fvNames[] = { "testFV1", "testFV2", "testFV3" };
-   Index                   ii;
-   Index                   fV_Index;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   if( data->rank == procToWatch ) {
-      fV_Register = FieldVariable_Register_New();
-
-      for( ii=0; ii < 3; ii++ ) {
-			testFVs[ii] = FieldVariable_New(
-				fvNames[ii],
-				NULL,
-				0,
-				3,
-				False,
-				data->comm,
-				fV_Register );
-			testFVs[ii]->_interpolateValueAt = FieldVariableRegisterSuite_dummyInterpolateValueAt;
-			testFVs[ii]->_getMinGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMinGlobalValue;
-			testFVs[ii]->_getMaxGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMaxGlobalValue;
-			testFVs[ii]->_getMinAndMaxLocalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords;
-			testFVs[ii]->_getMinAndMaxGlobalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords;
-
-      }
-      for( ii=0; ii < 3; ii++ ) {
-         fV_Index = FieldVariable_Register_GetIndex( fV_Register, fvNames[ii] );
-         pcu_check_true( fV_Index == ii );
-         pcu_check_streq( (FieldVariable_Register_GetByIndex( fV_Register, fV_Index ) )->name, fvNames[ii] );
-      }
-      Stg_Class_Delete(fV_Register);
-   }
-}
-
-void FieldVariableRegisterSuite_TestGetByName( FieldVariableRegisterSuiteData* data ) {
-   int                     procToWatch;
-   FieldVariable_Register* fV_Register;
-   FieldVariable*          testFVs[] = { NULL, NULL, NULL };
-   Name                    fvNames[] = { "testFV1", "testFV2", "testFV3" };
-   Index                   ii;
-   Index                   fV_Index;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   if( data->rank == procToWatch ) {
-      fV_Register = FieldVariable_Register_New();
-
-      for( ii=0; ii < 3; ii++ ) {
-			testFVs[ii] = FieldVariable_New(
-				fvNames[ii],
-				NULL,
-				0,
-				3,
-				False,
-				data->comm,
-				fV_Register );
-			testFVs[ii]->_interpolateValueAt = FieldVariableRegisterSuite_dummyInterpolateValueAt;
-			testFVs[ii]->_getMinGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMinGlobalValue;
-			testFVs[ii]->_getMaxGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMaxGlobalValue;
-			testFVs[ii]->_getMinAndMaxLocalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords;
-			testFVs[ii]->_getMinAndMaxGlobalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords;
-      }
-      for( ii=0; ii < 3; ii++ ) {
-         fV_Index = FieldVariable_Register_GetIndex( fV_Register, fvNames[ii] );
-         pcu_check_true( fV_Index == ii );
-         pcu_check_streq( (FieldVariable_Register_GetByName( fV_Register, fvNames[ii] ) )->name, fvNames[ii] );
-      }
-      Stg_Class_Delete(fV_Register);
-   }
-}
-
-void FieldVariableRegisterSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, FieldVariableRegisterSuiteData );
-	pcu_suite_setFixtures( suite, FieldVariableRegisterSuite_Setup, FieldVariableRegisterSuite_Teardown );
-	pcu_suite_addTest( suite, FieldVariableRegisterSuite_TestGetByIndex );
-	pcu_suite_addTest( suite, FieldVariableRegisterSuite_TestGetByName );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/FieldVariableRegisterSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/FieldVariableRegisterSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,152 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the FieldVariableRegisterSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "FieldVariableRegisterSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} FieldVariableRegisterSuiteData;
+
+InterpolationResult FieldVariableRegisterSuite_dummyInterpolateValueAt( void* sdVariable, Coord coord, double* value ) { return OUTSIDE_GLOBAL; }
+void FieldVariableRegisterSuite_dummyWithinElement( void* sdVariable, Element_DomainIndex dEl_I, Coord coord, double* value ) { return ; }
+double FieldVariableRegisterSuite_dummyGetMinGlobalValue( void* sdVariable ) { return 0; }
+double FieldVariableRegisterSuite_dummyGetMaxGlobalValue( void* sdVariable ) { return 1; }
+void FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords( void* sdVariable, Coord min, Coord max ) { return ; }
+void FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords( void* sdVariable, Coord min, Coord max ) { return ; }
+
+void FieldVariableRegisterSuite_Setup( FieldVariableRegisterSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void FieldVariableRegisterSuite_Teardown( FieldVariableRegisterSuiteData* data ) {
+} 
+
+void FieldVariableRegisterSuite_TestGetByIndex( FieldVariableRegisterSuiteData* data ) {
+   int                     procToWatch;
+   FieldVariable_Register* fV_Register;
+   FieldVariable*          testFVs[] = { NULL, NULL, NULL };
+   Name                    fvNames[] = { "testFV1", "testFV2", "testFV3" };
+   Index                   ii;
+   Index                   fV_Index;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   if( data->rank == procToWatch ) {
+      fV_Register = FieldVariable_Register_New();
+
+      for( ii=0; ii < 3; ii++ ) {
+			testFVs[ii] = FieldVariable_New(
+				fvNames[ii],
+				NULL,
+				0,
+				3,
+				False,
+				data->comm,
+				fV_Register );
+			testFVs[ii]->_interpolateValueAt = FieldVariableRegisterSuite_dummyInterpolateValueAt;
+			testFVs[ii]->_getMinGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMinGlobalValue;
+			testFVs[ii]->_getMaxGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMaxGlobalValue;
+			testFVs[ii]->_getMinAndMaxLocalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords;
+			testFVs[ii]->_getMinAndMaxGlobalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords;
+
+      }
+      for( ii=0; ii < 3; ii++ ) {
+         fV_Index = FieldVariable_Register_GetIndex( fV_Register, fvNames[ii] );
+         pcu_check_true( fV_Index == ii );
+         pcu_check_streq( (FieldVariable_Register_GetByIndex( fV_Register, fV_Index ) )->name, fvNames[ii] );
+      }
+      Stg_Class_Delete(fV_Register);
+   }
+}
+
+void FieldVariableRegisterSuite_TestGetByName( FieldVariableRegisterSuiteData* data ) {
+   int                     procToWatch;
+   FieldVariable_Register* fV_Register;
+   FieldVariable*          testFVs[] = { NULL, NULL, NULL };
+   Name                    fvNames[] = { "testFV1", "testFV2", "testFV3" };
+   Index                   ii;
+   Index                   fV_Index;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   if( data->rank == procToWatch ) {
+      fV_Register = FieldVariable_Register_New();
+
+      for( ii=0; ii < 3; ii++ ) {
+			testFVs[ii] = FieldVariable_New(
+				fvNames[ii],
+				NULL,
+				0,
+				3,
+				False,
+				data->comm,
+				fV_Register );
+			testFVs[ii]->_interpolateValueAt = FieldVariableRegisterSuite_dummyInterpolateValueAt;
+			testFVs[ii]->_getMinGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMinGlobalValue;
+			testFVs[ii]->_getMaxGlobalFieldMagnitude = FieldVariableRegisterSuite_dummyGetMaxGlobalValue;
+			testFVs[ii]->_getMinAndMaxLocalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxLocalCoords;
+			testFVs[ii]->_getMinAndMaxGlobalCoords = FieldVariableRegisterSuite_dummyGetMinAndMaxGlobalCoords;
+      }
+      for( ii=0; ii < 3; ii++ ) {
+         fV_Index = FieldVariable_Register_GetIndex( fV_Register, fvNames[ii] );
+         pcu_check_true( fV_Index == ii );
+         pcu_check_streq( (FieldVariable_Register_GetByName( fV_Register, fvNames[ii] ) )->name, fvNames[ii] );
+      }
+      Stg_Class_Delete(fV_Register);
+   }
+}
+
+void FieldVariableRegisterSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, FieldVariableRegisterSuiteData );
+	pcu_suite_setFixtures( suite, FieldVariableRegisterSuite_Setup, FieldVariableRegisterSuite_Teardown );
+	pcu_suite_addTest( suite, FieldVariableRegisterSuite_TestGetByIndex );
+	pcu_suite_addTest( suite, FieldVariableRegisterSuite_TestGetByName );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/OperatorFieldVariableSuite.c
--- a/Utils/tests/OperatorFieldVariableSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,324 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the OperatorFieldVariableSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "OperatorFieldVariableSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-	Stream*	stream; 	
-} OperatorFieldVariableSuiteData;
-
-/* Simulate Solid Body Rotation */
-InterpolationResult OperatorFieldVariableSuite_dummyInterpolateValueAt( void* sdVariable, Coord coord, double* value ) {
-	value[0] = -coord[1];
-	value[1] =  coord[0];
-	value[2] =  coord[2];
-	return LOCAL;
-}
-
-void OperatorFieldVariableSuite_dummyWithinElement( void* sdVariable, Element_DomainIndex dEl_I, Coord coord, double* value ) { return ; }
-double OperatorFieldVariableSuite_dummyGetMinGlobalValue( void* sdVariable ) { return 0; }
-double OperatorFieldVariableSuite_dummyGetMaxGlobalValue( void* sdVariable ) { return 1; }
-void OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords( void* sdVariable, Coord min, Coord max ) {
-	min[0] = -1.0;
-   min[1] = -2.3;
-   min[2] = -4.0;
-
-   max[0] = 11.0;
-   max[1] = 12.3;
-   max[2] = 14.0;
-   return ;
-}
-void OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords( void* sdVariable, Coord min, Coord max ) {   min[0] = -1.0;
-   min[0] = -111.0;
-   min[1] = -112.3;
-   min[2] = -114.0;
-
-   max[0] = 111.0;
-   max[1] = 112.3;
-   max[2] = 114.0;
-   return ;
-}
-
-void OperatorFieldVariableSuite_Setup( OperatorFieldVariableSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-
-	data->stream = Journal_Register( Info_Type, (Name)"OperatorFieldVariableStream"  );
-	Stream_RedirectFile( data->stream, "operatorFieldVariable.dat" );
-}
-
-void OperatorFieldVariableSuite_Teardown( OperatorFieldVariableSuiteData* data ) {
-}
-
-FieldVariable* OperatorFieldVariableSuite_GenerateVelocityField( OperatorFieldVariableSuiteData* data, FieldVariable_Register* fV_Register ) {
-	return FieldVariable_New( "Velocity", NULL, 3, 3, False, data->comm, fV_Register );
-}
-
-void OperatorFieldVariableSuite_TestVelocitySquared2D( OperatorFieldVariableSuiteData* data ) {
-	int							procToWatch;
-	FieldVariable_Register*	fV_Register;
-   FieldVariable*				velocityField;
-   OperatorFieldVariable*	velSquared2D;
-   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
-   double						value[3];
-   Index							index;
-   Coord                 	min, max;
-
-	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		fV_Register = FieldVariable_Register_New();
-		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
-		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
-		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
-		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
-		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
-		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
-
-		velSquared2D = OperatorFieldVariable_NewUnary( "VelocitySquaredField2D", NULL, velocityField, "VectorSquare" );
- 		velSquared2D->_operator->operandDofs = 2;
-
-		Journal_Printf( data->stream , "===Testing Velocity Squared 2D===\n" );
-
-		for ( index = 0 ; index < 3 ; index++ ) {
-			Journal_Printf( data->stream, "coord = ");
-			StGermain_PrintVector( data->stream, coord[ index ], 3 );
-
-			Journal_Printf( data->stream, "velocity = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 3 );
-
-			Journal_Printf( data->stream, "velocity squared 2d = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velSquared2D, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 1 );
-		}
-
-		Journal_Printf( data->stream , "testing min max local coords:\n" );
-		Journal_Printf( data->stream, "velocity:\n");
-		FieldVariable_GetMinAndMaxLocalCoords( velocityField, min, max );
-		StGermain_PrintNamedVector( data->stream, min, 3 );
-		StGermain_PrintNamedVector( data->stream, max, 3 );
-
-		Journal_Printf( data->stream, "velocity squared 2d = \n");
-		FieldVariable_GetMinAndMaxLocalCoords( velSquared2D, min, max );
-		StGermain_PrintNamedVector( data->stream, min, 3 );
-		StGermain_PrintNamedVector( data->stream, max, 3 );
-
-		Journal_Printf( data->stream , "testing min max global coords:\n" );
-		Journal_Printf( data->stream, "velocity:\n");
-		FieldVariable_GetMinAndMaxGlobalCoords( velocityField, min, max );
-		StGermain_PrintNamedVector( data->stream, min, 3 );
-		StGermain_PrintNamedVector( data->stream, max, 3 );
-
-		Journal_Printf( data->stream, "velocity squared 2d = \n");
-		FieldVariable_GetMinAndMaxGlobalCoords( velSquared2D, min, max );
-		StGermain_PrintNamedVector( data->stream, min, 3 );
-		StGermain_PrintNamedVector( data->stream, max, 3 );
-
-		Journal_Printf(data->stream, "\n");
-		Stg_Class_Delete(fV_Register);
-	}
-}
-
-void OperatorFieldVariableSuite_TestVelocitySquared3D( OperatorFieldVariableSuiteData* data ) {
-	int							procToWatch;
-	FieldVariable_Register*	fV_Register;
-   FieldVariable*				velocityField;
-   OperatorFieldVariable*	velSquared3D;
-   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
-   double						value[3];
-   Index							index;
-
-	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		fV_Register = FieldVariable_Register_New();
-		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
-		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
-		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
-		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
-		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
-		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
-
-		velSquared3D = OperatorFieldVariable_NewUnary( "VelocitySquaredField3D", NULL, velocityField, "VectorSquare" );
-
-		Journal_Printf( data->stream , "===Testing Velocity Squared 3D===\n" );
-
-		for ( index = 0 ; index < 3 ; index++ ) {
-			Journal_Printf( data->stream, "coord = ");
-			StGermain_PrintVector( data->stream, coord[ index ], 3 );
-
-			Journal_Printf( data->stream, "velocity = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 3 );
-
-			Journal_Printf( data->stream, "velocity squared 3d = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velSquared3D, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 1 );
-		}
-		Journal_Printf(data->stream, "\n");
-		Stg_Class_Delete(fV_Register);
-	}
-}
-	
-void OperatorFieldVariableSuite_TestVelocityMagnitude2D( OperatorFieldVariableSuiteData* data ) {
-	int							procToWatch;
-	FieldVariable_Register*	fV_Register;
-   FieldVariable*				velocityField;
-   OperatorFieldVariable*	velMag2D;
-   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
-   double						value[3];
-   Index							index;
-
-	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		fV_Register = FieldVariable_Register_New();
-		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
-		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
-		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
-		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
-		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
-		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
-
-		velMag2D = OperatorFieldVariable_NewUnary( "VelocityMagnitudeField2D", NULL, velocityField, "Magnitude" );
-		velMag2D->_operator->operandDofs = 2;
-
-		Journal_Printf( data->stream , "===Testing Velocity Magnitude 2D===\n" );
-
-		for ( index = 0 ; index < 3 ; index++ ) {
-			Journal_Printf( data->stream, "coord = ");
-			StGermain_PrintVector( data->stream, coord[ index ], 3 );
-
-			Journal_Printf( data->stream, "velocity = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 3 );
-
-			Journal_Printf( data->stream, "velocity magnitude 2d = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velMag2D, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 1 );
-		}
-		Journal_Printf(data->stream, "\n");
-		Stg_Class_Delete(fV_Register);
-	}
-}
-
-void OperatorFieldVariableSuite_TestVelocityMagnitude3D( OperatorFieldVariableSuiteData* data ) {
-	int							procToWatch;
-	FieldVariable_Register*	fV_Register;
-   FieldVariable*				velocityField;
-   OperatorFieldVariable*	velMag3D;
-   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
-   double						value[3];
-   Index							index;
-
-	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		fV_Register = FieldVariable_Register_New();
-		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
-		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
-		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
-		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
-		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
-		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
-		
-		velMag3D = OperatorFieldVariable_NewUnary( "VelocityMagnitudeField3D", NULL, velocityField, "Magnitude" );
-
-		Journal_Printf( data->stream , "===Testing Velocity Magnitude 3D===\n" );
-
-		for ( index = 0 ; index < 3 ; index++ ) {
-			Journal_Printf( data->stream, "coord = ");
-			StGermain_PrintVector( data->stream, coord[ index ], 3 );
-
-			Journal_Printf( data->stream, "velocity = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 3 );
-
-			Journal_Printf( data->stream, "velocity magnitude 3d = ");
-			pcu_check_true( FieldVariable_InterpolateValueAt( velMag3D, coord[ index ], value ) );
-			StGermain_PrintVector( data->stream, value, 1 );
-		}
-		Journal_Printf(data->stream, "\n");
-		Stg_Class_Delete(fV_Register);
-	}
-}
-
-void OperatorFieldVariableSuite_TestOutputFile( OperatorFieldVariableSuiteData* data ) {
-	int procToWatch;
-	char expected_file[PCU_PATH_MAX];
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		pcu_filename_expected( "testOperatorFieldVariableOutput.expected", expected_file );
-		pcu_check_fileEq( "operatorFieldVariable.dat", expected_file );
-		remove( "operatorFieldVariable.dat" );
-	}
-}
-
-void OperatorFieldVariableSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, OperatorFieldVariableSuiteData );
-	pcu_suite_setFixtures( suite, OperatorFieldVariableSuite_Setup, OperatorFieldVariableSuite_Teardown );
-	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocitySquared2D );
-	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocitySquared3D );
-	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocityMagnitude2D );
-	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocityMagnitude3D );
-	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestOutputFile );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/OperatorFieldVariableSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/OperatorFieldVariableSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,324 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the OperatorFieldVariableSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "OperatorFieldVariableSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+	Stream*	stream; 	
+} OperatorFieldVariableSuiteData;
+
+/* Simulate Solid Body Rotation */
+InterpolationResult OperatorFieldVariableSuite_dummyInterpolateValueAt( void* sdVariable, Coord coord, double* value ) {
+	value[0] = -coord[1];
+	value[1] =  coord[0];
+	value[2] =  coord[2];
+	return LOCAL;
+}
+
+void OperatorFieldVariableSuite_dummyWithinElement( void* sdVariable, Element_DomainIndex dEl_I, Coord coord, double* value ) { return ; }
+double OperatorFieldVariableSuite_dummyGetMinGlobalValue( void* sdVariable ) { return 0; }
+double OperatorFieldVariableSuite_dummyGetMaxGlobalValue( void* sdVariable ) { return 1; }
+void OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords( void* sdVariable, Coord min, Coord max ) {
+	min[0] = -1.0;
+   min[1] = -2.3;
+   min[2] = -4.0;
+
+   max[0] = 11.0;
+   max[1] = 12.3;
+   max[2] = 14.0;
+   return ;
+}
+void OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords( void* sdVariable, Coord min, Coord max ) {   min[0] = -1.0;
+   min[0] = -111.0;
+   min[1] = -112.3;
+   min[2] = -114.0;
+
+   max[0] = 111.0;
+   max[1] = 112.3;
+   max[2] = 114.0;
+   return ;
+}
+
+void OperatorFieldVariableSuite_Setup( OperatorFieldVariableSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+
+	data->stream = Journal_Register( Info_Type, (Name)"OperatorFieldVariableStream"  );
+	Stream_RedirectFile( data->stream, "operatorFieldVariable.dat" );
+}
+
+void OperatorFieldVariableSuite_Teardown( OperatorFieldVariableSuiteData* data ) {
+}
+
+FieldVariable* OperatorFieldVariableSuite_GenerateVelocityField( OperatorFieldVariableSuiteData* data, FieldVariable_Register* fV_Register ) {
+	return FieldVariable_New( "Velocity", NULL, 3, 3, False, data->comm, fV_Register );
+}
+
+void OperatorFieldVariableSuite_TestVelocitySquared2D( OperatorFieldVariableSuiteData* data ) {
+	int							procToWatch;
+	FieldVariable_Register*	fV_Register;
+   FieldVariable*				velocityField;
+   OperatorFieldVariable*	velSquared2D;
+   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
+   double						value[3];
+   Index							index;
+   Coord                 	min, max;
+
+	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		fV_Register = FieldVariable_Register_New();
+		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
+		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
+		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
+		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
+		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
+		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
+
+		velSquared2D = OperatorFieldVariable_NewUnary( "VelocitySquaredField2D", NULL, velocityField, "VectorSquare" );
+ 		velSquared2D->_operator->operandDofs = 2;
+
+		Journal_Printf( data->stream , "===Testing Velocity Squared 2D===\n" );
+
+		for ( index = 0 ; index < 3 ; index++ ) {
+			Journal_Printf( data->stream, "coord = ");
+			StGermain_PrintVector( data->stream, coord[ index ], 3 );
+
+			Journal_Printf( data->stream, "velocity = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 3 );
+
+			Journal_Printf( data->stream, "velocity squared 2d = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velSquared2D, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 1 );
+		}
+
+		Journal_Printf( data->stream , "testing min max local coords:\n" );
+		Journal_Printf( data->stream, "velocity:\n");
+		FieldVariable_GetMinAndMaxLocalCoords( velocityField, min, max );
+		StGermain_PrintNamedVector( data->stream, min, 3 );
+		StGermain_PrintNamedVector( data->stream, max, 3 );
+
+		Journal_Printf( data->stream, "velocity squared 2d = \n");
+		FieldVariable_GetMinAndMaxLocalCoords( velSquared2D, min, max );
+		StGermain_PrintNamedVector( data->stream, min, 3 );
+		StGermain_PrintNamedVector( data->stream, max, 3 );
+
+		Journal_Printf( data->stream , "testing min max global coords:\n" );
+		Journal_Printf( data->stream, "velocity:\n");
+		FieldVariable_GetMinAndMaxGlobalCoords( velocityField, min, max );
+		StGermain_PrintNamedVector( data->stream, min, 3 );
+		StGermain_PrintNamedVector( data->stream, max, 3 );
+
+		Journal_Printf( data->stream, "velocity squared 2d = \n");
+		FieldVariable_GetMinAndMaxGlobalCoords( velSquared2D, min, max );
+		StGermain_PrintNamedVector( data->stream, min, 3 );
+		StGermain_PrintNamedVector( data->stream, max, 3 );
+
+		Journal_Printf(data->stream, "\n");
+		Stg_Class_Delete(fV_Register);
+	}
+}
+
+void OperatorFieldVariableSuite_TestVelocitySquared3D( OperatorFieldVariableSuiteData* data ) {
+	int							procToWatch;
+	FieldVariable_Register*	fV_Register;
+   FieldVariable*				velocityField;
+   OperatorFieldVariable*	velSquared3D;
+   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
+   double						value[3];
+   Index							index;
+
+	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		fV_Register = FieldVariable_Register_New();
+		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
+		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
+		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
+		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
+		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
+		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
+
+		velSquared3D = OperatorFieldVariable_NewUnary( "VelocitySquaredField3D", NULL, velocityField, "VectorSquare" );
+
+		Journal_Printf( data->stream , "===Testing Velocity Squared 3D===\n" );
+
+		for ( index = 0 ; index < 3 ; index++ ) {
+			Journal_Printf( data->stream, "coord = ");
+			StGermain_PrintVector( data->stream, coord[ index ], 3 );
+
+			Journal_Printf( data->stream, "velocity = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 3 );
+
+			Journal_Printf( data->stream, "velocity squared 3d = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velSquared3D, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 1 );
+		}
+		Journal_Printf(data->stream, "\n");
+		Stg_Class_Delete(fV_Register);
+	}
+}
+	
+void OperatorFieldVariableSuite_TestVelocityMagnitude2D( OperatorFieldVariableSuiteData* data ) {
+	int							procToWatch;
+	FieldVariable_Register*	fV_Register;
+   FieldVariable*				velocityField;
+   OperatorFieldVariable*	velMag2D;
+   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
+   double						value[3];
+   Index							index;
+
+	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		fV_Register = FieldVariable_Register_New();
+		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
+		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
+		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
+		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
+		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
+		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
+
+		velMag2D = OperatorFieldVariable_NewUnary( "VelocityMagnitudeField2D", NULL, velocityField, "Magnitude" );
+		velMag2D->_operator->operandDofs = 2;
+
+		Journal_Printf( data->stream , "===Testing Velocity Magnitude 2D===\n" );
+
+		for ( index = 0 ; index < 3 ; index++ ) {
+			Journal_Printf( data->stream, "coord = ");
+			StGermain_PrintVector( data->stream, coord[ index ], 3 );
+
+			Journal_Printf( data->stream, "velocity = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 3 );
+
+			Journal_Printf( data->stream, "velocity magnitude 2d = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velMag2D, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 1 );
+		}
+		Journal_Printf(data->stream, "\n");
+		Stg_Class_Delete(fV_Register);
+	}
+}
+
+void OperatorFieldVariableSuite_TestVelocityMagnitude3D( OperatorFieldVariableSuiteData* data ) {
+	int							procToWatch;
+	FieldVariable_Register*	fV_Register;
+   FieldVariable*				velocityField;
+   OperatorFieldVariable*	velMag3D;
+   double						coord[3][3] = {{ 0.4 , 2.0 , 7.0 }, { -0.2 , 6.0 , 2.0 },{ 0.3 , -2.0 , -13.0 }} ;
+   double						value[3];
+   Index							index;
+
+	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		fV_Register = FieldVariable_Register_New();
+		velocityField = OperatorFieldVariableSuite_GenerateVelocityField( data, fV_Register );
+		velocityField->_interpolateValueAt = OperatorFieldVariableSuite_dummyInterpolateValueAt;
+		velocityField->_getMinGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMinGlobalValue;
+		velocityField->_getMaxGlobalFieldMagnitude = OperatorFieldVariableSuite_dummyGetMaxGlobalValue;
+		velocityField->_getMinAndMaxLocalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxLocalCoords;
+		velocityField->_getMinAndMaxGlobalCoords = OperatorFieldVariableSuite_dummyGetMinAndMaxGlobalCoords;		
+		
+		velMag3D = OperatorFieldVariable_NewUnary( "VelocityMagnitudeField3D", NULL, velocityField, "Magnitude" );
+
+		Journal_Printf( data->stream , "===Testing Velocity Magnitude 3D===\n" );
+
+		for ( index = 0 ; index < 3 ; index++ ) {
+			Journal_Printf( data->stream, "coord = ");
+			StGermain_PrintVector( data->stream, coord[ index ], 3 );
+
+			Journal_Printf( data->stream, "velocity = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velocityField, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 3 );
+
+			Journal_Printf( data->stream, "velocity magnitude 3d = ");
+			pcu_check_true( FieldVariable_InterpolateValueAt( velMag3D, coord[ index ], value ) );
+			StGermain_PrintVector( data->stream, value, 1 );
+		}
+		Journal_Printf(data->stream, "\n");
+		Stg_Class_Delete(fV_Register);
+	}
+}
+
+void OperatorFieldVariableSuite_TestOutputFile( OperatorFieldVariableSuiteData* data ) {
+	int procToWatch;
+	char expected_file[PCU_PATH_MAX];
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		pcu_filename_expected( "testOperatorFieldVariableOutput.expected", expected_file );
+		pcu_check_fileEq( "operatorFieldVariable.dat", expected_file );
+		remove( "operatorFieldVariable.dat" );
+	}
+}
+
+void OperatorFieldVariableSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, OperatorFieldVariableSuiteData );
+	pcu_suite_setFixtures( suite, OperatorFieldVariableSuite_Setup, OperatorFieldVariableSuite_Teardown );
+	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocitySquared2D );
+	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocitySquared3D );
+	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocityMagnitude2D );
+	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestVelocityMagnitude3D );
+	pcu_suite_addTest( suite, OperatorFieldVariableSuite_TestOutputFile );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/RegularMeshUtilsSuite.c
--- a/Utils/tests/RegularMeshUtilsSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,144 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the RegularMeshUtilsSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "RegularMeshUtilsSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} RegularMeshUtilsSuiteData;
-
-Mesh* RegularMeshUtilsSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	unsigned					maxDecomp[3] = {0, 1, 1};
-
-	gen = CartesianGenerator_New( "", NULL );
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-	FreeObject( mesh->generator );
-
-	return mesh;
-}
-
-
-void RegularMeshUtilsSuite_Setup( RegularMeshUtilsSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void RegularMeshUtilsSuite_Teardown( RegularMeshUtilsSuiteData* data ) {
-}
-
-void RegularMeshUtilsSuite_TestMeshUtils( RegularMeshUtilsSuiteData* data ) {
-	ExtensionManager_Register*	extensionMgr_Register;
-	unsigned							nDims = 3;
-	unsigned							meshSize[3] = {6, 6, 6};
-	double							minCrds[3] = {0.0, 0.0, 0.0};
-	double							maxCrds[3] = {1.0, 1.0, 1.0};
-	Mesh*								mesh;
-	char								expected_file[PCU_PATH_MAX];
-	int								procToWatch;
-	Stream*							stream; 	
-
-	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
-	stream = Journal_Register( Info_Type, (Name)"RegularMeshUtilsStream" );
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	extensionMgr_Register = ExtensionManager_Register_New( );
-	mesh = RegularMeshUtilsSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-
-	if( data->rank == procToWatch ) {
-		unsigned		currElementNodesCount=0;
-		unsigned*	currElementNodes = NULL;
-		unsigned		element_dI = 0;
-		unsigned		refNode_eI = 0;
-		unsigned		node_Diagonal = 0;
-		unsigned		node_Diagonal_gI = 0;
-		IArray*		inc;
-
-		inc = IArray_New();
-		
-		Stream_RedirectFile( stream, "regularMeshUtils.dat" );
-
-		for (element_dI=0; element_dI < Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ); element_dI++) {
-			Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims, element_dI, MT_VERTEX, inc );
-			currElementNodesCount = IArray_GetSize( inc );
-			currElementNodes = (unsigned*)IArray_GetPtr( inc );
-
-			for (refNode_eI = 0; refNode_eI < currElementNodesCount; refNode_eI++ ) {
-				node_Diagonal = RegularMeshUtils_GetDiagOppositeAcrossElementNodeIndex(mesh, element_dI, currElementNodes[refNode_eI]) ;
-				node_Diagonal_gI = Mesh_DomainToGlobal( mesh, MT_VERTEX, node_Diagonal );
-				/*print message stating: Element #, curr node #, diag opp node #*/
-				Journal_Printf( stream, "Element #: %d, Current Node #: %d, Diagonal Node #: %d, (%d) \n", element_dI, currElementNodes[refNode_eI], node_Diagonal, node_Diagonal_gI );
-			}
-		}
-		pcu_filename_expected( "testRegularMeshUtilsOutput.expected", expected_file );
-		pcu_check_fileEq( "regularMeshUtils.dat", expected_file );
-		NewClass_Delete( inc );
-		remove( "regularMeshUtils.dat" );
-	}
-	Stg_Class_Delete(extensionMgr_Register);
-}
-	
-void RegularMeshUtilsSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, RegularMeshUtilsSuiteData );
-	pcu_suite_setFixtures( suite, RegularMeshUtilsSuite_Setup, RegularMeshUtilsSuite_Teardown );
-	pcu_suite_addTest( suite, RegularMeshUtilsSuite_TestMeshUtils );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/RegularMeshUtilsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/RegularMeshUtilsSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,144 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the RegularMeshUtilsSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "RegularMeshUtilsSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} RegularMeshUtilsSuiteData;
+
+Mesh* RegularMeshUtilsSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	unsigned					maxDecomp[3] = {0, 1, 1};
+
+	gen = CartesianGenerator_New( "", NULL );
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+	FreeObject( mesh->generator );
+
+	return mesh;
+}
+
+
+void RegularMeshUtilsSuite_Setup( RegularMeshUtilsSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void RegularMeshUtilsSuite_Teardown( RegularMeshUtilsSuiteData* data ) {
+}
+
+void RegularMeshUtilsSuite_TestMeshUtils( RegularMeshUtilsSuiteData* data ) {
+	ExtensionManager_Register*	extensionMgr_Register;
+	unsigned							nDims = 3;
+	unsigned							meshSize[3] = {6, 6, 6};
+	double							minCrds[3] = {0.0, 0.0, 0.0};
+	double							maxCrds[3] = {1.0, 1.0, 1.0};
+	Mesh*								mesh;
+	char								expected_file[PCU_PATH_MAX];
+	int								procToWatch;
+	Stream*							stream; 	
+
+	Journal_Enable_NamedStream( Info_Type, CartesianGenerator_Type, False );
+	stream = Journal_Register( Info_Type, (Name)"RegularMeshUtilsStream" );
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	extensionMgr_Register = ExtensionManager_Register_New( );
+	mesh = RegularMeshUtilsSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+
+	if( data->rank == procToWatch ) {
+		unsigned		currElementNodesCount=0;
+		unsigned*	currElementNodes = NULL;
+		unsigned		element_dI = 0;
+		unsigned		refNode_eI = 0;
+		unsigned		node_Diagonal = 0;
+		unsigned		node_Diagonal_gI = 0;
+		IArray*		inc;
+
+		inc = IArray_New();
+		
+		Stream_RedirectFile( stream, "regularMeshUtils.dat" );
+
+		for (element_dI=0; element_dI < Mesh_GetDomainSize( mesh, (MeshTopology_Dim)nDims ); element_dI++) {
+			Mesh_GetIncidence( mesh, (MeshTopology_Dim)nDims, element_dI, MT_VERTEX, inc );
+			currElementNodesCount = IArray_GetSize( inc );
+			currElementNodes = (unsigned*)IArray_GetPtr( inc );
+
+			for (refNode_eI = 0; refNode_eI < currElementNodesCount; refNode_eI++ ) {
+				node_Diagonal = RegularMeshUtils_GetDiagOppositeAcrossElementNodeIndex(mesh, element_dI, currElementNodes[refNode_eI]) ;
+				node_Diagonal_gI = Mesh_DomainToGlobal( mesh, MT_VERTEX, node_Diagonal );
+				/*print message stating: Element #, curr node #, diag opp node #*/
+				Journal_Printf( stream, "Element #: %d, Current Node #: %d, Diagonal Node #: %d, (%d) \n", element_dI, currElementNodes[refNode_eI], node_Diagonal, node_Diagonal_gI );
+			}
+		}
+		pcu_filename_expected( "testRegularMeshUtilsOutput.expected", expected_file );
+		pcu_check_fileEq( "regularMeshUtils.dat", expected_file );
+		NewClass_Delete( inc );
+		remove( "regularMeshUtils.dat" );
+	}
+	Stg_Class_Delete(extensionMgr_Register);
+}
+	
+void RegularMeshUtilsSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, RegularMeshUtilsSuiteData );
+	pcu_suite_setFixtures( suite, RegularMeshUtilsSuite_Setup, RegularMeshUtilsSuite_Teardown );
+	pcu_suite_addTest( suite, RegularMeshUtilsSuite_TestMeshUtils );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/SobolGeneratorSuite.c
--- a/Utils/tests/SobolGeneratorSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the SobolGeneratorSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "SobolGeneratorSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} SobolGeneratorSuiteData;
-
-void SobolGeneratorSuite_Setup( SobolGeneratorSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void SobolGeneratorSuite_Teardown( SobolGeneratorSuiteData* data ) {
-}
-
-void SobolGeneratorSuite_TestSobolGenerator( SobolGeneratorSuiteData* data ) {
-	int					procToWatch;
-	Stream*				stream;
-	SobolGenerator*	sobolGenerator;
-	Index					index;
-	Index					sobol_I;
-	int					bit_I;
-	double				result;
-	char					output_file[PCU_PATH_MAX];
-	char					rightmostBit_file[PCU_PATH_MAX];
-	char					expected_name[PCU_PATH_MAX];
-	char					expected_file[PCU_PATH_MAX];
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {
-		stream = Journal_Register( Info_Type, (Name)"SobolGeneratorStream" );
-		Stream_RedirectFile( stream, "testSobolGeneratorRightmostBit.dat" );
-	
-		Journal_Printf( stream, " *********************** Testing _SobolGenerator_FindRightmostZeroBit *******************\n" );
-		for ( index = 0 ; index < 30 ; index++ ) {
-			for ( bit_I = sizeof( Index ) * 4 - 1 ; bit_I >= 0 ; bit_I-- )
-				Journal_Printf( stream, "%u", index & 1 << bit_I ? 1 : 0 );
-			Journal_Printf( stream, " number %u: %u\n", index, _SobolGenerator_FindRightmostZeroBit( index ) );
-		}
-
-		/* constructor  */
-		for ( sobol_I = 0 ; sobol_I < 100 ; sobol_I++ ) {
-			sprintf( output_file, "testSobolGenerator.%03u.dat", sobol_I );
-			Stream_RedirectFile( stream, output_file );
-			sobolGenerator = SobolGenerator_NewFromTable( output_file );
-
-			Journal_Printf( stream," ****************** Testing SobolGenerator_GetDirectionalNumber ***************\n" );
-			for ( index = 0 ; index < 30 ; index++ )
-				SobolGenerator_GetDirectionalNumber( sobolGenerator, index );
-	
-			/* Checking up to 200000 numbers - this number is arbitary - 
-			* it's only limited because we don't want file size to be huge
-			* This number is intentionally over 25535 = 2^16 - 1 because there was a time when numbers repeated after this */
-			for ( index = 0 ; index < 200000 ; index++ ) {
-				result = SobolGenerator_GetNextNumber(sobolGenerator);
-	
-				assert( fabs( result - SobolGenerator_GetNumberByIndex(sobolGenerator, index)) < 1e-8 );
-
-				/* Only dump subset of data - this output criterion is completely arbitary */
-				if ( index % 773 == 3 )
-					Journal_Printf( stream, "%.4g\n", result );
-			}
-			sprintf( expected_name, "testSobolGeneratorOutput.%03u-%03u.expected", sobolGenerator->polynomialDegree, sobolGenerator->polynomialCoefficient );
-
-			pcu_filename_expected( "testSobolGeneratorRightmostBitOutput.expected", rightmostBit_file );
-			pcu_check_fileEq( "testSobolGeneratorRightmostBit.dat", rightmostBit_file );
-
-			pcu_filename_expected( expected_name, expected_file );
-			pcu_check_fileEq( output_file, expected_file ); 
-
-			remove( output_file );
-
-			Stg_Class_Delete( sobolGenerator );
-		}
-		remove( "testSobolGeneratorRightmostBit.dat" );
-	}
-}
-
-void SobolGeneratorSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, SobolGeneratorSuiteData );
-	pcu_suite_setFixtures( suite, SobolGeneratorSuite_Setup, SobolGeneratorSuite_Teardown );
-	pcu_suite_addTest( suite, SobolGeneratorSuite_TestSobolGenerator );
-}
-
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/SobolGeneratorSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/SobolGeneratorSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,135 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the SobolGeneratorSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "SobolGeneratorSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} SobolGeneratorSuiteData;
+
+void SobolGeneratorSuite_Setup( SobolGeneratorSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void SobolGeneratorSuite_Teardown( SobolGeneratorSuiteData* data ) {
+}
+
+void SobolGeneratorSuite_TestSobolGenerator( SobolGeneratorSuiteData* data ) {
+	int					procToWatch;
+	Stream*				stream;
+	SobolGenerator*	sobolGenerator;
+	Index					index;
+	Index					sobol_I;
+	int					bit_I;
+	double				result;
+	char					output_file[PCU_PATH_MAX];
+	char					rightmostBit_file[PCU_PATH_MAX];
+	char					expected_name[PCU_PATH_MAX];
+	char					expected_file[PCU_PATH_MAX];
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {
+		stream = Journal_Register( Info_Type, (Name)"SobolGeneratorStream" );
+		Stream_RedirectFile( stream, "testSobolGeneratorRightmostBit.dat" );
+	
+		Journal_Printf( stream, " *********************** Testing _SobolGenerator_FindRightmostZeroBit *******************\n" );
+		for ( index = 0 ; index < 30 ; index++ ) {
+			for ( bit_I = sizeof( Index ) * 4 - 1 ; bit_I >= 0 ; bit_I-- )
+				Journal_Printf( stream, "%u", index & 1 << bit_I ? 1 : 0 );
+			Journal_Printf( stream, " number %u: %u\n", index, _SobolGenerator_FindRightmostZeroBit( index ) );
+		}
+
+		/* constructor  */
+		for ( sobol_I = 0 ; sobol_I < 100 ; sobol_I++ ) {
+			sprintf( output_file, "testSobolGenerator.%03u.dat", sobol_I );
+			Stream_RedirectFile( stream, output_file );
+			sobolGenerator = SobolGenerator_NewFromTable( output_file );
+
+			Journal_Printf( stream," ****************** Testing SobolGenerator_GetDirectionalNumber ***************\n" );
+			for ( index = 0 ; index < 30 ; index++ )
+				SobolGenerator_GetDirectionalNumber( sobolGenerator, index );
+	
+			/* Checking up to 200000 numbers - this number is arbitary - 
+			* it's only limited because we don't want file size to be huge
+			* This number is intentionally over 25535 = 2^16 - 1 because there was a time when numbers repeated after this */
+			for ( index = 0 ; index < 200000 ; index++ ) {
+				result = SobolGenerator_GetNextNumber(sobolGenerator);
+	
+				assert( fabs( result - SobolGenerator_GetNumberByIndex(sobolGenerator, index)) < 1e-8 );
+
+				/* Only dump subset of data - this output criterion is completely arbitary */
+				if ( index % 773 == 3 )
+					Journal_Printf( stream, "%.4g\n", result );
+			}
+			sprintf( expected_name, "testSobolGeneratorOutput.%03u-%03u.expected", sobolGenerator->polynomialDegree, sobolGenerator->polynomialCoefficient );
+
+			pcu_filename_expected( "testSobolGeneratorRightmostBitOutput.expected", rightmostBit_file );
+			pcu_check_fileEq( "testSobolGeneratorRightmostBit.dat", rightmostBit_file );
+
+			pcu_filename_expected( expected_name, expected_file );
+			pcu_check_fileEq( output_file, expected_file ); 
+
+			remove( output_file );
+
+			Stg_Class_Delete( sobolGenerator );
+		}
+		remove( "testSobolGeneratorRightmostBit.dat" );
+	}
+}
+
+void SobolGeneratorSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, SobolGeneratorSuiteData );
+	pcu_suite_setFixtures( suite, SobolGeneratorSuite_Setup, SobolGeneratorSuite_Teardown );
+	pcu_suite_addTest( suite, SobolGeneratorSuite_TestSobolGenerator );
+}
+
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/TimeIntegrationSuite.c
--- a/Utils/tests/TimeIntegrationSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,343 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the TimeIntegrationSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "TimeIntegrationSuite.h"
-
-#define  CURR_MODULE_NAME "TimeIntegrationSuite.c"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} TimeIntegrationSuiteData;
-
-double TimeIntegrationSuite_GetDt( void* context ) {
-   return 0.1;
-}
-
-Bool TimeIntegrationSuite_ConstantTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-	timeDeriv[0] = 2.0 * array_I;
-   timeDeriv[1] = -1.0 * array_I;
-
-   return True;
-}
-Bool TimeIntegrationSuite_ConstantTimeDeriv2( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-   timeDeriv[0] = -0.5 * array_I;
-   timeDeriv[1] = 3.0 * array_I;
-
-   return True;
-}
-Bool TimeIntegrationSuite_LinearTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-   double time = TimeIntegrand_GetTime( timeIntegrand );
-
-   timeDeriv[0] = 2.0 * array_I * time;
-   timeDeriv[1] = -1.0 * array_I * time;
-
-   return True;
-}
-Bool TimeIntegrationSuite_LinearTimeDeriv2( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-   double time = TimeIntegrand_GetTime( timeIntegrand );
-
-   timeDeriv[0] = -0.5 * array_I * time;
-   timeDeriv[1] = 3.0 * array_I * time;
-
-   return True;
-}
-Bool TimeIntegrationSuite_CubicTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-   double time = TimeIntegrand_GetTime( timeIntegrand );
-
-   timeDeriv[0] = 2.0 * array_I * ( time * time * time - time*time );
-   timeDeriv[1] = -1.0 * array_I * ( time * time * time - time*time );
-
-   return True;
-}
-Bool TimeIntegrationSuite_CubicTimeDeriv2( void* timeIntegrand, Index array_I, double* timeDeriv ) {
-   double time = TimeIntegrand_GetTime( timeIntegrand );
-
-   timeDeriv[0] = -0.5 * array_I * ( time * time * time - time*time );
-   timeDeriv[1] = 3.0 * array_I * ( time * time * time - time*time );
-
-   return True;
-}
-
-TimeIntegrand_CalculateTimeDerivFunction* TimeIntegrationSuite_GetFunctionPtr( Name derivName ) {
-   if ( strcasecmp( derivName, "Linear" ) == 0 )
-      return TimeIntegrationSuite_LinearTimeDeriv;
-   else if ( strcasecmp( derivName, "Linear2" ) == 0 )
-      return TimeIntegrationSuite_LinearTimeDeriv2;
-   else if ( strcasecmp( derivName, "Cubic" ) == 0 )
-      return TimeIntegrationSuite_CubicTimeDeriv;
-   else if ( strcasecmp( derivName, "Cubic2" ) == 0 )
-      return TimeIntegrationSuite_CubicTimeDeriv2;
-   else if ( strcasecmp( derivName, "Constant" ) == 0 )
-      return TimeIntegrationSuite_ConstantTimeDeriv;
-   else if ( strcasecmp( derivName, "Constant2" ) == 0 )
-      return TimeIntegrationSuite_ConstantTimeDeriv2;
-   else
-      Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ), "Don't understand DerivName '%s'\n", derivName  );
-
-   return NULL;
-}
-
-void TimeIntegrationSuite_TestContextType( void* timeIntegrand, Stg_Class* data ) {
-   assert( data->type == DomainContext_Type );
-}
-
-void TimeIntegrationSuite_TestVariableType( void* timeIntegrand, Stg_Class* data ) {
-   assert( data->type == Variable_Type );
-}
-
-void TimeIntegrationSuite_Setup( TimeIntegrationSuiteData* data ) {
-	Journal_Enable_AllTypedStream( False );
-
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void TimeIntegrationSuite_Teardown( TimeIntegrationSuiteData* data ) {
-	Journal_Enable_AllTypedStream( True );
-}
-
-void TimeIntegrationSuite_TestDriver( TimeIntegrationSuiteData* data, const char *_name, const char *_DerivName0, const char *_DerivName1, int _order ) {
-	Stg_ComponentFactory*	cf;
-	Stream*						stream;
-   Dictionary*					dictionary;
-   TimeIntegrator*			timeIntegrator;
-   TimeIntegrand*			timeIntegrand;
-   TimeIntegrand*			timeIntegrandList[2];
-   DomainContext*				context;
-   Variable*					variable;
-   Variable*					variableList[2];
-   double*						array;
-   double*						array2;
-   Index							size0	= 11;
-   Index							size1	= 7;
-	Index							array_I;
-   Index							timestep	= 0;
-   Index							maxTimesteps	= 10;
-	Bool							simultaneous;
-   unsigned						order;
-   double						error	= 0.0;
-   Name							derivName;
-   double						tolerance	= 0.001;
-   Index							integrand_I;
-   Index							integrandCount	= 2;
-	char							expected_file[PCU_PATH_MAX];
-
-	dictionary = Dictionary_New();
-	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
-	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName0", Dictionary_Entry_Value_FromString(_DerivName0) );
-	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName1", Dictionary_Entry_Value_FromString(_DerivName1) );
-
-	context = DomainContext_New( "context", 0, 0, MPI_COMM_WORLD, NULL );
-	cf = stgMainConstruct( dictionary, data->comm, context );
-	stgMainBuildAndInitialise( cf );
-      
-	ContextEP_Append( context, AbstractContext_EP_Dt, TimeIntegrationSuite_GetDt );
-
-	/* Create Stuff */
-	order							= _order;
-	simultaneous				= False;
-	variableList[0]			= Variable_NewVector( "testVariable", (AbstractContext*)context, Variable_DataType_Double, 2, &size0, NULL, (void**)&array, NULL );
-	variableList[1]			= Variable_NewVector( "testVariable2", (AbstractContext*)context, Variable_DataType_Double, 2, &size1, NULL, (void**)&array2, NULL );
-	timeIntegrator				= TimeIntegrator_New( "testTimeIntegrator", order, simultaneous, NULL, NULL );
-	timeIntegrator->context	= context;
-	timeIntegrandList[0]	= TimeIntegrand_New( "testTimeIntegrand0", context, timeIntegrator, variableList[0], 0, NULL, True );
-	timeIntegrandList[1]	= TimeIntegrand_New( "testTimeIntegrand1", context, timeIntegrator, variableList[1], 0, NULL, True );
-
-	Journal_Enable_AllTypedStream( True );
-	stream = Journal_Register( Info_Type, (Name)"EulerStream"  );
-	Stream_RedirectFile( stream, _name );
-
-	Stream_Enable( timeIntegrator->info, False );
-	derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName0" );
-	timeIntegrandList[0]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName  );
-	Journal_Printf( stream, "DerivName0 - %s\n", derivName );
-	derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName1" );
-	timeIntegrandList[1]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName  );
-	Journal_Printf( stream, "DerivName1 - %s\n", derivName );
-
-	/* Print Stuff to file */
-	Journal_PrintValue( stream, order );
-	Journal_PrintBool( stream, simultaneous );
-
-	/* Add stuff to EPs */
-	TimeIntegrator_AppendSetupEP( timeIntegrator, "start1", (void*)TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context );
-	TimeIntegrator_AppendFinishEP( timeIntegrator, "finish1", (void*)TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] );
-	TimeIntegrator_PrependSetupEP( timeIntegrator, "start0", (void*)TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] );
-	TimeIntegrator_PrependFinishEP( timeIntegrator, "finish0", (void*)TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context );
-
-	/* Build */
-	Stg_Component_Build( variableList[0], context, False );
-	Stg_Component_Build( variableList[1], context, False );
-	Stg_Component_Build( timeIntegrator, context, False );
-	Stg_Component_Build( timeIntegrandList[0], context, False );
-	Stg_Component_Build( timeIntegrandList[1], context, False );
-	array = Memory_Alloc_Array( double, 2 * size0, "name" );
-	array2 = Memory_Alloc_Array( double, 2 * size1, "name" );
-
-	/* Initialise */
-	memset( array, 0, sizeof(double) * 2 * size0 );
-	memset( array2, 0, sizeof(double) * 2 * size1 );
-	Stg_Component_Initialise( timeIntegrator, context, False );
-	Stg_Component_Initialise( variableList[0], context, False );
-	Stg_Component_Initialise( variableList[1], context, False );
-	Stg_Component_Initialise( timeIntegrandList[0], context, False );
-	Stg_Component_Initialise( timeIntegrandList[1], context, False );
-
-	for ( timestep = 0.0 ; timestep < maxTimesteps ; timestep ++ ) {
-		Journal_Printf( stream, "Step %u - Time = %.3g\n", timestep, context->currentTime );
-
-		Stg_Component_Execute( timeIntegrator, context, True );
-		context->currentTime += AbstractContext_Dt( context );
-
-		for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
-			timeIntegrand	= timeIntegrandList[ integrand_I ];
-			variable			= variableList[ integrand_I ];
-			for ( array_I = 0 ; array_I < variable->arraySize ; array_I++ ) {
-				if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv ) {
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * context->currentTime );
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * context->currentTime );
-				}
-				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) {
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * context->currentTime );
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3 * array_I * context->currentTime );
-				}
-				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv ) {
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - array_I * context->currentTime * context->currentTime );
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + 0.5 * array_I * context->currentTime * context->currentTime );
-				}
-				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) {
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.25 * array_I * context->currentTime * context->currentTime );
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 1.5 * array_I * context->currentTime * context->currentTime );
-				}
-				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv ) {
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0));
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0));
-				}
-				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) {
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0));
-					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0));
-				}
-				else
-					Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ), "Don't understand _calculateTimeDeriv = %p\n", timeIntegrand->_calculateTimeDeriv );
-			}
-		}
-	}
-	pcu_check_lt( error, tolerance );
-
-	if ( error < tolerance )
-		Journal_Printf( stream, "Passed\n" );
-	else
-		Journal_Printf( stream, "Failed - Error = %lf\n", error );
-	
-	Journal_Enable_AllTypedStream( False );
-
-	if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv
-		|| timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) {
-		pcu_filename_expected( "testTimeIntegrationEulerOutput.expected", expected_file );
-	}
-	else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv
-		|| timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) {
-		pcu_filename_expected( "testTimeIntegrationRK2Output.expected", expected_file );
-	}
-	else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv
-		|| timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) {
-		pcu_filename_expected( "testTimeIntegrationRK4Output.expected", expected_file );
-	}
-
-	pcu_check_fileEq( _name, expected_file );
-
-	/* Destroy stuff */
-	Stream_CloseAndFreeFile( stream );
-	Memory_Free( array );
-	Memory_Free( array2 );
-	Stg_Class_Delete( variable );
-	_Stg_Component_Delete( timeIntegrator );
-	_Stg_Component_Delete( timeIntegrandList[0] );
-	_Stg_Component_Delete( timeIntegrandList[1] );
-	remove( _name );
-}
-	
-void TimeIntegrationSuite_TestEuler( TimeIntegrationSuiteData* data ) {
-	int procToWatch;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {	
-		TimeIntegrationSuite_TestDriver( data, "testIntegrationEuler", "Constant", "Constant2", 1 );
-	}
-}
-
-void TimeIntegrationSuite_TestRK2( TimeIntegrationSuiteData* data ) {
-	int procToWatch;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {	
-		TimeIntegrationSuite_TestDriver( data, "testIntegrationRK2", "Linear", "Linear2", 2 );
-	}
-}
-
-void TimeIntegrationSuite_TestRK4( TimeIntegrationSuiteData* data ) {
-	int procToWatch;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-	if( data->rank == procToWatch ) {	
-		TimeIntegrationSuite_TestDriver( data, "testIntegrationRK4", "Cubic", "Cubic2", 4 );
-	}
-}
-
-void TimeIntegrationSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, TimeIntegrationSuiteData );
-	pcu_suite_setFixtures( suite, TimeIntegrationSuite_Setup, TimeIntegrationSuite_Teardown );
-	pcu_suite_addTest( suite, TimeIntegrationSuite_TestEuler );
-	pcu_suite_addTest( suite, TimeIntegrationSuite_TestRK2 );
-	pcu_suite_addTest( suite, TimeIntegrationSuite_TestRK4 );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/TimeIntegrationSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/TimeIntegrationSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,343 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the TimeIntegrationSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "TimeIntegrationSuite.h"
+
+#define  CURR_MODULE_NAME "TimeIntegrationSuite.c"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} TimeIntegrationSuiteData;
+
+double TimeIntegrationSuite_GetDt( void* context ) {
+   return 0.1;
+}
+
+Bool TimeIntegrationSuite_ConstantTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+	timeDeriv[0] = 2.0 * array_I;
+   timeDeriv[1] = -1.0 * array_I;
+
+   return True;
+}
+Bool TimeIntegrationSuite_ConstantTimeDeriv2( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+   timeDeriv[0] = -0.5 * array_I;
+   timeDeriv[1] = 3.0 * array_I;
+
+   return True;
+}
+Bool TimeIntegrationSuite_LinearTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+   double time = TimeIntegrand_GetTime( timeIntegrand );
+
+   timeDeriv[0] = 2.0 * array_I * time;
+   timeDeriv[1] = -1.0 * array_I * time;
+
+   return True;
+}
+Bool TimeIntegrationSuite_LinearTimeDeriv2( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+   double time = TimeIntegrand_GetTime( timeIntegrand );
+
+   timeDeriv[0] = -0.5 * array_I * time;
+   timeDeriv[1] = 3.0 * array_I * time;
+
+   return True;
+}
+Bool TimeIntegrationSuite_CubicTimeDeriv( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+   double time = TimeIntegrand_GetTime( timeIntegrand );
+
+   timeDeriv[0] = 2.0 * array_I * ( time * time * time - time*time );
+   timeDeriv[1] = -1.0 * array_I * ( time * time * time - time*time );
+
+   return True;
+}
+Bool TimeIntegrationSuite_CubicTimeDeriv2( void* timeIntegrand, Index array_I, double* timeDeriv ) {
+   double time = TimeIntegrand_GetTime( timeIntegrand );
+
+   timeDeriv[0] = -0.5 * array_I * ( time * time * time - time*time );
+   timeDeriv[1] = 3.0 * array_I * ( time * time * time - time*time );
+
+   return True;
+}
+
+TimeIntegrand_CalculateTimeDerivFunction* TimeIntegrationSuite_GetFunctionPtr( Name derivName ) {
+   if ( strcasecmp( derivName, "Linear" ) == 0 )
+      return TimeIntegrationSuite_LinearTimeDeriv;
+   else if ( strcasecmp( derivName, "Linear2" ) == 0 )
+      return TimeIntegrationSuite_LinearTimeDeriv2;
+   else if ( strcasecmp( derivName, "Cubic" ) == 0 )
+      return TimeIntegrationSuite_CubicTimeDeriv;
+   else if ( strcasecmp( derivName, "Cubic2" ) == 0 )
+      return TimeIntegrationSuite_CubicTimeDeriv2;
+   else if ( strcasecmp( derivName, "Constant" ) == 0 )
+      return TimeIntegrationSuite_ConstantTimeDeriv;
+   else if ( strcasecmp( derivName, "Constant2" ) == 0 )
+      return TimeIntegrationSuite_ConstantTimeDeriv2;
+   else
+      Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ), "Don't understand DerivName '%s'\n", derivName  );
+
+   return NULL;
+}
+
+void TimeIntegrationSuite_TestContextType( void* timeIntegrand, Stg_Class* data ) {
+   assert( data->type == DomainContext_Type );
+}
+
+void TimeIntegrationSuite_TestVariableType( void* timeIntegrand, Stg_Class* data ) {
+   assert( data->type == Variable_Type );
+}
+
+void TimeIntegrationSuite_Setup( TimeIntegrationSuiteData* data ) {
+	Journal_Enable_AllTypedStream( False );
+
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void TimeIntegrationSuite_Teardown( TimeIntegrationSuiteData* data ) {
+	Journal_Enable_AllTypedStream( True );
+}
+
+void TimeIntegrationSuite_TestDriver( TimeIntegrationSuiteData* data, const char *_name, const char *_DerivName0, const char *_DerivName1, int _order ) {
+	Stg_ComponentFactory*	cf;
+	Stream*						stream;
+   Dictionary*					dictionary;
+   TimeIntegrator*			timeIntegrator;
+   TimeIntegrand*			timeIntegrand;
+   TimeIntegrand*			timeIntegrandList[2];
+   DomainContext*				context;
+   Variable*					variable;
+   Variable*					variableList[2];
+   double*						array;
+   double*						array2;
+   Index							size0	= 11;
+   Index							size1	= 7;
+	Index							array_I;
+   Index							timestep	= 0;
+   Index							maxTimesteps	= 10;
+	Bool							simultaneous;
+   unsigned						order;
+   double						error	= 0.0;
+   Name							derivName;
+   double						tolerance	= 0.001;
+   Index							integrand_I;
+   Index							integrandCount	= 2;
+	char							expected_file[PCU_PATH_MAX];
+
+	dictionary = Dictionary_New();
+	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
+	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName0", Dictionary_Entry_Value_FromString(_DerivName0) );
+	Dictionary_Add( dictionary, (Dictionary_Entry_Key)"DerivName1", Dictionary_Entry_Value_FromString(_DerivName1) );
+
+	context = DomainContext_New( "context", 0, 0, MPI_COMM_WORLD, NULL );
+	cf = stgMainConstruct( dictionary, data->comm, context );
+	stgMainBuildAndInitialise( cf );
+      
+	ContextEP_Append( context, AbstractContext_EP_Dt, TimeIntegrationSuite_GetDt );
+
+	/* Create Stuff */
+	order							= _order;
+	simultaneous				= False;
+	variableList[0]			= Variable_NewVector( "testVariable", (AbstractContext*)context, Variable_DataType_Double, 2, &size0, NULL, (void**)&array, NULL );
+	variableList[1]			= Variable_NewVector( "testVariable2", (AbstractContext*)context, Variable_DataType_Double, 2, &size1, NULL, (void**)&array2, NULL );
+	timeIntegrator				= TimeIntegrator_New( "testTimeIntegrator", order, simultaneous, NULL, NULL );
+	timeIntegrator->context	= context;
+	timeIntegrandList[0]	= TimeIntegrand_New( "testTimeIntegrand0", context, timeIntegrator, variableList[0], 0, NULL, True );
+	timeIntegrandList[1]	= TimeIntegrand_New( "testTimeIntegrand1", context, timeIntegrator, variableList[1], 0, NULL, True );
+
+	Journal_Enable_AllTypedStream( True );
+	stream = Journal_Register( Info_Type, (Name)"EulerStream"  );
+	Stream_RedirectFile( stream, _name );
+
+	Stream_Enable( timeIntegrator->info, False );
+	derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName0" );
+	timeIntegrandList[0]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName  );
+	Journal_Printf( stream, "DerivName0 - %s\n", derivName );
+	derivName = Dictionary_GetString( dictionary, (Dictionary_Entry_Key)"DerivName1" );
+	timeIntegrandList[1]->_calculateTimeDeriv = TimeIntegrationSuite_GetFunctionPtr( derivName  );
+	Journal_Printf( stream, "DerivName1 - %s\n", derivName );
+
+	/* Print Stuff to file */
+	Journal_PrintValue( stream, order );
+	Journal_PrintBool( stream, simultaneous );
+
+	/* Add stuff to EPs */
+	TimeIntegrator_AppendSetupEP( timeIntegrator, "start1", (void*)TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context );
+	TimeIntegrator_AppendFinishEP( timeIntegrator, "finish1", (void*)TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] );
+	TimeIntegrator_PrependSetupEP( timeIntegrator, "start0", (void*)TimeIntegrationSuite_TestVariableType, CURR_MODULE_NAME, variableList[0] );
+	TimeIntegrator_PrependFinishEP( timeIntegrator, "finish0", (void*)TimeIntegrationSuite_TestContextType, CURR_MODULE_NAME, context );
+
+	/* Build */
+	Stg_Component_Build( variableList[0], context, False );
+	Stg_Component_Build( variableList[1], context, False );
+	Stg_Component_Build( timeIntegrator, context, False );
+	Stg_Component_Build( timeIntegrandList[0], context, False );
+	Stg_Component_Build( timeIntegrandList[1], context, False );
+	array = Memory_Alloc_Array( double, 2 * size0, "name" );
+	array2 = Memory_Alloc_Array( double, 2 * size1, "name" );
+
+	/* Initialise */
+	memset( array, 0, sizeof(double) * 2 * size0 );
+	memset( array2, 0, sizeof(double) * 2 * size1 );
+	Stg_Component_Initialise( timeIntegrator, context, False );
+	Stg_Component_Initialise( variableList[0], context, False );
+	Stg_Component_Initialise( variableList[1], context, False );
+	Stg_Component_Initialise( timeIntegrandList[0], context, False );
+	Stg_Component_Initialise( timeIntegrandList[1], context, False );
+
+	for ( timestep = 0.0 ; timestep < maxTimesteps ; timestep ++ ) {
+		Journal_Printf( stream, "Step %u - Time = %.3g\n", timestep, context->currentTime );
+
+		Stg_Component_Execute( timeIntegrator, context, True );
+		context->currentTime += AbstractContext_Dt( context );
+
+		for ( integrand_I = 0 ; integrand_I < integrandCount ; integrand_I++ ) {
+			timeIntegrand	= timeIntegrandList[ integrand_I ];
+			variable			= variableList[ integrand_I ];
+			for ( array_I = 0 ; array_I < variable->arraySize ; array_I++ ) {
+				if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv ) {
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * context->currentTime );
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * context->currentTime );
+				}
+				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) {
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * context->currentTime );
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3 * array_I * context->currentTime );
+				}
+				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv ) {
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - array_I * context->currentTime * context->currentTime );
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + 0.5 * array_I * context->currentTime * context->currentTime );
+				}
+				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) {
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.25 * array_I * context->currentTime * context->currentTime );
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 1.5 * array_I * context->currentTime * context->currentTime );
+				}
+				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv ) {
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) - 2.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0));
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) + array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0));
+				}
+				else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) {
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 0 ) + 0.5 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0)/3.0));
+					error += fabs( Variable_GetValueAtDouble( variable, array_I, 1 ) - 3.0 * array_I * ( 0.25 * pow( context->currentTime, 4.0 ) - pow( context->currentTime, 3.0 )/3.0));
+				}
+				else
+					Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  ), "Don't understand _calculateTimeDeriv = %p\n", timeIntegrand->_calculateTimeDeriv );
+			}
+		}
+	}
+	pcu_check_lt( error, tolerance );
+
+	if ( error < tolerance )
+		Journal_Printf( stream, "Passed\n" );
+	else
+		Journal_Printf( stream, "Failed - Error = %lf\n", error );
+	
+	Journal_Enable_AllTypedStream( False );
+
+	if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv
+		|| timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_ConstantTimeDeriv2 ) {
+		pcu_filename_expected( "testTimeIntegrationEulerOutput.expected", expected_file );
+	}
+	else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv
+		|| timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_LinearTimeDeriv2 ) {
+		pcu_filename_expected( "testTimeIntegrationRK2Output.expected", expected_file );
+	}
+	else if ( timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv
+		|| timeIntegrand->_calculateTimeDeriv == TimeIntegrationSuite_CubicTimeDeriv2 ) {
+		pcu_filename_expected( "testTimeIntegrationRK4Output.expected", expected_file );
+	}
+
+	pcu_check_fileEq( _name, expected_file );
+
+	/* Destroy stuff */
+	Stream_CloseAndFreeFile( stream );
+	Memory_Free( array );
+	Memory_Free( array2 );
+	Stg_Class_Delete( variable );
+	_Stg_Component_Delete( timeIntegrator );
+	_Stg_Component_Delete( timeIntegrandList[0] );
+	_Stg_Component_Delete( timeIntegrandList[1] );
+	remove( _name );
+}
+	
+void TimeIntegrationSuite_TestEuler( TimeIntegrationSuiteData* data ) {
+	int procToWatch;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {	
+		TimeIntegrationSuite_TestDriver( data, "testIntegrationEuler", "Constant", "Constant2", 1 );
+	}
+}
+
+void TimeIntegrationSuite_TestRK2( TimeIntegrationSuiteData* data ) {
+	int procToWatch;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {	
+		TimeIntegrationSuite_TestDriver( data, "testIntegrationRK2", "Linear", "Linear2", 2 );
+	}
+}
+
+void TimeIntegrationSuite_TestRK4( TimeIntegrationSuiteData* data ) {
+	int procToWatch;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+	if( data->rank == procToWatch ) {	
+		TimeIntegrationSuite_TestDriver( data, "testIntegrationRK4", "Cubic", "Cubic2", 4 );
+	}
+}
+
+void TimeIntegrationSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, TimeIntegrationSuiteData );
+	pcu_suite_setFixtures( suite, TimeIntegrationSuite_Setup, TimeIntegrationSuite_Teardown );
+	pcu_suite_addTest( suite, TimeIntegrationSuite_TestEuler );
+	pcu_suite_addTest( suite, TimeIntegrationSuite_TestRK2 );
+	pcu_suite_addTest( suite, TimeIntegrationSuite_TestRK4 );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/WallVCSuite.c
--- a/Utils/tests/WallVCSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** Role:
-**   Tests the WallVCSuite
-**
-** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h> 
-#include "StgDomain/Geometry/Geometry.h"
-#include "StgDomain/Shape/Shape.h"
-#include "StgDomain/Mesh/Mesh.h" 
-#include "StgDomain/Utils/Utils.h"
-#include "StgDomain/Swarm/Swarm.h"
-
-#include "WallVCSuite.h"
-
-typedef struct {
-	MPI_Comm	comm;
-	int		rank;
-	int		nProcs;
-} WallVCSuiteData;
-
-void WallVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
-	*(double *)result = 20.0;
-}
-
-void WallVCSuite_exponential(Index index, Variable_Index var_I, void* context, void* result) {
-	*(double *)result = 30.0;
-}
-
-Mesh* WallVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
-	CartesianGenerator*	gen;
-	Mesh*						mesh;
-	unsigned					maxDecomp[3] = {0, 1, 1};
-
-	gen = CartesianGenerator_New( "", NULL );
-	gen->shadowDepth = 0;
-	CartesianGenerator_SetDimSize( gen, nDims );
-	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
-	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
-
-	mesh = Mesh_New( "", NULL );
-	Mesh_SetExtensionManagerRegister( mesh, emReg );
-	Mesh_SetGenerator( mesh, gen );
-
-	Stg_Component_Build( mesh, NULL, False );
-	Stg_Component_Initialise( mesh, NULL, False );
-
-   return mesh;
-}
-
-void WallVCSuite_Setup( WallVCSuiteData* data ) {
-	/* MPI Initializations */
-	data->comm = MPI_COMM_WORLD;
-	MPI_Comm_rank( data->comm, &data->rank );
-	MPI_Comm_size( data->comm, &data->nProcs );
-}
-
-void WallVCSuite_Teardown( WallVCSuiteData* data ) {
-}
-/* Prototype because I can not find the prototype in any headers. */
-Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
-
-void WallVCSuite_TestWallVC( WallVCSuiteData* data ) {
-	unsigned								nDomains;
-	unsigned								nDims = 3;
-	unsigned								meshSize[3] = {3, 3, 3};
-	int									procToWatch;
-	double								minCrds[3] = {0.0, 0.0, 0.0};
-	double								maxCrds[3] = {1.0, 1.0, 1.0};
-	char*									vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right",
-														"WallVC_Top", "WallVC_Bottom"};
-	char*   								vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName",
-														"WallVC_TopName", "WallVC_BottomName"};
-	char*									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
-	char									input_file[PCU_PATH_MAX];
-	char									expected_file[PCU_PATH_MAX];
-	Mesh*									mesh;
-	Variable_Register*				variable_Register;
-	ConditionFunction*				quadCF;
-	ConditionFunction*				expCF;
-	ConditionFunction_Register*	conFunc_Register;
-	ExtensionManager_Register*		extensionMgr_Register;
-	Dictionary*							dictionary;
-	Stream*								stream;
-	XML_IO_Handler*					io_handler;
-	Variable*							var[7];
-	double*								array[7];
-	VariableCondition*				vc; 
-	Index									i;
-
-	procToWatch = data->nProcs >=2 ? 1 : 0;
-
-   io_handler = XML_IO_Handler_New();
-
- 	stream = Journal_Register( Info_Type, (Name)"WallVCStream"  );
-   Stream_RedirectFile( stream, "testWallVC.dat" );
-
-   dictionary = Dictionary_New();
-   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
-
-	/* Input file */
-	pcu_filename_input( "wallVC.xml", input_file );
-   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
-   fflush(stdout);
-
-   extensionMgr_Register = ExtensionManager_Register_New(); 
-
-	/* Create a mesh. */
-	mesh = (Mesh*) WallVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
-   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
-
-	/* Create CF stuff */
-	quadCF = ConditionFunction_New( WallVCSuite_quadratic, (Name)"quadratic" );
-	expCF = ConditionFunction_New( WallVCSuite_exponential, (Name)"exponential");
-	conFunc_Register = ConditionFunction_Register_New( );
-	ConditionFunction_Register_Add(conFunc_Register, quadCF);
-	ConditionFunction_Register_Add(conFunc_Register, expCF);
-
-	/* Create variable register */
-   variable_Register = Variable_Register_New();
-
-	/* Create variables */
-	for (i = 0; i < 6; i++) {
-		array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
-		var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
-		Variable_Register_Add(variable_Register, var[i]);
-	}
-	array[6] = Memory_Alloc_Array( double, nDomains * 5, "array[6]" );
-	var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
-	Variable_Register_Add(variable_Register, var[6]);
-	Variable_Register_BuildAll(variable_Register);
-
-	for (i = 0; i < 6; i++) {
-		Index j, k;
-
-		vc = (VariableCondition*) WallVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
-		Stg_Component_Build( vc, 0, False );
-
-		for (j = 0; j < 6; j++)
-			memset(array[j], 0, sizeof(double)* nDomains );
-		memset(array[6], 0, sizeof(double)* nDomains * 5);
-		VariableCondition_Apply(vc, NULL);
-
-		if (data->rank == procToWatch) {
-			Journal_Printf( stream,"Testing for %s\n", vcKey[i]);
-			for (j = 0; j < 6; j++) {
-				Journal_Printf( stream,"\nvar[%u]: %.2lf", j, array[j][0]);
-				for (k = 1; k < nDomains; k++)
-					Journal_Printf( stream,", %.2lf", array[j][k]);
-			}
-
-			Journal_Printf( stream,"\nvar[6]: %.2lf", array[6][0]);
-			for (j = 1; j < nDomains*5; j++)
-				Journal_Printf( stream,", %.2lf", array[6][j]);
-			Journal_Printf( stream,"\n\n");
-
-			for (j = 0; j < 7; j++) {
-				for (k = 0; k < nDomains; k++)
-					Journal_Printf( stream,"%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
-				Journal_Printf( stream,"\n");
-			} Journal_Printf( stream,"\n");
-
-			for (j = 0; j < 7; j++) {
-				for (k = 0; k < nDomains; k++) {
-					VariableCondition_ValueIndex  valIndex;
-					valIndex = VariableCondition_GetValueIndex(vc, k, j);
-					if (valIndex != (unsigned)-1)
-						Journal_Printf( stream,"%03u ", valIndex);
-					else
-						Journal_Printf( stream,"XXX ");
-				} Journal_Printf( stream,"\n");
-			} Journal_Printf( stream,"\n");
-		}
-		Stg_Class_Delete(vc);
-	}
-
-	if (data->rank == procToWatch) {
-		pcu_filename_expected( "testWallVC.expected", expected_file );
-		pcu_check_fileEq( "testWallVC.dat", expected_file );
-		remove( "testWallVC.dat" );
-	}
-
-	Stg_Class_Delete(variable_Register);
-	for (i = 0; i < 7; i++) {
-		Stg_Class_Delete(var[i]);
-		if (array[i]) Memory_Free(array[i]);
-	}
-	Stg_Class_Delete(extensionMgr_Register);
-	Stg_Class_Delete(io_handler);
-	Stg_Class_Delete(conFunc_Register);
-	Stg_Class_Delete(quadCF);
-	Stg_Class_Delete(expCF);
-	Stg_Class_Delete(dictionary);
-	FreeObject( mesh );
-}
-
-
-void WallVCSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, WallVCSuiteData );
-   pcu_suite_setFixtures( suite, WallVCSuite_Setup, WallVCSuite_Teardown );
-   pcu_suite_addTest( suite, WallVCSuite_TestWallVC );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 Utils/tests/WallVCSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/WallVCSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,235 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** Role:
+**   Tests the WallVCSuite
+**
+** $Id: testTemplate.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h> 
+#include "StgDomain/Geometry/Geometry.h"
+#include "StgDomain/Shape/Shape.h"
+#include "StgDomain/Mesh/Mesh.h" 
+#include "StgDomain/Utils/Utils.h"
+#include "StgDomain/Swarm/Swarm.h"
+
+#include "WallVCSuite.h"
+
+typedef struct {
+	MPI_Comm	comm;
+	int		rank;
+	int		nProcs;
+} WallVCSuiteData;
+
+void WallVCSuite_quadratic(Index index, Variable_Index var_I, void* context, void* result) {
+	*(double *)result = 20.0;
+}
+
+void WallVCSuite_exponential(Index index, Variable_Index var_I, void* context, void* result) {
+	*(double *)result = 30.0;
+}
+
+Mesh* WallVCSuite_buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg ) {
+	CartesianGenerator*	gen;
+	Mesh*						mesh;
+	unsigned					maxDecomp[3] = {0, 1, 1};
+
+	gen = CartesianGenerator_New( "", NULL );
+	gen->shadowDepth = 0;
+	CartesianGenerator_SetDimSize( gen, nDims );
+	CartesianGenerator_SetTopologyParams( gen, size, 0, NULL, maxDecomp );
+	CartesianGenerator_SetGeometryParams( gen, minCrds, maxCrds );
+
+	mesh = Mesh_New( "", NULL );
+	Mesh_SetExtensionManagerRegister( mesh, emReg );
+	Mesh_SetGenerator( mesh, gen );
+
+	Stg_Component_Build( mesh, NULL, False );
+	Stg_Component_Initialise( mesh, NULL, False );
+
+   return mesh;
+}
+
+void WallVCSuite_Setup( WallVCSuiteData* data ) {
+	/* MPI Initializations */
+	data->comm = MPI_COMM_WORLD;
+	MPI_Comm_rank( data->comm, &data->rank );
+	MPI_Comm_size( data->comm, &data->nProcs );
+}
+
+void WallVCSuite_Teardown( WallVCSuiteData* data ) {
+}
+/* Prototype because I can not find the prototype in any headers. */
+Mesh* buildMesh( unsigned nDims, unsigned* size, double* minCrds, double* maxCrds, ExtensionManager_Register* emReg );
+
+void WallVCSuite_TestWallVC( WallVCSuiteData* data ) {
+	unsigned								nDomains;
+	unsigned								nDims = 3;
+	unsigned								meshSize[3] = {3, 3, 3};
+	int									procToWatch;
+	double								minCrds[3] = {0.0, 0.0, 0.0};
+	double								maxCrds[3] = {1.0, 1.0, 1.0};
+	char*									vcKey[] = {"WallVC_Front", "WallVC_Back", "WallVC_Left", "WallVC_Right",
+														"WallVC_Top", "WallVC_Bottom"};
+	char*   								vcKeyName[] = {"WallVC_FrontName", "WallVC_BackName", "WallVC_LeftName", "WallVC_RightName",
+														"WallVC_TopName", "WallVC_BottomName"};
+	char*									varName[] = {"x", "y", "z", "vx", "vy", "vz", "temp"};
+	char									input_file[PCU_PATH_MAX];
+	char									expected_file[PCU_PATH_MAX];
+	Mesh*									mesh;
+	Variable_Register*				variable_Register;
+	ConditionFunction*				quadCF;
+	ConditionFunction*				expCF;
+	ConditionFunction_Register*	conFunc_Register;
+	ExtensionManager_Register*		extensionMgr_Register;
+	Dictionary*							dictionary;
+	Stream*								stream;
+	XML_IO_Handler*					io_handler;
+	Variable*							var[7];
+	double*								array[7];
+	VariableCondition*				vc; 
+	Index									i;
+
+	procToWatch = data->nProcs >=2 ? 1 : 0;
+
+   io_handler = XML_IO_Handler_New();
+
+ 	stream = Journal_Register( Info_Type, (Name)"WallVCStream"  );
+   Stream_RedirectFile( stream, "testWallVC.dat" );
+
+   dictionary = Dictionary_New();
+   Dictionary_Add( dictionary, (Dictionary_Entry_Key)"outputPath", Dictionary_Entry_Value_FromString("./output") );
+
+	/* Input file */
+	pcu_filename_input( "wallVC.xml", input_file );
+   IO_Handler_ReadAllFromFile(io_handler, input_file, dictionary);
+   fflush(stdout);
+
+   extensionMgr_Register = ExtensionManager_Register_New(); 
+
+	/* Create a mesh. */
+	mesh = (Mesh*) WallVCSuite_buildMesh( nDims, meshSize, minCrds, maxCrds, extensionMgr_Register );
+   nDomains = Mesh_GetDomainSize( mesh, MT_VERTEX );
+
+	/* Create CF stuff */
+	quadCF = ConditionFunction_New( WallVCSuite_quadratic, (Name)"quadratic" );
+	expCF = ConditionFunction_New( WallVCSuite_exponential, (Name)"exponential");
+	conFunc_Register = ConditionFunction_Register_New( );
+	ConditionFunction_Register_Add(conFunc_Register, quadCF);
+	ConditionFunction_Register_Add(conFunc_Register, expCF);
+
+	/* Create variable register */
+   variable_Register = Variable_Register_New();
+
+	/* Create variables */
+	for (i = 0; i < 6; i++) {
+		array[i] = Memory_Alloc_Array( double, nDomains, "array[i]" );
+		var[i] = Variable_NewScalar( varName[i], NULL, Variable_DataType_Double, (Index*)&nDomains, NULL, (void**)&array[i], 0  );
+		Variable_Register_Add(variable_Register, var[i]);
+	}
+	array[6] = Memory_Alloc_Array( double, nDomains * 5, "array[6]" );
+	var[6] = Variable_NewVector( varName[6], NULL, Variable_DataType_Double, 5, &nDomains, NULL, (void**)&array[6], 0 );
+	Variable_Register_Add(variable_Register, var[6]);
+	Variable_Register_BuildAll(variable_Register);
+
+	for (i = 0; i < 6; i++) {
+		Index j, k;
+
+		vc = (VariableCondition*) WallVC_New( vcKeyName[i], NULL, vcKey[i], variable_Register, conFunc_Register, dictionary, mesh );
+		Stg_Component_Build( vc, 0, False );
+
+		for (j = 0; j < 6; j++)
+			memset(array[j], 0, sizeof(double)* nDomains );
+		memset(array[6], 0, sizeof(double)* nDomains * 5);
+		VariableCondition_Apply(vc, NULL);
+
+		if (data->rank == procToWatch) {
+			Journal_Printf( stream,"Testing for %s\n", vcKey[i]);
+			for (j = 0; j < 6; j++) {
+				Journal_Printf( stream,"\nvar[%u]: %.2lf", j, array[j][0]);
+				for (k = 1; k < nDomains; k++)
+					Journal_Printf( stream,", %.2lf", array[j][k]);
+			}
+
+			Journal_Printf( stream,"\nvar[6]: %.2lf", array[6][0]);
+			for (j = 1; j < nDomains*5; j++)
+				Journal_Printf( stream,", %.2lf", array[6][j]);
+			Journal_Printf( stream,"\n\n");
+
+			for (j = 0; j < 7; j++) {
+				for (k = 0; k < nDomains; k++)
+					Journal_Printf( stream,"%s ", VariableCondition_IsCondition(vc, k, j) ? "True " : "False");
+				Journal_Printf( stream,"\n");
+			} Journal_Printf( stream,"\n");
+
+			for (j = 0; j < 7; j++) {
+				for (k = 0; k < nDomains; k++) {
+					VariableCondition_ValueIndex  valIndex;
+					valIndex = VariableCondition_GetValueIndex(vc, k, j);
+					if (valIndex != (unsigned)-1)
+						Journal_Printf( stream,"%03u ", valIndex);
+					else
+						Journal_Printf( stream,"XXX ");
+				} Journal_Printf( stream,"\n");
+			} Journal_Printf( stream,"\n");
+		}
+		Stg_Class_Delete(vc);
+	}
+
+	if (data->rank == procToWatch) {
+		pcu_filename_expected( "testWallVC.expected", expected_file );
+		pcu_check_fileEq( "testWallVC.dat", expected_file );
+		remove( "testWallVC.dat" );
+	}
+
+	Stg_Class_Delete(variable_Register);
+	for (i = 0; i < 7; i++) {
+		Stg_Class_Delete(var[i]);
+		if (array[i]) Memory_Free(array[i]);
+	}
+	Stg_Class_Delete(extensionMgr_Register);
+	Stg_Class_Delete(io_handler);
+	Stg_Class_Delete(conFunc_Register);
+	Stg_Class_Delete(quadCF);
+	Stg_Class_Delete(expCF);
+	Stg_Class_Delete(dictionary);
+	FreeObject( mesh );
+}
+
+
+void WallVCSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, WallVCSuiteData );
+   pcu_suite_setFixtures( suite, WallVCSuite_Setup, WallVCSuite_Teardown );
+   pcu_suite_addTest( suite, WallVCSuite_TestWallVC );
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/Toolbox/Toolbox.c
--- a/libStgDomain/Toolbox/Toolbox.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-**
-** Primary Contributing Organisations:
-**	Victorian Partnership for Advanced Computing Ltd, Computational Software Development - http://csd.vpac.org
-**	Australian Computational Earth Systems Simulator - http://www.access.edu.au
-**	Monash Cluster Computing - http://www.mcc.monash.edu.au
-**	Computational Infrastructure for Geodynamics - http://www.geodynamics.org
-**
-** Contributors:
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Louis Moresi, Associate Professor, Monash University. (louis.moresi at sci.monash.edu.au)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Kent Humphries, Software Engineer, VPAC. (kenth at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: StandardConditionFunctions.c 532 2006-04-04 00:21:59Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include "Toolbox.h"
-
-
-
-const Type StgDomain_Toolbox_Type = "StgDomain_Toolbox";
-
-void _StgDomain_Toolbox_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )  {
-}
-
-
-void* _StgDomain_Toolbox_DefaultNew( Name name ) {
-	return Codelet_New(
-			StgDomain_Toolbox_Type,
-			_StgDomain_Toolbox_DefaultNew,
-			_StgDomain_Toolbox_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-void StgDomain_Toolbox_Initialise( PluginsManager* pluginsManager, int* argc, char*** argv ) {
-	StgDomain_Init( argc, argv );
-}
-
-void StgDomain_Toolbox_Finalise( PluginsManager* pluginsManager ) {
-	StgDomain_Finalise();
-	
-	Journal_RPrintf( Journal_Register( DebugStream_Type, (Name)StgDomain_Toolbox_Type  ), "Finalised: StGermain Domain Toolbox.\n" );
-}
-
-Index StgDomain_Toolbox_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, StgDomain_Toolbox_Type, (Name)"0", _StgDomain_Toolbox_DefaultNew  );
-}
-
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/Toolbox/Toolbox.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libStgDomain/Toolbox/Toolbox.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,83 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+**
+** Primary Contributing Organisations:
+**	Victorian Partnership for Advanced Computing Ltd, Computational Software Development - http://csd.vpac.org
+**	Australian Computational Earth Systems Simulator - http://www.access.edu.au
+**	Monash Cluster Computing - http://www.mcc.monash.edu.au
+**	Computational Infrastructure for Geodynamics - http://www.geodynamics.org
+**
+** Contributors:
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Louis Moresi, Associate Professor, Monash University. (louis.moresi at sci.monash.edu.au)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Kent Humphries, Software Engineer, VPAC. (kenth at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: StandardConditionFunctions.c 532 2006-04-04 00:21:59Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include "Toolbox.h"
+
+
+
+const Type StgDomain_Toolbox_Type = "StgDomain_Toolbox";
+
+void _StgDomain_Toolbox_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )  {
+}
+
+
+void* _StgDomain_Toolbox_DefaultNew( Name name ) {
+	return Codelet_New(
+			StgDomain_Toolbox_Type,
+			_StgDomain_Toolbox_DefaultNew,
+			_StgDomain_Toolbox_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+void StgDomain_Toolbox_Initialise( PluginsManager* pluginsManager, int* argc, char*** argv ) {
+	StgDomain_Init( argc, argv );
+}
+
+void StgDomain_Toolbox_Finalise( PluginsManager* pluginsManager ) {
+	StgDomain_Finalise();
+	
+	Journal_RPrintf( Journal_Register( DebugStream_Type, (Name)StgDomain_Toolbox_Type  ), "Finalised: StGermain Domain Toolbox.\n" );
+}
+
+Index StgDomain_Toolbox_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, StgDomain_Toolbox_Type, (Name)"0", _StgDomain_Toolbox_DefaultNew  );
+}
+
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/src/Finalise.c
--- a/libStgDomain/src/Finalise.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include <StgDomain/Swarm/Swarm.h>
-
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool StgDomain_Finalise( void ) {
-	if( ToolboxesManager_IsInitialised( stgToolboxesManager, "StgDomain" ) ) {
-		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-		
-		StgDomainSwarm_Finalise();
-		StgDomainUtils_Finalise();
-		StgDomainMesh_Finalise();
-		StgDomainShape_Finalise();
-		StgDomainGeometry_Finalise();
-		return True;
-	} else { 
-		return False;
-	}
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libStgDomain/src/Finalise.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,59 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Finalise.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include <StgDomain/Swarm/Swarm.h>
+
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool StgDomain_Finalise( void ) {
+	if( ToolboxesManager_IsInitialised( stgToolboxesManager, "StgDomain" ) ) {
+		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+		
+		StgDomainSwarm_Finalise();
+		StgDomainUtils_Finalise();
+		StgDomainMesh_Finalise();
+		StgDomainShape_Finalise();
+		StgDomainGeometry_Finalise();
+		return True;
+	} else { 
+		return False;
+	}
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/src/Init.c
--- a/libStgDomain/src/Init.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
-**
-** Authors:
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
-**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
-**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  License along with this library; if not, write to the Free Software
-**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-**
-** $Id: Init.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-
-#include <StgDomain/Geometry/Geometry.h>
-#include <StgDomain/Shape/Shape.h>
-#include <StgDomain/Mesh/Mesh.h>
-#include <StgDomain/Utils/Utils.h>
-#include <StgDomain/Swarm/Swarm.h>
-
-#include "Init.h"
-
-#include <stdio.h>
-
-Bool StgDomain_Init( int* argc, char** argv[] ) {
-	/* This init function tells StGermain of all the component types, etc this module contributes. Because it can be linked at compile
-	   time or linked in by a toolbox at runtime, we need to make sure it isn't run twice (compiled in and loaded through a toolbox.*/
-	if( !ToolboxesManager_IsInitialised( stgToolboxesManager, "StgDomain" ) ) {
-		int tmp;
-	
-		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-		tmp = Stream_GetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context" )  );
-		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), 0 );
-		Journal_Printf( /* DO NOT CHANGE OR REMOVE */
-			Journal_Register( InfoStream_Type, (Name)"Context"  ), 
-			"StGermain Domain Library revision %s. Copyright (C) 2003-2007 VPAC.\n", VERSION );
-		Stream_Flush( Journal_Register( InfoStream_Type, (Name)"Context" )  );
-		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), tmp );
-	
-		StgDomainGeometry_Init( argc, argv );
-		StgDomainShape_Init( argc, argv );
-		StgDomainMesh_Init( argc, argv );
-		StgDomainUtils_Init( argc, argv );
-		StgDomainSwarm_Init( argc, argv );
-
-		return True;
-	}
-	return False;
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libStgDomain/src/Init.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,70 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Init.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+
+#include <StgDomain/Geometry/Geometry.h>
+#include <StgDomain/Shape/Shape.h>
+#include <StgDomain/Mesh/Mesh.h>
+#include <StgDomain/Utils/Utils.h>
+#include <StgDomain/Swarm/Swarm.h>
+
+#include "Init.h"
+
+#include <stdio.h>
+
+Bool StgDomain_Init( int* argc, char** argv[] ) {
+	/* This init function tells StGermain of all the component types, etc this module contributes. Because it can be linked at compile
+	   time or linked in by a toolbox at runtime, we need to make sure it isn't run twice (compiled in and loaded through a toolbox.*/
+	if( !ToolboxesManager_IsInitialised( stgToolboxesManager, "StgDomain" ) ) {
+		int tmp;
+	
+		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+		tmp = Stream_GetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context" )  );
+		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), 0 );
+		Journal_Printf( /* DO NOT CHANGE OR REMOVE */
+			Journal_Register( InfoStream_Type, (Name)"Context"  ), 
+			"StGermain Domain Library revision %s. Copyright (C) 2003-2007 VPAC.\n", VERSION );
+		Stream_Flush( Journal_Register( InfoStream_Type, (Name)"Context" )  );
+		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), tmp );
+	
+		StgDomainGeometry_Init( argc, argv );
+		StgDomainShape_Init( argc, argv );
+		StgDomainMesh_Init( argc, argv );
+		StgDomainUtils_Init( argc, argv );
+		StgDomainSwarm_Init( argc, argv );
+
+		return True;
+	}
+	return False;
+}
+
+
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/tests/LibDiscretisationSuite.c
--- a/libStgDomain/tests/LibDiscretisationSuite.c	Wed May 11 13:27:02 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#include <mpi.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include "StgDomain/StgDomain.h"
-
-#include "LibDiscretisationSuite.h"
-
-typedef struct {
-} LibDiscretisationSuiteData;
-
-void LibDiscretisationSuite_Setup( LibDiscretisationSuiteData* data ) {
-}
-
-void LibDiscretisationSuite_Teardown( LibDiscretisationSuiteData* data ) {
-}
-
-void LibDiscretisationSuite_DirectoryStGermain( LibDiscretisationSuiteData* data ) {
-	Stg_Object* testDirectoryStGermain;
-
-	testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain" );
-	pcu_check_true( testDirectoryStGermain != NULL );
-}
-
-void LibDiscretisationSuite_DirectoryDiscretisation( LibDiscretisationSuiteData * data  ) {
-	Stg_Object* testDirectoryStGermain;
-	Stg_Object* testDirectoryDiscretisation;
-
-	testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain"  );
-	testDirectoryDiscretisation = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StgDomain" );
-
-	pcu_check_true( ( strcmp((char* )LIB_DIR, (char*)testDirectoryStGermain) ) || ( testDirectoryDiscretisation != NULL ) );
-}
-
-void LibDiscretisationSuite( pcu_suite_t* suite ) {
-	pcu_suite_setData( suite, LibDiscretisationSuiteData );
-	pcu_suite_setFixtures( suite, LibDiscretisationSuite_Setup, LibDiscretisationSuite_Teardown);
-
-	pcu_suite_addTest( suite, LibDiscretisationSuite_DirectoryStGermain );
-	pcu_suite_addTest( suite, LibDiscretisationSuite_DirectoryDiscretisation );
-}
-
-
diff -r fecc51eb5f13 -r 5f446b6d9117 libStgDomain/tests/LibDiscretisationSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libStgDomain/tests/LibDiscretisationSuite.cxx	Thu May 12 11:18:48 2011 -0700
@@ -0,0 +1,47 @@
+#include <mpi.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include "StgDomain/StgDomain.h"
+
+#include "LibDiscretisationSuite.h"
+
+typedef struct {
+} LibDiscretisationSuiteData;
+
+void LibDiscretisationSuite_Setup( LibDiscretisationSuiteData* data ) {
+}
+
+void LibDiscretisationSuite_Teardown( LibDiscretisationSuiteData* data ) {
+}
+
+void LibDiscretisationSuite_DirectoryStGermain( LibDiscretisationSuiteData* data ) {
+	Stg_Object* testDirectoryStGermain;
+
+	testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain" );
+	pcu_check_true( testDirectoryStGermain != NULL );
+}
+
+void LibDiscretisationSuite_DirectoryDiscretisation( LibDiscretisationSuiteData * data  ) {
+	Stg_Object* testDirectoryStGermain;
+	Stg_Object* testDirectoryDiscretisation;
+
+	testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain"  );
+	testDirectoryDiscretisation = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StgDomain" );
+
+	pcu_check_true( ( strcmp((char* )LIB_DIR, (char*)testDirectoryStGermain) ) || ( testDirectoryDiscretisation != NULL ) );
+}
+
+void LibDiscretisationSuite( pcu_suite_t* suite ) {
+	pcu_suite_setData( suite, LibDiscretisationSuiteData );
+	pcu_suite_setFixtures( suite, LibDiscretisationSuite_Setup, LibDiscretisationSuite_Teardown);
+
+	pcu_suite_addTest( suite, LibDiscretisationSuite_DirectoryStGermain );
+	pcu_suite_addTest( suite, LibDiscretisationSuite_DirectoryDiscretisation );
+}
+
+



More information about the CIG-COMMITS mailing list