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

Mercurial hg at geodynamics.org
Thu May 12 11:23:51 PDT 2011


changeset:   418:285af3102548
tag:         tip
user:        Walter Landry <wlandry at caltech.edu>
date:        Thu May 12 11:18:04 2011 -0700
files:       Apps/RayleighTaylor/tests/AnalyticBlock/AnalyticBlock.c Apps/RayleighTaylor/tests/AnalyticBlock/AnalyticBlock.cxx Apps/RayleighTaylor/tests/AnalyticColumn/AnalyticColumn.c Apps/RayleighTaylor/tests/AnalyticColumn/AnalyticColumn.cxx MaterialPoints/src/BackgroundParticleLayout.c MaterialPoints/src/BackgroundParticleLayout.cxx MaterialPoints/src/CoincidentMapper.c MaterialPoints/src/CoincidentMapper.cxx MaterialPoints/src/Finalise.c MaterialPoints/src/Finalise.cxx MaterialPoints/src/GaussCoincidentMapper.c MaterialPoints/src/GaussCoincidentMapper.cxx MaterialPoints/src/GaussMapper.c MaterialPoints/src/GaussMapper.cxx MaterialPoints/src/Init.c MaterialPoints/src/Init.cxx MaterialPoints/src/IntegrationPointMapper.c MaterialPoints/src/IntegrationPointMapper.cxx MaterialPoints/src/IntegrationPointsSwarm.c MaterialPoints/src/IntegrationPointsSwarm.cxx MaterialPoints/src/ManyToOneMapper.c MaterialPoints/src/ManyToOneMapper.cxx MaterialPoints/src/MappedParticleLayout.c MaterialPoints/src/MappedParticleLayout.cxx MaterialPoints/src/Material.c MaterialPoints/src/Material.cxx MaterialPoints/src/MaterialFeVariable.c MaterialPoints/src/MaterialFeVariable.cxx MaterialPoints/src/MaterialPoint.c MaterialPoints/src/MaterialPoint.cxx MaterialPoints/src/MaterialPointsSwarm.c MaterialPoints/src/MaterialPointsSwarm.cxx MaterialPoints/src/Materials_Register.c MaterialPoints/src/Materials_Register.cxx MaterialPoints/src/OneToManyMapper.c MaterialPoints/src/OneToManyMapper.cxx MaterialPoints/src/OneToOneMapper.c MaterialPoints/src/OneToOneMapper.cxx MaterialPoints/src/PICelleratorContext.c MaterialPoints/src/PICelleratorContext.cxx MaterialPoints/src/ParticleFeVariable.c MaterialPoints/src/ParticleFeVariable.cxx MaterialPoints/src/PeriodicBoundariesManager.c MaterialPoints/src/PeriodicBoundariesManager.cxx MaterialPoints/src/SwarmAdvectionInAPlane.c MaterialPoints/src/SwarmAdvectionInAPlane.cxx MaterialPoints/src/SwarmAdvector.c MaterialPoints/src/SwarmAdvector.cxx MaterialPoints/src/SwarmVariableField.c MaterialPoints/src/SwarmVariableField.cxx MaterialPoints/tests/AdvectionSuite.c MaterialPoints/tests/AdvectionSuite.cxx MaterialPoints/tests/MaterialComponentsSuite.c MaterialPoints/tests/MaterialComponentsSuite.cxx MaterialPoints/tests/MaterialFeVariableSuite.c MaterialPoints/tests/MaterialFeVariableSuite.cxx MaterialPoints/tests/PeriodicBoundariesManagerSuite.c MaterialPoints/tests/PeriodicBoundariesManagerSuite.cxx PopulationControl/src/EscapedRoutine.c PopulationControl/src/EscapedRoutine.cxx PopulationControl/src/Finalise.c PopulationControl/src/Finalise.cxx PopulationControl/src/Init.c PopulationControl/src/Init.cxx PopulationControl/tests/EscapedRoutineSuite.c PopulationControl/tests/EscapedRoutineSuite.cxx SConscript SysTest/AnalyticPlugins/AnalyticPressure/AnalyticPressure.c SysTest/AnalyticPlugins/AnalyticPressure/AnalyticPressure.cxx Utils/src/BuoyancyForceTerm.c Utils/src/BuoyancyForceTerm.cxx Utils/src/BuoyancyForceTermThermoChem.c Utils/src/BuoyancyForceTermThermoChem.cxx Utils/src/DiffusionSMT.c Utils/src/DiffusionSMT.cxx Utils/src/Finalise.c Utils/src/Finalise.cxx Utils/src/HydrostaticTerm.c Utils/src/HydrostaticTerm.cxx Utils/src/Init.c Utils/src/Init.cxx Utils/src/MaterialSwarmVariable.c Utils/src/MaterialSwarmVariable.cxx Utils/src/PCDVC.c Utils/src/PCDVC.cxx Utils/tests/PCDVCSuite.c Utils/tests/PCDVCSuite.cxx Weights/src/ConstantWeights.c Weights/src/ConstantWeights.cxx Weights/src/DVCWeights.c Weights/src/DVCWeights.cxx Weights/src/Finalise.c Weights/src/Finalise.cxx Weights/src/Init.c Weights/src/Init.cxx Weights/src/IterativeWeights.c Weights/src/IterativeWeights.cxx Weights/src/MomentBalanceWeights.c Weights/src/MomentBalanceWeights.cxx Weights/src/VolumeWeights.c Weights/src/VolumeWeights.cxx Weights/src/WeightsCalculator.c Weights/src/WeightsCalculator.cxx Weights/tests/ConstantWeightsSuite.c Weights/tests/ConstantWeightsSuite.cxx Weights/tests/DVCWeightsSuite.c Weights/tests/DVCWeightsSuite.cxx Weights/tests/IterativeWeightsSuite.c Weights/tests/IterativeWeightsSuite.cxx Weights/tests/MomentBalanceWeightsSuite.c Weights/tests/MomentBalanceWeightsSuite.cxx libPICellerator/Toolbox/Toolbox.c libPICellerator/Toolbox/Toolbox.cxx libPICellerator/src/Finalise.c libPICellerator/src/Finalise.cxx libPICellerator/src/Init.c libPICellerator/src/Init.cxx libPICellerator/tests/LibPICelleratorSuite.c libPICellerator/tests/LibPICelleratorSuite.cxx plugins/CalculateParticleDisplacement/CalculateParticleDisplacement.c plugins/CalculateParticleDisplacement/CalculateParticleDisplacement.cxx plugins/Output/MaterialCentroid/MaterialCentroid.c plugins/Output/MaterialCentroid/MaterialCentroid.cxx
description:
Rename .c -> .cxx and make configure automatically use c++


diff -r 420e7ed7a877 -r 285af3102548 Apps/RayleighTaylor/tests/AnalyticBlock/AnalyticBlock.c
--- a/Apps/RayleighTaylor/tests/AnalyticBlock/AnalyticBlock.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1775 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: AnalyticBlock.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#define MAX_FOURIER_TERMS 45
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include <assert.h>
-
-const Type AnalyticBlock_Type = "AnalyticBlock";
-
-typedef struct {
-	__AnalyticSolution
-	FeVariable* velocityField;
-	FeVariable* pressureField;
-	double startBlockX;
-	double endBlockX;
-	double startBlockY;
-} AnalyticBlock;
-
-void _AnalyticBlock_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	AnalyticBlock*          self           = (AnalyticBlock*)analyticSolution;
-	double                  n;
-	double                  x, y;
-	double                  viscosity      = 1.0;
-	double                  deltaRho       = 1.0;
-	double                  startBlockX    = self->startBlockX;
-	double                  endBlockX      = self->endBlockX;
-	double                  startBlockY    = self->startBlockY;
-	double                  x0;
-	double                  dx;
-	double                  u1, u2;
-	double                  u1a, u1b;
-	double                  u2a, u2b;
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t44,t45,t46,t47,t48,t49,t50,t52,t53,t54,t55,t56,t57,t58,t59,t60,t61,t62,t63,t64,t65,t66,t67,t68,t69,t70,t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
-	double t81,t82,t83,t84,t85,t86,t87,t88,t90,t91,t92,t93,t95,t96,t97,t98,t99,t100,t101,t104,t105,t106,t107,t108,t109,t110,t111,t112,t113,t115,t116,t117,t118,t119,t120;
-	double t121,t122,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t135,t136,t137,t138,t140,t141,t142,t143,t144,t145,t146,t149,t150,t151,t153,t154,t155,t156,t157,t158,t159,t160;
-	double t161,t162,t163,t165,t166,t167,t168,t169,t170,t171,t172,t173,t175,t176,t177,t178,t179,t180,t181,t182,t183,t185,t186,t187,t188,t189,t190,t191,t192,t193,t194,t195,t197,t198,t199;
-	double t202,t203,t204,t206,t207,t208,t209,t210,t211,t212,t213,t214,t215,t216,t217,t218,t220,t221,t224,t225,t226,t227,t229,t230,t232,t233,t235,t236,t238,t239,t240;
-	double t241,t243,t244,t247,t248,t249,t250,t251,t252,t253,t254,t255,t256,t258,t259,t260,t262,t263,t264,t265,t266,t268,t270,t271,t272,t273,t275,t276,t279,t280;
-	double t281,t282,t283,t284,t285,t286,t287,t288,t290,t291,t293,t294,t295,t296,t297,t298,t299,t300,t301,t303,t304,t305,t307,t308,t309,t310,t313,t314,t316,t317,t319;
-	double t321,t322,t323,t326,t327,t328,t330,t333,t334,t335,t337,t338,t339,t341,t342,t343,t344,t346,t347,t348,t349,t351,t353,t355,t357,t360;
-	double t364,t365,t370,t371,t372,t373,t374,t379,t383,t384,t387,t388,t390,t394,t395,t396;
-	double t401,t402,t403,t404,t406,t408,t409,t410,t411,t413,t414,t416,t421,t424,t425,t429,t430,t431,t435;
-	double t441,t444,t446,t447,t449,t450,t453,t455,t459,t460,t462,t463,t464,t465,t467,t469,t471,t474,t479;
-	double t481,t483,t484,t485,t490,t491,t492,t494,t496,t501,t507,t512,t518,t519;
-	double t521,t522,t526,t535,t540,t542,t550,t557,t559;
-	double t567,t569,t572,t577,t582,t587,t594,t598,t600;
-	double t609,t610,t611,t613,t614,t615,t616,t618,t623,t628,t631,t634,t636,t637,t639,t640;
-	double t641,t642,t645,t650,t654,t658,t659,t661,t670,t673;
-	double t682,t685,t688,t701,t702,t705,t713,t716,t717,t719;
-	double t721,t726,t728,t731,t734,t735,t740,t742,t744,t745,t747,t749,t753,t757;
-	double t761,t771,t773,t779,t786;
-	double t801,t803,t812,t813,t827,t830;
-	double t853,t854,t863;
-	double t883,t886,t892,t899,t907,t910,t917,t920;
-	double t936,t947,t957;
-	double t969,t973,t974,t978,t982,t997;
-	double t1016;
-	double t1041,t1051,t1059,t1072;
-	double t1084,t1089,t1093,t1097;
-	
-	/* Find coordinate of node */
-	x = coord[ I_AXIS ];
-	y = coord[ J_AXIS ];
-
-	x0 = 0.0;
-	dx = endBlockX - startBlockX;
-
-	/* Initialise */
-	velocity[ I_AXIS ] = 0.0;
-	velocity[ J_AXIS ] = 0.0;
-
-	for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
-		t1 = n * M_PI;
-		t2 = 0.1e1 / cosh(t1);
-		t3 = startBlockY * n;
-		t4 = t3 * M_PI;
-		t5 = tanh(t4);
-		t6 = t2 * t5;
-		t7 = 0.1e1 / cosh(t4);
-		t8 = tanh(t1);
-		t9 = t8 * t7;
-		t13 = sin(t1 * dx);
-		t15 = y * n;
-		t16 = t15 * M_PI;
-		t17 = tanh(t16);
-		t18 = t17 * t17;
-		t19 = t18 * n;
-		t20 = M_PI * t2;
-		t21 = t20 * t8;
-		t24 = t18 * t2;
-		t25 = t8 * t5;
-		t26 = t24 * t25;
-		t29 = t2 * t2;
-		t30 = t29 * t2;
-		t32 = 0.1e1 / cosh(t16);
-		t33 = t32 * t32;
-		t35 = t33 * t8 * t7;
-		t38 = t33 * t2;
-		t39 = t38 * t5;
-		t41 = t18 * t30;
-		t42 = t41 * t5;
-		t45 = t17 * t8 * t7;
-		t47 = t38 * t8;
-		t52 = t24 * startBlockY;
-		t53 = t8 * t8;
-		t54 = t53 * t5;
-		t55 = t1 * t54;
-		t57 = M_PI * t33;
-		t60 = t53 * t8;
-		t62 = t18 * t60 * t7;
-		t64 = -0.4e1 * t19 * t21 + 0.2e1 * t16 * t26 + 0.2e1 * t30 - 0.3e1 * t16 * t35 + t16 * t39 - t16 * t42 + 0.12e2 * t45 + 0.2e1 * t16 * t47 - 0.2e1 * t33 * t7 + t52 * t55 - t15 * t57 * t30 - t16 * t62;
-		t65 = t38 * startBlockY;
-		t66 = t1 * t8;
-		t71 = t33 * t30;
-		t73 = t19 * M_PI;
-		t74 = startBlockY * t29;
-		t75 = t74 * t7;
-		t77 = t74 * t9;
-		t80 = t1 * t5;
-		t82 = t17 * t30;
-		t84 = M_PI * t18;
-		t90 = t33 * n;
-		t91 = t90 * M_PI;
-		t93 = t29 * t8 * t7;
-		t96 = t17 * n;
-		t98 = M_PI * t29 * t7;
-		t101 = -0.2e1 * t65 * t66 + 0.4e1 * t17 * t7 - 0.2e1 * t71 - t73 * t75 - t73 * t77 - 0.2e1 * t24 + t52 * t80 + 0.4e1 * t82 - t15 * t84 * t7 - t41 * startBlockY * t80 - 0.2e1 * t2 - 0.2e1 * t91 * t93 + 0.4e1 * t96 * t98;
-		t104 = t1 * t53;
-		t106 = t2 * t53;
-		t107 = t106 * t5;
-		t112 = t2 * t8;
-		t113 = t112 * t5;
-		t116 = t17 * t2;
-		t117 = t116 * t53;
-		t121 = t116 * t5;
-		t124 = t1 * t25;
-		t129 = t18 * startBlockY;
-		t130 = t1 * t7;
-		t132 = -0.2e1 * t6 - t65 * t104 - 0.2e1 * t73 * t107 + 0.4e1 * t90 * t21 - 0.4e1 * t73 * t113 - 0.4e1 * t117 + 0.4e1 * t47 - 0.6e1 * t35 + 0.2e1 * t16 * t121 + 0.2e1 * t52 * t124 + 0.2e1 * t19 * t98 + t129 * t130;
-		t133 = t24 * t5;
-		t137 = t20 * t53;
-		t140 = t17 * t29;
-		t141 = t140 * t9;
-		t143 = t38 * t53;
-		t146 = t18 * t53 * t7;
-		t150 = t20 * t5;
-		t153 = t140 * t7;
-		t158 = M_PI * t8;
-		t159 = t158 * t7;
-		t162 = t16 * t133 + 0.2e1 * t15 * t21 + 0.2e1 * t90 * t137 - 0.4e1 * t141 + t16 * t143 + 0.6e1 * t146 + 0.2e1 * t42 - 0.2e1 * t93 - 0.2e1 * t19 * t150 + 0.2e1 * t16 * t153 + 0.2e1 * t38 + t15 * t150 - 0.3e1 * t15 * t159;
-		t165 = t129 * n;
-		t167 = M_PI * t60 * t7;
-		t173 = t38 * t54;
-		t179 = M_PI * t53;
-		t180 = t179 * t7;
-		t183 = t24 * t8;
-		t187 = t33 * t29;
-		t188 = t187 * t9;
-		t190 = t17 * startBlockY;
-		t191 = t190 * n;
-		t195 = t165 * t167 + 0.2e1 * t73 * t93 + 0.2e1 * t16 * t117 + 0.2e1 * t173 + 0.3e1 * t165 * t159 - t15 * t84 * t30 + 0.3e1 * t165 * t180 + 0.2e1 * t16 * t183 + 0.2e1 * t7 + 0.2e1 * t188 + 0.2e1 * t191 * t167 + 0.2e1 * t39;
-		t197 = t33 * t60 * t7;
-		t199 = t187 * t7;
-		t204 = t33 * t53 * t7;
-		t207 = t33 * startBlockY;
-		t208 = t207 * n;
-		t213 = t116 * t8;
-		t216 = t24 * t53;
-		t221 = t17 * t60 * t7;
-		t224 = -0.2e1 * t197 + 0.2e1 * t199 - 0.2e1 * t19 * t137 - 0.3e1 * t16 * t204 - t208 * t167 - 0.3e1 * t208 * t159 + 0.6e1 * t9 + 0.4e1 * t16 * t213 + t16 * t216 - 0.4e1 * t121 - 0.4e1 * t153 + 0.4e1 * t221 + 0.2e1 * t41;
-		t227 = t71 * t5;
-		t238 = t17 * t53 * t7;
-		t240 = t82 * t5;
-		t247 = -0.8e1 * t213 - 0.2e1 * t227 - 0.6e1 * t204 + 0.6e1 * t191 * t159 + t16 * t188 - 0.6e1 * t16 * t45 + t15 * t84 * t2 + 0.12e2 * t238 + 0.4e1 * t240 - 0.2e1 * t65 * t124 - t65 * t55 - 0.3e1 * t208 * t180;
-		t248 = t96 * M_PI;
-		t254 = M_PI * t17;
-		t262 = t116 * startBlockY;
-		t266 = t38 * t25;
-		t271 = t29 * t7;
-		t275 = -0.4e1 * t248 * t107 - 0.2e1 * t106 + t91 * t75 - 0.4e1 * t112 + 0.2e1 * t15 * t254 * t2 - 0.8e1 * t248 * t113 + 0.6e1 * t191 * t180 + 0.2e1 * t262 * t55 + t16 * t173 + 0.2e1 * t16 * t266 + 0.2e1 * t90 * t20 - 0.2e1 * t271 + 0.2e1 * t262 * t80;
-		t283 = t18 * t29;
-		t284 = t283 * t9;
-		t293 = t2 * startBlockY;
-		t300 = -0.3e1 * t16 * t146 - 0.2e1 * t248 * t75 + t16 * t284 + 0.4e1 * t262 * t124 - t15 * t57 * t7 + t15 * t57 * t2 + t16 * t93 + 0.2e1 * t293 * t66 - t16 * t227 + t293 * t104 + t16 * t199 + t16 * t107;
-		t305 = t24 * t54;
-		t313 = t283 * t7;
-		t322 = -0.2e1 * t248 * t77 + 0.2e1 * t60 * t7 + t16 * t305 - 0.2e1 * t1 * t2 + 0.2e1 * t30 * t5 + t24 * t4 - 0.4e1 * t113 + t16 * t313 + 0.6e1 * t53 * t7 + t91 * t77 - t1 * t75 + 0.2e1 * t16 * t113 - t4 * t93;
-		t327 = M_PI * t30;
-		t335 = t30 * startBlockY;
-		t347 = 0.4e1 * t248 * t93 + t15 * t98 - t15 * t327 * t5 - 0.4e1 * t96 * t137 + 0.2e1 * t116 * t4 - t16 * t197 - t335 * t80 - 0.2e1 * t82 * startBlockY * t80 - 0.2e1 * t90 * t98 - t41 * t4 - 0.2e1 * t1 * t107 - 0.2e1 * t16 * t221;
-		t360 = t116 * t25;
-		t370 = 0.2e1 * t1 * t93 + t3 * t167 - 0.6e1 * t16 * t238 + 0.2e1 * t18 * t7 + t52 * t104 + 0.2e1 * t52 * t66 + 0.3e1 * t3 * t159 + 0.4e1 * t16 * t360 + 0.3e1 * t3 * t180 - t15 * t167 - 0.2e1 * t107 + 0.2e1 * t143 - 0.2e1 * t82 * t4;
-		t373 = t293 * n;
-		t384 = t18 * t8 * t7;
-		t395 = t373 * t179 * t5 - 0.4e1 * t1 * t113 + 0.2e1 * t16 * t141 + t293 * t80 - 0.4e1 * t183 - 0.2e1 * t216 + 0.6e1 * t384 + 0.2e1 * t373 * t158 * t5 - 0.3e1 * t15 * t180 + 0.2e1 * t262 * t104 - t65 * t80 - 0.2e1 * t133;
-		t408 = t116 * t54;
-		t414 = M_PI * t7;
-		t416 = -0.2e1 * t313 + 0.2e1 * t62 - t207 * t130 - 0.3e1 * t16 * t384 - 0.2e1 * t305 - 0.2e1 * t284 - 0.2e1 * t19 * t20 - 0.8e1 * t360 - 0.2e1 * t16 * t240 + 0.2e1 * t16 * t408 - 0.4e1 * t26 - 0.2e1 * t1 * t6 + t3 * t414;
-		t435 = -t335 * t1 + t293 * t1 - 0.2e1 * t1 * t106 - 0.4e1 * t1 * t112 + 0.2e1 * t1 * t271 + 0.2e1 * t190 * t130 - t15 * t327 + 0.4e1 * t266 - t15 * t414 - t38 * t4 - 0.4e1 * t408 - 0.4e1 * t96 * t20;
-		t460 = t15 * t20 - 0.2e1 * t15 * t254 * t30 + t71 * startBlockY * t80 + 0.2e1 * t90 * t150 - 0.2e1 * t15 * t254 * t7 - 0.8e1 * t96 * t21 + t15 * t137 - 0.4e1 * t96 * t150 + 0.2e1 * t91 * t107 + 0.4e1 * t262 * t66 + t71 * t4 + 0.4e1 * t91 * t113 - 0.4e1 * t116;
-		t471 = n * n;
-		t474 = M_PI * M_PI;
-		t479 = pow(t2 + 0.1e1 + t8, 0.2e1);
-		t483 = pow(t2 - 0.1e1 - t8, 0.2e1);
-
-		u1a = (t2 + t6 - t7 - t9) * deltaRho * t13 * (t64 + t101 + t132 + t162 + t195 + t224 + t247 + t275 + t300 + t322 + t347 + t370 + t395 + t416 + t435 + t460) / t7 / (0.1e1 + t5) / t471 / n / t474 / M_PI / t479 / t483 / t32 / viscosity / (0.1e1 + t17) / 0.2e1;
-
-		t1 = n * M_PI;
-		t3 = sin(t1 * dx);
-		t5 = y * n;
-		t6 = t5 * M_PI;
-		t7 = 0.1e1 / cosh(t6);
-		t8 = startBlockY * n;
-		t9 = t8 * M_PI;
-		t10 = 0.1e1 / cosh(t9);
-		t11 = t7 * t10;
-		t12 = tanh(t1);
-		t13 = t12 * t12;
-		t14 = t13 * t13;
-		t15 = tanh(t9);
-		t19 = tanh(t6);
-		t20 = t19 * t19;
-		t21 = t20 * startBlockY;
-		t22 = t21 * n;
-		t23 = M_PI * t12;
-		t24 = 0.1e1 / cosh(t1);
-		t25 = t24 * t24;
-		t26 = t15 * t25;
-		t27 = t23 * t26;
-		t30 = t20 * t24;
-		t31 = t12 * t10;
-		t32 = t31 * t15;
-		t35 = t7 * t7;
-		t36 = t15 * t15;
-		t37 = t35 * t36;
-		t38 = t25 * t13;
-		t39 = t37 * t38;
-		t41 = t25 * t12;
-		t42 = t37 * t41;
-		t44 = t25 * t24;
-		t45 = t19 * t44;
-		t46 = t45 * t31;
-		t48 = t19 * t24;
-		t49 = t10 * t15;
-		t50 = t48 * t49;
-		t52 = t35 * startBlockY;
-		t55 = t25 * t25;
-		t56 = t55 * t15;
-		t59 = t19 * t15;
-		t60 = t59 * t41;
-		t62 = t48 * t10;
-		t65 = t10 * t10;
-		t66 = t35 * t65;
-		t67 = t66 * t38;
-		t69 = t19 * t36;
-		t70 = t69 * t38;
-		t73 = t66 * t41;
-		t75 = -0.4e1 * t11 * t14 * t15 + 0.4e1 * t22 * t27 + 0.12e2 * t30 * t32 - 0.2e1 * t39 - 0.4e1 * t42 - 0.8e1 * t46 + 0.8e1 * t50 - t52 * t1 * t36 - 0.4e1 * t11 * t56 - 0.16e2 * t60 - 0.4e1 * t6 * t62 - 0.2e1 * t67 + 0.2e1 * t6 * t70 - 0.4e1 * t73;
-		t79 = t35 * t24;
-		t80 = t13 * t10;
-		t81 = t79 * t80;
-		t83 = t69 * t41;
-		t85 = t19 * n;
-		t86 = t85 * M_PI;
-		t87 = t24 * t12;
-		t88 = t87 * t49;
-		t91 = t52 * n;
-		t92 = M_PI * t65;
-		t93 = t92 * t25;
-		t95 = t20 * n;
-		t97 = M_PI * t44 * t10;
-		t100 = t35 * n;
-		t101 = t100 * M_PI;
-		t106 = t13 * t12;
-		t107 = t24 * t106;
-		t108 = t107 * t49;
-		t111 = t20 * t44;
-		t112 = t111 * t31;
-		t115 = t7 * t19;
-		t116 = t10 * t14;
-		t119 = t87 * t10;
-		t122 = t19 * t65;
-		t123 = t122 * t41;
-		t126 = 0.8e1 * t11 * t38 + 0.2e1 * t37 - 0.12e2 * t81 - 0.8e1 * t83 + 0.12e2 * t86 * t88 - t91 * t93 + 0.2e1 * t95 * t97 - 0.6e1 * t101 * t88 + 0.8e1 * t11 * t26 - 0.2e1 * t101 * t108 + 0.2e1 * t6 * t112 - 0.4e1 * t115 * t116 + 0.6e1 * t1 * t119 - 0.8e1 * t123 - 0.4e1 * t70;
-		t128 = t95 * M_PI;
-		t129 = t44 * t10;
-		t130 = t129 * t15;
-		t133 = t30 * t31;
-		t138 = t10 * t106;
-		t141 = M_PI * t35;
-		t142 = t5 * t141;
-		t143 = t24 * t13;
-		t144 = t143 * t49;
-		t150 = t35 * t15;
-		t151 = t150 * t41;
-		t154 = t69 * t25;
-		t157 = M_PI * t19;
-		t158 = t5 * t157;
-		t168 = t20 * t55;
-		t169 = t168 * t65;
-		t171 = 0.2e1 * t128 * t130 + 0.12e2 * t133 - 0.4e1 * t91 * t23 * t36 - 0.16e2 * t115 * t138 - 0.6e1 * t142 * t144 - 0.4e1 * t41 + 0.4e1 * t91 * t27 - 0.4e1 * t6 * t151 + 0.2e1 * t6 * t154 - 0.12e2 * t158 * t144 - 0.24e2 * t11 * t13 * t15 - 0.2e1 * t101 * t130 - 0.6e1 * t6 * t81 - t6 * t169;
-		t172 = t26 * t12;
-		t175 = M_PI * t13;
-		t176 = t175 * t25;
-		t178 = M_PI * t55;
-		t179 = t178 * t36;
-		t181 = t178 * t15;
-		t185 = t44 * t12;
-		t186 = t185 * t10;
-		t188 = t35 * t14;
-		t189 = t188 * t36;
-		t191 = t35 * t106;
-		t192 = t191 * t36;
-		t194 = t19 * t25;
-		t195 = t194 * t12;
-		t197 = t35 * t25;
-		t198 = t197 * t12;
-		t202 = M_PI * t36;
-		t203 = t202 * t25;
-		t211 = -0.16e2 * t86 * t172 + t91 * t176 - t8 * t179 - 0.2e1 * t8 * t181 - 0.4e1 * t130 - 0.4e1 * t186 + 0.2e1 * t189 + 0.8e1 * t192 - 0.8e1 * t195 - 0.4e1 * t198 - 0.2e1 * t101 * t186 + t91 * t203 + t5 * t141 * t36 - 0.6e1 * t6 * t119 + t5 * t141 * t65;
-		t214 = t35 * t13;
-		t215 = t214 * t65;
-		t226 = t19 * startBlockY;
-		t227 = t226 * n;
-		t230 = t20 * t25;
-		t232 = t20 * t36;
-		t233 = t232 * t41;
-		t235 = M_PI * t25;
-		t238 = t20 * t15;
-		t239 = t238 * t41;
-		t243 = t20 * t65;
-		t244 = t243 * t41;
-		t247 = t243 * t38;
-		t251 = t36 * t25;
-		t252 = t251 * t13;
-		t255 = 0.6e1 * t6 * t215 + 0.6e1 * t5 * t141 * t13 + 0.2e1 * t128 * t186 - 0.16e2 * t11 * t12 * t15 - 0.2e1 * t227 * t179 - 0.2e1 * t230 - 0.4e1 * t233 + 0.2e1 * t100 * t235 - 0.8e1 * t239 - 0.6e1 * t101 * t144 + 0.2e1 * t6 * t244 + t6 * t247 - 0.6e1 * t101 * t119 + 0.2e1 * t101 * t252;
-		t259 = t235 * t15;
-		t265 = t35 * t44;
-		t266 = t265 * t31;
-		t279 = t80 * t15;
-		t282 = t115 * t10;
-		t283 = t26 * t13;
-		t286 = t191 * t15;
-		t290 = -0.2e1 * t247 - 0.2e1 * t95 * t176 + 0.4e1 * t100 * t259 - 0.4e1 * t26 + 0.24e2 * t48 * t32 + 0.2e1 * t6 * t266 + 0.4e1 * t6 * t239 + 0.2e1 * t5 * t141 * t15 + 0.2e1 * t66 - 0.2e1 * t6 * t108 - 0.2e1 * t128 * t252 + 0.12e2 * t30 * t279 + 0.8e1 * t282 * t283 + 0.8e1 * t6 * t286 + t22 * t203;
-		t295 = M_PI * t24 * t10;
-		t299 = t168 * t36;
-		t303 = t24 * t10;
-		t308 = t185 * t49;
-		t310 = t303 * t15;
-		t313 = t48 * t138;
-		t316 = t202 * t41;
-		t319 = M_PI * t20;
-		t322 = t65 * t25;
-		t323 = t322 * t12;
-		t326 = t188 * t65;
-		t330 = 0.2e1 * t9 * t283 + 0.2e1 * t95 * t295 + 0.8e1 * t191 - t6 * t299 + 0.2e1 * t227 * t203 + 0.2e1 * t1 * t303 - 0.2e1 * t22 * t181 - 0.4e1 * t308 - 0.2e1 * t101 * t310 - 0.4e1 * t6 * t313 + 0.2e1 * t91 * t316 + t5 * t319 * t25 + 0.4e1 * t101 * t323 + t6 * t326 - 0.2e1 * t100 * t295;
-		t337 = t178 * t65;
-		t346 = t30 * t138;
-		t349 = t66 * t25;
-		t351 = t143 * t10;
-		t353 = t107 * t10;
-		t355 = t230 * t13;
-		t357 = t30 * t10;
-		t360 = -0.4e1 * t1 * t283 + 0.2e1 * t55 * t36 - 0.2e1 * t101 * t308 - t5 * t337 - 0.2e1 * t5 * t295 + 0.4e1 * t108 + 0.4e1 * t6 * t46 + 0.2e1 * t128 * t310 - 0.2e1 * t6 * t346 - t6 * t349 + 0.12e2 * t351 + 0.4e1 * t353 - 0.2e1 * t355 + 0.4e1 * t357 + 0.2e1 * t326;
-		t364 = t214 * t36;
-		t370 = t168 * t15;
-		t383 = t232 * t38;
-		t387 = 0.12e2 * t364 + 0.8e1 * t11 * t25 + 0.2e1 * t299 + 0.4e1 * t310 + 0.4e1 * t370 - 0.4e1 * t11 * t55 + 0.4e1 * t85 * t97 - 0.4e1 * t1 * t26 + 0.12e2 * t144 - 0.2e1 * t1 * t251 + 0.2e1 * t6 * t233 + t6 * t383 - t8 * t178 + 0.4e1 * t56;
-		t388 = t150 * t38;
-		t396 = t238 * t38;
-		t401 = t175 * t26;
-		t406 = t138 * t15;
-		t409 = M_PI * t106;
-		t413 = t122 * t25;
-		t421 = t92 * t41;
-		t424 = -0.2e1 * t6 * t388 - 0.4e1 * t11 + 0.8e1 * t227 * t27 + 0.2e1 * t1 * t129 + 0.2e1 * t6 * t396 - 0.4e1 * t128 * t283 + 0.2e1 * t22 * t401 + 0.2e1 * t100 * t176 + 0.4e1 * t30 * t406 + 0.4e1 * t91 * t409 * t65 + 0.2e1 * t6 * t413 - 0.2e1 * t25 + 0.2e1 * t6 * t323 - 0.4e1 * t85 * t93 - 0.2e1 * t22 * t421;
-		t431 = t322 * t13;
-		t435 = t10 * t25;
-		t446 = t79 * t49;
-		t459 = -0.12e2 * t91 * t175 * t15 + 0.2e1 * t6 * t130 + t6 * t431 - 0.24e2 * t115 * t80 + 0.16e2 * t115 * t435 * t12 - t5 * t319 * t55 - 0.4e1 * t115 * t116 * t15 - 0.16e2 * t115 * t406 - 0.2e1 * t6 * t446 - 0.4e1 * t91 * t409 * t36 - 0.2e1 * t6 * t357 - t8 * t93 - 0.2e1 * t142 * t108 + 0.4e1 * t85 * t295;
-		t462 = t111 * t10;
-		t465 = t232 * t25;
-		t469 = t30 * t49;
-		t474 = t265 * t10;
-		t481 = t188 * t15;
-		t484 = startBlockY * t25;
-		t485 = t484 * t12;
-		t490 = t92 * t38;
-		t492 = t202 * t38;
-		t494 = t243 * t25;
-		t496 = -0.2e1 * t6 * t73 + 0.2e1 * t6 * t462 + t6 * t465 + 0.4e1 * t101 * t283 - 0.2e1 * t6 * t469 - 0.12e2 * t158 * t88 + 0.2e1 * t6 * t474 - 0.16e2 * t115 * t32 + 0.2e1 * t6 * t308 + 0.2e1 * t6 * t481 + 0.2e1 * t1 * t485 + 0.16e2 * t282 * t172 - t91 * t490 + t91 * t492 + t6 * t494;
-		t507 = t79 * t31;
-		t521 = t235 * t12;
-		t526 = -0.2e1 * t101 * t353 - 0.8e1 * t85 * t259 - 0.2e1 * t5 * t181 - 0.2e1 * t1 * t322 - 0.6e1 * t6 * t507 + 0.12e2 * t88 - 0.4e1 * t227 * t421 + t5 * t235 + 0.16e2 * t11 * t41 - 0.24e2 * t115 * t279 - 0.6e1 * t6 * t133 + t8 * t203 + 0.4e1 * t100 * t521 - 0.4e1 * t79 * t406;
-		t535 = M_PI * t14;
-		t542 = t59 * t25;
-		t559 = 0.24e2 * t48 * t279 + 0.6e1 * t91 * t175 * t65 + 0.4e1 * t5 * t141 * t106 - 0.2e1 * t91 * t535 * t15 + 0.4e1 * t227 * t316 + t6 * t355 + 0.4e1 * t6 * t542 - 0.4e1 * t52 * t1 * t106 + 0.12e2 * t214 - 0.4e1 * t115 * t49 - 0.16e2 * t115 * t31 - 0.4e1 * t128 * t323 - t6 * t67 - 0.4e1 * t244 + 0.2e1 * t101 * t431;
-		t569 = t111 * t49;
-		t572 = t10 * t55;
-		t577 = t194 * t13;
-		t587 = t48 * t80;
-		t594 = -0.2e1 * t322 - 0.4e1 * t52 * t1 * t12 + 0.4e1 * t6 * t123 - 0.8e1 * t86 * t323 + 0.2e1 * t6 * t569 - 0.4e1 * t115 * t572 + 0.2e1 * t22 * t316 + 0.2e1 * t6 * t577 + 0.2e1 * t168 - 0.2e1 * t6 * t370 - 0.4e1 * t86 * t252 - 0.12e2 * t79 * t32 - 0.12e2 * t6 * t587 - 0.2e1 * t1 * t431 + 0.2e1 * t1 * t353;
-		t600 = t35 * t12;
-		t610 = t265 * t49;
-		t613 = t230 * t12;
-		t616 = t5 * t319;
-		t623 = 0.2e1 * t91 * t401 + 0.2e1 * t5 * t157 * t25 + 0.8e1 * t600 - 0.2e1 * t251 + t142 - 0.12e2 * t79 * t279 - 0.8e1 * t86 * t283 + 0.4e1 * t150 + 0.8e1 * t48 * t406 + 0.2e1 * t6 * t610 + 0.2e1 * t6 * t613 - 0.2e1 * t616 * t108 + 0.4e1 * t469 + t8 * t337 + 0.8e1 * t11 * t283;
-		t628 = t37 * t25;
-		t631 = t79 * t10;
-		t636 = t30 * t80;
-		t641 = t251 * t12;
-		t650 = t197 * t13;
-		t658 = -t6 * t628 + 0.4e1 * t346 - 0.2e1 * t6 * t631 + 0.2e1 * t55 * t65 + 0.12e2 * t636 - 0.2e1 * t5 * t157 * t55 - 0.4e1 * t1 * t641 - 0.2e1 * t95 * t203 - 0.8e1 * t45 * t32 - 0.6e1 * t142 * t88 - t6 * t650 - 0.8e1 * t1 * t172 + 0.2e1 * t227 * t337 + 0.16e2 * t11 * t172;
-		t659 = t122 * t38;
-		t661 = t59 * t38;
-		t670 = t238 * t25;
-		t685 = -0.4e1 * t659 - 0.8e1 * t661 - 0.2e1 * t128 * t431 - t52 * t1 * t14 + t22 * t176 - 0.4e1 * t111 * t32 + 0.2e1 * t6 * t670 - t9 * t431 + 0.24e2 * t587 - 0.4e1 * t396 + 0.4e1 * t265 * t32 + 0.4e1 * t86 * t485 + 0.2e1 * t100 * t93 + 0.2e1 * t128 * t308 - t5 * t178;
-		t688 = M_PI * startBlockY * t25;
-		t701 = t45 * t49;
-		t713 = t1 * t24;
-		t716 = t95 * t688 - 0.8e1 * t91 * t23 * t15 + t5 * t141 * t14 - 0.2e1 * t383 - 0.4e1 * t6 * t50 + 0.4e1 * t266 - 0.8e1 * t85 * t521 - 0.8e1 * t701 + 0.2e1 * t128 * t353 - 0.8e1 * t86 * t641 + 0.4e1 * t86 * t108 - 0.2e1 * t9 * t323 + t52 * t1 * t65 + 0.2e1 * t713 * t406;
-		t717 = t1 * t55;
-		t721 = t150 * t25;
-		t745 = -t21 * t717 + 0.8e1 * t6 * t60 - 0.2e1 * t6 * t721 + 0.4e1 * t101 * t641 - 0.6e1 * t91 * t175 * t36 + 0.2e1 * t1 * t130 + 0.2e1 * t9 * t641 - 0.8e1 * t151 + 0.4e1 * t610 + 0.4e1 * t6 * t192 + t8 * t176 + 0.8e1 * t115 * t435 + 0.2e1 * t227 * t176 + 0.2e1 * t616 * t308 + t5 * t203;
-		t749 = t214 * t15;
-		t757 = t45 * t10;
-		t773 = -0.4e1 * t388 + 0.12e2 * t6 * t749 + 0.12e2 * t86 * t119 + 0.6e1 * t713 * t32 - 0.2e1 * t197 + 0.4e1 * t6 * t757 - 0.4e1 * t446 + 0.2e1 * t6 * t659 + t5 * t176 + 0.4e1 * t86 * t130 - 0.4e1 * t1 * t323 - 0.2e1 * t6 * t310 - 0.12e2 * t507 - 0.6e1 * t6 * t351;
-		t786 = t79 * t138;
-		t803 = 0.2e1 * t5 * t521 - 0.4e1 * t128 * t641 + 0.2e1 * t22 * t259 + 0.4e1 * t91 * t23 * t65 - 0.4e1 * t85 * t176 - t22 * t179 - 0.4e1 * t786 - 0.6e1 * t616 * t144 - t5 * t141 * t25 - 0.4e1 * t158 * t108 + 0.2e1 * t6 * t641 + t6 * t252 + 0.4e1 * t6 * t661 - 0.6e1 * t6 * t88 - 0.4e1 * t95 * t521;
-		t812 = t19 * t55;
-		t813 = t812 * t15;
-		t827 = -0.4e1 * t323 - 0.2e1 * t431 - 0.2e1 * t465 - 0.2e1 * t494 - 0.4e1 * t670 - 0.4e1 * t154 - 0.4e1 * t413 + 0.8e1 * t813 - 0.4e1 * t11 * t14 - 0.16e2 * t11 * t106 - 0.24e2 * t11 * t13 - 0.4e1 * t11 * t15 - 0.16e2 * t11 * t12 - 0.8e1 * t542 + 0.12e2 * t119;
-		t853 = -0.6e1 * t6 * t144 + t91 * t535 * t65 - 0.2e1 * t100 * t97 - 0.8e1 * t128 * t172 + 0.2e1 * t128 * t108 + 0.2e1 * t5 * t97 + 0.4e1 * t158 * t308 + t9 * t252 + 0.2e1 * t188 + t1 * t484 + 0.6e1 * t128 * t351 - 0.2e1 * t38 - 0.4e1 * t227 * t181 - 0.4e1 * t194 - 0.2e1 * t1 * t38;
-		t863 = t600 * t36;
-		t886 = -0.2e1 * t6 * t198 + 0.4e1 * t86 * t310 - 0.4e1 * t6 * t813 + 0.4e1 * t6 * t863 + 0.2e1 * t8 * t259 + 0.2e1 * t1 * t310 + 0.6e1 * t1 * t351 + 0.4e1 * t303 + 0.2e1 * t142 * t308 + 0.2e1 * t227 * t492 + 0.4e1 * t6 * t172 - 0.4e1 * t95 * t259 - 0.8e1 * t91 * t409 * t15 + 0.4e1 * t227 * t259;
-		t892 = t191 * t65;
-		t899 = t812 * t36;
-		t907 = t812 * t65;
-		t917 = t48 * t31;
-		t920 = -0.16e2 * t11 * t106 * t15 - 0.2e1 * t6 * t353 + 0.4e1 * t6 * t892 + 0.12e2 * t86 * t351 + 0.6e1 * t128 * t88 - 0.2e1 * t6 * t899 + 0.8e1 * t115 * t435 * t13 + 0.4e1 * t6 * t83 - 0.2e1 * t6 * t907 + 0.2e1 * t35 - t6 * t39 + t5 * t93 + 0.2e1 * t128 * t485 + 0.12e2 * t86 * t144 - 0.12e2 * t6 * t917;
-		t947 = 0.2e1 * t5 * t259 - 0.4e1 * t85 * t203 + 0.2e1 * t100 * t203 - 0.2e1 * t6 * t786 - 0.2e1 * t1 * t252 - 0.2e1 * t226 * t717 + 0.6e1 * t128 * t144 - 0.2e1 * t227 * t93 + 0.4e1 * t86 * t308 - 0.6e1 * t616 * t88 + t100 * t688 + 0.8e1 * t313 - 0.6e1 * t6 * t636 - 0.4e1 * t112;
-		t973 = -0.4e1 * t85 * t235 + 0.24e2 * t917 + 0.2e1 * t91 * t259 + 0.4e1 * t86 * t186 - 0.4e1 * t569 - t22 * t93 + t6 * t189 - 0.6e1 * t52 * t1 * t13 + 0.4e1 * t9 * t172 + t22 * t337 - t22 * t490 - 0.2e1 * t52 * t1 * t15 + 0.2e1 * t6 * t186 - t52 * t1 + 0.2e1 * t6 * t283;
-		t997 = 0.8e1 * t101 * t172 + t22 * t492 + 0.6e1 * t713 * t279 - 0.2e1 * t95 * t235 + 0.8e1 * t62 - 0.2e1 * t628 - 0.2e1 * t349 - 0.2e1 * t650 + 0.8e1 * t892 + 0.12e2 * t215 + 0.4e1 * t481 + 0.2e1 * t85 * t688 + 0.4e1 * t5 * t141 * t12 - 0.2e1 * t95 * t93;
-		t1016 = -0.4e1 * t1 * t41 - t5 * t179 - 0.4e1 * t721 - 0.4e1 * t577 - 0.4e1 * t283 - 0.8e1 * t172 - 0.4e1 * t462 + 0.16e2 * t286 + 0.4e1 * t899 + 0.4e1 * t907 + 0.2e1 * t169 - 0.8e1 * t757 - 0.4e1 * t631 + 0.2e1 * t1 * t186 + 0.4e1 * t6 * t195;
-		t1041 = t600 * t65;
-		t1051 = -0.2e1 * t227 * t490 + 0.4e1 * t227 * t401 + 0.4e1 * t6 * t701 - 0.6e1 * t101 * t351 - t91 * t535 * t36 - 0.4e1 * t129 + 0.6e1 * t6 * t364 + 0.2e1 * t1 * t44 * t32 + 0.6e1 * t128 * t119 - 0.2e1 * t6 * t42 + 0.8e1 * t115 * t49 * t25 + 0.4e1 * t6 * t1041 - 0.2e1 * t91 * t421 - 0.4e1 * t115 * t572 * t15 + 0.4e1 * t86 * t353;
-		t1059 = t600 * t15;
-		t1072 = 0.2e1 * t55 + 0.2e1 * t101 * t485 + 0.4e1 * t812 - 0.4e1 * t86 * t431 - 0.4e1 * t613 + 0.16e2 * t1059 + 0.24e2 * t749 + 0.4e1 * t474 + 0.8e1 * t1041 + 0.8e1 * t863 - 0.2e1 * t1 * t25 - 0.4e1 * t282 - 0.2e1 * t252 - 0.4e1 * t641 + 0.8e1 * t6 * t1059;
-		t1084 = pow(t24 + 0.1e1 + t12, 0.2e1);
-		t1089 = pow(t24 - 0.1e1 - t12, 0.2e1);
-		t1093 = n * n;
-		t1097 = M_PI * M_PI;
-
-		u1b = deltaRho * t3 * (t1051 + t459 + t387 + t330 + t658 + t496 + t947 + t126 + t594 + t886 + t803 + t920 + t75 + t973 + t997 + t171 + t211 + t716 + t360 + t424 + t1072 + t559 + t745 + t1016 + t623 + t853 + t773 + t255 + t526 + t827 + t290 + t685) / t10 / (0.1e1 + t15) / t1084 / t1089 / t7 / t1093 / n / t1097 / M_PI / viscosity / (0.1e1 + t19) / 0.2e1;
-		
-		t1 = n * M_PI;
-		t2 = 0.1e1 / cosh(t1);
-		t3 = startBlockY * n;
-		t4 = t3 * M_PI;
-		t5 = tanh(t4);
-		t6 = t2 * t5;
-		t7 = 0.1e1 / cosh(t4);
-		t8 = tanh(t1);
-		t9 = t8 * t7;
-		t13 = sin(t1 * dx);
-		t15 = y * n;
-		t16 = t15 * M_PI;
-		t17 = tanh(t16);
-		t19 = t17 * t8 * t7;
-		t22 = t17 * t2;
-		t25 = t17 * n;
-		t26 = M_PI * t2;
-		t27 = t8 * t8;
-		t28 = t26 * t27;
-		t31 = t2 * startBlockY;
-		t32 = t1 * t5;
-		t34 = t17 * t17;
-		t35 = t34 * t2;
-		t37 = 0.1e1 / cosh(t16);
-		t38 = t37 * t37;
-		t39 = t38 * n;
-		t40 = t39 * M_PI;
-		t41 = t2 * t8;
-		t42 = t41 * t5;
-		t45 = t38 * t2;
-		t46 = t27 * t5;
-		t47 = t45 * t46;
-		t48 = t2 * t2;
-		t49 = t38 * t48;
-		t50 = t49 * t9;
-		t53 = t8 * t5;
-		t54 = t22 * t53;
-		t56 = t48 * t2;
-		t57 = t17 * t56;
-		t60 = t17 * t48;
-		t61 = t60 * t9;
-		t63 = 0.6e1 * t16 * t19 - 0.2e1 * t22 * t4 + 0.4e1 * t25 * t28 - t31 * t32 - t35 * t4 + 0.4e1 * t40 * t42 + t47 + t50 + 0.2e1 * t39 * t26 + 0.4e1 * t54 + 0.2e1 * t57 * t4 + 0.2e1 * t61;
-		t64 = t34 * n;
-		t67 = t34 * t56;
-		t69 = t35 * t53;
-		t71 = t35 * t46;
-		t72 = t34 * t48;
-		t73 = t72 * t9;
-		t74 = t22 * startBlockY;
-		t75 = t1 * t27;
-		t78 = t48 * t7;
-		t83 = M_PI * t7;
-		t85 = t56 * startBlockY;
-		t88 = t2 * t27;
-		t93 = 0.2e1 * t64 * t26 + t67 * t4 + 0.2e1 * t69 + t71 + t73 - 0.2e1 * t74 * t75 - 0.2e1 * t1 * t78 + 0.2e1 * t1 * t6 - t3 * t83 + t85 * t1 - t31 * t1 + 0.2e1 * t1 * t88 + 0.4e1 * t1 * t41;
-		t98 = t31 * n;
-		t99 = t8 * M_PI;
-		t104 = t17 * startBlockY;
-		t105 = t1 * t7;
-		t108 = M_PI * t56;
-		t110 = t45 * t53;
-		t113 = t22 * t46;
-		t117 = t38 * t56;
-		t118 = t117 * t5;
-		t120 = t26 * t5;
-		t123 = 0.4e1 * t25 * t26 - t15 * t26 - 0.2e1 * t98 * t99 * t5 + t15 * t83 - 0.2e1 * t104 * t105 + t15 * t108 + 0.2e1 * t110 + t85 * t32 + 0.2e1 * t113 + 0.2e1 * t16 * t110 - t16 * t118 + 0.4e1 * t25 * t120;
-		t125 = t34 * t27 * t7;
-		t128 = t48 * t8 * t7;
-		t129 = t88 * t5;
-		t130 = t45 * t27;
-		t131 = t67 * t5;
-		t133 = t49 * t7;
-		t135 = M_PI * t38;
-		t140 = t26 * t8;
-		t143 = t104 * n;
-		t144 = t27 * t8;
-		t146 = M_PI * t144 * t7;
-		t149 = t99 * t7;
-		t153 = M_PI * t48 * t7;
-		t156 = -0.3e1 * t125 + t128 + t129 + t130 - t131 - t15 * t28 + t16 * t133 - t15 * t135 * t7 + t15 * t135 * t2 - 0.2e1 * t15 * t140 - 0.2e1 * t143 * t146 - 0.6e1 * t143 * t149 - 0.2e1 * t39 * t153;
-		t159 = t45 * startBlockY;
-		t160 = t1 * t46;
-		t162 = M_PI * t27;
-		t163 = t162 * t7;
-		t166 = t38 * startBlockY;
-		t170 = M_PI * t25;
-		t171 = startBlockY * t48;
-		t172 = t171 * t7;
-		t177 = t35 * t8;
-		t182 = t171 * t9;
-		t186 = t34 * t8 * t7;
-		t191 = -t159 * t160 - 0.6e1 * t143 * t163 - t166 * t105 + 0.2e1 * t39 * t120 + 0.2e1 * t170 * t172 + 0.2e1 * t1 * t129 - 0.2e1 * t16 * t177 - 0.2e1 * t40 * t128 + 0.2e1 * t170 * t182 + 0.3e1 * t16 * t186 + t117 * t4 - t45 * t4;
-		t192 = t35 * t5;
-		t194 = t166 * n;
-		t199 = t1 * t8;
-		t206 = t57 * t5;
-		t210 = t38 * t27 * t7;
-		t217 = -t16 * t192 - t194 * t146 + 0.2e1 * t57 * startBlockY * t32 - 0.4e1 * t74 * t199 - t56 - 0.4e1 * t16 * t54 - 0.3e1 * t9 - 0.2e1 * t57 + 0.2e1 * t16 * t206 - 0.3e1 * t210 + 0.2e1 * t1 * t2 - 0.4e1 * t25 * t153 + t16 * t131;
-		t225 = M_PI * t17;
-		t236 = t38 * t8 * t7;
-		t239 = t45 * t5;
-		t241 = t45 * t8;
-		t244 = -0.2e1 * t16 * t69 - 0.2e1 * t159 * t199 - 0.2e1 * t1 * t128 + 0.2e1 * t15 * t225 * t56 + t35 - 0.2e1 * t17 * t7 + 0.2e1 * t15 * t225 * t7 - t159 * t75 - 0.3e1 * t16 * t236 - t117 + t16 * t239 + 0.2e1 * t16 * t241;
-		t249 = t64 * M_PI;
-		t253 = t38 * t144 * t7;
-		t258 = t22 * t5;
-		t264 = -t38 * t7 + t6 - 0.3e1 * t194 * t163 + t40 * t172 + t249 * t172 - t3 * t146 - t16 * t253 - t15 * t135 * t56 - t159 * t32 + t2 - 0.2e1 * t16 * t258 + t249 * t182 + t67 * startBlockY * t32;
-		t270 = t60 * t7;
-		t275 = t17 * t144 * t7;
-		t279 = t72 * t7;
-		t282 = t34 * t144 * t7;
-		t284 = t35 * t27;
-		t286 = 0.4e1 * t64 * t140 - 0.2e1 * t16 * t270 + t16 * t130 + 0.2e1 * t16 * t275 + t40 * t182 - t16 * t279 + t16 * t282 + t284 - 0.3e1 * t186 + t192 + t279 - t282;
-		t287 = t35 * startBlockY;
-		t295 = t22 * t27;
-		t299 = t22 * t8;
-		t304 = t17 * t27 * t7;
-		t307 = -0.2e1 * t287 * t199 + 0.2e1 * t249 * t129 - t34 * t7 + 0.4e1 * t249 * t42 + 0.2e1 * t295 + 0.2e1 * t241 - 0.3e1 * t236 + t239 - t253 + 0.4e1 * t299 - t118 - 0.2e1 * t64 * t153 + 0.6e1 * t16 * t304;
-		t309 = t34 * startBlockY;
-		t317 = M_PI * t34;
-		t328 = t309 * n;
-		t330 = -t309 * t105 + t117 * startBlockY * t32 - t7 + 0.4e1 * t39 * t140 + 0.2e1 * t64 * t120 + t45 + t15 * t317 * t7 - 0.2e1 * t249 * t128 - 0.3e1 * t3 * t149 + 0.2e1 * t39 * t28 - 0.3e1 * t194 * t149 - t328 * t146;
-		t342 = t1 * t53;
-		t349 = -0.3e1 * t328 * t149 + t15 * t317 * t56 - t67 - t16 * t284 - 0.3e1 * t328 * t163 + 0.2e1 * t64 * t28 - t15 * t317 * t2 - 0.2e1 * t159 * t342 - t287 * t160 + t133 + 0.2e1 * t258 + 0.2e1 * t270 - 0.2e1 * t275;
-		t371 = -0.6e1 * t304 - t287 * t75 + 0.2e1 * t177 + 0.4e1 * t170 * t129 - 0.2e1 * t15 * t225 * t2 - t287 * t32 - 0.3e1 * t3 * t163 - 0.2e1 * t287 * t342 - 0.2e1 * t16 * t295 + 0.8e1 * t170 * t42 + t88 - 0.2e1 * t16 * t61;
-		t390 = -0.2e1 * t206 + 0.2e1 * t42 - 0.6e1 * t19 - 0.2e1 * t74 * t160 + 0.3e1 * t16 * t125 - 0.2e1 * t74 * t32 - 0.4e1 * t74 * t342 + 0.3e1 * t15 * t149 + 0.2e1 * t41 - t16 * t128 - 0.4e1 * t170 * t128 - t15 * t120 + t78;
-		t411 = -t16 * t129 - 0.2e1 * t16 * t42 - 0.4e1 * t16 * t299 - t16 * t73 + t15 * t108 * t5 - 0.3e1 * t16 * t210 + 0.4e1 * t1 * t42 + t16 * t50 + t15 * t146 - t15 * t153 - 0.2e1 * t31 * t199 - 0.2e1 * t16 * t113;
-		t430 = -t31 * t75 - t16 * t71 - t144 * t7 + 0.3e1 * t15 * t163 + t16 * t47 - t56 * t5 + 0.8e1 * t25 * t140 - t98 * t162 * t5 - 0.3e1 * t27 * t7 + t1 * t172 + t4 * t128 + 0.2e1 * t40 * t129 + 0.2e1 * t22;
-		t441 = n * n;
-		t444 = M_PI * M_PI;
-		t449 = pow(t2 + 0.1e1 + t8, 0.2e1);
-		t453 = pow(t2 - 0.1e1 - t8, 0.2e1);
-
-		u2a = (t2 + t6 - t7 - t9) * deltaRho * t13 * (t63 + t93 + t123 + t156 + t191 + t217 + t244 + t264 + t286 + t307 + t330 + t349 + t371 + t390 + t411 + t430) / t7 / (0.1e1 + t5) / t441 / n / t444 / M_PI / t449 / t453 / t37 / viscosity / (0.1e1 + t17) / 0.2e1;
-
-		t1 = n * M_PI;
-		t3 = sin(t1 * dx);
-		t5 = 0.1e1 / cosh(t1);
-		t6 = t5 * t5;
-		t7 = t6 * t6;
-		t8 = startBlockY * n;
-		t9 = t8 * M_PI;
-		t10 = 0.1e1 / cosh(t9);
-		t11 = t10 * t10;
-		t13 = y * n;
-		t14 = t13 * M_PI;
-		t15 = tanh(t14);
-		t16 = t15 * n;
-		t17 = t16 * M_PI;
-		t18 = t6 * t5;
-		t19 = tanh(t1);
-		t20 = t18 * t19;
-		t21 = tanh(t9);
-		t22 = t10 * t21;
-		t23 = t20 * t22;
-		t26 = 0.1e1 / cosh(t14);
-		t27 = t26 * t26;
-		t28 = t27 * t11;
-		t29 = t28 * t6;
-		t30 = t15 * t15;
-		t31 = t30 * t5;
-		t32 = t19 * t19;
-		t33 = t32 * t10;
-		t34 = t31 * t33;
-		t37 = t27 * n;
-		t38 = t37 * M_PI;
-		t39 = t32 * t19;
-		t40 = t5 * t39;
-		t41 = t40 * t10;
-		t44 = t20 * t10;
-		t47 = t21 * t21;
-		t48 = t27 * t47;
-		t49 = t48 * t6;
-		t50 = t6 * t19;
-		t52 = t15 * t6;
-		t53 = t52 * t19;
-		t56 = t30 * startBlockY;
-		t57 = t56 * n;
-		t58 = M_PI * t19;
-		t59 = t21 * t6;
-		t60 = t58 * t59;
-		t64 = t19 * t10;
-		t65 = t64 * t21;
-		t68 = t27 * t18;
-		t71 = t68 * t22;
-		t74 = -t7 * t11 - 0.4e1 * t17 * t23 - t29 + 0.6e1 * t14 * t34 - 0.2e1 * t38 * t41 - 0.2e1 * t1 * t44 - t49 + 0.2e1 * t50 - 0.4e1 * t14 * t53 - 0.4e1 * t57 * t60 - 0.2e1 * t1 * t18 * t65 + 0.2e1 * t68 * t65 + 0.2e1 * t14 * t71;
-		t75 = t30 * t18;
-		t76 = t75 * t22;
-		t78 = startBlockY * t6;
-		t79 = t78 * t19;
-		t84 = t15 * t18;
-		t85 = t84 * t22;
-		t87 = t27 * startBlockY;
-		t91 = M_PI * t32;
-		t92 = t91 * t59;
-		t95 = t15 * t5;
-		t96 = t39 * t10;
-		t97 = t95 * t96;
-		t99 = t95 * t64;
-		t101 = M_PI * t6;
-		t104 = t75 * t64;
-		t106 = t30 * t11;
-		t107 = t106 * t50;
-		t109 = t15 * startBlockY;
-		t110 = t109 * n;
-		t111 = M_PI * t11;
-		t112 = t6 * t32;
-		t113 = t111 * t112;
-		t116 = M_PI * t27;
-		t117 = t13 * t116;
-		t118 = t87 * n;
-		t121 = 0.2e1 * t76 - 0.4e1 * t17 * t79 - 0.2e1 * t7 * t21 + 0.4e1 * t85 - 0.6e1 * t87 * t1 * t32 - 0.2e1 * t57 * t92 - 0.4e1 * t97 - 0.12e2 * t99 + 0.4e1 * t16 * t101 + 0.2e1 * t104 + 0.2e1 * t107 + 0.2e1 * t110 * t113 + t117 + 0.4e1 * t118 * t60;
-		t123 = t11 * t6;
-		t126 = t5 * t19;
-		t127 = t126 * t22;
-		t130 = M_PI * t7;
-		t132 = t18 * t10;
-		t135 = t27 * t5;
-		t136 = t135 * t10;
-		t138 = t68 * t64;
-		t143 = t130 * t47;
-		t145 = t30 * t7;
-		t146 = t145 * t11;
-		t150 = t5 * t32;
-		t151 = t150 * t22;
-		t155 = 0.2e1 * t1 * t123 - 0.6e1 * t127 - t13 * t101 + t8 * t130 - 0.2e1 * t1 * t132 - 0.2e1 * t136 + 0.2e1 * t138 + 0.6e1 * t118 * t91 * t11 + t57 * t143 + t14 * t146 - 0.4e1 * t17 * t41 - 0.6e1 * t151 + 0.4e1 * t1 * t59;
-		t156 = t47 * t6;
-		t159 = t95 * t10;
-		t161 = M_PI * t47;
-		t162 = t161 * t112;
-		t165 = t40 * t22;
-		t175 = t130 * t11;
-		t177 = t91 * t6;
-		t183 = 0.2e1 * t1 * t156 - 0.4e1 * t159 - 0.2e1 * t110 * t162 - 0.2e1 * t38 * t165 - 0.2e1 * t165 - t7 + 0.2e1 * t110 * t143 + 0.2e1 * t118 * t92 + 0.2e1 * t38 * t79 + t13 * t175 - t57 * t177 + t118 * t177 - t14 * t49 - 0.12e2 * t95 * t65;
-		t186 = t59 * t19;
-		t189 = t32 * t32;
-		t190 = M_PI * t189;
-		t193 = t95 * t22;
-		t199 = t5 * t10;
-		t202 = t30 * t21;
-		t203 = t202 * t6;
-		t206 = t135 * t96;
-		t209 = t135 * t22;
-		t212 = t95 * t33;
-		t214 = t106 * t112;
-		t218 = t31 * t64;
-		t220 = 0.16e2 * t17 * t186 + t118 * t190 * t11 + 0.4e1 * t14 * t193 - 0.6e1 * t31 * t65 + 0.2e1 * t23 - 0.2e1 * t1 * t199 - 0.2e1 * t14 * t203 - 0.2e1 * t14 * t206 - 0.2e1 * t14 * t209 - 0.12e2 * t212 + t214 + 0.2e1 * t13 * t116 * t21 - 0.6e1 * t218;
-		t226 = t202 * t50;
-		t229 = t30 * t47;
-		t230 = t229 * t50;
-		t233 = t68 * t10;
-		t236 = t31 * t96;
-		t241 = t111 * t50;
-		t244 = t101 * t11;
-		t247 = t123 * t32;
-		t250 = t156 * t19;
-		t253 = t57 * t113 + t28 + 0.12e2 * t14 * t99 + 0.2e1 * t37 * t101 - 0.4e1 * t14 * t226 + 0.2e1 * t230 + 0.4e1 * t226 + 0.2e1 * t14 * t233 + 0.2e1 * t14 * t236 + 0.4e1 * t1 * t50 + 0.4e1 * t110 * t241 + 0.4e1 * t16 * t244 + 0.4e1 * t17 * t247 - 0.2e1 * t14 * t250;
-		t256 = t161 * t50;
-		t260 = t101 * t21;
-		t263 = t123 * t19;
-		t268 = t31 * t22;
-		t272 = t229 * t112;
-		t273 = t84 * t64;
-		t275 = M_PI * t30;
-		t276 = t13 * t275;
-		t280 = t15 * t21;
-		t281 = t280 * t50;
-		t283 = t118 * t162 - 0.4e1 * t110 * t256 - t118 * t113 + 0.4e1 * t37 * t260 - 0.2e1 * t14 * t263 - 0.4e1 * t14 * t85 - 0.2e1 * t268 - 0.2e1 * t14 * t136 + t272 + 0.4e1 * t273 + 0.2e1 * t276 * t165 - 0.4e1 * t193 + 0.8e1 * t281;
-		t285 = t30 * t6;
-		t286 = t285 * t32;
-		t288 = t156 * t32;
-		t291 = t101 * t19;
-		t294 = t48 * t50;
-		t296 = t30 * n;
-		t297 = t296 * M_PI;
-		t298 = t132 * t21;
-		t301 = t28 * t50;
-		t303 = t48 * t112;
-		t305 = t28 * t112;
-		t310 = -t8 * t175 - t14 * t286 + 0.2e1 * t1 * t288 + 0.8e1 * t16 * t291 - 0.2e1 * t294 + t156 - 0.2e1 * t297 * t298 - 0.2e1 * t301 - t303 - 0.2e1 * t199 - t305 + 0.2e1 * t71 - 0.2e1 * t276 * t23 - t9 * t288;
-		t314 = t59 * t32;
-		t321 = t135 * t33;
-		t326 = t33 * t21;
-		t333 = t27 * t21;
-		t334 = t333 * t50;
-		t338 = t15 * t11;
-		t339 = t338 * t50;
-		t341 = t27 * t189;
-		t342 = 0.4e1 * t1 * t314 - 0.2e1 * t87 * t1 * t21 - t7 * t47 - 0.6e1 * t321 - 0.4e1 * t87 * t1 * t39 - 0.6e1 * t135 * t326 - t14 * t247 + 0.2e1 * t14 * t165 - 0.2e1 * t236 - 0.4e1 * t334 + 0.2e1 * t57 * t241 + 0.4e1 * t339 + t341;
-		t343 = t15 * t47;
-		t344 = t343 * t112;
-		t346 = t343 * t50;
-		t348 = M_PI * t15;
-		t349 = t13 * t348;
-		t365 = t161 * t6;
-		t372 = M_PI * startBlockY * t6;
-		t374 = 0.2e1 * t344 + 0.4e1 * t346 + 0.12e2 * t349 * t151 - 0.2e1 * t14 * t44 - 0.2e1 * t57 * t256 + 0.4e1 * t1 * t250 + 0.8e1 * t1 * t186 + 0.8e1 * t17 * t263 - 0.2e1 * t57 * t260 - 0.6e1 * t34 - t13 * t365 - 0.2e1 * t1 * t41 - 0.2e1 * t14 * t107 - t296 * t372;
-		t379 = t150 * t10;
-		t388 = t341 * t47;
-		t390 = t96 * t21;
-		t394 = M_PI * t18 * t10;
-		t402 = -0.2e1 * t14 * t23 + t57 * t244 - 0.6e1 * t297 * t379 + 0.2e1 * t296 * t244 - 0.2e1 * t297 * t23 - t1 * t78 + 0.2e1 * t59 + t14 * t388 - 0.2e1 * t135 * t390 - 0.2e1 * t296 * t394 - 0.2e1 * t110 * t175 - t87 * t1 - 0.2e1 * t297 * t44;
-		t403 = t27 * t39;
-		t404 = t403 * t47;
-		t409 = t15 * t7;
-		t410 = t409 * t47;
-		t414 = t333 * t112;
-		t425 = t130 * t21;
-		t429 = t341 * t11;
-		t431 = 0.4e1 * t14 * t404 + 0.2e1 * t296 * t365 - 0.2e1 * t410 - 0.2e1 * t16 * t372 - 0.2e1 * t414 - 0.4e1 * t17 * t165 + t112 + t8 * t143 - 0.6e1 * t38 * t379 - t14 * t214 + 0.4e1 * t13 * t116 * t19 + 0.2e1 * t8 * t425 + 0.2e1 * t132 + t14 * t429;
-		t447 = t126 * t10;
-		t450 = t199 * t21;
-		t455 = M_PI * t5 * t10;
-		t460 = t1 * t5;
-		t463 = -0.6e1 * t118 * t91 * t47 - 0.6e1 * t38 * t151 - 0.2e1 * t297 * t41 - 0.4e1 * t17 * t298 - 0.6e1 * t297 * t151 + t48 - 0.6e1 * t135 * t65 - 0.6e1 * t38 * t447 - 0.2e1 * t1 * t450 + t9 * t247 - 0.2e1 * t37 * t455 - 0.6e1 * t1 * t379 - 0.6e1 * t460 * t326;
-		t464 = t135 * t64;
-		t467 = t403 * t21;
-		t491 = -0.6e1 * t464 + t37 * t372 + 0.8e1 * t467 - 0.6e1 * t1 * t447 - 0.4e1 * t14 * t273 + 0.2e1 * t296 * t177 + 0.2e1 * t37 * t244 - 0.6e1 * t460 * t65 + 0.6e1 * t14 * t151 + 0.8e1 * t16 * t260 - 0.2e1 * t460 * t390 + 0.4e1 * t296 * t291 - 0.12e2 * t95 * t326 - 0.2e1 * t37 * t394;
-		t501 = t202 * t112;
-		t512 = t1 * t7;
-		t518 = t27 * t19;
-		t519 = t518 * t11;
-		t522 = -0.4e1 * t16 * t394 - 0.4e1 * t110 * t260 - 0.4e1 * t95 * t390 - 0.2e1 * t1 * t79 - 0.2e1 * t14 * t501 + 0.2e1 * t297 * t288 - 0.2e1 * t14 * t314 + 0.4e1 * t84 * t65 + 0.6e1 * t276 * t127 + t56 * t512 - 0.2e1 * t38 * t298 + 0.2e1 * t37 * t365 + 0.4e1 * t14 * t519;
-		t540 = t84 * t10;
-		t550 = -0.6e1 * t14 * t464 - t8 * t177 + 0.2e1 * t110 * t244 - 0.4e1 * t14 * t339 - 0.2e1 * t1 * t298 + 0.12e2 * t14 * t212 - 0.2e1 * t38 * t44 - t13 * t177 - 0.4e1 * t87 * t1 * t19 + 0.4e1 * t540 - 0.2e1 * t297 * t165 + 0.2e1 * t296 * t101 - 0.2e1 * t13 * t394 - 0.2e1 * t9 * t314;
-		t557 = t338 * t112;
-		t567 = t518 * t21;
-		t582 = -0.4e1 * t17 * t450 - 0.2e1 * t14 * t557 + 0.4e1 * t110 * t425 + 0.2e1 * t14 * t268 + 0.2e1 * t38 * t247 + t13 * t143 + 0.8e1 * t14 * t567 - 0.4e1 * t9 * t186 + 0.2e1 * t13 * t348 * t7 - 0.2e1 * t209 + 0.4e1 * t14 * t97 + 0.2e1 * t57 * t425 - 0.12e2 * t17 * t379;
-		t587 = t145 * t47;
-		t598 = t145 * t21;
-		t609 = -t57 * t162 - 0.4e1 * t14 * t334 - t57 * t175 + t14 * t587 - 0.4e1 * t14 * t540 - 0.12e2 * t17 * t151 - t146 + 0.2e1 * t14 * t410 - 0.12e2 * t118 * t91 * t21 + 0.2e1 * t14 * t598 + 0.4e1 * t38 * t263 - 0.2e1 * t297 * t450 + 0.4e1 * t14 * t159 + 0.2e1 * t38 * t288;
-		t611 = t52 * t32;
-		t614 = t27 * t32;
-		t615 = t614 * t21;
-		t618 = M_PI * t39;
-		t634 = t285 * t19;
-		t637 = t280 * t112;
-		t639 = t27 * t6;
-		t640 = t639 * t32;
-		t642 = t280 * t6;
-		t645 = -0.2e1 * t14 * t611 + 0.12e2 * t14 * t615 + 0.4e1 * t118 * t618 * t11 - 0.2e1 * t118 * t241 - t145 + 0.4e1 * t118 * t58 * t11 + 0.2e1 * t118 * t256 - 0.2e1 * t14 * t414 + 0.4e1 * t13 * t116 * t39 - 0.2e1 * t14 * t634 + 0.4e1 * t637 - t14 * t640 - 0.4e1 * t14 * t642;
-		t654 = t333 * t6;
-		t673 = -0.2e1 * t13 * t260 - t13 * t275 * t6 + 0.4e1 * t296 * t260 - 0.6e1 * t117 * t151 - 0.2e1 * t14 * t654 + 0.6e1 * t14 * t218 + 0.4e1 * t349 * t165 + 0.4e1 * t38 * t314 - 0.12e2 * t17 * t447 - 0.12e2 * t17 * t127 + 0.2e1 * t13 * t455 + t27 - 0.4e1 * t349 * t23 - 0.6e1 * t31 * t326;
-		t682 = t409 * t11;
-		t702 = t13 * t275 * t7 - 0.2e1 * t117 * t165 + 0.6e1 * t276 * t151 - 0.2e1 * t682 - 0.8e1 * t14 * t281 + 0.2e1 * t297 * t247 - 0.2e1 * t110 * t365 - 0.2e1 * t14 * t230 - 0.4e1 * t14 * t637 + 0.4e1 * t38 * t250 - t87 * t1 * t47 + 0.2e1 * t117 * t23 - 0.2e1 * t8 * t260;
-		t705 = t518 * t47;
-		t716 = t343 * t6;
-		t719 = t614 * t11;
-		t721 = t403 * t11;
-		t726 = t409 * t21;
-		t728 = t338 * t6;
-		t731 = 0.2e1 * t13 * t425 + 0.4e1 * t14 * t705 - t13 * t116 * t6 - 0.8e1 * t110 * t60 - 0.4e1 * t16 * t455 - 0.2e1 * t14 * t76 - 0.2e1 * t14 * t716 + 0.6e1 * t719 + 0.4e1 * t721 + 0.4e1 * t297 * t314 + 0.4e1 * t642 - 0.4e1 * t726 + 0.2e1 * t728 + 0.2e1 * t716;
-		t734 = t106 * t6;
-		t735 = t229 * t6;
-		t740 = t614 * t47;
-		t742 = t31 * t10;
-		t744 = 0.2e1 * t203 + t734 + t735 + t247 + 0.2e1 * t263 - 0.2e1 * t598 - 0.2e1 * t450 - t587 - t14 * t272 + 0.6e1 * t740 + t429 - 0.2e1 * t742 + t286;
-		t747 = t75 * t10;
-		t753 = t341 * t21;
-		t761 = -0.2e1 * t41 - 0.6e1 * t379 + 0.2e1 * t747 + 0.4e1 * t186 + 0.2e1 * t314 + 0.2e1 * t611 - 0.2e1 * t654 + 0.2e1 * t753 - t14 * t735 + 0.2e1 * t250 + t288 + 0.2e1 * t1 * t6 + 0.4e1 * t705 + 0.4e1 * t519;
-		t771 = t639 * t19;
-		t779 = 0.2e1 * t233 + 0.12e2 * t615 + 0.8e1 * t567 + 0.6e1 * t14 * t127 + 0.2e1 * t634 - 0.2e1 * t771 + 0.4e1 * t53 + 0.4e1 * t404 + t388 + 0.2e1 * t44 + 0.8e1 * t38 * t186 + 0.2e1 * t298 + t123;
-		t801 = -0.4e1 * t14 * t346 - 0.6e1 * t447 - 0.6e1 * t38 * t127 + 0.6e1 * t14 * t740 - t14 * t29 + 0.2e1 * t1 * t247 - t14 * t734 - 0.4e1 * t17 * t44 - t640 + t8 * t244 - 0.2e1 * t14 * t344 - 0.4e1 * t110 * t92 + 0.2e1 * t557 - 0.2e1 * t31 * t390;
-		t830 = -0.4e1 * t118 * t58 * t47 - 0.4e1 * t14 * t186 + 0.2e1 * t9 * t263 - 0.2e1 * t9 * t250 + 0.2e1 * t14 * t138 - 0.2e1 * t14 * t104 + 0.4e1 * t17 * t288 + 0.2e1 * t501 + 0.6e1 * t13 * t116 * t32 + 0.2e1 * t37 * t177 + 0.6e1 * t14 * t379 + 0.2e1 * t14 * t41 - t118 * t190 * t47;
-		t854 = -t87 * t1 * t189 - 0.6e1 * t14 * t321 + 0.2e1 * t333 + t13 * t130 + 0.2e1 * t75 * t65 + 0.8e1 * t17 * t314 + 0.2e1 * t109 * t512 + 0.4e1 * t297 * t250 - t8 * t365 + 0.4e1 * t14 * t721 + t6 + 0.4e1 * t16 * t365 - 0.6e1 * t297 * t447 - 0.2e1 * t14 * t301;
-		t883 = 0.4e1 * t37 * t291 - 0.2e1 * t296 * t455 + 0.8e1 * t17 * t250 - 0.2e1 * t118 * t190 * t21 + t87 * t1 * t11 + 0.12e2 * t349 * t127 + 0.6e1 * t14 * t719 + 0.2e1 * t52 + 0.2e1 * t14 * t450 - 0.2e1 * t38 * t23 + 0.4e1 * t297 * t263 + 0.2e1 * t1 * t112 - 0.2e1 * t297 * t79;
-		t910 = -0.2e1 * t13 * t291 - 0.6e1 * t117 * t127 + t285 - 0.2e1 * t13 * t348 * t6 + 0.8e1 * t297 * t186 - t13 * t244 - t57 * t365 - 0.4e1 * t118 * t618 * t47 + 0.2e1 * t14 * t753 + t13 * t116 * t11 + 0.2e1 * t118 * t260 + 0.6e1 * t14 * t447 - 0.2e1 * t206 - 0.8e1 * t118 * t618 * t21;
-		t936 = -0.2e1 * t14 * t771 + 0.2e1 * t14 * t742 + t13 * t116 * t47 - 0.6e1 * t297 * t127 - 0.2e1 * t14 * t728 - t14 * t288 - 0.2e1 * t38 * t450 + 0.6e1 * t614 - 0.2e1 * t14 * t294 + 0.4e1 * t518 - 0.2e1 * t110 * t177 - 0.2e1 * t14 * t747 - 0.8e1 * t118 * t58 * t21;
-		t957 = 0.2e1 * t14 * t682 + 0.4e1 * t14 * t726 + 0.4e1 * t16 * t177 + t13 * t116 * t189 + 0.4e1 * t403 - 0.2e1 * t14 * t298 - t14 * t303 - t118 * t244 - t639 + 0.4e1 * t1 * t263 - 0.2e1 * t409 + t118 * t365 - t14 * t305 + 0.8e1 * t14 * t467;
-		t969 = pow(t5 + 0.1e1 + t19, 0.2e1);
-		t974 = pow(t5 - 0.1e1 - t19, 0.2e1);
-		t978 = n * n;
-		t982 = M_PI * M_PI;
-
-		u2b = deltaRho * t3 * (t910 + t74 + t582 + t310 + t830 + t491 + t883 + t645 + t342 + t957 + t283 + t673 + t220 + t121 + t183 + t609 + t550 + t731 + t374 + t702 + t402 + t431 + t854 + t522 + t761 + t744 + t779 + t463 + t155 + t253 + t936 + t801) / t10 / (0.1e1 + t21) / t969 / t974 / t26 / t978 / n / t982 / M_PI / viscosity / (0.1e1 + t15) / 0.2e1;
-
-		if ( y > startBlockY ) {
-			u1=u1b; u2=u2b;
-		}
-		else {
-			u1 = u1a; u2=u2a;
-		}
-
-		u1 *= cos(n*M_PI*x);
-		velocity[ J_AXIS ] += u1;
-		u2 *= sin(n*M_PI*x);
-		velocity[ I_AXIS ] += u2;
-	}
-}
-
-
-void _AnalyticBlock_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	AnalyticBlock*          self           = (AnalyticBlock*)analyticSolution;
-	double                  n;
-	double                  x, y;
-	double                  viscosity      = 1.0;
-	double                  deltaRho       = 1.0;
-	double                  startBlockX    = self->startBlockX;
-	double                  endBlockX      = self->endBlockX;
-	double                  startBlockY    = self->startBlockY;
-	double                  x0;
-	double                  dx;
-	double                  u2, u3, u5;
-	double                  u2a, u2b;
-	double                  u3a, u3b;
-	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
-	double t41,t42,t44,t45,t46,t47,t48,t49,t50,t51,t52,t53,t54,t55,t56,t57,t58,t59,t60,t61,t62,t63,t64,t65,t66,t67,t68,t69,t70,t71,t72,t73,t74,t75,t76,t77,t78,t79;
-	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91,t92,t93,t94,t95,t96,t97,t98,t99,t100,t101,t102,t103,t104,t105,t106,t107,t108,t109,t110,t111,t112,t113,t114,t115,t116,t117,t118,t119,t120;
-	double t121,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t134,t135,t136,t138,t139,t140,t141,t143,t144,t145,t146,t148,t149,t150,t151,t153,t154,t155,t156,t157,t159,t160;
-	double t161,t162,t163,t164,t165,t166,t167,t169,t170,t171,t172,t173,t174,t175,t177,t178,t179,t180,t182,t183,t184,t186,t188,t189,t190,t191,t192,t193,t194,t196,t197,t199;
-	double t201,t202,t203,t205,t206,t208,t209,t210,t211,t212,t214,t216,t217,t218,t219,t220,t222,t225,t226,t228,t229,t230,t231,t233,t234,t235,t236,t238,t239;
-	double t241,t244,t247,t248,t249,t250,t252,t253,t255,t256,t257,t258,t259,t260,t262,t263,t264,t265,t266,t267,t268,t269,t270,t272,t273,t275,t276,t277,t279,t280;
-	double t281,t282,t283,t284,t285,t286,t287,t288,t289,t291,t294,t295,t296,t297,t298,t299,t300,t301,t303,t304,t305,t307,t308,t309,t310,t313,t314,t317;
-	double t321,t324,t326,t328,t329,t330,t331,t333,t334,t336,t338,t339,t341,t342,t343,t344,t346,t347,t348,t349,t350,t352,t353,t356,t359;
-	double t362,t365,t366,t367,t369,t370,t371,t372,t374,t376,t378,t379,t380,t382,t385,t387,t388,t389,t390,t392,t393,t394,t396,t399;
-	double t402,t403,t404,t405,t408,t409,t410,t411,t412,t414,t415,t416,t421,t422,t423,t425,t428,t429,t430,t431;
-	double t441,t442,t444,t447,t449,t450,t452,t453,t455,t460,t461,t463,t464,t467,t471,t473,t474,t476,t479;
-	double t483,t484,t485,t491,t492,t500,t501,t511,t512,t517,t518,t519;
-	double t522,t529,t536,t537,t540,t544,t550,t551,t553,t556,t557;
-	double t567,t573,t580,t582,t587,t598,t600;
-	double t605,t609,t611,t614,t615,t618,t626,t634,t637,t638,t639,t640;
-	double t642,t645,t646,t651,t652,t654,t657,t659,t662,t664,t673;
-	double t682,t699,t702,t705,t716,t719;
-	double t721,t726,t727,t728,t730,t731,t734,t735,t740,t742,t744,t747,t753,t755,t756;
-	double t761,t771,t779,t783,t795;
-	double t801,t806,t809,t811,t816,t823,t828,t830;
-	double t849,t854,t877;
-	double t883,t904,t910;
-	double t933,t936,t957;
-	double t962,t969,t974,t978,t982,t988;
-	double t1001,t1004,t1011,t1015;
-
-	
-	/* Find coordinate of node */
-	x = coord[ I_AXIS ];
-	y = coord[ J_AXIS ];
-
-	x0 = 0.0;
-	dx = endBlockX - startBlockX;
-
-	/* Initialise */
-	*pressure = 0.0;
-
-	for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
-
-
-		t1 = n * M_PI;
-		t2 = 0.1e1 / cosh(t1);
-		t3 = startBlockY * n;
-		t4 = t3 * M_PI;
-		t5 = tanh(t4);
-		t6 = t2 * t5;
-		t7 = 0.1e1 / cosh(t4);
-		t8 = tanh(t1);
-		t9 = t8 * t7;
-		t13 = sin(t1 * dx);
-		t15 = y * n;
-		t16 = t15 * M_PI;
-		t17 = tanh(t16);
-		t19 = t17 * t8 * t7;
-		t22 = t17 * t2;
-		t25 = t17 * n;
-		t26 = M_PI * t2;
-		t27 = t8 * t8;
-		t28 = t26 * t27;
-		t31 = t2 * startBlockY;
-		t32 = t1 * t5;
-		t34 = t17 * t17;
-		t35 = t34 * t2;
-		t37 = 0.1e1 / cosh(t16);
-		t38 = t37 * t37;
-		t39 = t38 * n;
-		t40 = t39 * M_PI;
-		t41 = t2 * t8;
-		t42 = t41 * t5;
-		t45 = t38 * t2;
-		t46 = t27 * t5;
-		t47 = t45 * t46;
-		t48 = t2 * t2;
-		t49 = t38 * t48;
-		t50 = t49 * t9;
-		t53 = t8 * t5;
-		t54 = t22 * t53;
-		t56 = t48 * t2;
-		t57 = t17 * t56;
-		t60 = t17 * t48;
-		t61 = t60 * t9;
-		t63 = 0.6e1 * t16 * t19 - 0.2e1 * t22 * t4 + 0.4e1 * t25 * t28 - t31 * t32 - t35 * t4 + 0.4e1 * t40 * t42 + t47 + t50 + 0.2e1 * t39 * t26 + 0.4e1 * t54 + 0.2e1 * t57 * t4 + 0.2e1 * t61;
-		t64 = t34 * n;
-		t67 = t34 * t56;
-		t69 = t35 * t53;
-		t71 = t35 * t46;
-		t72 = t34 * t48;
-		t73 = t72 * t9;
-		t74 = t22 * startBlockY;
-		t75 = t1 * t27;
-		t78 = t48 * t7;
-		t83 = M_PI * t7;
-		t85 = t56 * startBlockY;
-		t88 = t2 * t27;
-		t93 = 0.2e1 * t64 * t26 + t67 * t4 + 0.2e1 * t69 + t71 + t73 - 0.2e1 * t74 * t75 - 0.2e1 * t1 * t78 + 0.2e1 * t1 * t6 - t3 * t83 + t85 * t1 - t31 * t1 + 0.2e1 * t1 * t88 + 0.4e1 * t1 * t41;
-		t98 = t31 * n;
-		t99 = t8 * M_PI;
-		t104 = t17 * startBlockY;
-		t105 = t1 * t7;
-		t108 = M_PI * t56;
-		t110 = t45 * t53;
-		t113 = t22 * t46;
-		t117 = t38 * t56;
-		t118 = t117 * t5;
-		t120 = t26 * t5;
-		t123 = 0.4e1 * t25 * t26 - t15 * t26 - 0.2e1 * t98 * t99 * t5 + t15 * t83 - 0.2e1 * t104 * t105 + t15 * t108 + 0.2e1 * t110 + t85 * t32 + 0.2e1 * t113 + 0.2e1 * t16 * t110 - t16 * t118 + 0.4e1 * t25 * t120;
-		t125 = t34 * t27 * t7;
-		t128 = t48 * t8 * t7;
-		t129 = t88 * t5;
-		t130 = t45 * t27;
-		t131 = t67 * t5;
-		t133 = t49 * t7;
-		t135 = M_PI * t38;
-		t140 = t26 * t8;
-		t143 = t104 * n;
-		t144 = t27 * t8;
-		t146 = M_PI * t144 * t7;
-		t149 = t99 * t7;
-		t153 = M_PI * t48 * t7;
-		t156 = -0.3e1 * t125 + t128 + t129 + t130 - t131 - t15 * t28 + t16 * t133 - t15 * t135 * t7 + t15 * t135 * t2 - 0.2e1 * t15 * t140 - 0.2e1 * t143 * t146 - 0.6e1 * t143 * t149 - 0.2e1 * t39 * t153;
-		t159 = t45 * startBlockY;
-		t160 = t1 * t46;
-		t162 = M_PI * t27;
-		t163 = t162 * t7;
-		t166 = t38 * startBlockY;
-		t170 = M_PI * t25;
-		t171 = startBlockY * t48;
-		t172 = t171 * t7;
-		t177 = t35 * t8;
-		t182 = t171 * t9;
-		t186 = t34 * t8 * t7;
-		t191 = -t159 * t160 - 0.6e1 * t143 * t163 - t166 * t105 + 0.2e1 * t39 * t120 + 0.2e1 * t170 * t172 + 0.2e1 * t1 * t129 - 0.2e1 * t16 * t177 - 0.2e1 * t40 * t128 + 0.2e1 * t170 * t182 + 0.3e1 * t16 * t186 + t117 * t4 - t45 * t4;
-		t192 = t35 * t5;
-		t194 = t166 * n;
-		t199 = t1 * t8;
-		t206 = t57 * t5;
-		t210 = t38 * t27 * t7;
-		t217 = -t16 * t192 - t194 * t146 + 0.2e1 * t57 * startBlockY * t32 - 0.4e1 * t74 * t199 - t56 - 0.4e1 * t16 * t54 - 0.3e1 * t9 - 0.2e1 * t57 + 0.2e1 * t16 * t206 - 0.3e1 * t210 + 0.2e1 * t1 * t2 - 0.4e1 * t25 * t153 + t16 * t131;
-		t225 = M_PI * t17;
-		t236 = t38 * t8 * t7;
-		t239 = t45 * t5;
-		t241 = t45 * t8;
-		t244 = -0.2e1 * t16 * t69 - 0.2e1 * t159 * t199 - 0.2e1 * t1 * t128 + 0.2e1 * t15 * t225 * t56 + t35 - 0.2e1 * t17 * t7 + 0.2e1 * t15 * t225 * t7 - t159 * t75 - 0.3e1 * t16 * t236 - t117 + t16 * t239 + 0.2e1 * t16 * t241;
-		t249 = t64 * M_PI;
-		t253 = t38 * t144 * t7;
-		t258 = t22 * t5;
-		t264 = -t38 * t7 + t6 - 0.3e1 * t194 * t163 + t40 * t172 + t249 * t172 - t3 * t146 - t16 * t253 - t15 * t135 * t56 - t159 * t32 + t2 - 0.2e1 * t16 * t258 + t249 * t182 + t67 * startBlockY * t32;
-		t270 = t60 * t7;
-		t275 = t17 * t144 * t7;
-		t279 = t72 * t7;
-		t282 = t34 * t144 * t7;
-		t284 = t35 * t27;
-		t286 = 0.4e1 * t64 * t140 - 0.2e1 * t16 * t270 + t16 * t130 + 0.2e1 * t16 * t275 + t40 * t182 - t16 * t279 + t16 * t282 + t284 - 0.3e1 * t186 + t192 + t279 - t282;
-		t287 = t35 * startBlockY;
-		t295 = t22 * t27;
-		t299 = t22 * t8;
-		t304 = t17 * t27 * t7;
-		t307 = -0.2e1 * t287 * t199 + 0.2e1 * t249 * t129 - t34 * t7 + 0.4e1 * t249 * t42 + 0.2e1 * t295 + 0.2e1 * t241 - 0.3e1 * t236 + t239 - t253 + 0.4e1 * t299 - t118 - 0.2e1 * t64 * t153 + 0.6e1 * t16 * t304;
-		t309 = t34 * startBlockY;
-		t317 = M_PI * t34;
-		t328 = t309 * n;
-		t330 = -t309 * t105 + t117 * startBlockY * t32 - t7 + 0.4e1 * t39 * t140 + 0.2e1 * t64 * t120 + t45 + t15 * t317 * t7 - 0.2e1 * t249 * t128 - 0.3e1 * t3 * t149 + 0.2e1 * t39 * t28 - 0.3e1 * t194 * t149 - t328 * t146;
-		t342 = t1 * t53;
-		t349 = -0.3e1 * t328 * t149 + t15 * t317 * t56 - t67 - t16 * t284 - 0.3e1 * t328 * t163 + 0.2e1 * t64 * t28 - t15 * t317 * t2 - 0.2e1 * t159 * t342 - t287 * t160 + t133 + 0.2e1 * t258 + 0.2e1 * t270 - 0.2e1 * t275;
-		t371 = -0.6e1 * t304 - t287 * t75 + 0.2e1 * t177 + 0.4e1 * t170 * t129 - 0.2e1 * t15 * t225 * t2 - t287 * t32 - 0.3e1 * t3 * t163 - 0.2e1 * t287 * t342 - 0.2e1 * t16 * t295 + 0.8e1 * t170 * t42 + t88 - 0.2e1 * t16 * t61;
-		t390 = -0.2e1 * t206 + 0.2e1 * t42 - 0.6e1 * t19 - 0.2e1 * t74 * t160 + 0.3e1 * t16 * t125 - 0.2e1 * t74 * t32 - 0.4e1 * t74 * t342 + 0.3e1 * t15 * t149 + 0.2e1 * t41 - t16 * t128 - 0.4e1 * t170 * t128 - t15 * t120 + t78;
-		t411 = -t16 * t129 - 0.2e1 * t16 * t42 - 0.4e1 * t16 * t299 - t16 * t73 + t15 * t108 * t5 - 0.3e1 * t16 * t210 + 0.4e1 * t1 * t42 + t16 * t50 + t15 * t146 - t15 * t153 - 0.2e1 * t31 * t199 - 0.2e1 * t16 * t113;
-		t430 = -t31 * t75 - t16 * t71 - t144 * t7 + 0.3e1 * t15 * t163 + t16 * t47 - t56 * t5 + 0.8e1 * t25 * t140 - t98 * t162 * t5 - 0.3e1 * t27 * t7 + t1 * t172 + t4 * t128 + 0.2e1 * t40 * t129 + 0.2e1 * t22;
-		t441 = n * n;
-		t444 = M_PI * M_PI;
-		t449 = pow(t2 + 0.1e1 + t8, 0.2e1);
-		t453 = pow(t2 - 0.1e1 - t8, 0.2e1);
-
-		u2a = (t2 + t6 - t7 - t9) * deltaRho * t13 * (t63 + t93 + t123 + t156 + t191 + t217 + t244 + t264 + t286 + t307 + t330 + t349 + t371 + t390 + t411 + t430) / t7 / (0.1e1 + t5) / t441 / n / t444 / M_PI / t449 / t453 / t37 / viscosity / (0.1e1 + t17) / 0.2e1;
-
-		t1 = n * M_PI;
-		t3 = sin(t1 * dx);
-		t5 = 0.1e1 / cosh(t1);
-		t6 = t5 * t5;
-		t7 = t6 * t6;
-		t8 = startBlockY * n;
-		t9 = t8 * M_PI;
-		t10 = 0.1e1 / cosh(t9);
-		t11 = t10 * t10;
-		t13 = y * n;
-		t14 = t13 * M_PI;
-		t15 = tanh(t14);
-		t16 = t15 * n;
-		t17 = t16 * M_PI;
-		t18 = t6 * t5;
-		t19 = tanh(t1);
-		t20 = t18 * t19;
-		t21 = tanh(t9);
-		t22 = t10 * t21;
-		t23 = t20 * t22;
-		t26 = 0.1e1 / cosh(t14);
-		t27 = t26 * t26;
-		t28 = t27 * t11;
-		t29 = t28 * t6;
-		t30 = t15 * t15;
-		t31 = t30 * t5;
-		t32 = t19 * t19;
-		t33 = t32 * t10;
-		t34 = t31 * t33;
-		t37 = t27 * n;
-		t38 = t37 * M_PI;
-		t39 = t32 * t19;
-		t40 = t5 * t39;
-		t41 = t40 * t10;
-		t44 = t20 * t10;
-		t47 = t21 * t21;
-		t48 = t27 * t47;
-		t49 = t48 * t6;
-		t50 = t6 * t19;
-		t52 = t15 * t6;
-		t53 = t52 * t19;
-		t56 = t30 * startBlockY;
-		t57 = t56 * n;
-		t58 = M_PI * t19;
-		t59 = t21 * t6;
-		t60 = t58 * t59;
-		t64 = t19 * t10;
-		t65 = t64 * t21;
-		t68 = t27 * t18;
-		t71 = t68 * t22;
-		t74 = -t7 * t11 - 0.4e1 * t17 * t23 - t29 + 0.6e1 * t14 * t34 - 0.2e1 * t38 * t41 - 0.2e1 * t1 * t44 - t49 + 0.2e1 * t50 - 0.4e1 * t14 * t53 - 0.4e1 * t57 * t60 - 0.2e1 * t1 * t18 * t65 + 0.2e1 * t68 * t65 + 0.2e1 * t14 * t71;
-		t75 = t30 * t18;
-		t76 = t75 * t22;
-		t78 = startBlockY * t6;
-		t79 = t78 * t19;
-		t84 = t15 * t18;
-		t85 = t84 * t22;
-		t87 = t27 * startBlockY;
-		t91 = M_PI * t32;
-		t92 = t91 * t59;
-		t95 = t15 * t5;
-		t96 = t39 * t10;
-		t97 = t95 * t96;
-		t99 = t95 * t64;
-		t101 = M_PI * t6;
-		t104 = t75 * t64;
-		t106 = t30 * t11;
-		t107 = t106 * t50;
-		t109 = t15 * startBlockY;
-		t110 = t109 * n;
-		t111 = M_PI * t11;
-		t112 = t6 * t32;
-		t113 = t111 * t112;
-		t116 = M_PI * t27;
-		t117 = t13 * t116;
-		t118 = t87 * n;
-		t121 = 0.2e1 * t76 - 0.4e1 * t17 * t79 - 0.2e1 * t7 * t21 + 0.4e1 * t85 - 0.6e1 * t87 * t1 * t32 - 0.2e1 * t57 * t92 - 0.4e1 * t97 - 0.12e2 * t99 + 0.4e1 * t16 * t101 + 0.2e1 * t104 + 0.2e1 * t107 + 0.2e1 * t110 * t113 + t117 + 0.4e1 * t118 * t60;
-		t123 = t11 * t6;
-		t126 = t5 * t19;
-		t127 = t126 * t22;
-		t130 = M_PI * t7;
-		t132 = t18 * t10;
-		t135 = t27 * t5;
-		t136 = t135 * t10;
-		t138 = t68 * t64;
-		t143 = t130 * t47;
-		t145 = t30 * t7;
-		t146 = t145 * t11;
-		t150 = t5 * t32;
-		t151 = t150 * t22;
-		t155 = 0.2e1 * t1 * t123 - 0.6e1 * t127 - t13 * t101 + t8 * t130 - 0.2e1 * t1 * t132 - 0.2e1 * t136 + 0.2e1 * t138 + 0.6e1 * t118 * t91 * t11 + t57 * t143 + t14 * t146 - 0.4e1 * t17 * t41 - 0.6e1 * t151 + 0.4e1 * t1 * t59;
-		t156 = t47 * t6;
-		t159 = t95 * t10;
-		t161 = M_PI * t47;
-		t162 = t161 * t112;
-		t165 = t40 * t22;
-		t175 = t130 * t11;
-		t177 = t91 * t6;
-		t183 = 0.2e1 * t1 * t156 - 0.4e1 * t159 - 0.2e1 * t110 * t162 - 0.2e1 * t38 * t165 - 0.2e1 * t165 - t7 + 0.2e1 * t110 * t143 + 0.2e1 * t118 * t92 + 0.2e1 * t38 * t79 + t13 * t175 - t57 * t177 + t118 * t177 - t14 * t49 - 0.12e2 * t95 * t65;
-		t186 = t59 * t19;
-		t189 = t32 * t32;
-		t190 = M_PI * t189;
-		t193 = t95 * t22;
-		t199 = t5 * t10;
-		t202 = t30 * t21;
-		t203 = t202 * t6;
-		t206 = t135 * t96;
-		t209 = t135 * t22;
-		t212 = t95 * t33;
-		t214 = t106 * t112;
-		t218 = t31 * t64;
-		t220 = 0.16e2 * t17 * t186 + t118 * t190 * t11 + 0.4e1 * t14 * t193 - 0.6e1 * t31 * t65 + 0.2e1 * t23 - 0.2e1 * t1 * t199 - 0.2e1 * t14 * t203 - 0.2e1 * t14 * t206 - 0.2e1 * t14 * t209 - 0.12e2 * t212 + t214 + 0.2e1 * t13 * t116 * t21 - 0.6e1 * t218;
-		t226 = t202 * t50;
-		t229 = t30 * t47;
-		t230 = t229 * t50;
-		t233 = t68 * t10;
-		t236 = t31 * t96;
-		t241 = t111 * t50;
-		t244 = t101 * t11;
-		t247 = t123 * t32;
-		t250 = t156 * t19;
-		t253 = t57 * t113 + t28 + 0.12e2 * t14 * t99 + 0.2e1 * t37 * t101 - 0.4e1 * t14 * t226 + 0.2e1 * t230 + 0.4e1 * t226 + 0.2e1 * t14 * t233 + 0.2e1 * t14 * t236 + 0.4e1 * t1 * t50 + 0.4e1 * t110 * t241 + 0.4e1 * t16 * t244 + 0.4e1 * t17 * t247 - 0.2e1 * t14 * t250;
-		t256 = t161 * t50;
-		t260 = t101 * t21;
-		t263 = t123 * t19;
-		t268 = t31 * t22;
-		t272 = t229 * t112;
-		t273 = t84 * t64;
-		t275 = M_PI * t30;
-		t276 = t13 * t275;
-		t280 = t15 * t21;
-		t281 = t280 * t50;
-		t283 = t118 * t162 - 0.4e1 * t110 * t256 - t118 * t113 + 0.4e1 * t37 * t260 - 0.2e1 * t14 * t263 - 0.4e1 * t14 * t85 - 0.2e1 * t268 - 0.2e1 * t14 * t136 + t272 + 0.4e1 * t273 + 0.2e1 * t276 * t165 - 0.4e1 * t193 + 0.8e1 * t281;
-		t285 = t30 * t6;
-		t286 = t285 * t32;
-		t288 = t156 * t32;
-		t291 = t101 * t19;
-		t294 = t48 * t50;
-		t296 = t30 * n;
-		t297 = t296 * M_PI;
-		t298 = t132 * t21;
-		t301 = t28 * t50;
-		t303 = t48 * t112;
-		t305 = t28 * t112;
-		t310 = -t8 * t175 - t14 * t286 + 0.2e1 * t1 * t288 + 0.8e1 * t16 * t291 - 0.2e1 * t294 + t156 - 0.2e1 * t297 * t298 - 0.2e1 * t301 - t303 - 0.2e1 * t199 - t305 + 0.2e1 * t71 - 0.2e1 * t276 * t23 - t9 * t288;
-		t314 = t59 * t32;
-		t321 = t135 * t33;
-		t326 = t33 * t21;
-		t333 = t27 * t21;
-		t334 = t333 * t50;
-		t338 = t15 * t11;
-		t339 = t338 * t50;
-		t341 = t27 * t189;
-		t342 = 0.4e1 * t1 * t314 - 0.2e1 * t87 * t1 * t21 - t7 * t47 - 0.6e1 * t321 - 0.4e1 * t87 * t1 * t39 - 0.6e1 * t135 * t326 - t14 * t247 + 0.2e1 * t14 * t165 - 0.2e1 * t236 - 0.4e1 * t334 + 0.2e1 * t57 * t241 + 0.4e1 * t339 + t341;
-		t343 = t15 * t47;
-		t344 = t343 * t112;
-		t346 = t343 * t50;
-		t348 = M_PI * t15;
-		t349 = t13 * t348;
-		t365 = t161 * t6;
-		t372 = M_PI * startBlockY * t6;
-		t374 = 0.2e1 * t344 + 0.4e1 * t346 + 0.12e2 * t349 * t151 - 0.2e1 * t14 * t44 - 0.2e1 * t57 * t256 + 0.4e1 * t1 * t250 + 0.8e1 * t1 * t186 + 0.8e1 * t17 * t263 - 0.2e1 * t57 * t260 - 0.6e1 * t34 - t13 * t365 - 0.2e1 * t1 * t41 - 0.2e1 * t14 * t107 - t296 * t372;
-		t379 = t150 * t10;
-		t388 = t341 * t47;
-		t390 = t96 * t21;
-		t394 = M_PI * t18 * t10;
-		t402 = -0.2e1 * t14 * t23 + t57 * t244 - 0.6e1 * t297 * t379 + 0.2e1 * t296 * t244 - 0.2e1 * t297 * t23 - t1 * t78 + 0.2e1 * t59 + t14 * t388 - 0.2e1 * t135 * t390 - 0.2e1 * t296 * t394 - 0.2e1 * t110 * t175 - t87 * t1 - 0.2e1 * t297 * t44;
-		t403 = t27 * t39;
-		t404 = t403 * t47;
-		t409 = t15 * t7;
-		t410 = t409 * t47;
-		t414 = t333 * t112;
-		t425 = t130 * t21;
-		t429 = t341 * t11;
-		t431 = 0.4e1 * t14 * t404 + 0.2e1 * t296 * t365 - 0.2e1 * t410 - 0.2e1 * t16 * t372 - 0.2e1 * t414 - 0.4e1 * t17 * t165 + t112 + t8 * t143 - 0.6e1 * t38 * t379 - t14 * t214 + 0.4e1 * t13 * t116 * t19 + 0.2e1 * t8 * t425 + 0.2e1 * t132 + t14 * t429;
-		t447 = t126 * t10;
-		t450 = t199 * t21;
-		t455 = M_PI * t5 * t10;
-		t460 = t1 * t5;
-		t463 = -0.6e1 * t118 * t91 * t47 - 0.6e1 * t38 * t151 - 0.2e1 * t297 * t41 - 0.4e1 * t17 * t298 - 0.6e1 * t297 * t151 + t48 - 0.6e1 * t135 * t65 - 0.6e1 * t38 * t447 - 0.2e1 * t1 * t450 + t9 * t247 - 0.2e1 * t37 * t455 - 0.6e1 * t1 * t379 - 0.6e1 * t460 * t326;
-		t464 = t135 * t64;
-		t467 = t403 * t21;
-		t491 = -0.6e1 * t464 + t37 * t372 + 0.8e1 * t467 - 0.6e1 * t1 * t447 - 0.4e1 * t14 * t273 + 0.2e1 * t296 * t177 + 0.2e1 * t37 * t244 - 0.6e1 * t460 * t65 + 0.6e1 * t14 * t151 + 0.8e1 * t16 * t260 - 0.2e1 * t460 * t390 + 0.4e1 * t296 * t291 - 0.12e2 * t95 * t326 - 0.2e1 * t37 * t394;
-		t501 = t202 * t112;
-		t512 = t1 * t7;
-		t518 = t27 * t19;
-		t519 = t518 * t11;
-		t522 = -0.4e1 * t16 * t394 - 0.4e1 * t110 * t260 - 0.4e1 * t95 * t390 - 0.2e1 * t1 * t79 - 0.2e1 * t14 * t501 + 0.2e1 * t297 * t288 - 0.2e1 * t14 * t314 + 0.4e1 * t84 * t65 + 0.6e1 * t276 * t127 + t56 * t512 - 0.2e1 * t38 * t298 + 0.2e1 * t37 * t365 + 0.4e1 * t14 * t519;
-		t540 = t84 * t10;
-		t550 = -0.6e1 * t14 * t464 - t8 * t177 + 0.2e1 * t110 * t244 - 0.4e1 * t14 * t339 - 0.2e1 * t1 * t298 + 0.12e2 * t14 * t212 - 0.2e1 * t38 * t44 - t13 * t177 - 0.4e1 * t87 * t1 * t19 + 0.4e1 * t540 - 0.2e1 * t297 * t165 + 0.2e1 * t296 * t101 - 0.2e1 * t13 * t394 - 0.2e1 * t9 * t314;
-		t557 = t338 * t112;
-		t567 = t518 * t21;
-		t582 = -0.4e1 * t17 * t450 - 0.2e1 * t14 * t557 + 0.4e1 * t110 * t425 + 0.2e1 * t14 * t268 + 0.2e1 * t38 * t247 + t13 * t143 + 0.8e1 * t14 * t567 - 0.4e1 * t9 * t186 + 0.2e1 * t13 * t348 * t7 - 0.2e1 * t209 + 0.4e1 * t14 * t97 + 0.2e1 * t57 * t425 - 0.12e2 * t17 * t379;
-		t587 = t145 * t47;
-		t598 = t145 * t21;
-		t609 = -t57 * t162 - 0.4e1 * t14 * t334 - t57 * t175 + t14 * t587 - 0.4e1 * t14 * t540 - 0.12e2 * t17 * t151 - t146 + 0.2e1 * t14 * t410 - 0.12e2 * t118 * t91 * t21 + 0.2e1 * t14 * t598 + 0.4e1 * t38 * t263 - 0.2e1 * t297 * t450 + 0.4e1 * t14 * t159 + 0.2e1 * t38 * t288;
-		t611 = t52 * t32;
-		t614 = t27 * t32;
-		t615 = t614 * t21;
-		t618 = M_PI * t39;
-		t634 = t285 * t19;
-		t637 = t280 * t112;
-		t639 = t27 * t6;
-		t640 = t639 * t32;
-		t642 = t280 * t6;
-		t645 = -0.2e1 * t14 * t611 + 0.12e2 * t14 * t615 + 0.4e1 * t118 * t618 * t11 - 0.2e1 * t118 * t241 - t145 + 0.4e1 * t118 * t58 * t11 + 0.2e1 * t118 * t256 - 0.2e1 * t14 * t414 + 0.4e1 * t13 * t116 * t39 - 0.2e1 * t14 * t634 + 0.4e1 * t637 - t14 * t640 - 0.4e1 * t14 * t642;
-		t654 = t333 * t6;
-		t673 = -0.2e1 * t13 * t260 - t13 * t275 * t6 + 0.4e1 * t296 * t260 - 0.6e1 * t117 * t151 - 0.2e1 * t14 * t654 + 0.6e1 * t14 * t218 + 0.4e1 * t349 * t165 + 0.4e1 * t38 * t314 - 0.12e2 * t17 * t447 - 0.12e2 * t17 * t127 + 0.2e1 * t13 * t455 + t27 - 0.4e1 * t349 * t23 - 0.6e1 * t31 * t326;
-		t682 = t409 * t11;
-		t702 = t13 * t275 * t7 - 0.2e1 * t117 * t165 + 0.6e1 * t276 * t151 - 0.2e1 * t682 - 0.8e1 * t14 * t281 + 0.2e1 * t297 * t247 - 0.2e1 * t110 * t365 - 0.2e1 * t14 * t230 - 0.4e1 * t14 * t637 + 0.4e1 * t38 * t250 - t87 * t1 * t47 + 0.2e1 * t117 * t23 - 0.2e1 * t8 * t260;
-		t705 = t518 * t47;
-		t716 = t343 * t6;
-		t719 = t614 * t11;
-		t721 = t403 * t11;
-		t726 = t409 * t21;
-		t728 = t338 * t6;
-		t731 = 0.2e1 * t13 * t425 + 0.4e1 * t14 * t705 - t13 * t116 * t6 - 0.8e1 * t110 * t60 - 0.4e1 * t16 * t455 - 0.2e1 * t14 * t76 - 0.2e1 * t14 * t716 + 0.6e1 * t719 + 0.4e1 * t721 + 0.4e1 * t297 * t314 + 0.4e1 * t642 - 0.4e1 * t726 + 0.2e1 * t728 + 0.2e1 * t716;
-		t734 = t106 * t6;
-		t735 = t229 * t6;
-		t740 = t614 * t47;
-		t742 = t31 * t10;
-		t744 = 0.2e1 * t203 + t734 + t735 + t247 + 0.2e1 * t263 - 0.2e1 * t598 - 0.2e1 * t450 - t587 - t14 * t272 + 0.6e1 * t740 + t429 - 0.2e1 * t742 + t286;
-		t747 = t75 * t10;
-		t753 = t341 * t21;
-		t761 = -0.2e1 * t41 - 0.6e1 * t379 + 0.2e1 * t747 + 0.4e1 * t186 + 0.2e1 * t314 + 0.2e1 * t611 - 0.2e1 * t654 + 0.2e1 * t753 - t14 * t735 + 0.2e1 * t250 + t288 + 0.2e1 * t1 * t6 + 0.4e1 * t705 + 0.4e1 * t519;
-		t771 = t639 * t19;
-		t779 = 0.2e1 * t233 + 0.12e2 * t615 + 0.8e1 * t567 + 0.6e1 * t14 * t127 + 0.2e1 * t634 - 0.2e1 * t771 + 0.4e1 * t53 + 0.4e1 * t404 + t388 + 0.2e1 * t44 + 0.8e1 * t38 * t186 + 0.2e1 * t298 + t123;
-		t801 = -0.4e1 * t14 * t346 - 0.6e1 * t447 - 0.6e1 * t38 * t127 + 0.6e1 * t14 * t740 - t14 * t29 + 0.2e1 * t1 * t247 - t14 * t734 - 0.4e1 * t17 * t44 - t640 + t8 * t244 - 0.2e1 * t14 * t344 - 0.4e1 * t110 * t92 + 0.2e1 * t557 - 0.2e1 * t31 * t390;
-		t830 = -0.4e1 * t118 * t58 * t47 - 0.4e1 * t14 * t186 + 0.2e1 * t9 * t263 - 0.2e1 * t9 * t250 + 0.2e1 * t14 * t138 - 0.2e1 * t14 * t104 + 0.4e1 * t17 * t288 + 0.2e1 * t501 + 0.6e1 * t13 * t116 * t32 + 0.2e1 * t37 * t177 + 0.6e1 * t14 * t379 + 0.2e1 * t14 * t41 - t118 * t190 * t47;
-		t854 = -t87 * t1 * t189 - 0.6e1 * t14 * t321 + 0.2e1 * t333 + t13 * t130 + 0.2e1 * t75 * t65 + 0.8e1 * t17 * t314 + 0.2e1 * t109 * t512 + 0.4e1 * t297 * t250 - t8 * t365 + 0.4e1 * t14 * t721 + t6 + 0.4e1 * t16 * t365 - 0.6e1 * t297 * t447 - 0.2e1 * t14 * t301;
-		t883 = 0.4e1 * t37 * t291 - 0.2e1 * t296 * t455 + 0.8e1 * t17 * t250 - 0.2e1 * t118 * t190 * t21 + t87 * t1 * t11 + 0.12e2 * t349 * t127 + 0.6e1 * t14 * t719 + 0.2e1 * t52 + 0.2e1 * t14 * t450 - 0.2e1 * t38 * t23 + 0.4e1 * t297 * t263 + 0.2e1 * t1 * t112 - 0.2e1 * t297 * t79;
-		t910 = -0.2e1 * t13 * t291 - 0.6e1 * t117 * t127 + t285 - 0.2e1 * t13 * t348 * t6 + 0.8e1 * t297 * t186 - t13 * t244 - t57 * t365 - 0.4e1 * t118 * t618 * t47 + 0.2e1 * t14 * t753 + t13 * t116 * t11 + 0.2e1 * t118 * t260 + 0.6e1 * t14 * t447 - 0.2e1 * t206 - 0.8e1 * t118 * t618 * t21;
-		t936 = -0.2e1 * t14 * t771 + 0.2e1 * t14 * t742 + t13 * t116 * t47 - 0.6e1 * t297 * t127 - 0.2e1 * t14 * t728 - t14 * t288 - 0.2e1 * t38 * t450 + 0.6e1 * t614 - 0.2e1 * t14 * t294 + 0.4e1 * t518 - 0.2e1 * t110 * t177 - 0.2e1 * t14 * t747 - 0.8e1 * t118 * t58 * t21;
-		t957 = 0.2e1 * t14 * t682 + 0.4e1 * t14 * t726 + 0.4e1 * t16 * t177 + t13 * t116 * t189 + 0.4e1 * t403 - 0.2e1 * t14 * t298 - t14 * t303 - t118 * t244 - t639 + 0.4e1 * t1 * t263 - 0.2e1 * t409 + t118 * t365 - t14 * t305 + 0.8e1 * t14 * t467;
-		t969 = pow(t5 + 0.1e1 + t19, 0.2e1);
-		t974 = pow(t5 - 0.1e1 - t19, 0.2e1);
-		t978 = n * n;
-		t982 = M_PI * M_PI;
-
-		u2b = deltaRho * t3 * (t910 + t74 + t582 + t310 + t830 + t491 + t883 + t645 + t342 + t957 + t283 + t673 + t220 + t121 + t183 + t609 + t550 + t731 + t374 + t702 + t402 + t431 + t854 + t522 + t761 + t744 + t779 + t463 + t155 + t253 + t936 + t801) / t10 / (0.1e1 + t21) / t969 / t974 / t26 / t978 / n / t982 / M_PI / viscosity / (0.1e1 + t15) / 0.2e1;
-
-		t1 = n * M_PI;
-		t2 = 0.1e1 / cosh(t1);
-		t3 = startBlockY * n;
-		t4 = t3 * M_PI;
-		t5 = tanh(t4);
-		t6 = t2 * t5;
-		t7 = 0.1e1 / cosh(t4);
-		t8 = tanh(t1);
-		t9 = t8 * t7;
-		t13 = sin(t1 * dx);
-		t15 = y * n;
-		t16 = t15 * M_PI;
-		t17 = tanh(t16);
-		t18 = t17 * t17;
-		t19 = t18 * t2;
-		t20 = t19 * startBlockY;
-		t21 = t8 * t8;
-		t22 = t21 * t5;
-		t23 = t1 * t22;
-		t25 = t2 * t2;
-		t26 = t25 * t2;
-		t27 = t18 * t26;
-		t29 = t1 * t5;
-		t31 = 0.1e1 / cosh(t16);
-		t32 = t31 * t31;
-		t33 = t32 * n;
-		t34 = M_PI * t2;
-		t35 = t34 * t21;
-		t38 = M_PI * t18;
-		t41 = t17 * t26;
-		t45 = t17 * startBlockY;
-		t46 = t45 * n;
-		t47 = M_PI * t21;
-		t48 = t47 * t7;
-		t51 = t19 * t8;
-		t53 = t19 * t21;
-		t57 = M_PI * t17;
-		t62 = t18 * n;
-		t65 = -t20 * t23 + t27 * startBlockY * t29 + 0.2e1 * t33 * t35 + t15 * t38 * t26 + 0.2e1 * t41 * startBlockY * t29 - 0.6e1 * t46 * t48 + 0.4e1 * t51 + 0.2e1 * t53 - t15 * t38 * t2 - 0.2e1 * t15 * t57 * t2 - 0.2e1 * t27 + 0.2e1 * t62 * t35;
-		t66 = t62 * M_PI;
-		t67 = t2 * t21;
-		t68 = t67 * t5;
-		t71 = t32 * t2;
-		t72 = t71 * startBlockY;
-		t73 = t8 * t5;
-		t74 = t1 * t73;
-		t77 = t17 * n;
-		t78 = t77 * M_PI;
-		t82 = t17 * t21 * t7;
-		t87 = t18 * startBlockY;
-		t88 = t87 * n;
-		t89 = M_PI * t8;
-		t90 = t89 * t7;
-		t93 = t21 * t8;
-		t97 = t2 * t8;
-		t98 = t97 * t5;
-		t102 = t17 * t2;
-		t103 = t102 * startBlockY;
-		t110 = 0.2e1 * t66 * t68 - 0.2e1 * t72 * t74 + 0.4e1 * t78 * t68 + 0.6e1 * t16 * t82 + 0.2e1 * t1 * t68 - 0.3e1 * t88 * t90 - 0.2e1 * t93 * t7 + 0.2e1 * t2 + 0.8e1 * t78 * t98 - 0.6e1 * t9 - 0.2e1 * t103 * t29 - 0.4e1 * t103 * t74 - 0.2e1 * t103 * t23;
-		t113 = t25 * t8 * t7;
-		t116 = t102 * t73;
-		t123 = M_PI * t26;
-		t127 = M_PI * t93 * t7;
-		t132 = M_PI * t25 * t7;
-		t134 = t33 * M_PI;
-		t140 = -t16 * t113 - t16 * t68 - 0.4e1 * t16 * t116 - 0.4e1 * t17 * t7 - 0.2e1 * t16 * t98 + t15 * t123 * t5 + t15 * t127 + 0.3e1 * t15 * t48 - t15 * t132 + 0.2e1 * t134 * t68 + 0.4e1 * t134 * t98 + 0.4e1 * t102;
-		t141 = t34 * t5;
-		t145 = t18 * t25;
-		t146 = t145 * t7;
-		t148 = t32 * startBlockY;
-		t149 = t148 * n;
-		t154 = t25 * t7;
-		t156 = t102 * t22;
-		t159 = t18 * t93 * t7;
-		t166 = t102 * t21;
-		t169 = t102 * t8;
-		t172 = 0.2e1 * t62 * t141 - t72 * t23 - t16 * t146 - 0.3e1 * t149 * t48 - 0.3e1 * t88 * t48 + 0.2e1 * t154 + 0.4e1 * t156 + t16 * t159 + t15 * t38 * t7 + 0.4e1 * t77 * t34 - t15 * t34 - 0.2e1 * t16 * t166 - 0.4e1 * t16 * t169;
-		t177 = t17 * t8 * t7;
-		t180 = M_PI * t32;
-		t183 = startBlockY * t25;
-		t184 = t183 * t7;
-		t186 = t1 * t8;
-		t192 = t32 * t26;
-		t193 = t192 * t5;
-		t196 = t32 * t21 * t7;
-		t201 = 0.2e1 * t6 + 0.6e1 * t16 * t177 - t15 * t180 * t26 + t66 * t184 - 0.2e1 * t20 * t186 + 0.4e1 * t98 - 0.12e2 * t177 + 0.8e1 * t169 - 0.2e1 * t193 - 0.6e1 * t196 + 0.2e1 * t1 * t2 + 0.2e1 * t67;
-		t202 = t71 * t73;
-		t205 = M_PI * t7;
-		t218 = t145 * t9;
-		t226 = 0.2e1 * t16 * t202 + t15 * t205 - t15 * t180 * t7 + t15 * t180 * t2 + 0.4e1 * t202 + t15 * t123 - 0.3e1 * t149 * t90 - 0.2e1 * t33 * t132 + t134 * t184 - t16 * t218 - 0.2e1 * t72 * t186 - 0.2e1 * t1 * t154 - 0.2e1 * t134 * t113;
-		t228 = t1 * t7;
-		t235 = t2 * startBlockY;
-		t236 = t235 * n;
-		t244 = t19 * t22;
-		t248 = t26 * startBlockY;
-		t252 = -t148 * t228 + 0.2e1 * t33 * t141 - t20 * t29 + 0.2e1 * t1 * t6 - t236 * t47 * t5 - t235 * t29 - 0.2e1 * t236 * t89 * t5 - t3 * t205 - t16 * t244 - 0.2e1 * t20 * t74 + t248 * t1 + 0.4e1 * t66 * t98;
-		t257 = t34 * t8;
-		t265 = t17 * t25;
-		t266 = t265 * t9;
-		t269 = t1 * t21;
-		t277 = t102 * t5;
-		t280 = -t235 * t1 - t149 * t127 + 0.2e1 * t1 * t67 + 0.4e1 * t62 * t257 - t72 * t29 - 0.2e1 * t16 * t51 + 0.4e1 * t1 * t97 - 0.2e1 * t16 * t266 - 0.2e1 * t103 * t269 - 0.2e1 * t45 * t228 + 0.4e1 * t77 * t141 - t72 * t269 - 0.2e1 * t16 * t277;
-		t286 = t265 * t7;
-		t289 = t71 * t21;
-		t291 = t41 * t5;
-		t296 = t32 * t25;
-		t297 = t296 * t7;
-		t307 = -0.2e1 * t1 * t113 - 0.2e1 * t16 * t286 + t16 * t289 + 0.2e1 * t16 * t291 + 0.2e1 * t71 - t16 * t193 + t16 * t297 - t3 * t127 - 0.2e1 * t16 * t156 - 0.2e1 * t235 * t186 - 0.3e1 * t3 * t90 - t19 * t4;
-		t310 = t18 * t8 * t7;
-		t331 = t27 * t4 + 0.3e1 * t16 * t310 + 0.2e1 * t15 * t57 * t26 - 0.2e1 * t192 + 0.8e1 * t77 * t257 + 0.2e1 * t78 * t184 - t16 * t53 + 0.4e1 * t33 * t257 + 0.3e1 * t15 * t90 - t15 * t141 - 0.4e1 * t78 * t113 + 0.2e1 * t244 - t20 * t269;
-		t334 = t19 * t5;
-		t339 = t18 * t21 * t7;
-		t341 = t27 * t5;
-		t347 = t71 * t8;
-		t350 = t32 * t8 * t7;
-		t352 = -0.6e1 * t310 + 0.2e1 * t334 + 0.2e1 * t146 - 0.2e1 * t159 - 0.6e1 * t339 - 0.2e1 * t341 + 0.2e1 * t113 + 0.2e1 * t68 + 0.2e1 * t289 + 0.4e1 * t166 + 0.4e1 * t347 - 0.6e1 * t350;
-		t353 = t71 * t5;
-		t356 = t32 * t93 * t7;
-		t362 = t17 * t93 * t7;
-		t366 = t19 * t73;
-		t369 = t183 * t9;
-		t376 = 0.2e1 * t353 - 0.2e1 * t356 + 0.2e1 * t297 + 0.4e1 * t277 + 0.4e1 * t286 - 0.4e1 * t362 - 0.12e2 * t82 - 0.4e1 * t291 + 0.4e1 * t366 + 0.2e1 * t218 + 0.2e1 * t78 * t369 + 0.2e1 * t62 * t34 - 0.6e1 * t21 * t7;
-		t399 = -0.2e1 * t62 * t132 - 0.2e1 * t66 * t113 + 0.2e1 * t15 * t57 * t7 - 0.3e1 * t16 * t350 + t16 * t353 - 0.2e1 * t32 * t7 - 0.4e1 * t41 + 0.4e1 * t97 + 0.8e1 * t116 - 0.4e1 * t103 * t186 - 0.3e1 * t3 * t48 - t87 * t228;
-		t405 = t71 * t22;
-		t409 = t296 * t9;
-		t421 = -0.2e1 * t26 * t5 + t192 * startBlockY * t29 + t134 * t369 + 0.2e1 * t405 + 0.4e1 * t266 + 0.2e1 * t19 + 0.2e1 * t409 - 0.2e1 * t18 * t7 - t16 * t334 + 0.2e1 * t33 * t34 + 0.4e1 * t77 * t35 + 0.4e1 * t1 * t98 + t66 * t369;
-		t442 = 0.2e1 * t16 * t362 - t15 * t35 - 0.2e1 * t15 * t257 - 0.2e1 * t46 * t127 - 0.6e1 * t46 * t90 - t88 * t127 - 0.3e1 * t16 * t196 + t16 * t409 + 0.3e1 * t16 * t339 - 0.2e1 * t7 - 0.2e1 * t102 * t4 - t235 * t269;
-		t460 = -0.2e1 * t16 * t366 + t16 * t341 - 0.4e1 * t77 * t132 + t1 * t184 + 0.2e1 * t16 * t347 + t4 * t113 + t248 * t29 - t71 * t4 - 0.2e1 * t26 + 0.2e1 * t41 * t4 - t16 * t356 + t16 * t405 + t192 * t4;
-		t471 = n * n;
-		t474 = M_PI * M_PI;
-		t479 = pow(t2 + 0.1e1 + t8, 0.2e1);
-		t483 = pow(t2 - 0.1e1 - t8, 0.2e1);
-
-		u3a = -(t2 + t6 - t7 - t9) * deltaRho * t13 * (t65 + t110 + t140 + t172 + t201 + t226 + t252 + t280 + t307 + t331 + t352 + t376 + t399 + t421 + t442 + t460) / t7 / (0.1e1 + t5) / t471 / n / t474 / M_PI / t479 / t483 / t31 / (0.1e1 + t17) / 0.2e1;
-
-		t1 = n * M_PI;
-		t3 = sin(t1 * dx);
-		t5 = y * n;
-		t6 = t5 * M_PI;
-		t7 = tanh(t6);
-		t8 = t7 * t7;
-		t9 = 0.1e1 / cosh(t1);
-		t10 = t8 * t9;
-		t11 = tanh(t1);
-		t12 = t11 * t11;
-		t13 = startBlockY * n;
-		t14 = t13 * M_PI;
-		t15 = 0.1e1 / cosh(t14);
-		t16 = t12 * t15;
-		t17 = t10 * t16;
-		t20 = t9 * t9;
-		t21 = t20 * t20;
-		t22 = t8 * t21;
-		t23 = t15 * t15;
-		t24 = t22 * t23;
-		t26 = tanh(t14);
-		t27 = t22 * t26;
-		t30 = t10 * t15;
-		t33 = 0.1e1 / cosh(t6);
-		t34 = t33 * t33;
-		t35 = t34 * t11;
-		t36 = t35 * t26;
-		t39 = t34 * n;
-		t40 = t39 * M_PI;
-		t41 = t26 * t20;
-		t42 = t41 * t11;
-		t45 = t8 * n;
-		t46 = t45 * M_PI;
-		t47 = t26 * t26;
-		t48 = t47 * t20;
-		t49 = t48 * t11;
-		t52 = t23 * t20;
-		t54 = t34 * t47;
-		t55 = t54 * t20;
-		t57 = t7 * t9;
-		t58 = t15 * t26;
-		t59 = t57 * t58;
-		t64 = M_PI * t7;
-		t65 = t5 * t64;
-		t66 = t9 * t11;
-		t67 = t66 * t58;
-		t70 = t8 * t47;
-		t71 = t20 * t12;
-		t72 = t70 * t71;
-		t74 = 0.6e1 * t6 * t17 + t6 * t24 + 0.2e1 * t6 * t27 + 0.2e1 * t6 * t30 + 0.8e1 * t6 * t36 + 0.8e1 * t40 * t42 + 0.4e1 * t46 * t49 + 0.2e1 * t52 - t6 * t55 + 0.4e1 * t6 * t59 - 0.2e1 * t6 * t49 + 0.12e2 * t65 * t67 - t6 * t72;
-		t75 = t34 * startBlockY;
-		t76 = t75 * n;
-		t77 = t12 * t11;
-		t78 = M_PI * t77;
-		t82 = t9 * t15;
-		t83 = t82 * t26;
-		t86 = t48 * t12;
-		t88 = M_PI * t12;
-		t93 = t7 * startBlockY;
-		t94 = t93 * n;
-		t95 = M_PI * t11;
-		t96 = t95 * t41;
-		t99 = t20 * t9;
-		t100 = t8 * t99;
-		t101 = t100 * t58;
-		t104 = t34 * t26;
-		t105 = t104 * t71;
-		t108 = t7 * t20;
-		t109 = t108 * t11;
-		t112 = t7 * n;
-		t113 = t112 * M_PI;
-		t114 = startBlockY * t20;
-		t115 = t114 * t11;
-		t118 = t1 * t9;
-		t119 = t11 * t15;
-		t120 = t119 * t26;
-		t123 = t99 * t11;
-		t124 = t123 * t58;
-		t127 = t77 * t15;
-		t128 = t10 * t127;
-		t130 = t52 * t12;
-		t133 = -0.8e1 * t76 * t78 * t26 - 0.2e1 * t40 * t83 - t6 * t86 - 0.12e2 * t76 * t88 * t26 + 0.2e1 * t54 - 0.8e1 * t94 * t96 - 0.2e1 * t6 * t101 - 0.2e1 * t6 * t105 - 0.4e1 * t6 * t109 - 0.4e1 * t113 * t115 - 0.6e1 * t118 * t120 - 0.2e1 * t6 * t124 - 0.4e1 * t128 + 0.2e1 * t40 * t130;
-		t138 = t8 * startBlockY;
-		t139 = t138 * n;
-		t140 = M_PI * t21;
-		t141 = t140 * t47;
-		t146 = M_PI * t20;
-		t151 = t57 * t127;
-		t153 = t57 * t119;
-		t157 = t100 * t119;
-		t159 = t34 * t9;
-		t160 = t159 * t119;
-		t164 = 0.6e1 * t76 * t88 * t23 + t139 * t141 + 0.4e1 * t101 - t1 * t114 - t75 * t1 + 0.2e1 * t45 * t146 + 0.2e1 * t1 * t71 - 0.8e1 * t151 - 0.24e2 * t153 + 0.4e1 * t112 * t146 + 0.4e1 * t157 - 0.12e2 * t160 + 0.6e1 * t6 * t67;
-		t165 = t159 * t58;
-		t167 = t159 * t127;
-		t169 = t127 * t26;
-		t173 = t34 * t99;
-		t174 = t173 * t119;
-		t178 = t7 * t99;
-		t179 = t178 * t58;
-		t186 = t173 * t58;
-		t188 = t9 * t77;
-		t189 = t188 * t58;
-		t192 = t99 * t15;
-		t193 = t192 * t26;
-		t196 = t20 * t11;
-		t197 = t104 * t196;
-		t199 = -0.4e1 * t165 - 0.4e1 * t167 - 0.4e1 * t159 * t169 - 0.4e1 * t105 + 0.2e1 * t6 * t174 + 0.2e1 * t20 + 0.8e1 * t179 + 0.4e1 * t174 + 0.2e1 * t6 * t128 - 0.2e1 * t6 * t157 + 0.4e1 * t186 - 0.4e1 * t113 * t189 - 0.4e1 * t113 * t193 - 0.8e1 * t197;
-		t205 = t10 * t119;
-		t208 = t35 * t47;
-		t211 = M_PI * t23;
-		t212 = t211 * t71;
-		t216 = t7 * t23;
-		t217 = t216 * t71;
-		t219 = t8 * t26;
-		t220 = t219 * t71;
-		t222 = t57 * t16;
-		t225 = t10 * t58;
-		t230 = t7 * t26;
-		t231 = t230 * t71;
-		t233 = 0.4e1 * t173 * t120 + t5 * t140 + 0.6e1 * t6 * t205 + 0.4e1 * t6 * t208 + t139 * t212 + 0.2e1 * t94 * t212 + 0.4e1 * t217 + 0.4e1 * t220 - 0.24e2 * t222 + 0.2e1 * t72 - 0.4e1 * t225 - 0.6e1 * t75 * t1 * t12 + 0.8e1 * t231;
-		t234 = t9 * t12;
-		t235 = t234 * t15;
-		t238 = t16 * t26;
-		t241 = t66 * t15;
-		t244 = t52 * t11;
-		t250 = M_PI * t26 * t20;
-		t253 = t211 * t20;
-		t255 = t88 * t41;
-		t258 = M_PI * t34;
-		t259 = t5 * t258;
-		t262 = t88 * t20;
-		t266 = t12 * t12;
-		t267 = t34 * t266;
-		t268 = t267 * t23;
-		t272 = -0.6e1 * t1 * t235 - 0.6e1 * t118 * t238 - 0.6e1 * t1 * t241 + 0.4e1 * t40 * t244 + 0.4e1 * t76 * t96 - 0.2e1 * t139 * t250 + t139 * t253 + 0.2e1 * t76 * t255 + t259 + 0.16e2 * t113 * t42 + t76 * t262 - 0.12e2 * t10 * t238 + t6 * t268 + 0.12e2 * t6 * t153;
-		t276 = t8 * t23;
-		t277 = t276 * t196;
-		t279 = M_PI * t47;
-		t280 = t279 * t20;
-		t294 = t219 * t20;
-		t299 = 0.4e1 * t112 * t253 + 0.4e1 * t277 - t5 * t280 - 0.6e1 * t46 * t235 + 0.2e1 * t1 * t52 - 0.12e2 * t67 - t5 * t146 - t75 * t1 * t47 - 0.2e1 * t1 * t115 + 0.12e2 * t6 * t222 - 0.2e1 * t6 * t294 - 0.4e1 * t82 - t13 * t280;
-		t300 = t234 * t58;
-		t308 = t140 * t26;
-		t313 = M_PI * startBlockY * t20;
-		t321 = t279 * t71;
-		t324 = M_PI * t99 * t15;
-		t329 = 0.6e1 * t6 * t300 - 0.2e1 * t40 * t124 - 0.2e1 * t1 * t192 + t13 * t141 + 0.2e1 * t13 * t308 - 0.12e2 * t300 - t45 * t313 + 0.4e1 * t1 * t41 + 0.2e1 * t1 * t48 + t13 * t140 - t76 * t212 + t76 * t321 - 0.2e1 * t39 * t324 + 0.2e1 * t39 * t280;
-		t336 = t41 * t12;
-		t342 = t70 * t196;
-		t344 = t219 * t196;
-		t346 = t276 * t71;
-		t350 = t188 * t15;
-		t359 = -0.4e1 * t6 * t179 + 0.4e1 * t124 + 0.4e1 * t1 * t336 - 0.4e1 * t189 + 0.2e1 * t76 * t250 + 0.4e1 * t342 + 0.8e1 * t344 + 0.2e1 * t346 - 0.2e1 * t1 * t82 - 0.2e1 * t46 * t350 + 0.2e1 * t39 * t146 - 0.2e1 * t6 * t244 + 0.4e1 * t1 * t196;
-		t365 = t230 * t196;
-		t367 = t159 * t16;
-		t369 = t34 * t23;
-		t370 = t369 * t71;
-		t374 = t369 * t196;
-		t376 = t54 * t71;
-		t378 = t54 * t196;
-		t380 = t178 * t119;
-		t382 = t211 * t196;
-		t385 = t216 * t196;
-		t387 = -0.12e2 * t205 + 0.4e1 * t45 * t250 - t14 * t86 - 0.8e1 * t59 + 0.16e2 * t365 - 0.12e2 * t367 - 0.2e1 * t370 + 0.4e1 * t46 * t244 - 0.4e1 * t374 - 0.2e1 * t376 - 0.4e1 * t378 + 0.8e1 * t380 + 0.2e1 * t139 * t382 + 0.8e1 * t385;
-		t389 = t7 * t47;
-		t390 = t389 * t71;
-		t392 = t34 * t12;
-		t393 = t392 * t47;
-		t396 = t389 * t196;
-		t408 = t178 * t15;
-		t411 = t7 * t21;
-		t412 = t411 * t47;
-		t415 = t34 * t20;
-		t416 = t415 * t12;
-		t422 = 0.4e1 * t390 + 0.6e1 * t6 * t393 + 0.8e1 * t396 + 0.2e1 * t139 * t308 - 0.2e1 * t46 * t83 + 0.4e1 * t94 * t382 + 0.2e1 * t40 * t86 - 0.4e1 * t6 * t344 - 0.4e1 * t6 * t408 + 0.2e1 * t6 * t412 - t6 * t416 - 0.2e1 * t1 * t350 - 0.2e1 * t118 * t169;
-		t423 = t123 * t15;
-		t428 = t279 * t196;
-		t452 = -0.2e1 * t40 * t423 + 0.2e1 * t45 * t253 - 0.2e1 * t139 * t428 - 0.4e1 * t6 * t42 - 0.4e1 * t94 * t428 + 0.4e1 * t108 + 0.2e1 * t46 * t86 - 0.2e1 * t5 * t324 + t5 * t141 + 0.4e1 * t6 * t151 + 0.4e1 * t5 * t258 * t77 - 0.2e1 * t45 * t324 - 0.6e1 * t259 * t67 + 0.2e1 * t45 * t280;
-		t461 = t57 * t15;
-		t473 = t411 * t26;
-		t476 = t140 * t23;
-		t484 = 0.4e1 * t112 * t280 - 0.4e1 * t112 * t324 - 0.2e1 * t112 * t313 + 0.4e1 * t6 * t461 - 0.2e1 * t6 * t378 - 0.6e1 * t40 * t235 - t5 * t258 * t20 + 0.6e1 * t5 * t258 * t12 + 0.4e1 * t6 * t473 - t13 * t476 + 0.2e1 * t94 * t141 + 0.2e1 * t5 * t258 * t26 + 0.2e1 * t369;
-		t485 = t35 * t23;
-		t491 = t8 * t20;
-		t492 = t491 * t12;
-		t500 = M_PI * t9 * t15;
-		t511 = t216 * t20;
-		t517 = 0.4e1 * t6 * t485 + t14 * t130 - 0.6e1 * t40 * t300 - t6 * t492 - 0.2e1 * t5 * t64 * t20 - 0.2e1 * t6 * t374 - 0.2e1 * t39 * t500 - 0.6e1 * t40 * t241 - 0.4e1 * t6 * t231 - 0.4e1 * t6 * t380 - 0.6e1 * t46 * t300 - 0.2e1 * t6 * t511 + 0.8e1 * t46 * t42 + 0.12e2 * t392;
-		t529 = t1 * t21;
-		t536 = M_PI * t8;
-		t537 = t5 * t536;
-		t544 = 0.8e1 * t112 * t250 - 0.24e2 * t57 * t238 + t39 * t313 + 0.2e1 * t48 + 0.4e1 * t46 * t336 + 0.8e1 * t178 * t120 + t138 * t529 - 0.8e1 * t57 * t169 - 0.2e1 * t40 * t350 - t6 * t376 + 0.6e1 * t537 * t67 - 0.4e1 * t6 * t385 - 0.2e1 * t6 * t167;
-		t551 = t70 * t20;
-		t553 = t276 * t20;
-		t556 = t389 * t20;
-		t573 = -0.12e2 * t159 * t238 - 0.4e1 * t10 * t169 + 0.4e1 * t100 * t120 + 0.2e1 * t551 + 0.2e1 * t553 + 0.4e1 * t294 + 0.4e1 * t556 - t5 * t262 - 0.6e1 * t76 * t88 * t47 + 0.4e1 * t113 * t86 + 0.6e1 * t537 * t300 + 0.4e1 * t76 * t95 * t23 + 0.4e1 * t40 * t336 + 0.4e1 * t40 * t49;
-		t580 = t411 * t23;
-		t600 = t146 * t11;
-		t605 = -0.4e1 * t94 * t250 + 0.2e1 * t6 * t580 - 0.12e2 * t10 * t120 + 0.4e1 * t94 * t308 - 0.4e1 * t113 * t83 + 0.4e1 * t5 * t258 * t11 - 0.2e1 * t1 * t193 + 0.2e1 * t71 - t6 * t370 - t75 * t1 * t266 + t75 * t1 * t23 + 0.4e1 * t45 * t600 + 0.2e1 * t537 * t189;
-		t611 = t369 * t20;
-		t626 = -0.2e1 * t1 * t99 * t120 - 0.2e1 * t6 * t423 - t6 * t611 + t13 * t253 - 0.8e1 * t461 - 0.2e1 * t55 - 0.2e1 * t611 - 0.2e1 * t416 - 0.2e1 * t46 * t189 + 0.2e1 * t267 - 0.12e2 * t17 - 0.2e1 * t14 * t336 - t6 * t346 - t6 * t130;
-		t638 = t34 * t77;
-		t639 = t638 * t26;
-		t646 = t230 * t20;
-		t651 = -0.4e1 * t113 * t423 - 0.4e1 * t139 * t96 - 0.2e1 * t139 * t255 - 0.24e2 * t57 * t120 + 0.2e1 * t1 * t130 + 0.8e1 * t6 * t639 + 0.2e1 * t45 * t262 + 0.4e1 * t511 - 0.8e1 * t473 + 0.8e1 * t646 - 0.12e2 * t241 + 0.4e1 * t193 + 0.4e1 * t423;
-		t652 = t267 * t47;
-		t654 = t638 * t47;
-		t657 = t415 * t11;
-		t659 = t491 * t11;
-		t662 = t392 * t26;
-		t664 = t173 * t15;
-		t673 = 0.2e1 * t652 + 0.8e1 * t654 + 0.8e1 * t109 - 0.4e1 * t657 + 0.4e1 * t659 + 0.16e2 * t36 + 0.24e2 * t662 + 0.4e1 * t664 + 0.8e1 * t485 + 0.8e1 * t208 + 0.2e1 * t1 * t20 + 0.2e1 * t86 + 0.4e1 * t49 - 0.2e1 * t415;
-		t699 = t392 * t23;
-		t702 = 0.12e2 * t6 * t662 - 0.2e1 * t5 * t250 - 0.2e1 * t6 * t217 - 0.4e1 * t14 * t42 - 0.12e2 * t113 * t235 - 0.12e2 * t113 * t300 - 0.12e2 * t159 * t120 - t139 * t476 - 0.2e1 * t6 * t659 - 0.2e1 * t6 * t336 - 0.2e1 * t76 * t382 + 0.2e1 * t76 * t428 + 0.6e1 * t6 * t699;
-		t727 = t104 * t20;
-		t730 = -t139 * t262 + 0.2e1 * t6 * t225 - 0.4e1 * t6 * t646 + 0.2e1 * t39 * t262 + 0.4e1 * t39 * t600 + 0.2e1 * t6 * t83 - 0.2e1 * t94 * t321 - 0.4e1 * t75 * t1 * t11 + 0.2e1 * t492 + 0.8e1 * t35 + 0.4e1 * t1 * t49 + 0.2e1 * t5 * t500 + 0.2e1 * t5 * t308 - 0.2e1 * t6 * t727;
-		t734 = t22 * t47;
-		t755 = 0.8e1 * t113 * t244 + t6 * t734 + 0.2e1 * t491 - 0.2e1 * t46 * t124 - 0.2e1 * t1 * t83 - 0.2e1 * t22 + 0.4e1 * t6 * t654 + 0.2e1 * t1 * t86 - 0.2e1 * t537 * t124 + 0.4e1 * t196 - t5 * t536 * t20 - 0.12e2 * t113 * t241 + 0.6e1 * t6 * t241;
-		t756 = t108 * t12;
-		t783 = -0.2e1 * t6 * t756 - 0.4e1 * t113 * t124 - 0.2e1 * t21 - 0.6e1 * t259 * t300 - 0.12e2 * t113 * t67 - 0.2e1 * t40 * t189 - t139 * t280 + 0.4e1 * t41 - 0.2e1 * t21 * t47 - 0.4e1 * t76 * t95 * t47 - t139 * t321 - 0.2e1 * t6 * t193 - 0.4e1 * t75 * t1 * t77 - 0.2e1 * t6 * t220;
-		t795 = M_PI * t266;
-		t806 = t638 * t23;
-		t809 = t267 * t26;
-		t811 = -0.2e1 * t40 * t193 + 0.8e1 * t638 - 0.2e1 * t6 * t165 + 0.2e1 * t34 - 0.2e1 * t259 * t189 - t76 * t795 * t47 - 0.4e1 * t21 * t26 - 0.4e1 * t113 * t350 + 0.2e1 * t94 * t253 + 0.2e1 * t39 * t253 + 0.8e1 * t806 + 0.12e2 * t699 + 0.4e1 * t809;
-		t816 = t100 * t15;
-		t823 = t159 * t15;
-		t828 = -0.4e1 * t727 + 0.4e1 * t756 + 0.4e1 * t336 + 0.8e1 * t42 + 0.4e1 * t816 + 0.16e2 * t639 - 0.4e1 * t412 - 0.4e1 * t580 - 0.2e1 * t24 + 0.8e1 * t408 - 0.4e1 * t823 - 0.12e2 * t235 - 0.4e1 * t350 - 0.4e1 * t30;
-		t849 = 0.2e1 * t268 + 0.12e2 * t393 - 0.2e1 * t734 - 0.4e1 * t83 - 0.4e1 * t27 + 0.4e1 * t244 + 0.2e1 * t130 - 0.4e1 * t112 * t500 + 0.4e1 * t65 * t189 - 0.4e1 * t65 * t124 - 0.2e1 * t94 * t476 - 0.6e1 * t6 * t367 + 0.8e1 * t1 * t42;
-		t877 = 0.4e1 * t39 * t250 + 0.2e1 * t6 * t189 + 0.2e1 * t259 * t124 - 0.2e1 * t6 * t556 + t76 * t795 * t23 - 0.2e1 * t76 * t795 * t26 - 0.2e1 * t21 * t23 - t6 * t551 - t6 * t553 + 0.2e1 * t5 * t64 * t21 - 0.4e1 * t6 * t197 + 0.4e1 * t113 * t130 + 0.4e1 * t192 + 0.2e1 * t40 * t115;
-		t904 = t5 * t476 - t13 * t262 - 0.4e1 * t6 * t396 + 0.4e1 * t76 * t78 * t23 + 0.4e1 * t104 - 0.2e1 * t14 * t49 - 0.8e1 * t6 * t365 + 0.2e1 * t14 * t244 - 0.2e1 * t6 * t390 - 0.6e1 * t46 * t241 - 0.2e1 * t6 * t342 + 0.2e1 * t93 * t529 - 0.4e1 * t94 * t255;
-		t933 = 0.2e1 * t6 * t350 + 0.2e1 * t6 * t809 + 0.6e1 * t6 * t235 - 0.2e1 * t6 * t277 - 0.2e1 * t45 * t500 - 0.2e1 * t94 * t280 + 0.8e1 * t112 * t600 + 0.4e1 * t1 * t244 - 0.2e1 * t46 * t115 - t5 * t253 - 0.2e1 * t6 * t657 - 0.6e1 * t6 * t160 - 0.2e1 * t75 * t1 * t26 + 0.12e2 * t65 * t300;
-		t962 = -0.2e1 * t94 * t262 + 0.2e1 * t6 * t664 + t5 * t536 * t21 - 0.2e1 * t1 * t423 + 0.4e1 * t6 * t806 + 0.2e1 * t6 * t186 - 0.2e1 * t6 * t816 - 0.6e1 * t46 * t67 - 0.2e1 * t13 * t250 + 0.8e1 * t113 * t336 + 0.4e1 * t112 * t262 - 0.6e1 * t40 * t67 - 0.8e1 * t76 * t95 * t26;
-		t988 = t5 * t258 * t266 + t5 * t258 * t47 - 0.4e1 * t411 + t5 * t258 * t23 + t6 * t652 - 0.4e1 * t76 * t78 * t47 - 0.2e1 * t46 * t423 - 0.2e1 * t46 * t193 - t76 * t253 + t76 * t280 + 0.8e1 * t113 * t49 - 0.2e1 * t5 * t600 - 0.2e1 * t6 * t823 + 0.2e1 * t46 * t130;
-		t1001 = pow(t9 + 0.1e1 + t11, 0.2e1);
-		t1004 = pow(t9 - 0.1e1 - t11, 0.2e1);
-		t1011 = n * n;
-		t1015 = M_PI * M_PI;
-
-		u3b = -deltaRho * t3 * (t74 + t933 + t544 + t299 + t164 + t849 + t904 + t702 + t651 + t452 + t828 + t199 + t387 + t359 + t962 + t133 + t877 + t811 + t484 + t422 + t605 + t783 + t730 + t626 + t272 + t673 + t573 + t233 + t329 + t755 + t988 + t517) / t15 / (0.1e1 + t26) / t1001 / t1004 / t33 / (0.1e1 + t7) / t1011 / n / t1015 / M_PI / 0.2e1;
-
-		if ( y > startBlockY ) {
-			u2=u2b;u3=u3b;
-		}
-		else {
-			u2=u2a;u3=u3a;
-		}
-
-		u5 = (double)-2*n*M_PI*(viscosity*u2 + u3)*cos(n*M_PI*x);
-
-		*pressure +=u5;
-
-	}
-	
-	if ( y > startBlockY ) {
-	    *pressure += deltaRho*dx*(0.5-y);
-	 } else {
-	    *pressure += deltaRho*dx*(0.5-startBlockY);
-	}
-
-}
-
-void _AnalyticBlock_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	AnalyticBlock*           self           = (AnalyticBlock*)analyticSolution;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
-	self->pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  ); 
-
-	self->startBlockX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startBlockX", 0.0  );
-	self->endBlockX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"endBlockX", 0.0  );
-	self->startBlockY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startBlockY", 0.0  );
-}
-
-void _AnalyticBlock_Build( void* analyticSolution, void* data ) {
-	AnalyticBlock*	self = (AnalyticBlock*)analyticSolution;
-
-	assert( self && Stg_CheckType( self, AnalyticBlock ) );
-
-	Build( self->velocityField, data, False );
-	Build( self->pressureField, data, False );
-	AnalyticSolution_CreateAnalyticField( self, self->velocityField, _AnalyticBlock_VelocityFunction );
-	AnalyticSolution_CreateAnalyticField( self, self->pressureField, _AnalyticBlock_PressureFunction );
-
-	_AnalyticSolution_Build( self, data );
-}
-
-void* _AnalyticBlock_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(AnalyticBlock);
-	Type                                                      type = AnalyticBlock_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _AnalyticBlock_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _AnalyticBlock_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticBlock_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _AnalyticSolution_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _AnalyticSolution_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _AnalyticSolution_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 _AnalyticSolution_New(  ANALYTICSOLUTION_PASSARGS  );
-}
-
-Index _PICellerator_AnalyticBlock_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, AnalyticBlock_Type, (Name)"0", _AnalyticBlock_DefaultNew  );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Apps/RayleighTaylor/tests/AnalyticBlock/AnalyticBlock.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Apps/RayleighTaylor/tests/AnalyticBlock/AnalyticBlock.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,1775 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: AnalyticBlock.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#define MAX_FOURIER_TERMS 45
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include <assert.h>
+
+const Type AnalyticBlock_Type = "AnalyticBlock";
+
+typedef struct {
+	__AnalyticSolution
+	FeVariable* velocityField;
+	FeVariable* pressureField;
+	double startBlockX;
+	double endBlockX;
+	double startBlockY;
+} AnalyticBlock;
+
+void _AnalyticBlock_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	AnalyticBlock*          self           = (AnalyticBlock*)analyticSolution;
+	double                  n;
+	double                  x, y;
+	double                  viscosity      = 1.0;
+	double                  deltaRho       = 1.0;
+	double                  startBlockX    = self->startBlockX;
+	double                  endBlockX      = self->endBlockX;
+	double                  startBlockY    = self->startBlockY;
+	double                  x0;
+	double                  dx;
+	double                  u1, u2;
+	double                  u1a, u1b;
+	double                  u2a, u2b;
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t44,t45,t46,t47,t48,t49,t50,t52,t53,t54,t55,t56,t57,t58,t59,t60,t61,t62,t63,t64,t65,t66,t67,t68,t69,t70,t71,t72,t73,t74,t75,t76,t77,t78,t79,t80;
+	double t81,t82,t83,t84,t85,t86,t87,t88,t90,t91,t92,t93,t95,t96,t97,t98,t99,t100,t101,t104,t105,t106,t107,t108,t109,t110,t111,t112,t113,t115,t116,t117,t118,t119,t120;
+	double t121,t122,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t135,t136,t137,t138,t140,t141,t142,t143,t144,t145,t146,t149,t150,t151,t153,t154,t155,t156,t157,t158,t159,t160;
+	double t161,t162,t163,t165,t166,t167,t168,t169,t170,t171,t172,t173,t175,t176,t177,t178,t179,t180,t181,t182,t183,t185,t186,t187,t188,t189,t190,t191,t192,t193,t194,t195,t197,t198,t199;
+	double t202,t203,t204,t206,t207,t208,t209,t210,t211,t212,t213,t214,t215,t216,t217,t218,t220,t221,t224,t225,t226,t227,t229,t230,t232,t233,t235,t236,t238,t239,t240;
+	double t241,t243,t244,t247,t248,t249,t250,t251,t252,t253,t254,t255,t256,t258,t259,t260,t262,t263,t264,t265,t266,t268,t270,t271,t272,t273,t275,t276,t279,t280;
+	double t281,t282,t283,t284,t285,t286,t287,t288,t290,t291,t293,t294,t295,t296,t297,t298,t299,t300,t301,t303,t304,t305,t307,t308,t309,t310,t313,t314,t316,t317,t319;
+	double t321,t322,t323,t326,t327,t328,t330,t333,t334,t335,t337,t338,t339,t341,t342,t343,t344,t346,t347,t348,t349,t351,t353,t355,t357,t360;
+	double t364,t365,t370,t371,t372,t373,t374,t379,t383,t384,t387,t388,t390,t394,t395,t396;
+	double t401,t402,t403,t404,t406,t408,t409,t410,t411,t413,t414,t416,t421,t424,t425,t429,t430,t431,t435;
+	double t441,t444,t446,t447,t449,t450,t453,t455,t459,t460,t462,t463,t464,t465,t467,t469,t471,t474,t479;
+	double t481,t483,t484,t485,t490,t491,t492,t494,t496,t501,t507,t512,t518,t519;
+	double t521,t522,t526,t535,t540,t542,t550,t557,t559;
+	double t567,t569,t572,t577,t582,t587,t594,t598,t600;
+	double t609,t610,t611,t613,t614,t615,t616,t618,t623,t628,t631,t634,t636,t637,t639,t640;
+	double t641,t642,t645,t650,t654,t658,t659,t661,t670,t673;
+	double t682,t685,t688,t701,t702,t705,t713,t716,t717,t719;
+	double t721,t726,t728,t731,t734,t735,t740,t742,t744,t745,t747,t749,t753,t757;
+	double t761,t771,t773,t779,t786;
+	double t801,t803,t812,t813,t827,t830;
+	double t853,t854,t863;
+	double t883,t886,t892,t899,t907,t910,t917,t920;
+	double t936,t947,t957;
+	double t969,t973,t974,t978,t982,t997;
+	double t1016;
+	double t1041,t1051,t1059,t1072;
+	double t1084,t1089,t1093,t1097;
+	
+	/* Find coordinate of node */
+	x = coord[ I_AXIS ];
+	y = coord[ J_AXIS ];
+
+	x0 = 0.0;
+	dx = endBlockX - startBlockX;
+
+	/* Initialise */
+	velocity[ I_AXIS ] = 0.0;
+	velocity[ J_AXIS ] = 0.0;
+
+	for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
+		t1 = n * M_PI;
+		t2 = 0.1e1 / cosh(t1);
+		t3 = startBlockY * n;
+		t4 = t3 * M_PI;
+		t5 = tanh(t4);
+		t6 = t2 * t5;
+		t7 = 0.1e1 / cosh(t4);
+		t8 = tanh(t1);
+		t9 = t8 * t7;
+		t13 = sin(t1 * dx);
+		t15 = y * n;
+		t16 = t15 * M_PI;
+		t17 = tanh(t16);
+		t18 = t17 * t17;
+		t19 = t18 * n;
+		t20 = M_PI * t2;
+		t21 = t20 * t8;
+		t24 = t18 * t2;
+		t25 = t8 * t5;
+		t26 = t24 * t25;
+		t29 = t2 * t2;
+		t30 = t29 * t2;
+		t32 = 0.1e1 / cosh(t16);
+		t33 = t32 * t32;
+		t35 = t33 * t8 * t7;
+		t38 = t33 * t2;
+		t39 = t38 * t5;
+		t41 = t18 * t30;
+		t42 = t41 * t5;
+		t45 = t17 * t8 * t7;
+		t47 = t38 * t8;
+		t52 = t24 * startBlockY;
+		t53 = t8 * t8;
+		t54 = t53 * t5;
+		t55 = t1 * t54;
+		t57 = M_PI * t33;
+		t60 = t53 * t8;
+		t62 = t18 * t60 * t7;
+		t64 = -0.4e1 * t19 * t21 + 0.2e1 * t16 * t26 + 0.2e1 * t30 - 0.3e1 * t16 * t35 + t16 * t39 - t16 * t42 + 0.12e2 * t45 + 0.2e1 * t16 * t47 - 0.2e1 * t33 * t7 + t52 * t55 - t15 * t57 * t30 - t16 * t62;
+		t65 = t38 * startBlockY;
+		t66 = t1 * t8;
+		t71 = t33 * t30;
+		t73 = t19 * M_PI;
+		t74 = startBlockY * t29;
+		t75 = t74 * t7;
+		t77 = t74 * t9;
+		t80 = t1 * t5;
+		t82 = t17 * t30;
+		t84 = M_PI * t18;
+		t90 = t33 * n;
+		t91 = t90 * M_PI;
+		t93 = t29 * t8 * t7;
+		t96 = t17 * n;
+		t98 = M_PI * t29 * t7;
+		t101 = -0.2e1 * t65 * t66 + 0.4e1 * t17 * t7 - 0.2e1 * t71 - t73 * t75 - t73 * t77 - 0.2e1 * t24 + t52 * t80 + 0.4e1 * t82 - t15 * t84 * t7 - t41 * startBlockY * t80 - 0.2e1 * t2 - 0.2e1 * t91 * t93 + 0.4e1 * t96 * t98;
+		t104 = t1 * t53;
+		t106 = t2 * t53;
+		t107 = t106 * t5;
+		t112 = t2 * t8;
+		t113 = t112 * t5;
+		t116 = t17 * t2;
+		t117 = t116 * t53;
+		t121 = t116 * t5;
+		t124 = t1 * t25;
+		t129 = t18 * startBlockY;
+		t130 = t1 * t7;
+		t132 = -0.2e1 * t6 - t65 * t104 - 0.2e1 * t73 * t107 + 0.4e1 * t90 * t21 - 0.4e1 * t73 * t113 - 0.4e1 * t117 + 0.4e1 * t47 - 0.6e1 * t35 + 0.2e1 * t16 * t121 + 0.2e1 * t52 * t124 + 0.2e1 * t19 * t98 + t129 * t130;
+		t133 = t24 * t5;
+		t137 = t20 * t53;
+		t140 = t17 * t29;
+		t141 = t140 * t9;
+		t143 = t38 * t53;
+		t146 = t18 * t53 * t7;
+		t150 = t20 * t5;
+		t153 = t140 * t7;
+		t158 = M_PI * t8;
+		t159 = t158 * t7;
+		t162 = t16 * t133 + 0.2e1 * t15 * t21 + 0.2e1 * t90 * t137 - 0.4e1 * t141 + t16 * t143 + 0.6e1 * t146 + 0.2e1 * t42 - 0.2e1 * t93 - 0.2e1 * t19 * t150 + 0.2e1 * t16 * t153 + 0.2e1 * t38 + t15 * t150 - 0.3e1 * t15 * t159;
+		t165 = t129 * n;
+		t167 = M_PI * t60 * t7;
+		t173 = t38 * t54;
+		t179 = M_PI * t53;
+		t180 = t179 * t7;
+		t183 = t24 * t8;
+		t187 = t33 * t29;
+		t188 = t187 * t9;
+		t190 = t17 * startBlockY;
+		t191 = t190 * n;
+		t195 = t165 * t167 + 0.2e1 * t73 * t93 + 0.2e1 * t16 * t117 + 0.2e1 * t173 + 0.3e1 * t165 * t159 - t15 * t84 * t30 + 0.3e1 * t165 * t180 + 0.2e1 * t16 * t183 + 0.2e1 * t7 + 0.2e1 * t188 + 0.2e1 * t191 * t167 + 0.2e1 * t39;
+		t197 = t33 * t60 * t7;
+		t199 = t187 * t7;
+		t204 = t33 * t53 * t7;
+		t207 = t33 * startBlockY;
+		t208 = t207 * n;
+		t213 = t116 * t8;
+		t216 = t24 * t53;
+		t221 = t17 * t60 * t7;
+		t224 = -0.2e1 * t197 + 0.2e1 * t199 - 0.2e1 * t19 * t137 - 0.3e1 * t16 * t204 - t208 * t167 - 0.3e1 * t208 * t159 + 0.6e1 * t9 + 0.4e1 * t16 * t213 + t16 * t216 - 0.4e1 * t121 - 0.4e1 * t153 + 0.4e1 * t221 + 0.2e1 * t41;
+		t227 = t71 * t5;
+		t238 = t17 * t53 * t7;
+		t240 = t82 * t5;
+		t247 = -0.8e1 * t213 - 0.2e1 * t227 - 0.6e1 * t204 + 0.6e1 * t191 * t159 + t16 * t188 - 0.6e1 * t16 * t45 + t15 * t84 * t2 + 0.12e2 * t238 + 0.4e1 * t240 - 0.2e1 * t65 * t124 - t65 * t55 - 0.3e1 * t208 * t180;
+		t248 = t96 * M_PI;
+		t254 = M_PI * t17;
+		t262 = t116 * startBlockY;
+		t266 = t38 * t25;
+		t271 = t29 * t7;
+		t275 = -0.4e1 * t248 * t107 - 0.2e1 * t106 + t91 * t75 - 0.4e1 * t112 + 0.2e1 * t15 * t254 * t2 - 0.8e1 * t248 * t113 + 0.6e1 * t191 * t180 + 0.2e1 * t262 * t55 + t16 * t173 + 0.2e1 * t16 * t266 + 0.2e1 * t90 * t20 - 0.2e1 * t271 + 0.2e1 * t262 * t80;
+		t283 = t18 * t29;
+		t284 = t283 * t9;
+		t293 = t2 * startBlockY;
+		t300 = -0.3e1 * t16 * t146 - 0.2e1 * t248 * t75 + t16 * t284 + 0.4e1 * t262 * t124 - t15 * t57 * t7 + t15 * t57 * t2 + t16 * t93 + 0.2e1 * t293 * t66 - t16 * t227 + t293 * t104 + t16 * t199 + t16 * t107;
+		t305 = t24 * t54;
+		t313 = t283 * t7;
+		t322 = -0.2e1 * t248 * t77 + 0.2e1 * t60 * t7 + t16 * t305 - 0.2e1 * t1 * t2 + 0.2e1 * t30 * t5 + t24 * t4 - 0.4e1 * t113 + t16 * t313 + 0.6e1 * t53 * t7 + t91 * t77 - t1 * t75 + 0.2e1 * t16 * t113 - t4 * t93;
+		t327 = M_PI * t30;
+		t335 = t30 * startBlockY;
+		t347 = 0.4e1 * t248 * t93 + t15 * t98 - t15 * t327 * t5 - 0.4e1 * t96 * t137 + 0.2e1 * t116 * t4 - t16 * t197 - t335 * t80 - 0.2e1 * t82 * startBlockY * t80 - 0.2e1 * t90 * t98 - t41 * t4 - 0.2e1 * t1 * t107 - 0.2e1 * t16 * t221;
+		t360 = t116 * t25;
+		t370 = 0.2e1 * t1 * t93 + t3 * t167 - 0.6e1 * t16 * t238 + 0.2e1 * t18 * t7 + t52 * t104 + 0.2e1 * t52 * t66 + 0.3e1 * t3 * t159 + 0.4e1 * t16 * t360 + 0.3e1 * t3 * t180 - t15 * t167 - 0.2e1 * t107 + 0.2e1 * t143 - 0.2e1 * t82 * t4;
+		t373 = t293 * n;
+		t384 = t18 * t8 * t7;
+		t395 = t373 * t179 * t5 - 0.4e1 * t1 * t113 + 0.2e1 * t16 * t141 + t293 * t80 - 0.4e1 * t183 - 0.2e1 * t216 + 0.6e1 * t384 + 0.2e1 * t373 * t158 * t5 - 0.3e1 * t15 * t180 + 0.2e1 * t262 * t104 - t65 * t80 - 0.2e1 * t133;
+		t408 = t116 * t54;
+		t414 = M_PI * t7;
+		t416 = -0.2e1 * t313 + 0.2e1 * t62 - t207 * t130 - 0.3e1 * t16 * t384 - 0.2e1 * t305 - 0.2e1 * t284 - 0.2e1 * t19 * t20 - 0.8e1 * t360 - 0.2e1 * t16 * t240 + 0.2e1 * t16 * t408 - 0.4e1 * t26 - 0.2e1 * t1 * t6 + t3 * t414;
+		t435 = -t335 * t1 + t293 * t1 - 0.2e1 * t1 * t106 - 0.4e1 * t1 * t112 + 0.2e1 * t1 * t271 + 0.2e1 * t190 * t130 - t15 * t327 + 0.4e1 * t266 - t15 * t414 - t38 * t4 - 0.4e1 * t408 - 0.4e1 * t96 * t20;
+		t460 = t15 * t20 - 0.2e1 * t15 * t254 * t30 + t71 * startBlockY * t80 + 0.2e1 * t90 * t150 - 0.2e1 * t15 * t254 * t7 - 0.8e1 * t96 * t21 + t15 * t137 - 0.4e1 * t96 * t150 + 0.2e1 * t91 * t107 + 0.4e1 * t262 * t66 + t71 * t4 + 0.4e1 * t91 * t113 - 0.4e1 * t116;
+		t471 = n * n;
+		t474 = M_PI * M_PI;
+		t479 = pow(t2 + 0.1e1 + t8, 0.2e1);
+		t483 = pow(t2 - 0.1e1 - t8, 0.2e1);
+
+		u1a = (t2 + t6 - t7 - t9) * deltaRho * t13 * (t64 + t101 + t132 + t162 + t195 + t224 + t247 + t275 + t300 + t322 + t347 + t370 + t395 + t416 + t435 + t460) / t7 / (0.1e1 + t5) / t471 / n / t474 / M_PI / t479 / t483 / t32 / viscosity / (0.1e1 + t17) / 0.2e1;
+
+		t1 = n * M_PI;
+		t3 = sin(t1 * dx);
+		t5 = y * n;
+		t6 = t5 * M_PI;
+		t7 = 0.1e1 / cosh(t6);
+		t8 = startBlockY * n;
+		t9 = t8 * M_PI;
+		t10 = 0.1e1 / cosh(t9);
+		t11 = t7 * t10;
+		t12 = tanh(t1);
+		t13 = t12 * t12;
+		t14 = t13 * t13;
+		t15 = tanh(t9);
+		t19 = tanh(t6);
+		t20 = t19 * t19;
+		t21 = t20 * startBlockY;
+		t22 = t21 * n;
+		t23 = M_PI * t12;
+		t24 = 0.1e1 / cosh(t1);
+		t25 = t24 * t24;
+		t26 = t15 * t25;
+		t27 = t23 * t26;
+		t30 = t20 * t24;
+		t31 = t12 * t10;
+		t32 = t31 * t15;
+		t35 = t7 * t7;
+		t36 = t15 * t15;
+		t37 = t35 * t36;
+		t38 = t25 * t13;
+		t39 = t37 * t38;
+		t41 = t25 * t12;
+		t42 = t37 * t41;
+		t44 = t25 * t24;
+		t45 = t19 * t44;
+		t46 = t45 * t31;
+		t48 = t19 * t24;
+		t49 = t10 * t15;
+		t50 = t48 * t49;
+		t52 = t35 * startBlockY;
+		t55 = t25 * t25;
+		t56 = t55 * t15;
+		t59 = t19 * t15;
+		t60 = t59 * t41;
+		t62 = t48 * t10;
+		t65 = t10 * t10;
+		t66 = t35 * t65;
+		t67 = t66 * t38;
+		t69 = t19 * t36;
+		t70 = t69 * t38;
+		t73 = t66 * t41;
+		t75 = -0.4e1 * t11 * t14 * t15 + 0.4e1 * t22 * t27 + 0.12e2 * t30 * t32 - 0.2e1 * t39 - 0.4e1 * t42 - 0.8e1 * t46 + 0.8e1 * t50 - t52 * t1 * t36 - 0.4e1 * t11 * t56 - 0.16e2 * t60 - 0.4e1 * t6 * t62 - 0.2e1 * t67 + 0.2e1 * t6 * t70 - 0.4e1 * t73;
+		t79 = t35 * t24;
+		t80 = t13 * t10;
+		t81 = t79 * t80;
+		t83 = t69 * t41;
+		t85 = t19 * n;
+		t86 = t85 * M_PI;
+		t87 = t24 * t12;
+		t88 = t87 * t49;
+		t91 = t52 * n;
+		t92 = M_PI * t65;
+		t93 = t92 * t25;
+		t95 = t20 * n;
+		t97 = M_PI * t44 * t10;
+		t100 = t35 * n;
+		t101 = t100 * M_PI;
+		t106 = t13 * t12;
+		t107 = t24 * t106;
+		t108 = t107 * t49;
+		t111 = t20 * t44;
+		t112 = t111 * t31;
+		t115 = t7 * t19;
+		t116 = t10 * t14;
+		t119 = t87 * t10;
+		t122 = t19 * t65;
+		t123 = t122 * t41;
+		t126 = 0.8e1 * t11 * t38 + 0.2e1 * t37 - 0.12e2 * t81 - 0.8e1 * t83 + 0.12e2 * t86 * t88 - t91 * t93 + 0.2e1 * t95 * t97 - 0.6e1 * t101 * t88 + 0.8e1 * t11 * t26 - 0.2e1 * t101 * t108 + 0.2e1 * t6 * t112 - 0.4e1 * t115 * t116 + 0.6e1 * t1 * t119 - 0.8e1 * t123 - 0.4e1 * t70;
+		t128 = t95 * M_PI;
+		t129 = t44 * t10;
+		t130 = t129 * t15;
+		t133 = t30 * t31;
+		t138 = t10 * t106;
+		t141 = M_PI * t35;
+		t142 = t5 * t141;
+		t143 = t24 * t13;
+		t144 = t143 * t49;
+		t150 = t35 * t15;
+		t151 = t150 * t41;
+		t154 = t69 * t25;
+		t157 = M_PI * t19;
+		t158 = t5 * t157;
+		t168 = t20 * t55;
+		t169 = t168 * t65;
+		t171 = 0.2e1 * t128 * t130 + 0.12e2 * t133 - 0.4e1 * t91 * t23 * t36 - 0.16e2 * t115 * t138 - 0.6e1 * t142 * t144 - 0.4e1 * t41 + 0.4e1 * t91 * t27 - 0.4e1 * t6 * t151 + 0.2e1 * t6 * t154 - 0.12e2 * t158 * t144 - 0.24e2 * t11 * t13 * t15 - 0.2e1 * t101 * t130 - 0.6e1 * t6 * t81 - t6 * t169;
+		t172 = t26 * t12;
+		t175 = M_PI * t13;
+		t176 = t175 * t25;
+		t178 = M_PI * t55;
+		t179 = t178 * t36;
+		t181 = t178 * t15;
+		t185 = t44 * t12;
+		t186 = t185 * t10;
+		t188 = t35 * t14;
+		t189 = t188 * t36;
+		t191 = t35 * t106;
+		t192 = t191 * t36;
+		t194 = t19 * t25;
+		t195 = t194 * t12;
+		t197 = t35 * t25;
+		t198 = t197 * t12;
+		t202 = M_PI * t36;
+		t203 = t202 * t25;
+		t211 = -0.16e2 * t86 * t172 + t91 * t176 - t8 * t179 - 0.2e1 * t8 * t181 - 0.4e1 * t130 - 0.4e1 * t186 + 0.2e1 * t189 + 0.8e1 * t192 - 0.8e1 * t195 - 0.4e1 * t198 - 0.2e1 * t101 * t186 + t91 * t203 + t5 * t141 * t36 - 0.6e1 * t6 * t119 + t5 * t141 * t65;
+		t214 = t35 * t13;
+		t215 = t214 * t65;
+		t226 = t19 * startBlockY;
+		t227 = t226 * n;
+		t230 = t20 * t25;
+		t232 = t20 * t36;
+		t233 = t232 * t41;
+		t235 = M_PI * t25;
+		t238 = t20 * t15;
+		t239 = t238 * t41;
+		t243 = t20 * t65;
+		t244 = t243 * t41;
+		t247 = t243 * t38;
+		t251 = t36 * t25;
+		t252 = t251 * t13;
+		t255 = 0.6e1 * t6 * t215 + 0.6e1 * t5 * t141 * t13 + 0.2e1 * t128 * t186 - 0.16e2 * t11 * t12 * t15 - 0.2e1 * t227 * t179 - 0.2e1 * t230 - 0.4e1 * t233 + 0.2e1 * t100 * t235 - 0.8e1 * t239 - 0.6e1 * t101 * t144 + 0.2e1 * t6 * t244 + t6 * t247 - 0.6e1 * t101 * t119 + 0.2e1 * t101 * t252;
+		t259 = t235 * t15;
+		t265 = t35 * t44;
+		t266 = t265 * t31;
+		t279 = t80 * t15;
+		t282 = t115 * t10;
+		t283 = t26 * t13;
+		t286 = t191 * t15;
+		t290 = -0.2e1 * t247 - 0.2e1 * t95 * t176 + 0.4e1 * t100 * t259 - 0.4e1 * t26 + 0.24e2 * t48 * t32 + 0.2e1 * t6 * t266 + 0.4e1 * t6 * t239 + 0.2e1 * t5 * t141 * t15 + 0.2e1 * t66 - 0.2e1 * t6 * t108 - 0.2e1 * t128 * t252 + 0.12e2 * t30 * t279 + 0.8e1 * t282 * t283 + 0.8e1 * t6 * t286 + t22 * t203;
+		t295 = M_PI * t24 * t10;
+		t299 = t168 * t36;
+		t303 = t24 * t10;
+		t308 = t185 * t49;
+		t310 = t303 * t15;
+		t313 = t48 * t138;
+		t316 = t202 * t41;
+		t319 = M_PI * t20;
+		t322 = t65 * t25;
+		t323 = t322 * t12;
+		t326 = t188 * t65;
+		t330 = 0.2e1 * t9 * t283 + 0.2e1 * t95 * t295 + 0.8e1 * t191 - t6 * t299 + 0.2e1 * t227 * t203 + 0.2e1 * t1 * t303 - 0.2e1 * t22 * t181 - 0.4e1 * t308 - 0.2e1 * t101 * t310 - 0.4e1 * t6 * t313 + 0.2e1 * t91 * t316 + t5 * t319 * t25 + 0.4e1 * t101 * t323 + t6 * t326 - 0.2e1 * t100 * t295;
+		t337 = t178 * t65;
+		t346 = t30 * t138;
+		t349 = t66 * t25;
+		t351 = t143 * t10;
+		t353 = t107 * t10;
+		t355 = t230 * t13;
+		t357 = t30 * t10;
+		t360 = -0.4e1 * t1 * t283 + 0.2e1 * t55 * t36 - 0.2e1 * t101 * t308 - t5 * t337 - 0.2e1 * t5 * t295 + 0.4e1 * t108 + 0.4e1 * t6 * t46 + 0.2e1 * t128 * t310 - 0.2e1 * t6 * t346 - t6 * t349 + 0.12e2 * t351 + 0.4e1 * t353 - 0.2e1 * t355 + 0.4e1 * t357 + 0.2e1 * t326;
+		t364 = t214 * t36;
+		t370 = t168 * t15;
+		t383 = t232 * t38;
+		t387 = 0.12e2 * t364 + 0.8e1 * t11 * t25 + 0.2e1 * t299 + 0.4e1 * t310 + 0.4e1 * t370 - 0.4e1 * t11 * t55 + 0.4e1 * t85 * t97 - 0.4e1 * t1 * t26 + 0.12e2 * t144 - 0.2e1 * t1 * t251 + 0.2e1 * t6 * t233 + t6 * t383 - t8 * t178 + 0.4e1 * t56;
+		t388 = t150 * t38;
+		t396 = t238 * t38;
+		t401 = t175 * t26;
+		t406 = t138 * t15;
+		t409 = M_PI * t106;
+		t413 = t122 * t25;
+		t421 = t92 * t41;
+		t424 = -0.2e1 * t6 * t388 - 0.4e1 * t11 + 0.8e1 * t227 * t27 + 0.2e1 * t1 * t129 + 0.2e1 * t6 * t396 - 0.4e1 * t128 * t283 + 0.2e1 * t22 * t401 + 0.2e1 * t100 * t176 + 0.4e1 * t30 * t406 + 0.4e1 * t91 * t409 * t65 + 0.2e1 * t6 * t413 - 0.2e1 * t25 + 0.2e1 * t6 * t323 - 0.4e1 * t85 * t93 - 0.2e1 * t22 * t421;
+		t431 = t322 * t13;
+		t435 = t10 * t25;
+		t446 = t79 * t49;
+		t459 = -0.12e2 * t91 * t175 * t15 + 0.2e1 * t6 * t130 + t6 * t431 - 0.24e2 * t115 * t80 + 0.16e2 * t115 * t435 * t12 - t5 * t319 * t55 - 0.4e1 * t115 * t116 * t15 - 0.16e2 * t115 * t406 - 0.2e1 * t6 * t446 - 0.4e1 * t91 * t409 * t36 - 0.2e1 * t6 * t357 - t8 * t93 - 0.2e1 * t142 * t108 + 0.4e1 * t85 * t295;
+		t462 = t111 * t10;
+		t465 = t232 * t25;
+		t469 = t30 * t49;
+		t474 = t265 * t10;
+		t481 = t188 * t15;
+		t484 = startBlockY * t25;
+		t485 = t484 * t12;
+		t490 = t92 * t38;
+		t492 = t202 * t38;
+		t494 = t243 * t25;
+		t496 = -0.2e1 * t6 * t73 + 0.2e1 * t6 * t462 + t6 * t465 + 0.4e1 * t101 * t283 - 0.2e1 * t6 * t469 - 0.12e2 * t158 * t88 + 0.2e1 * t6 * t474 - 0.16e2 * t115 * t32 + 0.2e1 * t6 * t308 + 0.2e1 * t6 * t481 + 0.2e1 * t1 * t485 + 0.16e2 * t282 * t172 - t91 * t490 + t91 * t492 + t6 * t494;
+		t507 = t79 * t31;
+		t521 = t235 * t12;
+		t526 = -0.2e1 * t101 * t353 - 0.8e1 * t85 * t259 - 0.2e1 * t5 * t181 - 0.2e1 * t1 * t322 - 0.6e1 * t6 * t507 + 0.12e2 * t88 - 0.4e1 * t227 * t421 + t5 * t235 + 0.16e2 * t11 * t41 - 0.24e2 * t115 * t279 - 0.6e1 * t6 * t133 + t8 * t203 + 0.4e1 * t100 * t521 - 0.4e1 * t79 * t406;
+		t535 = M_PI * t14;
+		t542 = t59 * t25;
+		t559 = 0.24e2 * t48 * t279 + 0.6e1 * t91 * t175 * t65 + 0.4e1 * t5 * t141 * t106 - 0.2e1 * t91 * t535 * t15 + 0.4e1 * t227 * t316 + t6 * t355 + 0.4e1 * t6 * t542 - 0.4e1 * t52 * t1 * t106 + 0.12e2 * t214 - 0.4e1 * t115 * t49 - 0.16e2 * t115 * t31 - 0.4e1 * t128 * t323 - t6 * t67 - 0.4e1 * t244 + 0.2e1 * t101 * t431;
+		t569 = t111 * t49;
+		t572 = t10 * t55;
+		t577 = t194 * t13;
+		t587 = t48 * t80;
+		t594 = -0.2e1 * t322 - 0.4e1 * t52 * t1 * t12 + 0.4e1 * t6 * t123 - 0.8e1 * t86 * t323 + 0.2e1 * t6 * t569 - 0.4e1 * t115 * t572 + 0.2e1 * t22 * t316 + 0.2e1 * t6 * t577 + 0.2e1 * t168 - 0.2e1 * t6 * t370 - 0.4e1 * t86 * t252 - 0.12e2 * t79 * t32 - 0.12e2 * t6 * t587 - 0.2e1 * t1 * t431 + 0.2e1 * t1 * t353;
+		t600 = t35 * t12;
+		t610 = t265 * t49;
+		t613 = t230 * t12;
+		t616 = t5 * t319;
+		t623 = 0.2e1 * t91 * t401 + 0.2e1 * t5 * t157 * t25 + 0.8e1 * t600 - 0.2e1 * t251 + t142 - 0.12e2 * t79 * t279 - 0.8e1 * t86 * t283 + 0.4e1 * t150 + 0.8e1 * t48 * t406 + 0.2e1 * t6 * t610 + 0.2e1 * t6 * t613 - 0.2e1 * t616 * t108 + 0.4e1 * t469 + t8 * t337 + 0.8e1 * t11 * t283;
+		t628 = t37 * t25;
+		t631 = t79 * t10;
+		t636 = t30 * t80;
+		t641 = t251 * t12;
+		t650 = t197 * t13;
+		t658 = -t6 * t628 + 0.4e1 * t346 - 0.2e1 * t6 * t631 + 0.2e1 * t55 * t65 + 0.12e2 * t636 - 0.2e1 * t5 * t157 * t55 - 0.4e1 * t1 * t641 - 0.2e1 * t95 * t203 - 0.8e1 * t45 * t32 - 0.6e1 * t142 * t88 - t6 * t650 - 0.8e1 * t1 * t172 + 0.2e1 * t227 * t337 + 0.16e2 * t11 * t172;
+		t659 = t122 * t38;
+		t661 = t59 * t38;
+		t670 = t238 * t25;
+		t685 = -0.4e1 * t659 - 0.8e1 * t661 - 0.2e1 * t128 * t431 - t52 * t1 * t14 + t22 * t176 - 0.4e1 * t111 * t32 + 0.2e1 * t6 * t670 - t9 * t431 + 0.24e2 * t587 - 0.4e1 * t396 + 0.4e1 * t265 * t32 + 0.4e1 * t86 * t485 + 0.2e1 * t100 * t93 + 0.2e1 * t128 * t308 - t5 * t178;
+		t688 = M_PI * startBlockY * t25;
+		t701 = t45 * t49;
+		t713 = t1 * t24;
+		t716 = t95 * t688 - 0.8e1 * t91 * t23 * t15 + t5 * t141 * t14 - 0.2e1 * t383 - 0.4e1 * t6 * t50 + 0.4e1 * t266 - 0.8e1 * t85 * t521 - 0.8e1 * t701 + 0.2e1 * t128 * t353 - 0.8e1 * t86 * t641 + 0.4e1 * t86 * t108 - 0.2e1 * t9 * t323 + t52 * t1 * t65 + 0.2e1 * t713 * t406;
+		t717 = t1 * t55;
+		t721 = t150 * t25;
+		t745 = -t21 * t717 + 0.8e1 * t6 * t60 - 0.2e1 * t6 * t721 + 0.4e1 * t101 * t641 - 0.6e1 * t91 * t175 * t36 + 0.2e1 * t1 * t130 + 0.2e1 * t9 * t641 - 0.8e1 * t151 + 0.4e1 * t610 + 0.4e1 * t6 * t192 + t8 * t176 + 0.8e1 * t115 * t435 + 0.2e1 * t227 * t176 + 0.2e1 * t616 * t308 + t5 * t203;
+		t749 = t214 * t15;
+		t757 = t45 * t10;
+		t773 = -0.4e1 * t388 + 0.12e2 * t6 * t749 + 0.12e2 * t86 * t119 + 0.6e1 * t713 * t32 - 0.2e1 * t197 + 0.4e1 * t6 * t757 - 0.4e1 * t446 + 0.2e1 * t6 * t659 + t5 * t176 + 0.4e1 * t86 * t130 - 0.4e1 * t1 * t323 - 0.2e1 * t6 * t310 - 0.12e2 * t507 - 0.6e1 * t6 * t351;
+		t786 = t79 * t138;
+		t803 = 0.2e1 * t5 * t521 - 0.4e1 * t128 * t641 + 0.2e1 * t22 * t259 + 0.4e1 * t91 * t23 * t65 - 0.4e1 * t85 * t176 - t22 * t179 - 0.4e1 * t786 - 0.6e1 * t616 * t144 - t5 * t141 * t25 - 0.4e1 * t158 * t108 + 0.2e1 * t6 * t641 + t6 * t252 + 0.4e1 * t6 * t661 - 0.6e1 * t6 * t88 - 0.4e1 * t95 * t521;
+		t812 = t19 * t55;
+		t813 = t812 * t15;
+		t827 = -0.4e1 * t323 - 0.2e1 * t431 - 0.2e1 * t465 - 0.2e1 * t494 - 0.4e1 * t670 - 0.4e1 * t154 - 0.4e1 * t413 + 0.8e1 * t813 - 0.4e1 * t11 * t14 - 0.16e2 * t11 * t106 - 0.24e2 * t11 * t13 - 0.4e1 * t11 * t15 - 0.16e2 * t11 * t12 - 0.8e1 * t542 + 0.12e2 * t119;
+		t853 = -0.6e1 * t6 * t144 + t91 * t535 * t65 - 0.2e1 * t100 * t97 - 0.8e1 * t128 * t172 + 0.2e1 * t128 * t108 + 0.2e1 * t5 * t97 + 0.4e1 * t158 * t308 + t9 * t252 + 0.2e1 * t188 + t1 * t484 + 0.6e1 * t128 * t351 - 0.2e1 * t38 - 0.4e1 * t227 * t181 - 0.4e1 * t194 - 0.2e1 * t1 * t38;
+		t863 = t600 * t36;
+		t886 = -0.2e1 * t6 * t198 + 0.4e1 * t86 * t310 - 0.4e1 * t6 * t813 + 0.4e1 * t6 * t863 + 0.2e1 * t8 * t259 + 0.2e1 * t1 * t310 + 0.6e1 * t1 * t351 + 0.4e1 * t303 + 0.2e1 * t142 * t308 + 0.2e1 * t227 * t492 + 0.4e1 * t6 * t172 - 0.4e1 * t95 * t259 - 0.8e1 * t91 * t409 * t15 + 0.4e1 * t227 * t259;
+		t892 = t191 * t65;
+		t899 = t812 * t36;
+		t907 = t812 * t65;
+		t917 = t48 * t31;
+		t920 = -0.16e2 * t11 * t106 * t15 - 0.2e1 * t6 * t353 + 0.4e1 * t6 * t892 + 0.12e2 * t86 * t351 + 0.6e1 * t128 * t88 - 0.2e1 * t6 * t899 + 0.8e1 * t115 * t435 * t13 + 0.4e1 * t6 * t83 - 0.2e1 * t6 * t907 + 0.2e1 * t35 - t6 * t39 + t5 * t93 + 0.2e1 * t128 * t485 + 0.12e2 * t86 * t144 - 0.12e2 * t6 * t917;
+		t947 = 0.2e1 * t5 * t259 - 0.4e1 * t85 * t203 + 0.2e1 * t100 * t203 - 0.2e1 * t6 * t786 - 0.2e1 * t1 * t252 - 0.2e1 * t226 * t717 + 0.6e1 * t128 * t144 - 0.2e1 * t227 * t93 + 0.4e1 * t86 * t308 - 0.6e1 * t616 * t88 + t100 * t688 + 0.8e1 * t313 - 0.6e1 * t6 * t636 - 0.4e1 * t112;
+		t973 = -0.4e1 * t85 * t235 + 0.24e2 * t917 + 0.2e1 * t91 * t259 + 0.4e1 * t86 * t186 - 0.4e1 * t569 - t22 * t93 + t6 * t189 - 0.6e1 * t52 * t1 * t13 + 0.4e1 * t9 * t172 + t22 * t337 - t22 * t490 - 0.2e1 * t52 * t1 * t15 + 0.2e1 * t6 * t186 - t52 * t1 + 0.2e1 * t6 * t283;
+		t997 = 0.8e1 * t101 * t172 + t22 * t492 + 0.6e1 * t713 * t279 - 0.2e1 * t95 * t235 + 0.8e1 * t62 - 0.2e1 * t628 - 0.2e1 * t349 - 0.2e1 * t650 + 0.8e1 * t892 + 0.12e2 * t215 + 0.4e1 * t481 + 0.2e1 * t85 * t688 + 0.4e1 * t5 * t141 * t12 - 0.2e1 * t95 * t93;
+		t1016 = -0.4e1 * t1 * t41 - t5 * t179 - 0.4e1 * t721 - 0.4e1 * t577 - 0.4e1 * t283 - 0.8e1 * t172 - 0.4e1 * t462 + 0.16e2 * t286 + 0.4e1 * t899 + 0.4e1 * t907 + 0.2e1 * t169 - 0.8e1 * t757 - 0.4e1 * t631 + 0.2e1 * t1 * t186 + 0.4e1 * t6 * t195;
+		t1041 = t600 * t65;
+		t1051 = -0.2e1 * t227 * t490 + 0.4e1 * t227 * t401 + 0.4e1 * t6 * t701 - 0.6e1 * t101 * t351 - t91 * t535 * t36 - 0.4e1 * t129 + 0.6e1 * t6 * t364 + 0.2e1 * t1 * t44 * t32 + 0.6e1 * t128 * t119 - 0.2e1 * t6 * t42 + 0.8e1 * t115 * t49 * t25 + 0.4e1 * t6 * t1041 - 0.2e1 * t91 * t421 - 0.4e1 * t115 * t572 * t15 + 0.4e1 * t86 * t353;
+		t1059 = t600 * t15;
+		t1072 = 0.2e1 * t55 + 0.2e1 * t101 * t485 + 0.4e1 * t812 - 0.4e1 * t86 * t431 - 0.4e1 * t613 + 0.16e2 * t1059 + 0.24e2 * t749 + 0.4e1 * t474 + 0.8e1 * t1041 + 0.8e1 * t863 - 0.2e1 * t1 * t25 - 0.4e1 * t282 - 0.2e1 * t252 - 0.4e1 * t641 + 0.8e1 * t6 * t1059;
+		t1084 = pow(t24 + 0.1e1 + t12, 0.2e1);
+		t1089 = pow(t24 - 0.1e1 - t12, 0.2e1);
+		t1093 = n * n;
+		t1097 = M_PI * M_PI;
+
+		u1b = deltaRho * t3 * (t1051 + t459 + t387 + t330 + t658 + t496 + t947 + t126 + t594 + t886 + t803 + t920 + t75 + t973 + t997 + t171 + t211 + t716 + t360 + t424 + t1072 + t559 + t745 + t1016 + t623 + t853 + t773 + t255 + t526 + t827 + t290 + t685) / t10 / (0.1e1 + t15) / t1084 / t1089 / t7 / t1093 / n / t1097 / M_PI / viscosity / (0.1e1 + t19) / 0.2e1;
+		
+		t1 = n * M_PI;
+		t2 = 0.1e1 / cosh(t1);
+		t3 = startBlockY * n;
+		t4 = t3 * M_PI;
+		t5 = tanh(t4);
+		t6 = t2 * t5;
+		t7 = 0.1e1 / cosh(t4);
+		t8 = tanh(t1);
+		t9 = t8 * t7;
+		t13 = sin(t1 * dx);
+		t15 = y * n;
+		t16 = t15 * M_PI;
+		t17 = tanh(t16);
+		t19 = t17 * t8 * t7;
+		t22 = t17 * t2;
+		t25 = t17 * n;
+		t26 = M_PI * t2;
+		t27 = t8 * t8;
+		t28 = t26 * t27;
+		t31 = t2 * startBlockY;
+		t32 = t1 * t5;
+		t34 = t17 * t17;
+		t35 = t34 * t2;
+		t37 = 0.1e1 / cosh(t16);
+		t38 = t37 * t37;
+		t39 = t38 * n;
+		t40 = t39 * M_PI;
+		t41 = t2 * t8;
+		t42 = t41 * t5;
+		t45 = t38 * t2;
+		t46 = t27 * t5;
+		t47 = t45 * t46;
+		t48 = t2 * t2;
+		t49 = t38 * t48;
+		t50 = t49 * t9;
+		t53 = t8 * t5;
+		t54 = t22 * t53;
+		t56 = t48 * t2;
+		t57 = t17 * t56;
+		t60 = t17 * t48;
+		t61 = t60 * t9;
+		t63 = 0.6e1 * t16 * t19 - 0.2e1 * t22 * t4 + 0.4e1 * t25 * t28 - t31 * t32 - t35 * t4 + 0.4e1 * t40 * t42 + t47 + t50 + 0.2e1 * t39 * t26 + 0.4e1 * t54 + 0.2e1 * t57 * t4 + 0.2e1 * t61;
+		t64 = t34 * n;
+		t67 = t34 * t56;
+		t69 = t35 * t53;
+		t71 = t35 * t46;
+		t72 = t34 * t48;
+		t73 = t72 * t9;
+		t74 = t22 * startBlockY;
+		t75 = t1 * t27;
+		t78 = t48 * t7;
+		t83 = M_PI * t7;
+		t85 = t56 * startBlockY;
+		t88 = t2 * t27;
+		t93 = 0.2e1 * t64 * t26 + t67 * t4 + 0.2e1 * t69 + t71 + t73 - 0.2e1 * t74 * t75 - 0.2e1 * t1 * t78 + 0.2e1 * t1 * t6 - t3 * t83 + t85 * t1 - t31 * t1 + 0.2e1 * t1 * t88 + 0.4e1 * t1 * t41;
+		t98 = t31 * n;
+		t99 = t8 * M_PI;
+		t104 = t17 * startBlockY;
+		t105 = t1 * t7;
+		t108 = M_PI * t56;
+		t110 = t45 * t53;
+		t113 = t22 * t46;
+		t117 = t38 * t56;
+		t118 = t117 * t5;
+		t120 = t26 * t5;
+		t123 = 0.4e1 * t25 * t26 - t15 * t26 - 0.2e1 * t98 * t99 * t5 + t15 * t83 - 0.2e1 * t104 * t105 + t15 * t108 + 0.2e1 * t110 + t85 * t32 + 0.2e1 * t113 + 0.2e1 * t16 * t110 - t16 * t118 + 0.4e1 * t25 * t120;
+		t125 = t34 * t27 * t7;
+		t128 = t48 * t8 * t7;
+		t129 = t88 * t5;
+		t130 = t45 * t27;
+		t131 = t67 * t5;
+		t133 = t49 * t7;
+		t135 = M_PI * t38;
+		t140 = t26 * t8;
+		t143 = t104 * n;
+		t144 = t27 * t8;
+		t146 = M_PI * t144 * t7;
+		t149 = t99 * t7;
+		t153 = M_PI * t48 * t7;
+		t156 = -0.3e1 * t125 + t128 + t129 + t130 - t131 - t15 * t28 + t16 * t133 - t15 * t135 * t7 + t15 * t135 * t2 - 0.2e1 * t15 * t140 - 0.2e1 * t143 * t146 - 0.6e1 * t143 * t149 - 0.2e1 * t39 * t153;
+		t159 = t45 * startBlockY;
+		t160 = t1 * t46;
+		t162 = M_PI * t27;
+		t163 = t162 * t7;
+		t166 = t38 * startBlockY;
+		t170 = M_PI * t25;
+		t171 = startBlockY * t48;
+		t172 = t171 * t7;
+		t177 = t35 * t8;
+		t182 = t171 * t9;
+		t186 = t34 * t8 * t7;
+		t191 = -t159 * t160 - 0.6e1 * t143 * t163 - t166 * t105 + 0.2e1 * t39 * t120 + 0.2e1 * t170 * t172 + 0.2e1 * t1 * t129 - 0.2e1 * t16 * t177 - 0.2e1 * t40 * t128 + 0.2e1 * t170 * t182 + 0.3e1 * t16 * t186 + t117 * t4 - t45 * t4;
+		t192 = t35 * t5;
+		t194 = t166 * n;
+		t199 = t1 * t8;
+		t206 = t57 * t5;
+		t210 = t38 * t27 * t7;
+		t217 = -t16 * t192 - t194 * t146 + 0.2e1 * t57 * startBlockY * t32 - 0.4e1 * t74 * t199 - t56 - 0.4e1 * t16 * t54 - 0.3e1 * t9 - 0.2e1 * t57 + 0.2e1 * t16 * t206 - 0.3e1 * t210 + 0.2e1 * t1 * t2 - 0.4e1 * t25 * t153 + t16 * t131;
+		t225 = M_PI * t17;
+		t236 = t38 * t8 * t7;
+		t239 = t45 * t5;
+		t241 = t45 * t8;
+		t244 = -0.2e1 * t16 * t69 - 0.2e1 * t159 * t199 - 0.2e1 * t1 * t128 + 0.2e1 * t15 * t225 * t56 + t35 - 0.2e1 * t17 * t7 + 0.2e1 * t15 * t225 * t7 - t159 * t75 - 0.3e1 * t16 * t236 - t117 + t16 * t239 + 0.2e1 * t16 * t241;
+		t249 = t64 * M_PI;
+		t253 = t38 * t144 * t7;
+		t258 = t22 * t5;
+		t264 = -t38 * t7 + t6 - 0.3e1 * t194 * t163 + t40 * t172 + t249 * t172 - t3 * t146 - t16 * t253 - t15 * t135 * t56 - t159 * t32 + t2 - 0.2e1 * t16 * t258 + t249 * t182 + t67 * startBlockY * t32;
+		t270 = t60 * t7;
+		t275 = t17 * t144 * t7;
+		t279 = t72 * t7;
+		t282 = t34 * t144 * t7;
+		t284 = t35 * t27;
+		t286 = 0.4e1 * t64 * t140 - 0.2e1 * t16 * t270 + t16 * t130 + 0.2e1 * t16 * t275 + t40 * t182 - t16 * t279 + t16 * t282 + t284 - 0.3e1 * t186 + t192 + t279 - t282;
+		t287 = t35 * startBlockY;
+		t295 = t22 * t27;
+		t299 = t22 * t8;
+		t304 = t17 * t27 * t7;
+		t307 = -0.2e1 * t287 * t199 + 0.2e1 * t249 * t129 - t34 * t7 + 0.4e1 * t249 * t42 + 0.2e1 * t295 + 0.2e1 * t241 - 0.3e1 * t236 + t239 - t253 + 0.4e1 * t299 - t118 - 0.2e1 * t64 * t153 + 0.6e1 * t16 * t304;
+		t309 = t34 * startBlockY;
+		t317 = M_PI * t34;
+		t328 = t309 * n;
+		t330 = -t309 * t105 + t117 * startBlockY * t32 - t7 + 0.4e1 * t39 * t140 + 0.2e1 * t64 * t120 + t45 + t15 * t317 * t7 - 0.2e1 * t249 * t128 - 0.3e1 * t3 * t149 + 0.2e1 * t39 * t28 - 0.3e1 * t194 * t149 - t328 * t146;
+		t342 = t1 * t53;
+		t349 = -0.3e1 * t328 * t149 + t15 * t317 * t56 - t67 - t16 * t284 - 0.3e1 * t328 * t163 + 0.2e1 * t64 * t28 - t15 * t317 * t2 - 0.2e1 * t159 * t342 - t287 * t160 + t133 + 0.2e1 * t258 + 0.2e1 * t270 - 0.2e1 * t275;
+		t371 = -0.6e1 * t304 - t287 * t75 + 0.2e1 * t177 + 0.4e1 * t170 * t129 - 0.2e1 * t15 * t225 * t2 - t287 * t32 - 0.3e1 * t3 * t163 - 0.2e1 * t287 * t342 - 0.2e1 * t16 * t295 + 0.8e1 * t170 * t42 + t88 - 0.2e1 * t16 * t61;
+		t390 = -0.2e1 * t206 + 0.2e1 * t42 - 0.6e1 * t19 - 0.2e1 * t74 * t160 + 0.3e1 * t16 * t125 - 0.2e1 * t74 * t32 - 0.4e1 * t74 * t342 + 0.3e1 * t15 * t149 + 0.2e1 * t41 - t16 * t128 - 0.4e1 * t170 * t128 - t15 * t120 + t78;
+		t411 = -t16 * t129 - 0.2e1 * t16 * t42 - 0.4e1 * t16 * t299 - t16 * t73 + t15 * t108 * t5 - 0.3e1 * t16 * t210 + 0.4e1 * t1 * t42 + t16 * t50 + t15 * t146 - t15 * t153 - 0.2e1 * t31 * t199 - 0.2e1 * t16 * t113;
+		t430 = -t31 * t75 - t16 * t71 - t144 * t7 + 0.3e1 * t15 * t163 + t16 * t47 - t56 * t5 + 0.8e1 * t25 * t140 - t98 * t162 * t5 - 0.3e1 * t27 * t7 + t1 * t172 + t4 * t128 + 0.2e1 * t40 * t129 + 0.2e1 * t22;
+		t441 = n * n;
+		t444 = M_PI * M_PI;
+		t449 = pow(t2 + 0.1e1 + t8, 0.2e1);
+		t453 = pow(t2 - 0.1e1 - t8, 0.2e1);
+
+		u2a = (t2 + t6 - t7 - t9) * deltaRho * t13 * (t63 + t93 + t123 + t156 + t191 + t217 + t244 + t264 + t286 + t307 + t330 + t349 + t371 + t390 + t411 + t430) / t7 / (0.1e1 + t5) / t441 / n / t444 / M_PI / t449 / t453 / t37 / viscosity / (0.1e1 + t17) / 0.2e1;
+
+		t1 = n * M_PI;
+		t3 = sin(t1 * dx);
+		t5 = 0.1e1 / cosh(t1);
+		t6 = t5 * t5;
+		t7 = t6 * t6;
+		t8 = startBlockY * n;
+		t9 = t8 * M_PI;
+		t10 = 0.1e1 / cosh(t9);
+		t11 = t10 * t10;
+		t13 = y * n;
+		t14 = t13 * M_PI;
+		t15 = tanh(t14);
+		t16 = t15 * n;
+		t17 = t16 * M_PI;
+		t18 = t6 * t5;
+		t19 = tanh(t1);
+		t20 = t18 * t19;
+		t21 = tanh(t9);
+		t22 = t10 * t21;
+		t23 = t20 * t22;
+		t26 = 0.1e1 / cosh(t14);
+		t27 = t26 * t26;
+		t28 = t27 * t11;
+		t29 = t28 * t6;
+		t30 = t15 * t15;
+		t31 = t30 * t5;
+		t32 = t19 * t19;
+		t33 = t32 * t10;
+		t34 = t31 * t33;
+		t37 = t27 * n;
+		t38 = t37 * M_PI;
+		t39 = t32 * t19;
+		t40 = t5 * t39;
+		t41 = t40 * t10;
+		t44 = t20 * t10;
+		t47 = t21 * t21;
+		t48 = t27 * t47;
+		t49 = t48 * t6;
+		t50 = t6 * t19;
+		t52 = t15 * t6;
+		t53 = t52 * t19;
+		t56 = t30 * startBlockY;
+		t57 = t56 * n;
+		t58 = M_PI * t19;
+		t59 = t21 * t6;
+		t60 = t58 * t59;
+		t64 = t19 * t10;
+		t65 = t64 * t21;
+		t68 = t27 * t18;
+		t71 = t68 * t22;
+		t74 = -t7 * t11 - 0.4e1 * t17 * t23 - t29 + 0.6e1 * t14 * t34 - 0.2e1 * t38 * t41 - 0.2e1 * t1 * t44 - t49 + 0.2e1 * t50 - 0.4e1 * t14 * t53 - 0.4e1 * t57 * t60 - 0.2e1 * t1 * t18 * t65 + 0.2e1 * t68 * t65 + 0.2e1 * t14 * t71;
+		t75 = t30 * t18;
+		t76 = t75 * t22;
+		t78 = startBlockY * t6;
+		t79 = t78 * t19;
+		t84 = t15 * t18;
+		t85 = t84 * t22;
+		t87 = t27 * startBlockY;
+		t91 = M_PI * t32;
+		t92 = t91 * t59;
+		t95 = t15 * t5;
+		t96 = t39 * t10;
+		t97 = t95 * t96;
+		t99 = t95 * t64;
+		t101 = M_PI * t6;
+		t104 = t75 * t64;
+		t106 = t30 * t11;
+		t107 = t106 * t50;
+		t109 = t15 * startBlockY;
+		t110 = t109 * n;
+		t111 = M_PI * t11;
+		t112 = t6 * t32;
+		t113 = t111 * t112;
+		t116 = M_PI * t27;
+		t117 = t13 * t116;
+		t118 = t87 * n;
+		t121 = 0.2e1 * t76 - 0.4e1 * t17 * t79 - 0.2e1 * t7 * t21 + 0.4e1 * t85 - 0.6e1 * t87 * t1 * t32 - 0.2e1 * t57 * t92 - 0.4e1 * t97 - 0.12e2 * t99 + 0.4e1 * t16 * t101 + 0.2e1 * t104 + 0.2e1 * t107 + 0.2e1 * t110 * t113 + t117 + 0.4e1 * t118 * t60;
+		t123 = t11 * t6;
+		t126 = t5 * t19;
+		t127 = t126 * t22;
+		t130 = M_PI * t7;
+		t132 = t18 * t10;
+		t135 = t27 * t5;
+		t136 = t135 * t10;
+		t138 = t68 * t64;
+		t143 = t130 * t47;
+		t145 = t30 * t7;
+		t146 = t145 * t11;
+		t150 = t5 * t32;
+		t151 = t150 * t22;
+		t155 = 0.2e1 * t1 * t123 - 0.6e1 * t127 - t13 * t101 + t8 * t130 - 0.2e1 * t1 * t132 - 0.2e1 * t136 + 0.2e1 * t138 + 0.6e1 * t118 * t91 * t11 + t57 * t143 + t14 * t146 - 0.4e1 * t17 * t41 - 0.6e1 * t151 + 0.4e1 * t1 * t59;
+		t156 = t47 * t6;
+		t159 = t95 * t10;
+		t161 = M_PI * t47;
+		t162 = t161 * t112;
+		t165 = t40 * t22;
+		t175 = t130 * t11;
+		t177 = t91 * t6;
+		t183 = 0.2e1 * t1 * t156 - 0.4e1 * t159 - 0.2e1 * t110 * t162 - 0.2e1 * t38 * t165 - 0.2e1 * t165 - t7 + 0.2e1 * t110 * t143 + 0.2e1 * t118 * t92 + 0.2e1 * t38 * t79 + t13 * t175 - t57 * t177 + t118 * t177 - t14 * t49 - 0.12e2 * t95 * t65;
+		t186 = t59 * t19;
+		t189 = t32 * t32;
+		t190 = M_PI * t189;
+		t193 = t95 * t22;
+		t199 = t5 * t10;
+		t202 = t30 * t21;
+		t203 = t202 * t6;
+		t206 = t135 * t96;
+		t209 = t135 * t22;
+		t212 = t95 * t33;
+		t214 = t106 * t112;
+		t218 = t31 * t64;
+		t220 = 0.16e2 * t17 * t186 + t118 * t190 * t11 + 0.4e1 * t14 * t193 - 0.6e1 * t31 * t65 + 0.2e1 * t23 - 0.2e1 * t1 * t199 - 0.2e1 * t14 * t203 - 0.2e1 * t14 * t206 - 0.2e1 * t14 * t209 - 0.12e2 * t212 + t214 + 0.2e1 * t13 * t116 * t21 - 0.6e1 * t218;
+		t226 = t202 * t50;
+		t229 = t30 * t47;
+		t230 = t229 * t50;
+		t233 = t68 * t10;
+		t236 = t31 * t96;
+		t241 = t111 * t50;
+		t244 = t101 * t11;
+		t247 = t123 * t32;
+		t250 = t156 * t19;
+		t253 = t57 * t113 + t28 + 0.12e2 * t14 * t99 + 0.2e1 * t37 * t101 - 0.4e1 * t14 * t226 + 0.2e1 * t230 + 0.4e1 * t226 + 0.2e1 * t14 * t233 + 0.2e1 * t14 * t236 + 0.4e1 * t1 * t50 + 0.4e1 * t110 * t241 + 0.4e1 * t16 * t244 + 0.4e1 * t17 * t247 - 0.2e1 * t14 * t250;
+		t256 = t161 * t50;
+		t260 = t101 * t21;
+		t263 = t123 * t19;
+		t268 = t31 * t22;
+		t272 = t229 * t112;
+		t273 = t84 * t64;
+		t275 = M_PI * t30;
+		t276 = t13 * t275;
+		t280 = t15 * t21;
+		t281 = t280 * t50;
+		t283 = t118 * t162 - 0.4e1 * t110 * t256 - t118 * t113 + 0.4e1 * t37 * t260 - 0.2e1 * t14 * t263 - 0.4e1 * t14 * t85 - 0.2e1 * t268 - 0.2e1 * t14 * t136 + t272 + 0.4e1 * t273 + 0.2e1 * t276 * t165 - 0.4e1 * t193 + 0.8e1 * t281;
+		t285 = t30 * t6;
+		t286 = t285 * t32;
+		t288 = t156 * t32;
+		t291 = t101 * t19;
+		t294 = t48 * t50;
+		t296 = t30 * n;
+		t297 = t296 * M_PI;
+		t298 = t132 * t21;
+		t301 = t28 * t50;
+		t303 = t48 * t112;
+		t305 = t28 * t112;
+		t310 = -t8 * t175 - t14 * t286 + 0.2e1 * t1 * t288 + 0.8e1 * t16 * t291 - 0.2e1 * t294 + t156 - 0.2e1 * t297 * t298 - 0.2e1 * t301 - t303 - 0.2e1 * t199 - t305 + 0.2e1 * t71 - 0.2e1 * t276 * t23 - t9 * t288;
+		t314 = t59 * t32;
+		t321 = t135 * t33;
+		t326 = t33 * t21;
+		t333 = t27 * t21;
+		t334 = t333 * t50;
+		t338 = t15 * t11;
+		t339 = t338 * t50;
+		t341 = t27 * t189;
+		t342 = 0.4e1 * t1 * t314 - 0.2e1 * t87 * t1 * t21 - t7 * t47 - 0.6e1 * t321 - 0.4e1 * t87 * t1 * t39 - 0.6e1 * t135 * t326 - t14 * t247 + 0.2e1 * t14 * t165 - 0.2e1 * t236 - 0.4e1 * t334 + 0.2e1 * t57 * t241 + 0.4e1 * t339 + t341;
+		t343 = t15 * t47;
+		t344 = t343 * t112;
+		t346 = t343 * t50;
+		t348 = M_PI * t15;
+		t349 = t13 * t348;
+		t365 = t161 * t6;
+		t372 = M_PI * startBlockY * t6;
+		t374 = 0.2e1 * t344 + 0.4e1 * t346 + 0.12e2 * t349 * t151 - 0.2e1 * t14 * t44 - 0.2e1 * t57 * t256 + 0.4e1 * t1 * t250 + 0.8e1 * t1 * t186 + 0.8e1 * t17 * t263 - 0.2e1 * t57 * t260 - 0.6e1 * t34 - t13 * t365 - 0.2e1 * t1 * t41 - 0.2e1 * t14 * t107 - t296 * t372;
+		t379 = t150 * t10;
+		t388 = t341 * t47;
+		t390 = t96 * t21;
+		t394 = M_PI * t18 * t10;
+		t402 = -0.2e1 * t14 * t23 + t57 * t244 - 0.6e1 * t297 * t379 + 0.2e1 * t296 * t244 - 0.2e1 * t297 * t23 - t1 * t78 + 0.2e1 * t59 + t14 * t388 - 0.2e1 * t135 * t390 - 0.2e1 * t296 * t394 - 0.2e1 * t110 * t175 - t87 * t1 - 0.2e1 * t297 * t44;
+		t403 = t27 * t39;
+		t404 = t403 * t47;
+		t409 = t15 * t7;
+		t410 = t409 * t47;
+		t414 = t333 * t112;
+		t425 = t130 * t21;
+		t429 = t341 * t11;
+		t431 = 0.4e1 * t14 * t404 + 0.2e1 * t296 * t365 - 0.2e1 * t410 - 0.2e1 * t16 * t372 - 0.2e1 * t414 - 0.4e1 * t17 * t165 + t112 + t8 * t143 - 0.6e1 * t38 * t379 - t14 * t214 + 0.4e1 * t13 * t116 * t19 + 0.2e1 * t8 * t425 + 0.2e1 * t132 + t14 * t429;
+		t447 = t126 * t10;
+		t450 = t199 * t21;
+		t455 = M_PI * t5 * t10;
+		t460 = t1 * t5;
+		t463 = -0.6e1 * t118 * t91 * t47 - 0.6e1 * t38 * t151 - 0.2e1 * t297 * t41 - 0.4e1 * t17 * t298 - 0.6e1 * t297 * t151 + t48 - 0.6e1 * t135 * t65 - 0.6e1 * t38 * t447 - 0.2e1 * t1 * t450 + t9 * t247 - 0.2e1 * t37 * t455 - 0.6e1 * t1 * t379 - 0.6e1 * t460 * t326;
+		t464 = t135 * t64;
+		t467 = t403 * t21;
+		t491 = -0.6e1 * t464 + t37 * t372 + 0.8e1 * t467 - 0.6e1 * t1 * t447 - 0.4e1 * t14 * t273 + 0.2e1 * t296 * t177 + 0.2e1 * t37 * t244 - 0.6e1 * t460 * t65 + 0.6e1 * t14 * t151 + 0.8e1 * t16 * t260 - 0.2e1 * t460 * t390 + 0.4e1 * t296 * t291 - 0.12e2 * t95 * t326 - 0.2e1 * t37 * t394;
+		t501 = t202 * t112;
+		t512 = t1 * t7;
+		t518 = t27 * t19;
+		t519 = t518 * t11;
+		t522 = -0.4e1 * t16 * t394 - 0.4e1 * t110 * t260 - 0.4e1 * t95 * t390 - 0.2e1 * t1 * t79 - 0.2e1 * t14 * t501 + 0.2e1 * t297 * t288 - 0.2e1 * t14 * t314 + 0.4e1 * t84 * t65 + 0.6e1 * t276 * t127 + t56 * t512 - 0.2e1 * t38 * t298 + 0.2e1 * t37 * t365 + 0.4e1 * t14 * t519;
+		t540 = t84 * t10;
+		t550 = -0.6e1 * t14 * t464 - t8 * t177 + 0.2e1 * t110 * t244 - 0.4e1 * t14 * t339 - 0.2e1 * t1 * t298 + 0.12e2 * t14 * t212 - 0.2e1 * t38 * t44 - t13 * t177 - 0.4e1 * t87 * t1 * t19 + 0.4e1 * t540 - 0.2e1 * t297 * t165 + 0.2e1 * t296 * t101 - 0.2e1 * t13 * t394 - 0.2e1 * t9 * t314;
+		t557 = t338 * t112;
+		t567 = t518 * t21;
+		t582 = -0.4e1 * t17 * t450 - 0.2e1 * t14 * t557 + 0.4e1 * t110 * t425 + 0.2e1 * t14 * t268 + 0.2e1 * t38 * t247 + t13 * t143 + 0.8e1 * t14 * t567 - 0.4e1 * t9 * t186 + 0.2e1 * t13 * t348 * t7 - 0.2e1 * t209 + 0.4e1 * t14 * t97 + 0.2e1 * t57 * t425 - 0.12e2 * t17 * t379;
+		t587 = t145 * t47;
+		t598 = t145 * t21;
+		t609 = -t57 * t162 - 0.4e1 * t14 * t334 - t57 * t175 + t14 * t587 - 0.4e1 * t14 * t540 - 0.12e2 * t17 * t151 - t146 + 0.2e1 * t14 * t410 - 0.12e2 * t118 * t91 * t21 + 0.2e1 * t14 * t598 + 0.4e1 * t38 * t263 - 0.2e1 * t297 * t450 + 0.4e1 * t14 * t159 + 0.2e1 * t38 * t288;
+		t611 = t52 * t32;
+		t614 = t27 * t32;
+		t615 = t614 * t21;
+		t618 = M_PI * t39;
+		t634 = t285 * t19;
+		t637 = t280 * t112;
+		t639 = t27 * t6;
+		t640 = t639 * t32;
+		t642 = t280 * t6;
+		t645 = -0.2e1 * t14 * t611 + 0.12e2 * t14 * t615 + 0.4e1 * t118 * t618 * t11 - 0.2e1 * t118 * t241 - t145 + 0.4e1 * t118 * t58 * t11 + 0.2e1 * t118 * t256 - 0.2e1 * t14 * t414 + 0.4e1 * t13 * t116 * t39 - 0.2e1 * t14 * t634 + 0.4e1 * t637 - t14 * t640 - 0.4e1 * t14 * t642;
+		t654 = t333 * t6;
+		t673 = -0.2e1 * t13 * t260 - t13 * t275 * t6 + 0.4e1 * t296 * t260 - 0.6e1 * t117 * t151 - 0.2e1 * t14 * t654 + 0.6e1 * t14 * t218 + 0.4e1 * t349 * t165 + 0.4e1 * t38 * t314 - 0.12e2 * t17 * t447 - 0.12e2 * t17 * t127 + 0.2e1 * t13 * t455 + t27 - 0.4e1 * t349 * t23 - 0.6e1 * t31 * t326;
+		t682 = t409 * t11;
+		t702 = t13 * t275 * t7 - 0.2e1 * t117 * t165 + 0.6e1 * t276 * t151 - 0.2e1 * t682 - 0.8e1 * t14 * t281 + 0.2e1 * t297 * t247 - 0.2e1 * t110 * t365 - 0.2e1 * t14 * t230 - 0.4e1 * t14 * t637 + 0.4e1 * t38 * t250 - t87 * t1 * t47 + 0.2e1 * t117 * t23 - 0.2e1 * t8 * t260;
+		t705 = t518 * t47;
+		t716 = t343 * t6;
+		t719 = t614 * t11;
+		t721 = t403 * t11;
+		t726 = t409 * t21;
+		t728 = t338 * t6;
+		t731 = 0.2e1 * t13 * t425 + 0.4e1 * t14 * t705 - t13 * t116 * t6 - 0.8e1 * t110 * t60 - 0.4e1 * t16 * t455 - 0.2e1 * t14 * t76 - 0.2e1 * t14 * t716 + 0.6e1 * t719 + 0.4e1 * t721 + 0.4e1 * t297 * t314 + 0.4e1 * t642 - 0.4e1 * t726 + 0.2e1 * t728 + 0.2e1 * t716;
+		t734 = t106 * t6;
+		t735 = t229 * t6;
+		t740 = t614 * t47;
+		t742 = t31 * t10;
+		t744 = 0.2e1 * t203 + t734 + t735 + t247 + 0.2e1 * t263 - 0.2e1 * t598 - 0.2e1 * t450 - t587 - t14 * t272 + 0.6e1 * t740 + t429 - 0.2e1 * t742 + t286;
+		t747 = t75 * t10;
+		t753 = t341 * t21;
+		t761 = -0.2e1 * t41 - 0.6e1 * t379 + 0.2e1 * t747 + 0.4e1 * t186 + 0.2e1 * t314 + 0.2e1 * t611 - 0.2e1 * t654 + 0.2e1 * t753 - t14 * t735 + 0.2e1 * t250 + t288 + 0.2e1 * t1 * t6 + 0.4e1 * t705 + 0.4e1 * t519;
+		t771 = t639 * t19;
+		t779 = 0.2e1 * t233 + 0.12e2 * t615 + 0.8e1 * t567 + 0.6e1 * t14 * t127 + 0.2e1 * t634 - 0.2e1 * t771 + 0.4e1 * t53 + 0.4e1 * t404 + t388 + 0.2e1 * t44 + 0.8e1 * t38 * t186 + 0.2e1 * t298 + t123;
+		t801 = -0.4e1 * t14 * t346 - 0.6e1 * t447 - 0.6e1 * t38 * t127 + 0.6e1 * t14 * t740 - t14 * t29 + 0.2e1 * t1 * t247 - t14 * t734 - 0.4e1 * t17 * t44 - t640 + t8 * t244 - 0.2e1 * t14 * t344 - 0.4e1 * t110 * t92 + 0.2e1 * t557 - 0.2e1 * t31 * t390;
+		t830 = -0.4e1 * t118 * t58 * t47 - 0.4e1 * t14 * t186 + 0.2e1 * t9 * t263 - 0.2e1 * t9 * t250 + 0.2e1 * t14 * t138 - 0.2e1 * t14 * t104 + 0.4e1 * t17 * t288 + 0.2e1 * t501 + 0.6e1 * t13 * t116 * t32 + 0.2e1 * t37 * t177 + 0.6e1 * t14 * t379 + 0.2e1 * t14 * t41 - t118 * t190 * t47;
+		t854 = -t87 * t1 * t189 - 0.6e1 * t14 * t321 + 0.2e1 * t333 + t13 * t130 + 0.2e1 * t75 * t65 + 0.8e1 * t17 * t314 + 0.2e1 * t109 * t512 + 0.4e1 * t297 * t250 - t8 * t365 + 0.4e1 * t14 * t721 + t6 + 0.4e1 * t16 * t365 - 0.6e1 * t297 * t447 - 0.2e1 * t14 * t301;
+		t883 = 0.4e1 * t37 * t291 - 0.2e1 * t296 * t455 + 0.8e1 * t17 * t250 - 0.2e1 * t118 * t190 * t21 + t87 * t1 * t11 + 0.12e2 * t349 * t127 + 0.6e1 * t14 * t719 + 0.2e1 * t52 + 0.2e1 * t14 * t450 - 0.2e1 * t38 * t23 + 0.4e1 * t297 * t263 + 0.2e1 * t1 * t112 - 0.2e1 * t297 * t79;
+		t910 = -0.2e1 * t13 * t291 - 0.6e1 * t117 * t127 + t285 - 0.2e1 * t13 * t348 * t6 + 0.8e1 * t297 * t186 - t13 * t244 - t57 * t365 - 0.4e1 * t118 * t618 * t47 + 0.2e1 * t14 * t753 + t13 * t116 * t11 + 0.2e1 * t118 * t260 + 0.6e1 * t14 * t447 - 0.2e1 * t206 - 0.8e1 * t118 * t618 * t21;
+		t936 = -0.2e1 * t14 * t771 + 0.2e1 * t14 * t742 + t13 * t116 * t47 - 0.6e1 * t297 * t127 - 0.2e1 * t14 * t728 - t14 * t288 - 0.2e1 * t38 * t450 + 0.6e1 * t614 - 0.2e1 * t14 * t294 + 0.4e1 * t518 - 0.2e1 * t110 * t177 - 0.2e1 * t14 * t747 - 0.8e1 * t118 * t58 * t21;
+		t957 = 0.2e1 * t14 * t682 + 0.4e1 * t14 * t726 + 0.4e1 * t16 * t177 + t13 * t116 * t189 + 0.4e1 * t403 - 0.2e1 * t14 * t298 - t14 * t303 - t118 * t244 - t639 + 0.4e1 * t1 * t263 - 0.2e1 * t409 + t118 * t365 - t14 * t305 + 0.8e1 * t14 * t467;
+		t969 = pow(t5 + 0.1e1 + t19, 0.2e1);
+		t974 = pow(t5 - 0.1e1 - t19, 0.2e1);
+		t978 = n * n;
+		t982 = M_PI * M_PI;
+
+		u2b = deltaRho * t3 * (t910 + t74 + t582 + t310 + t830 + t491 + t883 + t645 + t342 + t957 + t283 + t673 + t220 + t121 + t183 + t609 + t550 + t731 + t374 + t702 + t402 + t431 + t854 + t522 + t761 + t744 + t779 + t463 + t155 + t253 + t936 + t801) / t10 / (0.1e1 + t21) / t969 / t974 / t26 / t978 / n / t982 / M_PI / viscosity / (0.1e1 + t15) / 0.2e1;
+
+		if ( y > startBlockY ) {
+			u1=u1b; u2=u2b;
+		}
+		else {
+			u1 = u1a; u2=u2a;
+		}
+
+		u1 *= cos(n*M_PI*x);
+		velocity[ J_AXIS ] += u1;
+		u2 *= sin(n*M_PI*x);
+		velocity[ I_AXIS ] += u2;
+	}
+}
+
+
+void _AnalyticBlock_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	AnalyticBlock*          self           = (AnalyticBlock*)analyticSolution;
+	double                  n;
+	double                  x, y;
+	double                  viscosity      = 1.0;
+	double                  deltaRho       = 1.0;
+	double                  startBlockX    = self->startBlockX;
+	double                  endBlockX      = self->endBlockX;
+	double                  startBlockY    = self->startBlockY;
+	double                  x0;
+	double                  dx;
+	double                  u2, u3, u5;
+	double                  u2a, u2b;
+	double                  u3a, u3b;
+	double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40;
+	double t41,t42,t44,t45,t46,t47,t48,t49,t50,t51,t52,t53,t54,t55,t56,t57,t58,t59,t60,t61,t62,t63,t64,t65,t66,t67,t68,t69,t70,t71,t72,t73,t74,t75,t76,t77,t78,t79;
+	double t82,t83,t84,t85,t86,t87,t88,t89,t90,t91,t92,t93,t94,t95,t96,t97,t98,t99,t100,t101,t102,t103,t104,t105,t106,t107,t108,t109,t110,t111,t112,t113,t114,t115,t116,t117,t118,t119,t120;
+	double t121,t123,t124,t125,t126,t127,t128,t129,t130,t131,t132,t133,t134,t135,t136,t138,t139,t140,t141,t143,t144,t145,t146,t148,t149,t150,t151,t153,t154,t155,t156,t157,t159,t160;
+	double t161,t162,t163,t164,t165,t166,t167,t169,t170,t171,t172,t173,t174,t175,t177,t178,t179,t180,t182,t183,t184,t186,t188,t189,t190,t191,t192,t193,t194,t196,t197,t199;
+	double t201,t202,t203,t205,t206,t208,t209,t210,t211,t212,t214,t216,t217,t218,t219,t220,t222,t225,t226,t228,t229,t230,t231,t233,t234,t235,t236,t238,t239;
+	double t241,t244,t247,t248,t249,t250,t252,t253,t255,t256,t257,t258,t259,t260,t262,t263,t264,t265,t266,t267,t268,t269,t270,t272,t273,t275,t276,t277,t279,t280;
+	double t281,t282,t283,t284,t285,t286,t287,t288,t289,t291,t294,t295,t296,t297,t298,t299,t300,t301,t303,t304,t305,t307,t308,t309,t310,t313,t314,t317;
+	double t321,t324,t326,t328,t329,t330,t331,t333,t334,t336,t338,t339,t341,t342,t343,t344,t346,t347,t348,t349,t350,t352,t353,t356,t359;
+	double t362,t365,t366,t367,t369,t370,t371,t372,t374,t376,t378,t379,t380,t382,t385,t387,t388,t389,t390,t392,t393,t394,t396,t399;
+	double t402,t403,t404,t405,t408,t409,t410,t411,t412,t414,t415,t416,t421,t422,t423,t425,t428,t429,t430,t431;
+	double t441,t442,t444,t447,t449,t450,t452,t453,t455,t460,t461,t463,t464,t467,t471,t473,t474,t476,t479;
+	double t483,t484,t485,t491,t492,t500,t501,t511,t512,t517,t518,t519;
+	double t522,t529,t536,t537,t540,t544,t550,t551,t553,t556,t557;
+	double t567,t573,t580,t582,t587,t598,t600;
+	double t605,t609,t611,t614,t615,t618,t626,t634,t637,t638,t639,t640;
+	double t642,t645,t646,t651,t652,t654,t657,t659,t662,t664,t673;
+	double t682,t699,t702,t705,t716,t719;
+	double t721,t726,t727,t728,t730,t731,t734,t735,t740,t742,t744,t747,t753,t755,t756;
+	double t761,t771,t779,t783,t795;
+	double t801,t806,t809,t811,t816,t823,t828,t830;
+	double t849,t854,t877;
+	double t883,t904,t910;
+	double t933,t936,t957;
+	double t962,t969,t974,t978,t982,t988;
+	double t1001,t1004,t1011,t1015;
+
+	
+	/* Find coordinate of node */
+	x = coord[ I_AXIS ];
+	y = coord[ J_AXIS ];
+
+	x0 = 0.0;
+	dx = endBlockX - startBlockX;
+
+	/* Initialise */
+	*pressure = 0.0;
+
+	for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
+
+
+		t1 = n * M_PI;
+		t2 = 0.1e1 / cosh(t1);
+		t3 = startBlockY * n;
+		t4 = t3 * M_PI;
+		t5 = tanh(t4);
+		t6 = t2 * t5;
+		t7 = 0.1e1 / cosh(t4);
+		t8 = tanh(t1);
+		t9 = t8 * t7;
+		t13 = sin(t1 * dx);
+		t15 = y * n;
+		t16 = t15 * M_PI;
+		t17 = tanh(t16);
+		t19 = t17 * t8 * t7;
+		t22 = t17 * t2;
+		t25 = t17 * n;
+		t26 = M_PI * t2;
+		t27 = t8 * t8;
+		t28 = t26 * t27;
+		t31 = t2 * startBlockY;
+		t32 = t1 * t5;
+		t34 = t17 * t17;
+		t35 = t34 * t2;
+		t37 = 0.1e1 / cosh(t16);
+		t38 = t37 * t37;
+		t39 = t38 * n;
+		t40 = t39 * M_PI;
+		t41 = t2 * t8;
+		t42 = t41 * t5;
+		t45 = t38 * t2;
+		t46 = t27 * t5;
+		t47 = t45 * t46;
+		t48 = t2 * t2;
+		t49 = t38 * t48;
+		t50 = t49 * t9;
+		t53 = t8 * t5;
+		t54 = t22 * t53;
+		t56 = t48 * t2;
+		t57 = t17 * t56;
+		t60 = t17 * t48;
+		t61 = t60 * t9;
+		t63 = 0.6e1 * t16 * t19 - 0.2e1 * t22 * t4 + 0.4e1 * t25 * t28 - t31 * t32 - t35 * t4 + 0.4e1 * t40 * t42 + t47 + t50 + 0.2e1 * t39 * t26 + 0.4e1 * t54 + 0.2e1 * t57 * t4 + 0.2e1 * t61;
+		t64 = t34 * n;
+		t67 = t34 * t56;
+		t69 = t35 * t53;
+		t71 = t35 * t46;
+		t72 = t34 * t48;
+		t73 = t72 * t9;
+		t74 = t22 * startBlockY;
+		t75 = t1 * t27;
+		t78 = t48 * t7;
+		t83 = M_PI * t7;
+		t85 = t56 * startBlockY;
+		t88 = t2 * t27;
+		t93 = 0.2e1 * t64 * t26 + t67 * t4 + 0.2e1 * t69 + t71 + t73 - 0.2e1 * t74 * t75 - 0.2e1 * t1 * t78 + 0.2e1 * t1 * t6 - t3 * t83 + t85 * t1 - t31 * t1 + 0.2e1 * t1 * t88 + 0.4e1 * t1 * t41;
+		t98 = t31 * n;
+		t99 = t8 * M_PI;
+		t104 = t17 * startBlockY;
+		t105 = t1 * t7;
+		t108 = M_PI * t56;
+		t110 = t45 * t53;
+		t113 = t22 * t46;
+		t117 = t38 * t56;
+		t118 = t117 * t5;
+		t120 = t26 * t5;
+		t123 = 0.4e1 * t25 * t26 - t15 * t26 - 0.2e1 * t98 * t99 * t5 + t15 * t83 - 0.2e1 * t104 * t105 + t15 * t108 + 0.2e1 * t110 + t85 * t32 + 0.2e1 * t113 + 0.2e1 * t16 * t110 - t16 * t118 + 0.4e1 * t25 * t120;
+		t125 = t34 * t27 * t7;
+		t128 = t48 * t8 * t7;
+		t129 = t88 * t5;
+		t130 = t45 * t27;
+		t131 = t67 * t5;
+		t133 = t49 * t7;
+		t135 = M_PI * t38;
+		t140 = t26 * t8;
+		t143 = t104 * n;
+		t144 = t27 * t8;
+		t146 = M_PI * t144 * t7;
+		t149 = t99 * t7;
+		t153 = M_PI * t48 * t7;
+		t156 = -0.3e1 * t125 + t128 + t129 + t130 - t131 - t15 * t28 + t16 * t133 - t15 * t135 * t7 + t15 * t135 * t2 - 0.2e1 * t15 * t140 - 0.2e1 * t143 * t146 - 0.6e1 * t143 * t149 - 0.2e1 * t39 * t153;
+		t159 = t45 * startBlockY;
+		t160 = t1 * t46;
+		t162 = M_PI * t27;
+		t163 = t162 * t7;
+		t166 = t38 * startBlockY;
+		t170 = M_PI * t25;
+		t171 = startBlockY * t48;
+		t172 = t171 * t7;
+		t177 = t35 * t8;
+		t182 = t171 * t9;
+		t186 = t34 * t8 * t7;
+		t191 = -t159 * t160 - 0.6e1 * t143 * t163 - t166 * t105 + 0.2e1 * t39 * t120 + 0.2e1 * t170 * t172 + 0.2e1 * t1 * t129 - 0.2e1 * t16 * t177 - 0.2e1 * t40 * t128 + 0.2e1 * t170 * t182 + 0.3e1 * t16 * t186 + t117 * t4 - t45 * t4;
+		t192 = t35 * t5;
+		t194 = t166 * n;
+		t199 = t1 * t8;
+		t206 = t57 * t5;
+		t210 = t38 * t27 * t7;
+		t217 = -t16 * t192 - t194 * t146 + 0.2e1 * t57 * startBlockY * t32 - 0.4e1 * t74 * t199 - t56 - 0.4e1 * t16 * t54 - 0.3e1 * t9 - 0.2e1 * t57 + 0.2e1 * t16 * t206 - 0.3e1 * t210 + 0.2e1 * t1 * t2 - 0.4e1 * t25 * t153 + t16 * t131;
+		t225 = M_PI * t17;
+		t236 = t38 * t8 * t7;
+		t239 = t45 * t5;
+		t241 = t45 * t8;
+		t244 = -0.2e1 * t16 * t69 - 0.2e1 * t159 * t199 - 0.2e1 * t1 * t128 + 0.2e1 * t15 * t225 * t56 + t35 - 0.2e1 * t17 * t7 + 0.2e1 * t15 * t225 * t7 - t159 * t75 - 0.3e1 * t16 * t236 - t117 + t16 * t239 + 0.2e1 * t16 * t241;
+		t249 = t64 * M_PI;
+		t253 = t38 * t144 * t7;
+		t258 = t22 * t5;
+		t264 = -t38 * t7 + t6 - 0.3e1 * t194 * t163 + t40 * t172 + t249 * t172 - t3 * t146 - t16 * t253 - t15 * t135 * t56 - t159 * t32 + t2 - 0.2e1 * t16 * t258 + t249 * t182 + t67 * startBlockY * t32;
+		t270 = t60 * t7;
+		t275 = t17 * t144 * t7;
+		t279 = t72 * t7;
+		t282 = t34 * t144 * t7;
+		t284 = t35 * t27;
+		t286 = 0.4e1 * t64 * t140 - 0.2e1 * t16 * t270 + t16 * t130 + 0.2e1 * t16 * t275 + t40 * t182 - t16 * t279 + t16 * t282 + t284 - 0.3e1 * t186 + t192 + t279 - t282;
+		t287 = t35 * startBlockY;
+		t295 = t22 * t27;
+		t299 = t22 * t8;
+		t304 = t17 * t27 * t7;
+		t307 = -0.2e1 * t287 * t199 + 0.2e1 * t249 * t129 - t34 * t7 + 0.4e1 * t249 * t42 + 0.2e1 * t295 + 0.2e1 * t241 - 0.3e1 * t236 + t239 - t253 + 0.4e1 * t299 - t118 - 0.2e1 * t64 * t153 + 0.6e1 * t16 * t304;
+		t309 = t34 * startBlockY;
+		t317 = M_PI * t34;
+		t328 = t309 * n;
+		t330 = -t309 * t105 + t117 * startBlockY * t32 - t7 + 0.4e1 * t39 * t140 + 0.2e1 * t64 * t120 + t45 + t15 * t317 * t7 - 0.2e1 * t249 * t128 - 0.3e1 * t3 * t149 + 0.2e1 * t39 * t28 - 0.3e1 * t194 * t149 - t328 * t146;
+		t342 = t1 * t53;
+		t349 = -0.3e1 * t328 * t149 + t15 * t317 * t56 - t67 - t16 * t284 - 0.3e1 * t328 * t163 + 0.2e1 * t64 * t28 - t15 * t317 * t2 - 0.2e1 * t159 * t342 - t287 * t160 + t133 + 0.2e1 * t258 + 0.2e1 * t270 - 0.2e1 * t275;
+		t371 = -0.6e1 * t304 - t287 * t75 + 0.2e1 * t177 + 0.4e1 * t170 * t129 - 0.2e1 * t15 * t225 * t2 - t287 * t32 - 0.3e1 * t3 * t163 - 0.2e1 * t287 * t342 - 0.2e1 * t16 * t295 + 0.8e1 * t170 * t42 + t88 - 0.2e1 * t16 * t61;
+		t390 = -0.2e1 * t206 + 0.2e1 * t42 - 0.6e1 * t19 - 0.2e1 * t74 * t160 + 0.3e1 * t16 * t125 - 0.2e1 * t74 * t32 - 0.4e1 * t74 * t342 + 0.3e1 * t15 * t149 + 0.2e1 * t41 - t16 * t128 - 0.4e1 * t170 * t128 - t15 * t120 + t78;
+		t411 = -t16 * t129 - 0.2e1 * t16 * t42 - 0.4e1 * t16 * t299 - t16 * t73 + t15 * t108 * t5 - 0.3e1 * t16 * t210 + 0.4e1 * t1 * t42 + t16 * t50 + t15 * t146 - t15 * t153 - 0.2e1 * t31 * t199 - 0.2e1 * t16 * t113;
+		t430 = -t31 * t75 - t16 * t71 - t144 * t7 + 0.3e1 * t15 * t163 + t16 * t47 - t56 * t5 + 0.8e1 * t25 * t140 - t98 * t162 * t5 - 0.3e1 * t27 * t7 + t1 * t172 + t4 * t128 + 0.2e1 * t40 * t129 + 0.2e1 * t22;
+		t441 = n * n;
+		t444 = M_PI * M_PI;
+		t449 = pow(t2 + 0.1e1 + t8, 0.2e1);
+		t453 = pow(t2 - 0.1e1 - t8, 0.2e1);
+
+		u2a = (t2 + t6 - t7 - t9) * deltaRho * t13 * (t63 + t93 + t123 + t156 + t191 + t217 + t244 + t264 + t286 + t307 + t330 + t349 + t371 + t390 + t411 + t430) / t7 / (0.1e1 + t5) / t441 / n / t444 / M_PI / t449 / t453 / t37 / viscosity / (0.1e1 + t17) / 0.2e1;
+
+		t1 = n * M_PI;
+		t3 = sin(t1 * dx);
+		t5 = 0.1e1 / cosh(t1);
+		t6 = t5 * t5;
+		t7 = t6 * t6;
+		t8 = startBlockY * n;
+		t9 = t8 * M_PI;
+		t10 = 0.1e1 / cosh(t9);
+		t11 = t10 * t10;
+		t13 = y * n;
+		t14 = t13 * M_PI;
+		t15 = tanh(t14);
+		t16 = t15 * n;
+		t17 = t16 * M_PI;
+		t18 = t6 * t5;
+		t19 = tanh(t1);
+		t20 = t18 * t19;
+		t21 = tanh(t9);
+		t22 = t10 * t21;
+		t23 = t20 * t22;
+		t26 = 0.1e1 / cosh(t14);
+		t27 = t26 * t26;
+		t28 = t27 * t11;
+		t29 = t28 * t6;
+		t30 = t15 * t15;
+		t31 = t30 * t5;
+		t32 = t19 * t19;
+		t33 = t32 * t10;
+		t34 = t31 * t33;
+		t37 = t27 * n;
+		t38 = t37 * M_PI;
+		t39 = t32 * t19;
+		t40 = t5 * t39;
+		t41 = t40 * t10;
+		t44 = t20 * t10;
+		t47 = t21 * t21;
+		t48 = t27 * t47;
+		t49 = t48 * t6;
+		t50 = t6 * t19;
+		t52 = t15 * t6;
+		t53 = t52 * t19;
+		t56 = t30 * startBlockY;
+		t57 = t56 * n;
+		t58 = M_PI * t19;
+		t59 = t21 * t6;
+		t60 = t58 * t59;
+		t64 = t19 * t10;
+		t65 = t64 * t21;
+		t68 = t27 * t18;
+		t71 = t68 * t22;
+		t74 = -t7 * t11 - 0.4e1 * t17 * t23 - t29 + 0.6e1 * t14 * t34 - 0.2e1 * t38 * t41 - 0.2e1 * t1 * t44 - t49 + 0.2e1 * t50 - 0.4e1 * t14 * t53 - 0.4e1 * t57 * t60 - 0.2e1 * t1 * t18 * t65 + 0.2e1 * t68 * t65 + 0.2e1 * t14 * t71;
+		t75 = t30 * t18;
+		t76 = t75 * t22;
+		t78 = startBlockY * t6;
+		t79 = t78 * t19;
+		t84 = t15 * t18;
+		t85 = t84 * t22;
+		t87 = t27 * startBlockY;
+		t91 = M_PI * t32;
+		t92 = t91 * t59;
+		t95 = t15 * t5;
+		t96 = t39 * t10;
+		t97 = t95 * t96;
+		t99 = t95 * t64;
+		t101 = M_PI * t6;
+		t104 = t75 * t64;
+		t106 = t30 * t11;
+		t107 = t106 * t50;
+		t109 = t15 * startBlockY;
+		t110 = t109 * n;
+		t111 = M_PI * t11;
+		t112 = t6 * t32;
+		t113 = t111 * t112;
+		t116 = M_PI * t27;
+		t117 = t13 * t116;
+		t118 = t87 * n;
+		t121 = 0.2e1 * t76 - 0.4e1 * t17 * t79 - 0.2e1 * t7 * t21 + 0.4e1 * t85 - 0.6e1 * t87 * t1 * t32 - 0.2e1 * t57 * t92 - 0.4e1 * t97 - 0.12e2 * t99 + 0.4e1 * t16 * t101 + 0.2e1 * t104 + 0.2e1 * t107 + 0.2e1 * t110 * t113 + t117 + 0.4e1 * t118 * t60;
+		t123 = t11 * t6;
+		t126 = t5 * t19;
+		t127 = t126 * t22;
+		t130 = M_PI * t7;
+		t132 = t18 * t10;
+		t135 = t27 * t5;
+		t136 = t135 * t10;
+		t138 = t68 * t64;
+		t143 = t130 * t47;
+		t145 = t30 * t7;
+		t146 = t145 * t11;
+		t150 = t5 * t32;
+		t151 = t150 * t22;
+		t155 = 0.2e1 * t1 * t123 - 0.6e1 * t127 - t13 * t101 + t8 * t130 - 0.2e1 * t1 * t132 - 0.2e1 * t136 + 0.2e1 * t138 + 0.6e1 * t118 * t91 * t11 + t57 * t143 + t14 * t146 - 0.4e1 * t17 * t41 - 0.6e1 * t151 + 0.4e1 * t1 * t59;
+		t156 = t47 * t6;
+		t159 = t95 * t10;
+		t161 = M_PI * t47;
+		t162 = t161 * t112;
+		t165 = t40 * t22;
+		t175 = t130 * t11;
+		t177 = t91 * t6;
+		t183 = 0.2e1 * t1 * t156 - 0.4e1 * t159 - 0.2e1 * t110 * t162 - 0.2e1 * t38 * t165 - 0.2e1 * t165 - t7 + 0.2e1 * t110 * t143 + 0.2e1 * t118 * t92 + 0.2e1 * t38 * t79 + t13 * t175 - t57 * t177 + t118 * t177 - t14 * t49 - 0.12e2 * t95 * t65;
+		t186 = t59 * t19;
+		t189 = t32 * t32;
+		t190 = M_PI * t189;
+		t193 = t95 * t22;
+		t199 = t5 * t10;
+		t202 = t30 * t21;
+		t203 = t202 * t6;
+		t206 = t135 * t96;
+		t209 = t135 * t22;
+		t212 = t95 * t33;
+		t214 = t106 * t112;
+		t218 = t31 * t64;
+		t220 = 0.16e2 * t17 * t186 + t118 * t190 * t11 + 0.4e1 * t14 * t193 - 0.6e1 * t31 * t65 + 0.2e1 * t23 - 0.2e1 * t1 * t199 - 0.2e1 * t14 * t203 - 0.2e1 * t14 * t206 - 0.2e1 * t14 * t209 - 0.12e2 * t212 + t214 + 0.2e1 * t13 * t116 * t21 - 0.6e1 * t218;
+		t226 = t202 * t50;
+		t229 = t30 * t47;
+		t230 = t229 * t50;
+		t233 = t68 * t10;
+		t236 = t31 * t96;
+		t241 = t111 * t50;
+		t244 = t101 * t11;
+		t247 = t123 * t32;
+		t250 = t156 * t19;
+		t253 = t57 * t113 + t28 + 0.12e2 * t14 * t99 + 0.2e1 * t37 * t101 - 0.4e1 * t14 * t226 + 0.2e1 * t230 + 0.4e1 * t226 + 0.2e1 * t14 * t233 + 0.2e1 * t14 * t236 + 0.4e1 * t1 * t50 + 0.4e1 * t110 * t241 + 0.4e1 * t16 * t244 + 0.4e1 * t17 * t247 - 0.2e1 * t14 * t250;
+		t256 = t161 * t50;
+		t260 = t101 * t21;
+		t263 = t123 * t19;
+		t268 = t31 * t22;
+		t272 = t229 * t112;
+		t273 = t84 * t64;
+		t275 = M_PI * t30;
+		t276 = t13 * t275;
+		t280 = t15 * t21;
+		t281 = t280 * t50;
+		t283 = t118 * t162 - 0.4e1 * t110 * t256 - t118 * t113 + 0.4e1 * t37 * t260 - 0.2e1 * t14 * t263 - 0.4e1 * t14 * t85 - 0.2e1 * t268 - 0.2e1 * t14 * t136 + t272 + 0.4e1 * t273 + 0.2e1 * t276 * t165 - 0.4e1 * t193 + 0.8e1 * t281;
+		t285 = t30 * t6;
+		t286 = t285 * t32;
+		t288 = t156 * t32;
+		t291 = t101 * t19;
+		t294 = t48 * t50;
+		t296 = t30 * n;
+		t297 = t296 * M_PI;
+		t298 = t132 * t21;
+		t301 = t28 * t50;
+		t303 = t48 * t112;
+		t305 = t28 * t112;
+		t310 = -t8 * t175 - t14 * t286 + 0.2e1 * t1 * t288 + 0.8e1 * t16 * t291 - 0.2e1 * t294 + t156 - 0.2e1 * t297 * t298 - 0.2e1 * t301 - t303 - 0.2e1 * t199 - t305 + 0.2e1 * t71 - 0.2e1 * t276 * t23 - t9 * t288;
+		t314 = t59 * t32;
+		t321 = t135 * t33;
+		t326 = t33 * t21;
+		t333 = t27 * t21;
+		t334 = t333 * t50;
+		t338 = t15 * t11;
+		t339 = t338 * t50;
+		t341 = t27 * t189;
+		t342 = 0.4e1 * t1 * t314 - 0.2e1 * t87 * t1 * t21 - t7 * t47 - 0.6e1 * t321 - 0.4e1 * t87 * t1 * t39 - 0.6e1 * t135 * t326 - t14 * t247 + 0.2e1 * t14 * t165 - 0.2e1 * t236 - 0.4e1 * t334 + 0.2e1 * t57 * t241 + 0.4e1 * t339 + t341;
+		t343 = t15 * t47;
+		t344 = t343 * t112;
+		t346 = t343 * t50;
+		t348 = M_PI * t15;
+		t349 = t13 * t348;
+		t365 = t161 * t6;
+		t372 = M_PI * startBlockY * t6;
+		t374 = 0.2e1 * t344 + 0.4e1 * t346 + 0.12e2 * t349 * t151 - 0.2e1 * t14 * t44 - 0.2e1 * t57 * t256 + 0.4e1 * t1 * t250 + 0.8e1 * t1 * t186 + 0.8e1 * t17 * t263 - 0.2e1 * t57 * t260 - 0.6e1 * t34 - t13 * t365 - 0.2e1 * t1 * t41 - 0.2e1 * t14 * t107 - t296 * t372;
+		t379 = t150 * t10;
+		t388 = t341 * t47;
+		t390 = t96 * t21;
+		t394 = M_PI * t18 * t10;
+		t402 = -0.2e1 * t14 * t23 + t57 * t244 - 0.6e1 * t297 * t379 + 0.2e1 * t296 * t244 - 0.2e1 * t297 * t23 - t1 * t78 + 0.2e1 * t59 + t14 * t388 - 0.2e1 * t135 * t390 - 0.2e1 * t296 * t394 - 0.2e1 * t110 * t175 - t87 * t1 - 0.2e1 * t297 * t44;
+		t403 = t27 * t39;
+		t404 = t403 * t47;
+		t409 = t15 * t7;
+		t410 = t409 * t47;
+		t414 = t333 * t112;
+		t425 = t130 * t21;
+		t429 = t341 * t11;
+		t431 = 0.4e1 * t14 * t404 + 0.2e1 * t296 * t365 - 0.2e1 * t410 - 0.2e1 * t16 * t372 - 0.2e1 * t414 - 0.4e1 * t17 * t165 + t112 + t8 * t143 - 0.6e1 * t38 * t379 - t14 * t214 + 0.4e1 * t13 * t116 * t19 + 0.2e1 * t8 * t425 + 0.2e1 * t132 + t14 * t429;
+		t447 = t126 * t10;
+		t450 = t199 * t21;
+		t455 = M_PI * t5 * t10;
+		t460 = t1 * t5;
+		t463 = -0.6e1 * t118 * t91 * t47 - 0.6e1 * t38 * t151 - 0.2e1 * t297 * t41 - 0.4e1 * t17 * t298 - 0.6e1 * t297 * t151 + t48 - 0.6e1 * t135 * t65 - 0.6e1 * t38 * t447 - 0.2e1 * t1 * t450 + t9 * t247 - 0.2e1 * t37 * t455 - 0.6e1 * t1 * t379 - 0.6e1 * t460 * t326;
+		t464 = t135 * t64;
+		t467 = t403 * t21;
+		t491 = -0.6e1 * t464 + t37 * t372 + 0.8e1 * t467 - 0.6e1 * t1 * t447 - 0.4e1 * t14 * t273 + 0.2e1 * t296 * t177 + 0.2e1 * t37 * t244 - 0.6e1 * t460 * t65 + 0.6e1 * t14 * t151 + 0.8e1 * t16 * t260 - 0.2e1 * t460 * t390 + 0.4e1 * t296 * t291 - 0.12e2 * t95 * t326 - 0.2e1 * t37 * t394;
+		t501 = t202 * t112;
+		t512 = t1 * t7;
+		t518 = t27 * t19;
+		t519 = t518 * t11;
+		t522 = -0.4e1 * t16 * t394 - 0.4e1 * t110 * t260 - 0.4e1 * t95 * t390 - 0.2e1 * t1 * t79 - 0.2e1 * t14 * t501 + 0.2e1 * t297 * t288 - 0.2e1 * t14 * t314 + 0.4e1 * t84 * t65 + 0.6e1 * t276 * t127 + t56 * t512 - 0.2e1 * t38 * t298 + 0.2e1 * t37 * t365 + 0.4e1 * t14 * t519;
+		t540 = t84 * t10;
+		t550 = -0.6e1 * t14 * t464 - t8 * t177 + 0.2e1 * t110 * t244 - 0.4e1 * t14 * t339 - 0.2e1 * t1 * t298 + 0.12e2 * t14 * t212 - 0.2e1 * t38 * t44 - t13 * t177 - 0.4e1 * t87 * t1 * t19 + 0.4e1 * t540 - 0.2e1 * t297 * t165 + 0.2e1 * t296 * t101 - 0.2e1 * t13 * t394 - 0.2e1 * t9 * t314;
+		t557 = t338 * t112;
+		t567 = t518 * t21;
+		t582 = -0.4e1 * t17 * t450 - 0.2e1 * t14 * t557 + 0.4e1 * t110 * t425 + 0.2e1 * t14 * t268 + 0.2e1 * t38 * t247 + t13 * t143 + 0.8e1 * t14 * t567 - 0.4e1 * t9 * t186 + 0.2e1 * t13 * t348 * t7 - 0.2e1 * t209 + 0.4e1 * t14 * t97 + 0.2e1 * t57 * t425 - 0.12e2 * t17 * t379;
+		t587 = t145 * t47;
+		t598 = t145 * t21;
+		t609 = -t57 * t162 - 0.4e1 * t14 * t334 - t57 * t175 + t14 * t587 - 0.4e1 * t14 * t540 - 0.12e2 * t17 * t151 - t146 + 0.2e1 * t14 * t410 - 0.12e2 * t118 * t91 * t21 + 0.2e1 * t14 * t598 + 0.4e1 * t38 * t263 - 0.2e1 * t297 * t450 + 0.4e1 * t14 * t159 + 0.2e1 * t38 * t288;
+		t611 = t52 * t32;
+		t614 = t27 * t32;
+		t615 = t614 * t21;
+		t618 = M_PI * t39;
+		t634 = t285 * t19;
+		t637 = t280 * t112;
+		t639 = t27 * t6;
+		t640 = t639 * t32;
+		t642 = t280 * t6;
+		t645 = -0.2e1 * t14 * t611 + 0.12e2 * t14 * t615 + 0.4e1 * t118 * t618 * t11 - 0.2e1 * t118 * t241 - t145 + 0.4e1 * t118 * t58 * t11 + 0.2e1 * t118 * t256 - 0.2e1 * t14 * t414 + 0.4e1 * t13 * t116 * t39 - 0.2e1 * t14 * t634 + 0.4e1 * t637 - t14 * t640 - 0.4e1 * t14 * t642;
+		t654 = t333 * t6;
+		t673 = -0.2e1 * t13 * t260 - t13 * t275 * t6 + 0.4e1 * t296 * t260 - 0.6e1 * t117 * t151 - 0.2e1 * t14 * t654 + 0.6e1 * t14 * t218 + 0.4e1 * t349 * t165 + 0.4e1 * t38 * t314 - 0.12e2 * t17 * t447 - 0.12e2 * t17 * t127 + 0.2e1 * t13 * t455 + t27 - 0.4e1 * t349 * t23 - 0.6e1 * t31 * t326;
+		t682 = t409 * t11;
+		t702 = t13 * t275 * t7 - 0.2e1 * t117 * t165 + 0.6e1 * t276 * t151 - 0.2e1 * t682 - 0.8e1 * t14 * t281 + 0.2e1 * t297 * t247 - 0.2e1 * t110 * t365 - 0.2e1 * t14 * t230 - 0.4e1 * t14 * t637 + 0.4e1 * t38 * t250 - t87 * t1 * t47 + 0.2e1 * t117 * t23 - 0.2e1 * t8 * t260;
+		t705 = t518 * t47;
+		t716 = t343 * t6;
+		t719 = t614 * t11;
+		t721 = t403 * t11;
+		t726 = t409 * t21;
+		t728 = t338 * t6;
+		t731 = 0.2e1 * t13 * t425 + 0.4e1 * t14 * t705 - t13 * t116 * t6 - 0.8e1 * t110 * t60 - 0.4e1 * t16 * t455 - 0.2e1 * t14 * t76 - 0.2e1 * t14 * t716 + 0.6e1 * t719 + 0.4e1 * t721 + 0.4e1 * t297 * t314 + 0.4e1 * t642 - 0.4e1 * t726 + 0.2e1 * t728 + 0.2e1 * t716;
+		t734 = t106 * t6;
+		t735 = t229 * t6;
+		t740 = t614 * t47;
+		t742 = t31 * t10;
+		t744 = 0.2e1 * t203 + t734 + t735 + t247 + 0.2e1 * t263 - 0.2e1 * t598 - 0.2e1 * t450 - t587 - t14 * t272 + 0.6e1 * t740 + t429 - 0.2e1 * t742 + t286;
+		t747 = t75 * t10;
+		t753 = t341 * t21;
+		t761 = -0.2e1 * t41 - 0.6e1 * t379 + 0.2e1 * t747 + 0.4e1 * t186 + 0.2e1 * t314 + 0.2e1 * t611 - 0.2e1 * t654 + 0.2e1 * t753 - t14 * t735 + 0.2e1 * t250 + t288 + 0.2e1 * t1 * t6 + 0.4e1 * t705 + 0.4e1 * t519;
+		t771 = t639 * t19;
+		t779 = 0.2e1 * t233 + 0.12e2 * t615 + 0.8e1 * t567 + 0.6e1 * t14 * t127 + 0.2e1 * t634 - 0.2e1 * t771 + 0.4e1 * t53 + 0.4e1 * t404 + t388 + 0.2e1 * t44 + 0.8e1 * t38 * t186 + 0.2e1 * t298 + t123;
+		t801 = -0.4e1 * t14 * t346 - 0.6e1 * t447 - 0.6e1 * t38 * t127 + 0.6e1 * t14 * t740 - t14 * t29 + 0.2e1 * t1 * t247 - t14 * t734 - 0.4e1 * t17 * t44 - t640 + t8 * t244 - 0.2e1 * t14 * t344 - 0.4e1 * t110 * t92 + 0.2e1 * t557 - 0.2e1 * t31 * t390;
+		t830 = -0.4e1 * t118 * t58 * t47 - 0.4e1 * t14 * t186 + 0.2e1 * t9 * t263 - 0.2e1 * t9 * t250 + 0.2e1 * t14 * t138 - 0.2e1 * t14 * t104 + 0.4e1 * t17 * t288 + 0.2e1 * t501 + 0.6e1 * t13 * t116 * t32 + 0.2e1 * t37 * t177 + 0.6e1 * t14 * t379 + 0.2e1 * t14 * t41 - t118 * t190 * t47;
+		t854 = -t87 * t1 * t189 - 0.6e1 * t14 * t321 + 0.2e1 * t333 + t13 * t130 + 0.2e1 * t75 * t65 + 0.8e1 * t17 * t314 + 0.2e1 * t109 * t512 + 0.4e1 * t297 * t250 - t8 * t365 + 0.4e1 * t14 * t721 + t6 + 0.4e1 * t16 * t365 - 0.6e1 * t297 * t447 - 0.2e1 * t14 * t301;
+		t883 = 0.4e1 * t37 * t291 - 0.2e1 * t296 * t455 + 0.8e1 * t17 * t250 - 0.2e1 * t118 * t190 * t21 + t87 * t1 * t11 + 0.12e2 * t349 * t127 + 0.6e1 * t14 * t719 + 0.2e1 * t52 + 0.2e1 * t14 * t450 - 0.2e1 * t38 * t23 + 0.4e1 * t297 * t263 + 0.2e1 * t1 * t112 - 0.2e1 * t297 * t79;
+		t910 = -0.2e1 * t13 * t291 - 0.6e1 * t117 * t127 + t285 - 0.2e1 * t13 * t348 * t6 + 0.8e1 * t297 * t186 - t13 * t244 - t57 * t365 - 0.4e1 * t118 * t618 * t47 + 0.2e1 * t14 * t753 + t13 * t116 * t11 + 0.2e1 * t118 * t260 + 0.6e1 * t14 * t447 - 0.2e1 * t206 - 0.8e1 * t118 * t618 * t21;
+		t936 = -0.2e1 * t14 * t771 + 0.2e1 * t14 * t742 + t13 * t116 * t47 - 0.6e1 * t297 * t127 - 0.2e1 * t14 * t728 - t14 * t288 - 0.2e1 * t38 * t450 + 0.6e1 * t614 - 0.2e1 * t14 * t294 + 0.4e1 * t518 - 0.2e1 * t110 * t177 - 0.2e1 * t14 * t747 - 0.8e1 * t118 * t58 * t21;
+		t957 = 0.2e1 * t14 * t682 + 0.4e1 * t14 * t726 + 0.4e1 * t16 * t177 + t13 * t116 * t189 + 0.4e1 * t403 - 0.2e1 * t14 * t298 - t14 * t303 - t118 * t244 - t639 + 0.4e1 * t1 * t263 - 0.2e1 * t409 + t118 * t365 - t14 * t305 + 0.8e1 * t14 * t467;
+		t969 = pow(t5 + 0.1e1 + t19, 0.2e1);
+		t974 = pow(t5 - 0.1e1 - t19, 0.2e1);
+		t978 = n * n;
+		t982 = M_PI * M_PI;
+
+		u2b = deltaRho * t3 * (t910 + t74 + t582 + t310 + t830 + t491 + t883 + t645 + t342 + t957 + t283 + t673 + t220 + t121 + t183 + t609 + t550 + t731 + t374 + t702 + t402 + t431 + t854 + t522 + t761 + t744 + t779 + t463 + t155 + t253 + t936 + t801) / t10 / (0.1e1 + t21) / t969 / t974 / t26 / t978 / n / t982 / M_PI / viscosity / (0.1e1 + t15) / 0.2e1;
+
+		t1 = n * M_PI;
+		t2 = 0.1e1 / cosh(t1);
+		t3 = startBlockY * n;
+		t4 = t3 * M_PI;
+		t5 = tanh(t4);
+		t6 = t2 * t5;
+		t7 = 0.1e1 / cosh(t4);
+		t8 = tanh(t1);
+		t9 = t8 * t7;
+		t13 = sin(t1 * dx);
+		t15 = y * n;
+		t16 = t15 * M_PI;
+		t17 = tanh(t16);
+		t18 = t17 * t17;
+		t19 = t18 * t2;
+		t20 = t19 * startBlockY;
+		t21 = t8 * t8;
+		t22 = t21 * t5;
+		t23 = t1 * t22;
+		t25 = t2 * t2;
+		t26 = t25 * t2;
+		t27 = t18 * t26;
+		t29 = t1 * t5;
+		t31 = 0.1e1 / cosh(t16);
+		t32 = t31 * t31;
+		t33 = t32 * n;
+		t34 = M_PI * t2;
+		t35 = t34 * t21;
+		t38 = M_PI * t18;
+		t41 = t17 * t26;
+		t45 = t17 * startBlockY;
+		t46 = t45 * n;
+		t47 = M_PI * t21;
+		t48 = t47 * t7;
+		t51 = t19 * t8;
+		t53 = t19 * t21;
+		t57 = M_PI * t17;
+		t62 = t18 * n;
+		t65 = -t20 * t23 + t27 * startBlockY * t29 + 0.2e1 * t33 * t35 + t15 * t38 * t26 + 0.2e1 * t41 * startBlockY * t29 - 0.6e1 * t46 * t48 + 0.4e1 * t51 + 0.2e1 * t53 - t15 * t38 * t2 - 0.2e1 * t15 * t57 * t2 - 0.2e1 * t27 + 0.2e1 * t62 * t35;
+		t66 = t62 * M_PI;
+		t67 = t2 * t21;
+		t68 = t67 * t5;
+		t71 = t32 * t2;
+		t72 = t71 * startBlockY;
+		t73 = t8 * t5;
+		t74 = t1 * t73;
+		t77 = t17 * n;
+		t78 = t77 * M_PI;
+		t82 = t17 * t21 * t7;
+		t87 = t18 * startBlockY;
+		t88 = t87 * n;
+		t89 = M_PI * t8;
+		t90 = t89 * t7;
+		t93 = t21 * t8;
+		t97 = t2 * t8;
+		t98 = t97 * t5;
+		t102 = t17 * t2;
+		t103 = t102 * startBlockY;
+		t110 = 0.2e1 * t66 * t68 - 0.2e1 * t72 * t74 + 0.4e1 * t78 * t68 + 0.6e1 * t16 * t82 + 0.2e1 * t1 * t68 - 0.3e1 * t88 * t90 - 0.2e1 * t93 * t7 + 0.2e1 * t2 + 0.8e1 * t78 * t98 - 0.6e1 * t9 - 0.2e1 * t103 * t29 - 0.4e1 * t103 * t74 - 0.2e1 * t103 * t23;
+		t113 = t25 * t8 * t7;
+		t116 = t102 * t73;
+		t123 = M_PI * t26;
+		t127 = M_PI * t93 * t7;
+		t132 = M_PI * t25 * t7;
+		t134 = t33 * M_PI;
+		t140 = -t16 * t113 - t16 * t68 - 0.4e1 * t16 * t116 - 0.4e1 * t17 * t7 - 0.2e1 * t16 * t98 + t15 * t123 * t5 + t15 * t127 + 0.3e1 * t15 * t48 - t15 * t132 + 0.2e1 * t134 * t68 + 0.4e1 * t134 * t98 + 0.4e1 * t102;
+		t141 = t34 * t5;
+		t145 = t18 * t25;
+		t146 = t145 * t7;
+		t148 = t32 * startBlockY;
+		t149 = t148 * n;
+		t154 = t25 * t7;
+		t156 = t102 * t22;
+		t159 = t18 * t93 * t7;
+		t166 = t102 * t21;
+		t169 = t102 * t8;
+		t172 = 0.2e1 * t62 * t141 - t72 * t23 - t16 * t146 - 0.3e1 * t149 * t48 - 0.3e1 * t88 * t48 + 0.2e1 * t154 + 0.4e1 * t156 + t16 * t159 + t15 * t38 * t7 + 0.4e1 * t77 * t34 - t15 * t34 - 0.2e1 * t16 * t166 - 0.4e1 * t16 * t169;
+		t177 = t17 * t8 * t7;
+		t180 = M_PI * t32;
+		t183 = startBlockY * t25;
+		t184 = t183 * t7;
+		t186 = t1 * t8;
+		t192 = t32 * t26;
+		t193 = t192 * t5;
+		t196 = t32 * t21 * t7;
+		t201 = 0.2e1 * t6 + 0.6e1 * t16 * t177 - t15 * t180 * t26 + t66 * t184 - 0.2e1 * t20 * t186 + 0.4e1 * t98 - 0.12e2 * t177 + 0.8e1 * t169 - 0.2e1 * t193 - 0.6e1 * t196 + 0.2e1 * t1 * t2 + 0.2e1 * t67;
+		t202 = t71 * t73;
+		t205 = M_PI * t7;
+		t218 = t145 * t9;
+		t226 = 0.2e1 * t16 * t202 + t15 * t205 - t15 * t180 * t7 + t15 * t180 * t2 + 0.4e1 * t202 + t15 * t123 - 0.3e1 * t149 * t90 - 0.2e1 * t33 * t132 + t134 * t184 - t16 * t218 - 0.2e1 * t72 * t186 - 0.2e1 * t1 * t154 - 0.2e1 * t134 * t113;
+		t228 = t1 * t7;
+		t235 = t2 * startBlockY;
+		t236 = t235 * n;
+		t244 = t19 * t22;
+		t248 = t26 * startBlockY;
+		t252 = -t148 * t228 + 0.2e1 * t33 * t141 - t20 * t29 + 0.2e1 * t1 * t6 - t236 * t47 * t5 - t235 * t29 - 0.2e1 * t236 * t89 * t5 - t3 * t205 - t16 * t244 - 0.2e1 * t20 * t74 + t248 * t1 + 0.4e1 * t66 * t98;
+		t257 = t34 * t8;
+		t265 = t17 * t25;
+		t266 = t265 * t9;
+		t269 = t1 * t21;
+		t277 = t102 * t5;
+		t280 = -t235 * t1 - t149 * t127 + 0.2e1 * t1 * t67 + 0.4e1 * t62 * t257 - t72 * t29 - 0.2e1 * t16 * t51 + 0.4e1 * t1 * t97 - 0.2e1 * t16 * t266 - 0.2e1 * t103 * t269 - 0.2e1 * t45 * t228 + 0.4e1 * t77 * t141 - t72 * t269 - 0.2e1 * t16 * t277;
+		t286 = t265 * t7;
+		t289 = t71 * t21;
+		t291 = t41 * t5;
+		t296 = t32 * t25;
+		t297 = t296 * t7;
+		t307 = -0.2e1 * t1 * t113 - 0.2e1 * t16 * t286 + t16 * t289 + 0.2e1 * t16 * t291 + 0.2e1 * t71 - t16 * t193 + t16 * t297 - t3 * t127 - 0.2e1 * t16 * t156 - 0.2e1 * t235 * t186 - 0.3e1 * t3 * t90 - t19 * t4;
+		t310 = t18 * t8 * t7;
+		t331 = t27 * t4 + 0.3e1 * t16 * t310 + 0.2e1 * t15 * t57 * t26 - 0.2e1 * t192 + 0.8e1 * t77 * t257 + 0.2e1 * t78 * t184 - t16 * t53 + 0.4e1 * t33 * t257 + 0.3e1 * t15 * t90 - t15 * t141 - 0.4e1 * t78 * t113 + 0.2e1 * t244 - t20 * t269;
+		t334 = t19 * t5;
+		t339 = t18 * t21 * t7;
+		t341 = t27 * t5;
+		t347 = t71 * t8;
+		t350 = t32 * t8 * t7;
+		t352 = -0.6e1 * t310 + 0.2e1 * t334 + 0.2e1 * t146 - 0.2e1 * t159 - 0.6e1 * t339 - 0.2e1 * t341 + 0.2e1 * t113 + 0.2e1 * t68 + 0.2e1 * t289 + 0.4e1 * t166 + 0.4e1 * t347 - 0.6e1 * t350;
+		t353 = t71 * t5;
+		t356 = t32 * t93 * t7;
+		t362 = t17 * t93 * t7;
+		t366 = t19 * t73;
+		t369 = t183 * t9;
+		t376 = 0.2e1 * t353 - 0.2e1 * t356 + 0.2e1 * t297 + 0.4e1 * t277 + 0.4e1 * t286 - 0.4e1 * t362 - 0.12e2 * t82 - 0.4e1 * t291 + 0.4e1 * t366 + 0.2e1 * t218 + 0.2e1 * t78 * t369 + 0.2e1 * t62 * t34 - 0.6e1 * t21 * t7;
+		t399 = -0.2e1 * t62 * t132 - 0.2e1 * t66 * t113 + 0.2e1 * t15 * t57 * t7 - 0.3e1 * t16 * t350 + t16 * t353 - 0.2e1 * t32 * t7 - 0.4e1 * t41 + 0.4e1 * t97 + 0.8e1 * t116 - 0.4e1 * t103 * t186 - 0.3e1 * t3 * t48 - t87 * t228;
+		t405 = t71 * t22;
+		t409 = t296 * t9;
+		t421 = -0.2e1 * t26 * t5 + t192 * startBlockY * t29 + t134 * t369 + 0.2e1 * t405 + 0.4e1 * t266 + 0.2e1 * t19 + 0.2e1 * t409 - 0.2e1 * t18 * t7 - t16 * t334 + 0.2e1 * t33 * t34 + 0.4e1 * t77 * t35 + 0.4e1 * t1 * t98 + t66 * t369;
+		t442 = 0.2e1 * t16 * t362 - t15 * t35 - 0.2e1 * t15 * t257 - 0.2e1 * t46 * t127 - 0.6e1 * t46 * t90 - t88 * t127 - 0.3e1 * t16 * t196 + t16 * t409 + 0.3e1 * t16 * t339 - 0.2e1 * t7 - 0.2e1 * t102 * t4 - t235 * t269;
+		t460 = -0.2e1 * t16 * t366 + t16 * t341 - 0.4e1 * t77 * t132 + t1 * t184 + 0.2e1 * t16 * t347 + t4 * t113 + t248 * t29 - t71 * t4 - 0.2e1 * t26 + 0.2e1 * t41 * t4 - t16 * t356 + t16 * t405 + t192 * t4;
+		t471 = n * n;
+		t474 = M_PI * M_PI;
+		t479 = pow(t2 + 0.1e1 + t8, 0.2e1);
+		t483 = pow(t2 - 0.1e1 - t8, 0.2e1);
+
+		u3a = -(t2 + t6 - t7 - t9) * deltaRho * t13 * (t65 + t110 + t140 + t172 + t201 + t226 + t252 + t280 + t307 + t331 + t352 + t376 + t399 + t421 + t442 + t460) / t7 / (0.1e1 + t5) / t471 / n / t474 / M_PI / t479 / t483 / t31 / (0.1e1 + t17) / 0.2e1;
+
+		t1 = n * M_PI;
+		t3 = sin(t1 * dx);
+		t5 = y * n;
+		t6 = t5 * M_PI;
+		t7 = tanh(t6);
+		t8 = t7 * t7;
+		t9 = 0.1e1 / cosh(t1);
+		t10 = t8 * t9;
+		t11 = tanh(t1);
+		t12 = t11 * t11;
+		t13 = startBlockY * n;
+		t14 = t13 * M_PI;
+		t15 = 0.1e1 / cosh(t14);
+		t16 = t12 * t15;
+		t17 = t10 * t16;
+		t20 = t9 * t9;
+		t21 = t20 * t20;
+		t22 = t8 * t21;
+		t23 = t15 * t15;
+		t24 = t22 * t23;
+		t26 = tanh(t14);
+		t27 = t22 * t26;
+		t30 = t10 * t15;
+		t33 = 0.1e1 / cosh(t6);
+		t34 = t33 * t33;
+		t35 = t34 * t11;
+		t36 = t35 * t26;
+		t39 = t34 * n;
+		t40 = t39 * M_PI;
+		t41 = t26 * t20;
+		t42 = t41 * t11;
+		t45 = t8 * n;
+		t46 = t45 * M_PI;
+		t47 = t26 * t26;
+		t48 = t47 * t20;
+		t49 = t48 * t11;
+		t52 = t23 * t20;
+		t54 = t34 * t47;
+		t55 = t54 * t20;
+		t57 = t7 * t9;
+		t58 = t15 * t26;
+		t59 = t57 * t58;
+		t64 = M_PI * t7;
+		t65 = t5 * t64;
+		t66 = t9 * t11;
+		t67 = t66 * t58;
+		t70 = t8 * t47;
+		t71 = t20 * t12;
+		t72 = t70 * t71;
+		t74 = 0.6e1 * t6 * t17 + t6 * t24 + 0.2e1 * t6 * t27 + 0.2e1 * t6 * t30 + 0.8e1 * t6 * t36 + 0.8e1 * t40 * t42 + 0.4e1 * t46 * t49 + 0.2e1 * t52 - t6 * t55 + 0.4e1 * t6 * t59 - 0.2e1 * t6 * t49 + 0.12e2 * t65 * t67 - t6 * t72;
+		t75 = t34 * startBlockY;
+		t76 = t75 * n;
+		t77 = t12 * t11;
+		t78 = M_PI * t77;
+		t82 = t9 * t15;
+		t83 = t82 * t26;
+		t86 = t48 * t12;
+		t88 = M_PI * t12;
+		t93 = t7 * startBlockY;
+		t94 = t93 * n;
+		t95 = M_PI * t11;
+		t96 = t95 * t41;
+		t99 = t20 * t9;
+		t100 = t8 * t99;
+		t101 = t100 * t58;
+		t104 = t34 * t26;
+		t105 = t104 * t71;
+		t108 = t7 * t20;
+		t109 = t108 * t11;
+		t112 = t7 * n;
+		t113 = t112 * M_PI;
+		t114 = startBlockY * t20;
+		t115 = t114 * t11;
+		t118 = t1 * t9;
+		t119 = t11 * t15;
+		t120 = t119 * t26;
+		t123 = t99 * t11;
+		t124 = t123 * t58;
+		t127 = t77 * t15;
+		t128 = t10 * t127;
+		t130 = t52 * t12;
+		t133 = -0.8e1 * t76 * t78 * t26 - 0.2e1 * t40 * t83 - t6 * t86 - 0.12e2 * t76 * t88 * t26 + 0.2e1 * t54 - 0.8e1 * t94 * t96 - 0.2e1 * t6 * t101 - 0.2e1 * t6 * t105 - 0.4e1 * t6 * t109 - 0.4e1 * t113 * t115 - 0.6e1 * t118 * t120 - 0.2e1 * t6 * t124 - 0.4e1 * t128 + 0.2e1 * t40 * t130;
+		t138 = t8 * startBlockY;
+		t139 = t138 * n;
+		t140 = M_PI * t21;
+		t141 = t140 * t47;
+		t146 = M_PI * t20;
+		t151 = t57 * t127;
+		t153 = t57 * t119;
+		t157 = t100 * t119;
+		t159 = t34 * t9;
+		t160 = t159 * t119;
+		t164 = 0.6e1 * t76 * t88 * t23 + t139 * t141 + 0.4e1 * t101 - t1 * t114 - t75 * t1 + 0.2e1 * t45 * t146 + 0.2e1 * t1 * t71 - 0.8e1 * t151 - 0.24e2 * t153 + 0.4e1 * t112 * t146 + 0.4e1 * t157 - 0.12e2 * t160 + 0.6e1 * t6 * t67;
+		t165 = t159 * t58;
+		t167 = t159 * t127;
+		t169 = t127 * t26;
+		t173 = t34 * t99;
+		t174 = t173 * t119;
+		t178 = t7 * t99;
+		t179 = t178 * t58;
+		t186 = t173 * t58;
+		t188 = t9 * t77;
+		t189 = t188 * t58;
+		t192 = t99 * t15;
+		t193 = t192 * t26;
+		t196 = t20 * t11;
+		t197 = t104 * t196;
+		t199 = -0.4e1 * t165 - 0.4e1 * t167 - 0.4e1 * t159 * t169 - 0.4e1 * t105 + 0.2e1 * t6 * t174 + 0.2e1 * t20 + 0.8e1 * t179 + 0.4e1 * t174 + 0.2e1 * t6 * t128 - 0.2e1 * t6 * t157 + 0.4e1 * t186 - 0.4e1 * t113 * t189 - 0.4e1 * t113 * t193 - 0.8e1 * t197;
+		t205 = t10 * t119;
+		t208 = t35 * t47;
+		t211 = M_PI * t23;
+		t212 = t211 * t71;
+		t216 = t7 * t23;
+		t217 = t216 * t71;
+		t219 = t8 * t26;
+		t220 = t219 * t71;
+		t222 = t57 * t16;
+		t225 = t10 * t58;
+		t230 = t7 * t26;
+		t231 = t230 * t71;
+		t233 = 0.4e1 * t173 * t120 + t5 * t140 + 0.6e1 * t6 * t205 + 0.4e1 * t6 * t208 + t139 * t212 + 0.2e1 * t94 * t212 + 0.4e1 * t217 + 0.4e1 * t220 - 0.24e2 * t222 + 0.2e1 * t72 - 0.4e1 * t225 - 0.6e1 * t75 * t1 * t12 + 0.8e1 * t231;
+		t234 = t9 * t12;
+		t235 = t234 * t15;
+		t238 = t16 * t26;
+		t241 = t66 * t15;
+		t244 = t52 * t11;
+		t250 = M_PI * t26 * t20;
+		t253 = t211 * t20;
+		t255 = t88 * t41;
+		t258 = M_PI * t34;
+		t259 = t5 * t258;
+		t262 = t88 * t20;
+		t266 = t12 * t12;
+		t267 = t34 * t266;
+		t268 = t267 * t23;
+		t272 = -0.6e1 * t1 * t235 - 0.6e1 * t118 * t238 - 0.6e1 * t1 * t241 + 0.4e1 * t40 * t244 + 0.4e1 * t76 * t96 - 0.2e1 * t139 * t250 + t139 * t253 + 0.2e1 * t76 * t255 + t259 + 0.16e2 * t113 * t42 + t76 * t262 - 0.12e2 * t10 * t238 + t6 * t268 + 0.12e2 * t6 * t153;
+		t276 = t8 * t23;
+		t277 = t276 * t196;
+		t279 = M_PI * t47;
+		t280 = t279 * t20;
+		t294 = t219 * t20;
+		t299 = 0.4e1 * t112 * t253 + 0.4e1 * t277 - t5 * t280 - 0.6e1 * t46 * t235 + 0.2e1 * t1 * t52 - 0.12e2 * t67 - t5 * t146 - t75 * t1 * t47 - 0.2e1 * t1 * t115 + 0.12e2 * t6 * t222 - 0.2e1 * t6 * t294 - 0.4e1 * t82 - t13 * t280;
+		t300 = t234 * t58;
+		t308 = t140 * t26;
+		t313 = M_PI * startBlockY * t20;
+		t321 = t279 * t71;
+		t324 = M_PI * t99 * t15;
+		t329 = 0.6e1 * t6 * t300 - 0.2e1 * t40 * t124 - 0.2e1 * t1 * t192 + t13 * t141 + 0.2e1 * t13 * t308 - 0.12e2 * t300 - t45 * t313 + 0.4e1 * t1 * t41 + 0.2e1 * t1 * t48 + t13 * t140 - t76 * t212 + t76 * t321 - 0.2e1 * t39 * t324 + 0.2e1 * t39 * t280;
+		t336 = t41 * t12;
+		t342 = t70 * t196;
+		t344 = t219 * t196;
+		t346 = t276 * t71;
+		t350 = t188 * t15;
+		t359 = -0.4e1 * t6 * t179 + 0.4e1 * t124 + 0.4e1 * t1 * t336 - 0.4e1 * t189 + 0.2e1 * t76 * t250 + 0.4e1 * t342 + 0.8e1 * t344 + 0.2e1 * t346 - 0.2e1 * t1 * t82 - 0.2e1 * t46 * t350 + 0.2e1 * t39 * t146 - 0.2e1 * t6 * t244 + 0.4e1 * t1 * t196;
+		t365 = t230 * t196;
+		t367 = t159 * t16;
+		t369 = t34 * t23;
+		t370 = t369 * t71;
+		t374 = t369 * t196;
+		t376 = t54 * t71;
+		t378 = t54 * t196;
+		t380 = t178 * t119;
+		t382 = t211 * t196;
+		t385 = t216 * t196;
+		t387 = -0.12e2 * t205 + 0.4e1 * t45 * t250 - t14 * t86 - 0.8e1 * t59 + 0.16e2 * t365 - 0.12e2 * t367 - 0.2e1 * t370 + 0.4e1 * t46 * t244 - 0.4e1 * t374 - 0.2e1 * t376 - 0.4e1 * t378 + 0.8e1 * t380 + 0.2e1 * t139 * t382 + 0.8e1 * t385;
+		t389 = t7 * t47;
+		t390 = t389 * t71;
+		t392 = t34 * t12;
+		t393 = t392 * t47;
+		t396 = t389 * t196;
+		t408 = t178 * t15;
+		t411 = t7 * t21;
+		t412 = t411 * t47;
+		t415 = t34 * t20;
+		t416 = t415 * t12;
+		t422 = 0.4e1 * t390 + 0.6e1 * t6 * t393 + 0.8e1 * t396 + 0.2e1 * t139 * t308 - 0.2e1 * t46 * t83 + 0.4e1 * t94 * t382 + 0.2e1 * t40 * t86 - 0.4e1 * t6 * t344 - 0.4e1 * t6 * t408 + 0.2e1 * t6 * t412 - t6 * t416 - 0.2e1 * t1 * t350 - 0.2e1 * t118 * t169;
+		t423 = t123 * t15;
+		t428 = t279 * t196;
+		t452 = -0.2e1 * t40 * t423 + 0.2e1 * t45 * t253 - 0.2e1 * t139 * t428 - 0.4e1 * t6 * t42 - 0.4e1 * t94 * t428 + 0.4e1 * t108 + 0.2e1 * t46 * t86 - 0.2e1 * t5 * t324 + t5 * t141 + 0.4e1 * t6 * t151 + 0.4e1 * t5 * t258 * t77 - 0.2e1 * t45 * t324 - 0.6e1 * t259 * t67 + 0.2e1 * t45 * t280;
+		t461 = t57 * t15;
+		t473 = t411 * t26;
+		t476 = t140 * t23;
+		t484 = 0.4e1 * t112 * t280 - 0.4e1 * t112 * t324 - 0.2e1 * t112 * t313 + 0.4e1 * t6 * t461 - 0.2e1 * t6 * t378 - 0.6e1 * t40 * t235 - t5 * t258 * t20 + 0.6e1 * t5 * t258 * t12 + 0.4e1 * t6 * t473 - t13 * t476 + 0.2e1 * t94 * t141 + 0.2e1 * t5 * t258 * t26 + 0.2e1 * t369;
+		t485 = t35 * t23;
+		t491 = t8 * t20;
+		t492 = t491 * t12;
+		t500 = M_PI * t9 * t15;
+		t511 = t216 * t20;
+		t517 = 0.4e1 * t6 * t485 + t14 * t130 - 0.6e1 * t40 * t300 - t6 * t492 - 0.2e1 * t5 * t64 * t20 - 0.2e1 * t6 * t374 - 0.2e1 * t39 * t500 - 0.6e1 * t40 * t241 - 0.4e1 * t6 * t231 - 0.4e1 * t6 * t380 - 0.6e1 * t46 * t300 - 0.2e1 * t6 * t511 + 0.8e1 * t46 * t42 + 0.12e2 * t392;
+		t529 = t1 * t21;
+		t536 = M_PI * t8;
+		t537 = t5 * t536;
+		t544 = 0.8e1 * t112 * t250 - 0.24e2 * t57 * t238 + t39 * t313 + 0.2e1 * t48 + 0.4e1 * t46 * t336 + 0.8e1 * t178 * t120 + t138 * t529 - 0.8e1 * t57 * t169 - 0.2e1 * t40 * t350 - t6 * t376 + 0.6e1 * t537 * t67 - 0.4e1 * t6 * t385 - 0.2e1 * t6 * t167;
+		t551 = t70 * t20;
+		t553 = t276 * t20;
+		t556 = t389 * t20;
+		t573 = -0.12e2 * t159 * t238 - 0.4e1 * t10 * t169 + 0.4e1 * t100 * t120 + 0.2e1 * t551 + 0.2e1 * t553 + 0.4e1 * t294 + 0.4e1 * t556 - t5 * t262 - 0.6e1 * t76 * t88 * t47 + 0.4e1 * t113 * t86 + 0.6e1 * t537 * t300 + 0.4e1 * t76 * t95 * t23 + 0.4e1 * t40 * t336 + 0.4e1 * t40 * t49;
+		t580 = t411 * t23;
+		t600 = t146 * t11;
+		t605 = -0.4e1 * t94 * t250 + 0.2e1 * t6 * t580 - 0.12e2 * t10 * t120 + 0.4e1 * t94 * t308 - 0.4e1 * t113 * t83 + 0.4e1 * t5 * t258 * t11 - 0.2e1 * t1 * t193 + 0.2e1 * t71 - t6 * t370 - t75 * t1 * t266 + t75 * t1 * t23 + 0.4e1 * t45 * t600 + 0.2e1 * t537 * t189;
+		t611 = t369 * t20;
+		t626 = -0.2e1 * t1 * t99 * t120 - 0.2e1 * t6 * t423 - t6 * t611 + t13 * t253 - 0.8e1 * t461 - 0.2e1 * t55 - 0.2e1 * t611 - 0.2e1 * t416 - 0.2e1 * t46 * t189 + 0.2e1 * t267 - 0.12e2 * t17 - 0.2e1 * t14 * t336 - t6 * t346 - t6 * t130;
+		t638 = t34 * t77;
+		t639 = t638 * t26;
+		t646 = t230 * t20;
+		t651 = -0.4e1 * t113 * t423 - 0.4e1 * t139 * t96 - 0.2e1 * t139 * t255 - 0.24e2 * t57 * t120 + 0.2e1 * t1 * t130 + 0.8e1 * t6 * t639 + 0.2e1 * t45 * t262 + 0.4e1 * t511 - 0.8e1 * t473 + 0.8e1 * t646 - 0.12e2 * t241 + 0.4e1 * t193 + 0.4e1 * t423;
+		t652 = t267 * t47;
+		t654 = t638 * t47;
+		t657 = t415 * t11;
+		t659 = t491 * t11;
+		t662 = t392 * t26;
+		t664 = t173 * t15;
+		t673 = 0.2e1 * t652 + 0.8e1 * t654 + 0.8e1 * t109 - 0.4e1 * t657 + 0.4e1 * t659 + 0.16e2 * t36 + 0.24e2 * t662 + 0.4e1 * t664 + 0.8e1 * t485 + 0.8e1 * t208 + 0.2e1 * t1 * t20 + 0.2e1 * t86 + 0.4e1 * t49 - 0.2e1 * t415;
+		t699 = t392 * t23;
+		t702 = 0.12e2 * t6 * t662 - 0.2e1 * t5 * t250 - 0.2e1 * t6 * t217 - 0.4e1 * t14 * t42 - 0.12e2 * t113 * t235 - 0.12e2 * t113 * t300 - 0.12e2 * t159 * t120 - t139 * t476 - 0.2e1 * t6 * t659 - 0.2e1 * t6 * t336 - 0.2e1 * t76 * t382 + 0.2e1 * t76 * t428 + 0.6e1 * t6 * t699;
+		t727 = t104 * t20;
+		t730 = -t139 * t262 + 0.2e1 * t6 * t225 - 0.4e1 * t6 * t646 + 0.2e1 * t39 * t262 + 0.4e1 * t39 * t600 + 0.2e1 * t6 * t83 - 0.2e1 * t94 * t321 - 0.4e1 * t75 * t1 * t11 + 0.2e1 * t492 + 0.8e1 * t35 + 0.4e1 * t1 * t49 + 0.2e1 * t5 * t500 + 0.2e1 * t5 * t308 - 0.2e1 * t6 * t727;
+		t734 = t22 * t47;
+		t755 = 0.8e1 * t113 * t244 + t6 * t734 + 0.2e1 * t491 - 0.2e1 * t46 * t124 - 0.2e1 * t1 * t83 - 0.2e1 * t22 + 0.4e1 * t6 * t654 + 0.2e1 * t1 * t86 - 0.2e1 * t537 * t124 + 0.4e1 * t196 - t5 * t536 * t20 - 0.12e2 * t113 * t241 + 0.6e1 * t6 * t241;
+		t756 = t108 * t12;
+		t783 = -0.2e1 * t6 * t756 - 0.4e1 * t113 * t124 - 0.2e1 * t21 - 0.6e1 * t259 * t300 - 0.12e2 * t113 * t67 - 0.2e1 * t40 * t189 - t139 * t280 + 0.4e1 * t41 - 0.2e1 * t21 * t47 - 0.4e1 * t76 * t95 * t47 - t139 * t321 - 0.2e1 * t6 * t193 - 0.4e1 * t75 * t1 * t77 - 0.2e1 * t6 * t220;
+		t795 = M_PI * t266;
+		t806 = t638 * t23;
+		t809 = t267 * t26;
+		t811 = -0.2e1 * t40 * t193 + 0.8e1 * t638 - 0.2e1 * t6 * t165 + 0.2e1 * t34 - 0.2e1 * t259 * t189 - t76 * t795 * t47 - 0.4e1 * t21 * t26 - 0.4e1 * t113 * t350 + 0.2e1 * t94 * t253 + 0.2e1 * t39 * t253 + 0.8e1 * t806 + 0.12e2 * t699 + 0.4e1 * t809;
+		t816 = t100 * t15;
+		t823 = t159 * t15;
+		t828 = -0.4e1 * t727 + 0.4e1 * t756 + 0.4e1 * t336 + 0.8e1 * t42 + 0.4e1 * t816 + 0.16e2 * t639 - 0.4e1 * t412 - 0.4e1 * t580 - 0.2e1 * t24 + 0.8e1 * t408 - 0.4e1 * t823 - 0.12e2 * t235 - 0.4e1 * t350 - 0.4e1 * t30;
+		t849 = 0.2e1 * t268 + 0.12e2 * t393 - 0.2e1 * t734 - 0.4e1 * t83 - 0.4e1 * t27 + 0.4e1 * t244 + 0.2e1 * t130 - 0.4e1 * t112 * t500 + 0.4e1 * t65 * t189 - 0.4e1 * t65 * t124 - 0.2e1 * t94 * t476 - 0.6e1 * t6 * t367 + 0.8e1 * t1 * t42;
+		t877 = 0.4e1 * t39 * t250 + 0.2e1 * t6 * t189 + 0.2e1 * t259 * t124 - 0.2e1 * t6 * t556 + t76 * t795 * t23 - 0.2e1 * t76 * t795 * t26 - 0.2e1 * t21 * t23 - t6 * t551 - t6 * t553 + 0.2e1 * t5 * t64 * t21 - 0.4e1 * t6 * t197 + 0.4e1 * t113 * t130 + 0.4e1 * t192 + 0.2e1 * t40 * t115;
+		t904 = t5 * t476 - t13 * t262 - 0.4e1 * t6 * t396 + 0.4e1 * t76 * t78 * t23 + 0.4e1 * t104 - 0.2e1 * t14 * t49 - 0.8e1 * t6 * t365 + 0.2e1 * t14 * t244 - 0.2e1 * t6 * t390 - 0.6e1 * t46 * t241 - 0.2e1 * t6 * t342 + 0.2e1 * t93 * t529 - 0.4e1 * t94 * t255;
+		t933 = 0.2e1 * t6 * t350 + 0.2e1 * t6 * t809 + 0.6e1 * t6 * t235 - 0.2e1 * t6 * t277 - 0.2e1 * t45 * t500 - 0.2e1 * t94 * t280 + 0.8e1 * t112 * t600 + 0.4e1 * t1 * t244 - 0.2e1 * t46 * t115 - t5 * t253 - 0.2e1 * t6 * t657 - 0.6e1 * t6 * t160 - 0.2e1 * t75 * t1 * t26 + 0.12e2 * t65 * t300;
+		t962 = -0.2e1 * t94 * t262 + 0.2e1 * t6 * t664 + t5 * t536 * t21 - 0.2e1 * t1 * t423 + 0.4e1 * t6 * t806 + 0.2e1 * t6 * t186 - 0.2e1 * t6 * t816 - 0.6e1 * t46 * t67 - 0.2e1 * t13 * t250 + 0.8e1 * t113 * t336 + 0.4e1 * t112 * t262 - 0.6e1 * t40 * t67 - 0.8e1 * t76 * t95 * t26;
+		t988 = t5 * t258 * t266 + t5 * t258 * t47 - 0.4e1 * t411 + t5 * t258 * t23 + t6 * t652 - 0.4e1 * t76 * t78 * t47 - 0.2e1 * t46 * t423 - 0.2e1 * t46 * t193 - t76 * t253 + t76 * t280 + 0.8e1 * t113 * t49 - 0.2e1 * t5 * t600 - 0.2e1 * t6 * t823 + 0.2e1 * t46 * t130;
+		t1001 = pow(t9 + 0.1e1 + t11, 0.2e1);
+		t1004 = pow(t9 - 0.1e1 - t11, 0.2e1);
+		t1011 = n * n;
+		t1015 = M_PI * M_PI;
+
+		u3b = -deltaRho * t3 * (t74 + t933 + t544 + t299 + t164 + t849 + t904 + t702 + t651 + t452 + t828 + t199 + t387 + t359 + t962 + t133 + t877 + t811 + t484 + t422 + t605 + t783 + t730 + t626 + t272 + t673 + t573 + t233 + t329 + t755 + t988 + t517) / t15 / (0.1e1 + t26) / t1001 / t1004 / t33 / (0.1e1 + t7) / t1011 / n / t1015 / M_PI / 0.2e1;
+
+		if ( y > startBlockY ) {
+			u2=u2b;u3=u3b;
+		}
+		else {
+			u2=u2a;u3=u3a;
+		}
+
+		u5 = (double)-2*n*M_PI*(viscosity*u2 + u3)*cos(n*M_PI*x);
+
+		*pressure +=u5;
+
+	}
+	
+	if ( y > startBlockY ) {
+	    *pressure += deltaRho*dx*(0.5-y);
+	 } else {
+	    *pressure += deltaRho*dx*(0.5-startBlockY);
+	}
+
+}
+
+void _AnalyticBlock_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	AnalyticBlock*           self           = (AnalyticBlock*)analyticSolution;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
+	self->pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  ); 
+
+	self->startBlockX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startBlockX", 0.0  );
+	self->endBlockX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"endBlockX", 0.0  );
+	self->startBlockY = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startBlockY", 0.0  );
+}
+
+void _AnalyticBlock_Build( void* analyticSolution, void* data ) {
+	AnalyticBlock*	self = (AnalyticBlock*)analyticSolution;
+
+	assert( self && Stg_CheckType( self, AnalyticBlock ) );
+
+	Build( self->velocityField, data, False );
+	Build( self->pressureField, data, False );
+	AnalyticSolution_CreateAnalyticField( self, self->velocityField, _AnalyticBlock_VelocityFunction );
+	AnalyticSolution_CreateAnalyticField( self, self->pressureField, _AnalyticBlock_PressureFunction );
+
+	_AnalyticSolution_Build( self, data );
+}
+
+void* _AnalyticBlock_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(AnalyticBlock);
+	Type                                                      type = AnalyticBlock_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _AnalyticBlock_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _AnalyticBlock_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticBlock_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _AnalyticSolution_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _AnalyticSolution_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _AnalyticSolution_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 _AnalyticSolution_New(  ANALYTICSOLUTION_PASSARGS  );
+}
+
+Index _PICellerator_AnalyticBlock_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, AnalyticBlock_Type, (Name)"0", _AnalyticBlock_DefaultNew  );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Apps/RayleighTaylor/tests/AnalyticColumn/AnalyticColumn.c
--- a/Apps/RayleighTaylor/tests/AnalyticColumn/AnalyticColumn.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,353 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: AnalyticColumn.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#define MAX_FOURIER_TERMS 220
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include <assert.h>
-
-const Type AnalyticColumn_Type = "AnalyticColumn";
-
-typedef struct {
-	__AnalyticSolution
-	FeVariable*		velocityField;
-	FeVariable*		pressureField;
-	Dimension_Index         dim;
-	double                  sigma;
-	double                  viscosity;
-	double                  startColumnX;
-	double                  endColumnX;
-	double                  startColumnZ;
-	double                  endColumnZ;
-} AnalyticColumn;
-
-void AnalyticColumn_Constants( void* analyticSolution, double n, double* C1, double* C2, double* C3, double *C4 ) {
-	AnalyticColumn*          self           = (AnalyticColumn*)analyticSolution;
-	double                  viscosity      = self->viscosity;
-	double                  deltaRho       = self->sigma;
-	double                  x0             = 0.5 * ( self->startColumnX + self->endColumnX );
-	double                  dx             = self->endColumnX - self->startColumnX;
-	double                  factor = M_PI * n;
-
-	*C1 = 0.2e1 * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) * exp(-factor) * (0.2e1 * exp(-factor) + 0.2e1 + factor) * pow(exp(-factor) + 0.1e1, -0.2e1) / viscosity * pow(M_PI, -0.3e1) * pow(n, -0.3e1); 
-		
-	*C2 = -0.2e1 * (-0.2e1 * exp(-factor) + factor * exp(-factor) - 0.2e1) * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) * pow(exp(-factor) + 0.1e1, -0.2e1) / viscosity * pow(M_PI, -0.3e1) * pow(n, -0.3e1); 
-		
-	*C3 = -0.2e1 * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) * exp(-factor) / viscosity * pow(n, -0.2e1) * pow(M_PI, -0.2e1) / (exp(-factor) + 0.1e1); 
-		
-	*C4 = 0.2e1 * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) / viscosity * pow(n, -0.2e1) * pow(M_PI, -0.2e1) / (exp(-factor) + 0.1e1);
-}
-
-
-void _AnalyticColumn_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
-	AnalyticColumn*         self           = (AnalyticColumn*)analyticSolution;
-	double                  n, m;
-	double                  x, y, z;
-	double                  C1, C2, C3, C4;
-	double                  viscosity      = self->viscosity;
-	double                  sigma          = self->sigma;
-	double                  deltaRho;
-	double                  x0;
-	double                  z0;
-	double                  dx;
-	double                  dz;
-	double                  u1, u2, u3;
-	double                  factor;
-	
-	/* Find coordinate of node */
-	x = coord[ I_AXIS ];
-	y = coord[ J_AXIS ];
-	z = coord[ K_AXIS ];
-
-	x0 = 0.5 * ( self->startColumnX + self->endColumnX );
-	dx = self->endColumnX - self->startColumnX;
-	z0 = 0.5 * ( self->startColumnZ + self->endColumnZ );
-	dz = self->endColumnZ - self->startColumnZ;
-
-	/* Initialise */
-	if ( self->dim == 2 ) {
-		velocity[ I_AXIS ] = 0.0;
-		velocity[ J_AXIS ] = 0.0;
-
-		for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
-			factor = M_PI * n;
-
-			AnalyticColumn_Constants( self, n, &C1, &C2, &C3, &C4 );
-
-			u1 = (-0.2e1 * sigma * sin(factor * x0 + factor * dx / 0.2e1) + 0.2e1 * sigma * sin(factor * x0 - factor * dx / 0.2e1) + C1 * exp(factor * y) * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity + C2 * exp(-factor * y) * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity + C3 * exp(factor * y) * y * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity + C4 * exp(-factor * y) * y * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity) * pow(n, -0.3e1) * pow(M_PI, -0.3e1) / viscosity;
-
-			u2 = (-C1 * factor * exp(factor * y) + C2 * factor * exp(-factor * y) - C3 * factor * exp(factor * y) * y - C3 * exp(factor * y) + C4 * factor * exp(-factor * y) * y - C4 * exp(-factor * y)) / n / M_PI;
-			
-			u2 *= sin( factor * x );
-			velocity[ I_AXIS ] += u2;
-			u1 *= cos( factor * x );
-			velocity[ J_AXIS ] += u1;
-		}
-	}
-	else {
-		double L1,kn,km; 
-		double Am,Ap,Bm,Bp,C,D,E;
-
-		velocity[ I_AXIS ] = 0.0;
-		velocity[ J_AXIS ] = 0.0;
-		velocity[ K_AXIS ] = 0.0;
-
-		for ( n = 0 ; n < 45 ; n++ ) {
-			for ( m = 0 ; m < 45 ; m++ ) {
-
-				if ( n != 0 && m!=0 ){
-					deltaRho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dz)/(double)n/M_PI/(double)m/M_PI; 
-				} 
-				else if ( n == 0 && m != 0 ) { 
-					deltaRho = 2.0*sigma*dx*sin((double)m*M_PI*dz)/(double)m/M_PI; 
-				}
-				else if  ( n != 0 && m == 0 ) { 
-					deltaRho = 2.0*sigma*dz*sin((double)n*M_PI*dx)/(double)n/M_PI; 
-				} 
-				else { 
-					deltaRho = sigma*dx*dz; 
-				} 
-				kn = M_PI * (double)n; 
-				km = M_PI * (double)m;
-				
-				L1 = M_PI * sqrt( (double)(n*n + m*m)); 
-				
-				Am = exp((y-2.0)*L1)-exp(-y*L1);
-				Ap = exp((y-2.0)*L1)+exp(-y*L1); 
-				Bm = exp((y-1.0)*L1)-exp(-(y+1.0)*L1); 
-				Bp = exp((y-1.0)*L1)+exp(-(y+1.0)*L1);
-
-				C = (exp(-y*L1)-1.0)*(exp((y-1.0)*L1)-1.0); 
-				D = exp((y-1.0)*L1)-exp(-y*L1); 
-				E = (1.0+exp(-L1)); 
-				
-				u1 = (n!=0 || m!=0) 
-					?  -( y*Am+(y-1.0)*Bm )*deltaRho/( 2*viscosity*L1*E*E ) - C*deltaRho/(viscosity*L1*L1*E) 
-					:  0.0; 
-				if ( m != 0 ){ 
-					u2 = ( y*Ap+(y-1.0)*Bp )*deltaRho*km/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*km/(2*viscosity*L1*L1*L1*E);
-				} 
-				else { 
-					u2 = 0.0; 
-				} 
-				
-				if ( n != 0 ){ 
-					u3 = ( y*Ap+(y-1.0)*Bp )*deltaRho*kn/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*kn/(2*viscosity*L1*L1*L1*E);
-				} 
-				else { 
-					u3 = 0.0; 
-				} 
-
-				u1 *= cos(n*M_PI*x)*cos(m*M_PI*z); 
-				velocity[ J_AXIS ] += u1;
-				u2 *= cos(n*M_PI*x)*sin(m*M_PI*z);
-				velocity[ K_AXIS ] += u2;
-				u3 *= sin(n*M_PI*x)*cos(m*M_PI*z);
-				velocity[ I_AXIS ] += u3;
-			}
-		}
-	}
-}
-
-void _AnalyticColumn_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
-	AnalyticColumn*          self           = (AnalyticColumn*)analyticSolution;
-	double                  viscosity      = self->viscosity;
-	double                  sigma          = self->sigma;
-	double                  n, m;
-	double                  x, y, z;
-	double                  C1, C2, C3, C4;
-	double                  deltaRho;
-	double                  x0, z0;
-	double                  dx, dz;
-	double                  u2, u3, u4;
-	double                  pp;
-	double                  factor;
-	
-	/* Find coordinate of node */
-	x = coord[ I_AXIS ];
-	y = coord[ J_AXIS ];
-	z = coord[ K_AXIS ];
-
-	x0 = 0.5 * ( self->startColumnX + self->endColumnX );
-	dx = self->endColumnX - self->startColumnX;
-	z0 = 0.5 * ( self->startColumnZ + self->endColumnZ );
-	dz = self->endColumnZ - self->startColumnZ;
-
-	/* Initialise */
-	*pressure = 0.0;
-
-	if ( self->dim == 2 ) {
-		for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
-			factor = M_PI * n;
-
-			AnalyticColumn_Constants( self, n, &C1, &C2, &C3, &C4 );
-
-			u2 = (-C1 * factor * exp(factor * y) + C2 * factor * exp(-factor * y) - C3 * factor * exp(factor * y) * y - C3 * exp(factor * y) + C4 * factor * exp(-factor * y) * y - C4 * exp(-factor * y)) / n / M_PI;
-			
-			u3 = -viscosity * (-C1 * exp(factor * y) + C2 * exp(-factor * y) - C3 * exp(factor * y) * y + C4 * exp(-factor * y) * y);
-			*pressure += (double)( -2.0* viscosity * factor * u2 - u3*2.0*factor )*cos( factor * x );
-		}
-	}
-	else {
-		double L1,kn,km; 
-		double Am,Ap,Bm,Bp,C,D,E;
-
-		for ( n = 0 ; n < 45 ; n++ ) {
-			for ( m = 0 ; m < 45 ; m++ ) {
-
-				if ( n!=0 && m!=0 ){
-					deltaRho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dz)/(double)n/M_PI/(double)m/M_PI; 
-				} 
-				else if ( n==0 && m !=0) { 
-					deltaRho = 2.0*sigma*dx*sin((double)m*M_PI*dz)/(double)m/M_PI; 
-				}
-				else if  ( n!=0 && m ==0) { 
-					deltaRho = 2.0*sigma*dz*sin((double)n*M_PI*dx)/(double)n/M_PI; 
-				} 
-				else { 
-					deltaRho = sigma*dx*dz; 
-				} 
-				kn = M_PI * (double)n; 
-				km = M_PI * (double)m;
-				
-				L1 = M_PI * sqrt( (double)(n*n + m*m)); 
-				
-				Am = exp((y-2.0)*L1)-exp(-y*L1);
-				Ap = exp((y-2.0)*L1)+exp(-y*L1); 
-				Bm = exp((y-1.0)*L1)-exp(-(y+1.0)*L1); 
-				Bp = exp((y-1.0)*L1)+exp(-(y+1.0)*L1);
-
-				C = (exp(-y*L1)-1.0)*(exp((y-1.0)*L1)-1.0); 
-				D = exp((y-1.0)*L1)-exp(-y*L1); 
-				E = (1.0+exp(-L1)); 
-				
-				if ( m != 0 ){ 
-					u2 = ( y*Ap+(y-1.0)*Bp )*deltaRho*km/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*km/(2*viscosity*L1*L1*L1*E);
-				} 
-				else { 
-					u2 = 0.0; 
-				} 
-				
-				if ( n != 0 ){ 
-					u3 = ( y*Ap+(y-1.0)*Bp )*deltaRho*kn/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*kn/(2*viscosity*L1*L1*L1*E);
-				} 
-				else { 
-					u3 = 0.0; 
-				} 
-				
-				u4 = (n == 0 && m == 0 ) 
-					?  deltaRho*(y-0.5) 
-					:  -( y*Ap+(y-1.0)*Bp )*deltaRho/( E*E ) + 2.0*D*deltaRho/(L1*E) ; 
-				
-				pp = -u4-2.0*viscosity*(kn*u3+km*u2); 
-				pp *= cos(n*M_PI*x)*cos(m*M_PI*z); 
-				*pressure += pp; /* total pressure */
-			}
-		}
-	}
-}
-
-	
-void _AnalyticColumn_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
-	AnalyticColumn*          self           = (AnalyticColumn*)analyticSolution;
-
-	/* Construct Parent */
-	_AnalyticSolution_AssignFromXML( self, cf, data );
-
-	/* Create Analytic Fields */
-	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
-	self->pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  ); 
-
-	self->dim          = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-	self->startColumnX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startColumnX", 0.0  );
-	self->endColumnX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"endColumnX", 0.0  );
-	self->startColumnZ = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startColumnZ", 0.0  );
-	self->endColumnZ   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"endColumnZ", 0.0  );
-	self->viscosity    = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"viscosity", 1.0  );
-	self->sigma        = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"sigma", 1.0  );
-}
-
-void _AnalyticColumn_Build( void* analyticSolution, void* data ) {
-	AnalyticColumn*	self = (AnalyticColumn*)analyticSolution;
-
-	assert( self && Stg_CheckType( self, AnalyticColumn ) );
-
-	Build( self->velocityField, data, False );
-	Build( self->pressureField, data, False );
-	AnalyticSolution_CreateAnalyticField( self, self->velocityField, _AnalyticColumn_VelocityFunction );
-	AnalyticSolution_CreateAnalyticField( self, self->pressureField, _AnalyticColumn_PressureFunction );
-
-	_AnalyticSolution_Build( self, data );
-}
-
-void* _AnalyticColumn_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(AnalyticColumn);
-	Type                                                      type = AnalyticColumn_Type;
-	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
-	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
-	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _AnalyticColumn_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _AnalyticColumn_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticColumn_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _AnalyticSolution_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _AnalyticSolution_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _AnalyticSolution_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 _AnalyticSolution_New(  ANALYTICSOLUTION_PASSARGS  );
-}
-
-Index _PICellerator_AnalyticColumn_Register( PluginsManager* pluginsManager ) {
-	return PluginsManager_Submit( pluginsManager, AnalyticColumn_Type, (Name)"0", _AnalyticColumn_DefaultNew  );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Apps/RayleighTaylor/tests/AnalyticColumn/AnalyticColumn.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Apps/RayleighTaylor/tests/AnalyticColumn/AnalyticColumn.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,353 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: AnalyticColumn.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#define MAX_FOURIER_TERMS 220
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include <assert.h>
+
+const Type AnalyticColumn_Type = "AnalyticColumn";
+
+typedef struct {
+	__AnalyticSolution
+	FeVariable*		velocityField;
+	FeVariable*		pressureField;
+	Dimension_Index         dim;
+	double                  sigma;
+	double                  viscosity;
+	double                  startColumnX;
+	double                  endColumnX;
+	double                  startColumnZ;
+	double                  endColumnZ;
+} AnalyticColumn;
+
+void AnalyticColumn_Constants( void* analyticSolution, double n, double* C1, double* C2, double* C3, double *C4 ) {
+	AnalyticColumn*          self           = (AnalyticColumn*)analyticSolution;
+	double                  viscosity      = self->viscosity;
+	double                  deltaRho       = self->sigma;
+	double                  x0             = 0.5 * ( self->startColumnX + self->endColumnX );
+	double                  dx             = self->endColumnX - self->startColumnX;
+	double                  factor = M_PI * n;
+
+	*C1 = 0.2e1 * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) * exp(-factor) * (0.2e1 * exp(-factor) + 0.2e1 + factor) * pow(exp(-factor) + 0.1e1, -0.2e1) / viscosity * pow(M_PI, -0.3e1) * pow(n, -0.3e1); 
+		
+	*C2 = -0.2e1 * (-0.2e1 * exp(-factor) + factor * exp(-factor) - 0.2e1) * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) * pow(exp(-factor) + 0.1e1, -0.2e1) / viscosity * pow(M_PI, -0.3e1) * pow(n, -0.3e1); 
+		
+	*C3 = -0.2e1 * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) * exp(-factor) / viscosity * pow(n, -0.2e1) * pow(M_PI, -0.2e1) / (exp(-factor) + 0.1e1); 
+		
+	*C4 = 0.2e1 * deltaRho * sin(factor * dx / 0.2e1) * cos(factor * x0) / viscosity * pow(n, -0.2e1) * pow(M_PI, -0.2e1) / (exp(-factor) + 0.1e1);
+}
+
+
+void _AnalyticColumn_VelocityFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* velocity ) {
+	AnalyticColumn*         self           = (AnalyticColumn*)analyticSolution;
+	double                  n, m;
+	double                  x, y, z;
+	double                  C1, C2, C3, C4;
+	double                  viscosity      = self->viscosity;
+	double                  sigma          = self->sigma;
+	double                  deltaRho;
+	double                  x0;
+	double                  z0;
+	double                  dx;
+	double                  dz;
+	double                  u1, u2, u3;
+	double                  factor;
+	
+	/* Find coordinate of node */
+	x = coord[ I_AXIS ];
+	y = coord[ J_AXIS ];
+	z = coord[ K_AXIS ];
+
+	x0 = 0.5 * ( self->startColumnX + self->endColumnX );
+	dx = self->endColumnX - self->startColumnX;
+	z0 = 0.5 * ( self->startColumnZ + self->endColumnZ );
+	dz = self->endColumnZ - self->startColumnZ;
+
+	/* Initialise */
+	if ( self->dim == 2 ) {
+		velocity[ I_AXIS ] = 0.0;
+		velocity[ J_AXIS ] = 0.0;
+
+		for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
+			factor = M_PI * n;
+
+			AnalyticColumn_Constants( self, n, &C1, &C2, &C3, &C4 );
+
+			u1 = (-0.2e1 * sigma * sin(factor * x0 + factor * dx / 0.2e1) + 0.2e1 * sigma * sin(factor * x0 - factor * dx / 0.2e1) + C1 * exp(factor * y) * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity + C2 * exp(-factor * y) * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity + C3 * exp(factor * y) * y * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity + C4 * exp(-factor * y) * y * pow(n, 0.3e1) * pow(M_PI, 0.3e1) * viscosity) * pow(n, -0.3e1) * pow(M_PI, -0.3e1) / viscosity;
+
+			u2 = (-C1 * factor * exp(factor * y) + C2 * factor * exp(-factor * y) - C3 * factor * exp(factor * y) * y - C3 * exp(factor * y) + C4 * factor * exp(-factor * y) * y - C4 * exp(-factor * y)) / n / M_PI;
+			
+			u2 *= sin( factor * x );
+			velocity[ I_AXIS ] += u2;
+			u1 *= cos( factor * x );
+			velocity[ J_AXIS ] += u1;
+		}
+	}
+	else {
+		double L1,kn,km; 
+		double Am,Ap,Bm,Bp,C,D,E;
+
+		velocity[ I_AXIS ] = 0.0;
+		velocity[ J_AXIS ] = 0.0;
+		velocity[ K_AXIS ] = 0.0;
+
+		for ( n = 0 ; n < 45 ; n++ ) {
+			for ( m = 0 ; m < 45 ; m++ ) {
+
+				if ( n != 0 && m!=0 ){
+					deltaRho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dz)/(double)n/M_PI/(double)m/M_PI; 
+				} 
+				else if ( n == 0 && m != 0 ) { 
+					deltaRho = 2.0*sigma*dx*sin((double)m*M_PI*dz)/(double)m/M_PI; 
+				}
+				else if  ( n != 0 && m == 0 ) { 
+					deltaRho = 2.0*sigma*dz*sin((double)n*M_PI*dx)/(double)n/M_PI; 
+				} 
+				else { 
+					deltaRho = sigma*dx*dz; 
+				} 
+				kn = M_PI * (double)n; 
+				km = M_PI * (double)m;
+				
+				L1 = M_PI * sqrt( (double)(n*n + m*m)); 
+				
+				Am = exp((y-2.0)*L1)-exp(-y*L1);
+				Ap = exp((y-2.0)*L1)+exp(-y*L1); 
+				Bm = exp((y-1.0)*L1)-exp(-(y+1.0)*L1); 
+				Bp = exp((y-1.0)*L1)+exp(-(y+1.0)*L1);
+
+				C = (exp(-y*L1)-1.0)*(exp((y-1.0)*L1)-1.0); 
+				D = exp((y-1.0)*L1)-exp(-y*L1); 
+				E = (1.0+exp(-L1)); 
+				
+				u1 = (n!=0 || m!=0) 
+					?  -( y*Am+(y-1.0)*Bm )*deltaRho/( 2*viscosity*L1*E*E ) - C*deltaRho/(viscosity*L1*L1*E) 
+					:  0.0; 
+				if ( m != 0 ){ 
+					u2 = ( y*Ap+(y-1.0)*Bp )*deltaRho*km/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*km/(2*viscosity*L1*L1*L1*E);
+				} 
+				else { 
+					u2 = 0.0; 
+				} 
+				
+				if ( n != 0 ){ 
+					u3 = ( y*Ap+(y-1.0)*Bp )*deltaRho*kn/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*kn/(2*viscosity*L1*L1*L1*E);
+				} 
+				else { 
+					u3 = 0.0; 
+				} 
+
+				u1 *= cos(n*M_PI*x)*cos(m*M_PI*z); 
+				velocity[ J_AXIS ] += u1;
+				u2 *= cos(n*M_PI*x)*sin(m*M_PI*z);
+				velocity[ K_AXIS ] += u2;
+				u3 *= sin(n*M_PI*x)*cos(m*M_PI*z);
+				velocity[ I_AXIS ] += u3;
+			}
+		}
+	}
+}
+
+void _AnalyticColumn_PressureFunction( void* analyticSolution, FeVariable* analyticFeVariable, double* coord, double* pressure ) {
+	AnalyticColumn*          self           = (AnalyticColumn*)analyticSolution;
+	double                  viscosity      = self->viscosity;
+	double                  sigma          = self->sigma;
+	double                  n, m;
+	double                  x, y, z;
+	double                  C1, C2, C3, C4;
+	double                  deltaRho;
+	double                  x0, z0;
+	double                  dx, dz;
+	double                  u2, u3, u4;
+	double                  pp;
+	double                  factor;
+	
+	/* Find coordinate of node */
+	x = coord[ I_AXIS ];
+	y = coord[ J_AXIS ];
+	z = coord[ K_AXIS ];
+
+	x0 = 0.5 * ( self->startColumnX + self->endColumnX );
+	dx = self->endColumnX - self->startColumnX;
+	z0 = 0.5 * ( self->startColumnZ + self->endColumnZ );
+	dz = self->endColumnZ - self->startColumnZ;
+
+	/* Initialise */
+	*pressure = 0.0;
+
+	if ( self->dim == 2 ) {
+		for( n = 1.0 ; n < MAX_FOURIER_TERMS ; n++ ) {
+			factor = M_PI * n;
+
+			AnalyticColumn_Constants( self, n, &C1, &C2, &C3, &C4 );
+
+			u2 = (-C1 * factor * exp(factor * y) + C2 * factor * exp(-factor * y) - C3 * factor * exp(factor * y) * y - C3 * exp(factor * y) + C4 * factor * exp(-factor * y) * y - C4 * exp(-factor * y)) / n / M_PI;
+			
+			u3 = -viscosity * (-C1 * exp(factor * y) + C2 * exp(-factor * y) - C3 * exp(factor * y) * y + C4 * exp(-factor * y) * y);
+			*pressure += (double)( -2.0* viscosity * factor * u2 - u3*2.0*factor )*cos( factor * x );
+		}
+	}
+	else {
+		double L1,kn,km; 
+		double Am,Ap,Bm,Bp,C,D,E;
+
+		for ( n = 0 ; n < 45 ; n++ ) {
+			for ( m = 0 ; m < 45 ; m++ ) {
+
+				if ( n!=0 && m!=0 ){
+					deltaRho = 4.0*sigma*sin((double)n*M_PI*dx)*sin((double)m*M_PI*dz)/(double)n/M_PI/(double)m/M_PI; 
+				} 
+				else if ( n==0 && m !=0) { 
+					deltaRho = 2.0*sigma*dx*sin((double)m*M_PI*dz)/(double)m/M_PI; 
+				}
+				else if  ( n!=0 && m ==0) { 
+					deltaRho = 2.0*sigma*dz*sin((double)n*M_PI*dx)/(double)n/M_PI; 
+				} 
+				else { 
+					deltaRho = sigma*dx*dz; 
+				} 
+				kn = M_PI * (double)n; 
+				km = M_PI * (double)m;
+				
+				L1 = M_PI * sqrt( (double)(n*n + m*m)); 
+				
+				Am = exp((y-2.0)*L1)-exp(-y*L1);
+				Ap = exp((y-2.0)*L1)+exp(-y*L1); 
+				Bm = exp((y-1.0)*L1)-exp(-(y+1.0)*L1); 
+				Bp = exp((y-1.0)*L1)+exp(-(y+1.0)*L1);
+
+				C = (exp(-y*L1)-1.0)*(exp((y-1.0)*L1)-1.0); 
+				D = exp((y-1.0)*L1)-exp(-y*L1); 
+				E = (1.0+exp(-L1)); 
+				
+				if ( m != 0 ){ 
+					u2 = ( y*Ap+(y-1.0)*Bp )*deltaRho*km/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*km/(2*viscosity*L1*L1*L1*E);
+				} 
+				else { 
+					u2 = 0.0; 
+				} 
+				
+				if ( n != 0 ){ 
+					u3 = ( y*Ap+(y-1.0)*Bp )*deltaRho*kn/( 2*viscosity*L1*L1*E*E ) - D*deltaRho*kn/(2*viscosity*L1*L1*L1*E);
+				} 
+				else { 
+					u3 = 0.0; 
+				} 
+				
+				u4 = (n == 0 && m == 0 ) 
+					?  deltaRho*(y-0.5) 
+					:  -( y*Ap+(y-1.0)*Bp )*deltaRho/( E*E ) + 2.0*D*deltaRho/(L1*E) ; 
+				
+				pp = -u4-2.0*viscosity*(kn*u3+km*u2); 
+				pp *= cos(n*M_PI*x)*cos(m*M_PI*z); 
+				*pressure += pp; /* total pressure */
+			}
+		}
+	}
+}
+
+	
+void _AnalyticColumn_AssignFromXML( void* analyticSolution, Stg_ComponentFactory* cf, void* data ) {
+	AnalyticColumn*          self           = (AnalyticColumn*)analyticSolution;
+
+	/* Construct Parent */
+	_AnalyticSolution_AssignFromXML( self, cf, data );
+
+	/* Create Analytic Fields */
+	self->velocityField = Stg_ComponentFactory_ConstructByName( cf, (Name)"VelocityField", FeVariable, True, data  ); 
+	self->pressureField = Stg_ComponentFactory_ConstructByName( cf, (Name)"PressureField", FeVariable, True, data  ); 
+
+	self->dim          = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+	self->startColumnX = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startColumnX", 0.0  );
+	self->endColumnX   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"endColumnX", 0.0  );
+	self->startColumnZ = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"startColumnZ", 0.0  );
+	self->endColumnZ   = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"endColumnZ", 0.0  );
+	self->viscosity    = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"viscosity", 1.0  );
+	self->sigma        = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"sigma", 1.0  );
+}
+
+void _AnalyticColumn_Build( void* analyticSolution, void* data ) {
+	AnalyticColumn*	self = (AnalyticColumn*)analyticSolution;
+
+	assert( self && Stg_CheckType( self, AnalyticColumn ) );
+
+	Build( self->velocityField, data, False );
+	Build( self->pressureField, data, False );
+	AnalyticSolution_CreateAnalyticField( self, self->velocityField, _AnalyticColumn_VelocityFunction );
+	AnalyticSolution_CreateAnalyticField( self, self->pressureField, _AnalyticColumn_PressureFunction );
+
+	_AnalyticSolution_Build( self, data );
+}
+
+void* _AnalyticColumn_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(AnalyticColumn);
+	Type                                                      type = AnalyticColumn_Type;
+	Stg_Class_DeleteFunction*                              _delete = _AnalyticSolution_Delete;
+	Stg_Class_PrintFunction*                                _print = _AnalyticSolution_Print;
+	Stg_Class_CopyFunction*                                  _copy = _AnalyticSolution_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _AnalyticColumn_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _AnalyticColumn_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticColumn_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _AnalyticSolution_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _AnalyticSolution_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _AnalyticSolution_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 _AnalyticSolution_New(  ANALYTICSOLUTION_PASSARGS  );
+}
+
+Index _PICellerator_AnalyticColumn_Register( PluginsManager* pluginsManager ) {
+	return PluginsManager_Submit( pluginsManager, AnalyticColumn_Type, (Name)"0", _AnalyticColumn_DefaultNew  );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/BackgroundParticleLayout.c
--- a/MaterialPoints/src/BackgroundParticleLayout.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,185 +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 file may be distributed under the terms of the VPAC Public License
-** as defined by VPAC of Australia and appearing in the file
-** LICENSE.VPL included in the packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** $Id: BackgroundParticleLayout.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
-**
-*/
-/** \file
- **  Role:
- **	A particle layout which creates only 1 particle, for use in creating backgroud layers where materials are "everywhere"
- **
- ** Assumptions:
- **
- ** Comments:
- **
- **~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "BackgroundParticleLayout.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type BackgroundParticleLayout_Type = "BackgroundParticleLayout";
-
-BackgroundParticleLayout* BackgroundParticleLayout_New( Name name,
-   AbstractContext* context, 
-   CoordSystem      coordSystem, 
-   Bool             weightsInitialisedAtStartup ) {
-
-  BackgroundParticleLayout* self = (BackgroundParticleLayout*)_BackgroundParticleLayout_DefaultNew( name );
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _BackgroundParticleLayout_Init( self );
-   self->isConstructed = True;
-   return self;
-}
-
-BackgroundParticleLayout* _BackgroundParticleLayout_New(  BACKGROUNDPARTICLELAYOUT_DEFARGS  ) {
-    BackgroundParticleLayout* self;
-	
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(BackgroundParticleLayout) );
-    self = (BackgroundParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
-	
-    return self;
-}
-
-
-void _BackgroundParticleLayout_Init( void* particleLayout ) {
-	BackgroundParticleLayout* self;
-
-	self = (BackgroundParticleLayout*)particleLayout;
-}
-
-void _BackgroundParticleLayout_Delete( void* particleLayout ) {
-    BackgroundParticleLayout* self = (BackgroundParticleLayout*)particleLayout;
-	
-    _ParticleLayout_Delete( self );
-}
-
-void _BackgroundParticleLayout_Print( void* particleLayout, Stream* stream ) {
-    BackgroundParticleLayout* self = (BackgroundParticleLayout*)particleLayout;
-	
-    Journal_Printf( stream, "BackgroundParticleLayout (ptr): %p\n", self );
-	
-    /* Parent class info */
-    _ParticleLayout_Print( self, stream );
-	
-}
-
-void* _BackgroundParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    BackgroundParticleLayout*		self = (BackgroundParticleLayout*)particleLayout;
-    BackgroundParticleLayout*		newBackgroundParticleLayout;
-	
-    newBackgroundParticleLayout = (BackgroundParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-
-    return (void*)newBackgroundParticleLayout;
-}
-
-void* _BackgroundParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                        _sizeOfSelf = sizeof(BackgroundParticleLayout);
-	Type                                                                type = BackgroundParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                        _delete = _BackgroundParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                          _print = _BackgroundParticleLayout_Print;
-	Stg_Class_CopyFunction*                                            _copy = _BackgroundParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = _BackgroundParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                              _construct = _BackgroundParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                      _build = _BackgroundParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                            _initialise = _BackgroundParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                  _execute = _BackgroundParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                  _destroy = _BackgroundParticleLayout_Destroy;
-	AllocationType                                        nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*               _setInitialCounts = _BackgroundParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*         _initialiseParticles = _BackgroundParticleLayout_InitialiseParticles;
-	CoordSystem                                                  coordSystem = GlobalCoordSystem;
-	Bool                                         weightsInitialisedAtStartup = False;
-
-    return _BackgroundParticleLayout_New(  BACKGROUNDPARTICLELAYOUT_PASSARGS  );
-}
-void  _BackgroundParticleLayout_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )  {
-   BackgroundParticleLayout*	self = (BackgroundParticleLayout*)component;
-
-   _ParticleLayout_AssignFromXML( self, cf, data );
-
-   _BackgroundParticleLayout_Init( self );
-}
-
-void  _BackgroundParticleLayout_Build( void* component, void* data ) {}
-void  _BackgroundParticleLayout_Initialise( void* component, void* data ) {}
-void  _BackgroundParticleLayout_Execute( void* component, void* data ) {}
-void  _BackgroundParticleLayout_Destroy( void* component, void* data ) {
-   BackgroundParticleLayout*	self = (BackgroundParticleLayout*)component;
-   _ParticleLayout_Destroy( self, data );
-}
-
-
-void _BackgroundParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
-{
-    Swarm*			  swarm         = (Swarm*)_swarm;
-    Cell_DomainIndex	  cell_I        = 0;
-    char			  tempStr[100];
-
-    swarm->particleLocalCount = 1;
-
-    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; 
-        swarm->cellParticleSizeTbl[cell_I] = 1; /* Just to create array */
-
-        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;
-    }
-}
-
-void _BackgroundParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
-{
-    Swarm*                    swarm         = (Swarm*)_swarm;
-    GlobalParticle*           particle;
-
-    particle = (GlobalParticle*)Swarm_ParticleAt( swarm, 0 );
-
-    particle->owningCell = 0;
-    particle->coord[0] = 0.5; /* just some value, doesn't matter where */
-    particle->coord[1] = 0.5;
-    particle->coord[2] = 0.5;
-
-    Swarm_AddParticleToCell( swarm, 0, 0 );
-}
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/BackgroundParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/BackgroundParticleLayout.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,185 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This file may be distributed under the terms of the VPAC Public License
+** as defined by VPAC of Australia and appearing in the file
+** LICENSE.VPL included in the packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** $Id: BackgroundParticleLayout.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
+**
+*/
+/** \file
+ **  Role:
+ **	A particle layout which creates only 1 particle, for use in creating backgroud layers where materials are "everywhere"
+ **
+ ** Assumptions:
+ **
+ ** Comments:
+ **
+ **~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "BackgroundParticleLayout.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type BackgroundParticleLayout_Type = "BackgroundParticleLayout";
+
+BackgroundParticleLayout* BackgroundParticleLayout_New( Name name,
+   AbstractContext* context, 
+   CoordSystem      coordSystem, 
+   Bool             weightsInitialisedAtStartup ) {
+
+  BackgroundParticleLayout* self = (BackgroundParticleLayout*)_BackgroundParticleLayout_DefaultNew( name );
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _BackgroundParticleLayout_Init( self );
+   self->isConstructed = True;
+   return self;
+}
+
+BackgroundParticleLayout* _BackgroundParticleLayout_New(  BACKGROUNDPARTICLELAYOUT_DEFARGS  ) {
+    BackgroundParticleLayout* self;
+	
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(BackgroundParticleLayout) );
+    self = (BackgroundParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
+	
+    return self;
+}
+
+
+void _BackgroundParticleLayout_Init( void* particleLayout ) {
+	BackgroundParticleLayout* self;
+
+	self = (BackgroundParticleLayout*)particleLayout;
+}
+
+void _BackgroundParticleLayout_Delete( void* particleLayout ) {
+    BackgroundParticleLayout* self = (BackgroundParticleLayout*)particleLayout;
+	
+    _ParticleLayout_Delete( self );
+}
+
+void _BackgroundParticleLayout_Print( void* particleLayout, Stream* stream ) {
+    BackgroundParticleLayout* self = (BackgroundParticleLayout*)particleLayout;
+	
+    Journal_Printf( stream, "BackgroundParticleLayout (ptr): %p\n", self );
+	
+    /* Parent class info */
+    _ParticleLayout_Print( self, stream );
+	
+}
+
+void* _BackgroundParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    BackgroundParticleLayout*		self = (BackgroundParticleLayout*)particleLayout;
+    BackgroundParticleLayout*		newBackgroundParticleLayout;
+	
+    newBackgroundParticleLayout = (BackgroundParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+
+    return (void*)newBackgroundParticleLayout;
+}
+
+void* _BackgroundParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                        _sizeOfSelf = sizeof(BackgroundParticleLayout);
+	Type                                                                type = BackgroundParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                        _delete = _BackgroundParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                          _print = _BackgroundParticleLayout_Print;
+	Stg_Class_CopyFunction*                                            _copy = _BackgroundParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = _BackgroundParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                              _construct = _BackgroundParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                      _build = _BackgroundParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                            _initialise = _BackgroundParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                  _execute = _BackgroundParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                  _destroy = _BackgroundParticleLayout_Destroy;
+	AllocationType                                        nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*               _setInitialCounts = _BackgroundParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*         _initialiseParticles = _BackgroundParticleLayout_InitialiseParticles;
+	CoordSystem                                                  coordSystem = GlobalCoordSystem;
+	Bool                                         weightsInitialisedAtStartup = False;
+
+    return _BackgroundParticleLayout_New(  BACKGROUNDPARTICLELAYOUT_PASSARGS  );
+}
+void  _BackgroundParticleLayout_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data )  {
+   BackgroundParticleLayout*	self = (BackgroundParticleLayout*)component;
+
+   _ParticleLayout_AssignFromXML( self, cf, data );
+
+   _BackgroundParticleLayout_Init( self );
+}
+
+void  _BackgroundParticleLayout_Build( void* component, void* data ) {}
+void  _BackgroundParticleLayout_Initialise( void* component, void* data ) {}
+void  _BackgroundParticleLayout_Execute( void* component, void* data ) {}
+void  _BackgroundParticleLayout_Destroy( void* component, void* data ) {
+   BackgroundParticleLayout*	self = (BackgroundParticleLayout*)component;
+   _ParticleLayout_Destroy( self, data );
+}
+
+
+void _BackgroundParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
+{
+    Swarm*			  swarm         = (Swarm*)_swarm;
+    Cell_DomainIndex	  cell_I        = 0;
+    char			  tempStr[100];
+
+    swarm->particleLocalCount = 1;
+
+    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; 
+        swarm->cellParticleSizeTbl[cell_I] = 1; /* Just to create array */
+
+        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;
+    }
+}
+
+void _BackgroundParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
+{
+    Swarm*                    swarm         = (Swarm*)_swarm;
+    GlobalParticle*           particle;
+
+    particle = (GlobalParticle*)Swarm_ParticleAt( swarm, 0 );
+
+    particle->owningCell = 0;
+    particle->coord[0] = 0.5; /* just some value, doesn't matter where */
+    particle->coord[1] = 0.5;
+    particle->coord[2] = 0.5;
+
+    Swarm_AddParticleToCell( swarm, 0, 0 );
+}
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/CoincidentMapper.c
--- a/MaterialPoints/src/CoincidentMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,262 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "IntegrationPointMapper.h"
-#include "OneToOneMapper.h"
-#include "CoincidentMapper.h"
-
-#include "MaterialPointsSwarm.h"
-#include "MaterialPoint.h"
-#include "IntegrationPointsSwarm.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type CoincidentMapper_Type = "CoincidentMapper";
-
-CoincidentMapper* CoincidentMapper_New(
-	Name							name,
-	PICelleratorContext*		context,
-	IntegrationPointsSwarm*	integrationSwarm,
-	MaterialPointsSwarm*		materialSwarm )
-{
-  CoincidentMapper* self = (CoincidentMapper*)_CoincidentMapper_DefaultNew( name );
-
-	self->isConstructed = True;
-	_IntegrationPointMapper_Init( self, context, integrationSwarm );
-	_OneToOneMapper_Init( self, materialSwarm );
-	_CoincidentMapper_Init( self );
-
-	return self;
-}
-
-void* _CoincidentMapper_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                 _sizeOfSelf = sizeof(CoincidentMapper);
-	Type                                                                         type = CoincidentMapper_Type;
-	Stg_Class_DeleteFunction*                                                 _delete = _CoincidentMapper_Delete;
-	Stg_Class_PrintFunction*                                                   _print = _CoincidentMapper_Print;
-	Stg_Class_CopyFunction*                                                     _copy = _CoincidentMapper_Copy;
-	Stg_Component_DefaultConstructorFunction*                     _defaultConstructor = _CoincidentMapper_DefaultNew;
-	Stg_Component_ConstructFunction*                                       _construct = _CoincidentMapper_AssignFromXML;
-	Stg_Component_BuildFunction*                                               _build = _CoincidentMapper_Build;
-	Stg_Component_InitialiseFunction*                                     _initialise = _CoincidentMapper_Initialise;
-	Stg_Component_ExecuteFunction*                                           _execute = _CoincidentMapper_Execute;
-	Stg_Component_DestroyFunction*                                           _destroy = _CoincidentMapper_Destroy;
-	AllocationType                                                 nameAllocationType = NON_GLOBAL;
-	IntegrationPointMapper_MapFunction*                                          _map = _CoincidentMapper_Map;
-	IntegrationPointMapper_GetMaterialPointsSwarmsFunction*  _getMaterialPointsSwarms = _OneToOneMapper_GetMaterialPointsSwarms;
-	IntegrationPointMapper_GetMaterialIndexOnFunction*            _getMaterialIndexOn = _OneToOneMapper_GetMaterialIndexOn;
-	IntegrationPointMapper_GetExtensionOnFunction*                    _getExtensionOn = _OneToOneMapper_GetExtensionOn;
-    IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromExtension = _OneToOneMapper_GetDoubleFromExtension;
-	IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromMaterial = _OneToOneMapper_GetDoubleFromMaterial;
-
-	return _CoincidentMapper_New(  COINCIDENTMAPPER_PASSARGS  );
-}
-
-CoincidentMapper* _CoincidentMapper_New(  COINCIDENTMAPPER_DEFARGS  ) {
-	CoincidentMapper* result;
-
-	result = (CoincidentMapper*)_OneToOneMapper_New(  ONETOONEMAPPER_PASSARGS  );
-
-	return result;
-}
-
-void _CoincidentMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	_OneToOneMapper_AssignFromXML( mapper, cf, data );
-}
-
-void _CoincidentMapper_Init( void* mapper ) {
-}
-
-void _CoincidentMapper_Delete( void* mapper ) {
-	CoincidentMapper* self = (CoincidentMapper*)mapper;
-
-	_OneToOneMapper_Delete( self );
-}
-
-void _CoincidentMapper_Print( void* mapper, Stream* stream ) {
-	_IntegrationPointMapper_Print( mapper, stream );
-}
-
-void* _CoincidentMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	return _IntegrationPointMapper_Copy( mapper, dest, deep, nameExt, ptrMap );
-}
-
-void _CoincidentMapper_Build( void* mapper, void* cf ) {
-	CoincidentMapper* self = (CoincidentMapper*)mapper;
-
-	_OneToOneMapper_Build( self, cf );
-}
-
-void _CoincidentMapper_Initialise( void* mapper, void* cf ) {
-	CoincidentMapper* self = (CoincidentMapper*)mapper;
-
-	_OneToOneMapper_Initialise( self, cf );
-}
-
-void _CoincidentMapper_Execute( void* mapper, void* data ) {
-}
-
-void _CoincidentMapper_Destroy( void* mapper, void* data ) {
-	CoincidentMapper* self = (CoincidentMapper*)mapper;
-
-	_OneToOneMapper_Destroy( self, data );
-}
-
-void _CoincidentMapper_Map( void* mapper ) {
-	CoincidentMapper*			self = (CoincidentMapper*)mapper;
-	IntegrationPointsSwarm*	integrationSwarm = self->integrationSwarm;
-	MaterialPointsSwarm*		materialSwarm = self->materialSwarm;
-	IntegrationPoint*			integrationPoint;
-	MaterialPoint*				materialPoint;
-	MaterialPointRef*			ref;
-	FeMesh*						mesh = materialSwarm->mesh;
-	Particle_Index				particle_lI;
-	Cell_Index					cell_dI;
-
-#ifdef CAUTIOUS
-	Index							dim_I;
-	Stream*						errorStream = Journal_Register( Error_Type, self->type  );
-#endif
-	Stream*						debugStream = Swarm_Debug;
-	
-	Journal_DPrintfL( debugStream, 1, "In %s(): Re-creating a new set of integration points, exactly\n" 
-		"\tmapping to the current material points & their positions.\n", __func__ );
-
-	Stream_IndentBranch( debugStream );
-
-	Journal_DPrintfL( debugStream, 2, "Reallocating the integration points array from size of %u points "
-		"to the \n\tcurrent material swarm particle count of %u\n", integrationSwarm->particleLocalCount,
-		materialSwarm->particleLocalCount );
-
-	integrationSwarm->particleLocalCount = materialSwarm->particleLocalCount;
-	Swarm_Realloc( integrationSwarm );
-
-	Journal_DPrintfL( debugStream, 2, "Clearing all the cell->particle ownership tables, "
-		"ready to add new cell->particle\n\trelationships as new integration points are set up.\n" );
-
-	for( cell_dI = 0; cell_dI < integrationSwarm->cellDomainCount; cell_dI++ ) {
-		integrationSwarm->cellParticleCountTbl[cell_dI] = 0;
-		integrationSwarm->cellParticleSizeTbl[cell_dI] = 0;
-
-		if ( integrationSwarm->cellParticleTbl[cell_dI] ) {
-			Memory_Free( integrationSwarm->cellParticleTbl[cell_dI] );
-		}
-		integrationSwarm->cellParticleTbl[cell_dI] = NULL;
-	}
-
-	Journal_DPrintfL( debugStream, 2, "For each material particle, setting up a corresponding integration "
-                      "point, and\n\tcalculating its element-local coord based on the material's global coord:\n" );
-	Stream_IndentBranch( debugStream );	
-
-	/* Map each point */
-	for ( particle_lI = 0; particle_lI < materialSwarm->particleLocalCount; particle_lI++ ) {
-		integrationPoint = (IntegrationPoint*)Swarm_ParticleAt( integrationSwarm, particle_lI );
-		materialPoint = (MaterialPoint*)Swarm_ParticleAt( materialSwarm, particle_lI );
-
-		cell_dI = materialPoint->owningCell;
-
-		Journal_DPrintfL( debugStream, 3, "Referring to local material point %u, from material swarm cell %u:\n", particle_lI, cell_dI );
-		Stream_IndentBranch( debugStream );	
-
-		Journal_DPrintfL( debugStream, 3, "Adding new integration point %u to integration swarm cell %u\n", particle_lI, cell_dI );
-
-		Swarm_AddParticleToCell( integrationSwarm, cell_dI, particle_lI );
-
-		/* Convert global to local coordinates */
-		ElementType_ConvertGlobalCoordToElLocal(
-			FeMesh_GetElementType( mesh, cell_dI ),
-			mesh, 
-			cell_dI, 
-			materialPoint->coord,
-			integrationPoint->xi );
-
-		Journal_DPrintfL( debugStream, 3, "Based on material point's coord of (%.2f,%.2f,%.2f):\n"
-			"calculated and set new integration point's local coord as (%.2f,%.2f,%.2f)\n",
-			materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2],
-			integrationPoint->xi[0], integrationPoint->xi[1], integrationPoint->xi[2] );
-
-#ifdef CAUTIOUS
-		/* Check the result is between -1 to 1 in all dimensions : if not, something is stuffed */		
-		for ( dim_I= 0; dim_I < materialSwarm->dim; dim_I++ ) {
-			Journal_Firewall(
-				(integrationPoint->xi[dim_I] >= -1.001) && (integrationPoint->xi[dim_I] <= 1.001 ),
-				errorStream,
-				"Error - in %s(): unable to map material point %d in cell %d of swarm \"%s\" (type %s) "
-				"coord to a valid \"local\" coordinate (xi). Coord was (%.3f,%.3f,%.3f), swarm's "
-				"particle layout type was %s, Xi result was (%.4f,%.4f,%.4f).\n",
-				__func__, particle_lI, cell_dI, materialSwarm->name, materialSwarm->type,
-				materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2],
-				materialSwarm->particleLayout->type, integrationPoint->xi[0],
-				integrationPoint->xi[1], integrationPoint->xi[2] );
-		}
-#endif
-
-		ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
-		ref->swarm_I = materialSwarm->swarmReg_I;
-		ref->particle_I = particle_lI;
-		Journal_DPrintfL( debugStream, 3, "updated the coincident mapper's material reference for "
-			"this integration point to map back to the material point.\n" );
-		Stream_UnIndentBranch( debugStream );	
-	}
-
-	Stream_UnIndentBranch( debugStream );	
-	Journal_DPrintfL( debugStream, 2, "...finished updating local positions.\n" );
-
-	Stream_UnIndentBranch( debugStream );
-	Journal_DPrintfL( debugStream, 1, "...%s(): Done.\n", __func__ );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/CoincidentMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/CoincidentMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,262 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "IntegrationPointMapper.h"
+#include "OneToOneMapper.h"
+#include "CoincidentMapper.h"
+
+#include "MaterialPointsSwarm.h"
+#include "MaterialPoint.h"
+#include "IntegrationPointsSwarm.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type CoincidentMapper_Type = "CoincidentMapper";
+
+CoincidentMapper* CoincidentMapper_New(
+	Name							name,
+	PICelleratorContext*		context,
+	IntegrationPointsSwarm*	integrationSwarm,
+	MaterialPointsSwarm*		materialSwarm )
+{
+  CoincidentMapper* self = (CoincidentMapper*)_CoincidentMapper_DefaultNew( name );
+
+	self->isConstructed = True;
+	_IntegrationPointMapper_Init( self, context, integrationSwarm );
+	_OneToOneMapper_Init( self, materialSwarm );
+	_CoincidentMapper_Init( self );
+
+	return self;
+}
+
+void* _CoincidentMapper_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                 _sizeOfSelf = sizeof(CoincidentMapper);
+	Type                                                                         type = CoincidentMapper_Type;
+	Stg_Class_DeleteFunction*                                                 _delete = _CoincidentMapper_Delete;
+	Stg_Class_PrintFunction*                                                   _print = _CoincidentMapper_Print;
+	Stg_Class_CopyFunction*                                                     _copy = _CoincidentMapper_Copy;
+	Stg_Component_DefaultConstructorFunction*                     _defaultConstructor = _CoincidentMapper_DefaultNew;
+	Stg_Component_ConstructFunction*                                       _construct = _CoincidentMapper_AssignFromXML;
+	Stg_Component_BuildFunction*                                               _build = _CoincidentMapper_Build;
+	Stg_Component_InitialiseFunction*                                     _initialise = _CoincidentMapper_Initialise;
+	Stg_Component_ExecuteFunction*                                           _execute = _CoincidentMapper_Execute;
+	Stg_Component_DestroyFunction*                                           _destroy = _CoincidentMapper_Destroy;
+	AllocationType                                                 nameAllocationType = NON_GLOBAL;
+	IntegrationPointMapper_MapFunction*                                          _map = _CoincidentMapper_Map;
+	IntegrationPointMapper_GetMaterialPointsSwarmsFunction*  _getMaterialPointsSwarms = _OneToOneMapper_GetMaterialPointsSwarms;
+	IntegrationPointMapper_GetMaterialIndexOnFunction*            _getMaterialIndexOn = _OneToOneMapper_GetMaterialIndexOn;
+	IntegrationPointMapper_GetExtensionOnFunction*                    _getExtensionOn = _OneToOneMapper_GetExtensionOn;
+    IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromExtension = _OneToOneMapper_GetDoubleFromExtension;
+	IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromMaterial = _OneToOneMapper_GetDoubleFromMaterial;
+
+	return _CoincidentMapper_New(  COINCIDENTMAPPER_PASSARGS  );
+}
+
+CoincidentMapper* _CoincidentMapper_New(  COINCIDENTMAPPER_DEFARGS  ) {
+	CoincidentMapper* result;
+
+	result = (CoincidentMapper*)_OneToOneMapper_New(  ONETOONEMAPPER_PASSARGS  );
+
+	return result;
+}
+
+void _CoincidentMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	_OneToOneMapper_AssignFromXML( mapper, cf, data );
+}
+
+void _CoincidentMapper_Init( void* mapper ) {
+}
+
+void _CoincidentMapper_Delete( void* mapper ) {
+	CoincidentMapper* self = (CoincidentMapper*)mapper;
+
+	_OneToOneMapper_Delete( self );
+}
+
+void _CoincidentMapper_Print( void* mapper, Stream* stream ) {
+	_IntegrationPointMapper_Print( mapper, stream );
+}
+
+void* _CoincidentMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	return _IntegrationPointMapper_Copy( mapper, dest, deep, nameExt, ptrMap );
+}
+
+void _CoincidentMapper_Build( void* mapper, void* cf ) {
+	CoincidentMapper* self = (CoincidentMapper*)mapper;
+
+	_OneToOneMapper_Build( self, cf );
+}
+
+void _CoincidentMapper_Initialise( void* mapper, void* cf ) {
+	CoincidentMapper* self = (CoincidentMapper*)mapper;
+
+	_OneToOneMapper_Initialise( self, cf );
+}
+
+void _CoincidentMapper_Execute( void* mapper, void* data ) {
+}
+
+void _CoincidentMapper_Destroy( void* mapper, void* data ) {
+	CoincidentMapper* self = (CoincidentMapper*)mapper;
+
+	_OneToOneMapper_Destroy( self, data );
+}
+
+void _CoincidentMapper_Map( void* mapper ) {
+	CoincidentMapper*			self = (CoincidentMapper*)mapper;
+	IntegrationPointsSwarm*	integrationSwarm = self->integrationSwarm;
+	MaterialPointsSwarm*		materialSwarm = self->materialSwarm;
+	IntegrationPoint*			integrationPoint;
+	MaterialPoint*				materialPoint;
+	MaterialPointRef*			ref;
+	FeMesh*						mesh = materialSwarm->mesh;
+	Particle_Index				particle_lI;
+	Cell_Index					cell_dI;
+
+#ifdef CAUTIOUS
+	Index							dim_I;
+	Stream*						errorStream = Journal_Register( Error_Type, self->type  );
+#endif
+	Stream*						debugStream = Swarm_Debug;
+	
+	Journal_DPrintfL( debugStream, 1, "In %s(): Re-creating a new set of integration points, exactly\n" 
+		"\tmapping to the current material points & their positions.\n", __func__ );
+
+	Stream_IndentBranch( debugStream );
+
+	Journal_DPrintfL( debugStream, 2, "Reallocating the integration points array from size of %u points "
+		"to the \n\tcurrent material swarm particle count of %u\n", integrationSwarm->particleLocalCount,
+		materialSwarm->particleLocalCount );
+
+	integrationSwarm->particleLocalCount = materialSwarm->particleLocalCount;
+	Swarm_Realloc( integrationSwarm );
+
+	Journal_DPrintfL( debugStream, 2, "Clearing all the cell->particle ownership tables, "
+		"ready to add new cell->particle\n\trelationships as new integration points are set up.\n" );
+
+	for( cell_dI = 0; cell_dI < integrationSwarm->cellDomainCount; cell_dI++ ) {
+		integrationSwarm->cellParticleCountTbl[cell_dI] = 0;
+		integrationSwarm->cellParticleSizeTbl[cell_dI] = 0;
+
+		if ( integrationSwarm->cellParticleTbl[cell_dI] ) {
+			Memory_Free( integrationSwarm->cellParticleTbl[cell_dI] );
+		}
+		integrationSwarm->cellParticleTbl[cell_dI] = NULL;
+	}
+
+	Journal_DPrintfL( debugStream, 2, "For each material particle, setting up a corresponding integration "
+                      "point, and\n\tcalculating its element-local coord based on the material's global coord:\n" );
+	Stream_IndentBranch( debugStream );	
+
+	/* Map each point */
+	for ( particle_lI = 0; particle_lI < materialSwarm->particleLocalCount; particle_lI++ ) {
+		integrationPoint = (IntegrationPoint*)Swarm_ParticleAt( integrationSwarm, particle_lI );
+		materialPoint = (MaterialPoint*)Swarm_ParticleAt( materialSwarm, particle_lI );
+
+		cell_dI = materialPoint->owningCell;
+
+		Journal_DPrintfL( debugStream, 3, "Referring to local material point %u, from material swarm cell %u:\n", particle_lI, cell_dI );
+		Stream_IndentBranch( debugStream );	
+
+		Journal_DPrintfL( debugStream, 3, "Adding new integration point %u to integration swarm cell %u\n", particle_lI, cell_dI );
+
+		Swarm_AddParticleToCell( integrationSwarm, cell_dI, particle_lI );
+
+		/* Convert global to local coordinates */
+		ElementType_ConvertGlobalCoordToElLocal(
+			FeMesh_GetElementType( mesh, cell_dI ),
+			mesh, 
+			cell_dI, 
+			materialPoint->coord,
+			integrationPoint->xi );
+
+		Journal_DPrintfL( debugStream, 3, "Based on material point's coord of (%.2f,%.2f,%.2f):\n"
+			"calculated and set new integration point's local coord as (%.2f,%.2f,%.2f)\n",
+			materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2],
+			integrationPoint->xi[0], integrationPoint->xi[1], integrationPoint->xi[2] );
+
+#ifdef CAUTIOUS
+		/* Check the result is between -1 to 1 in all dimensions : if not, something is stuffed */		
+		for ( dim_I= 0; dim_I < materialSwarm->dim; dim_I++ ) {
+			Journal_Firewall(
+				(integrationPoint->xi[dim_I] >= -1.001) && (integrationPoint->xi[dim_I] <= 1.001 ),
+				errorStream,
+				"Error - in %s(): unable to map material point %d in cell %d of swarm \"%s\" (type %s) "
+				"coord to a valid \"local\" coordinate (xi). Coord was (%.3f,%.3f,%.3f), swarm's "
+				"particle layout type was %s, Xi result was (%.4f,%.4f,%.4f).\n",
+				__func__, particle_lI, cell_dI, materialSwarm->name, materialSwarm->type,
+				materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2],
+				materialSwarm->particleLayout->type, integrationPoint->xi[0],
+				integrationPoint->xi[1], integrationPoint->xi[2] );
+		}
+#endif
+
+		ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
+		ref->swarm_I = materialSwarm->swarmReg_I;
+		ref->particle_I = particle_lI;
+		Journal_DPrintfL( debugStream, 3, "updated the coincident mapper's material reference for "
+			"this integration point to map back to the material point.\n" );
+		Stream_UnIndentBranch( debugStream );	
+	}
+
+	Stream_UnIndentBranch( debugStream );	
+	Journal_DPrintfL( debugStream, 2, "...finished updating local positions.\n" );
+
+	Stream_UnIndentBranch( debugStream );
+	Journal_DPrintfL( debugStream, 1, "...%s(): Done.\n", __func__ );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Finalise.c
--- a/MaterialPoints/src/Finalise.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-
-
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool PICellerator_MaterialPoints_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/Finalise.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,61 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+
+
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool PICellerator_MaterialPoints_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/GaussCoincidentMapper.c
--- a/MaterialPoints/src/GaussCoincidentMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,252 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "IntegrationPointMapper.h"
-#include "OneToOneMapper.h"
-#include "GaussCoincidentMapper.h"
-
-#include "MaterialPointsSwarm.h"
-#include "MaterialPoint.h"
-#include "IntegrationPointsSwarm.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type GaussCoincidentMapper_Type = "GaussCoincidentMapper";
-
-GaussCoincidentMapper* GaussCoincidentMapper_New(
-	Name								name,
-	PICelleratorContext*			context,
-	IntegrationPointsSwarm*		integrationSwarm,
-	MaterialPointsSwarm*			materialSwarm )
-{
-  GaussCoincidentMapper* self = (GaussCoincidentMapper*)_GaussCoincidentMapper_DefaultNew( name );
-
-	self->isConstructed = True;
-	_IntegrationPointMapper_Init( self, context, integrationSwarm );
-   _OneToOneMapper_Init( self, materialSwarm );
-	_GaussCoincidentMapper_Init( self );
-
-	return self;
-}
-
-void* _GaussCoincidentMapper_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                 _sizeOfSelf = sizeof(GaussCoincidentMapper);
-	Type                                                                         type = GaussCoincidentMapper_Type;
-	Stg_Class_DeleteFunction*                                                 _delete = _GaussCoincidentMapper_Delete;
-	Stg_Class_PrintFunction*                                                   _print = _GaussCoincidentMapper_Print;
-	Stg_Class_CopyFunction*                                                     _copy = _GaussCoincidentMapper_Copy;
-	Stg_Component_DefaultConstructorFunction*                     _defaultConstructor = _GaussCoincidentMapper_DefaultNew;
-	Stg_Component_ConstructFunction*                                       _construct = _GaussCoincidentMapper_AssignFromXML;
-	Stg_Component_BuildFunction*                                               _build = _GaussCoincidentMapper_Build;
-	Stg_Component_InitialiseFunction*                                     _initialise = _GaussCoincidentMapper_Initialise;
-	Stg_Component_ExecuteFunction*                                           _execute = _GaussCoincidentMapper_Execute;
-	Stg_Component_DestroyFunction*                                           _destroy = _GaussCoincidentMapper_Destroy;
-	AllocationType                                                 nameAllocationType = NON_GLOBAL;
-	IntegrationPointMapper_MapFunction*                                          _map = _GaussCoincidentMapper_Map;
-	IntegrationPointMapper_GetMaterialPointsSwarmsFunction*  _getMaterialPointsSwarms = _OneToOneMapper_GetMaterialPointsSwarms;
-	IntegrationPointMapper_GetMaterialIndexOnFunction*            _getMaterialIndexOn = _OneToOneMapper_GetMaterialIndexOn;
-	IntegrationPointMapper_GetExtensionOnFunction*                    _getExtensionOn = _OneToOneMapper_GetExtensionOn;
-        IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromExtension = _OneToOneMapper_GetDoubleFromExtension;
-    IntegrationPointMapper_GetDoubleFromMaterial*                  _getDoubleFromMaterial = _OneToOneMapper_GetDoubleFromMaterial;
-
-	return _GaussCoincidentMapper_New(  GAUSSCOINCIDENTMAPPER_PASSARGS  );
-}
-
-GaussCoincidentMapper* _GaussCoincidentMapper_New(  GAUSSCOINCIDENTMAPPER_DEFARGS  ) {
-	GaussCoincidentMapper* result;
-
-	result = (GaussCoincidentMapper*)_OneToOneMapper_New(  ONETOONEMAPPER_PASSARGS  );
-
-	return result;
-}
-
-void _GaussCoincidentMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
-
-	_OneToOneMapper_AssignFromXML( self, cf, data );
-}
-
-void _GaussCoincidentMapper_Init( void* mapper ) {
-}
-
-void _GaussCoincidentMapper_Delete( void* mapper ) {
-	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
-
-	_OneToOneMapper_Delete( self );
-}
-
-void _GaussCoincidentMapper_Print( void* mapper, Stream* stream ) {
-	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
-
-	_IntegrationPointMapper_Print( self, stream );
-}
-
-void* _GaussCoincidentMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	return _IntegrationPointMapper_Copy( mapper, dest, deep, nameExt, ptrMap );
-}
-
-void _GaussCoincidentMapper_Build( void* mapper, void* cf ) {
-	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
-
-	_OneToOneMapper_Build( self, cf );
-}
-
-void _GaussCoincidentMapper_Initialise( void* mapper, void* cf ) {
-	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
-
-	_OneToOneMapper_Initialise( self, cf );
-}
-
-void _GaussCoincidentMapper_Execute( void* mapper, void* data ) {
-}
-
-void _GaussCoincidentMapper_Destroy( void* mapper, void* data ) {
-	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
-
-	_OneToOneMapper_Destroy( self, data );
-}
-
-void _GaussCoincidentMapper_Map( void* mapper ) {
-	GaussCoincidentMapper*	self = (GaussCoincidentMapper*)mapper;
-	IntegrationPointsSwarm*	integrationSwarm = self->integrationSwarm;
-	MaterialPointsSwarm*    materialSwarm = self->materialSwarm;
-	IntegrationPoint*			integrationPoint;
-	MaterialPoint*				materialPoint;
-	MaterialPointRef*			ref;
-	Particle_Index				particle_lI;
-#if 0
-	FeMesh*						mesh = materialSwarm->mesh;
-	Cell_Index					cell_dI;
-#endif
-
-#ifdef CAUTIOUS
-    Index						dim_I;
-    Stream*						errorStream = Journal_Register( Error_Type, self->type  );
-#endif
-    Stream*						debugStream = Swarm_Debug;
-	
-#if 0
-	Journal_DPrintfL( debugStream, 1, "In %s(): Re-creating a new set of integration points, exactly\n" 
-		"\tmapping to the current material points & their positions.\n", __func__ ) ;
-	Stream_IndentBranch( debugStream );
-
-	Journal_DPrintfL( debugStream, 2, "Reallocating the integration points array from size of %u points "
-		"to the \n\tcurrent material swarm particle count of %u\n", integrationSwarm->particleLocalCount,
-		materialSwarm->particleLocalCount );
-	materialSwarm->particleLocalCount = integrationSwarm->particleLocalCount;
-	Swarm_Realloc( materialSwarm );
-
-	Journal_DPrintfL( debugStream, 2, "Clearing all the cell->particle ownership tables, "
-		"ready to add new cell->particle\n\trelationships as new integration points are set up.\n" );
-
-	for( cell_dI = 0; cell_dI < materialSwarm->cellDomainCount; cell_dI++ ) {
-		materialSwarm->cellParticleCountTbl[cell_dI] = 0;
-		materialSwarm->cellParticleSizeTbl[cell_dI] = 0;
-
-		if ( materialSwarm->cellParticleTbl[cell_dI] ) {
-			Memory_Free( materialSwarm->cellParticleTbl[cell_dI] );
-		}
-		materialSwarm->cellParticleTbl[cell_dI] = NULL;
-	}
-
-	Journal_DPrintfL( debugStream, 2, "For each material particle, setting up a corresponding integration "
-		"point, and\n\tcalculating its element-local coord based on the material's global coord:\n" );
-		Stream_IndentBranch( debugStream );
-#endif
-
-	/* Map each point */
-	for ( particle_lI = 0; particle_lI < integrationSwarm->particleLocalCount; particle_lI++ ) {
-		integrationPoint = (IntegrationPoint*)Swarm_ParticleAt( integrationSwarm, particle_lI );
-		materialPoint = (MaterialPoint*)Swarm_ParticleAt( materialSwarm, particle_lI );
-
-#if 0
-		cell_dI = integrationPoint->owningCell;
-
-		Journal_DPrintfL( debugStream, 3, "Referring to local material point %u, from material swarm cell %u:\n", particle_lI, cell_dI );
-		Stream_IndentBranch( debugStream );
-
-		Journal_DPrintfL( debugStream, 3, "Adding new integration point %u to integration swarm cell %u\n", particle_lI, cell_dI );
-
-		Swarm_AddParticleToCell( materialSwarm, cell_dI, particle_lI );
-
-		/* Convert local to global coordinates */
-		FeMesh_CoordLocalToGlobal(mesh, cell_dI, integrationPoint->xi, materialPoint->coord);
-
-		Journal_DPrintfL( debugStream, 3, "Based on material point's coord of (%.2f,%.2f,%.2f):\n"
-			"calculated and set new integration point's local coord as (%.2f,%.2f,%.2f)\n",
-			materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2],
-			integrationPoint->xi[0], integrationPoint->xi[1], integrationPoint->xi[2] );
-#endif
-
-		ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
-		ref->swarm_I = materialSwarm->swarmReg_I;
-		ref->particle_I = particle_lI;
-		Journal_DPrintfL( debugStream, 3, "updated the coincident mapper's material reference for "
-			"this integration point to map back to the material point.\n" );
-		Stream_UnIndentBranch( debugStream );	
-	}
-
-#if 0
-	Stream_UnIndentBranch( debugStream );	
-	Journal_DPrintfL( debugStream, 2, "...finished updating local positions.\n" );
-
-	Stream_UnIndentBranch( debugStream );
-	Journal_DPrintfL( debugStream, 1, "...%s(): Done.\n", __func__ );
-#endif
-
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/GaussCoincidentMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/GaussCoincidentMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,252 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "IntegrationPointMapper.h"
+#include "OneToOneMapper.h"
+#include "GaussCoincidentMapper.h"
+
+#include "MaterialPointsSwarm.h"
+#include "MaterialPoint.h"
+#include "IntegrationPointsSwarm.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type GaussCoincidentMapper_Type = "GaussCoincidentMapper";
+
+GaussCoincidentMapper* GaussCoincidentMapper_New(
+	Name								name,
+	PICelleratorContext*			context,
+	IntegrationPointsSwarm*		integrationSwarm,
+	MaterialPointsSwarm*			materialSwarm )
+{
+  GaussCoincidentMapper* self = (GaussCoincidentMapper*)_GaussCoincidentMapper_DefaultNew( name );
+
+	self->isConstructed = True;
+	_IntegrationPointMapper_Init( self, context, integrationSwarm );
+   _OneToOneMapper_Init( self, materialSwarm );
+	_GaussCoincidentMapper_Init( self );
+
+	return self;
+}
+
+void* _GaussCoincidentMapper_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                 _sizeOfSelf = sizeof(GaussCoincidentMapper);
+	Type                                                                         type = GaussCoincidentMapper_Type;
+	Stg_Class_DeleteFunction*                                                 _delete = _GaussCoincidentMapper_Delete;
+	Stg_Class_PrintFunction*                                                   _print = _GaussCoincidentMapper_Print;
+	Stg_Class_CopyFunction*                                                     _copy = _GaussCoincidentMapper_Copy;
+	Stg_Component_DefaultConstructorFunction*                     _defaultConstructor = _GaussCoincidentMapper_DefaultNew;
+	Stg_Component_ConstructFunction*                                       _construct = _GaussCoincidentMapper_AssignFromXML;
+	Stg_Component_BuildFunction*                                               _build = _GaussCoincidentMapper_Build;
+	Stg_Component_InitialiseFunction*                                     _initialise = _GaussCoincidentMapper_Initialise;
+	Stg_Component_ExecuteFunction*                                           _execute = _GaussCoincidentMapper_Execute;
+	Stg_Component_DestroyFunction*                                           _destroy = _GaussCoincidentMapper_Destroy;
+	AllocationType                                                 nameAllocationType = NON_GLOBAL;
+	IntegrationPointMapper_MapFunction*                                          _map = _GaussCoincidentMapper_Map;
+	IntegrationPointMapper_GetMaterialPointsSwarmsFunction*  _getMaterialPointsSwarms = _OneToOneMapper_GetMaterialPointsSwarms;
+	IntegrationPointMapper_GetMaterialIndexOnFunction*            _getMaterialIndexOn = _OneToOneMapper_GetMaterialIndexOn;
+	IntegrationPointMapper_GetExtensionOnFunction*                    _getExtensionOn = _OneToOneMapper_GetExtensionOn;
+        IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromExtension = _OneToOneMapper_GetDoubleFromExtension;
+    IntegrationPointMapper_GetDoubleFromMaterial*                  _getDoubleFromMaterial = _OneToOneMapper_GetDoubleFromMaterial;
+
+	return _GaussCoincidentMapper_New(  GAUSSCOINCIDENTMAPPER_PASSARGS  );
+}
+
+GaussCoincidentMapper* _GaussCoincidentMapper_New(  GAUSSCOINCIDENTMAPPER_DEFARGS  ) {
+	GaussCoincidentMapper* result;
+
+	result = (GaussCoincidentMapper*)_OneToOneMapper_New(  ONETOONEMAPPER_PASSARGS  );
+
+	return result;
+}
+
+void _GaussCoincidentMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
+
+	_OneToOneMapper_AssignFromXML( self, cf, data );
+}
+
+void _GaussCoincidentMapper_Init( void* mapper ) {
+}
+
+void _GaussCoincidentMapper_Delete( void* mapper ) {
+	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
+
+	_OneToOneMapper_Delete( self );
+}
+
+void _GaussCoincidentMapper_Print( void* mapper, Stream* stream ) {
+	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
+
+	_IntegrationPointMapper_Print( self, stream );
+}
+
+void* _GaussCoincidentMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	return _IntegrationPointMapper_Copy( mapper, dest, deep, nameExt, ptrMap );
+}
+
+void _GaussCoincidentMapper_Build( void* mapper, void* cf ) {
+	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
+
+	_OneToOneMapper_Build( self, cf );
+}
+
+void _GaussCoincidentMapper_Initialise( void* mapper, void* cf ) {
+	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
+
+	_OneToOneMapper_Initialise( self, cf );
+}
+
+void _GaussCoincidentMapper_Execute( void* mapper, void* data ) {
+}
+
+void _GaussCoincidentMapper_Destroy( void* mapper, void* data ) {
+	GaussCoincidentMapper* self = (GaussCoincidentMapper*)mapper;
+
+	_OneToOneMapper_Destroy( self, data );
+}
+
+void _GaussCoincidentMapper_Map( void* mapper ) {
+	GaussCoincidentMapper*	self = (GaussCoincidentMapper*)mapper;
+	IntegrationPointsSwarm*	integrationSwarm = self->integrationSwarm;
+	MaterialPointsSwarm*    materialSwarm = self->materialSwarm;
+	IntegrationPoint*			integrationPoint;
+	MaterialPoint*				materialPoint;
+	MaterialPointRef*			ref;
+	Particle_Index				particle_lI;
+#if 0
+	FeMesh*						mesh = materialSwarm->mesh;
+	Cell_Index					cell_dI;
+#endif
+
+#ifdef CAUTIOUS
+    Index						dim_I;
+    Stream*						errorStream = Journal_Register( Error_Type, self->type  );
+#endif
+    Stream*						debugStream = Swarm_Debug;
+	
+#if 0
+	Journal_DPrintfL( debugStream, 1, "In %s(): Re-creating a new set of integration points, exactly\n" 
+		"\tmapping to the current material points & their positions.\n", __func__ ) ;
+	Stream_IndentBranch( debugStream );
+
+	Journal_DPrintfL( debugStream, 2, "Reallocating the integration points array from size of %u points "
+		"to the \n\tcurrent material swarm particle count of %u\n", integrationSwarm->particleLocalCount,
+		materialSwarm->particleLocalCount );
+	materialSwarm->particleLocalCount = integrationSwarm->particleLocalCount;
+	Swarm_Realloc( materialSwarm );
+
+	Journal_DPrintfL( debugStream, 2, "Clearing all the cell->particle ownership tables, "
+		"ready to add new cell->particle\n\trelationships as new integration points are set up.\n" );
+
+	for( cell_dI = 0; cell_dI < materialSwarm->cellDomainCount; cell_dI++ ) {
+		materialSwarm->cellParticleCountTbl[cell_dI] = 0;
+		materialSwarm->cellParticleSizeTbl[cell_dI] = 0;
+
+		if ( materialSwarm->cellParticleTbl[cell_dI] ) {
+			Memory_Free( materialSwarm->cellParticleTbl[cell_dI] );
+		}
+		materialSwarm->cellParticleTbl[cell_dI] = NULL;
+	}
+
+	Journal_DPrintfL( debugStream, 2, "For each material particle, setting up a corresponding integration "
+		"point, and\n\tcalculating its element-local coord based on the material's global coord:\n" );
+		Stream_IndentBranch( debugStream );
+#endif
+
+	/* Map each point */
+	for ( particle_lI = 0; particle_lI < integrationSwarm->particleLocalCount; particle_lI++ ) {
+		integrationPoint = (IntegrationPoint*)Swarm_ParticleAt( integrationSwarm, particle_lI );
+		materialPoint = (MaterialPoint*)Swarm_ParticleAt( materialSwarm, particle_lI );
+
+#if 0
+		cell_dI = integrationPoint->owningCell;
+
+		Journal_DPrintfL( debugStream, 3, "Referring to local material point %u, from material swarm cell %u:\n", particle_lI, cell_dI );
+		Stream_IndentBranch( debugStream );
+
+		Journal_DPrintfL( debugStream, 3, "Adding new integration point %u to integration swarm cell %u\n", particle_lI, cell_dI );
+
+		Swarm_AddParticleToCell( materialSwarm, cell_dI, particle_lI );
+
+		/* Convert local to global coordinates */
+		FeMesh_CoordLocalToGlobal(mesh, cell_dI, integrationPoint->xi, materialPoint->coord);
+
+		Journal_DPrintfL( debugStream, 3, "Based on material point's coord of (%.2f,%.2f,%.2f):\n"
+			"calculated and set new integration point's local coord as (%.2f,%.2f,%.2f)\n",
+			materialPoint->coord[0], materialPoint->coord[1], materialPoint->coord[2],
+			integrationPoint->xi[0], integrationPoint->xi[1], integrationPoint->xi[2] );
+#endif
+
+		ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
+		ref->swarm_I = materialSwarm->swarmReg_I;
+		ref->particle_I = particle_lI;
+		Journal_DPrintfL( debugStream, 3, "updated the coincident mapper's material reference for "
+			"this integration point to map back to the material point.\n" );
+		Stream_UnIndentBranch( debugStream );	
+	}
+
+#if 0
+	Stream_UnIndentBranch( debugStream );	
+	Journal_DPrintfL( debugStream, 2, "...finished updating local positions.\n" );
+
+	Stream_UnIndentBranch( debugStream );
+	Journal_DPrintfL( debugStream, 1, "...%s(): Done.\n", __func__ );
+#endif
+
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/GaussMapper.c
--- a/MaterialPoints/src/GaussMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +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 file may be distributed under the terms of the VPAC Public License
-** as defined by VPAC of Australia and appearing in the file
-** LICENSE.VPL included in the packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** $Id: GaussMapper.c 189 2005-10-20 00:39:29Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "IntegrationPointMapper.h"
-#include "OneToOneMapper.h"
-#include "GaussMapper.h"
-#include "IntegrationPointsSwarm.h"
-#include "BackgroundParticleLayout.h"
-#include "MaterialPoint.h"
-#include "MaterialPointsSwarm.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type GaussMapper_Type = "GaussMapper";
-
-GaussMapper* _GaussMapper_New(  GAUSSMAPPER_DEFARGS  ) {
-	GaussMapper* result;
-
-	result = (GaussMapper*)_OneToOneMapper_New(  ONETOONEMAPPER_PASSARGS  );
-
-	return result;
-}
-
-void* _GaussMapper_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                                 _sizeOfSelf = sizeof(GaussMapper);
-	Type                                                                         type = GaussMapper_Type;
-	Stg_Class_DeleteFunction*                                                 _delete = _GaussMapper_Delete;
-	Stg_Class_PrintFunction*                                                   _print = _GaussMapper_Print;
-	Stg_Class_CopyFunction*                                                     _copy = _GaussMapper_Copy;
-	Stg_Component_DefaultConstructorFunction*                     _defaultConstructor = _GaussMapper_DefaultNew;
-	Stg_Component_ConstructFunction*                                       _construct = _GaussMapper_AssignFromXML;
-	Stg_Component_BuildFunction*                                               _build = _GaussMapper_Build;
-	Stg_Component_InitialiseFunction*                                     _initialise = _GaussMapper_Initialise;
-	Stg_Component_ExecuteFunction*                                           _execute = _GaussMapper_Execute;
-	Stg_Component_DestroyFunction*                                           _destroy = _GaussMapper_Destroy;
-	AllocationType                                                 nameAllocationType = NON_GLOBAL;
-	IntegrationPointMapper_MapFunction*                                          _map = _GaussMapper_Map;
-	IntegrationPointMapper_GetMaterialPointsSwarmsFunction*  _getMaterialPointsSwarms = _OneToOneMapper_GetMaterialPointsSwarms;
-	IntegrationPointMapper_GetMaterialIndexOnFunction*            _getMaterialIndexOn = _OneToOneMapper_GetMaterialIndexOn;
-	IntegrationPointMapper_GetExtensionOnFunction*                    _getExtensionOn = _OneToOneMapper_GetExtensionOn;
-    IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromExtension = _OneToOneMapper_GetDoubleFromExtension;
-	IntegrationPointMapper_GetDoubleFromMaterial*                  _getDoubleFromMaterial = _OneToOneMapper_GetDoubleFromMaterial;
-
-	return _GaussMapper_New(  GAUSSMAPPER_PASSARGS  );
-}
-
-void _GaussMapper_Init( void* mapper ) {
-	GaussMapper* self;
-
-	self = (GaussMapper*)mapper;
-}
-
-void _GaussMapper_Delete( void* mapper ) {
-	GaussMapper* self = (GaussMapper*)mapper;
-
-	_OneToOneMapper_Delete( self );
-}
-
-void _GaussMapper_Print( void* mapper, Stream* stream ) {
-	GaussMapper* self = (GaussMapper*)mapper;
-
-	_OneToOneMapper_Print( self, stream );
-}
-
-void* _GaussMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	return _IntegrationPointMapper_Copy( mapper, dest, deep, nameExt, ptrMap );
-}
-
-void _GaussMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	GaussMapper* self = (GaussMapper*)mapper;
-	
-	_OneToOneMapper_AssignFromXML( mapper, cf, data );
-
-	/* Validate assumptions on the layouts the swarms use */
-	Journal_Firewall(
-		Stg_Class_IsInstance( self->integrationSwarm->particleLayout, GaussParticleLayout_Type ) ||
-		Stg_Class_IsInstance( self->integrationSwarm->particleLayout, TriGaussParticleLayout_Type ),
-		Journal_MyStream( Error_Type, self ),
-		"In func %s, To use Gauss mapper, the integration point swarm %s must use a %s\n",
-		__func__,
-		self->integrationSwarm->name,
-		GaussParticleLayout_Type );
-
-	Journal_Firewall(
-		Stg_Class_IsInstance( self->materialSwarm->particleLayout, BackgroundParticleLayout_Type ),
-		Journal_MyStream( Error_Type, self ),
-		"In func %s, To use Gauss mapper, the material point swarm %s must use a %s\n",
-		__func__,
-		self->materialSwarm->particleLayout,
-		BackgroundParticleLayout_Type );
-
-	_GaussMapper_Init( self );
-}
-
-void _GaussMapper_Build( void* mapper, void* cf ) {
-	GaussMapper* self = (GaussMapper*)mapper;
-
-	_OneToOneMapper_Build( self, cf );
-}
-
-void _GaussMapper_Initialise( void* mapper, void* cf ) {
-	GaussMapper* self = (GaussMapper*)mapper;
-
-	_OneToOneMapper_Initialise( self, cf );
-}
-
-void _GaussMapper_Execute( void* mapper, void* data ) {
-}
-
-void _GaussMapper_Destroy( void* mapper, void* data ) {
-	GaussMapper* self = (GaussMapper*)mapper;
-
-	_OneToOneMapper_Destroy( self, data );
-}
-
-void _GaussMapper_Map( void* mapper ) {
-	GaussMapper*				self = (GaussMapper*)mapper;
-	IntegrationPointsSwarm*	integrationSwarm = self->integrationSwarm;
-	MaterialPointsSwarm*		materialSwarm = self->materialSwarm;
-	IntegrationPoint*			integrationPoint;
-	MaterialPoint*				materialPoint;
-	MaterialPointRef*			ref;
-	Particle_Index				point_I;
-
-	materialPoint = (MaterialPoint*)Swarm_ParticleAt( materialSwarm, 0 ); /* Get the first and only point */
-	
-	/* Map each point in integration to the single material point for its properties */
-	for ( point_I = 0; point_I < integrationSwarm->particleLocalCount; point_I++ ) {
-		integrationPoint = (IntegrationPoint*)Swarm_ParticleAt( integrationSwarm, point_I );
-
-		ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
-		ref->swarm_I = materialSwarm->swarmReg_I;
-		ref->particle_I = 0;
-	}
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/GaussMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/GaussMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,169 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org) ) {
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This file may be distributed under the terms of the VPAC Public License
+** as defined by VPAC of Australia and appearing in the file
+** LICENSE.VPL included in the packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** $Id: GaussMapper.c 189 2005-10-20 00:39:29Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "IntegrationPointMapper.h"
+#include "OneToOneMapper.h"
+#include "GaussMapper.h"
+#include "IntegrationPointsSwarm.h"
+#include "BackgroundParticleLayout.h"
+#include "MaterialPoint.h"
+#include "MaterialPointsSwarm.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type GaussMapper_Type = "GaussMapper";
+
+GaussMapper* _GaussMapper_New(  GAUSSMAPPER_DEFARGS  ) {
+	GaussMapper* result;
+
+	result = (GaussMapper*)_OneToOneMapper_New(  ONETOONEMAPPER_PASSARGS  );
+
+	return result;
+}
+
+void* _GaussMapper_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                                 _sizeOfSelf = sizeof(GaussMapper);
+	Type                                                                         type = GaussMapper_Type;
+	Stg_Class_DeleteFunction*                                                 _delete = _GaussMapper_Delete;
+	Stg_Class_PrintFunction*                                                   _print = _GaussMapper_Print;
+	Stg_Class_CopyFunction*                                                     _copy = _GaussMapper_Copy;
+	Stg_Component_DefaultConstructorFunction*                     _defaultConstructor = _GaussMapper_DefaultNew;
+	Stg_Component_ConstructFunction*                                       _construct = _GaussMapper_AssignFromXML;
+	Stg_Component_BuildFunction*                                               _build = _GaussMapper_Build;
+	Stg_Component_InitialiseFunction*                                     _initialise = _GaussMapper_Initialise;
+	Stg_Component_ExecuteFunction*                                           _execute = _GaussMapper_Execute;
+	Stg_Component_DestroyFunction*                                           _destroy = _GaussMapper_Destroy;
+	AllocationType                                                 nameAllocationType = NON_GLOBAL;
+	IntegrationPointMapper_MapFunction*                                          _map = _GaussMapper_Map;
+	IntegrationPointMapper_GetMaterialPointsSwarmsFunction*  _getMaterialPointsSwarms = _OneToOneMapper_GetMaterialPointsSwarms;
+	IntegrationPointMapper_GetMaterialIndexOnFunction*            _getMaterialIndexOn = _OneToOneMapper_GetMaterialIndexOn;
+	IntegrationPointMapper_GetExtensionOnFunction*                    _getExtensionOn = _OneToOneMapper_GetExtensionOn;
+    IntegrationPointMapper_GetDoubleFromExtension*                  _getDoubleFromExtension = _OneToOneMapper_GetDoubleFromExtension;
+	IntegrationPointMapper_GetDoubleFromMaterial*                  _getDoubleFromMaterial = _OneToOneMapper_GetDoubleFromMaterial;
+
+	return _GaussMapper_New(  GAUSSMAPPER_PASSARGS  );
+}
+
+void _GaussMapper_Init( void* mapper ) {
+	GaussMapper* self;
+
+	self = (GaussMapper*)mapper;
+}
+
+void _GaussMapper_Delete( void* mapper ) {
+	GaussMapper* self = (GaussMapper*)mapper;
+
+	_OneToOneMapper_Delete( self );
+}
+
+void _GaussMapper_Print( void* mapper, Stream* stream ) {
+	GaussMapper* self = (GaussMapper*)mapper;
+
+	_OneToOneMapper_Print( self, stream );
+}
+
+void* _GaussMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	return _IntegrationPointMapper_Copy( mapper, dest, deep, nameExt, ptrMap );
+}
+
+void _GaussMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	GaussMapper* self = (GaussMapper*)mapper;
+	
+	_OneToOneMapper_AssignFromXML( mapper, cf, data );
+
+	/* Validate assumptions on the layouts the swarms use */
+	Journal_Firewall(
+		Stg_Class_IsInstance( self->integrationSwarm->particleLayout, GaussParticleLayout_Type ) ||
+		Stg_Class_IsInstance( self->integrationSwarm->particleLayout, TriGaussParticleLayout_Type ),
+		Journal_MyStream( Error_Type, self ),
+		"In func %s, To use Gauss mapper, the integration point swarm %s must use a %s\n",
+		__func__,
+		self->integrationSwarm->name,
+		GaussParticleLayout_Type );
+
+	Journal_Firewall(
+		Stg_Class_IsInstance( self->materialSwarm->particleLayout, BackgroundParticleLayout_Type ),
+		Journal_MyStream( Error_Type, self ),
+		"In func %s, To use Gauss mapper, the material point swarm %s must use a %s\n",
+		__func__,
+		self->materialSwarm->particleLayout,
+		BackgroundParticleLayout_Type );
+
+	_GaussMapper_Init( self );
+}
+
+void _GaussMapper_Build( void* mapper, void* cf ) {
+	GaussMapper* self = (GaussMapper*)mapper;
+
+	_OneToOneMapper_Build( self, cf );
+}
+
+void _GaussMapper_Initialise( void* mapper, void* cf ) {
+	GaussMapper* self = (GaussMapper*)mapper;
+
+	_OneToOneMapper_Initialise( self, cf );
+}
+
+void _GaussMapper_Execute( void* mapper, void* data ) {
+}
+
+void _GaussMapper_Destroy( void* mapper, void* data ) {
+	GaussMapper* self = (GaussMapper*)mapper;
+
+	_OneToOneMapper_Destroy( self, data );
+}
+
+void _GaussMapper_Map( void* mapper ) {
+	GaussMapper*				self = (GaussMapper*)mapper;
+	IntegrationPointsSwarm*	integrationSwarm = self->integrationSwarm;
+	MaterialPointsSwarm*		materialSwarm = self->materialSwarm;
+	IntegrationPoint*			integrationPoint;
+	MaterialPoint*				materialPoint;
+	MaterialPointRef*			ref;
+	Particle_Index				point_I;
+
+	materialPoint = (MaterialPoint*)Swarm_ParticleAt( materialSwarm, 0 ); /* Get the first and only point */
+	
+	/* Map each point in integration to the single material point for its properties */
+	for ( point_I = 0; point_I < integrationSwarm->particleLocalCount; point_I++ ) {
+		integrationPoint = (IntegrationPoint*)Swarm_ParticleAt( integrationSwarm, point_I );
+
+		ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
+		ref->swarm_I = materialSwarm->swarmReg_I;
+		ref->particle_I = 0;
+	}
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Init.c
--- a/MaterialPoints/src/Init.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 582 2008-08-12 03:15:11Z WendySharples $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <stdio.h>
-
-Bool PICellerator_MaterialPoints_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, "Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-	Stg_ComponentRegister_Add( componentsRegister, PICelleratorContext_Type, "0", _PICelleratorContext_DefaultNew  );
-
-	Stg_ComponentRegister_Add( componentsRegister, BackgroundParticleLayout_Type, "0", _BackgroundParticleLayout_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentsRegister, MappedParticleLayout_Type, "0", _MappedParticleLayout_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, IntegrationPointsSwarm_Type, "0", _IntegrationPointsSwarm_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, MaterialPointsSwarm_Type, "0", _MaterialPointsSwarm_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentsRegister, MaterialFeVariable_Type, "0", _MaterialFeVariable_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, Material_Type, "0", _Material_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentsRegister, CoincidentMapper_Type, "0", _CoincidentMapper_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, GaussCoincidentMapper_Type, "0", _GaussCoincidentMapper_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, GaussMapper_Type, "0", _GaussMapper_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentsRegister, SwarmAdvector_Type, "0", _SwarmAdvector_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, SwarmAdvectionInAPlane_Type, "0", _SwarmAdvectionInAPlane_DefaultNew  );
-
-	Stg_ComponentRegister_Add( componentsRegister, PeriodicBoundariesManager_Type, "0", _PeriodicBoundariesManager_DefaultNew  );
-	
-	Stg_ComponentRegister_Add( componentsRegister, SwarmVariableField_Type, "0", _SwarmVariableField_DefaultNew  );
-
-	/* Doing this in alphabetical order to match ls output */
-	RegisterParent( BackgroundParticleLayout_Type,  ParticleLayout_Type );
-	RegisterParent( CoincidentMapper_Type,          OneToOneMapper_Type );
-	RegisterParent( GaussCoincidentMapper_Type,     OneToOneMapper_Type );
-	RegisterParent( PICelleratorContext_Type,       FiniteElementContext_Type );
-	RegisterParent( GaussMapper_Type,               OneToOneMapper_Type );
-	RegisterParent( IntegrationPointMapper_Type,    Stg_Component_Type );
-	RegisterParent( IntegrationPointsSwarm_Type,    Swarm_Type );
-	RegisterParent( MappedParticleLayout_Type,      ParticleLayout_Type );
-	RegisterParent( ManyToOneMapper_Type,           IntegrationPointMapper_Type );
-	RegisterParent( Material_Type,                  Stg_Component_Type );
-	RegisterParent( MaterialFeVariable_Type,        ParticleFeVariable_Type );
-	RegisterParent( Materials_Register_Type,        NamedObject_Register_Type );
-	RegisterParent( MaterialPointsSwarm_Type,       Swarm_Type );
-	RegisterParent( OneToOneMapper_Type,            IntegrationPointMapper_Type );
-	RegisterParent(OneToManyMapper_Type, IntegrationPointMapper_Type);
-	RegisterParent( ParticleFeVariable_Type,        FeVariable_Type );
-	RegisterParent( PeriodicBoundariesManager_Type, Stg_Component_Type );
-	RegisterParent( SwarmAdvector_Type,             TimeIntegrand_Type );
-	RegisterParent( SwarmAdvectionInAPlane_Type,            SwarmAdvector_Type );
-	
-	/* dave, 18.09.07 */
-	RegisterParent( SwarmVariableField_Type,        ParticleFeVariable_Type );
-
-
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/Init.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,111 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 582 2008-08-12 03:15:11Z WendySharples $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <stdio.h>
+
+Bool PICellerator_MaterialPoints_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, "Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+	Stg_ComponentRegister_Add( componentsRegister, PICelleratorContext_Type, "0", _PICelleratorContext_DefaultNew  );
+
+	Stg_ComponentRegister_Add( componentsRegister, BackgroundParticleLayout_Type, "0", _BackgroundParticleLayout_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentsRegister, MappedParticleLayout_Type, "0", _MappedParticleLayout_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, IntegrationPointsSwarm_Type, "0", _IntegrationPointsSwarm_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, MaterialPointsSwarm_Type, "0", _MaterialPointsSwarm_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentsRegister, MaterialFeVariable_Type, "0", _MaterialFeVariable_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, Material_Type, "0", _Material_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentsRegister, CoincidentMapper_Type, "0", _CoincidentMapper_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, GaussCoincidentMapper_Type, "0", _GaussCoincidentMapper_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, GaussMapper_Type, "0", _GaussMapper_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentsRegister, SwarmAdvector_Type, "0", _SwarmAdvector_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, SwarmAdvectionInAPlane_Type, "0", _SwarmAdvectionInAPlane_DefaultNew  );
+
+	Stg_ComponentRegister_Add( componentsRegister, PeriodicBoundariesManager_Type, "0", _PeriodicBoundariesManager_DefaultNew  );
+	
+	Stg_ComponentRegister_Add( componentsRegister, SwarmVariableField_Type, "0", _SwarmVariableField_DefaultNew  );
+
+	/* Doing this in alphabetical order to match ls output */
+	RegisterParent( BackgroundParticleLayout_Type,  ParticleLayout_Type );
+	RegisterParent( CoincidentMapper_Type,          OneToOneMapper_Type );
+	RegisterParent( GaussCoincidentMapper_Type,     OneToOneMapper_Type );
+	RegisterParent( PICelleratorContext_Type,       FiniteElementContext_Type );
+	RegisterParent( GaussMapper_Type,               OneToOneMapper_Type );
+	RegisterParent( IntegrationPointMapper_Type,    Stg_Component_Type );
+	RegisterParent( IntegrationPointsSwarm_Type,    Swarm_Type );
+	RegisterParent( MappedParticleLayout_Type,      ParticleLayout_Type );
+	RegisterParent( ManyToOneMapper_Type,           IntegrationPointMapper_Type );
+	RegisterParent( Material_Type,                  Stg_Component_Type );
+	RegisterParent( MaterialFeVariable_Type,        ParticleFeVariable_Type );
+	RegisterParent( Materials_Register_Type,        NamedObject_Register_Type );
+	RegisterParent( MaterialPointsSwarm_Type,       Swarm_Type );
+	RegisterParent( OneToOneMapper_Type,            IntegrationPointMapper_Type );
+	RegisterParent(OneToManyMapper_Type, IntegrationPointMapper_Type);
+	RegisterParent( ParticleFeVariable_Type,        FeVariable_Type );
+	RegisterParent( PeriodicBoundariesManager_Type, Stg_Component_Type );
+	RegisterParent( SwarmAdvector_Type,             TimeIntegrand_Type );
+	RegisterParent( SwarmAdvectionInAPlane_Type,            SwarmAdvector_Type );
+	
+	/* dave, 18.09.07 */
+	RegisterParent( SwarmVariableField_Type,        ParticleFeVariable_Type );
+
+
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/IntegrationPointMapper.c
--- a/MaterialPoints/src/IntegrationPointMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type IntegrationPointMapper_Type = "IntegrationPointMapper";
-
-IntegrationPointMapper* _IntegrationPointMapper_New(  INTEGRATIONPOINTMAPPER_DEFARGS  ) {
-	IntegrationPointMapper* self;
-
-	self = (IntegrationPointMapper*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	self->_map = _map;
-	self->_getMaterialPointsSwarms = _getMaterialPointsSwarms;
-	self->_getMaterialIndexOn = _getMaterialIndexOn;
-	self->_getExtensionOn = _getExtensionOn;
-    self->_getDoubleFromExtension        = _getDoubleFromExtension;
-	self->_getDoubleFromMaterial         = _getDoubleFromMaterial;
-
-	return self;
-}
-
-void _IntegrationPointMapper_Init( void* mapper, PICelleratorContext* context, IntegrationPointsSwarm* integrationSwarm ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-
-	self->context = context;
-	self->integrationSwarm = integrationSwarm;
-}
-
-void _IntegrationPointMapper_Delete( void* mapper ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-
-	_Stg_Component_Delete( self );
-}
-
-void _IntegrationPointMapper_Print( void* mapper, Stream* stream ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-	
-	Journal_Printf( stream, "IntegrationPointMapper (ptr): %s\n", (void*)self );
-	_Stg_Component_Print( self, stream );
-
-	Stream_Indent( stream );
-
-	Stg_Class_Print( self->integrationSwarm, stream );
-
-	Stream_UnIndent( stream );
-}
-
-void* _IntegrationPointMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-	IntegrationPointMapper* newCopy = (IntegrationPointMapper*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newCopy->integrationSwarm = (IntegrationPointsSwarm*)(Stg_Class_Copy( self->integrationSwarm, NULL, deep, nameExt, ptrMap ));
-
-	return newCopy;
-}
-
-void _IntegrationPointMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	IntegrationPointMapper*	self = (IntegrationPointMapper*)mapper;
-	IntegrationPointsSwarm*	integrationSwarm;
-	PICelleratorContext*		context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
-	if( !context  ) 
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );
-
-	integrationSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)IntegrationPointsSwarm_Type, IntegrationPointsSwarm, True, data  );
-	
-	_IntegrationPointMapper_Init( self, context, integrationSwarm );
-}
-
-void _IntegrationPointMapper_Build( void* mapper, void* data ) {
-	IntegrationPointMapper*	self;
-
-	self = (IntegrationPointMapper*)mapper;
-}
-
-void _IntegrationPointMapper_Initialise( void* mapper, void* data ) {
-	IntegrationPointMapper*	self;
-
-	self = (IntegrationPointMapper*)mapper;
-}
-
-void _IntegrationPointMapper_Execute( void* mapper, void* data ) {
-}
-
-void _IntegrationPointMapper_Destroy( void* mapper, void* data ) {
-	IntegrationPointMapper* self;
-	
-	self = (IntegrationPointMapper*)mapper;
-}
-
-void IntegrationPointMapper_Map( void* mapper ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-
-	self->_map( self );
-}
-
-MaterialPointsSwarm** IntegrationPointMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-
-	return self->_getMaterialPointsSwarms( mapper, count );
-}
-
-Material_Index IntegrationPointMapper_GetMaterialIndexOnFunc( void* mapper, void* point ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-
-	return self->_getMaterialIndexOn( mapper, point );
-}
-
-void* IntegrationPointMapper_GetExtensionOnFunc( void* mapper, void* point, ExtensionInfo_Index extHandle ) {
-	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
-
-	return self->_getExtensionOn( mapper, point, extHandle );
-}
-
-Material_Index IntegrationPointMapper_GetMaterialIndexAtFunc( void* mapper, Index point_I ) {
-	IntegrationPointMapper* self  = (IntegrationPointMapper*)mapper;
-	void*                   point = Swarm_ParticleAt( self->integrationSwarm, point_I );
-
-	Journal_Firewall( point != NULL, Journal_MyStream( Error_Type, self ), "In func %s, no point in swarm of index %d\n", __func__, point_I );
-
-	return IntegrationPointMapper_GetMaterialIndexOn( mapper, point );
-}
-void* IntegrationPointMapper_GetExtensionAtFunc( void* mapper, Index point_I, ExtensionInfo_Index extHandle ) {
-	IntegrationPointMapper* self  = (IntegrationPointMapper*)mapper;
-	void*                   point = Swarm_ParticleAt( self->integrationSwarm, point_I );
-
-	Journal_Firewall( point != NULL, Journal_MyStream( Error_Type, self ), "In func %s, no point in swarm of index %d\n", __func__, point_I );
-	
-	return IntegrationPointMapper_GetExtensionOn( mapper, point, extHandle );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/IntegrationPointMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/IntegrationPointMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,187 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type IntegrationPointMapper_Type = "IntegrationPointMapper";
+
+IntegrationPointMapper* _IntegrationPointMapper_New(  INTEGRATIONPOINTMAPPER_DEFARGS  ) {
+	IntegrationPointMapper* self;
+
+	self = (IntegrationPointMapper*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	self->_map = _map;
+	self->_getMaterialPointsSwarms = _getMaterialPointsSwarms;
+	self->_getMaterialIndexOn = _getMaterialIndexOn;
+	self->_getExtensionOn = _getExtensionOn;
+    self->_getDoubleFromExtension        = _getDoubleFromExtension;
+	self->_getDoubleFromMaterial         = _getDoubleFromMaterial;
+
+	return self;
+}
+
+void _IntegrationPointMapper_Init( void* mapper, PICelleratorContext* context, IntegrationPointsSwarm* integrationSwarm ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+
+	self->context = context;
+	self->integrationSwarm = integrationSwarm;
+}
+
+void _IntegrationPointMapper_Delete( void* mapper ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+
+	_Stg_Component_Delete( self );
+}
+
+void _IntegrationPointMapper_Print( void* mapper, Stream* stream ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+	
+	Journal_Printf( stream, "IntegrationPointMapper (ptr): %s\n", (void*)self );
+	_Stg_Component_Print( self, stream );
+
+	Stream_Indent( stream );
+
+	Stg_Class_Print( self->integrationSwarm, stream );
+
+	Stream_UnIndent( stream );
+}
+
+void* _IntegrationPointMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+	IntegrationPointMapper* newCopy = (IntegrationPointMapper*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newCopy->integrationSwarm = (IntegrationPointsSwarm*)(Stg_Class_Copy( self->integrationSwarm, NULL, deep, nameExt, ptrMap ));
+
+	return newCopy;
+}
+
+void _IntegrationPointMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	IntegrationPointMapper*	self = (IntegrationPointMapper*)mapper;
+	IntegrationPointsSwarm*	integrationSwarm;
+	PICelleratorContext*		context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
+	if( !context  ) 
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );
+
+	integrationSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)IntegrationPointsSwarm_Type, IntegrationPointsSwarm, True, data  );
+	
+	_IntegrationPointMapper_Init( self, context, integrationSwarm );
+}
+
+void _IntegrationPointMapper_Build( void* mapper, void* data ) {
+	IntegrationPointMapper*	self;
+
+	self = (IntegrationPointMapper*)mapper;
+}
+
+void _IntegrationPointMapper_Initialise( void* mapper, void* data ) {
+	IntegrationPointMapper*	self;
+
+	self = (IntegrationPointMapper*)mapper;
+}
+
+void _IntegrationPointMapper_Execute( void* mapper, void* data ) {
+}
+
+void _IntegrationPointMapper_Destroy( void* mapper, void* data ) {
+	IntegrationPointMapper* self;
+	
+	self = (IntegrationPointMapper*)mapper;
+}
+
+void IntegrationPointMapper_Map( void* mapper ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+
+	self->_map( self );
+}
+
+MaterialPointsSwarm** IntegrationPointMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+
+	return self->_getMaterialPointsSwarms( mapper, count );
+}
+
+Material_Index IntegrationPointMapper_GetMaterialIndexOnFunc( void* mapper, void* point ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+
+	return self->_getMaterialIndexOn( mapper, point );
+}
+
+void* IntegrationPointMapper_GetExtensionOnFunc( void* mapper, void* point, ExtensionInfo_Index extHandle ) {
+	IntegrationPointMapper* self = (IntegrationPointMapper*)mapper;
+
+	return self->_getExtensionOn( mapper, point, extHandle );
+}
+
+Material_Index IntegrationPointMapper_GetMaterialIndexAtFunc( void* mapper, Index point_I ) {
+	IntegrationPointMapper* self  = (IntegrationPointMapper*)mapper;
+	void*                   point = Swarm_ParticleAt( self->integrationSwarm, point_I );
+
+	Journal_Firewall( point != NULL, Journal_MyStream( Error_Type, self ), "In func %s, no point in swarm of index %d\n", __func__, point_I );
+
+	return IntegrationPointMapper_GetMaterialIndexOn( mapper, point );
+}
+void* IntegrationPointMapper_GetExtensionAtFunc( void* mapper, Index point_I, ExtensionInfo_Index extHandle ) {
+	IntegrationPointMapper* self  = (IntegrationPointMapper*)mapper;
+	void*                   point = Swarm_ParticleAt( self->integrationSwarm, point_I );
+
+	Journal_Firewall( point != NULL, Journal_MyStream( Error_Type, self ), "In func %s, no point in swarm of index %d\n", __func__, point_I );
+	
+	return IntegrationPointMapper_GetExtensionOn( mapper, point, extHandle );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/IntegrationPointsSwarm.c
--- a/MaterialPoints/src/IntegrationPointsSwarm.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,458 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: IntegrationPointsSwarm.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-#include "Material.h"
-#include "PICelleratorContext.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type IntegrationPointsSwarm_Type = "IntegrationPointsSwarm";
-
-IntegrationPointsSwarm* IntegrationPointsSwarm_New(
-		Name                                  name,
-      AbstractContext*                      context,
-		void*                                 cellLayout,
-		void*                                 particleLayout,
-		Dimension_Index                       dim,
-		SizeT                                 particleSize,
-		Particle_InCellIndex                  cellParticleTblDelta,
-		double                                extraParticlesFactor,
-		FeMesh*                   	      mesh,
-		TimeIntegrator*                       timeIntegrator,
-		WeightsCalculator*                    weights,
-		IntegrationPointMapper*               mapper,
-		Bool                                  recalculateWeights,
-		ExtensionManager_Register*            extensionMgr_Register,
-		Variable_Register*                    swarmVariable_Register,
-		Materials_Register*                   materials_Register,
-		MPI_Comm                              comm,
-      void*                                 ics_dummy)
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(IntegrationPointsSwarm);
-	Type                                                      type = IntegrationPointsSwarm_Type;
-	Stg_Class_DeleteFunction*                              _delete = _IntegrationPointsSwarm_Delete;
-	Stg_Class_PrintFunction*                                _print = _IntegrationPointsSwarm_Print;
-	Stg_Class_CopyFunction*                                  _copy = _IntegrationPointsSwarm_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _IntegrationPointsSwarm_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _IntegrationPointsSwarm_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _IntegrationPointsSwarm_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _IntegrationPointsSwarm_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _IntegrationPointsSwarm_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _IntegrationPointsSwarm_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 */;
-	void*                          ics = ZERO;
-
-    IntegrationPointsSwarm* self = _IntegrationPointsSwarm_New(  INTEGRATIONPOINTSSWARM_PASSARGS  );
-
-    _Swarm_Init( 
-         (Swarm*)self, context,
-         cellLayout,
-         particleLayout,
-         dim,
-         particleSize,
-         cellParticleTblDelta,
-         extraParticlesFactor,
-         extensionMgr_Register,
-         swarmVariable_Register,
-         comm, 
-         ics_dummy );
-
-   _IntegrationPointsSwarm_Init( 
-      self,
-      mesh, 
-      timeIntegrator,
-      weights,
-      mapper,
-      materials_Register,
-      recalculateWeights );
-
-	return self;
-}
-
-void* _IntegrationPointsSwarm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(IntegrationPointsSwarm);
-	Type                                                         type = IntegrationPointsSwarm_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _IntegrationPointsSwarm_Delete;
-	Stg_Class_PrintFunction*                                   _print = _IntegrationPointsSwarm_Print;
-	Stg_Class_CopyFunction*                                     _copy = _IntegrationPointsSwarm_Copy;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _IntegrationPointsSwarm_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _IntegrationPointsSwarm_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _IntegrationPointsSwarm_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _IntegrationPointsSwarm_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _IntegrationPointsSwarm_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _IntegrationPointsSwarm_Destroy;
-	SizeT                                                particleSize = sizeof(IntegrationPoint);
-
-	/* 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 */;
-	void*                          ics = ZERO;
-
-	return (void*) _IntegrationPointsSwarm_New(  INTEGRATIONPOINTSSWARM_PASSARGS  );
-}
-
-
-IntegrationPointsSwarm* _IntegrationPointsSwarm_New(  INTEGRATIONPOINTSSWARM_DEFARGS  )
-{
-	IntegrationPointsSwarm* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(IntegrationPointsSwarm) );
-	/* 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. */
-	ics = NULL;
-
-	self = (IntegrationPointsSwarm*)_Swarm_New(  SWARM_PASSARGS  );
-
-	return self;
-}
-
-
-void _IntegrationPointsSwarm_AssignFromXML( void* integrationPoints, Stg_ComponentFactory* cf, void* data ) {
-	IntegrationPointsSwarm*	        self          = (IntegrationPointsSwarm*) integrationPoints;
-	FeMesh*             		mesh;
-	TimeIntegrator*                 timeIntegrator;
-	WeightsCalculator*              weights;
-	IntegrationPointMapper*         mapper;
-	Materials_Register*             materials_Register;
-	Bool                            recalculateWeights;
-	PICelleratorContext*		context;
-
-	/* This will also call _Swarm_Init */
-	_Swarm_AssignFromXML( self, cf, data );
-
-	mesh           = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data  );
-	timeIntegrator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TimeIntegrator", TimeIntegrator, True, data  );
-	weights        = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"WeightsCalculator", WeightsCalculator, False, data  );
-	mapper         = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IntegrationPointMapper", IntegrationPointMapper, True, data  );
-	recalculateWeights = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"recalculateWeights", True  );
-
-	Journal_Firewall (
-			weights != NULL ||
-			(weights == NULL && (Stg_Class_IsInstance( mapper, GaussMapper_Type ) ||
-					     Stg_Class_IsInstance( mapper, GaussCoincidentMapper_Type) ||
-					     !strcmp( mapper->type, "PCDVCGaussMapper"))),
-			Journal_MyStream( Error_Type, self ),
-			"In func %s, %s which is a %s must either have a %s or use %s\n",
-			__func__,
-			self->name,
-			self->type,
-			WeightsCalculator_Type,
-			GaussMapper_Type );
-	
-	context = (PICelleratorContext*)self->context;
-	assert( Stg_CheckType( context, PICelleratorContext ) );
-	materials_Register = context->materials_Register;
-	assert( materials_Register );
-
-	_IntegrationPointsSwarm_Init( self, mesh, timeIntegrator, weights, mapper, materials_Register, recalculateWeights );
-}
-
-
-void _IntegrationPointsSwarm_Init( 
-		void*                                 swarm,
-		FeMesh*                   mesh, 
-		TimeIntegrator*                       timeIntegrator,
-		WeightsCalculator*                    weights,
-		IntegrationPointMapper*               mapper,
-		Materials_Register*                   materials_Register,
-		Bool                                  recalculateWeights )
-{
-	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
-	LocalParticle localParticle;
-	IntegrationPoint particle;
-
-	self->mesh               = mesh;
-	self->timeIntegrator     = timeIntegrator;
-	self->weights            = weights;
-	self->mapper             = mapper;
-	self->materials_Register = materials_Register;
-
-	self->recalculateWeights = recalculateWeights;
-
-	/* Disable checkpointing and reloading of IP swarms - currently they can't be reloaded if the particles
-	don't have a global coord. We assume there is no history info on them which means we're happy to re-create
-	them from scratch given the position the material points were in when the checkpoint was made as input
-	-- PatrickSunter 12 June 2006 */
-	self->isSwarmTypeToCheckPointAndReload = False;
-
-	self->weightVariable = Swarm_NewScalarVariable( self, (Name)"Weight", GetOffsetOfMember( particle , weight  ), 
-			Variable_DataType_Double );
-
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable );
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable->variable );
-
-	self->localCoordVariable = Swarm_NewVectorVariable( self, (Name)"LocalElCoord", GetOffsetOfMember( localParticle , xi ),
-		Variable_DataType_Double,
-		self->dim,
-		"Xi",
-		"Eta",
-		"Zeta" );
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable );
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable->variable );
-
-	if ( timeIntegrator ) {
-		/* Assuming this is called from _IntegrationPointsSwarm_AssignFromXML, it would have always called construct
-		 * on the mapper which in turn would have constructed any MaterialPointsSwarms with it.
-		 * The MaterialPointsSwarms would have already appended their update routines to the EP, and hence this
-		 * ensures that the _IntegrationPointsSwarm_UpdateHook will always be called last */
-		TimeIntegrator_InsertAfterFinishEP(
-				timeIntegrator,
-				"MaterialPointsSwarm_Update", /* Needs to be after a the material update */
-				"IntegrationPointsSwarm_Update",
-				(Func_Ptr)_IntegrationPointsSwarm_UpdateHook,
-				self->name,
-				self );
-	}
-	
-	/* _Construct calls _Swarm_Init */
-
-	/* Lock down the extension manager.
-	 * It doesn't make sense for the IntegrationPointsSwarm to allow IntegrationPoints to be extended
-	 * This means attempts to extend integration points are firewalled to pickup errors.
-	 * -- Alan 20060506
-	 */
-	ExtensionManager_SetLockDown( self->particleExtensionMgr, True );
-}
-
-void _IntegrationPointsSwarm_Delete( void* integrationPoints ) {
-	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)integrationPoints;
-
-	_Swarm_Delete( self );
-}
-
-
-void _IntegrationPointsSwarm_Print( void* integrationPoints, Stream* stream ) {
-	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)integrationPoints;
-	
-	_Swarm_Print( self, stream );
-}
-
-void* _IntegrationPointsSwarm_Copy( const void* integrationPoints, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*)integrationPoints;
-	IntegrationPointsSwarm*	newIntegrationPointsSwarm;
-	
-	newIntegrationPointsSwarm = (IntegrationPointsSwarm*)_Swarm_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newIntegrationPointsSwarm->mesh = (FeMesh*)Stg_Class_Copy(
-				self->mesh,
-				NULL,
-				deep,
-				nameExt,
-				ptrMap );
-	if ( self->weights != NULL ) {
-		newIntegrationPointsSwarm->weights = (WeightsCalculator*)Stg_Class_Copy(
-					self->weights,
-					NULL,
-					deep,
-					nameExt,
-					ptrMap );
-	}
-	newIntegrationPointsSwarm->mapper = (IntegrationPointMapper*)Stg_Class_Copy(
-				self->mapper,
-				NULL,
-				deep,
-				nameExt,
-				ptrMap );
-	newIntegrationPointsSwarm->materials_Register = self->materials_Register;
-	newIntegrationPointsSwarm->weightVariable = (SwarmVariable*)Stg_Class_Copy(
-				self->weightVariable,
-				NULL,
-				deep,
-				nameExt,
-				ptrMap );
-	
-	return (void*)newIntegrationPointsSwarm;
-}
-
-
-void _IntegrationPointsSwarm_Build( void* integrationPoints, void* data ) {
-	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*) integrationPoints;
-
-	_Swarm_Build( self, data );
-
-	Stg_Component_Build( self->localCoordVariable, data, False );
-	Stg_Component_Build( self->weightVariable, data, False );
-	Stg_Component_Build( self->mapper, data, False );
-   Stg_Component_Build( self->mesh, data, False );
-   Stg_Component_Build( self->timeIntegrator, data, False );
-   if ( self->weights != NULL ) {
-		Stg_Component_Build( self->weights, data, False );
-	}
-   
-}
-void _IntegrationPointsSwarm_Initialise( void* integrationPoints, void* data ) {
-	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*) integrationPoints;
-
-	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\":\n",
-		__func__, self->name );
-	Stream_IndentBranch( Swarm_Debug );
-
-	_Swarm_Initialise( self, data );
-
-	Stg_Component_Initialise( self->localCoordVariable, data, False );
-	Stg_Component_Initialise( self->weightVariable, data, False );
-	Stg_Component_Initialise( self->mapper, data, False );
-   Stg_Component_Initialise( self->mesh, data, False );
-   Stg_Component_Initialise( self->timeIntegrator, data, False );
-
-	if ( self->weights != NULL ) {
-		Stg_Component_Initialise( self->weights, data, False );
-	}
-
-	/* We call this function to actually set up the integration point positions and 
-	weights, based on the now set up material point swarm */
-	IntegrationPointsSwarm_RemapIntegrationPointsAndRecalculateWeights( self );
-
-	Stream_UnIndentBranch( Swarm_Debug );
-	Journal_DPrintf( self->debug, "...done in %s() for swarm \"%s\".\n",
-		__func__, self->name );
-}
-void _IntegrationPointsSwarm_Execute( void* integrationPoints, void* data ) {
-	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*)integrationPoints;
-	
-	_Swarm_Execute( self, data );
-}
-void _IntegrationPointsSwarm_Destroy( void* integrationPoints, void* data ) {
-	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*)integrationPoints;
-
-	Stg_Component_Destroy( self->localCoordVariable, data, False );
-	Stg_Component_Destroy( self->weightVariable, data, False );
-	Stg_Component_Destroy( self->mapper, data, False );
-   Stg_Component_Destroy( self->mesh, data, False );
-   Stg_Component_Destroy( self->timeIntegrator, data, False );
-   if ( self->weights != NULL ) {
-		Stg_Component_Destroy( self->weights, data, False );
-	}
-	
-	_Swarm_Destroy( self, data );
-}
-
-void _IntegrationPointsSwarm_UpdateHook( void* timeIntegrator, void* swarm ) {
-	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
-
-	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\":\n",
-		__func__, self->name );
-	Stream_IndentBranch( Swarm_Debug );
-
-	IntegrationPointsSwarm_RemapIntegrationPointsAndRecalculateWeights( self );
-
-	Stream_UnIndentBranch( Swarm_Debug );
-	Journal_DPrintf( self->debug, "...done in %s() for swarm \"%s\".\n",
-		__func__, self->name );
-}
-
-
-void IntegrationPointsSwarm_RemapIntegrationPointsAndRecalculateWeights( void* swarm ) {	
-	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
-	double                  mapStartTime, mapTime;
-	double                  weightsUpdateStartTime, weightsUpdateTime;
-
-	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\":\n",
-		__func__, self->name );
-	Stream_IndentBranch( Swarm_Debug );
-
-	Journal_DPrintf( self->debug, "Calling IntegrationPointsMapper \"%s\" (of type %s) to set up mappings\n"
-		"\tfrom I.P.s to M.P.s, and calculate local coords:\n", self->mapper->name, self->mapper->type );
-	mapStartTime = MPI_Wtime();	
-	IntegrationPointMapper_Map( self->mapper );
-	mapTime = MPI_Wtime() - mapStartTime;
-	Journal_DPrintf( self->debug, "...done - took %g secs.\n", mapTime );
-
-	if ( self->weights != NULL ) {
-		Journal_DPrintf( self->debug, "Calling WeightsCalculator \"%s\" (of type %s)\n"
-			"\tto calculate and set integration weights:\n",
-			self->weights->name, self->weights->type );
-		weightsUpdateStartTime = MPI_Wtime();
-		WeightsCalculator_CalculateAll(self->weights, self );
-		weightsUpdateTime = MPI_Wtime() - weightsUpdateStartTime;
-		Journal_DPrintf( self->debug, "...weights updating finished - took %g secs.\n", weightsUpdateTime );
-	}	
-	else {
-		Stream* errorStream = Journal_Register( Error_Type, (Name)self->type  );
-		Journal_Firewall( Stg_Class_IsInstance( self->mapper, GaussMapper_Type ) ||
-				  Stg_Class_IsInstance( self->mapper, GaussCoincidentMapper_Type ) ||
-				  !strcmp(self->mapper->type, "PCDVCGaussMapper"), errorStream,
-			"Error - in %s(): for IntegrationPointSwarm \"%s\", no weights calculator provided "
-			"and mapper is not a %s.\n", GaussMapper_Type );
-
-		Journal_DPrintf( self->debug, "not recalculating weights since we are using a %s mapper and "
-			"assume the points are not being advected.\n", GaussMapper_Type );
-	}
-
-	Stream_UnIndentBranch( Swarm_Debug );
-	Journal_DPrintf( self->debug, "...done in %s() for swarm \"%s\"\n",
-		__func__, self->name );
-}
-
-
-Material_Index IntegrationPointsSwarm_GetMaterialIndexOn( IntegrationPointsSwarm* swarm, IntegrationPoint* point ) {
-	return IntegrationPointMapper_GetMaterialIndexOn( swarm->mapper, point );
-}
-
-
-Material* IntegrationPointsSwarm_GetMaterialOn( IntegrationPointsSwarm* swarm, IntegrationPoint* point ) {
-	return Materials_Register_GetByIndex(
-		swarm->materials_Register, 
-		IntegrationPointsSwarm_GetMaterialIndexOn( swarm, point ) );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/IntegrationPointsSwarm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/IntegrationPointsSwarm.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,458 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: IntegrationPointsSwarm.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+#include "Material.h"
+#include "PICelleratorContext.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type IntegrationPointsSwarm_Type = "IntegrationPointsSwarm";
+
+IntegrationPointsSwarm* IntegrationPointsSwarm_New(
+		Name                                  name,
+      AbstractContext*                      context,
+		void*                                 cellLayout,
+		void*                                 particleLayout,
+		Dimension_Index                       dim,
+		SizeT                                 particleSize,
+		Particle_InCellIndex                  cellParticleTblDelta,
+		double                                extraParticlesFactor,
+		FeMesh*                   	      mesh,
+		TimeIntegrator*                       timeIntegrator,
+		WeightsCalculator*                    weights,
+		IntegrationPointMapper*               mapper,
+		Bool                                  recalculateWeights,
+		ExtensionManager_Register*            extensionMgr_Register,
+		Variable_Register*                    swarmVariable_Register,
+		Materials_Register*                   materials_Register,
+		MPI_Comm                              comm,
+      void*                                 ics_dummy)
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(IntegrationPointsSwarm);
+	Type                                                      type = IntegrationPointsSwarm_Type;
+	Stg_Class_DeleteFunction*                              _delete = _IntegrationPointsSwarm_Delete;
+	Stg_Class_PrintFunction*                                _print = _IntegrationPointsSwarm_Print;
+	Stg_Class_CopyFunction*                                  _copy = _IntegrationPointsSwarm_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _IntegrationPointsSwarm_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _IntegrationPointsSwarm_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _IntegrationPointsSwarm_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _IntegrationPointsSwarm_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _IntegrationPointsSwarm_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _IntegrationPointsSwarm_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 */;
+	void*                          ics = ZERO;
+
+    IntegrationPointsSwarm* self = _IntegrationPointsSwarm_New(  INTEGRATIONPOINTSSWARM_PASSARGS  );
+
+    _Swarm_Init( 
+         (Swarm*)self, context,
+         cellLayout,
+         particleLayout,
+         dim,
+         particleSize,
+         cellParticleTblDelta,
+         extraParticlesFactor,
+         extensionMgr_Register,
+         swarmVariable_Register,
+         comm, 
+         ics_dummy );
+
+   _IntegrationPointsSwarm_Init( 
+      self,
+      mesh, 
+      timeIntegrator,
+      weights,
+      mapper,
+      materials_Register,
+      recalculateWeights );
+
+	return self;
+}
+
+void* _IntegrationPointsSwarm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(IntegrationPointsSwarm);
+	Type                                                         type = IntegrationPointsSwarm_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _IntegrationPointsSwarm_Delete;
+	Stg_Class_PrintFunction*                                   _print = _IntegrationPointsSwarm_Print;
+	Stg_Class_CopyFunction*                                     _copy = _IntegrationPointsSwarm_Copy;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _IntegrationPointsSwarm_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _IntegrationPointsSwarm_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _IntegrationPointsSwarm_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _IntegrationPointsSwarm_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _IntegrationPointsSwarm_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _IntegrationPointsSwarm_Destroy;
+	SizeT                                                particleSize = sizeof(IntegrationPoint);
+
+	/* 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 */;
+	void*                          ics = ZERO;
+
+	return (void*) _IntegrationPointsSwarm_New(  INTEGRATIONPOINTSSWARM_PASSARGS  );
+}
+
+
+IntegrationPointsSwarm* _IntegrationPointsSwarm_New(  INTEGRATIONPOINTSSWARM_DEFARGS  )
+{
+	IntegrationPointsSwarm* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(IntegrationPointsSwarm) );
+	/* 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. */
+	ics = NULL;
+
+	self = (IntegrationPointsSwarm*)_Swarm_New(  SWARM_PASSARGS  );
+
+	return self;
+}
+
+
+void _IntegrationPointsSwarm_AssignFromXML( void* integrationPoints, Stg_ComponentFactory* cf, void* data ) {
+	IntegrationPointsSwarm*	        self          = (IntegrationPointsSwarm*) integrationPoints;
+	FeMesh*             		mesh;
+	TimeIntegrator*                 timeIntegrator;
+	WeightsCalculator*              weights;
+	IntegrationPointMapper*         mapper;
+	Materials_Register*             materials_Register;
+	Bool                            recalculateWeights;
+	PICelleratorContext*		context;
+
+	/* This will also call _Swarm_Init */
+	_Swarm_AssignFromXML( self, cf, data );
+
+	mesh           = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data  );
+	timeIntegrator = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TimeIntegrator", TimeIntegrator, True, data  );
+	weights        = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"WeightsCalculator", WeightsCalculator, False, data  );
+	mapper         = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"IntegrationPointMapper", IntegrationPointMapper, True, data  );
+	recalculateWeights = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"recalculateWeights", True  );
+
+	Journal_Firewall (
+			weights != NULL ||
+			(weights == NULL && (Stg_Class_IsInstance( mapper, GaussMapper_Type ) ||
+					     Stg_Class_IsInstance( mapper, GaussCoincidentMapper_Type) ||
+					     !strcmp( mapper->type, "PCDVCGaussMapper"))),
+			Journal_MyStream( Error_Type, self ),
+			"In func %s, %s which is a %s must either have a %s or use %s\n",
+			__func__,
+			self->name,
+			self->type,
+			WeightsCalculator_Type,
+			GaussMapper_Type );
+	
+	context = (PICelleratorContext*)self->context;
+	assert( Stg_CheckType( context, PICelleratorContext ) );
+	materials_Register = context->materials_Register;
+	assert( materials_Register );
+
+	_IntegrationPointsSwarm_Init( self, mesh, timeIntegrator, weights, mapper, materials_Register, recalculateWeights );
+}
+
+
+void _IntegrationPointsSwarm_Init( 
+		void*                                 swarm,
+		FeMesh*                   mesh, 
+		TimeIntegrator*                       timeIntegrator,
+		WeightsCalculator*                    weights,
+		IntegrationPointMapper*               mapper,
+		Materials_Register*                   materials_Register,
+		Bool                                  recalculateWeights )
+{
+	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
+	LocalParticle localParticle;
+	IntegrationPoint particle;
+
+	self->mesh               = mesh;
+	self->timeIntegrator     = timeIntegrator;
+	self->weights            = weights;
+	self->mapper             = mapper;
+	self->materials_Register = materials_Register;
+
+	self->recalculateWeights = recalculateWeights;
+
+	/* Disable checkpointing and reloading of IP swarms - currently they can't be reloaded if the particles
+	don't have a global coord. We assume there is no history info on them which means we're happy to re-create
+	them from scratch given the position the material points were in when the checkpoint was made as input
+	-- PatrickSunter 12 June 2006 */
+	self->isSwarmTypeToCheckPointAndReload = False;
+
+	self->weightVariable = Swarm_NewScalarVariable( self, (Name)"Weight", GetOffsetOfMember( particle , weight  ), 
+			Variable_DataType_Double );
+
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable );
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->weightVariable->variable );
+
+	self->localCoordVariable = Swarm_NewVectorVariable( self, (Name)"LocalElCoord", GetOffsetOfMember( localParticle , xi ),
+		Variable_DataType_Double,
+		self->dim,
+		"Xi",
+		"Eta",
+		"Zeta" );
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable );
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->localCoordVariable->variable );
+
+	if ( timeIntegrator ) {
+		/* Assuming this is called from _IntegrationPointsSwarm_AssignFromXML, it would have always called construct
+		 * on the mapper which in turn would have constructed any MaterialPointsSwarms with it.
+		 * The MaterialPointsSwarms would have already appended their update routines to the EP, and hence this
+		 * ensures that the _IntegrationPointsSwarm_UpdateHook will always be called last */
+		TimeIntegrator_InsertAfterFinishEP(
+				timeIntegrator,
+				"MaterialPointsSwarm_Update", /* Needs to be after a the material update */
+				"IntegrationPointsSwarm_Update",
+				(Func_Ptr)_IntegrationPointsSwarm_UpdateHook,
+				self->name,
+				self );
+	}
+	
+	/* _Construct calls _Swarm_Init */
+
+	/* Lock down the extension manager.
+	 * It doesn't make sense for the IntegrationPointsSwarm to allow IntegrationPoints to be extended
+	 * This means attempts to extend integration points are firewalled to pickup errors.
+	 * -- Alan 20060506
+	 */
+	ExtensionManager_SetLockDown( self->particleExtensionMgr, True );
+}
+
+void _IntegrationPointsSwarm_Delete( void* integrationPoints ) {
+	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)integrationPoints;
+
+	_Swarm_Delete( self );
+}
+
+
+void _IntegrationPointsSwarm_Print( void* integrationPoints, Stream* stream ) {
+	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)integrationPoints;
+	
+	_Swarm_Print( self, stream );
+}
+
+void* _IntegrationPointsSwarm_Copy( const void* integrationPoints, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*)integrationPoints;
+	IntegrationPointsSwarm*	newIntegrationPointsSwarm;
+	
+	newIntegrationPointsSwarm = (IntegrationPointsSwarm*)_Swarm_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newIntegrationPointsSwarm->mesh = (FeMesh*)Stg_Class_Copy(
+				self->mesh,
+				NULL,
+				deep,
+				nameExt,
+				ptrMap );
+	if ( self->weights != NULL ) {
+		newIntegrationPointsSwarm->weights = (WeightsCalculator*)Stg_Class_Copy(
+					self->weights,
+					NULL,
+					deep,
+					nameExt,
+					ptrMap );
+	}
+	newIntegrationPointsSwarm->mapper = (IntegrationPointMapper*)Stg_Class_Copy(
+				self->mapper,
+				NULL,
+				deep,
+				nameExt,
+				ptrMap );
+	newIntegrationPointsSwarm->materials_Register = self->materials_Register;
+	newIntegrationPointsSwarm->weightVariable = (SwarmVariable*)Stg_Class_Copy(
+				self->weightVariable,
+				NULL,
+				deep,
+				nameExt,
+				ptrMap );
+	
+	return (void*)newIntegrationPointsSwarm;
+}
+
+
+void _IntegrationPointsSwarm_Build( void* integrationPoints, void* data ) {
+	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*) integrationPoints;
+
+	_Swarm_Build( self, data );
+
+	Stg_Component_Build( self->localCoordVariable, data, False );
+	Stg_Component_Build( self->weightVariable, data, False );
+	Stg_Component_Build( self->mapper, data, False );
+   Stg_Component_Build( self->mesh, data, False );
+   Stg_Component_Build( self->timeIntegrator, data, False );
+   if ( self->weights != NULL ) {
+		Stg_Component_Build( self->weights, data, False );
+	}
+   
+}
+void _IntegrationPointsSwarm_Initialise( void* integrationPoints, void* data ) {
+	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*) integrationPoints;
+
+	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\":\n",
+		__func__, self->name );
+	Stream_IndentBranch( Swarm_Debug );
+
+	_Swarm_Initialise( self, data );
+
+	Stg_Component_Initialise( self->localCoordVariable, data, False );
+	Stg_Component_Initialise( self->weightVariable, data, False );
+	Stg_Component_Initialise( self->mapper, data, False );
+   Stg_Component_Initialise( self->mesh, data, False );
+   Stg_Component_Initialise( self->timeIntegrator, data, False );
+
+	if ( self->weights != NULL ) {
+		Stg_Component_Initialise( self->weights, data, False );
+	}
+
+	/* We call this function to actually set up the integration point positions and 
+	weights, based on the now set up material point swarm */
+	IntegrationPointsSwarm_RemapIntegrationPointsAndRecalculateWeights( self );
+
+	Stream_UnIndentBranch( Swarm_Debug );
+	Journal_DPrintf( self->debug, "...done in %s() for swarm \"%s\".\n",
+		__func__, self->name );
+}
+void _IntegrationPointsSwarm_Execute( void* integrationPoints, void* data ) {
+	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*)integrationPoints;
+	
+	_Swarm_Execute( self, data );
+}
+void _IntegrationPointsSwarm_Destroy( void* integrationPoints, void* data ) {
+	IntegrationPointsSwarm*	self = (IntegrationPointsSwarm*)integrationPoints;
+
+	Stg_Component_Destroy( self->localCoordVariable, data, False );
+	Stg_Component_Destroy( self->weightVariable, data, False );
+	Stg_Component_Destroy( self->mapper, data, False );
+   Stg_Component_Destroy( self->mesh, data, False );
+   Stg_Component_Destroy( self->timeIntegrator, data, False );
+   if ( self->weights != NULL ) {
+		Stg_Component_Destroy( self->weights, data, False );
+	}
+	
+	_Swarm_Destroy( self, data );
+}
+
+void _IntegrationPointsSwarm_UpdateHook( void* timeIntegrator, void* swarm ) {
+	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
+
+	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\":\n",
+		__func__, self->name );
+	Stream_IndentBranch( Swarm_Debug );
+
+	IntegrationPointsSwarm_RemapIntegrationPointsAndRecalculateWeights( self );
+
+	Stream_UnIndentBranch( Swarm_Debug );
+	Journal_DPrintf( self->debug, "...done in %s() for swarm \"%s\".\n",
+		__func__, self->name );
+}
+
+
+void IntegrationPointsSwarm_RemapIntegrationPointsAndRecalculateWeights( void* swarm ) {	
+	IntegrationPointsSwarm* self = (IntegrationPointsSwarm*)swarm;
+	double                  mapStartTime, mapTime;
+	double                  weightsUpdateStartTime, weightsUpdateTime;
+
+	Journal_DPrintf( self->debug, "In %s(): for swarm \"%s\":\n",
+		__func__, self->name );
+	Stream_IndentBranch( Swarm_Debug );
+
+	Journal_DPrintf( self->debug, "Calling IntegrationPointsMapper \"%s\" (of type %s) to set up mappings\n"
+		"\tfrom I.P.s to M.P.s, and calculate local coords:\n", self->mapper->name, self->mapper->type );
+	mapStartTime = MPI_Wtime();	
+	IntegrationPointMapper_Map( self->mapper );
+	mapTime = MPI_Wtime() - mapStartTime;
+	Journal_DPrintf( self->debug, "...done - took %g secs.\n", mapTime );
+
+	if ( self->weights != NULL ) {
+		Journal_DPrintf( self->debug, "Calling WeightsCalculator \"%s\" (of type %s)\n"
+			"\tto calculate and set integration weights:\n",
+			self->weights->name, self->weights->type );
+		weightsUpdateStartTime = MPI_Wtime();
+		WeightsCalculator_CalculateAll(self->weights, self );
+		weightsUpdateTime = MPI_Wtime() - weightsUpdateStartTime;
+		Journal_DPrintf( self->debug, "...weights updating finished - took %g secs.\n", weightsUpdateTime );
+	}	
+	else {
+		Stream* errorStream = Journal_Register( Error_Type, (Name)self->type  );
+		Journal_Firewall( Stg_Class_IsInstance( self->mapper, GaussMapper_Type ) ||
+				  Stg_Class_IsInstance( self->mapper, GaussCoincidentMapper_Type ) ||
+				  !strcmp(self->mapper->type, "PCDVCGaussMapper"), errorStream,
+			"Error - in %s(): for IntegrationPointSwarm \"%s\", no weights calculator provided "
+			"and mapper is not a %s.\n", GaussMapper_Type );
+
+		Journal_DPrintf( self->debug, "not recalculating weights since we are using a %s mapper and "
+			"assume the points are not being advected.\n", GaussMapper_Type );
+	}
+
+	Stream_UnIndentBranch( Swarm_Debug );
+	Journal_DPrintf( self->debug, "...done in %s() for swarm \"%s\"\n",
+		__func__, self->name );
+}
+
+
+Material_Index IntegrationPointsSwarm_GetMaterialIndexOn( IntegrationPointsSwarm* swarm, IntegrationPoint* point ) {
+	return IntegrationPointMapper_GetMaterialIndexOn( swarm->mapper, point );
+}
+
+
+Material* IntegrationPointsSwarm_GetMaterialOn( IntegrationPointsSwarm* swarm, IntegrationPoint* point ) {
+	return Materials_Register_GetByIndex(
+		swarm->materials_Register, 
+		IntegrationPointsSwarm_GetMaterialIndexOn( swarm, point ) );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/ManyToOneMapper.c
--- a/MaterialPoints/src/ManyToOneMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type ManyToOneMapper_Type = "ManyToOneMapper";
-
-ManyToOneMapper* _ManyToOneMapper_New(  MANYTOONEMAPPER_DEFARGS  ) {
-	ManyToOneMapper* result;
-
-	result = (ManyToOneMapper*)_IntegrationPointMapper_New(  INTEGRATIONPOINTMAPPER_PASSARGS  );
-
-	return result;
-}
-
-void _ManyToOneMapper_Init( void* mapper, MaterialPointsSwarm** materialSwarms, Index materialSwarmCount ) {
-	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
-	unsigned int					i;
-
-	self->materialSwarms = materialSwarms;
-	self->materialSwarmCount = materialSwarmCount;
-
-	/* Each integration point will have a reference to a material particle (one for each swarm) */
-	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, materialSwarms[i]->name, sizeof(MaterialPointRef)  );
-	}
-	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
-}
-
-void _ManyToOneMapper_Delete( void* mapper ) {
-	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
-
-	_IntegrationPointMapper_Delete( self );
-}
-
-void _ManyToOneMapper_Print( void* mapper, Stream* stream ) {
-	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
-	unsigned int					i;
-
-	_IntegrationPointMapper_Print( self, stream );
-	if ( self->materialSwarms != NULL ) {
-		Stream_Indent( stream );
-		for ( i = 0; i < self->materialSwarmCount; ++i ) {
-			Stg_Class_Print( self->materialSwarms[i], stream );
-		}
-		Stream_UnIndent( stream );
-	}
-}
-
-void* _ManyToOneMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	ManyToOneMapper* self = (ManyToOneMapper*)mapper;
-	ManyToOneMapper* newCopy;
-	
-	newCopy = (ManyToOneMapper*)_IntegrationPointMapper_Copy( self, dest, deep, nameExt, ptrMap );
-
-	if ( self->materialSwarms != NULL ) {
-          newCopy->materialSwarms = (MaterialPointsSwarm**)PtrMap_Find( ptrMap, self->materialSwarms );
-
-		if ( newCopy->materialSwarms == NULL ) {
-			newCopy->materialSwarms = Memory_Alloc_Array( MaterialPointsSwarm*, self->materialSwarmCount, "componentList" );
-			PtrMap_Append( ptrMap, self->materialSwarms, newCopy->materialSwarms );
-		}
-		newCopy->materialSwarmCount = self->materialSwarmCount;
-	}
-	else {
-		newCopy->materialSwarms = NULL;
-		newCopy->materialSwarmCount = 0;
-	}
-	return newCopy;
-}
-
-void _ManyToOneMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	ManyToOneMapper*			self = (ManyToOneMapper*)mapper;
-	MaterialPointsSwarm**	materialSwarms;
-	
-	_IntegrationPointMapper_AssignFromXML( self, cf, data );
-
-	materialSwarms = (MaterialPointsSwarm**)Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)IntegrationPointsSwarm_Type, Stg_ComponentFactory_Unlimited, IntegrationPointsSwarm, True, &(self->materialSwarmCount), data  );
-
-	Journal_Firewall( 
-		self->materialSwarmCount < 1,
-		Journal_Register( Error_Type, (Name)self->type  ),
-		"In func %s, there must be at least one swarm in the material swarm list!\n", __func__ );
-
-	_ManyToOneMapper_Init( self, materialSwarms, self->materialSwarmCount );
-}
-
-void _ManyToOneMapper_Build( void* mapper, void* data ) {
-	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
-	unsigned int					i;
-
-	_IntegrationPointMapper_Build( mapper, data );
-	
-	for ( i = 0 ; i < self->materialSwarmCount; ++i ) {
-		Stg_Component_Build( self->materialSwarms[i], data, False );
-	}
-}
-
-void _ManyToOneMapper_Initialise( void* mapper, void* data ) {
-	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
-	unsigned int					i;
-
-	_IntegrationPointMapper_Initialise( mapper, data );
-
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		Stg_Component_Initialise( self->materialSwarms[i], data, False );
-	}
-}
-
-void _ManyToOneMapper_Execute( void* mapper, void* data ) {
-}
-
-void _ManyToOneMapper_Destroy( void* mapper, void* data ) {
-	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
-	unsigned int					i;
-
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		Stg_Component_Destroy( self->materialSwarms[i], data, False );
-	}
-
-	_IntegrationPointMapper_Destroy( self, data );
-   
-}
-
-MaterialPointsSwarm** ManyToOneMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
-	ManyToOneMapper*			self = (ManyToOneMapper*)mapper;
-	MaterialPointsSwarm**	result = Memory_Alloc_Array( MaterialPointsSwarm*, self->materialSwarmCount, "Swarms" );
-	Index							i;
-	
-	*count = self->materialSwarmCount;
-
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		result[i] = self->materialSwarms[i];
-	}
-
-	return result;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/ManyToOneMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/ManyToOneMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,193 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type ManyToOneMapper_Type = "ManyToOneMapper";
+
+ManyToOneMapper* _ManyToOneMapper_New(  MANYTOONEMAPPER_DEFARGS  ) {
+	ManyToOneMapper* result;
+
+	result = (ManyToOneMapper*)_IntegrationPointMapper_New(  INTEGRATIONPOINTMAPPER_PASSARGS  );
+
+	return result;
+}
+
+void _ManyToOneMapper_Init( void* mapper, MaterialPointsSwarm** materialSwarms, Index materialSwarmCount ) {
+	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
+	unsigned int					i;
+
+	self->materialSwarms = materialSwarms;
+	self->materialSwarmCount = materialSwarmCount;
+
+	/* Each integration point will have a reference to a material particle (one for each swarm) */
+	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, materialSwarms[i]->name, sizeof(MaterialPointRef)  );
+	}
+	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
+}
+
+void _ManyToOneMapper_Delete( void* mapper ) {
+	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
+
+	_IntegrationPointMapper_Delete( self );
+}
+
+void _ManyToOneMapper_Print( void* mapper, Stream* stream ) {
+	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
+	unsigned int					i;
+
+	_IntegrationPointMapper_Print( self, stream );
+	if ( self->materialSwarms != NULL ) {
+		Stream_Indent( stream );
+		for ( i = 0; i < self->materialSwarmCount; ++i ) {
+			Stg_Class_Print( self->materialSwarms[i], stream );
+		}
+		Stream_UnIndent( stream );
+	}
+}
+
+void* _ManyToOneMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	ManyToOneMapper* self = (ManyToOneMapper*)mapper;
+	ManyToOneMapper* newCopy;
+	
+	newCopy = (ManyToOneMapper*)_IntegrationPointMapper_Copy( self, dest, deep, nameExt, ptrMap );
+
+	if ( self->materialSwarms != NULL ) {
+          newCopy->materialSwarms = (MaterialPointsSwarm**)PtrMap_Find( ptrMap, self->materialSwarms );
+
+		if ( newCopy->materialSwarms == NULL ) {
+			newCopy->materialSwarms = Memory_Alloc_Array( MaterialPointsSwarm*, self->materialSwarmCount, "componentList" );
+			PtrMap_Append( ptrMap, self->materialSwarms, newCopy->materialSwarms );
+		}
+		newCopy->materialSwarmCount = self->materialSwarmCount;
+	}
+	else {
+		newCopy->materialSwarms = NULL;
+		newCopy->materialSwarmCount = 0;
+	}
+	return newCopy;
+}
+
+void _ManyToOneMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	ManyToOneMapper*			self = (ManyToOneMapper*)mapper;
+	MaterialPointsSwarm**	materialSwarms;
+	
+	_IntegrationPointMapper_AssignFromXML( self, cf, data );
+
+	materialSwarms = (MaterialPointsSwarm**)Stg_ComponentFactory_ConstructByList( cf, self->name, (Dictionary_Entry_Key)IntegrationPointsSwarm_Type, Stg_ComponentFactory_Unlimited, IntegrationPointsSwarm, True, &(self->materialSwarmCount), data  );
+
+	Journal_Firewall( 
+		self->materialSwarmCount < 1,
+		Journal_Register( Error_Type, (Name)self->type  ),
+		"In func %s, there must be at least one swarm in the material swarm list!\n", __func__ );
+
+	_ManyToOneMapper_Init( self, materialSwarms, self->materialSwarmCount );
+}
+
+void _ManyToOneMapper_Build( void* mapper, void* data ) {
+	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
+	unsigned int					i;
+
+	_IntegrationPointMapper_Build( mapper, data );
+	
+	for ( i = 0 ; i < self->materialSwarmCount; ++i ) {
+		Stg_Component_Build( self->materialSwarms[i], data, False );
+	}
+}
+
+void _ManyToOneMapper_Initialise( void* mapper, void* data ) {
+	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
+	unsigned int					i;
+
+	_IntegrationPointMapper_Initialise( mapper, data );
+
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		Stg_Component_Initialise( self->materialSwarms[i], data, False );
+	}
+}
+
+void _ManyToOneMapper_Execute( void* mapper, void* data ) {
+}
+
+void _ManyToOneMapper_Destroy( void* mapper, void* data ) {
+	ManyToOneMapper*	self = (ManyToOneMapper*)mapper;
+	unsigned int					i;
+
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		Stg_Component_Destroy( self->materialSwarms[i], data, False );
+	}
+
+	_IntegrationPointMapper_Destroy( self, data );
+   
+}
+
+MaterialPointsSwarm** ManyToOneMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
+	ManyToOneMapper*			self = (ManyToOneMapper*)mapper;
+	MaterialPointsSwarm**	result = Memory_Alloc_Array( MaterialPointsSwarm*, self->materialSwarmCount, "Swarms" );
+	Index							i;
+	
+	*count = self->materialSwarmCount;
+
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		result[i] = self->materialSwarms[i];
+	}
+
+	return result;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MappedParticleLayout.c
--- a/MaterialPoints/src/MappedParticleLayout.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,174 +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 file may be distributed under the terms of the VPAC Public License
-** as defined by VPAC of Australia and appearing in the file
-** LICENSE.VPL included in the packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** $Id: MappedParticleLayout.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
-**
-*/
-/** \file
- **  Role:
- **      A particle layout designed for IntegrationPointsSwarms where particle positions and weights are mapped by
- **	another matieral points swarm and a weights calculator. Hence this particle layout does nothing except for
- **	creating the swarm's cell table arrays
- **
- ** Assumptions:
- **
- ** Comments:
- **
- **~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type MappedParticleLayout_Type = "MappedParticleLayout";
-
-MappedParticleLayout* MappedParticleLayout_New( 
-	Name					name, 
-	AbstractContext*	context,
-	CoordSystem			coordSystem,
-	Bool					weightsInitialisedAtStartup )
-{
-
-  MappedParticleLayout* self = (MappedParticleLayout*)_MappedParticleLayout_DefaultNew( name ); 
-
-   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
-   _MappedParticleLayout_Init( self );
-
-	return self;
-}
-MappedParticleLayout* _MappedParticleLayout_New(  MAPPEDPARTICLELAYOUT_DEFARGS  )
-{
-   MappedParticleLayout*		self;
-
-   /* Allocate memory */
-   assert( _sizeOfSelf >= sizeof(MappedParticleLayout) );
-   self = (MappedParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
-
-   return self;
-}
-
-
-void _MappedParticleLayout_Init( void* particleLayout ) {
-	MappedParticleLayout* self;
-
-	self = (MappedParticleLayout*)particleLayout;
-}
-
-void _MappedParticleLayout_Delete( void* particleLayout ) {
-    MappedParticleLayout* self = (MappedParticleLayout*)particleLayout;
-	
-    _ParticleLayout_Delete( self );
-}
-
-void _MappedParticleLayout_Print( void* particleLayout, Stream* stream ) {
-    MappedParticleLayout* self = (MappedParticleLayout*)particleLayout;
-	
-    Journal_Printf( stream, "MappedParticleLayout (ptr): %p\n", self );
-	
-    /* Parent class info */
-    _ParticleLayout_Print( self, stream );
-	
-}
-
-void* _MappedParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    MappedParticleLayout*		self = (MappedParticleLayout*)particleLayout;
-    MappedParticleLayout*		newMappedParticleLayout;
-	
-    newMappedParticleLayout = (MappedParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
-
-    return (void*)newMappedParticleLayout;
-}
-
-void* _MappedParticleLayout_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                        _sizeOfSelf = sizeof(MappedParticleLayout);
-	Type                                                                type = MappedParticleLayout_Type;
-	Stg_Class_DeleteFunction*                                        _delete = _MappedParticleLayout_Delete;
-	Stg_Class_PrintFunction*                                          _print = _MappedParticleLayout_Print;
-	Stg_Class_CopyFunction*                                            _copy = _MappedParticleLayout_Copy;
-	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = _MappedParticleLayout_DefaultNew;
-	Stg_Component_ConstructFunction*                              _construct = _MappedParticleLayout_AssignFromXML;
-	Stg_Component_BuildFunction*                                      _build = _MappedParticleLayout_Build;
-	Stg_Component_InitialiseFunction*                            _initialise = _MappedParticleLayout_Initialise;
-	Stg_Component_ExecuteFunction*                                  _execute = _MappedParticleLayout_Execute;
-	Stg_Component_DestroyFunction*                                  _destroy = _MappedParticleLayout_Destroy;
-	AllocationType                                        nameAllocationType = NON_GLOBAL;
-	ParticleLayout_SetInitialCountsFunction*               _setInitialCounts = _MappedParticleLayout_SetInitialCounts;
-	ParticleLayout_InitialiseParticlesFunction*         _initialiseParticles = _MappedParticleLayout_InitialiseParticles;
-	CoordSystem                                                  coordSystem = LocalCoordSystem;
-	Bool                                         weightsInitialisedAtStartup = False;
-
-    return _MappedParticleLayout_New(  MAPPEDPARTICLELAYOUT_PASSARGS  );
-}
-void  _MappedParticleLayout_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-    MappedParticleLayout*		self = (MappedParticleLayout*)component;
-
-    _ParticleLayout_AssignFromXML( self, cf, data );
-
-    _MappedParticleLayout_Init( self );
-}
-void  _MappedParticleLayout_Build( void* component, void* data ) {}
-void  _MappedParticleLayout_Initialise( void* component, void* data ) {}
-void  _MappedParticleLayout_Execute( void* component, void* data ) {}
-void  _MappedParticleLayout_Destroy( void* component, void* data ) {
-    MappedParticleLayout*		self = (MappedParticleLayout*)component;
-
-    _ParticleLayout_Destroy( self, data );
-}
-
-void _MappedParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
-{
-    Swarm*			swarm = (Swarm*)_swarm;
-    Cell_DomainIndex	cell_I = 0;
-    char			tempStr[100];
-
-    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; 
-        swarm->cellParticleSizeTbl[cell_I] = 1; /* Just to create array */
-
-        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;
-    }
-}
-
-void _MappedParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
-{
-    /* Don't need to do anything */
-}
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MappedParticleLayout.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/MappedParticleLayout.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,174 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This file may be distributed under the terms of the VPAC Public License
+** as defined by VPAC of Australia and appearing in the file
+** LICENSE.VPL included in the packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** $Id: MappedParticleLayout.c 3310 2005-10-26 07:10:18Z RobertTurnbull $
+**
+*/
+/** \file
+ **  Role:
+ **      A particle layout designed for IntegrationPointsSwarms where particle positions and weights are mapped by
+ **	another matieral points swarm and a weights calculator. Hence this particle layout does nothing except for
+ **	creating the swarm's cell table arrays
+ **
+ ** Assumptions:
+ **
+ ** Comments:
+ **
+ **~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type MappedParticleLayout_Type = "MappedParticleLayout";
+
+MappedParticleLayout* MappedParticleLayout_New( 
+	Name					name, 
+	AbstractContext*	context,
+	CoordSystem			coordSystem,
+	Bool					weightsInitialisedAtStartup )
+{
+
+  MappedParticleLayout* self = (MappedParticleLayout*)_MappedParticleLayout_DefaultNew( name ); 
+
+   _ParticleLayout_Init( self, context, coordSystem, weightsInitialisedAtStartup );
+   _MappedParticleLayout_Init( self );
+
+	return self;
+}
+MappedParticleLayout* _MappedParticleLayout_New(  MAPPEDPARTICLELAYOUT_DEFARGS  )
+{
+   MappedParticleLayout*		self;
+
+   /* Allocate memory */
+   assert( _sizeOfSelf >= sizeof(MappedParticleLayout) );
+   self = (MappedParticleLayout*)_ParticleLayout_New(  PARTICLELAYOUT_PASSARGS  );
+
+   return self;
+}
+
+
+void _MappedParticleLayout_Init( void* particleLayout ) {
+	MappedParticleLayout* self;
+
+	self = (MappedParticleLayout*)particleLayout;
+}
+
+void _MappedParticleLayout_Delete( void* particleLayout ) {
+    MappedParticleLayout* self = (MappedParticleLayout*)particleLayout;
+	
+    _ParticleLayout_Delete( self );
+}
+
+void _MappedParticleLayout_Print( void* particleLayout, Stream* stream ) {
+    MappedParticleLayout* self = (MappedParticleLayout*)particleLayout;
+	
+    Journal_Printf( stream, "MappedParticleLayout (ptr): %p\n", self );
+	
+    /* Parent class info */
+    _ParticleLayout_Print( self, stream );
+	
+}
+
+void* _MappedParticleLayout_Copy( const void* particleLayout, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    MappedParticleLayout*		self = (MappedParticleLayout*)particleLayout;
+    MappedParticleLayout*		newMappedParticleLayout;
+	
+    newMappedParticleLayout = (MappedParticleLayout*)_ParticleLayout_Copy( self, dest, deep, nameExt, ptrMap );
+
+    return (void*)newMappedParticleLayout;
+}
+
+void* _MappedParticleLayout_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                        _sizeOfSelf = sizeof(MappedParticleLayout);
+	Type                                                                type = MappedParticleLayout_Type;
+	Stg_Class_DeleteFunction*                                        _delete = _MappedParticleLayout_Delete;
+	Stg_Class_PrintFunction*                                          _print = _MappedParticleLayout_Print;
+	Stg_Class_CopyFunction*                                            _copy = _MappedParticleLayout_Copy;
+	Stg_Component_DefaultConstructorFunction*            _defaultConstructor = _MappedParticleLayout_DefaultNew;
+	Stg_Component_ConstructFunction*                              _construct = _MappedParticleLayout_AssignFromXML;
+	Stg_Component_BuildFunction*                                      _build = _MappedParticleLayout_Build;
+	Stg_Component_InitialiseFunction*                            _initialise = _MappedParticleLayout_Initialise;
+	Stg_Component_ExecuteFunction*                                  _execute = _MappedParticleLayout_Execute;
+	Stg_Component_DestroyFunction*                                  _destroy = _MappedParticleLayout_Destroy;
+	AllocationType                                        nameAllocationType = NON_GLOBAL;
+	ParticleLayout_SetInitialCountsFunction*               _setInitialCounts = _MappedParticleLayout_SetInitialCounts;
+	ParticleLayout_InitialiseParticlesFunction*         _initialiseParticles = _MappedParticleLayout_InitialiseParticles;
+	CoordSystem                                                  coordSystem = LocalCoordSystem;
+	Bool                                         weightsInitialisedAtStartup = False;
+
+    return _MappedParticleLayout_New(  MAPPEDPARTICLELAYOUT_PASSARGS  );
+}
+void  _MappedParticleLayout_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+    MappedParticleLayout*		self = (MappedParticleLayout*)component;
+
+    _ParticleLayout_AssignFromXML( self, cf, data );
+
+    _MappedParticleLayout_Init( self );
+}
+void  _MappedParticleLayout_Build( void* component, void* data ) {}
+void  _MappedParticleLayout_Initialise( void* component, void* data ) {}
+void  _MappedParticleLayout_Execute( void* component, void* data ) {}
+void  _MappedParticleLayout_Destroy( void* component, void* data ) {
+    MappedParticleLayout*		self = (MappedParticleLayout*)component;
+
+    _ParticleLayout_Destroy( self, data );
+}
+
+void _MappedParticleLayout_SetInitialCounts( void* particleLayout, void* _swarm )
+{
+    Swarm*			swarm = (Swarm*)_swarm;
+    Cell_DomainIndex	cell_I = 0;
+    char			tempStr[100];
+
+    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; 
+        swarm->cellParticleSizeTbl[cell_I] = 1; /* Just to create array */
+
+        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;
+    }
+}
+
+void _MappedParticleLayout_InitialiseParticles( void* particleLayout, void* _swarm )
+{
+    /* Don't need to do anything */
+}
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Material.c
--- a/MaterialPoints/src/Material.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,360 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Material.c 532 2008-02-12 01:17:48Z DavidMay $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type Material_Type = "Material";
-
-const Index UNDEFINED_MATERIAL = (unsigned)-1;
-
-/* Public Constructor */
-Material* Material_New( 
-	Name						name,
-	PICelleratorContext*	context,
-	Stg_Shape*				shape,
-	Dictionary*				materialDictionary,
-	Materials_Register*	materialRegister )
-{
-  Material* self = (Material*)_Material_DefaultNew( name );
-
-	self->isConstructed = True;
-	_Material_Init( self, context, shape, materialDictionary, materialRegister );
-
-	return self;
-}
-
-
-void* _Material_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(Material);
-	Type                                                      type = Material_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Material_Delete;
-	Stg_Class_PrintFunction*                                _print = _Material_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Material_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Material_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _Material_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Material_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Material_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Material_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Material_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*) _Material_New(  MATERIAL_PASSARGS  );
-}
-
-
-/* Private Constructor */
-Material* _Material_New(  MATERIAL_DEFARGS  )
-{
-	Material* self;
-	
-	assert( _sizeOfSelf >= sizeof(Material) );
-	/* 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 = (Material*) _Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-	return self;
-}
-
-
-void _Material_Init( 
-	void*						material,
-	PICelleratorContext*	context,
-	Stg_Shape*				shape,
-	Dictionary*				materialDictionary,
-	Materials_Register*	materialRegister )
-{
-	Material* self = (Material*)material;
-	
-	/* Set Values */
-	self->context = context;
-	self->dictionary = materialDictionary;
-	self->shape = shape;
-
-	/* Register material */
-	if (materialRegister != NULL)	
-		self->index = Materials_Register_Add( materialRegister, self );	
-	else 
-		self->index = 0;
-
-	self->extensionMgr = ExtensionManager_New_OfExistingObject( self->name, self );
-}
-
-void _Material_Delete( void* material ) {
-	Material* self = (Material*) material;
-
-   Stg_Class_Delete( self->extensionMgr );
-   
-	_Stg_Component_Delete( material );
-}
-
-
-void _Material_Print( void* material, Stream* stream ) {
-	Material* self = (Material*) material;
-
-	_Stg_Component_Print( self, stream );
-
-	Journal_PrintPointer( stream, self->dictionary );
-	Journal_PrintUnsignedInt( stream, self->index );
-}
-
-
-void* _Material_Copy( const void* material, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Material* self = (Material*) material;
-	Material* newMaterial;
-
-	newMaterial = (Material*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newMaterial->dictionary = self->dictionary;
-	newMaterial->index      = self->index;
-
-	return newMaterial;
-}
-
-
-void _Material_AssignFromXML( void* material, Stg_ComponentFactory* cf, void* data ) {
-	Material*				self = (Material*) material;
-	Dictionary*				materialDictionary;
-	Stg_Shape*				shape;
-	Materials_Register*	materials_Register;
-	PICelleratorContext*	context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
-	if( !context  ) 
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );
-
-	materialDictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	shape =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, data   ) ;
-	materials_Register = context->materials_Register;
-
-	_Material_Init( self, context, shape, materialDictionary, materials_Register );
-}
-
-
-void _Material_Build( void* material, void* data ) {
-	Material*				self = (Material*) material;
-
-   Stg_Component_Build( self->shape, data , False );
-}
-void _Material_Initialise( void* material, void* data ) {
-	Material*				self = (Material*) material;
-
-   Stg_Component_Initialise( self->shape, data , False );
-}
-void _Material_Execute( void* material, void* data ) {}
-
-void _Material_Destroy( void* material, void* data ) {
-	Material* self = (Material*) material;
-
-	Stg_Component_Destroy( self->shape, data , False );
-}
-
-
-void Material_Layout( void* material, MaterialPointsSwarm* swarm ) {	
-	Material*             self               = (Material*) material;
-	Stg_Shape*            shape              = self->shape;
-	MaterialPoint*        particle;
-	Particle_Index        lParticle_I;
-	Particle_Index        particleLocalCount = swarm->particleLocalCount;
-	Stream*               stream             = Journal_MyStream( Info_Type, self );
-
-	Journal_RPrintf( stream, "Laying out material '%s' within %s '%s':\n", self->name, shape->type, shape->name );
-	
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-		particle = (MaterialPoint*)Swarm_ParticleAt( swarm, lParticle_I );
-		
-		if ( Stg_Shape_IsCoordInside( shape, particle->coord ) ) {
-			particle->materialIndex = self->index;
-		}
-	}
-}
-
-double Material_Volume( void* material, IntegrationPointsSwarm* swarm, Coord centroid ) {
-	Material*            self               = (Material*)material;
-	FeMesh*  	     feMesh             = swarm->mesh;
-	ElementType*         elementType;
-	IntegrationPoint*    particle;
-	Coord                globalCoord;
-	Cell_Index           lCell_I;
-	Cell_Index           cellLocalCount     = swarm->cellLocalCount;
-	Particle_InCellIndex cParticle_I;
-	Particle_Index       lParticle_I;
-	Material_Index       material_I         = self->index;
-	Dimension_Index      dim                = swarm->dim;
-	Coord                localCentroid;
-	double               detJac;
-	double               volume; 
-	double               volumeGlobal;
-
-	/* Initialise Sumation of Integral */
-	volume = 0.0;	
-	memset( localCentroid, 0, sizeof(Coord) );
-
-	/* Loop over all cells in domain */
-	for ( lCell_I = 0 ; lCell_I < cellLocalCount ; lCell_I++ ) {
-		elementType = FeMesh_GetElementType( feMesh, lCell_I );
-		for( cParticle_I = 0 ; cParticle_I < swarm->cellParticleCountTbl[lCell_I] ; cParticle_I++ ) {
-			lParticle_I = swarm->cellParticleTbl[lCell_I][cParticle_I];
-			particle = (IntegrationPoint*)Swarm_ParticleAt( swarm, lParticle_I );
-
-			/* If particle isn't of the same material type as the material passed in - 
-			 * then there is no contribution to the volume */
-			if ( material_I != IntegrationPointsSwarm_GetMaterialIndexOn( swarm, particle ) )
-				continue;
-
-			/* Calculate Determinant of Jacobian */
-			detJac = ElementType_JacobianDeterminant( elementType, feMesh, lCell_I, particle->xi, dim );
-
-			/* Sum Volume */
-			volume += detJac * particle->weight;
-
-			FeMesh_CoordLocalToGlobal( feMesh, lCell_I, particle->xi, globalCoord );
-				
-			/* Sum centroid */
-			localCentroid[ I_AXIS ] += detJac * particle->weight * globalCoord[ I_AXIS ];
-			localCentroid[ J_AXIS ] += detJac * particle->weight * globalCoord[ J_AXIS ];
-			if ( dim == 3 )
-				localCentroid[ K_AXIS ] += detJac * particle->weight * globalCoord[ K_AXIS ];
-		}
-	}
-
-	/* Gather and sum volumes from other processors */
-	MPI_Allreduce( &volume, &volumeGlobal, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	MPI_Allreduce( &localCentroid, centroid, dim, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-
-	/* Divide by volume to obtain true centroid */
-	centroid[ I_AXIS ] /= volumeGlobal;
-	centroid[ J_AXIS ] /= volumeGlobal;
-	if ( dim == 3 )
-		centroid[ K_AXIS ] /= volumeGlobal;
-	else
-		centroid[ K_AXIS ] = 0.0;
-
-	return volumeGlobal;
-}
-
-
-void Material_IntegrateField( 
-		void*                   material, 
-		IntegrationPointsSwarm* swarm, 
-		FeVariable*             field, 
-		double*                 volumeGlobal, 
-		double*                 result ) 
-{
-	Material*            self               = (Material*)material;
-	FeMesh*  	     feMesh             = swarm->mesh;
-	ElementType*         elementType;
-	IntegrationPoint*    particle;
-	Cell_Index           lCell_I;
-	Cell_Index           cellLocalCount     = swarm->cellLocalCount;
-	Particle_InCellIndex cParticle_I;
-	Particle_Index       lParticle_I;
-	Material_Index       material_I         = self->index;
-	double               detJac;
-	double               volume; 
-	double*              fieldValue;
-	double*              localResult;
-	Dof_Index            fieldComponentCount = field->fieldComponentCount;
-	Dof_Index            component_I;
-	
-	/* Allocate memory */
-	fieldValue  = Memory_Alloc_Array( double, fieldComponentCount, "fieldValue" );
-	localResult = Memory_Alloc_Array( double, fieldComponentCount, "localResult" );
-
-	/* Initialise Sumation of Integral */
-	volume = 0.0;	
-	memset( localResult, 0, sizeof(double) * fieldComponentCount );
-
-	/* Loop over all cells in domain */
-	for ( lCell_I = 0 ; lCell_I < cellLocalCount ; lCell_I++ ) {
-		elementType = FeMesh_GetElementType( feMesh, lCell_I );
-		for( cParticle_I = 0 ; cParticle_I < swarm->cellParticleCountTbl[lCell_I] ; cParticle_I++ ) {
-			lParticle_I = swarm->cellParticleTbl[lCell_I][cParticle_I];
-			particle = (IntegrationPoint*) Swarm_ParticleAt( swarm, lParticle_I );
-
-			/* If particle isn't of the same material type as the material passed in - 
-			 * then there is no contribution to the volume */
-			if ( material_I != IntegrationPointsSwarm_GetMaterialIndexOn( swarm, particle ) )
-				continue;
-
-			/* Calculate Determinant of Jacobian */
-			detJac = ElementType_JacobianDeterminant( elementType, feMesh, lCell_I, particle->xi, swarm->dim );
-
-			/* Sum Volume */
-			volume += detJac * particle->weight;
-
-			/* Integrate field */ 
-			FeVariable_InterpolateWithinElement( field, lCell_I, particle->xi, fieldValue );
-			for ( component_I = 0 ; component_I < fieldComponentCount ; component_I++ ) {
-				localResult[ component_I ] += detJac * particle->weight * fieldValue[ component_I ];
-			}
-		}
-	}
-
-	/* Gather and sum volumes from other processors */
-	MPI_Allreduce( localResult, result, fieldComponentCount, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-	if ( volumeGlobal )
-		MPI_Allreduce( &volume, volumeGlobal, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
-
-	Memory_Free( fieldValue );
-	Memory_Free( localResult );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Material.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/Material.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,360 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Material.c 532 2008-02-12 01:17:48Z DavidMay $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type Material_Type = "Material";
+
+const Index UNDEFINED_MATERIAL = (unsigned)-1;
+
+/* Public Constructor */
+Material* Material_New( 
+	Name						name,
+	PICelleratorContext*	context,
+	Stg_Shape*				shape,
+	Dictionary*				materialDictionary,
+	Materials_Register*	materialRegister )
+{
+  Material* self = (Material*)_Material_DefaultNew( name );
+
+	self->isConstructed = True;
+	_Material_Init( self, context, shape, materialDictionary, materialRegister );
+
+	return self;
+}
+
+
+void* _Material_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(Material);
+	Type                                                      type = Material_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Material_Delete;
+	Stg_Class_PrintFunction*                                _print = _Material_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Material_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _Material_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _Material_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Material_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Material_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Material_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Material_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*) _Material_New(  MATERIAL_PASSARGS  );
+}
+
+
+/* Private Constructor */
+Material* _Material_New(  MATERIAL_DEFARGS  )
+{
+	Material* self;
+	
+	assert( _sizeOfSelf >= sizeof(Material) );
+	/* 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 = (Material*) _Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+	return self;
+}
+
+
+void _Material_Init( 
+	void*						material,
+	PICelleratorContext*	context,
+	Stg_Shape*				shape,
+	Dictionary*				materialDictionary,
+	Materials_Register*	materialRegister )
+{
+	Material* self = (Material*)material;
+	
+	/* Set Values */
+	self->context = context;
+	self->dictionary = materialDictionary;
+	self->shape = shape;
+
+	/* Register material */
+	if (materialRegister != NULL)	
+		self->index = Materials_Register_Add( materialRegister, self );	
+	else 
+		self->index = 0;
+
+	self->extensionMgr = ExtensionManager_New_OfExistingObject( self->name, self );
+}
+
+void _Material_Delete( void* material ) {
+	Material* self = (Material*) material;
+
+   Stg_Class_Delete( self->extensionMgr );
+   
+	_Stg_Component_Delete( material );
+}
+
+
+void _Material_Print( void* material, Stream* stream ) {
+	Material* self = (Material*) material;
+
+	_Stg_Component_Print( self, stream );
+
+	Journal_PrintPointer( stream, self->dictionary );
+	Journal_PrintUnsignedInt( stream, self->index );
+}
+
+
+void* _Material_Copy( const void* material, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Material* self = (Material*) material;
+	Material* newMaterial;
+
+	newMaterial = (Material*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newMaterial->dictionary = self->dictionary;
+	newMaterial->index      = self->index;
+
+	return newMaterial;
+}
+
+
+void _Material_AssignFromXML( void* material, Stg_ComponentFactory* cf, void* data ) {
+	Material*				self = (Material*) material;
+	Dictionary*				materialDictionary;
+	Stg_Shape*				shape;
+	Materials_Register*	materials_Register;
+	PICelleratorContext*	context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
+	if( !context  ) 
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );
+
+	materialDictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	shape =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, data   ) ;
+	materials_Register = context->materials_Register;
+
+	_Material_Init( self, context, shape, materialDictionary, materials_Register );
+}
+
+
+void _Material_Build( void* material, void* data ) {
+	Material*				self = (Material*) material;
+
+   Stg_Component_Build( self->shape, data , False );
+}
+void _Material_Initialise( void* material, void* data ) {
+	Material*				self = (Material*) material;
+
+   Stg_Component_Initialise( self->shape, data , False );
+}
+void _Material_Execute( void* material, void* data ) {}
+
+void _Material_Destroy( void* material, void* data ) {
+	Material* self = (Material*) material;
+
+	Stg_Component_Destroy( self->shape, data , False );
+}
+
+
+void Material_Layout( void* material, MaterialPointsSwarm* swarm ) {	
+	Material*             self               = (Material*) material;
+	Stg_Shape*            shape              = self->shape;
+	MaterialPoint*        particle;
+	Particle_Index        lParticle_I;
+	Particle_Index        particleLocalCount = swarm->particleLocalCount;
+	Stream*               stream             = Journal_MyStream( Info_Type, self );
+
+	Journal_RPrintf( stream, "Laying out material '%s' within %s '%s':\n", self->name, shape->type, shape->name );
+	
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+		particle = (MaterialPoint*)Swarm_ParticleAt( swarm, lParticle_I );
+		
+		if ( Stg_Shape_IsCoordInside( shape, particle->coord ) ) {
+			particle->materialIndex = self->index;
+		}
+	}
+}
+
+double Material_Volume( void* material, IntegrationPointsSwarm* swarm, Coord centroid ) {
+	Material*            self               = (Material*)material;
+	FeMesh*  	     feMesh             = swarm->mesh;
+	ElementType*         elementType;
+	IntegrationPoint*    particle;
+	Coord                globalCoord;
+	Cell_Index           lCell_I;
+	Cell_Index           cellLocalCount     = swarm->cellLocalCount;
+	Particle_InCellIndex cParticle_I;
+	Particle_Index       lParticle_I;
+	Material_Index       material_I         = self->index;
+	Dimension_Index      dim                = swarm->dim;
+	Coord                localCentroid;
+	double               detJac;
+	double               volume; 
+	double               volumeGlobal;
+
+	/* Initialise Sumation of Integral */
+	volume = 0.0;	
+	memset( localCentroid, 0, sizeof(Coord) );
+
+	/* Loop over all cells in domain */
+	for ( lCell_I = 0 ; lCell_I < cellLocalCount ; lCell_I++ ) {
+		elementType = FeMesh_GetElementType( feMesh, lCell_I );
+		for( cParticle_I = 0 ; cParticle_I < swarm->cellParticleCountTbl[lCell_I] ; cParticle_I++ ) {
+			lParticle_I = swarm->cellParticleTbl[lCell_I][cParticle_I];
+			particle = (IntegrationPoint*)Swarm_ParticleAt( swarm, lParticle_I );
+
+			/* If particle isn't of the same material type as the material passed in - 
+			 * then there is no contribution to the volume */
+			if ( material_I != IntegrationPointsSwarm_GetMaterialIndexOn( swarm, particle ) )
+				continue;
+
+			/* Calculate Determinant of Jacobian */
+			detJac = ElementType_JacobianDeterminant( elementType, feMesh, lCell_I, particle->xi, dim );
+
+			/* Sum Volume */
+			volume += detJac * particle->weight;
+
+			FeMesh_CoordLocalToGlobal( feMesh, lCell_I, particle->xi, globalCoord );
+				
+			/* Sum centroid */
+			localCentroid[ I_AXIS ] += detJac * particle->weight * globalCoord[ I_AXIS ];
+			localCentroid[ J_AXIS ] += detJac * particle->weight * globalCoord[ J_AXIS ];
+			if ( dim == 3 )
+				localCentroid[ K_AXIS ] += detJac * particle->weight * globalCoord[ K_AXIS ];
+		}
+	}
+
+	/* Gather and sum volumes from other processors */
+	MPI_Allreduce( &volume, &volumeGlobal, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	MPI_Allreduce( &localCentroid, centroid, dim, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+
+	/* Divide by volume to obtain true centroid */
+	centroid[ I_AXIS ] /= volumeGlobal;
+	centroid[ J_AXIS ] /= volumeGlobal;
+	if ( dim == 3 )
+		centroid[ K_AXIS ] /= volumeGlobal;
+	else
+		centroid[ K_AXIS ] = 0.0;
+
+	return volumeGlobal;
+}
+
+
+void Material_IntegrateField( 
+		void*                   material, 
+		IntegrationPointsSwarm* swarm, 
+		FeVariable*             field, 
+		double*                 volumeGlobal, 
+		double*                 result ) 
+{
+	Material*            self               = (Material*)material;
+	FeMesh*  	     feMesh             = swarm->mesh;
+	ElementType*         elementType;
+	IntegrationPoint*    particle;
+	Cell_Index           lCell_I;
+	Cell_Index           cellLocalCount     = swarm->cellLocalCount;
+	Particle_InCellIndex cParticle_I;
+	Particle_Index       lParticle_I;
+	Material_Index       material_I         = self->index;
+	double               detJac;
+	double               volume; 
+	double*              fieldValue;
+	double*              localResult;
+	Dof_Index            fieldComponentCount = field->fieldComponentCount;
+	Dof_Index            component_I;
+	
+	/* Allocate memory */
+	fieldValue  = Memory_Alloc_Array( double, fieldComponentCount, "fieldValue" );
+	localResult = Memory_Alloc_Array( double, fieldComponentCount, "localResult" );
+
+	/* Initialise Sumation of Integral */
+	volume = 0.0;	
+	memset( localResult, 0, sizeof(double) * fieldComponentCount );
+
+	/* Loop over all cells in domain */
+	for ( lCell_I = 0 ; lCell_I < cellLocalCount ; lCell_I++ ) {
+		elementType = FeMesh_GetElementType( feMesh, lCell_I );
+		for( cParticle_I = 0 ; cParticle_I < swarm->cellParticleCountTbl[lCell_I] ; cParticle_I++ ) {
+			lParticle_I = swarm->cellParticleTbl[lCell_I][cParticle_I];
+			particle = (IntegrationPoint*) Swarm_ParticleAt( swarm, lParticle_I );
+
+			/* If particle isn't of the same material type as the material passed in - 
+			 * then there is no contribution to the volume */
+			if ( material_I != IntegrationPointsSwarm_GetMaterialIndexOn( swarm, particle ) )
+				continue;
+
+			/* Calculate Determinant of Jacobian */
+			detJac = ElementType_JacobianDeterminant( elementType, feMesh, lCell_I, particle->xi, swarm->dim );
+
+			/* Sum Volume */
+			volume += detJac * particle->weight;
+
+			/* Integrate field */ 
+			FeVariable_InterpolateWithinElement( field, lCell_I, particle->xi, fieldValue );
+			for ( component_I = 0 ; component_I < fieldComponentCount ; component_I++ ) {
+				localResult[ component_I ] += detJac * particle->weight * fieldValue[ component_I ];
+			}
+		}
+	}
+
+	/* Gather and sum volumes from other processors */
+	MPI_Allreduce( localResult, result, fieldComponentCount, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+	if ( volumeGlobal )
+		MPI_Allreduce( &volume, volumeGlobal, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
+
+	Memory_Free( fieldValue );
+	Memory_Free( localResult );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MaterialFeVariable.c
--- a/MaterialPoints/src/MaterialFeVariable.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MaterialFeVariable.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-
-const Type MaterialFeVariable_Type = "MaterialFeVariable";
-
-MaterialFeVariable* _MaterialFeVariable_New(  MATERIALFEVARIABLE_DEFARGS  ) {
-	MaterialFeVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MaterialFeVariable) );
-	self = (MaterialFeVariable*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-	
-	return self;
-}
-
-void _MaterialFeVariable_Init( MaterialFeVariable* self, Material* material ) {
-	IntegrationPointsSwarm* swarm;
-
-	/* Assign Pointers */
-	swarm = Stg_CheckType( self->assemblyTerm->integrationSwarm, IntegrationPointsSwarm );
-	self->picIntegrationPoints = swarm;
-	self->material = material;
-}
-
-/* --- Virtual Function Implementations --- */
-void _MaterialFeVariable_Delete( void* materialFeVariable ) {
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-
-	_ParticleFeVariable_Delete( self );
-}
-
-void _MaterialFeVariable_Print( void* materialFeVariable, Stream* stream ) {
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-	
-	/* General info */
-	Journal_Printf( stream, "MaterialFeVariable (ptr): %p\n", self );
-	
-	/* Print parent */
-	_ParticleFeVariable_Print( self, stream );
-	
-	/* MaterialFeVariable info */
-	Journal_PrintPointer( stream, self->material );
-}
-
-void* _MaterialFeVariable_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	MaterialFeVariable*	self = (MaterialFeVariable*)feVariable;
-	MaterialFeVariable*	newMaterialFeVariable;
-	
-	newMaterialFeVariable = (MaterialFeVariable*) _ParticleFeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
-
-	newMaterialFeVariable->picIntegrationPoints = self->picIntegrationPoints;
-	newMaterialFeVariable->material = self->material;
-	
-	return (void*)newMaterialFeVariable;
-}
-
-void* _MaterialFeVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(MaterialFeVariable);
-	Type                                                               type = MaterialFeVariable_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _MaterialFeVariable_Delete;
-	Stg_Class_PrintFunction*                                         _print = _MaterialFeVariable_Print;
-	Stg_Class_CopyFunction*                                           _copy = _MaterialFeVariable_Copy;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _MaterialFeVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _MaterialFeVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _MaterialFeVariable_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _MaterialFeVariable_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _MaterialFeVariable_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _MaterialFeVariable_Destroy;
-	FieldVariable_InterpolateValueAtFunction*           _interpolateValueAt = _FeVariable_InterpolateValueAt;
-	FieldVariable_GetCoordFunction*                _getMinAndMaxLocalCoords = _FeVariable_GetMinAndMaxLocalCoords;
-	FieldVariable_GetCoordFunction*               _getMinAndMaxGlobalCoords = _FeVariable_GetMinAndMaxGlobalCoords;
-	FeVariable_InterpolateWithinElementFunction*  _interpolateWithinElement = _FeVariable_InterpolateNodeValuesToElLocalCoord;
-	FeVariable_GetValueAtNodeFunction*                      _getValueAtNode = _FeVariable_GetValueAtNode;
-	ParticleFeVariable_ValueAtParticleFunction*            _valueAtParticle = _MaterialFeVariable_ValueAtParticle;
-
-	/* 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;
-	FieldVariable_GetValueFunction*   _getMinGlobalFieldMagnitude = NULL;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = NULL;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = NULL;
-
-	return (void*) _MaterialFeVariable_New(  MATERIALFEVARIABLE_PASSARGS  );
-}
-
-void _MaterialFeVariable_AssignFromXML( void* materialFeVariable, Stg_ComponentFactory* cf, void* data ){
-	MaterialFeVariable*	self = (MaterialFeVariable*) materialFeVariable;
-	Material*				material;
-	
-	material = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Material", Material, True, data  );
-
-	/* Construct Parent */
-	_ParticleFeVariable_AssignFromXML( self, cf, data );
-
-	_MaterialFeVariable_Init( self, material );
-}
-
-void _MaterialFeVariable_Build( void* materialFeVariable, void* data ) {
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-	IntegrationPointsSwarm* swarm;
-	char *tmpName;
-	Variable_Register* variable_Register = NULL;
-
-	Stg_Component_Build( self->feMesh, data, False );
-
-	/* Create Dof Layout */
-	swarm = self->picIntegrationPoints;
-	if ( swarm->swarmVariable_Register )
-		variable_Register = swarm->swarmVariable_Register->variable_Register;
-
-	tmpName = Stg_Object_AppendSuffix( self, "DataVariable"  );
-	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-	self->dataVariable = Variable_NewScalar( 
-		tmpName,
-		(AbstractContext*)self->context,
-		Variable_DataType_Double, 
-		(Index*)(&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains),
-		NULL,
-		(void**)&self->data, 
-		variable_Register );
-	Memory_Free( tmpName );
-	self->fieldComponentCount = 1;
-	
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
-	self->dofLayout = DofLayout_New( tmpName, self->context, variable_Register, ((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains, NULL );
-	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
-	Memory_Free( tmpName );
-	self->eqNum->dofLayout = self->dofLayout;
-	
-	_ParticleFeVariable_Build( self, data );
-}
-
-void _MaterialFeVariable_Initialise( void* materialFeVariable, void* data ) {
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-
-	_ParticleFeVariable_Initialise( self, data );
-}
-
-void _MaterialFeVariable_Execute( void* materialFeVariable, void* data ) {
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-
-	_ParticleFeVariable_Execute( self, data );
-}
-
-void _MaterialFeVariable_Destroy( void* materialFeVariable, void* data ) {
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-
-	_ParticleFeVariable_Destroy( self, data );
-}
-
-void _MaterialFeVariable_ValueAtParticle( 
-	void*                   materialFeVariable,
-	IntegrationPointsSwarm* swarm,
-	Element_LocalIndex      lElement_I,
-	void*                   particle,
-	double*                 particleValue )
-{
-	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
-	*particleValue = (double) ( self->material->index == IntegrationPointsSwarm_GetMaterialIndexOn( swarm, (IntegrationPoint*)particle ) );
-}
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MaterialFeVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/MaterialFeVariable.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,216 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MaterialFeVariable.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+
+const Type MaterialFeVariable_Type = "MaterialFeVariable";
+
+MaterialFeVariable* _MaterialFeVariable_New(  MATERIALFEVARIABLE_DEFARGS  ) {
+	MaterialFeVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MaterialFeVariable) );
+	self = (MaterialFeVariable*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+	
+	return self;
+}
+
+void _MaterialFeVariable_Init( MaterialFeVariable* self, Material* material ) {
+	IntegrationPointsSwarm* swarm;
+
+	/* Assign Pointers */
+	swarm = Stg_CheckType( self->assemblyTerm->integrationSwarm, IntegrationPointsSwarm );
+	self->picIntegrationPoints = swarm;
+	self->material = material;
+}
+
+/* --- Virtual Function Implementations --- */
+void _MaterialFeVariable_Delete( void* materialFeVariable ) {
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+
+	_ParticleFeVariable_Delete( self );
+}
+
+void _MaterialFeVariable_Print( void* materialFeVariable, Stream* stream ) {
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+	
+	/* General info */
+	Journal_Printf( stream, "MaterialFeVariable (ptr): %p\n", self );
+	
+	/* Print parent */
+	_ParticleFeVariable_Print( self, stream );
+	
+	/* MaterialFeVariable info */
+	Journal_PrintPointer( stream, self->material );
+}
+
+void* _MaterialFeVariable_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	MaterialFeVariable*	self = (MaterialFeVariable*)feVariable;
+	MaterialFeVariable*	newMaterialFeVariable;
+	
+	newMaterialFeVariable = (MaterialFeVariable*) _ParticleFeVariable_Copy( feVariable, dest, deep, nameExt, ptrMap );
+
+	newMaterialFeVariable->picIntegrationPoints = self->picIntegrationPoints;
+	newMaterialFeVariable->material = self->material;
+	
+	return (void*)newMaterialFeVariable;
+}
+
+void* _MaterialFeVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(MaterialFeVariable);
+	Type                                                               type = MaterialFeVariable_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _MaterialFeVariable_Delete;
+	Stg_Class_PrintFunction*                                         _print = _MaterialFeVariable_Print;
+	Stg_Class_CopyFunction*                                           _copy = _MaterialFeVariable_Copy;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _MaterialFeVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _MaterialFeVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _MaterialFeVariable_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _MaterialFeVariable_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _MaterialFeVariable_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _MaterialFeVariable_Destroy;
+	FieldVariable_InterpolateValueAtFunction*           _interpolateValueAt = _FeVariable_InterpolateValueAt;
+	FieldVariable_GetCoordFunction*                _getMinAndMaxLocalCoords = _FeVariable_GetMinAndMaxLocalCoords;
+	FieldVariable_GetCoordFunction*               _getMinAndMaxGlobalCoords = _FeVariable_GetMinAndMaxGlobalCoords;
+	FeVariable_InterpolateWithinElementFunction*  _interpolateWithinElement = _FeVariable_InterpolateNodeValuesToElLocalCoord;
+	FeVariable_GetValueAtNodeFunction*                      _getValueAtNode = _FeVariable_GetValueAtNode;
+	ParticleFeVariable_ValueAtParticleFunction*            _valueAtParticle = _MaterialFeVariable_ValueAtParticle;
+
+	/* 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;
+	FieldVariable_GetValueFunction*   _getMinGlobalFieldMagnitude = NULL;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = NULL;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = NULL;
+
+	return (void*) _MaterialFeVariable_New(  MATERIALFEVARIABLE_PASSARGS  );
+}
+
+void _MaterialFeVariable_AssignFromXML( void* materialFeVariable, Stg_ComponentFactory* cf, void* data ){
+	MaterialFeVariable*	self = (MaterialFeVariable*) materialFeVariable;
+	Material*				material;
+	
+	material = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Material", Material, True, data  );
+
+	/* Construct Parent */
+	_ParticleFeVariable_AssignFromXML( self, cf, data );
+
+	_MaterialFeVariable_Init( self, material );
+}
+
+void _MaterialFeVariable_Build( void* materialFeVariable, void* data ) {
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+	IntegrationPointsSwarm* swarm;
+	char *tmpName;
+	Variable_Register* variable_Register = NULL;
+
+	Stg_Component_Build( self->feMesh, data, False );
+
+	/* Create Dof Layout */
+	swarm = self->picIntegrationPoints;
+	if ( swarm->swarmVariable_Register )
+		variable_Register = swarm->swarmVariable_Register->variable_Register;
+
+	tmpName = Stg_Object_AppendSuffix( self, "DataVariable"  );
+	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+	self->dataVariable = Variable_NewScalar( 
+		tmpName,
+		(AbstractContext*)self->context,
+		Variable_DataType_Double, 
+		(Index*)(&((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains),
+		NULL,
+		(void**)&self->data, 
+		variable_Register );
+	Memory_Free( tmpName );
+	self->fieldComponentCount = 1;
+	
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
+	self->dofLayout = DofLayout_New( tmpName, self->context, variable_Register, ((IGraph*)self->feMesh->topo)->remotes[MT_VERTEX]->nDomains, NULL );
+	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
+	Memory_Free( tmpName );
+	self->eqNum->dofLayout = self->dofLayout;
+	
+	_ParticleFeVariable_Build( self, data );
+}
+
+void _MaterialFeVariable_Initialise( void* materialFeVariable, void* data ) {
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+
+	_ParticleFeVariable_Initialise( self, data );
+}
+
+void _MaterialFeVariable_Execute( void* materialFeVariable, void* data ) {
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+
+	_ParticleFeVariable_Execute( self, data );
+}
+
+void _MaterialFeVariable_Destroy( void* materialFeVariable, void* data ) {
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+
+	_ParticleFeVariable_Destroy( self, data );
+}
+
+void _MaterialFeVariable_ValueAtParticle( 
+	void*                   materialFeVariable,
+	IntegrationPointsSwarm* swarm,
+	Element_LocalIndex      lElement_I,
+	void*                   particle,
+	double*                 particleValue )
+{
+	MaterialFeVariable* self = (MaterialFeVariable*) materialFeVariable;
+	*particleValue = (double) ( self->material->index == IntegrationPointsSwarm_GetMaterialIndexOn( swarm, (IntegrationPoint*)particle ) );
+}
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MaterialPoint.c
--- a/MaterialPoints/src/MaterialPoint.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "MaterialPoint.h"
-
-const Type MaterialPoint_Type = "MaterialPoint";
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MaterialPoint.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/MaterialPoint.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,58 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "MaterialPoint.h"
+
+const Type MaterialPoint_Type = "MaterialPoint";
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MaterialPointsSwarm.c
--- a/MaterialPoints/src/MaterialPointsSwarm.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,544 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-#include "MaterialPointsSwarm.h"
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type MaterialPointsSwarm_Type = "MaterialPointsSwarm";
-
-MaterialPointsSwarm* MaterialPointsSwarm_New(
-      Name                                 name,
-      AbstractContext*                      context,
-      void*                                 cellLayout,
-      void*                                 particleLayout,
-      Dimension_Index                       dim,
-      SizeT                                 particleSize,
-      FeMesh*                               mesh,
-      EscapedRoutine*                       escapedRoutine, 
-      Material*                             material,
-      Variable_Register*                    swarmVariable_Register,
-      ExtensionManager_Register*            extensionMgr_Register,
-      Materials_Register*                   materials_Register,		
-      MPI_Comm                              comm,
-      void*                                 ics_dummy ) 
-{
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(MaterialPointsSwarm);
-	Type                                                      type = MaterialPointsSwarm_Type;
-	Stg_Class_DeleteFunction*                              _delete = _MaterialPointsSwarm_Delete;
-	Stg_Class_PrintFunction*                                _print = _MaterialPointsSwarm_Print;
-	Stg_Class_CopyFunction*                                  _copy = _MaterialPointsSwarm_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _MaterialPointsSwarm_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _MaterialPointsSwarm_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _MaterialPointsSwarm_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _MaterialPointsSwarm_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _MaterialPointsSwarm_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _MaterialPointsSwarm_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 */;
-	void*                          ics = ZERO;
-
-	/* 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 */
-	Particle_InCellIndex  cellParticleTblDelta = DEFAULT_CELL_PARTICLE_TBL_DELTA;
-	double                extraParticlesFactor = DEFAULT_EXTRA_PARTICLES_FACTOR;
-
-  MaterialPointsSwarm* self = _MaterialPointsSwarm_New(  MATERIALPOINTSSWARM_PASSARGS  );
-
-   _Swarm_Init( 
-         (Swarm*)self, context,
-         cellLayout,
-         particleLayout,
-         dim,
-         particleSize,
-         cellParticleTblDelta,
-         extraParticlesFactor,
-         extensionMgr_Register,
-         swarmVariable_Register,
-         comm, 
-         ics_dummy );
-
-   _MaterialPointsSwarm_Init( 
-      self, 
-      mesh,
-      escapedRoutine, 
-      material,
-      materials_Register );
-
-   return self;
-}
-
-
-MaterialPointsSwarm* _MaterialPointsSwarm_New(  MATERIALPOINTSSWARM_DEFARGS  )
-{
-	MaterialPointsSwarm* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MaterialPointsSwarm) );
-	/* 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. */
-	ics = NULL;
-
-	self = (MaterialPointsSwarm*)_Swarm_New(  SWARM_PASSARGS  );
-
-	return self;
-}
-
-
-void _MaterialPointsSwarm_Init( 
-		void*                                 swarm,
-		FeMesh*                               mesh,
-		EscapedRoutine*                       escapedRoutine, 
-		Material*                             material,
-		Materials_Register*                   materials_Register )
-{
-	MaterialPointsSwarm*    self = (MaterialPointsSwarm*)swarm;
-	MaterialPoint           particle;
-	GlobalParticle          globalParticle;
-
-	self->mesh               = mesh;
-	self->swarmAdvector      = NULL;		/* If we're using a SwarmAdvector, it will 'attach' itself later on. */
-	self->escapedRoutine     = escapedRoutine;
-	self->material           = material;
-	self->materials_Register = materials_Register;
-	
-	self->particleCoordVariable = Swarm_NewVectorVariable( self, (Name)"Position", GetOffsetOfMember( globalParticle, coord ),
-		Variable_DataType_Double,
-		self->dim,
-		"PositionX",
-		"PositionY",
-		"PositionZ" );
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleCoordVariable->variable );
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleCoordVariable );
-
-	self->materialIndexVariable = Swarm_NewScalarVariable( self, (Name)"MaterialIndex", GetOffsetOfMember( particle , materialIndex  ), Variable_DataType_Int ); /* Should be unsigned int */
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->materialIndexVariable->variable );
-   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->materialIndexVariable );
-
-	/* If we have an escaped routine, clear the defensive flag. */
-#if 0
-	if( self->escapedRoutine )
-		self->particleCommunicationHandler->defensive = False;
-#endif
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _MaterialPointsSwarm_Delete( void* swarm ) {
-	MaterialPointsSwarm* self = (MaterialPointsSwarm*)swarm;
-
-	_Swarm_Delete( self );
-}
-
-
-void _MaterialPointsSwarm_Print( void* swarm, Stream* stream ) {
-	MaterialPointsSwarm* self = (MaterialPointsSwarm*)swarm;
-	
-	_Swarm_Print( self, stream );
-}
-
-void* _MaterialPointsSwarm_Copy( const void* swarm, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	MaterialPointsSwarm*	self = (MaterialPointsSwarm*)swarm;
-	MaterialPointsSwarm*	newMaterialPointsSwarm;
-	
-	newMaterialPointsSwarm = (MaterialPointsSwarm*)_Swarm_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newMaterialPointsSwarm->materialIndexVariable = (SwarmVariable*)Stg_Class_Copy(
-				self->materialIndexVariable,
-				NULL,
-				deep,
-				nameExt,
-				ptrMap );
-	
-	return (void*)newMaterialPointsSwarm;
-}
-
-void* _MaterialPointsSwarm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(MaterialPointsSwarm);
-	Type                                                         type = MaterialPointsSwarm_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _MaterialPointsSwarm_Delete;
-	Stg_Class_PrintFunction*                                   _print = _MaterialPointsSwarm_Print;
-	Stg_Class_CopyFunction*                                     _copy = _MaterialPointsSwarm_Copy;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _MaterialPointsSwarm_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _MaterialPointsSwarm_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _MaterialPointsSwarm_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _MaterialPointsSwarm_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _MaterialPointsSwarm_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _MaterialPointsSwarm_Destroy;
-	SizeT                                                particleSize = sizeof(MaterialPoint);
-
-	/* 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 */;
-	void*                          ics = ZERO;
-
-	return _MaterialPointsSwarm_New(  MATERIALPOINTSSWARM_PASSARGS  );
-}
-
-
-void _MaterialPointsSwarm_AssignFromXML( void* swarm, Stg_ComponentFactory* cf, void* data ) {
-	MaterialPointsSwarm*	        self          = (MaterialPointsSwarm*) swarm;
-	FeMesh*             		mesh;
-	EscapedRoutine*                 escapedRoutine;
-	Material*                       material;
-	Materials_Register*             materials_Register;
-	PICelleratorContext*		context;
-
-	_Swarm_AssignFromXML( self, cf, data );
-
-	mesh             = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data  );
-	escapedRoutine   = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"EscapedRoutine", EscapedRoutine, False, data  );
-	material         = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Material", Material, False, data );
-
-	context = (PICelleratorContext* )self->context;
-	assert( Stg_CheckType( context, PICelleratorContext ) );
-	materials_Register = context->materials_Register; 
-	assert( materials_Register );
-
-	_MaterialPointsSwarm_Init(
-			self,
-			mesh, 
-			escapedRoutine,
-			material,
-			materials_Register );
-
-	self->geomodHack = Dictionary_GetBool_WithDefault( cf->rootDict, (Dictionary_Entry_Key)"geomodHacks", False  );
-}
-
-void _MaterialPointsSwarm_Build( void* swarm, void* data ) {
-	MaterialPointsSwarm*	self = (MaterialPointsSwarm*) swarm;
-	unsigned int			commHandler_I;
-	Bool                    movementCommHandlerFound = False;
-	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
-	Index var_I;
-
-	_Swarm_Build( self, data );
-
-	Stg_Component_Build( self->mesh, data , False );
-	if( self->escapedRoutine != NULL) Stg_Component_Build( self->escapedRoutine, data , False );
-	if( self->material       != NULL) Stg_Component_Build( self->material,       data , False );
-
-	/* Since this swarm is being set up to advect a PICellerator material, it should make sure
-	 * at least one ParticleMovementHandler-type ParticleCommHandler has been added to the base
-	 * Swarm. */
-	for( commHandler_I=0; commHandler_I < self->commHandlerList->count; commHandler_I++ ){
-		ParticleCommHandler *pComm = NULL;
-
-		pComm = (ParticleCommHandler*)(Stg_ObjectList_At( self->commHandlerList, commHandler_I ));
-		if( pComm->type == ParticleMovementHandler_Type ) {
-			movementCommHandlerFound = True;
-			break;
-		}
-	}
-
-	Journal_Firewall( (Stg_ObjectList_Count(self->commHandlerList) >= 1) && (movementCommHandlerFound == True),
-		errorStream, "Error: for MaterialPointsSwarm Swarms, at least one ParticleMovementHandler"
-			" commHandler must be registered. Please rectify this in your XML / code.\n" );
-
-	for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ ) {
-		Stg_Component_Build( self->swarmVars[var_I], data , False );
-	}
-}
-void _MaterialPointsSwarm_Initialise( void* swarm, void* data ) {
-	MaterialPointsSwarm*	self 	= (MaterialPointsSwarm*) swarm;
-	AbstractContext* 	context = (AbstractContext*)self->context;
-	Index            var_I	= 0;
-	Particle_Index          lParticle_I=0;
-	MaterialPoint*		matPoint=NULL;
-
-	_Swarm_Initialise( self, data );
-
-	Stg_Component_Initialise( self->mesh, data , False );
-	if( self->escapedRoutine != NULL) Stg_Component_Initialise( self->escapedRoutine, data , False );
-	if( self->material       != NULL) Stg_Component_Initialise( self->material,       data , False );
-
-	for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ ) {
-		Stg_Component_Initialise( self->swarmVars[var_I], data , False );
-	}
-
-	/* Now setup the material properties */
-   if(  False == context->loadFromCheckPoint ) {
-
-      /* Beforehand, set each particle to have UNDEFINED_MATERIAL */
-      for ( lParticle_I = 0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
-         matPoint = (MaterialPoint*)Swarm_ParticleAt( self, lParticle_I );
-         matPoint->materialIndex = UNDEFINED_MATERIAL;
-      }
-		if( self->material == NULL ) {
-			/* Do it by the layout of all known materials */
-			Materials_Register_SetupSwarm( self->materials_Register, self );
-		}
-		else {
-			Material_Layout( self->material, self );
-			Materials_Register_AssignParticleProperties( 
-					self->materials_Register, 
-					self, 
-					self->swarmVariable_Register->variable_Register );
-		}
-	}
-
-	/** if loading from checkpoint, particle materials etc have already been loaded in Swarm_Build() - */ 
-	/** possibly need to check for empty cells (and populate) if performing a interpolation restart */
-   if ( True == context->loadFromCheckPoint ){
-      if ( (True == self->isSwarmTypeToCheckPointAndReload) && (True == context->interpolateRestart) ) {	   
-         Particle_InCellIndex cParticle_I         = 0;
-         Particle_InCellIndex particle_I          = 0;
-         GlobalParticle*      particle            = NULL;
-         double               minDistance         = HUGE_VAL;
-         double               distanceToParticle;
-         Dimension_Index      dim = self->dim;
-         Cell_DomainIndex     dCell_I;
-         Cell_LocalIndex      lCell_I;
-         Cell_DomainIndex     belongsToCell_I = 0;
-         MaterialPoint*       matNewParticle;
-         MaterialPoint*       matParticleToSplit;
-         Particle_Index       matNewParticle_IndexOnCPU;
-         Coord                xi;
-         Coord                coord;
-         unsigned             nEmptyCells = 0;
-         Index*				   cellID = NULL;
-         Index*				   particleCPUID = NULL;
-         unsigned             count;
-         unsigned             ii;
-         
-         /** first determine how many local cells are empty */
-         for( lCell_I = 0 ; lCell_I < self->cellLocalCount ; lCell_I++ )
-            if (self->cellParticleCountTbl[lCell_I] == 0) nEmptyCells++;
-
-         /** create arrays which will be later used to populate cells */
-         cellID        = Memory_Alloc_Array( Index, nEmptyCells, "Cell ID for cell to be populated" );
-         particleCPUID = Memory_Alloc_Array( Index, nEmptyCells, "particle ID for particle to populate cell" );
-
-         count = 0;
-         for( lCell_I = 0 ; lCell_I < self->cellLocalCount ; lCell_I++ ) {
-            minDistance = HUGE_VAL;
-            if (self->cellParticleCountTbl[lCell_I] == 0) {
-               /** select the centre of the current cell */
-               xi[0] = 0;  xi[1] = 0;  xi[2] = 0;
-               /** get global coord */
-               FeMesh_CoordLocalToGlobal( self->mesh, lCell_I, xi, coord );
-      
-               for( dCell_I = 0 ; dCell_I < self->cellDomainCount ; dCell_I++ ) {
-                  /** Loop over particles find closest to cell centre */
-                  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;
-                        belongsToCell_I  = dCell_I;
-                     }
-                  }
-               }
-
-               /** create new particle which will be placed at centre of empty cell */
-               matNewParticle      = (MaterialPoint*) Swarm_CreateNewParticle( self, &matNewParticle_IndexOnCPU );
-               /** grab closest particle, which we will copy */
-               matParticleToSplit  = (MaterialPoint*) Swarm_ParticleInCellAt( self, belongsToCell_I, particle_I );
-               /** copy */
-               memcpy( matNewParticle, matParticleToSplit, self->particleExtensionMgr->finalSize );
-               /** set the owningCell to the cellDomainCount so that its owningCell will be reinitialised (not sure if necessary) */ 
-               matNewParticle->owningCell = self->cellDomainCount;
-               /** Copy new global position (cell centre) to coord on new mat particle */
-               memcpy( matNewParticle->coord, coord, sizeof(Coord) );
-               
-               /** we now store the required information to populate empty cells */
-               /** note that cells are not populated at this point, as this may interfere
-                   with the 0th order interpolation we are performing */ 
-               cellID[count]        = lCell_I;
-               particleCPUID[count] = matNewParticle_IndexOnCPU;
-               count++;
-      
-            }
-         }
-         /** populate empty cells */ 
-         for(ii = 0 ; ii < count ; ii++)
-            Swarm_AddParticleToCell( self, cellID[ii], particleCPUID[ii] );
-         Memory_Free( cellID );
-         Memory_Free( particleCPUID );
-      }
-	/* TODO: print info / debug message */
-   }
-}
-void _MaterialPointsSwarm_Execute( void* swarm, void* data ) {
-	MaterialPointsSwarm*	self = (MaterialPointsSwarm*)swarm;
-	
-	_Swarm_Execute( self, data );
-}
-void _MaterialPointsSwarm_Destroy( void* swarm, void* data ) {
-	MaterialPointsSwarm*	self = (MaterialPointsSwarm*)swarm;
-   Index var_I;
-	
-	Stg_Component_Destroy( self->mesh, data , False );
-	if( self->escapedRoutine != NULL) Stg_Component_Destroy( self->escapedRoutine, data , False );
-	if( self->material       != NULL) Stg_Component_Destroy( self->material,       data , False );
-
-	for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ ) {
-		Stg_Component_Destroy( self->swarmVars[var_I], data , False );
-	}
-
-	_Swarm_Destroy( self, data );
-}
-
-void _MaterialPointsSwarm_UpdateHook( void* timeIntegrator, void* swarm ) {
-	MaterialPointsSwarm* self               = (MaterialPointsSwarm*)swarm;
-	FeMesh*  mesh               = self->mesh;
-	Index                cell;
-	Index                point_I;
-	MaterialPoint*       materialPoint;
-
-	/* Need to check for escaped particles before the next block. */
-	if ( self->escapedRoutine ) {
-		Stg_Component_Execute( self->escapedRoutine, self, True );
-	}
-
-	/* Check that particles have not exited the box after advection */
-	if ( self->swarmAdvector  ) {
-		for ( point_I = 0; point_I < self->particleLocalCount; ++point_I ) {
-			materialPoint = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
-			cell = materialPoint->owningCell;
-			Journal_Firewall(
-					 cell < FeMesh_GetElementDomainSize( mesh ), 
-				Journal_MyStream( Error_Type, self ),
-				"In func %s: MaterialPoint '%d' outside element. Coord = {%g, %g, %g}\n",
-				__func__,
-				point_I,
-				materialPoint->coord[ I_AXIS ],
-				materialPoint->coord[ J_AXIS ],
-				materialPoint->coord[ K_AXIS ] );
-		}
-	}
-
-}
-
-void MaterialPointsSwarm_SetMaterialAt( void* swarm, Index point_I, Index materialIndex ) {
-	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
-	MaterialPoint*       point;
-
-	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
-	point->materialIndex = materialIndex;
-}
-
-
-Material* MaterialPointsSwarm_GetMaterialOn( void* swarm, void* particle ) {
-	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
-	MaterialPoint*       materialPoint = (MaterialPoint*)particle;
-
-	return Materials_Register_GetByIndex( self->materials_Register, materialPoint->materialIndex );
-}
-
-
-Material* MaterialPointsSwarm_GetMaterialAt( void* swarm, Index point_I ) {
-	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
-	MaterialPoint*       point;
-
-	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
-	return Materials_Register_GetByIndex( self->materials_Register, point->materialIndex );
-}
-
-Index MaterialPointsSwarm_GetMaterialIndexAt( void* swarm, Index point_I ) {
-	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
-	MaterialPoint*       point;
-
-	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
-	return point->materialIndex;
-}
-
-void* MaterialPointsSwarm_GetMaterialExtensionOn( void* swarm, void *matPoint, Index extHandle ) {
-	MaterialPointsSwarm *self  = (MaterialPointsSwarm*)swarm;
-	Material *mat;
-
-	mat = MaterialPointsSwarm_GetMaterialOn(self, matPoint);
-	return ExtensionManager_Get(mat->extensionMgr, mat, extHandle);
-}
-
-void* MaterialPointsSwarm_GetMaterialExtensionAt( void* swarm, int matPointInd, Index extHandle ) {
-	MaterialPointsSwarm *self  = (MaterialPointsSwarm*)swarm;
-	Material *mat;
-
-	mat = MaterialPointsSwarm_GetMaterialAt(self, matPointInd);
-	return ExtensionManager_Get(mat->extensionMgr, mat, extHandle);
-}
-
-void* MaterialPointsSwarm_GetExtensionAt( void* swarm, Index point_I, Index extHandle ) {
-	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
-	MaterialPoint*       point;
-
-	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
-	return ExtensionManager_Get( self->particleExtensionMgr, point, extHandle );
-	
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/MaterialPointsSwarm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/MaterialPointsSwarm.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,544 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+#include "MaterialPointsSwarm.h"
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type MaterialPointsSwarm_Type = "MaterialPointsSwarm";
+
+MaterialPointsSwarm* MaterialPointsSwarm_New(
+      Name                                 name,
+      AbstractContext*                      context,
+      void*                                 cellLayout,
+      void*                                 particleLayout,
+      Dimension_Index                       dim,
+      SizeT                                 particleSize,
+      FeMesh*                               mesh,
+      EscapedRoutine*                       escapedRoutine, 
+      Material*                             material,
+      Variable_Register*                    swarmVariable_Register,
+      ExtensionManager_Register*            extensionMgr_Register,
+      Materials_Register*                   materials_Register,		
+      MPI_Comm                              comm,
+      void*                                 ics_dummy ) 
+{
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(MaterialPointsSwarm);
+	Type                                                      type = MaterialPointsSwarm_Type;
+	Stg_Class_DeleteFunction*                              _delete = _MaterialPointsSwarm_Delete;
+	Stg_Class_PrintFunction*                                _print = _MaterialPointsSwarm_Print;
+	Stg_Class_CopyFunction*                                  _copy = _MaterialPointsSwarm_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _MaterialPointsSwarm_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _MaterialPointsSwarm_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _MaterialPointsSwarm_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _MaterialPointsSwarm_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _MaterialPointsSwarm_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _MaterialPointsSwarm_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 */;
+	void*                          ics = ZERO;
+
+	/* 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 */
+	Particle_InCellIndex  cellParticleTblDelta = DEFAULT_CELL_PARTICLE_TBL_DELTA;
+	double                extraParticlesFactor = DEFAULT_EXTRA_PARTICLES_FACTOR;
+
+  MaterialPointsSwarm* self = _MaterialPointsSwarm_New(  MATERIALPOINTSSWARM_PASSARGS  );
+
+   _Swarm_Init( 
+         (Swarm*)self, context,
+         cellLayout,
+         particleLayout,
+         dim,
+         particleSize,
+         cellParticleTblDelta,
+         extraParticlesFactor,
+         extensionMgr_Register,
+         swarmVariable_Register,
+         comm, 
+         ics_dummy );
+
+   _MaterialPointsSwarm_Init( 
+      self, 
+      mesh,
+      escapedRoutine, 
+      material,
+      materials_Register );
+
+   return self;
+}
+
+
+MaterialPointsSwarm* _MaterialPointsSwarm_New(  MATERIALPOINTSSWARM_DEFARGS  )
+{
+	MaterialPointsSwarm* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MaterialPointsSwarm) );
+	/* 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. */
+	ics = NULL;
+
+	self = (MaterialPointsSwarm*)_Swarm_New(  SWARM_PASSARGS  );
+
+	return self;
+}
+
+
+void _MaterialPointsSwarm_Init( 
+		void*                                 swarm,
+		FeMesh*                               mesh,
+		EscapedRoutine*                       escapedRoutine, 
+		Material*                             material,
+		Materials_Register*                   materials_Register )
+{
+	MaterialPointsSwarm*    self = (MaterialPointsSwarm*)swarm;
+	MaterialPoint           particle;
+	GlobalParticle          globalParticle;
+
+	self->mesh               = mesh;
+	self->swarmAdvector      = NULL;		/* If we're using a SwarmAdvector, it will 'attach' itself later on. */
+	self->escapedRoutine     = escapedRoutine;
+	self->material           = material;
+	self->materials_Register = materials_Register;
+	
+	self->particleCoordVariable = Swarm_NewVectorVariable( self, (Name)"Position", GetOffsetOfMember( globalParticle, coord ),
+		Variable_DataType_Double,
+		self->dim,
+		"PositionX",
+		"PositionY",
+		"PositionZ" );
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleCoordVariable->variable );
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->particleCoordVariable );
+
+	self->materialIndexVariable = Swarm_NewScalarVariable( self, (Name)"MaterialIndex", GetOffsetOfMember( particle , materialIndex  ), Variable_DataType_Int ); /* Should be unsigned int */
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->materialIndexVariable->variable );
+   LiveComponentRegister_Add( LiveComponentRegister_GetLiveComponentRegister(), (Stg_Component*)self->materialIndexVariable );
+
+	/* If we have an escaped routine, clear the defensive flag. */
+#if 0
+	if( self->escapedRoutine )
+		self->particleCommunicationHandler->defensive = False;
+#endif
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _MaterialPointsSwarm_Delete( void* swarm ) {
+	MaterialPointsSwarm* self = (MaterialPointsSwarm*)swarm;
+
+	_Swarm_Delete( self );
+}
+
+
+void _MaterialPointsSwarm_Print( void* swarm, Stream* stream ) {
+	MaterialPointsSwarm* self = (MaterialPointsSwarm*)swarm;
+	
+	_Swarm_Print( self, stream );
+}
+
+void* _MaterialPointsSwarm_Copy( const void* swarm, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	MaterialPointsSwarm*	self = (MaterialPointsSwarm*)swarm;
+	MaterialPointsSwarm*	newMaterialPointsSwarm;
+	
+	newMaterialPointsSwarm = (MaterialPointsSwarm*)_Swarm_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newMaterialPointsSwarm->materialIndexVariable = (SwarmVariable*)Stg_Class_Copy(
+				self->materialIndexVariable,
+				NULL,
+				deep,
+				nameExt,
+				ptrMap );
+	
+	return (void*)newMaterialPointsSwarm;
+}
+
+void* _MaterialPointsSwarm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(MaterialPointsSwarm);
+	Type                                                         type = MaterialPointsSwarm_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _MaterialPointsSwarm_Delete;
+	Stg_Class_PrintFunction*                                   _print = _MaterialPointsSwarm_Print;
+	Stg_Class_CopyFunction*                                     _copy = _MaterialPointsSwarm_Copy;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _MaterialPointsSwarm_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _MaterialPointsSwarm_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _MaterialPointsSwarm_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _MaterialPointsSwarm_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _MaterialPointsSwarm_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _MaterialPointsSwarm_Destroy;
+	SizeT                                                particleSize = sizeof(MaterialPoint);
+
+	/* 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 */;
+	void*                          ics = ZERO;
+
+	return _MaterialPointsSwarm_New(  MATERIALPOINTSSWARM_PASSARGS  );
+}
+
+
+void _MaterialPointsSwarm_AssignFromXML( void* swarm, Stg_ComponentFactory* cf, void* data ) {
+	MaterialPointsSwarm*	        self          = (MaterialPointsSwarm*) swarm;
+	FeMesh*             		mesh;
+	EscapedRoutine*                 escapedRoutine;
+	Material*                       material;
+	Materials_Register*             materials_Register;
+	PICelleratorContext*		context;
+
+	_Swarm_AssignFromXML( self, cf, data );
+
+	mesh             = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"FeMesh", FeMesh, True, data  );
+	escapedRoutine   = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"EscapedRoutine", EscapedRoutine, False, data  );
+	material         = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Material", Material, False, data );
+
+	context = (PICelleratorContext* )self->context;
+	assert( Stg_CheckType( context, PICelleratorContext ) );
+	materials_Register = context->materials_Register; 
+	assert( materials_Register );
+
+	_MaterialPointsSwarm_Init(
+			self,
+			mesh, 
+			escapedRoutine,
+			material,
+			materials_Register );
+
+	self->geomodHack = Dictionary_GetBool_WithDefault( cf->rootDict, (Dictionary_Entry_Key)"geomodHacks", False  );
+}
+
+void _MaterialPointsSwarm_Build( void* swarm, void* data ) {
+	MaterialPointsSwarm*	self = (MaterialPointsSwarm*) swarm;
+	unsigned int			commHandler_I;
+	Bool                    movementCommHandlerFound = False;
+	Stream*                 errorStream = Journal_Register( Error_Type, (Name)self->type  );
+	Index var_I;
+
+	_Swarm_Build( self, data );
+
+	Stg_Component_Build( self->mesh, data , False );
+	if( self->escapedRoutine != NULL) Stg_Component_Build( self->escapedRoutine, data , False );
+	if( self->material       != NULL) Stg_Component_Build( self->material,       data , False );
+
+	/* Since this swarm is being set up to advect a PICellerator material, it should make sure
+	 * at least one ParticleMovementHandler-type ParticleCommHandler has been added to the base
+	 * Swarm. */
+	for( commHandler_I=0; commHandler_I < self->commHandlerList->count; commHandler_I++ ){
+		ParticleCommHandler *pComm = NULL;
+
+		pComm = (ParticleCommHandler*)(Stg_ObjectList_At( self->commHandlerList, commHandler_I ));
+		if( pComm->type == ParticleMovementHandler_Type ) {
+			movementCommHandlerFound = True;
+			break;
+		}
+	}
+
+	Journal_Firewall( (Stg_ObjectList_Count(self->commHandlerList) >= 1) && (movementCommHandlerFound == True),
+		errorStream, "Error: for MaterialPointsSwarm Swarms, at least one ParticleMovementHandler"
+			" commHandler must be registered. Please rectify this in your XML / code.\n" );
+
+	for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ ) {
+		Stg_Component_Build( self->swarmVars[var_I], data , False );
+	}
+}
+void _MaterialPointsSwarm_Initialise( void* swarm, void* data ) {
+	MaterialPointsSwarm*	self 	= (MaterialPointsSwarm*) swarm;
+	AbstractContext* 	context = (AbstractContext*)self->context;
+	Index            var_I	= 0;
+	Particle_Index          lParticle_I=0;
+	MaterialPoint*		matPoint=NULL;
+
+	_Swarm_Initialise( self, data );
+
+	Stg_Component_Initialise( self->mesh, data , False );
+	if( self->escapedRoutine != NULL) Stg_Component_Initialise( self->escapedRoutine, data , False );
+	if( self->material       != NULL) Stg_Component_Initialise( self->material,       data , False );
+
+	for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ ) {
+		Stg_Component_Initialise( self->swarmVars[var_I], data , False );
+	}
+
+	/* Now setup the material properties */
+   if(  False == context->loadFromCheckPoint ) {
+
+      /* Beforehand, set each particle to have UNDEFINED_MATERIAL */
+      for ( lParticle_I = 0; lParticle_I < self->particleLocalCount; lParticle_I++ ) {
+         matPoint = (MaterialPoint*)Swarm_ParticleAt( self, lParticle_I );
+         matPoint->materialIndex = UNDEFINED_MATERIAL;
+      }
+		if( self->material == NULL ) {
+			/* Do it by the layout of all known materials */
+			Materials_Register_SetupSwarm( self->materials_Register, self );
+		}
+		else {
+			Material_Layout( self->material, self );
+			Materials_Register_AssignParticleProperties( 
+					self->materials_Register, 
+					self, 
+					self->swarmVariable_Register->variable_Register );
+		}
+	}
+
+	/** if loading from checkpoint, particle materials etc have already been loaded in Swarm_Build() - */ 
+	/** possibly need to check for empty cells (and populate) if performing a interpolation restart */
+   if ( True == context->loadFromCheckPoint ){
+      if ( (True == self->isSwarmTypeToCheckPointAndReload) && (True == context->interpolateRestart) ) {	   
+         Particle_InCellIndex cParticle_I         = 0;
+         Particle_InCellIndex particle_I          = 0;
+         GlobalParticle*      particle            = NULL;
+         double               minDistance         = HUGE_VAL;
+         double               distanceToParticle;
+         Dimension_Index      dim = self->dim;
+         Cell_DomainIndex     dCell_I;
+         Cell_LocalIndex      lCell_I;
+         Cell_DomainIndex     belongsToCell_I = 0;
+         MaterialPoint*       matNewParticle;
+         MaterialPoint*       matParticleToSplit;
+         Particle_Index       matNewParticle_IndexOnCPU;
+         Coord                xi;
+         Coord                coord;
+         unsigned             nEmptyCells = 0;
+         Index*				   cellID = NULL;
+         Index*				   particleCPUID = NULL;
+         unsigned             count;
+         unsigned             ii;
+         
+         /** first determine how many local cells are empty */
+         for( lCell_I = 0 ; lCell_I < self->cellLocalCount ; lCell_I++ )
+            if (self->cellParticleCountTbl[lCell_I] == 0) nEmptyCells++;
+
+         /** create arrays which will be later used to populate cells */
+         cellID        = Memory_Alloc_Array( Index, nEmptyCells, "Cell ID for cell to be populated" );
+         particleCPUID = Memory_Alloc_Array( Index, nEmptyCells, "particle ID for particle to populate cell" );
+
+         count = 0;
+         for( lCell_I = 0 ; lCell_I < self->cellLocalCount ; lCell_I++ ) {
+            minDistance = HUGE_VAL;
+            if (self->cellParticleCountTbl[lCell_I] == 0) {
+               /** select the centre of the current cell */
+               xi[0] = 0;  xi[1] = 0;  xi[2] = 0;
+               /** get global coord */
+               FeMesh_CoordLocalToGlobal( self->mesh, lCell_I, xi, coord );
+      
+               for( dCell_I = 0 ; dCell_I < self->cellDomainCount ; dCell_I++ ) {
+                  /** Loop over particles find closest to cell centre */
+                  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;
+                        belongsToCell_I  = dCell_I;
+                     }
+                  }
+               }
+
+               /** create new particle which will be placed at centre of empty cell */
+               matNewParticle      = (MaterialPoint*) Swarm_CreateNewParticle( self, &matNewParticle_IndexOnCPU );
+               /** grab closest particle, which we will copy */
+               matParticleToSplit  = (MaterialPoint*) Swarm_ParticleInCellAt( self, belongsToCell_I, particle_I );
+               /** copy */
+               memcpy( matNewParticle, matParticleToSplit, self->particleExtensionMgr->finalSize );
+               /** set the owningCell to the cellDomainCount so that its owningCell will be reinitialised (not sure if necessary) */ 
+               matNewParticle->owningCell = self->cellDomainCount;
+               /** Copy new global position (cell centre) to coord on new mat particle */
+               memcpy( matNewParticle->coord, coord, sizeof(Coord) );
+               
+               /** we now store the required information to populate empty cells */
+               /** note that cells are not populated at this point, as this may interfere
+                   with the 0th order interpolation we are performing */ 
+               cellID[count]        = lCell_I;
+               particleCPUID[count] = matNewParticle_IndexOnCPU;
+               count++;
+      
+            }
+         }
+         /** populate empty cells */ 
+         for(ii = 0 ; ii < count ; ii++)
+            Swarm_AddParticleToCell( self, cellID[ii], particleCPUID[ii] );
+         Memory_Free( cellID );
+         Memory_Free( particleCPUID );
+      }
+	/* TODO: print info / debug message */
+   }
+}
+void _MaterialPointsSwarm_Execute( void* swarm, void* data ) {
+	MaterialPointsSwarm*	self = (MaterialPointsSwarm*)swarm;
+	
+	_Swarm_Execute( self, data );
+}
+void _MaterialPointsSwarm_Destroy( void* swarm, void* data ) {
+	MaterialPointsSwarm*	self = (MaterialPointsSwarm*)swarm;
+   Index var_I;
+	
+	Stg_Component_Destroy( self->mesh, data , False );
+	if( self->escapedRoutine != NULL) Stg_Component_Destroy( self->escapedRoutine, data , False );
+	if( self->material       != NULL) Stg_Component_Destroy( self->material,       data , False );
+
+	for( var_I = 0 ; var_I < self->nSwarmVars ; var_I++ ) {
+		Stg_Component_Destroy( self->swarmVars[var_I], data , False );
+	}
+
+	_Swarm_Destroy( self, data );
+}
+
+void _MaterialPointsSwarm_UpdateHook( void* timeIntegrator, void* swarm ) {
+	MaterialPointsSwarm* self               = (MaterialPointsSwarm*)swarm;
+	FeMesh*  mesh               = self->mesh;
+	Index                cell;
+	Index                point_I;
+	MaterialPoint*       materialPoint;
+
+	/* Need to check for escaped particles before the next block. */
+	if ( self->escapedRoutine ) {
+		Stg_Component_Execute( self->escapedRoutine, self, True );
+	}
+
+	/* Check that particles have not exited the box after advection */
+	if ( self->swarmAdvector  ) {
+		for ( point_I = 0; point_I < self->particleLocalCount; ++point_I ) {
+			materialPoint = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
+			cell = materialPoint->owningCell;
+			Journal_Firewall(
+					 cell < FeMesh_GetElementDomainSize( mesh ), 
+				Journal_MyStream( Error_Type, self ),
+				"In func %s: MaterialPoint '%d' outside element. Coord = {%g, %g, %g}\n",
+				__func__,
+				point_I,
+				materialPoint->coord[ I_AXIS ],
+				materialPoint->coord[ J_AXIS ],
+				materialPoint->coord[ K_AXIS ] );
+		}
+	}
+
+}
+
+void MaterialPointsSwarm_SetMaterialAt( void* swarm, Index point_I, Index materialIndex ) {
+	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
+	MaterialPoint*       point;
+
+	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
+	point->materialIndex = materialIndex;
+}
+
+
+Material* MaterialPointsSwarm_GetMaterialOn( void* swarm, void* particle ) {
+	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
+	MaterialPoint*       materialPoint = (MaterialPoint*)particle;
+
+	return Materials_Register_GetByIndex( self->materials_Register, materialPoint->materialIndex );
+}
+
+
+Material* MaterialPointsSwarm_GetMaterialAt( void* swarm, Index point_I ) {
+	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
+	MaterialPoint*       point;
+
+	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
+	return Materials_Register_GetByIndex( self->materials_Register, point->materialIndex );
+}
+
+Index MaterialPointsSwarm_GetMaterialIndexAt( void* swarm, Index point_I ) {
+	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
+	MaterialPoint*       point;
+
+	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
+	return point->materialIndex;
+}
+
+void* MaterialPointsSwarm_GetMaterialExtensionOn( void* swarm, void *matPoint, Index extHandle ) {
+	MaterialPointsSwarm *self  = (MaterialPointsSwarm*)swarm;
+	Material *mat;
+
+	mat = MaterialPointsSwarm_GetMaterialOn(self, matPoint);
+	return ExtensionManager_Get(mat->extensionMgr, mat, extHandle);
+}
+
+void* MaterialPointsSwarm_GetMaterialExtensionAt( void* swarm, int matPointInd, Index extHandle ) {
+	MaterialPointsSwarm *self  = (MaterialPointsSwarm*)swarm;
+	Material *mat;
+
+	mat = MaterialPointsSwarm_GetMaterialAt(self, matPointInd);
+	return ExtensionManager_Get(mat->extensionMgr, mat, extHandle);
+}
+
+void* MaterialPointsSwarm_GetExtensionAt( void* swarm, Index point_I, Index extHandle ) {
+	MaterialPointsSwarm* self  = (MaterialPointsSwarm*)swarm;
+	MaterialPoint*       point;
+
+	point = (MaterialPoint*)Swarm_ParticleAt( self, point_I );
+	return ExtensionManager_Get( self->particleExtensionMgr, point, extHandle );
+	
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Materials_Register.c
--- a/MaterialPoints/src/Materials_Register.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,311 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Materials_Register.c 532 2008-02-12 01:17:48Z DavidMay $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <string.h>
-#include <assert.h>
-#include <math.h>
-
-const Type Materials_Register_Type = "Materials_Register";
-
-Materials_Register* Materials_Register_New( void ) {
-	/* Variables set in this function */
-	SizeT                      _sizeOfSelf = sizeof(Materials_Register);
-	Type                              type = Materials_Register_Type;
-	Stg_Class_DeleteFunction*      _delete = _Materials_Register_Delete;
-	Stg_Class_PrintFunction*        _print = _Materials_Register_Print;
-	Stg_Class_CopyFunction*          _copy = _Materials_Register_Copy;
-
-	Materials_Register* self;
-
-	self = (Materials_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
-
-	return self;
-}
-
-void _Materials_Register_Delete( void* _materialsRegister ) {
-	Materials_Register* self = (Materials_Register*) _materialsRegister;
-
-	_NamedObject_Register_Delete( self );
-}
-void _Materials_Register_Print( void* _materialsRegister, Stream* stream ) {
-	Materials_Register* self = (Materials_Register*) _materialsRegister;
-
-	_NamedObject_Register_Print( self, stream );
-}
-
-void* _Materials_Register_Copy( const void* _materialsRegister, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	Materials_Register* self                   = (Materials_Register*) _materialsRegister;
-	Materials_Register* newMaterials_Register;
-
-	newMaterials_Register = (Materials_Register*)_NamedObject_Register_Copy( self, dest, deep, nameExt, ptrMap );
-
-	return newMaterials_Register;
-}
-
-
-Material* Materials_Register_GetByIndex( Materials_Register* self, Index materialIndex ) {
-	if ( UNDEFINED_MATERIAL == materialIndex ) {
-		return NULL;
-	}
-
-	return (Material*) NamedObject_Register_GetByIndex( self, materialIndex );
-}
-
-
-void Materials_Register_SetupSwarm( void* materialRegister, MaterialPointsSwarm* swarm )
-{
-	Materials_Register* self = (Materials_Register*)materialRegister;
-
-	assert( swarm != NULL );
-
-	_Materials_Register_LayoutGeometry( self, swarm );
-/* 	Materials_Register_SetupParticleToMaterialMappings( self, swarm ); */
-	Materials_Register_AssignParticleProperties( self, swarm, swarm->swarmVariable_Register->variable_Register );
-}
-
-
-ExtensionInfo_Index Materials_Register_AddMaterialExtension( void* materialsRegister, Type type, SizeT extensionSize ) {
-	Materials_Register*     self         = (Materials_Register*) materialsRegister;
-	Material*               material;
-	ExtensionInfo_Index     firstResult  = 0;
-	ExtensionInfo_Index     result       = 0;
-	Material_Index          material_I   = 0;
-
-	for ( material_I = 0 ; material_I < Materials_Register_GetCount( self ) ; material_I++) {
-		material = Materials_Register_GetByIndex( self, material_I );
-
-		result = ExtensionManager_Add( material->extensionMgr, (char*)type, extensionSize );
-
-		if ( material_I == 0  )
-			firstResult = result;
-		else {
-			Journal_Firewall( 
-				firstResult == result, 
-				Journal_Register( Error_Type, (Name)self->type  ),
-				"Material '%s' has a different number of extensions than eariler materials.\n", 
-				material->name );
-		}
-	}
-
-	return result;
-}
-			
-void _Materials_Register_LayoutGeometry( void* materialsRegister, void* swarm ) {
-	Materials_Register*     self         = (Materials_Register*) materialsRegister;
-	Material_Index          material_I;
-	Material*               material;
-	
-	for ( material_I = 0 ; material_I < Materials_Register_GetCount( self ) ; material_I++) {
-		material = Materials_Register_GetByIndex( self, material_I );
-		Material_Layout( material, (MaterialPointsSwarm*)swarm );
-	}
-}
-
-void Materials_Register_AssignParticleProperties( 
-		void*                   materialRegister,
-		MaterialPointsSwarm*    swarm,
-		Variable_Register*      variableRegister )
-{
-	Materials_Register* self               = (Materials_Register*)materialRegister;
-	Material*           material;
-	Particle_Index      lParticle_I;
-	Particle_Index      particleLocalCount = swarm->particleLocalCount;
-	Particle_Index      particleGlobalCount = 0;
-	Stream*             stream = Journal_Register( Info_Type, (Name)self->type  );
-	Processor_Index     formerStreamPrintingRank;
-	double              setupStartTime = 0;
-	double              setupTime = 0, tmin, tmax;
-	Bool                firstStatusPrint = True;
-
-        formerStreamPrintingRank = Stream_GetPrintingRank( stream );
-        Stream_SetPrintingRank( stream, 0 );
-
-	Journal_Printf( stream, "In func %s(): for swarm \"%s\"\n", __func__, swarm->name );
-	Stream_Indent( stream );
-	setupStartTime = MPI_Wtime();
-	MPI_Reduce( &particleLocalCount, &particleGlobalCount, 1, MPI_UNSIGNED, MPI_SUM, 0, swarm->comm );
-	Journal_Printf( stream, "Assigning initial particle properties to the %u global particles\n",
-		particleGlobalCount );
-	Stream_Indent( stream );
-
-	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
-		material = MaterialPointsSwarm_GetMaterialAt( swarm, lParticle_I );
-
-		if ( material ) {
-			/* Loop through material's dictionary assigning values to the variables of this particle */
-			Variable_Register_SetAllVariablesFromDictionary( variableRegister, lParticle_I, material->dictionary );
-		}
-
-		_Materials_Register_PrintParticleAssignUpdate( self, swarm, lParticle_I, stream, &firstStatusPrint );
-	}
-
-	Stream_UnIndent( stream );
-	/* Need this barrier so the time is accurate */
-	MPI_Barrier( swarm->comm );
-	setupTime = MPI_Wtime() - setupStartTime;
-
-	Stream_UnIndent( stream );
-
-	MPI_Reduce( &setupTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, swarm->comm );
-	MPI_Reduce( &setupTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, swarm->comm );
-	Journal_Printf( stream, "%s(): finished setup of material properties for swarm \"%s\"\n"
-		"\ttook %g [min] / %g [max] secs\n", __func__, swarm->name, tmin, tmax );
-	Stream_SetPrintingRank( stream, formerStreamPrintingRank );
-}
-
-
-void _Materials_Register_PrintParticleAssignUpdate(  
-		void*                   materialRegister,
-		MaterialPointsSwarm*    swarm,
-		Particle_Index          lParticle_I,
-		Stream*                 stream,
-		Bool*                   firstStatusPrint )
-{
-	unsigned int               numberOfCompletionPrintIncrements=10;
-	double                     completionRatioIncrement= 1 / (double)numberOfCompletionPrintIncrements;
-	static double              nextCompletionRatioToPrint=0;
-	static Particle_Index      nextCompletedParticleCountToPrint=0;
-	static Particle_Index      nextPlusOneCompletedParticleCountToPrint=0;
-
-	if (*firstStatusPrint) {
-		nextCompletionRatioToPrint = completionRatioIncrement;
-		nextCompletedParticleCountToPrint = ceil(swarm->particleLocalCount * nextCompletionRatioToPrint - 0.001 );
-		nextPlusOneCompletedParticleCountToPrint=0;
-		*firstStatusPrint = False;
-	}
-
-	if ( /*(swarm->myRank == 0) && */ ((lParticle_I+1) >= nextCompletedParticleCountToPrint ) ) {
-		/* TODO: parallelise : non-master CPUs send a non-blocking update to the master to report */
-		/* status. Master does blocking receive on all updates before printing */
-
-		/* Special case for really small swarms, or really small increments - may cross more than one
-			at once */
-		nextPlusOneCompletedParticleCountToPrint = ceil(( swarm->particleLocalCount
-			* (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
-
-		while ( (lParticle_I+1) >= nextPlusOneCompletedParticleCountToPrint )
-		{
-			nextCompletionRatioToPrint += completionRatioIncrement;
-			nextPlusOneCompletedParticleCountToPrint = ceil(( swarm->particleLocalCount
-				* (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
-			if ( nextCompletionRatioToPrint >= 1.0 ) {
-				nextCompletionRatioToPrint = 1.0;
-				break;
-			}
-		}
-		Journal_Printf( stream, "done %.0f%% (%u particles)...\n", 
-			(nextCompletionRatioToPrint * 100),
-			lParticle_I+1 );
-		nextCompletionRatioToPrint += completionRatioIncrement;
-		nextCompletedParticleCountToPrint = ceil(swarm->particleLocalCount * nextCompletionRatioToPrint - 0.001);
-	}
-}
-
-
-void Variable_SetValueFromDictionary( void* _variable, Index index, Dictionary* dictionary ) {
-	Variable*          variable = (Variable*)_variable;
-
-	Variable_Update( variable );
-	
-	/* Assign variable from dictionary according to data type */
-	switch (variable->dataTypes[0]) {
-		case Variable_DataType_Char:
-			Variable_SetValueChar(  variable, index, Dictionary_GetUnsignedInt( dictionary, variable->name ));
-			break;
-		case Variable_DataType_Short:
-			Variable_SetValueShort( variable, index, Dictionary_GetUnsignedInt( dictionary, variable->name ));
-			break;
-		case Variable_DataType_Int:
-			Variable_SetValueInt( variable, index, Dictionary_GetInt( dictionary, (Dictionary_Entry_Key)variable->name ) );
-			break;
-		case Variable_DataType_Float:
-			Variable_SetValueFloat(  variable, index, Dictionary_GetDouble( dictionary, variable->name ));
-			break;
-		case Variable_DataType_Double:
-			Variable_SetValueDouble( variable, index, Dictionary_GetDouble( dictionary, variable->name ));
-			break;
-		default: {
-			Journal_Printf( 
-				Journal_MyStream( Error_Type, variable ), 
-				"In func %s: Unable to set value of %s from dictionary.", 
-				__func__, 
-				variable->name );
-		}
-	}
-}
-
-void Variable_Register_SetAllVariablesFromDictionary( void* _variable_Register, Index index, Dictionary* dictionary ) {
-	Variable_Register* variable_Register = (Variable_Register*) _variable_Register;
-	Variable*          variable;
-	Dictionary_Index   dictionary_I;
-	Dictionary_Entry*  entry;
-
-	for ( dictionary_I = 0 ; dictionary_I < dictionary->count ; dictionary_I++ ) {
-		entry = dictionary->entryPtr[ dictionary_I ];
-
-		/* Find variable on particle associated with this name */
-		variable = Variable_Register_GetByName( variable_Register, entry->key );
-		
-		/* If there is no variable, continue through loop */
-		if (variable == NULL) 
-			continue;
-
-		/* Assign Value */
-		Variable_SetValueFromDictionary( variable, index, dictionary );
-	}
-}
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/Materials_Register.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/Materials_Register.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,311 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Materials_Register.c 532 2008-02-12 01:17:48Z DavidMay $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <string.h>
+#include <assert.h>
+#include <math.h>
+
+const Type Materials_Register_Type = "Materials_Register";
+
+Materials_Register* Materials_Register_New( void ) {
+	/* Variables set in this function */
+	SizeT                      _sizeOfSelf = sizeof(Materials_Register);
+	Type                              type = Materials_Register_Type;
+	Stg_Class_DeleteFunction*      _delete = _Materials_Register_Delete;
+	Stg_Class_PrintFunction*        _print = _Materials_Register_Print;
+	Stg_Class_CopyFunction*          _copy = _Materials_Register_Copy;
+
+	Materials_Register* self;
+
+	self = (Materials_Register*) _NamedObject_Register_New(  NAMEDOBJECT_REGISTER_PASSARGS  );
+
+	return self;
+}
+
+void _Materials_Register_Delete( void* _materialsRegister ) {
+	Materials_Register* self = (Materials_Register*) _materialsRegister;
+
+	_NamedObject_Register_Delete( self );
+}
+void _Materials_Register_Print( void* _materialsRegister, Stream* stream ) {
+	Materials_Register* self = (Materials_Register*) _materialsRegister;
+
+	_NamedObject_Register_Print( self, stream );
+}
+
+void* _Materials_Register_Copy( const void* _materialsRegister, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	Materials_Register* self                   = (Materials_Register*) _materialsRegister;
+	Materials_Register* newMaterials_Register;
+
+	newMaterials_Register = (Materials_Register*)_NamedObject_Register_Copy( self, dest, deep, nameExt, ptrMap );
+
+	return newMaterials_Register;
+}
+
+
+Material* Materials_Register_GetByIndex( Materials_Register* self, Index materialIndex ) {
+	if ( UNDEFINED_MATERIAL == materialIndex ) {
+		return NULL;
+	}
+
+	return (Material*) NamedObject_Register_GetByIndex( self, materialIndex );
+}
+
+
+void Materials_Register_SetupSwarm( void* materialRegister, MaterialPointsSwarm* swarm )
+{
+	Materials_Register* self = (Materials_Register*)materialRegister;
+
+	assert( swarm != NULL );
+
+	_Materials_Register_LayoutGeometry( self, swarm );
+/* 	Materials_Register_SetupParticleToMaterialMappings( self, swarm ); */
+	Materials_Register_AssignParticleProperties( self, swarm, swarm->swarmVariable_Register->variable_Register );
+}
+
+
+ExtensionInfo_Index Materials_Register_AddMaterialExtension( void* materialsRegister, Type type, SizeT extensionSize ) {
+	Materials_Register*     self         = (Materials_Register*) materialsRegister;
+	Material*               material;
+	ExtensionInfo_Index     firstResult  = 0;
+	ExtensionInfo_Index     result       = 0;
+	Material_Index          material_I   = 0;
+
+	for ( material_I = 0 ; material_I < Materials_Register_GetCount( self ) ; material_I++) {
+		material = Materials_Register_GetByIndex( self, material_I );
+
+		result = ExtensionManager_Add( material->extensionMgr, (char*)type, extensionSize );
+
+		if ( material_I == 0  )
+			firstResult = result;
+		else {
+			Journal_Firewall( 
+				firstResult == result, 
+				Journal_Register( Error_Type, (Name)self->type  ),
+				"Material '%s' has a different number of extensions than eariler materials.\n", 
+				material->name );
+		}
+	}
+
+	return result;
+}
+			
+void _Materials_Register_LayoutGeometry( void* materialsRegister, void* swarm ) {
+	Materials_Register*     self         = (Materials_Register*) materialsRegister;
+	Material_Index          material_I;
+	Material*               material;
+	
+	for ( material_I = 0 ; material_I < Materials_Register_GetCount( self ) ; material_I++) {
+		material = Materials_Register_GetByIndex( self, material_I );
+		Material_Layout( material, (MaterialPointsSwarm*)swarm );
+	}
+}
+
+void Materials_Register_AssignParticleProperties( 
+		void*                   materialRegister,
+		MaterialPointsSwarm*    swarm,
+		Variable_Register*      variableRegister )
+{
+	Materials_Register* self               = (Materials_Register*)materialRegister;
+	Material*           material;
+	Particle_Index      lParticle_I;
+	Particle_Index      particleLocalCount = swarm->particleLocalCount;
+	Particle_Index      particleGlobalCount = 0;
+	Stream*             stream = Journal_Register( Info_Type, (Name)self->type  );
+	Processor_Index     formerStreamPrintingRank;
+	double              setupStartTime = 0;
+	double              setupTime = 0, tmin, tmax;
+	Bool                firstStatusPrint = True;
+
+        formerStreamPrintingRank = Stream_GetPrintingRank( stream );
+        Stream_SetPrintingRank( stream, 0 );
+
+	Journal_Printf( stream, "In func %s(): for swarm \"%s\"\n", __func__, swarm->name );
+	Stream_Indent( stream );
+	setupStartTime = MPI_Wtime();
+	MPI_Reduce( &particleLocalCount, &particleGlobalCount, 1, MPI_UNSIGNED, MPI_SUM, 0, swarm->comm );
+	Journal_Printf( stream, "Assigning initial particle properties to the %u global particles\n",
+		particleGlobalCount );
+	Stream_Indent( stream );
+
+	for ( lParticle_I = 0 ; lParticle_I < particleLocalCount ; lParticle_I++ ) {
+		material = MaterialPointsSwarm_GetMaterialAt( swarm, lParticle_I );
+
+		if ( material ) {
+			/* Loop through material's dictionary assigning values to the variables of this particle */
+			Variable_Register_SetAllVariablesFromDictionary( variableRegister, lParticle_I, material->dictionary );
+		}
+
+		_Materials_Register_PrintParticleAssignUpdate( self, swarm, lParticle_I, stream, &firstStatusPrint );
+	}
+
+	Stream_UnIndent( stream );
+	/* Need this barrier so the time is accurate */
+	MPI_Barrier( swarm->comm );
+	setupTime = MPI_Wtime() - setupStartTime;
+
+	Stream_UnIndent( stream );
+
+	MPI_Reduce( &setupTime, &tmin, 1, MPI_DOUBLE, MPI_MIN, 0, swarm->comm );
+	MPI_Reduce( &setupTime, &tmax, 1, MPI_DOUBLE, MPI_MAX, 0, swarm->comm );
+	Journal_Printf( stream, "%s(): finished setup of material properties for swarm \"%s\"\n"
+		"\ttook %g [min] / %g [max] secs\n", __func__, swarm->name, tmin, tmax );
+	Stream_SetPrintingRank( stream, formerStreamPrintingRank );
+}
+
+
+void _Materials_Register_PrintParticleAssignUpdate(  
+		void*                   materialRegister,
+		MaterialPointsSwarm*    swarm,
+		Particle_Index          lParticle_I,
+		Stream*                 stream,
+		Bool*                   firstStatusPrint )
+{
+	unsigned int               numberOfCompletionPrintIncrements=10;
+	double                     completionRatioIncrement= 1 / (double)numberOfCompletionPrintIncrements;
+	static double              nextCompletionRatioToPrint=0;
+	static Particle_Index      nextCompletedParticleCountToPrint=0;
+	static Particle_Index      nextPlusOneCompletedParticleCountToPrint=0;
+
+	if (*firstStatusPrint) {
+		nextCompletionRatioToPrint = completionRatioIncrement;
+		nextCompletedParticleCountToPrint = ceil(swarm->particleLocalCount * nextCompletionRatioToPrint - 0.001 );
+		nextPlusOneCompletedParticleCountToPrint=0;
+		*firstStatusPrint = False;
+	}
+
+	if ( /*(swarm->myRank == 0) && */ ((lParticle_I+1) >= nextCompletedParticleCountToPrint ) ) {
+		/* TODO: parallelise : non-master CPUs send a non-blocking update to the master to report */
+		/* status. Master does blocking receive on all updates before printing */
+
+		/* Special case for really small swarms, or really small increments - may cross more than one
+			at once */
+		nextPlusOneCompletedParticleCountToPrint = ceil(( swarm->particleLocalCount
+			* (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
+
+		while ( (lParticle_I+1) >= nextPlusOneCompletedParticleCountToPrint )
+		{
+			nextCompletionRatioToPrint += completionRatioIncrement;
+			nextPlusOneCompletedParticleCountToPrint = ceil(( swarm->particleLocalCount
+				* (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
+			if ( nextCompletionRatioToPrint >= 1.0 ) {
+				nextCompletionRatioToPrint = 1.0;
+				break;
+			}
+		}
+		Journal_Printf( stream, "done %.0f%% (%u particles)...\n", 
+			(nextCompletionRatioToPrint * 100),
+			lParticle_I+1 );
+		nextCompletionRatioToPrint += completionRatioIncrement;
+		nextCompletedParticleCountToPrint = ceil(swarm->particleLocalCount * nextCompletionRatioToPrint - 0.001);
+	}
+}
+
+
+void Variable_SetValueFromDictionary( void* _variable, Index index, Dictionary* dictionary ) {
+	Variable*          variable = (Variable*)_variable;
+
+	Variable_Update( variable );
+	
+	/* Assign variable from dictionary according to data type */
+	switch (variable->dataTypes[0]) {
+		case Variable_DataType_Char:
+			Variable_SetValueChar(  variable, index, Dictionary_GetUnsignedInt( dictionary, variable->name ));
+			break;
+		case Variable_DataType_Short:
+			Variable_SetValueShort( variable, index, Dictionary_GetUnsignedInt( dictionary, variable->name ));
+			break;
+		case Variable_DataType_Int:
+			Variable_SetValueInt( variable, index, Dictionary_GetInt( dictionary, (Dictionary_Entry_Key)variable->name ) );
+			break;
+		case Variable_DataType_Float:
+			Variable_SetValueFloat(  variable, index, Dictionary_GetDouble( dictionary, variable->name ));
+			break;
+		case Variable_DataType_Double:
+			Variable_SetValueDouble( variable, index, Dictionary_GetDouble( dictionary, variable->name ));
+			break;
+		default: {
+			Journal_Printf( 
+				Journal_MyStream( Error_Type, variable ), 
+				"In func %s: Unable to set value of %s from dictionary.", 
+				__func__, 
+				variable->name );
+		}
+	}
+}
+
+void Variable_Register_SetAllVariablesFromDictionary( void* _variable_Register, Index index, Dictionary* dictionary ) {
+	Variable_Register* variable_Register = (Variable_Register*) _variable_Register;
+	Variable*          variable;
+	Dictionary_Index   dictionary_I;
+	Dictionary_Entry*  entry;
+
+	for ( dictionary_I = 0 ; dictionary_I < dictionary->count ; dictionary_I++ ) {
+		entry = dictionary->entryPtr[ dictionary_I ];
+
+		/* Find variable on particle associated with this name */
+		variable = Variable_Register_GetByName( variable_Register, entry->key );
+		
+		/* If there is no variable, continue through loop */
+		if (variable == NULL) 
+			continue;
+
+		/* Assign Value */
+		Variable_SetValueFromDictionary( variable, index, dictionary );
+	}
+}
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/OneToManyMapper.c
--- a/MaterialPoints/src/OneToManyMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,193 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-#include "MaterialPoints.h"
-
-const Type OneToManyMapper_Type = "OneToManyMapper";
-
-OneToManyMapper* _OneToManyMapper_New( ONETOMANYMAPPER_DEFARGS ) {
-	OneToManyMapper* result;
-
-	result = (OneToManyMapper*)_IntegrationPointMapper_New( INTEGRATIONPOINTMAPPER_PASSARGS );
-		
-	return result;
-}
-
-void _OneToManyMapper_Init( void* mapper, MaterialPointsSwarm* materialSwarm ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-
-	self->errorStream = Journal_MyStream( Error_Type, self );
-	self->materialSwarm = materialSwarm;
-
-	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
-	self->refHandle = ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, materialSwarm->name, sizeof(OneToManyRef)  );
-	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
-}
-
-void _OneToManyMapper_Delete( void* mapper ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-	
-	_IntegrationPointMapper_Delete( self );
-}
-void _OneToManyMapper_Print( void* mapper, Stream* stream ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-	
-	_IntegrationPointMapper_Print( self, stream );
-	Stream_Indent( stream );
-	Stg_Class_Print( self->materialSwarm, stream );
-	Stream_UnIndent( stream );
-}
-void* _OneToManyMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-	OneToManyMapper* newCopy;
-	
-	newCopy = (OneToManyMapper*)_IntegrationPointMapper_Copy( self, dest, deep, nameExt, ptrMap );
-	newCopy->materialSwarm = (MaterialPointsSwarm*)Stg_Class_Copy( self->materialSwarm, NULL, deep, nameExt, ptrMap );
-
-	return newCopy;
-}
-
-void _OneToManyMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-	MaterialPointsSwarm* materialSwarm;
-	
-	_IntegrationPointMapper_AssignFromXML( self, cf, data );
-
-	materialSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)MaterialPointsSwarm_Type, MaterialPointsSwarm, True, data   );
-
-	_OneToManyMapper_Init( self, materialSwarm );
-
-}
-
-void _OneToManyMapper_Build( void* mapper, void* data ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-
-	_IntegrationPointMapper_Build( mapper, data );
-	Stg_Component_Build( self->materialSwarm, data, False );
-	
-}
-void _OneToManyMapper_Initialise( void* mapper, void* data ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-
-	_IntegrationPointMapper_Initialise( mapper, data );
-	Stg_Component_Initialise( self->materialSwarm, data, False );
-}
-void _OneToManyMapper_Execute( void* mapper, void* data ) {}
-
-void _OneToManyMapper_Destroy( void* mapper, void* data ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-
-	/*Stg_Class_Delete( self->materialSwarm );*/
-
-	_IntegrationPointMapper_Destroy( self, data );
-}
-
-OneToManyRef* OneToManyMapper_GetMaterialRef( void* mapper, void* intPoint ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-
-	return (OneToManyRef*)ExtensionManager_Get( 
-			self->integrationSwarm->particleExtensionMgr, 
-			intPoint,
-			self->refHandle );
-}
-
-MaterialPointsSwarm** _OneToManyMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
-	OneToManyMapper* self = (OneToManyMapper*)mapper;
-	MaterialPointsSwarm** result = Memory_Alloc_Array( MaterialPointsSwarm*, 1,  "Swarms" );
-	result[0] = self->materialSwarm;
-	*count = 1;
-
-	return result;
-}
-
-Material_Index _OneToManyMapper_GetMaterialIndexOn( void* mapper, void* point ) {
-    /* This method cannot work with a one-to-many mapping. */
-    return -1;
-}
-
-void* _OneToManyMapper_GetExtensionOn( void* mapper, void* point, ExtensionInfo_Index extHandle ) {
-    /* This method cannot work with a one-to-many mapping. */
-    return NULL;
-}
-
-double _OneToManyMapper_GetDoubleFromExtension(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
-    OneToManyMapper *self = (OneToManyMapper*)mapper;
-    OneToManyRef *ref;
-    double v = 0.0, c;
-    int ii;
-
-    ref = OneToManyMapper_GetMaterialRef(mapper, intPoint);
-    for(ii = 0; ii < ref->numParticles; ii++) {
-      c = *(double*)(MaterialPointsSwarm_GetExtensionAt(self->materialSwarm, ref->particleInds[ii], extHandle) + offs);
-      v += ((double)ref->weights[ii])*c;
-    }
-
-    return v;
-}
-
-double _OneToManyMapper_GetDoubleFromMaterial(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
-    OneToManyMapper *self = (OneToManyMapper*)mapper;
-    OneToManyRef *ref;
-    double v = 0.0, c;
-    int ii;
-
-    ref = OneToManyMapper_GetMaterialRef(mapper, intPoint);
-    for(ii = 0; ii < ref->numParticles; ii++) {
-      c = *(double*)(MaterialPointsSwarm_GetMaterialExtensionAt(self->materialSwarm, ref->particleInds[ii], extHandle) + offs);
-      v += ((double)ref->weights[ii])*c;
-    }
-
-    return v;
-}
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/OneToManyMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/OneToManyMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,193 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+#include "MaterialPoints.h"
+
+const Type OneToManyMapper_Type = "OneToManyMapper";
+
+OneToManyMapper* _OneToManyMapper_New( ONETOMANYMAPPER_DEFARGS ) {
+	OneToManyMapper* result;
+
+	result = (OneToManyMapper*)_IntegrationPointMapper_New( INTEGRATIONPOINTMAPPER_PASSARGS );
+		
+	return result;
+}
+
+void _OneToManyMapper_Init( void* mapper, MaterialPointsSwarm* materialSwarm ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+
+	self->errorStream = Journal_MyStream( Error_Type, self );
+	self->materialSwarm = materialSwarm;
+
+	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
+	self->refHandle = ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, materialSwarm->name, sizeof(OneToManyRef)  );
+	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
+}
+
+void _OneToManyMapper_Delete( void* mapper ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+	
+	_IntegrationPointMapper_Delete( self );
+}
+void _OneToManyMapper_Print( void* mapper, Stream* stream ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+	
+	_IntegrationPointMapper_Print( self, stream );
+	Stream_Indent( stream );
+	Stg_Class_Print( self->materialSwarm, stream );
+	Stream_UnIndent( stream );
+}
+void* _OneToManyMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+	OneToManyMapper* newCopy;
+	
+	newCopy = (OneToManyMapper*)_IntegrationPointMapper_Copy( self, dest, deep, nameExt, ptrMap );
+	newCopy->materialSwarm = (MaterialPointsSwarm*)Stg_Class_Copy( self->materialSwarm, NULL, deep, nameExt, ptrMap );
+
+	return newCopy;
+}
+
+void _OneToManyMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+	MaterialPointsSwarm* materialSwarm;
+	
+	_IntegrationPointMapper_AssignFromXML( self, cf, data );
+
+	materialSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)MaterialPointsSwarm_Type, MaterialPointsSwarm, True, data   );
+
+	_OneToManyMapper_Init( self, materialSwarm );
+
+}
+
+void _OneToManyMapper_Build( void* mapper, void* data ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+
+	_IntegrationPointMapper_Build( mapper, data );
+	Stg_Component_Build( self->materialSwarm, data, False );
+	
+}
+void _OneToManyMapper_Initialise( void* mapper, void* data ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+
+	_IntegrationPointMapper_Initialise( mapper, data );
+	Stg_Component_Initialise( self->materialSwarm, data, False );
+}
+void _OneToManyMapper_Execute( void* mapper, void* data ) {}
+
+void _OneToManyMapper_Destroy( void* mapper, void* data ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+
+	/*Stg_Class_Delete( self->materialSwarm );*/
+
+	_IntegrationPointMapper_Destroy( self, data );
+}
+
+OneToManyRef* OneToManyMapper_GetMaterialRef( void* mapper, void* intPoint ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+
+	return (OneToManyRef*)ExtensionManager_Get( 
+			self->integrationSwarm->particleExtensionMgr, 
+			intPoint,
+			self->refHandle );
+}
+
+MaterialPointsSwarm** _OneToManyMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
+	OneToManyMapper* self = (OneToManyMapper*)mapper;
+	MaterialPointsSwarm** result = Memory_Alloc_Array( MaterialPointsSwarm*, 1,  "Swarms" );
+	result[0] = self->materialSwarm;
+	*count = 1;
+
+	return result;
+}
+
+Material_Index _OneToManyMapper_GetMaterialIndexOn( void* mapper, void* point ) {
+    /* This method cannot work with a one-to-many mapping. */
+    return -1;
+}
+
+void* _OneToManyMapper_GetExtensionOn( void* mapper, void* point, ExtensionInfo_Index extHandle ) {
+    /* This method cannot work with a one-to-many mapping. */
+    return NULL;
+}
+
+double _OneToManyMapper_GetDoubleFromExtension(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
+    OneToManyMapper *self = (OneToManyMapper*)mapper;
+    OneToManyRef *ref;
+    double v = 0.0, c;
+    int ii;
+
+    ref = OneToManyMapper_GetMaterialRef(mapper, intPoint);
+    for(ii = 0; ii < ref->numParticles; ii++) {
+      c = *(double*)(MaterialPointsSwarm_GetExtensionAt(self->materialSwarm, ref->particleInds[ii], extHandle) + offs);
+      v += ((double)ref->weights[ii])*c;
+    }
+
+    return v;
+}
+
+double _OneToManyMapper_GetDoubleFromMaterial(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
+    OneToManyMapper *self = (OneToManyMapper*)mapper;
+    OneToManyRef *ref;
+    double v = 0.0, c;
+    int ii;
+
+    ref = OneToManyMapper_GetMaterialRef(mapper, intPoint);
+    for(ii = 0; ii < ref->numParticles; ii++) {
+      c = *(double*)(MaterialPointsSwarm_GetMaterialExtensionAt(self->materialSwarm, ref->particleInds[ii], extHandle) + offs);
+      v += ((double)ref->weights[ii])*c;
+    }
+
+    return v;
+}
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/OneToOneMapper.c
--- a/MaterialPoints/src/OneToOneMapper.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,211 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-const Type OneToOneMapper_Type = "OneToOneMapper";
-
-OneToOneMapper* _OneToOneMapper_New(  ONETOONEMAPPER_DEFARGS  ) {
-	OneToOneMapper* result;
-
-	result = (OneToOneMapper*)_IntegrationPointMapper_New(  INTEGRATIONPOINTMAPPER_PASSARGS  );
-
-	return result;
-}
-
-void _OneToOneMapper_Init( void* mapper, MaterialPointsSwarm* materialSwarm ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-	
-	self->errorStream = Journal_MyStream( Error_Type, self );
-	self->materialSwarm = materialSwarm;
-
-	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
-	self->materialRefHandle = ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, materialSwarm->name, sizeof(MaterialPointRef)  );
-	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
-}
-
-void _OneToOneMapper_Delete( void* mapper ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-
-	_IntegrationPointMapper_Delete( self );
-}
-
-void _OneToOneMapper_Print( void* mapper, Stream* stream ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-	
-	_IntegrationPointMapper_Print( self, stream );
-	Stream_Indent( stream );
-	Stg_Class_Print( self->materialSwarm, stream );
-	Stream_UnIndent( stream );
-}
-
-void* _OneToOneMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-	OneToOneMapper* newCopy;
-	
-	newCopy = (OneToOneMapper*)_IntegrationPointMapper_Copy( self, dest, deep, nameExt, ptrMap );
-	newCopy->materialSwarm = (MaterialPointsSwarm*)Stg_Class_Copy( self->materialSwarm, NULL, deep, nameExt, ptrMap );
-
-	return newCopy;
-}
-
-void _OneToOneMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
-	OneToOneMapper*		self = (OneToOneMapper*)mapper;
-	MaterialPointsSwarm*	materialSwarm;
-
-	_IntegrationPointMapper_AssignFromXML( self, cf, data );
-
-	materialSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)MaterialPointsSwarm_Type, MaterialPointsSwarm, True, data  );
-
-	_OneToOneMapper_Init( self, materialSwarm );
-}
-
-void _OneToOneMapper_Build( void* mapper, void* data ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-
-	_IntegrationPointMapper_Build( mapper, data );
-	Stg_Component_Build( self->materialSwarm, data, False );
-}
-
-void _OneToOneMapper_Initialise( void* mapper, void* data ) {
-    OneToOneMapper* self = (OneToOneMapper*)mapper;
-
-    _IntegrationPointMapper_Initialise( mapper, data );
-    Stg_Component_Initialise( self->materialSwarm, data, False );
-}
-
-void _OneToOneMapper_Execute( void* mapper, void* data ) {}
-
-void _OneToOneMapper_Destroy( void* mapper, void* data ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-
-	_IntegrationPointMapper_Destroy( self, data );
-}
-
-MaterialPointRef* OneToOneMapper_GetMaterialRef( void* mapper, void* integrationPoint ) {
-	OneToOneMapper* self = (OneToOneMapper*)mapper;
-
-	return (MaterialPointRef*)ExtensionManager_Get( self->integrationSwarm->particleExtensionMgr, integrationPoint, self->materialRefHandle );
-}
-
-MaterialPoint* OneToOneMapper_GetMaterialPoint( void* mapper, void* integrationPoint, MaterialPointsSwarm** materialSwarm ) {
-	OneToOneMapper*		self = (OneToOneMapper*)mapper;
-	MaterialPointRef*		ref;
-	MaterialPointsSwarm*	swarm;
-	MaterialPoint*			materialPoint; /* Assumes that material swarm holds Material particle or derivative */
-
-	ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
-	Journal_Firewall( ref != NULL, self->errorStream, "In func %s, no MaterialPointRef found on point\n", __func__ );
-
-	swarm = (MaterialPointsSwarm*)Swarm_Register_At( Swarm_Register_GetSwarm_Register(), ref->swarm_I );
-	Journal_Firewall( swarm != NULL, self->errorStream, "In func %s, no swarm found on for index %d\n", __func__, ref->swarm_I );
-
-	if ( materialSwarm != NULL ) {
-		*materialSwarm = swarm;
-	}
-
-	materialPoint = (MaterialPoint*)Swarm_ParticleAt( swarm, ref->particle_I );
-	Journal_Firewall(
-		materialPoint != NULL,
-		self->errorStream, 
-		"In func %s, no MaterialPoint found for swarm index %d, point index %d\n",
-		__func__,
-		ref->swarm_I,
-		ref->particle_I );
-
-	return materialPoint;
-}
-
-MaterialPointsSwarm** _OneToOneMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
-	OneToOneMapper*			self = (OneToOneMapper*)mapper;
-	MaterialPointsSwarm**	result = Memory_Alloc_Array( MaterialPointsSwarm*, 1,  "Swarms" );
-
-	result[0] = self->materialSwarm;
-	*count = 1;
-
-	return result;
-}
-
-Material_Index _OneToOneMapper_GetMaterialIndexOn( void* mapper, void* point ) {
-	OneToOneMapper*	self = (OneToOneMapper*)mapper;
-	MaterialPoint*		materialPoint; /* Assumes that material swarm holds Material particle or derivative */
-	
-	materialPoint = OneToOneMapper_GetMaterialPoint( self, point, NULL );
-
-	return materialPoint->materialIndex;
-}
-
-void* _OneToOneMapper_GetExtensionOn( void* mapper, void* point, ExtensionInfo_Index extHandle ) {
-	OneToOneMapper*		self = (OneToOneMapper*)mapper;
-	MaterialPointsSwarm*	swarm;
-	MaterialPoint*			materialPoint; /* Assumes that material swarm holds Material particle or derivative */
-
-	materialPoint = OneToOneMapper_GetMaterialPoint( self, point, &swarm );
-
-	return ExtensionManager_Get( swarm->particleExtensionMgr, materialPoint, extHandle );
-}
-
-double _OneToOneMapper_GetDoubleFromExtension(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
-    return *(double*)(IntegrationPointMapper_GetExtensionOn(mapper, intPoint, extHandle) + offs);
-}
-
-double _OneToOneMapper_GetDoubleFromMaterial(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
-    MaterialPointsSwarm *matSwarm;
-    MaterialPoint *matPoint;
-
-    matPoint = OneToOneMapper_GetMaterialPoint(mapper, intPoint, &matSwarm);
-    return *(double*)(MaterialPointsSwarm_GetMaterialExtensionOn(matSwarm, matPoint, extHandle) + offs);
-}
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/OneToOneMapper.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/OneToOneMapper.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,211 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+const Type OneToOneMapper_Type = "OneToOneMapper";
+
+OneToOneMapper* _OneToOneMapper_New(  ONETOONEMAPPER_DEFARGS  ) {
+	OneToOneMapper* result;
+
+	result = (OneToOneMapper*)_IntegrationPointMapper_New(  INTEGRATIONPOINTMAPPER_PASSARGS  );
+
+	return result;
+}
+
+void _OneToOneMapper_Init( void* mapper, MaterialPointsSwarm* materialSwarm ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+	
+	self->errorStream = Journal_MyStream( Error_Type, self );
+	self->materialSwarm = materialSwarm;
+
+	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, False );
+	self->materialRefHandle = ExtensionManager_Add( self->integrationSwarm->particleExtensionMgr, materialSwarm->name, sizeof(MaterialPointRef)  );
+	ExtensionManager_SetLockDown( self->integrationSwarm->particleExtensionMgr, True );
+}
+
+void _OneToOneMapper_Delete( void* mapper ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+
+	_IntegrationPointMapper_Delete( self );
+}
+
+void _OneToOneMapper_Print( void* mapper, Stream* stream ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+	
+	_IntegrationPointMapper_Print( self, stream );
+	Stream_Indent( stream );
+	Stg_Class_Print( self->materialSwarm, stream );
+	Stream_UnIndent( stream );
+}
+
+void* _OneToOneMapper_Copy( const void* mapper, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+	OneToOneMapper* newCopy;
+	
+	newCopy = (OneToOneMapper*)_IntegrationPointMapper_Copy( self, dest, deep, nameExt, ptrMap );
+	newCopy->materialSwarm = (MaterialPointsSwarm*)Stg_Class_Copy( self->materialSwarm, NULL, deep, nameExt, ptrMap );
+
+	return newCopy;
+}
+
+void _OneToOneMapper_AssignFromXML( void* mapper, Stg_ComponentFactory* cf, void* data ) {
+	OneToOneMapper*		self = (OneToOneMapper*)mapper;
+	MaterialPointsSwarm*	materialSwarm;
+
+	_IntegrationPointMapper_AssignFromXML( self, cf, data );
+
+	materialSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)MaterialPointsSwarm_Type, MaterialPointsSwarm, True, data  );
+
+	_OneToOneMapper_Init( self, materialSwarm );
+}
+
+void _OneToOneMapper_Build( void* mapper, void* data ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+
+	_IntegrationPointMapper_Build( mapper, data );
+	Stg_Component_Build( self->materialSwarm, data, False );
+}
+
+void _OneToOneMapper_Initialise( void* mapper, void* data ) {
+    OneToOneMapper* self = (OneToOneMapper*)mapper;
+
+    _IntegrationPointMapper_Initialise( mapper, data );
+    Stg_Component_Initialise( self->materialSwarm, data, False );
+}
+
+void _OneToOneMapper_Execute( void* mapper, void* data ) {}
+
+void _OneToOneMapper_Destroy( void* mapper, void* data ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+
+	_IntegrationPointMapper_Destroy( self, data );
+}
+
+MaterialPointRef* OneToOneMapper_GetMaterialRef( void* mapper, void* integrationPoint ) {
+	OneToOneMapper* self = (OneToOneMapper*)mapper;
+
+	return (MaterialPointRef*)ExtensionManager_Get( self->integrationSwarm->particleExtensionMgr, integrationPoint, self->materialRefHandle );
+}
+
+MaterialPoint* OneToOneMapper_GetMaterialPoint( void* mapper, void* integrationPoint, MaterialPointsSwarm** materialSwarm ) {
+	OneToOneMapper*		self = (OneToOneMapper*)mapper;
+	MaterialPointRef*		ref;
+	MaterialPointsSwarm*	swarm;
+	MaterialPoint*			materialPoint; /* Assumes that material swarm holds Material particle or derivative */
+
+	ref = OneToOneMapper_GetMaterialRef( self, integrationPoint );
+	Journal_Firewall( ref != NULL, self->errorStream, "In func %s, no MaterialPointRef found on point\n", __func__ );
+
+	swarm = (MaterialPointsSwarm*)Swarm_Register_At( Swarm_Register_GetSwarm_Register(), ref->swarm_I );
+	Journal_Firewall( swarm != NULL, self->errorStream, "In func %s, no swarm found on for index %d\n", __func__, ref->swarm_I );
+
+	if ( materialSwarm != NULL ) {
+		*materialSwarm = swarm;
+	}
+
+	materialPoint = (MaterialPoint*)Swarm_ParticleAt( swarm, ref->particle_I );
+	Journal_Firewall(
+		materialPoint != NULL,
+		self->errorStream, 
+		"In func %s, no MaterialPoint found for swarm index %d, point index %d\n",
+		__func__,
+		ref->swarm_I,
+		ref->particle_I );
+
+	return materialPoint;
+}
+
+MaterialPointsSwarm** _OneToOneMapper_GetMaterialPointsSwarms( void* mapper, Index* count ) {
+	OneToOneMapper*			self = (OneToOneMapper*)mapper;
+	MaterialPointsSwarm**	result = Memory_Alloc_Array( MaterialPointsSwarm*, 1,  "Swarms" );
+
+	result[0] = self->materialSwarm;
+	*count = 1;
+
+	return result;
+}
+
+Material_Index _OneToOneMapper_GetMaterialIndexOn( void* mapper, void* point ) {
+	OneToOneMapper*	self = (OneToOneMapper*)mapper;
+	MaterialPoint*		materialPoint; /* Assumes that material swarm holds Material particle or derivative */
+	
+	materialPoint = OneToOneMapper_GetMaterialPoint( self, point, NULL );
+
+	return materialPoint->materialIndex;
+}
+
+void* _OneToOneMapper_GetExtensionOn( void* mapper, void* point, ExtensionInfo_Index extHandle ) {
+	OneToOneMapper*		self = (OneToOneMapper*)mapper;
+	MaterialPointsSwarm*	swarm;
+	MaterialPoint*			materialPoint; /* Assumes that material swarm holds Material particle or derivative */
+
+	materialPoint = OneToOneMapper_GetMaterialPoint( self, point, &swarm );
+
+	return ExtensionManager_Get( swarm->particleExtensionMgr, materialPoint, extHandle );
+}
+
+double _OneToOneMapper_GetDoubleFromExtension(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
+    return *(double*)(IntegrationPointMapper_GetExtensionOn(mapper, intPoint, extHandle) + offs);
+}
+
+double _OneToOneMapper_GetDoubleFromMaterial(void* mapper, void* intPoint, ExtensionInfo_Index extHandle, int offs) {
+    MaterialPointsSwarm *matSwarm;
+    MaterialPoint *matPoint;
+
+    matPoint = OneToOneMapper_GetMaterialPoint(mapper, intPoint, &matSwarm);
+    return *(double*)(MaterialPointsSwarm_GetMaterialExtensionOn(matSwarm, matPoint, extHandle) + offs);
+}
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/PICelleratorContext.c
--- a/MaterialPoints/src/PICelleratorContext.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,190 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Context.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "types.h"
-#include "Materials_Register.h"
-#include "Material.h"
-#include "PICelleratorContext.h"
-
-/* Textual name of this class */
-const Type PICelleratorContext_Type = "PICelleratorContext";
-
-/* Constructors ------------------------------------------------------------------------------------------------*/
-
-PICelleratorContext* PICelleratorContext_New( 
-	Name			name,
-	double		start,
-	double		stop,
-	MPI_Comm		communicator,
-	Dictionary*	dictionary )
-{
-  PICelleratorContext* self = (PICelleratorContext*)_PICelleratorContext_DefaultNew( name );
-
-	self->isConstructed = True;
-	_AbstractContext_Init( (AbstractContext*) self );
-	_DomainContext_Init( (DomainContext*) self );	
-	_FiniteElementContext_Init( (FiniteElementContext*) self );
-	_PICelleratorContext_Init( self );
-
-	return self;
-}	
-
-PICelleratorContext* _PICelleratorContext_New(  PICELLERATORCONTEXT_DEFARGS  ) {
-	PICelleratorContext* self;
-	
-	/* Allocate memory */
-	self = (PICelleratorContext*)_FiniteElementContext_New(  FINITEELEMENTCONTEXT_PASSARGS  );
-	
-	/* General info */
-	
-	/* Virtual info */
-	
-	return self;
-}
-
-void* _PICelleratorContext_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(PICelleratorContext);
-	Type                                                      type = PICelleratorContext_Type;
-	Stg_Class_DeleteFunction*                              _delete = _PICelleratorContext_Delete;
-	Stg_Class_PrintFunction*                                _print = _PICelleratorContext_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PICelleratorContext_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _PICelleratorContext_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AbstractContext_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _AbstractContext_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = (Stg_Component_ExecuteFunction*)_AbstractContext_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _PICelleratorContext_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	AbstractContext_SetDt*                                  _setDt = _PICelleratorContext_SetDt;
-	double                                               startTime = 0;
-	double                                                stopTime = 0;
-	MPI_Comm                                          communicator = MPI_COMM_WORLD;
-	Dictionary*                                         dictionary = NULL;
-
-	return (void*) _PICelleratorContext_New(  PICELLERATORCONTEXT_PASSARGS  );
-}
-
-void _PICelleratorContext_Init( void* context ) {
-	PICelleratorContext* self = (PICelleratorContext*)context;
-	self->isConstructed = True;
-
-	self->materials_Register = Materials_Register_New();
-
-	ContextEP_Prepend( self, AbstractContext_EP_AssignFromXMLExtensions, PICelleratorContext_CreateDefaultMaterial );
-
-/* 	 TODO want to append an EP to the end of the time integration that makes sure that after all integration  */
-/* 	 swarms have been updated, each element has at least one integration point from one swarm in it, or else */
-/* 	 we will fail the next timestep */
-}
-
-
-/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
-
-void _PICelleratorContext_Delete( void* context ) {
-	PICelleratorContext* self = (PICelleratorContext*)context;
-	
-	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
-
-	Stg_Class_Delete( self->materials_Register );
-
-	/* Stg_Class_Delete parent */
-	_FiniteElementContext_Delete( self );
-}
-
-void _PICelleratorContext_Destroy( void *component, void* context ) {
-	PICelleratorContext* self = (PICelleratorContext*)component;
-	
-	_FiniteElementContext_Destroy( self );
-}
-
-void _PICelleratorContext_Print( void* context, Stream* stream ) {
-	PICelleratorContext* self = (PICelleratorContext*)context;
-	
-	/* General info */
-	Journal_Printf( (void*) stream, "PICelleratorContext (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FiniteElementContext_Print( self, stream );
-
-	Journal_PrintPointer( stream, self->materials_Register );
-
-}
-
-void _PICelleratorContext_SetDt( void* context, double dt ) {
-	PICelleratorContext* self = (PICelleratorContext*)context;
-	
-	self->dt = dt;
-}
-
-
-/* Public Functions ----------------------------------------------------------------------------------------------------*/
-
-
-
-/* EntryPoint Hooks ----------------------------------------------------------------------------------------------------*/
-void PICelleratorContext_CreateDefaultMaterial( void* context ) {
-	PICelleratorContext* self = (PICelleratorContext*) context;
-	
-	if ( Materials_Register_GetCount( self->materials_Register ) == 0 ) {
-		Stg_Shape* everywhereShape = (Stg_Shape*) Everywhere_New( "defaultShape", self->dim );
-
-		Material_New( "backgroundMaterial", self, everywhereShape, self->dictionary, self->materials_Register );
-	}
-}
-
-void _PICelleratorContext_AssignFromXML( void* context, Stg_ComponentFactory *cf, void* data ){
-	PICelleratorContext* self = (PICelleratorContext*) context;
-	
-	_FiniteElementContext_AssignFromXML( context, cf, data );
-
-	_PICelleratorContext_Init( self );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/PICelleratorContext.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/PICelleratorContext.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,190 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Context.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "types.h"
+#include "Materials_Register.h"
+#include "Material.h"
+#include "PICelleratorContext.h"
+
+/* Textual name of this class */
+const Type PICelleratorContext_Type = "PICelleratorContext";
+
+/* Constructors ------------------------------------------------------------------------------------------------*/
+
+PICelleratorContext* PICelleratorContext_New( 
+	Name			name,
+	double		start,
+	double		stop,
+	MPI_Comm		communicator,
+	Dictionary*	dictionary )
+{
+  PICelleratorContext* self = (PICelleratorContext*)_PICelleratorContext_DefaultNew( name );
+
+	self->isConstructed = True;
+	_AbstractContext_Init( (AbstractContext*) self );
+	_DomainContext_Init( (DomainContext*) self );	
+	_FiniteElementContext_Init( (FiniteElementContext*) self );
+	_PICelleratorContext_Init( self );
+
+	return self;
+}	
+
+PICelleratorContext* _PICelleratorContext_New(  PICELLERATORCONTEXT_DEFARGS  ) {
+	PICelleratorContext* self;
+	
+	/* Allocate memory */
+	self = (PICelleratorContext*)_FiniteElementContext_New(  FINITEELEMENTCONTEXT_PASSARGS  );
+	
+	/* General info */
+	
+	/* Virtual info */
+	
+	return self;
+}
+
+void* _PICelleratorContext_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(PICelleratorContext);
+	Type                                                      type = PICelleratorContext_Type;
+	Stg_Class_DeleteFunction*                              _delete = _PICelleratorContext_Delete;
+	Stg_Class_PrintFunction*                                _print = _PICelleratorContext_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PICelleratorContext_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _PICelleratorContext_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AbstractContext_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _AbstractContext_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = (Stg_Component_ExecuteFunction*)_AbstractContext_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _PICelleratorContext_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	AbstractContext_SetDt*                                  _setDt = _PICelleratorContext_SetDt;
+	double                                               startTime = 0;
+	double                                                stopTime = 0;
+	MPI_Comm                                          communicator = MPI_COMM_WORLD;
+	Dictionary*                                         dictionary = NULL;
+
+	return (void*) _PICelleratorContext_New(  PICELLERATORCONTEXT_PASSARGS  );
+}
+
+void _PICelleratorContext_Init( void* context ) {
+	PICelleratorContext* self = (PICelleratorContext*)context;
+	self->isConstructed = True;
+
+	self->materials_Register = Materials_Register_New();
+
+	ContextEP_Prepend( self, AbstractContext_EP_AssignFromXMLExtensions, PICelleratorContext_CreateDefaultMaterial );
+
+/* 	 TODO want to append an EP to the end of the time integration that makes sure that after all integration  */
+/* 	 swarms have been updated, each element has at least one integration point from one swarm in it, or else */
+/* 	 we will fail the next timestep */
+}
+
+
+/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
+
+void _PICelleratorContext_Delete( void* context ) {
+	PICelleratorContext* self = (PICelleratorContext*)context;
+	
+	Journal_DPrintf( self->debug, "In: %s()\n", __func__ );
+
+	Stg_Class_Delete( self->materials_Register );
+
+	/* Stg_Class_Delete parent */
+	_FiniteElementContext_Delete( self );
+}
+
+void _PICelleratorContext_Destroy( void *component, void* context ) {
+	PICelleratorContext* self = (PICelleratorContext*)component;
+	
+	_FiniteElementContext_Destroy( self );
+}
+
+void _PICelleratorContext_Print( void* context, Stream* stream ) {
+	PICelleratorContext* self = (PICelleratorContext*)context;
+	
+	/* General info */
+	Journal_Printf( (void*) stream, "PICelleratorContext (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FiniteElementContext_Print( self, stream );
+
+	Journal_PrintPointer( stream, self->materials_Register );
+
+}
+
+void _PICelleratorContext_SetDt( void* context, double dt ) {
+	PICelleratorContext* self = (PICelleratorContext*)context;
+	
+	self->dt = dt;
+}
+
+
+/* Public Functions ----------------------------------------------------------------------------------------------------*/
+
+
+
+/* EntryPoint Hooks ----------------------------------------------------------------------------------------------------*/
+void PICelleratorContext_CreateDefaultMaterial( void* context ) {
+	PICelleratorContext* self = (PICelleratorContext*) context;
+	
+	if ( Materials_Register_GetCount( self->materials_Register ) == 0 ) {
+		Stg_Shape* everywhereShape = (Stg_Shape*) Everywhere_New( "defaultShape", self->dim );
+
+		Material_New( "backgroundMaterial", self, everywhereShape, self->dictionary, self->materials_Register );
+	}
+}
+
+void _PICelleratorContext_AssignFromXML( void* context, Stg_ComponentFactory *cf, void* data ){
+	PICelleratorContext* self = (PICelleratorContext*) context;
+	
+	_FiniteElementContext_AssignFromXML( context, cf, data );
+
+	_PICelleratorContext_Init( self );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/ParticleFeVariable.c
--- a/MaterialPoints/src/ParticleFeVariable.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,320 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: ParticleFeVariable.c 595 2008-09-11 05:26:49Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "MaterialPoints.h"
-
-#include <assert.h>
-
-const Type ParticleFeVariable_Type = "ParticleFeVariable";
-
-Name ParticleFeVariable_names[10];
-int ParticleFeVariable_nNames = 0;
-int ParticleFeVariable_curName = 0;
-
-ParticleFeVariable* _ParticleFeVariable_New(  PARTICLEFEVARIABLE_DEFARGS  ) {
-	ParticleFeVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(ParticleFeVariable) );
-	/* 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;
-	_syncShadowValues  = _FeVariable_SyncShadowValues;
-	_getMinGlobalFieldMagnitude = _FeVariable_GetMinGlobalFieldMagnitude;
-	_getMaxGlobalFieldMagnitude = _FeVariable_GetMaxGlobalFieldMagnitude;
-
-	self = (ParticleFeVariable*) _FeVariable_New(  FEVARIABLE_PASSARGS  );
-
-	self->_valueAtParticle = _valueAtParticle;
-	
-	return self;
-}
-
-void _ParticleFeVariable_Init( ParticleFeVariable* self, IntegrationPointsSwarm* swarm ) {
-	/* Create Vector */
-	self->assemblyVectorName = Stg_Object_AppendSuffix( self, (Name)"assemblyVector"  );
-	self->assemblyVector = ForceVector_New( 
-		self->assemblyVectorName,
-		(FiniteElementContext*) self->context,
-		(FeVariable*) self, 
-		self->dim, 
-		self->context->entryPoint_Register, 
-		self->communicator );
-	self->assemblyTerm = ForceTerm_New( "assemblyTerm", (FiniteElementContext*) self->context, self->assemblyVector, (Swarm*)swarm, (Stg_Component*) self );
-
-	self->massMatrixName = Stg_Object_AppendSuffix( self, (Name)"massMatrix"  );
-	self->massMatrix = ForceVector_New( 
-		self->massMatrixName,
-		(FiniteElementContext*) self->context,
-		(FeVariable*) self, 
-		self->dim, 
-		self->context->entryPoint_Register, 
-		self->communicator );
-	self->massMatrixForceTerm = ForceTerm_New( "massMatrixForceTerm", (FiniteElementContext*) self->context, self->massMatrix, (Swarm*)swarm, (Stg_Component*) self );
-	ForceTerm_SetAssembleElementFunction( self->massMatrixForceTerm, ParticleFeVariable_AssembleElementShapeFunc );
-   
-   /* Changed by PatrickSunter, 8/7/2009 - used to append onto stokesEqn-execute. However
-    * this component should work for other FE systems other than the Stokes solver */
-	EP_InsertClassHookBefore( Context_GetEntryPoint( self->context, AbstractContext_EP_UpdateClass ), "TimeIntegrator_UpdateClass", _ParticleFeVariable_Execute, self );
-	ParticleFeVariable_names[ParticleFeVariable_nNames++] = self->name;
-
-	self->useDeriv = False;
-	self->GNx = NULL;
-}
-
-/* --- Virtual Function Implementations --- */
-void _ParticleFeVariable_Delete( void* materialFeVariable ) {
-	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
-
-	_FeVariable_Delete( self );
-}
-
-void _ParticleFeVariable_Print( void* materialFeVariable, Stream* stream ) {
-	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
-	
-	/* General info */
-	Journal_Printf( stream, "ParticleFeVariable (ptr): %p\n", self );
-	
-	/* Print parent */
-	_FeVariable_Print( self, stream );
-	
-	/* ParticleFeVariable info */
-}
-
-void* _ParticleFeVariable_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	abort();
-	
-	return NULL;
-}
-
-void _ParticleFeVariable_AssignFromXML( void* materialFeVariable, Stg_ComponentFactory* cf, void* data ){
-	ParticleFeVariable*		self = (ParticleFeVariable*) materialFeVariable;
-	IntegrationPointsSwarm*	swarm;
-	FiniteElementContext*	context;
-	FeMesh*						mesh;
-
-	_FieldVariable_AssignFromXML( self, cf, data );
-
-	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", IntegrationPointsSwarm, True, data  );
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", FiniteElementContext, False, data  );
-	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", FeMesh, True, data );
-
-	_FeVariable_Init( (FeVariable* )self, mesh, NULL, NULL, NULL, NULL, NULL, NULL, False, False );
-	_ParticleFeVariable_Init( self, swarm );
-}
-
-void _ParticleFeVariable_Build( void* materialFeVariable, void* data ) {
-	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
-	int dataSize;
-
-	ForceTerm_SetAssembleElementFunction( self->assemblyTerm, ParticleFeVariable_AssembleElement );
-#if 0
-	if( self->useDeriv )
-	   ForceTerm_SetAssembleElementFunction( self->assemblyTerm, ParticleFeVariable_AssembleElement_Deriv );
-#endif
-	
-	Stg_Component_Build( self->feMesh, data, False );
-	dataSize = FeMesh_GetNodeDomainSize( self->feMesh ) * self->fieldComponentCount;
-	self->data = Memory_Alloc_Array( double, dataSize, "data" );
-
-	/* Do a Variable_Update() first as well as last, since if we are loading from checkpoint we need
-	to make sure the variable exists to put ICs onto - and we only just allocated it */
-	Stg_Component_Build( self->dataVariable, data, False );
-	Variable_Update( self->dataVariable );
-
-	_FeVariable_Build( self, data );
-
-	Stg_Component_Build( self->assemblyVector, data, False );
-	Stg_Component_Build( self->massMatrix, data, False );
-	Stg_Component_Build( self->assemblyTerm, data, False );
-
-	Variable_Update( self->dataVariable );
-}
-
-void _ParticleFeVariable_Initialise( void* materialFeVariable, void* data ) {
-	ParticleFeVariable*      self = (ParticleFeVariable*) materialFeVariable;
-	DomainContext*   context = (DomainContext*)data;
-
-	/* Do a Variable_Update() first as well as last, since if we are loading from checkpoint we need
-	to make sure the variable exists to put ICs onto */
-
-	Stg_Component_Initialise( self->assemblyVector, data, False );
-	Stg_Component_Initialise( self->massMatrix, data, False );
-	Stg_Component_Initialise( self->assemblyTerm, data, False );
-	Stg_Component_Initialise( self->dataVariable, data, False );
-	Variable_Update( self->dataVariable );
-
-	_FeVariable_Initialise( self, data );
-
-	Variable_Update( self->dataVariable );
-	/* If loading from CP, _don't_ recalculate the field as we've already just loaded it!
-		-- PatrickSunter 22 Nov 2006 */
-	if ( !(context && (True == context->loadFromCheckPoint)  ) ) {
-		ParticleFeVariable_Update( self );
-	}
-}
-
-void _ParticleFeVariable_Execute( void* materialFeVariable, void* _ctx ) {
-   AbstractContext* ctx = (AbstractContext*)_ctx;
-
-   if( ParticleFeVariable_curName >= ParticleFeVariable_nNames )
-      ParticleFeVariable_curName = 0;
-   ParticleFeVariable_Update( LiveComponentRegister_Get( ctx->CF->LCRegister, (Name)ParticleFeVariable_names[ParticleFeVariable_curName++] )  );
-}
-
-void _ParticleFeVariable_Destroy( void* materialFeVariable, void* data ) {
-	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
-
-	Memory_Free( self->assemblyVectorName );
-	Memory_Free( self->massMatrixName );
-	Memory_Free( self->data );
-
-	Stg_Component_Destroy( self->assemblyVector, data, False );
-	Stg_Component_Destroy( self->assemblyTerm, data, False );
-
-	Stg_Component_Destroy( self->massMatrix, data, False );
-	Stg_Component_Destroy( self->massMatrixForceTerm, data, False );
-
-	_FeVariable_Destroy( self, data );
-}
-
-void ParticleFeVariable_Update( void* materialFeVariable ) {
-	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
-
-	/* Initialise Vectors */
-	VecSet( self->assemblyVector->vector, 0.0 );
-	VecSet( self->massMatrix->vector, 0.0 );
-
-	ForceVector_Assemble( self->assemblyVector );
-	ForceVector_Assemble( self->massMatrix );
-
-	VecPointwiseDivide( self->assemblyVector->vector, self->assemblyVector->vector, self->massMatrix->vector );
-
-	SolutionVector_UpdateSolutionOntoNodes( self->assemblyVector );
-}
-
-void ParticleFeVariable_AssembleElement( void* _forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVector ) {
-	ForceTerm*                 forceTerm         = (ForceTerm*) _forceTerm;
-	ParticleFeVariable*        self              = Stg_CheckType( forceVector->feVariable, ParticleFeVariable );
-	IntegrationPointsSwarm*    swarm             = (IntegrationPointsSwarm*)forceTerm->integrationSwarm;
-	FeMesh*							mesh              = self->feMesh;
-	Element_NodeIndex          elementNodeCount  = FeMesh_GetElementNodeSize( mesh, lElement_I );
-	ElementType*               elementType       = FeMesh_GetElementType( mesh, lElement_I );
-	Cell_Index                 cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	Particle_InCellIndex       cellParticleCount;
-	Particle_InCellIndex       cParticle_I;
-	IntegrationPoint*          particle;
-	Node_Index                 node_I;
-	Dof_Index                  dofCount          = self->fieldComponentCount;
-	Dof_Index                  dof_I;
-	Dof_Index                  dim               = self->dim;
-	double                     shapeFunc[8], detJac;
-	double                     particleValue[9];
-
-	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-	
-	for( cParticle_I = 0 ; cParticle_I < cellParticleCount; cParticle_I++ ) {
-		/* Find this particle in the element */
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-
-		self->currentParticleIndex = swarm->cellParticleTbl[cell_I][cParticle_I];
-		ParticleFeVariable_ValueAtParticle( self, swarm, lElement_I, particle, particleValue );
-
-		/* get shape function and detJac */
-		ElementType_EvaluateShapeFunctionsAt( elementType, particle->xi, shapeFunc );
-		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, particle->xi, dim );
-
-		for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
-			for ( node_I = 0 ; node_I < elementNodeCount ; node_I++ ) {
-				elForceVector[ node_I * dofCount + dof_I ] += particle->weight * detJac * shapeFunc[ node_I ] * particleValue[ dof_I ]; 
-			}
-		}
-	}
-}
-
-void ParticleFeVariable_AssembleElementShapeFunc( void* _forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVector ) {
-	ForceTerm*                 forceTerm         = (ForceTerm*) _forceTerm;
-	ParticleFeVariable*        self              = Stg_CheckType( forceVector->feVariable, ParticleFeVariable );
-	Swarm*                     swarm             = forceTerm->integrationSwarm;
-	FeMesh*							mesh              = self->feMesh;
-	Element_NodeIndex          elementNodeCount  = FeMesh_GetElementNodeSize( mesh, lElement_I );
-	ElementType*               elementType       = FeMesh_GetElementType( mesh, lElement_I );
-	Cell_Index                 cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	int                        dim = Mesh_GetDimSize( mesh );
-	Particle_InCellIndex       cellParticleCount;
-	Particle_InCellIndex       cParticle_I;
-	IntegrationPoint*          particle;
-	double                     detJac;
-	double                     shapeFunc[8];
-	Node_Index                 node_I;
-	Dof_Index                  dofCount          = self->fieldComponentCount;
-	Dof_Index                  dof_I;
-
-	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-	
-	for( cParticle_I = 0 ; cParticle_I < cellParticleCount; cParticle_I++ ) {
-		/* Find this particle in the element */
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-
-		ElementType_EvaluateShapeFunctionsAt( elementType, particle->xi, shapeFunc );
-		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, particle->xi, dim );
-
-		for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
-			for ( node_I = 0 ; node_I < elementNodeCount ; node_I++ ) {
-			   elForceVector[ node_I * dofCount + dof_I ] += particle->weight * detJac * shapeFunc[node_I];
-			}
-		}
-	}
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/ParticleFeVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/ParticleFeVariable.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,320 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: ParticleFeVariable.c 595 2008-09-11 05:26:49Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "MaterialPoints.h"
+
+#include <assert.h>
+
+const Type ParticleFeVariable_Type = "ParticleFeVariable";
+
+Name ParticleFeVariable_names[10];
+int ParticleFeVariable_nNames = 0;
+int ParticleFeVariable_curName = 0;
+
+ParticleFeVariable* _ParticleFeVariable_New(  PARTICLEFEVARIABLE_DEFARGS  ) {
+	ParticleFeVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(ParticleFeVariable) );
+	/* 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;
+	_syncShadowValues  = _FeVariable_SyncShadowValues;
+	_getMinGlobalFieldMagnitude = _FeVariable_GetMinGlobalFieldMagnitude;
+	_getMaxGlobalFieldMagnitude = _FeVariable_GetMaxGlobalFieldMagnitude;
+
+	self = (ParticleFeVariable*) _FeVariable_New(  FEVARIABLE_PASSARGS  );
+
+	self->_valueAtParticle = _valueAtParticle;
+	
+	return self;
+}
+
+void _ParticleFeVariable_Init( ParticleFeVariable* self, IntegrationPointsSwarm* swarm ) {
+	/* Create Vector */
+	self->assemblyVectorName = Stg_Object_AppendSuffix( self, (Name)"assemblyVector"  );
+	self->assemblyVector = ForceVector_New( 
+		self->assemblyVectorName,
+		(FiniteElementContext*) self->context,
+		(FeVariable*) self, 
+		self->dim, 
+		self->context->entryPoint_Register, 
+		self->communicator );
+	self->assemblyTerm = ForceTerm_New( "assemblyTerm", (FiniteElementContext*) self->context, self->assemblyVector, (Swarm*)swarm, (Stg_Component*) self );
+
+	self->massMatrixName = Stg_Object_AppendSuffix( self, (Name)"massMatrix"  );
+	self->massMatrix = ForceVector_New( 
+		self->massMatrixName,
+		(FiniteElementContext*) self->context,
+		(FeVariable*) self, 
+		self->dim, 
+		self->context->entryPoint_Register, 
+		self->communicator );
+	self->massMatrixForceTerm = ForceTerm_New( "massMatrixForceTerm", (FiniteElementContext*) self->context, self->massMatrix, (Swarm*)swarm, (Stg_Component*) self );
+	ForceTerm_SetAssembleElementFunction( self->massMatrixForceTerm, ParticleFeVariable_AssembleElementShapeFunc );
+   
+   /* Changed by PatrickSunter, 8/7/2009 - used to append onto stokesEqn-execute. However
+    * this component should work for other FE systems other than the Stokes solver */
+	EP_InsertClassHookBefore( Context_GetEntryPoint( self->context, AbstractContext_EP_UpdateClass ), "TimeIntegrator_UpdateClass", _ParticleFeVariable_Execute, self );
+	ParticleFeVariable_names[ParticleFeVariable_nNames++] = self->name;
+
+	self->useDeriv = False;
+	self->GNx = NULL;
+}
+
+/* --- Virtual Function Implementations --- */
+void _ParticleFeVariable_Delete( void* materialFeVariable ) {
+	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
+
+	_FeVariable_Delete( self );
+}
+
+void _ParticleFeVariable_Print( void* materialFeVariable, Stream* stream ) {
+	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
+	
+	/* General info */
+	Journal_Printf( stream, "ParticleFeVariable (ptr): %p\n", self );
+	
+	/* Print parent */
+	_FeVariable_Print( self, stream );
+	
+	/* ParticleFeVariable info */
+}
+
+void* _ParticleFeVariable_Copy( const void* feVariable, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	abort();
+	
+	return NULL;
+}
+
+void _ParticleFeVariable_AssignFromXML( void* materialFeVariable, Stg_ComponentFactory* cf, void* data ){
+	ParticleFeVariable*		self = (ParticleFeVariable*) materialFeVariable;
+	IntegrationPointsSwarm*	swarm;
+	FiniteElementContext*	context;
+	FeMesh*						mesh;
+
+	_FieldVariable_AssignFromXML( self, cf, data );
+
+	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", IntegrationPointsSwarm, True, data  );
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", FiniteElementContext, False, data  );
+	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", FeMesh, True, data );
+
+	_FeVariable_Init( (FeVariable* )self, mesh, NULL, NULL, NULL, NULL, NULL, NULL, False, False );
+	_ParticleFeVariable_Init( self, swarm );
+}
+
+void _ParticleFeVariable_Build( void* materialFeVariable, void* data ) {
+	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
+	int dataSize;
+
+	ForceTerm_SetAssembleElementFunction( self->assemblyTerm, ParticleFeVariable_AssembleElement );
+#if 0
+	if( self->useDeriv )
+	   ForceTerm_SetAssembleElementFunction( self->assemblyTerm, ParticleFeVariable_AssembleElement_Deriv );
+#endif
+	
+	Stg_Component_Build( self->feMesh, data, False );
+	dataSize = FeMesh_GetNodeDomainSize( self->feMesh ) * self->fieldComponentCount;
+	self->data = Memory_Alloc_Array( double, dataSize, "data" );
+
+	/* Do a Variable_Update() first as well as last, since if we are loading from checkpoint we need
+	to make sure the variable exists to put ICs onto - and we only just allocated it */
+	Stg_Component_Build( self->dataVariable, data, False );
+	Variable_Update( self->dataVariable );
+
+	_FeVariable_Build( self, data );
+
+	Stg_Component_Build( self->assemblyVector, data, False );
+	Stg_Component_Build( self->massMatrix, data, False );
+	Stg_Component_Build( self->assemblyTerm, data, False );
+
+	Variable_Update( self->dataVariable );
+}
+
+void _ParticleFeVariable_Initialise( void* materialFeVariable, void* data ) {
+	ParticleFeVariable*      self = (ParticleFeVariable*) materialFeVariable;
+	DomainContext*   context = (DomainContext*)data;
+
+	/* Do a Variable_Update() first as well as last, since if we are loading from checkpoint we need
+	to make sure the variable exists to put ICs onto */
+
+	Stg_Component_Initialise( self->assemblyVector, data, False );
+	Stg_Component_Initialise( self->massMatrix, data, False );
+	Stg_Component_Initialise( self->assemblyTerm, data, False );
+	Stg_Component_Initialise( self->dataVariable, data, False );
+	Variable_Update( self->dataVariable );
+
+	_FeVariable_Initialise( self, data );
+
+	Variable_Update( self->dataVariable );
+	/* If loading from CP, _don't_ recalculate the field as we've already just loaded it!
+		-- PatrickSunter 22 Nov 2006 */
+	if ( !(context && (True == context->loadFromCheckPoint)  ) ) {
+		ParticleFeVariable_Update( self );
+	}
+}
+
+void _ParticleFeVariable_Execute( void* materialFeVariable, void* _ctx ) {
+   AbstractContext* ctx = (AbstractContext*)_ctx;
+
+   if( ParticleFeVariable_curName >= ParticleFeVariable_nNames )
+      ParticleFeVariable_curName = 0;
+   ParticleFeVariable_Update( LiveComponentRegister_Get( ctx->CF->LCRegister, (Name)ParticleFeVariable_names[ParticleFeVariable_curName++] )  );
+}
+
+void _ParticleFeVariable_Destroy( void* materialFeVariable, void* data ) {
+	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
+
+	Memory_Free( self->assemblyVectorName );
+	Memory_Free( self->massMatrixName );
+	Memory_Free( self->data );
+
+	Stg_Component_Destroy( self->assemblyVector, data, False );
+	Stg_Component_Destroy( self->assemblyTerm, data, False );
+
+	Stg_Component_Destroy( self->massMatrix, data, False );
+	Stg_Component_Destroy( self->massMatrixForceTerm, data, False );
+
+	_FeVariable_Destroy( self, data );
+}
+
+void ParticleFeVariable_Update( void* materialFeVariable ) {
+	ParticleFeVariable* self = (ParticleFeVariable*) materialFeVariable;
+
+	/* Initialise Vectors */
+	VecSet( self->assemblyVector->vector, 0.0 );
+	VecSet( self->massMatrix->vector, 0.0 );
+
+	ForceVector_Assemble( self->assemblyVector );
+	ForceVector_Assemble( self->massMatrix );
+
+	VecPointwiseDivide( self->assemblyVector->vector, self->assemblyVector->vector, self->massMatrix->vector );
+
+	SolutionVector_UpdateSolutionOntoNodes( self->assemblyVector );
+}
+
+void ParticleFeVariable_AssembleElement( void* _forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVector ) {
+	ForceTerm*                 forceTerm         = (ForceTerm*) _forceTerm;
+	ParticleFeVariable*        self              = Stg_CheckType( forceVector->feVariable, ParticleFeVariable );
+	IntegrationPointsSwarm*    swarm             = (IntegrationPointsSwarm*)forceTerm->integrationSwarm;
+	FeMesh*							mesh              = self->feMesh;
+	Element_NodeIndex          elementNodeCount  = FeMesh_GetElementNodeSize( mesh, lElement_I );
+	ElementType*               elementType       = FeMesh_GetElementType( mesh, lElement_I );
+	Cell_Index                 cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	Particle_InCellIndex       cellParticleCount;
+	Particle_InCellIndex       cParticle_I;
+	IntegrationPoint*          particle;
+	Node_Index                 node_I;
+	Dof_Index                  dofCount          = self->fieldComponentCount;
+	Dof_Index                  dof_I;
+	Dof_Index                  dim               = self->dim;
+	double                     shapeFunc[8], detJac;
+	double                     particleValue[9];
+
+	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+	
+	for( cParticle_I = 0 ; cParticle_I < cellParticleCount; cParticle_I++ ) {
+		/* Find this particle in the element */
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+
+		self->currentParticleIndex = swarm->cellParticleTbl[cell_I][cParticle_I];
+		ParticleFeVariable_ValueAtParticle( self, swarm, lElement_I, particle, particleValue );
+
+		/* get shape function and detJac */
+		ElementType_EvaluateShapeFunctionsAt( elementType, particle->xi, shapeFunc );
+		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, particle->xi, dim );
+
+		for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
+			for ( node_I = 0 ; node_I < elementNodeCount ; node_I++ ) {
+				elForceVector[ node_I * dofCount + dof_I ] += particle->weight * detJac * shapeFunc[ node_I ] * particleValue[ dof_I ]; 
+			}
+		}
+	}
+}
+
+void ParticleFeVariable_AssembleElementShapeFunc( void* _forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVector ) {
+	ForceTerm*                 forceTerm         = (ForceTerm*) _forceTerm;
+	ParticleFeVariable*        self              = Stg_CheckType( forceVector->feVariable, ParticleFeVariable );
+	Swarm*                     swarm             = forceTerm->integrationSwarm;
+	FeMesh*							mesh              = self->feMesh;
+	Element_NodeIndex          elementNodeCount  = FeMesh_GetElementNodeSize( mesh, lElement_I );
+	ElementType*               elementType       = FeMesh_GetElementType( mesh, lElement_I );
+	Cell_Index                 cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	int                        dim = Mesh_GetDimSize( mesh );
+	Particle_InCellIndex       cellParticleCount;
+	Particle_InCellIndex       cParticle_I;
+	IntegrationPoint*          particle;
+	double                     detJac;
+	double                     shapeFunc[8];
+	Node_Index                 node_I;
+	Dof_Index                  dofCount          = self->fieldComponentCount;
+	Dof_Index                  dof_I;
+
+	cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+	
+	for( cParticle_I = 0 ; cParticle_I < cellParticleCount; cParticle_I++ ) {
+		/* Find this particle in the element */
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+
+		ElementType_EvaluateShapeFunctionsAt( elementType, particle->xi, shapeFunc );
+		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, particle->xi, dim );
+
+		for ( dof_I = 0 ; dof_I < dofCount ; dof_I++ ) {
+			for ( node_I = 0 ; node_I < elementNodeCount ; node_I++ ) {
+			   elForceVector[ node_I * dofCount + dof_I ] += particle->weight * detJac * shapeFunc[node_I];
+			}
+		}
+	}
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/PeriodicBoundariesManager.c
--- a/MaterialPoints/src/PeriodicBoundariesManager.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,379 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: PeriodicBoundariesManager.c 569 2008-05-14 02:42:54Z LukeHodkinson $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "PICelleratorContext.h"
-#include "PeriodicBoundariesManager.h"
-
-#include <string.h>
-#include <assert.h>
-
-char IJKTopology_DimNumToDimLetter[3] = {'I', 'J', 'K'};
-
-/* Textual name of this class */
-const Type PeriodicBoundariesManager_Type = "PeriodicBoundariesManager";
-
-/* Constructors ------------------------------------------------------------------------------------------------*/
-PeriodicBoundariesManager* PeriodicBoundariesManager_New( 
-	Name						name,
-	PICelleratorContext*	context,
-	Mesh*						mesh, 
-	Swarm*					swarm,
-	Dictionary*				dictionary )
-{
-  PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)_PeriodicBoundariesManager_DefaultNew( name );
-
-	self->isConstructed = True;
-	_PeriodicBoundariesManager_Init( self, context, mesh, swarm, dictionary );
-
-	return self;
-}	
-
-void* _PeriodicBoundariesManager_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(PeriodicBoundariesManager);
-	Type                                                      type = PeriodicBoundariesManager_Type;
-	Stg_Class_DeleteFunction*                              _delete = _PeriodicBoundariesManager_Delete;
-	Stg_Class_PrintFunction*                                _print = _PeriodicBoundariesManager_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PeriodicBoundariesManager_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _PeriodicBoundariesManager_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _PeriodicBoundariesManager_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _PeriodicBoundariesManager_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _PeriodicBoundariesManager_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _PeriodicBoundariesManager_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-
-	return (void*) _PeriodicBoundariesManager_New(  PERIODICBOUNDARIESMANAGER_PASSARGS  );
-}
-
-PeriodicBoundariesManager* _PeriodicBoundariesManager_New(  PERIODICBOUNDARIESMANAGER_DEFARGS  ) {
-	PeriodicBoundariesManager* self;
-	
-	/* Allocate memory */
-	self = (PeriodicBoundariesManager*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* General info */
-	
-	/* Virtual info */
-	
-	return self;
-}
-
-void _PeriodicBoundariesManager_Init(
-	void*						periodicBCsManager,
-	PICelleratorContext*	context,
-	Mesh*						mesh, 
-	Swarm*					swarm,
-	Dictionary*				dictionary )
-{
-	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
-
-	self->context = context;
-	self->dictionary = dictionary;
-	self->mesh = mesh;
-	self->swarm = swarm;
-	self->count = 0;
-	self->delta = 0;
-	self->size = 0;
-	self->boundaries = NULL;
-	self->debug = Journal_Register( Debug_Type, (Name)self->type  );
-}
-
-void _PeriodicBoundariesManager_AssignFromXML( void* periodicBCsManager, Stg_ComponentFactory* cf, void* data ) {
-	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
-	Dictionary*						dictionary = NULL;
-	Mesh*								mesh = NULL;
-	Swarm*							swarm = NULL;
-	PICelleratorContext*			context;
-
-	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
-	if( !context  ) 
-		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );
-
-	dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
-	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
-	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data  );
-
-	_PeriodicBoundariesManager_Init( self, context, mesh, swarm, dictionary );
-}
-
-void _PeriodicBoundariesManager_Delete( void* perBCsManager ) {
-	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)perBCsManager;
-	
-	/* Stg_Class_Delete parent */
-	_Stg_Component_Delete( self );
-}
-
-/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
-
-void _PeriodicBoundariesManager_Print( void* perBCsManager, Stream* stream ) {
-	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)perBCsManager;
-	Index								perBoundary_I = 0;
-	
-	/* General info */
-	Journal_Printf( stream, "PeriodicBoundariesManager (ptr): %p\n", self );
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-
-	Journal_Printf( stream, "%d periodic boundaries registered: %p\n", self );
-	Stream_Indent( stream );
-
-	for ( perBoundary_I = 0; perBoundary_I < self->count; perBoundary_I++ ) {
-		Journal_Printf( stream, "Boundary %d: Axis %d, Min=%f, Max=%f\n", perBoundary_I,
-			self->boundaries[perBoundary_I].axis,
-			self->boundaries[perBoundary_I].minWall,
-			self->boundaries[perBoundary_I].maxWall );
-	}
-	Stream_UnIndent( stream );
-}
-
-void* _PeriodicBoundariesManager_Copy( const void* periodicBCsManager, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
-	PeriodicBoundariesManager*	newPeriodicBCsManager;
-	PtrMap*							map = ptrMap;
-	Bool								ownMap = False;
-	
-	if( !map ) {
-		map = PtrMap_New( 10 );
-		ownMap = True;
-	}
-
-	newPeriodicBCsManager = (PeriodicBoundariesManager*)_Stg_Class_Copy( self, dest, deep, nameExt, map );
-
-	newPeriodicBCsManager->count = self->count;
-	newPeriodicBCsManager->size = self->size;
-	newPeriodicBCsManager->delta = self->delta;
-
-	if ( deep ) {
-		newPeriodicBCsManager->dictionary = (Dictionary*)Stg_Class_Copy( self->dictionary, NULL, deep, nameExt, map );
-		newPeriodicBCsManager->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
-		newPeriodicBCsManager->swarm = (Swarm*)Stg_Class_Copy( self->swarm, NULL, deep, nameExt, map );
-		newPeriodicBCsManager->debug = self->debug;
-		newPeriodicBCsManager->boundaries = Memory_Alloc_Array( PeriodicBoundary, self->size, "PeriodicBoundaries" );
-		memcpy( newPeriodicBCsManager->boundaries, self->boundaries, sizeof(PeriodicBoundary)*self->count );	
-	}
-	else {
-		newPeriodicBCsManager->dictionary = self->dictionary;
-		newPeriodicBCsManager->mesh = self->mesh;
-		newPeriodicBCsManager->swarm = self->swarm;
-		newPeriodicBCsManager->boundaries = self->boundaries;
-		newPeriodicBCsManager->debug = self->debug;
-	}
-	
-	if( ownMap ) {
-		Stg_Class_Delete( map );
-	}
-	
-	return (void*)newPeriodicBCsManager;
-}
-
-void _PeriodicBoundariesManager_Build( void* periodicBCsManager, void* data ) {	
-	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
-	Dictionary_Entry_Value*    periodicBCsList = NULL;
-
-	Stg_Component_Build( self->swarm, data, False );
-	Stg_Component_Build( self->mesh, data, False );
-	self->size = 4;
-	self->boundaries = Memory_Alloc_Array( PeriodicBoundary, self->size, "PeriodicBoundariesManager->boundaries" );
-
-	if ( self->dictionary ) {
-		periodicBCsList = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"PeriodicBoundaries" );
-		
-		/* Dictionary entry is optional - users may prefer to enter in code */
-		if ( periodicBCsList ) {
-			Index                   numPeriodicBCs = 0;
-			Index                   periodicBC_I = 0;
-			Dictionary_Entry_Value* periodicBC = NULL;
-			char*                   perBCAxis = NULL;
-			
-			numPeriodicBCs = Dictionary_Entry_Value_GetCount( periodicBCsList );
-
-			for ( periodicBC_I = 0; periodicBC_I < numPeriodicBCs; periodicBC_I++  ) {
-				periodicBC = Dictionary_Entry_Value_GetElement( periodicBCsList, periodicBC_I );
-				perBCAxis = Dictionary_Entry_Value_AsString( periodicBC );
-
-				if ( 0 == strcmp( perBCAxis, "I_AXIS" ) ) {
-					PeriodicBoundariesManager_AddPeriodicBoundary( self, I_AXIS );
-				}
-				else if ( 0 == strcmp( perBCAxis, "J_AXIS" ) ) {
-					PeriodicBoundariesManager_AddPeriodicBoundary( self, J_AXIS );
-				}
-				else if ( 0 == strcmp( perBCAxis, "K_AXIS" ) ) {
-					PeriodicBoundariesManager_AddPeriodicBoundary( self, K_AXIS );
-				}
-			}
-		}
-	}
-	/* Test if mesh is periodic */
-	else if ( Stg_Class_IsInstance( self->mesh->generator, CartesianGenerator_Type ) ) {
-		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) self->mesh->generator;
-		Dimension_Index dim_I;
-
-		for ( dim_I = 0 ; dim_I < self->swarm->dim ; dim_I++ ) {
-			/* Add boundaries straight from mesh generator */
-			if ( cartesianGenerator->periodic[ dim_I ] ) 
-                          PeriodicBoundariesManager_AddPeriodicBoundary( self, (Axis)dim_I );
-		}		
-	}
-}
-
-void _PeriodicBoundariesManager_Initialise( void* periodicBCsManager, void* data ) {
-	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
-
-	Stg_Component_Initialise( self->swarm, data, False );
-	Stg_Component_Initialise( self->mesh, data, False );
-}
-
-void _PeriodicBoundariesManager_Execute( void* periodicBCsManager, void* data ) {	
-}
-
-void _PeriodicBoundariesManager_Destroy( void* periodicBCsManager, void* data ) {	
-	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
-
-	Stg_Component_Destroy( self->swarm, data, False );
-	Stg_Component_Destroy( self->mesh, data, False );
-
-	Memory_Free( self->boundaries );
-}
-
-/* Public Functions -------------------------------------------------------------------------------------------------------------*/
-
-void PeriodicBoundariesManager_AddPeriodicBoundary( void* periodicBCsManager, Axis axis ) {
-	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;	
-	PeriodicBoundary*				newPeriodicBoundary;
-	double							min[3], max[3];
-
-	Mesh_GetGlobalCoordRange( self->mesh, min, max );
-	
-	if ( self->count == self->size ) {
-		self->size += self->delta;
-		self->boundaries = Memory_Realloc_Array( self->boundaries, PeriodicBoundary, self->size );
-	}
-
-	newPeriodicBoundary = &self->boundaries[self->count];
-	newPeriodicBoundary->axis = axis;
-	newPeriodicBoundary->minWall = min[axis];
-	newPeriodicBoundary->maxWall = max[axis];
-	newPeriodicBoundary->particlesUpdatedMinEndCount = 0;	
-	newPeriodicBoundary->particlesUpdatedMaxEndCount = 0;	
-	self->count++;
-}
-
-void PeriodicBoundariesManager_UpdateParticle( void* periodicBCsManager, Particle_Index lParticle_I ) {
-	Axis								boundaryAxis;	
-	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
-	double							difference = 0.0;
-	GlobalParticle*				particle = NULL;
-	Index								perBoundary_I = 0;
-	PeriodicBoundary*				perBoundary = NULL;
-
-	Journal_DPrintfL( self->debug, 2, "In %s:\n", __func__ );
-	Stream_Indent( self->debug );
-
-	particle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
-
-	Journal_DPrintfL( self->debug, 2, "Checking particle %d at (%.4g,%.4g,%.4g)\n", lParticle_I, particle->coord[0], particle->coord[1], particle->coord[2] );
-
-	for ( perBoundary_I = 0; perBoundary_I < self->count; perBoundary_I++ ) {
-		perBoundary = &self->boundaries[perBoundary_I];
-		boundaryAxis = perBoundary->axis;
-
-		Journal_DPrintfL( self->debug, 2, "Checking axis %d:\n", boundaryAxis );
-		Stream_Indent( self->debug );
-
-		if ( particle->coord[boundaryAxis] < perBoundary->minWall ) {
-			Journal_DPrintfL( self->debug, 3, "coord is < min wall %.4f:\n", perBoundary->minWall );
-			difference = perBoundary->minWall - particle->coord[boundaryAxis];
-			particle->coord[boundaryAxis] = perBoundary->maxWall - difference;
-			perBoundary->particlesUpdatedMinEndCount++;
-			Journal_DPrintfL( self->debug, 3, "moving to (%.4f,%.4f,%.4f).\n", particle->coord[I_AXIS], particle->coord[J_AXIS], particle->coord[K_AXIS] );
-		}
-		else if ( particle->coord[perBoundary->axis] > perBoundary->maxWall ) {
-			Journal_DPrintfL( self->debug, 3, "coord is > max wall %.4f:\n", perBoundary->maxWall );
-			difference = particle->coord[boundaryAxis] - perBoundary->maxWall; 
-			particle->coord[boundaryAxis] = perBoundary->minWall + difference;
-			perBoundary->particlesUpdatedMaxEndCount++;
-			Journal_DPrintfL( self->debug, 3, "moving to (%.4f,%.4f,%.4f).\n", particle->coord[I_AXIS], particle->coord[J_AXIS], particle->coord[K_AXIS] );
-		}
-		Stream_UnIndent( self->debug );
-	}	
-
-	Stream_UnIndent( self->debug );
-
-	/* TODO: this is a bit of a hack to print this here using the lParticleI = swarm->total - 1, but its
-	the only way I can see given this func is part of the SwarmAdvector intermediate. Should really be a 
-	function on this class that updates all the particles. -- Main.PatrickSunter 15 May 2006 */
-	if ( lParticle_I == (self->swarm->particleLocalCount-1) ) {
-		PeriodicBoundary*	boundary = NULL;
-		Index					perB_I;
-	
-		Journal_DPrintfL( self->debug, 1, "PeriodicBoundariesManager total particles updated:\n" );
-		Stream_Indent( self->debug );
-
-		for ( perB_I = 0; perB_I < self->count; perB_I++ ) {
-			boundary = &self->boundaries[perB_I];
-
-			Journal_DPrintfL( self->debug, 1, "Periodic Boundary in %c Axis {%.2f,%.2f}: %d min end, %d max end\n",
-				IJKTopology_DimNumToDimLetter[boundary->axis], boundary->minWall, boundary->maxWall,
-				boundary->particlesUpdatedMinEndCount, boundary->particlesUpdatedMaxEndCount );
-			/* Reset the counters for next time */
-			boundary->particlesUpdatedMinEndCount = 0;	
-			boundary->particlesUpdatedMaxEndCount = 0;	
-		}
-		Stream_UnIndent( self->debug );
-	}
-}	
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/PeriodicBoundariesManager.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/PeriodicBoundariesManager.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,379 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: PeriodicBoundariesManager.c 569 2008-05-14 02:42:54Z LukeHodkinson $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "PICelleratorContext.h"
+#include "PeriodicBoundariesManager.h"
+
+#include <string.h>
+#include <assert.h>
+
+char IJKTopology_DimNumToDimLetter[3] = {'I', 'J', 'K'};
+
+/* Textual name of this class */
+const Type PeriodicBoundariesManager_Type = "PeriodicBoundariesManager";
+
+/* Constructors ------------------------------------------------------------------------------------------------*/
+PeriodicBoundariesManager* PeriodicBoundariesManager_New( 
+	Name						name,
+	PICelleratorContext*	context,
+	Mesh*						mesh, 
+	Swarm*					swarm,
+	Dictionary*				dictionary )
+{
+  PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)_PeriodicBoundariesManager_DefaultNew( name );
+
+	self->isConstructed = True;
+	_PeriodicBoundariesManager_Init( self, context, mesh, swarm, dictionary );
+
+	return self;
+}	
+
+void* _PeriodicBoundariesManager_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(PeriodicBoundariesManager);
+	Type                                                      type = PeriodicBoundariesManager_Type;
+	Stg_Class_DeleteFunction*                              _delete = _PeriodicBoundariesManager_Delete;
+	Stg_Class_PrintFunction*                                _print = _PeriodicBoundariesManager_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PeriodicBoundariesManager_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _PeriodicBoundariesManager_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _PeriodicBoundariesManager_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _PeriodicBoundariesManager_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _PeriodicBoundariesManager_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _PeriodicBoundariesManager_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+
+	return (void*) _PeriodicBoundariesManager_New(  PERIODICBOUNDARIESMANAGER_PASSARGS  );
+}
+
+PeriodicBoundariesManager* _PeriodicBoundariesManager_New(  PERIODICBOUNDARIESMANAGER_DEFARGS  ) {
+	PeriodicBoundariesManager* self;
+	
+	/* Allocate memory */
+	self = (PeriodicBoundariesManager*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* General info */
+	
+	/* Virtual info */
+	
+	return self;
+}
+
+void _PeriodicBoundariesManager_Init(
+	void*						periodicBCsManager,
+	PICelleratorContext*	context,
+	Mesh*						mesh, 
+	Swarm*					swarm,
+	Dictionary*				dictionary )
+{
+	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
+
+	self->context = context;
+	self->dictionary = dictionary;
+	self->mesh = mesh;
+	self->swarm = swarm;
+	self->count = 0;
+	self->delta = 0;
+	self->size = 0;
+	self->boundaries = NULL;
+	self->debug = Journal_Register( Debug_Type, (Name)self->type  );
+}
+
+void _PeriodicBoundariesManager_AssignFromXML( void* periodicBCsManager, Stg_ComponentFactory* cf, void* data ) {
+	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
+	Dictionary*						dictionary = NULL;
+	Mesh*								mesh = NULL;
+	Swarm*							swarm = NULL;
+	PICelleratorContext*			context;
+
+	context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", PICelleratorContext, False, data );
+	if( !context  ) 
+		context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", PICelleratorContext, True, data  );
+
+	dictionary = Dictionary_GetDictionary( cf->componentDict, self->name );
+	mesh = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"mesh", Mesh, True, data  );
+	swarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", Swarm, True, data  );
+
+	_PeriodicBoundariesManager_Init( self, context, mesh, swarm, dictionary );
+}
+
+void _PeriodicBoundariesManager_Delete( void* perBCsManager ) {
+	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)perBCsManager;
+	
+	/* Stg_Class_Delete parent */
+	_Stg_Component_Delete( self );
+}
+
+/* Virtual Functions -------------------------------------------------------------------------------------------------------------*/
+
+void _PeriodicBoundariesManager_Print( void* perBCsManager, Stream* stream ) {
+	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)perBCsManager;
+	Index								perBoundary_I = 0;
+	
+	/* General info */
+	Journal_Printf( stream, "PeriodicBoundariesManager (ptr): %p\n", self );
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+
+	Journal_Printf( stream, "%d periodic boundaries registered: %p\n", self );
+	Stream_Indent( stream );
+
+	for ( perBoundary_I = 0; perBoundary_I < self->count; perBoundary_I++ ) {
+		Journal_Printf( stream, "Boundary %d: Axis %d, Min=%f, Max=%f\n", perBoundary_I,
+			self->boundaries[perBoundary_I].axis,
+			self->boundaries[perBoundary_I].minWall,
+			self->boundaries[perBoundary_I].maxWall );
+	}
+	Stream_UnIndent( stream );
+}
+
+void* _PeriodicBoundariesManager_Copy( const void* periodicBCsManager, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
+	PeriodicBoundariesManager*	newPeriodicBCsManager;
+	PtrMap*							map = ptrMap;
+	Bool								ownMap = False;
+	
+	if( !map ) {
+		map = PtrMap_New( 10 );
+		ownMap = True;
+	}
+
+	newPeriodicBCsManager = (PeriodicBoundariesManager*)_Stg_Class_Copy( self, dest, deep, nameExt, map );
+
+	newPeriodicBCsManager->count = self->count;
+	newPeriodicBCsManager->size = self->size;
+	newPeriodicBCsManager->delta = self->delta;
+
+	if ( deep ) {
+		newPeriodicBCsManager->dictionary = (Dictionary*)Stg_Class_Copy( self->dictionary, NULL, deep, nameExt, map );
+		newPeriodicBCsManager->mesh = (Mesh*)Stg_Class_Copy( self->mesh, NULL, deep, nameExt, map );
+		newPeriodicBCsManager->swarm = (Swarm*)Stg_Class_Copy( self->swarm, NULL, deep, nameExt, map );
+		newPeriodicBCsManager->debug = self->debug;
+		newPeriodicBCsManager->boundaries = Memory_Alloc_Array( PeriodicBoundary, self->size, "PeriodicBoundaries" );
+		memcpy( newPeriodicBCsManager->boundaries, self->boundaries, sizeof(PeriodicBoundary)*self->count );	
+	}
+	else {
+		newPeriodicBCsManager->dictionary = self->dictionary;
+		newPeriodicBCsManager->mesh = self->mesh;
+		newPeriodicBCsManager->swarm = self->swarm;
+		newPeriodicBCsManager->boundaries = self->boundaries;
+		newPeriodicBCsManager->debug = self->debug;
+	}
+	
+	if( ownMap ) {
+		Stg_Class_Delete( map );
+	}
+	
+	return (void*)newPeriodicBCsManager;
+}
+
+void _PeriodicBoundariesManager_Build( void* periodicBCsManager, void* data ) {	
+	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
+	Dictionary_Entry_Value*    periodicBCsList = NULL;
+
+	Stg_Component_Build( self->swarm, data, False );
+	Stg_Component_Build( self->mesh, data, False );
+	self->size = 4;
+	self->boundaries = Memory_Alloc_Array( PeriodicBoundary, self->size, "PeriodicBoundariesManager->boundaries" );
+
+	if ( self->dictionary ) {
+		periodicBCsList = Dictionary_Get( self->dictionary, (Dictionary_Entry_Key)"PeriodicBoundaries" );
+		
+		/* Dictionary entry is optional - users may prefer to enter in code */
+		if ( periodicBCsList ) {
+			Index                   numPeriodicBCs = 0;
+			Index                   periodicBC_I = 0;
+			Dictionary_Entry_Value* periodicBC = NULL;
+			char*                   perBCAxis = NULL;
+			
+			numPeriodicBCs = Dictionary_Entry_Value_GetCount( periodicBCsList );
+
+			for ( periodicBC_I = 0; periodicBC_I < numPeriodicBCs; periodicBC_I++  ) {
+				periodicBC = Dictionary_Entry_Value_GetElement( periodicBCsList, periodicBC_I );
+				perBCAxis = Dictionary_Entry_Value_AsString( periodicBC );
+
+				if ( 0 == strcmp( perBCAxis, "I_AXIS" ) ) {
+					PeriodicBoundariesManager_AddPeriodicBoundary( self, I_AXIS );
+				}
+				else if ( 0 == strcmp( perBCAxis, "J_AXIS" ) ) {
+					PeriodicBoundariesManager_AddPeriodicBoundary( self, J_AXIS );
+				}
+				else if ( 0 == strcmp( perBCAxis, "K_AXIS" ) ) {
+					PeriodicBoundariesManager_AddPeriodicBoundary( self, K_AXIS );
+				}
+			}
+		}
+	}
+	/* Test if mesh is periodic */
+	else if ( Stg_Class_IsInstance( self->mesh->generator, CartesianGenerator_Type ) ) {
+		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) self->mesh->generator;
+		Dimension_Index dim_I;
+
+		for ( dim_I = 0 ; dim_I < self->swarm->dim ; dim_I++ ) {
+			/* Add boundaries straight from mesh generator */
+			if ( cartesianGenerator->periodic[ dim_I ] ) 
+                          PeriodicBoundariesManager_AddPeriodicBoundary( self, (Axis)dim_I );
+		}		
+	}
+}
+
+void _PeriodicBoundariesManager_Initialise( void* periodicBCsManager, void* data ) {
+	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
+
+	Stg_Component_Initialise( self->swarm, data, False );
+	Stg_Component_Initialise( self->mesh, data, False );
+}
+
+void _PeriodicBoundariesManager_Execute( void* periodicBCsManager, void* data ) {	
+}
+
+void _PeriodicBoundariesManager_Destroy( void* periodicBCsManager, void* data ) {	
+	PeriodicBoundariesManager* self = (PeriodicBoundariesManager*)periodicBCsManager;
+
+	Stg_Component_Destroy( self->swarm, data, False );
+	Stg_Component_Destroy( self->mesh, data, False );
+
+	Memory_Free( self->boundaries );
+}
+
+/* Public Functions -------------------------------------------------------------------------------------------------------------*/
+
+void PeriodicBoundariesManager_AddPeriodicBoundary( void* periodicBCsManager, Axis axis ) {
+	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;	
+	PeriodicBoundary*				newPeriodicBoundary;
+	double							min[3], max[3];
+
+	Mesh_GetGlobalCoordRange( self->mesh, min, max );
+	
+	if ( self->count == self->size ) {
+		self->size += self->delta;
+		self->boundaries = Memory_Realloc_Array( self->boundaries, PeriodicBoundary, self->size );
+	}
+
+	newPeriodicBoundary = &self->boundaries[self->count];
+	newPeriodicBoundary->axis = axis;
+	newPeriodicBoundary->minWall = min[axis];
+	newPeriodicBoundary->maxWall = max[axis];
+	newPeriodicBoundary->particlesUpdatedMinEndCount = 0;	
+	newPeriodicBoundary->particlesUpdatedMaxEndCount = 0;	
+	self->count++;
+}
+
+void PeriodicBoundariesManager_UpdateParticle( void* periodicBCsManager, Particle_Index lParticle_I ) {
+	Axis								boundaryAxis;	
+	PeriodicBoundariesManager*	self = (PeriodicBoundariesManager*)periodicBCsManager;
+	double							difference = 0.0;
+	GlobalParticle*				particle = NULL;
+	Index								perBoundary_I = 0;
+	PeriodicBoundary*				perBoundary = NULL;
+
+	Journal_DPrintfL( self->debug, 2, "In %s:\n", __func__ );
+	Stream_Indent( self->debug );
+
+	particle = (GlobalParticle*)Swarm_ParticleAt( self->swarm, lParticle_I );
+
+	Journal_DPrintfL( self->debug, 2, "Checking particle %d at (%.4g,%.4g,%.4g)\n", lParticle_I, particle->coord[0], particle->coord[1], particle->coord[2] );
+
+	for ( perBoundary_I = 0; perBoundary_I < self->count; perBoundary_I++ ) {
+		perBoundary = &self->boundaries[perBoundary_I];
+		boundaryAxis = perBoundary->axis;
+
+		Journal_DPrintfL( self->debug, 2, "Checking axis %d:\n", boundaryAxis );
+		Stream_Indent( self->debug );
+
+		if ( particle->coord[boundaryAxis] < perBoundary->minWall ) {
+			Journal_DPrintfL( self->debug, 3, "coord is < min wall %.4f:\n", perBoundary->minWall );
+			difference = perBoundary->minWall - particle->coord[boundaryAxis];
+			particle->coord[boundaryAxis] = perBoundary->maxWall - difference;
+			perBoundary->particlesUpdatedMinEndCount++;
+			Journal_DPrintfL( self->debug, 3, "moving to (%.4f,%.4f,%.4f).\n", particle->coord[I_AXIS], particle->coord[J_AXIS], particle->coord[K_AXIS] );
+		}
+		else if ( particle->coord[perBoundary->axis] > perBoundary->maxWall ) {
+			Journal_DPrintfL( self->debug, 3, "coord is > max wall %.4f:\n", perBoundary->maxWall );
+			difference = particle->coord[boundaryAxis] - perBoundary->maxWall; 
+			particle->coord[boundaryAxis] = perBoundary->minWall + difference;
+			perBoundary->particlesUpdatedMaxEndCount++;
+			Journal_DPrintfL( self->debug, 3, "moving to (%.4f,%.4f,%.4f).\n", particle->coord[I_AXIS], particle->coord[J_AXIS], particle->coord[K_AXIS] );
+		}
+		Stream_UnIndent( self->debug );
+	}	
+
+	Stream_UnIndent( self->debug );
+
+	/* TODO: this is a bit of a hack to print this here using the lParticleI = swarm->total - 1, but its
+	the only way I can see given this func is part of the SwarmAdvector intermediate. Should really be a 
+	function on this class that updates all the particles. -- Main.PatrickSunter 15 May 2006 */
+	if ( lParticle_I == (self->swarm->particleLocalCount-1) ) {
+		PeriodicBoundary*	boundary = NULL;
+		Index					perB_I;
+	
+		Journal_DPrintfL( self->debug, 1, "PeriodicBoundariesManager total particles updated:\n" );
+		Stream_Indent( self->debug );
+
+		for ( perB_I = 0; perB_I < self->count; perB_I++ ) {
+			boundary = &self->boundaries[perB_I];
+
+			Journal_DPrintfL( self->debug, 1, "Periodic Boundary in %c Axis {%.2f,%.2f}: %d min end, %d max end\n",
+				IJKTopology_DimNumToDimLetter[boundary->axis], boundary->minWall, boundary->maxWall,
+				boundary->particlesUpdatedMinEndCount, boundary->particlesUpdatedMaxEndCount );
+			/* Reset the counters for next time */
+			boundary->particlesUpdatedMinEndCount = 0;	
+			boundary->particlesUpdatedMaxEndCount = 0;	
+		}
+		Stream_UnIndent( self->debug );
+	}
+}	
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/SwarmAdvectionInAPlane.c
--- a/MaterialPoints/src/SwarmAdvectionInAPlane.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,212 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "SwarmAdvector.h"
-#include "SwarmAdvectionInAPlane.h"
-
-#include "MaterialPointsSwarm.h"
-#include "PeriodicBoundariesManager.h"
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/*I am generalising this so that I can use it- Wendy S*/
-
-
-/* Textual name of this class */
-const Type SwarmAdvectionInAPlane_Type = "SwarmAdvectionInAPlane";
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-SwarmAdvectionInAPlane* SwarmAdvectionInAPlane_New(
-		Name                                       name,
-		DomainContext*                             context,
-		TimeIntegrator*                            timeIntegrator,
-		FeVariable*                                velocityField,
-		Bool                                       allowFallbackToFirstOrder,
-		MaterialPointsSwarm*                       swarm,
-		PeriodicBoundariesManager*                 periodicBCsManager )
-{
-	SwarmAdvectionInAPlane* self = (SwarmAdvectionInAPlane*) _SwarmAdvectionInAPlane_DefaultNew( name );
-	int whichaxis=0;
-	
-	/* 	SwarmAdvectionInAPlane_InitAll */
-	_TimeIntegrand_Init( self, context, timeIntegrator, swarm->particleCoordVariable->variable, 0, NULL,
-		allowFallbackToFirstOrder );
-	_SwarmAdvector_Init( (SwarmAdvector*)self, velocityField, swarm, periodicBCsManager);
-	_SwarmAdvectionInAPlane_Init( self, whichaxis );
-
-	return self;
-}
-
-SwarmAdvectionInAPlane* _SwarmAdvectionInAPlane_New(  SWARMADVECTIONINAPLANE_DEFARGS  )
-{
-	SwarmAdvectionInAPlane* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SwarmAdvectionInAPlane) );
-	self = (SwarmAdvectionInAPlane*)_SwarmAdvector_New(  SWARMADVECTOR_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	
-	return self;
-}
-
-void _SwarmAdvectionInAPlane_Init( SwarmAdvectionInAPlane* self, int whichaxis )
-{
-	/* Adding parameter which axis as the user can choose to prevent the advection of a tracer in the X (0), Y (1) or Z (2) directions */
-	self->whichaxis = whichaxis;
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void* _SwarmAdvectionInAPlane_Copy( const void* swarmAdvector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SwarmAdvectionInAPlane*	self = (SwarmAdvectionInAPlane*)swarmAdvector;
-	SwarmAdvectionInAPlane*	newSwarmAdvectionInAPlane;
-	
-	newSwarmAdvectionInAPlane = (SwarmAdvectionInAPlane*)_SwarmAdvector_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newSwarmAdvectionInAPlane->velocityField = self->velocityField;
-	newSwarmAdvectionInAPlane->swarm         = self->swarm;
-	newSwarmAdvectionInAPlane->periodicBCsManager = self->periodicBCsManager;
-	
-	return (void*)newSwarmAdvectionInAPlane;
-}
-
-void* _SwarmAdvectionInAPlane_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(SwarmAdvectionInAPlane);
-	Type                                                       type = SwarmAdvectionInAPlane_Type;
-	Stg_Class_DeleteFunction*                               _delete = _SwarmAdvector_Delete;
-	Stg_Class_PrintFunction*                                 _print = _SwarmAdvector_Print;
-	Stg_Class_CopyFunction*                                   _copy = _SwarmAdvectionInAPlane_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _SwarmAdvectionInAPlane_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _SwarmAdvectionInAPlane_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _SwarmAdvector_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _SwarmAdvector_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _SwarmAdvector_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _SwarmAdvector_Destroy;
-	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _SwarmAdvectionInAPlane_TimeDeriv;
-	TimeIntegrand_IntermediateFunction*              _intermediate = _SwarmAdvector_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*) _SwarmAdvectionInAPlane_New(  SWARMADVECTIONINAPLANE_PASSARGS  );
-}
-
-
-void _SwarmAdvectionInAPlane_AssignFromXML( void* swarmAdvector, Stg_ComponentFactory* cf, void* data) {
-	SwarmAdvectionInAPlane*	            self          = (SwarmAdvectionInAPlane*) swarmAdvector;
-	int							whichaxis;
-	_SwarmAdvector_AssignFromXML( self, cf, data );
-	/* Everything except whichaxis constructed by parent already */
-	whichaxis = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"whichaxis", 1  );
-	_SwarmAdvectionInAPlane_Init( self, whichaxis );
-}
-
-
-Bool _SwarmAdvectionInAPlane_TimeDeriv( void* swarmAdvector, Index array_I, double* timeDeriv ) {
-	SwarmAdvectionInAPlane*      self          = (SwarmAdvectionInAPlane*) swarmAdvector;
-	FieldVariable*      velocityField = (FieldVariable*) self->velocityField;
-	double*             coord;
-	InterpolationResult result;
-
-	/* Get Coordinate of Object using Variable */
-	coord = Variable_GetPtrDouble( self->variable, array_I );
-
-	result = FieldVariable_InterpolateValueAt( velocityField, coord, timeDeriv );
-	
-	
-	/* This prevents advection in the X, Y or Z direction */
-	timeDeriv[ self->whichaxis ] = 0.0;
-
-
-	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
-			( self->swarm->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\tInteropolation result is %u.\n",
-			__func__, array_I, coord[0], coord[1], coord[2], 
-			timeDeriv[0], timeDeriv[1], ( self->swarm->dim == 3 ? timeDeriv[2] : 0.0 ),
-			result );
-		abort();
-		#endif
-
-		return False;
-	}
-
-	return True;
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-/*---------------------------------------------------------------------------------------------------------------------
-** Entry Point Hooks
-*/
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/SwarmAdvectionInAPlane.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/SwarmAdvectionInAPlane.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,212 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "SwarmAdvector.h"
+#include "SwarmAdvectionInAPlane.h"
+
+#include "MaterialPointsSwarm.h"
+#include "PeriodicBoundariesManager.h"
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/*I am generalising this so that I can use it- Wendy S*/
+
+
+/* Textual name of this class */
+const Type SwarmAdvectionInAPlane_Type = "SwarmAdvectionInAPlane";
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+SwarmAdvectionInAPlane* SwarmAdvectionInAPlane_New(
+		Name                                       name,
+		DomainContext*                             context,
+		TimeIntegrator*                            timeIntegrator,
+		FeVariable*                                velocityField,
+		Bool                                       allowFallbackToFirstOrder,
+		MaterialPointsSwarm*                       swarm,
+		PeriodicBoundariesManager*                 periodicBCsManager )
+{
+	SwarmAdvectionInAPlane* self = (SwarmAdvectionInAPlane*) _SwarmAdvectionInAPlane_DefaultNew( name );
+	int whichaxis=0;
+	
+	/* 	SwarmAdvectionInAPlane_InitAll */
+	_TimeIntegrand_Init( self, context, timeIntegrator, swarm->particleCoordVariable->variable, 0, NULL,
+		allowFallbackToFirstOrder );
+	_SwarmAdvector_Init( (SwarmAdvector*)self, velocityField, swarm, periodicBCsManager);
+	_SwarmAdvectionInAPlane_Init( self, whichaxis );
+
+	return self;
+}
+
+SwarmAdvectionInAPlane* _SwarmAdvectionInAPlane_New(  SWARMADVECTIONINAPLANE_DEFARGS  )
+{
+	SwarmAdvectionInAPlane* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SwarmAdvectionInAPlane) );
+	self = (SwarmAdvectionInAPlane*)_SwarmAdvector_New(  SWARMADVECTOR_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	
+	return self;
+}
+
+void _SwarmAdvectionInAPlane_Init( SwarmAdvectionInAPlane* self, int whichaxis )
+{
+	/* Adding parameter which axis as the user can choose to prevent the advection of a tracer in the X (0), Y (1) or Z (2) directions */
+	self->whichaxis = whichaxis;
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void* _SwarmAdvectionInAPlane_Copy( const void* swarmAdvector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SwarmAdvectionInAPlane*	self = (SwarmAdvectionInAPlane*)swarmAdvector;
+	SwarmAdvectionInAPlane*	newSwarmAdvectionInAPlane;
+	
+	newSwarmAdvectionInAPlane = (SwarmAdvectionInAPlane*)_SwarmAdvector_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newSwarmAdvectionInAPlane->velocityField = self->velocityField;
+	newSwarmAdvectionInAPlane->swarm         = self->swarm;
+	newSwarmAdvectionInAPlane->periodicBCsManager = self->periodicBCsManager;
+	
+	return (void*)newSwarmAdvectionInAPlane;
+}
+
+void* _SwarmAdvectionInAPlane_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(SwarmAdvectionInAPlane);
+	Type                                                       type = SwarmAdvectionInAPlane_Type;
+	Stg_Class_DeleteFunction*                               _delete = _SwarmAdvector_Delete;
+	Stg_Class_PrintFunction*                                 _print = _SwarmAdvector_Print;
+	Stg_Class_CopyFunction*                                   _copy = _SwarmAdvectionInAPlane_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _SwarmAdvectionInAPlane_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _SwarmAdvectionInAPlane_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _SwarmAdvector_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _SwarmAdvector_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _SwarmAdvector_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _SwarmAdvector_Destroy;
+	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _SwarmAdvectionInAPlane_TimeDeriv;
+	TimeIntegrand_IntermediateFunction*              _intermediate = _SwarmAdvector_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*) _SwarmAdvectionInAPlane_New(  SWARMADVECTIONINAPLANE_PASSARGS  );
+}
+
+
+void _SwarmAdvectionInAPlane_AssignFromXML( void* swarmAdvector, Stg_ComponentFactory* cf, void* data) {
+	SwarmAdvectionInAPlane*	            self          = (SwarmAdvectionInAPlane*) swarmAdvector;
+	int							whichaxis;
+	_SwarmAdvector_AssignFromXML( self, cf, data );
+	/* Everything except whichaxis constructed by parent already */
+	whichaxis = Stg_ComponentFactory_GetInt( cf, self->name, (Dictionary_Entry_Key)"whichaxis", 1  );
+	_SwarmAdvectionInAPlane_Init( self, whichaxis );
+}
+
+
+Bool _SwarmAdvectionInAPlane_TimeDeriv( void* swarmAdvector, Index array_I, double* timeDeriv ) {
+	SwarmAdvectionInAPlane*      self          = (SwarmAdvectionInAPlane*) swarmAdvector;
+	FieldVariable*      velocityField = (FieldVariable*) self->velocityField;
+	double*             coord;
+	InterpolationResult result;
+
+	/* Get Coordinate of Object using Variable */
+	coord = Variable_GetPtrDouble( self->variable, array_I );
+
+	result = FieldVariable_InterpolateValueAt( velocityField, coord, timeDeriv );
+	
+	
+	/* This prevents advection in the X, Y or Z direction */
+	timeDeriv[ self->whichaxis ] = 0.0;
+
+
+	if ( result == OTHER_PROC || result == OUTSIDE_GLOBAL || isinf(timeDeriv[0]) || isinf(timeDeriv[1]) || 
+			( self->swarm->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\tInteropolation result is %u.\n",
+			__func__, array_I, coord[0], coord[1], coord[2], 
+			timeDeriv[0], timeDeriv[1], ( self->swarm->dim == 3 ? timeDeriv[2] : 0.0 ),
+			result );
+		abort();
+		#endif
+
+		return False;
+	}
+
+	return True;
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+/*---------------------------------------------------------------------------------------------------------------------
+** Entry Point Hooks
+*/
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/SwarmAdvector.c
--- a/MaterialPoints/src/SwarmAdvector.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,323 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: SwarmAdvector.c 559 2008-04-08 05:54:05Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "SwarmAdvector.h"
-
-#include "MaterialPointsSwarm.h"
-#include "PeriodicBoundariesManager.h"
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type SwarmAdvector_Type = "SwarmAdvector";
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-SwarmAdvector* SwarmAdvector_New(
-		Name                                       name,
-		DomainContext*                             context,
-		TimeIntegrator*                            timeIntegrator,
-		FeVariable*                                velocityField,
-		Bool                                       allowFallbackToFirstOrder,
-		MaterialPointsSwarm*                       swarm,
-		PeriodicBoundariesManager*                 periodicBCsManager )
-{
-	SwarmAdvector* self = (SwarmAdvector*) _SwarmAdvector_DefaultNew( name );
-
-	/* 	SwarmAdvector_InitAll */
-	_TimeIntegrand_Init( self, context, timeIntegrator, swarm->particleCoordVariable->variable, 0, NULL,
-		allowFallbackToFirstOrder );
-	_SwarmAdvector_Init( self, velocityField, swarm, periodicBCsManager );
-
-	return self;
-}
-
-SwarmAdvector* _SwarmAdvector_New(  SWARMADVECTOR_DEFARGS  )
-{
-	SwarmAdvector* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SwarmAdvector) );
-	self = (SwarmAdvector*)_TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	
-	return self;
-}
-
-void _SwarmAdvector_Init( 
-		SwarmAdvector*                             self,
-		FeVariable*                                velocityField,
-		MaterialPointsSwarm*                       swarm,
-		PeriodicBoundariesManager*                 periodicBCsManager )
-{
-/* 	 TODO - commented out by Pat Sunter 20060428 since we need to use gauss layout initially for testing sometimes */
-	/*
-	Journal_Firewall(
-		swarm->particleLayout->coordSystem == GlobalCoordSystem,
-		Journal_MyStream( Error_Type, self ),
-		"In func - %s, swarm %s does not use a global coordinate system because of particle layout %s is of type %s\n",
-		__func__,
-		swarm->name,
-		swarm->particleLayout->name,
-		swarm->particleLayout->type );
-	*/
-	
-	self->velocityField = velocityField;
-	self->swarm = swarm;
-	self->swarm->swarmAdvector = self;	/* Attach ourselves to the swarm */
-	self->variable = swarm->particleCoordVariable->variable;
-
-	/* Test if mesh is periodic and a periodic boundaries manager hasn't been given */
-	if ( !periodicBCsManager && Stg_Class_IsInstance( swarm->mesh->generator, CartesianGenerator_Type ) ) {
-		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) swarm->mesh->generator;
-		if ( cartesianGenerator->periodic[ I_AXIS ] || cartesianGenerator->periodic[ J_AXIS ] || cartesianGenerator->periodic[ K_AXIS ] ) {
-			/* Create a periodicBCsManager if there isn't one already */
-			periodicBCsManager = PeriodicBoundariesManager_New( "periodicBCsManager", (PICelleratorContext*)self->context, (Mesh*)swarm->mesh, (Swarm*)swarm, NULL );
-		}
-	}	
-	self->periodicBCsManager = periodicBCsManager;
-	
-
-
-	TimeIntegrator_AppendSetupEP( self->timeIntegrator,  
-                                      "SwarmAdvector_AdvectionSetup", (Func_Ptr)SwarmAdvector_AdvectionSetup,  self->name, self );
-	TimeIntegrator_PrependFinishEP( self->timeIntegrator,
-			"SwarmAdvector_AdvectionFinish", (Func_Ptr)SwarmAdvector_AdvectionFinish,  self->name, self );
-	TimeIntegrator_InsertBeforeFinishEP( 
-		self->timeIntegrator,
-		"IntegrationPointsSwarm_Update", /* Must before this */
-		"MaterialPointsSwarm_Update", 
-		(Func_Ptr)_MaterialPointsSwarm_UpdateHook, 
-		swarm->name, 
-		swarm );
-			
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _SwarmAdvector_Delete( void* swarmAdvector ) {
-	SwarmAdvector* self = (SwarmAdvector*)swarmAdvector;
-
-	/* Delete parent */
-	_TimeIntegrand_Delete( self );
-}
-
-
-void _SwarmAdvector_Print( void* swarmAdvector, Stream* stream ) {
-	SwarmAdvector* self = (SwarmAdvector*)swarmAdvector;
-	
-	/* Print parent */
-	_TimeIntegrand_Print( self, stream );
-}
-
-
-void* _SwarmAdvector_Copy( const void* swarmAdvector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	SwarmAdvector*	self = (SwarmAdvector*)swarmAdvector;
-	SwarmAdvector*	newSwarmAdvector;
-	
-	newSwarmAdvector = (SwarmAdvector*)_TimeIntegrand_Copy( self, dest, deep, nameExt, ptrMap );
-
-	newSwarmAdvector->velocityField = self->velocityField;
-	newSwarmAdvector->swarm         = self->swarm;
-	newSwarmAdvector->periodicBCsManager = self->periodicBCsManager;
-	
-	return (void*)newSwarmAdvector;
-}
-
-void* _SwarmAdvector_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                               _sizeOfSelf = sizeof(SwarmAdvector);
-	Type                                                       type = SwarmAdvector_Type;
-	Stg_Class_DeleteFunction*                               _delete = _SwarmAdvector_Delete;
-	Stg_Class_PrintFunction*                                 _print = _SwarmAdvector_Print;
-	Stg_Class_CopyFunction*                                   _copy = _SwarmAdvector_Copy;
-	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _SwarmAdvector_DefaultNew;
-	Stg_Component_ConstructFunction*                     _construct = _SwarmAdvector_AssignFromXML;
-	Stg_Component_BuildFunction*                             _build = _SwarmAdvector_Build;
-	Stg_Component_InitialiseFunction*                   _initialise = _SwarmAdvector_Initialise;
-	Stg_Component_ExecuteFunction*                         _execute = _SwarmAdvector_Execute;
-	Stg_Component_DestroyFunction*                         _destroy = _SwarmAdvector_Destroy;
-	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _SwarmAdvector_TimeDeriv;
-	TimeIntegrand_IntermediateFunction*              _intermediate = _SwarmAdvector_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*) _SwarmAdvector_New(  SWARMADVECTOR_PASSARGS  );
-}
-
-
-void _SwarmAdvector_AssignFromXML( void* swarmAdvector, Stg_ComponentFactory* cf, void* data ) {
-	SwarmAdvector*	            self          = (SwarmAdvector*) swarmAdvector;
-	FeVariable*                 velocityField;
-	MaterialPointsSwarm*        swarm;
-	PeriodicBoundariesManager*  periodicBCsManager;
-
-	_TimeIntegrand_AssignFromXML( self, cf, data );
-
-	velocityField      = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  );
-	swarm              = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", MaterialPointsSwarm, True, data  );
-	periodicBCsManager = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PeriodicBCsManager", PeriodicBoundariesManager, False, data  );
-
-	_SwarmAdvector_Init( self, velocityField, swarm, periodicBCsManager );
-}
-
-void _SwarmAdvector_Build( void* swarmAdvector, void* data ) {
-	SwarmAdvector*	self = (SwarmAdvector*) swarmAdvector;
-
-   Stg_Component_Build( self->velocityField, data, False );
-   Stg_Component_Build( self->swarm, data, False );
-	if ( self->periodicBCsManager )
-		Stg_Component_Build( self->periodicBCsManager, data, False );
-   _TimeIntegrand_Build( self, data );
-
-}
-
-void _SwarmAdvector_Initialise( void* swarmAdvector, void* data ) {
-	SwarmAdvector*	self = (SwarmAdvector*) swarmAdvector;
-	
-   Stg_Component_Initialise( self->velocityField, data, False );
-   Stg_Component_Initialise( self->swarm, data, False );
-	if ( self->periodicBCsManager )
-		Stg_Component_Initialise( self->periodicBCsManager, data, False );
-	_TimeIntegrand_Initialise( self, data );
-}
-
-void _SwarmAdvector_Execute( void* swarmAdvector, void* data ) {
-	SwarmAdvector*	self = (SwarmAdvector*)swarmAdvector;
-	
-	_TimeIntegrand_Execute( self, data );
-}
-
-void _SwarmAdvector_Destroy( void* swarmAdvector, void* data ) {
-	SwarmAdvector*	self = (SwarmAdvector*)swarmAdvector;
-
-	_TimeIntegrand_Destroy( self, data );	
-   Stg_Component_Destroy( self->velocityField, data, False );
-   Stg_Component_Destroy( self->swarm, data, False );
-	if ( self->periodicBCsManager )
-		Stg_Component_Destroy( self->periodicBCsManager, data, False );
-}
-
-Bool _SwarmAdvector_TimeDeriv( void* swarmAdvector, Index array_I, double* timeDeriv ) {
-	SwarmAdvector*      self          = (SwarmAdvector*) swarmAdvector;
-	FieldVariable*      velocityField = (FieldVariable*) self->velocityField;
-	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]) || 
-			( self->swarm->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], ( self->swarm->dim == 3 ? timeDeriv[2] : 0.0 ),
-			InterpolationResultToStringMap[result]  );
-		#endif	
-		return False;	
-	}
-
-	return True;
-}
-
-
-void _SwarmAdvector_Intermediate( void* swarmAdvector, Index lParticle_I ) {
-	SwarmAdvector*      self          = (SwarmAdvector*) swarmAdvector;
-
-	if ( self->periodicBCsManager ) {
-		PeriodicBoundariesManager_UpdateParticle( self->periodicBCsManager, lParticle_I );
-	}
-}
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-/*---------------------------------------------------------------------------------------------------------------------
-** Entry Point Hooks
-*/
-void SwarmAdvector_AdvectionSetup( TimeIntegrator* timeIntegrator, SwarmAdvector* self ) {
-	FeVariable_SyncShadowValues( self->velocityField );
-}
-
-void SwarmAdvector_AdvectionFinish( TimeIntegrator* timeIntegrator, SwarmAdvector* self ) {
-	#if DEBUG
-		Swarm_CheckCoordsAreFinite( self->swarm );
-	#endif
-	
-	/* Move particles across processors because they've just been advected */
-	Swarm_UpdateAllParticleOwners( self->swarm );
-}
-
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/SwarmAdvector.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/SwarmAdvector.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,323 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: SwarmAdvector.c 559 2008-04-08 05:54:05Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "SwarmAdvector.h"
+
+#include "MaterialPointsSwarm.h"
+#include "PeriodicBoundariesManager.h"
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type SwarmAdvector_Type = "SwarmAdvector";
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+SwarmAdvector* SwarmAdvector_New(
+		Name                                       name,
+		DomainContext*                             context,
+		TimeIntegrator*                            timeIntegrator,
+		FeVariable*                                velocityField,
+		Bool                                       allowFallbackToFirstOrder,
+		MaterialPointsSwarm*                       swarm,
+		PeriodicBoundariesManager*                 periodicBCsManager )
+{
+	SwarmAdvector* self = (SwarmAdvector*) _SwarmAdvector_DefaultNew( name );
+
+	/* 	SwarmAdvector_InitAll */
+	_TimeIntegrand_Init( self, context, timeIntegrator, swarm->particleCoordVariable->variable, 0, NULL,
+		allowFallbackToFirstOrder );
+	_SwarmAdvector_Init( self, velocityField, swarm, periodicBCsManager );
+
+	return self;
+}
+
+SwarmAdvector* _SwarmAdvector_New(  SWARMADVECTOR_DEFARGS  )
+{
+	SwarmAdvector* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SwarmAdvector) );
+	self = (SwarmAdvector*)_TimeIntegrand_New(  TIMEINTEGRAND_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	
+	return self;
+}
+
+void _SwarmAdvector_Init( 
+		SwarmAdvector*                             self,
+		FeVariable*                                velocityField,
+		MaterialPointsSwarm*                       swarm,
+		PeriodicBoundariesManager*                 periodicBCsManager )
+{
+/* 	 TODO - commented out by Pat Sunter 20060428 since we need to use gauss layout initially for testing sometimes */
+	/*
+	Journal_Firewall(
+		swarm->particleLayout->coordSystem == GlobalCoordSystem,
+		Journal_MyStream( Error_Type, self ),
+		"In func - %s, swarm %s does not use a global coordinate system because of particle layout %s is of type %s\n",
+		__func__,
+		swarm->name,
+		swarm->particleLayout->name,
+		swarm->particleLayout->type );
+	*/
+	
+	self->velocityField = velocityField;
+	self->swarm = swarm;
+	self->swarm->swarmAdvector = self;	/* Attach ourselves to the swarm */
+	self->variable = swarm->particleCoordVariable->variable;
+
+	/* Test if mesh is periodic and a periodic boundaries manager hasn't been given */
+	if ( !periodicBCsManager && Stg_Class_IsInstance( swarm->mesh->generator, CartesianGenerator_Type ) ) {
+		CartesianGenerator* cartesianGenerator = (CartesianGenerator*) swarm->mesh->generator;
+		if ( cartesianGenerator->periodic[ I_AXIS ] || cartesianGenerator->periodic[ J_AXIS ] || cartesianGenerator->periodic[ K_AXIS ] ) {
+			/* Create a periodicBCsManager if there isn't one already */
+			periodicBCsManager = PeriodicBoundariesManager_New( "periodicBCsManager", (PICelleratorContext*)self->context, (Mesh*)swarm->mesh, (Swarm*)swarm, NULL );
+		}
+	}	
+	self->periodicBCsManager = periodicBCsManager;
+	
+
+
+	TimeIntegrator_AppendSetupEP( self->timeIntegrator,  
+                                      "SwarmAdvector_AdvectionSetup", (Func_Ptr)SwarmAdvector_AdvectionSetup,  self->name, self );
+	TimeIntegrator_PrependFinishEP( self->timeIntegrator,
+			"SwarmAdvector_AdvectionFinish", (Func_Ptr)SwarmAdvector_AdvectionFinish,  self->name, self );
+	TimeIntegrator_InsertBeforeFinishEP( 
+		self->timeIntegrator,
+		"IntegrationPointsSwarm_Update", /* Must before this */
+		"MaterialPointsSwarm_Update", 
+		(Func_Ptr)_MaterialPointsSwarm_UpdateHook, 
+		swarm->name, 
+		swarm );
+			
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _SwarmAdvector_Delete( void* swarmAdvector ) {
+	SwarmAdvector* self = (SwarmAdvector*)swarmAdvector;
+
+	/* Delete parent */
+	_TimeIntegrand_Delete( self );
+}
+
+
+void _SwarmAdvector_Print( void* swarmAdvector, Stream* stream ) {
+	SwarmAdvector* self = (SwarmAdvector*)swarmAdvector;
+	
+	/* Print parent */
+	_TimeIntegrand_Print( self, stream );
+}
+
+
+void* _SwarmAdvector_Copy( const void* swarmAdvector, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	SwarmAdvector*	self = (SwarmAdvector*)swarmAdvector;
+	SwarmAdvector*	newSwarmAdvector;
+	
+	newSwarmAdvector = (SwarmAdvector*)_TimeIntegrand_Copy( self, dest, deep, nameExt, ptrMap );
+
+	newSwarmAdvector->velocityField = self->velocityField;
+	newSwarmAdvector->swarm         = self->swarm;
+	newSwarmAdvector->periodicBCsManager = self->periodicBCsManager;
+	
+	return (void*)newSwarmAdvector;
+}
+
+void* _SwarmAdvector_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                               _sizeOfSelf = sizeof(SwarmAdvector);
+	Type                                                       type = SwarmAdvector_Type;
+	Stg_Class_DeleteFunction*                               _delete = _SwarmAdvector_Delete;
+	Stg_Class_PrintFunction*                                 _print = _SwarmAdvector_Print;
+	Stg_Class_CopyFunction*                                   _copy = _SwarmAdvector_Copy;
+	Stg_Component_DefaultConstructorFunction*   _defaultConstructor = _SwarmAdvector_DefaultNew;
+	Stg_Component_ConstructFunction*                     _construct = _SwarmAdvector_AssignFromXML;
+	Stg_Component_BuildFunction*                             _build = _SwarmAdvector_Build;
+	Stg_Component_InitialiseFunction*                   _initialise = _SwarmAdvector_Initialise;
+	Stg_Component_ExecuteFunction*                         _execute = _SwarmAdvector_Execute;
+	Stg_Component_DestroyFunction*                         _destroy = _SwarmAdvector_Destroy;
+	TimeIntegrand_CalculateTimeDerivFunction*  _calculateTimeDeriv = _SwarmAdvector_TimeDeriv;
+	TimeIntegrand_IntermediateFunction*              _intermediate = _SwarmAdvector_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*) _SwarmAdvector_New(  SWARMADVECTOR_PASSARGS  );
+}
+
+
+void _SwarmAdvector_AssignFromXML( void* swarmAdvector, Stg_ComponentFactory* cf, void* data ) {
+	SwarmAdvector*	            self          = (SwarmAdvector*) swarmAdvector;
+	FeVariable*                 velocityField;
+	MaterialPointsSwarm*        swarm;
+	PeriodicBoundariesManager*  periodicBCsManager;
+
+	_TimeIntegrand_AssignFromXML( self, cf, data );
+
+	velocityField      = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"VelocityField", FeVariable, True, data  );
+	swarm              = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", MaterialPointsSwarm, True, data  );
+	periodicBCsManager = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"PeriodicBCsManager", PeriodicBoundariesManager, False, data  );
+
+	_SwarmAdvector_Init( self, velocityField, swarm, periodicBCsManager );
+}
+
+void _SwarmAdvector_Build( void* swarmAdvector, void* data ) {
+	SwarmAdvector*	self = (SwarmAdvector*) swarmAdvector;
+
+   Stg_Component_Build( self->velocityField, data, False );
+   Stg_Component_Build( self->swarm, data, False );
+	if ( self->periodicBCsManager )
+		Stg_Component_Build( self->periodicBCsManager, data, False );
+   _TimeIntegrand_Build( self, data );
+
+}
+
+void _SwarmAdvector_Initialise( void* swarmAdvector, void* data ) {
+	SwarmAdvector*	self = (SwarmAdvector*) swarmAdvector;
+	
+   Stg_Component_Initialise( self->velocityField, data, False );
+   Stg_Component_Initialise( self->swarm, data, False );
+	if ( self->periodicBCsManager )
+		Stg_Component_Initialise( self->periodicBCsManager, data, False );
+	_TimeIntegrand_Initialise( self, data );
+}
+
+void _SwarmAdvector_Execute( void* swarmAdvector, void* data ) {
+	SwarmAdvector*	self = (SwarmAdvector*)swarmAdvector;
+	
+	_TimeIntegrand_Execute( self, data );
+}
+
+void _SwarmAdvector_Destroy( void* swarmAdvector, void* data ) {
+	SwarmAdvector*	self = (SwarmAdvector*)swarmAdvector;
+
+	_TimeIntegrand_Destroy( self, data );	
+   Stg_Component_Destroy( self->velocityField, data, False );
+   Stg_Component_Destroy( self->swarm, data, False );
+	if ( self->periodicBCsManager )
+		Stg_Component_Destroy( self->periodicBCsManager, data, False );
+}
+
+Bool _SwarmAdvector_TimeDeriv( void* swarmAdvector, Index array_I, double* timeDeriv ) {
+	SwarmAdvector*      self          = (SwarmAdvector*) swarmAdvector;
+	FieldVariable*      velocityField = (FieldVariable*) self->velocityField;
+	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]) || 
+			( self->swarm->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], ( self->swarm->dim == 3 ? timeDeriv[2] : 0.0 ),
+			InterpolationResultToStringMap[result]  );
+		#endif	
+		return False;	
+	}
+
+	return True;
+}
+
+
+void _SwarmAdvector_Intermediate( void* swarmAdvector, Index lParticle_I ) {
+	SwarmAdvector*      self          = (SwarmAdvector*) swarmAdvector;
+
+	if ( self->periodicBCsManager ) {
+		PeriodicBoundariesManager_UpdateParticle( self->periodicBCsManager, lParticle_I );
+	}
+}
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+/*---------------------------------------------------------------------------------------------------------------------
+** Entry Point Hooks
+*/
+void SwarmAdvector_AdvectionSetup( TimeIntegrator* timeIntegrator, SwarmAdvector* self ) {
+	FeVariable_SyncShadowValues( self->velocityField );
+}
+
+void SwarmAdvector_AdvectionFinish( TimeIntegrator* timeIntegrator, SwarmAdvector* self ) {
+	#if DEBUG
+		Swarm_CheckCoordsAreFinite( self->swarm );
+	#endif
+	
+	/* Move particles across processors because they've just been advected */
+	Swarm_UpdateAllParticleOwners( self->swarm );
+}
+
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/SwarmVariableField.c
--- a/MaterialPoints/src/SwarmVariableField.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,262 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: SwarmVariableField.c 376 2006-10-18 06:58:41Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-
-#include "types.h"
-#include "ParticleFeVariable.h"
-#include "SwarmVariableField.h"
-#include "IntegrationPointsSwarm.h"
-#include "MaterialPointsSwarm.h"
-#include "IntegrationPointMapper.h"
-
-#include <assert.h>
-#include <string.h>
-
-const Type SwarmVariableField_Type = "SwarmVariableField";
-
-/* Creation implementation / Virtual constructor */
-SwarmVariableField* _SwarmVariableField_New(  SWARMVARIABLEFIELD_DEFARGS  ) 
-{
-	SwarmVariableField* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(SwarmVariableField) );
-
-	self = (SwarmVariableField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
-	/* Virtual info */
-	
-	return self;
-}
-
-void _SwarmVariableField_Init( SwarmVariableField* swarmVariableField, Variable_Register* variable_Register, Name swarmVarName, MaterialPointsSwarm*	materialSwarm ) {
-	SwarmVariableField* 	self 	= (SwarmVariableField*)swarmVariableField;
-	self->variable_Register = variable_Register;
-	self->swarmVarName = swarmVarName;
-	self->materialSwarm = materialSwarm;
-}
-
-void _SwarmVariableField_Delete( void* swarmVariableField ) {
-	SwarmVariableField* self = (SwarmVariableField*)swarmVariableField;
-
-	_ParticleFeVariable_Delete( self );
-}
-
-void _SwarmVariableField_Print( void* swarmVariableField, Stream* stream ) {
-	SwarmVariableField* self = (SwarmVariableField*)swarmVariableField;
-	
-	_ParticleFeVariable_Print( self, stream );
-}
-
-void* _SwarmVariableField_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                       _sizeOfSelf = sizeof(SwarmVariableField);
-	Type                                                               type = SwarmVariableField_Type;
-	Stg_Class_DeleteFunction*                                       _delete = _SwarmVariableField_Delete;
-	Stg_Class_PrintFunction*                                         _print = _SwarmVariableField_Print;
-	Stg_Class_CopyFunction*                                           _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _SwarmVariableField_DefaultNew;
-	Stg_Component_ConstructFunction*                             _construct = _SwarmVariableField_AssignFromXML;
-	Stg_Component_BuildFunction*                                     _build = _SwarmVariableField_Build;
-	Stg_Component_InitialiseFunction*                           _initialise = _SwarmVariableField_Initialise;
-	Stg_Component_ExecuteFunction*                                 _execute = _SwarmVariableField_Execute;
-	Stg_Component_DestroyFunction*                                 _destroy = _SwarmVariableField_Destroy;
-	FieldVariable_InterpolateValueAtFunction*           _interpolateValueAt = _FeVariable_InterpolateValueAt;
-	FieldVariable_GetCoordFunction*                _getMinAndMaxLocalCoords = _FeVariable_GetMinAndMaxLocalCoords;
-	FieldVariable_GetCoordFunction*               _getMinAndMaxGlobalCoords = _FeVariable_GetMinAndMaxGlobalCoords;
-	FeVariable_InterpolateWithinElementFunction*  _interpolateWithinElement = _FeVariable_InterpolateNodeValuesToElLocalCoord;
-	FeVariable_GetValueAtNodeFunction*                      _getValueAtNode = _FeVariable_GetValueAtNode;
-	ParticleFeVariable_ValueAtParticleFunction*            _valueAtParticle = (ParticleFeVariable_ValueAtParticleFunction*)_SwarmVariableField_ValueAtParticle;
-
-	/* 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;
-	FieldVariable_GetValueFunction*   _getMinGlobalFieldMagnitude = NULL;
-	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = NULL;
-	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = NULL;
-
-	return (void*)_SwarmVariableField_New(  SWARMVARIABLEFIELD_PASSARGS  );
-}
-
-void _SwarmVariableField_AssignFromXML( void* swarmVariableField, Stg_ComponentFactory* cf, void* data ) {
-	SwarmVariableField*		self = (SwarmVariableField*)swarmVariableField;
-	IntegrationPointsSwarm*	integrationSwarm;
-	Variable_Register*		variable_Register;
-   Name			            swarmVarName;
-   MaterialPointsSwarm*	   materialSwarm;
-	_ParticleFeVariable_AssignFromXML( self, cf, data );
-
-	variable_Register = self->context->variable_Register; 
-
-	// TODO: just get the textual name here - see gLucifer's SwarmPlotter DrawignObject 
-	swarmVarName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"swarmVariable", ""  );
-
-	materialSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialSwarm", MaterialPointsSwarm, True, data  );
-	integrationSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", IntegrationPointsSwarm, True, NULL );
-	assert( integrationSwarm  );
-
-	_SwarmVariableField_Init( self, variable_Register, swarmVarName, materialSwarm );
-}
-
-void _SwarmVariableField_Build( void* swarmVariableField, void* data ) {
-	SwarmVariableField*	      self	            = (SwarmVariableField*)swarmVariableField;
-	unsigned		               nDomainVerts      = Mesh_GetDomainSize( self->feMesh, MT_VERTEX );
-	SwarmVariable_Register*		swarmVar_Register	= self->materialSwarm->swarmVariable_Register;
-	Stream*				         errorStream		   = Journal_Register( Error_Type, (Name)self->type  );
-	char*			               tmpName;
-
-	Stg_Component_Build( self->materialSwarm, data, False );
-	/* make this more flexible to handle vector values at each node - will have to get the num dofs from the XML
-	 * as other components are not necessarily built yet... dave. 03.10.07 */
-	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"DataVariable"  );
-	self->dataVariable = Variable_NewScalar( tmpName,
-		(AbstractContext*)self->context,
-		Variable_DataType_Double,
-		&nDomainVerts,
-		NULL,
-		(void**)&self->data,
-		self->variable_Register );
-	Memory_Free( tmpName );
-	self->fieldComponentCount = 1;
-
-	tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
-	self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
-
-	/* must build before adding the variable to the dof layout, dave. 04.10.07 */
-	//Stg_Component_Build( self->dofLayout, data, False );
-	Stg_Component_Build( self->dofLayout->mesh, data, False );
-	self->dofLayout->_numItemsInLayout = Mesh_GetDomainSize( self->dofLayout->mesh, MT_VERTEX );
-	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
-	Memory_Free( tmpName );
-	
-	self->eqNum->dofLayout = self->dofLayout;
-
-	/* assign the swarm variable, assume its already built */
-	if( 0 != strcmp( self->swarmVarName, "" ) ) {
-		self->swarmVar = SwarmVariable_Register_GetByName( swarmVar_Register, self->swarmVarName );
-		Journal_Firewall( self->swarmVar != NULL, errorStream, "Error - cannot find swarm variable \"%s\" in %s() for swarm \"%s\".\n",
-			          self->swarmVarName, __func__, self->materialSwarm->name );
-
-		Stg_Component_Build( self->swarmVar, data, False );
-	}
-
-	_ParticleFeVariable_Build( self, data );
-	/* TODO: build self->swarmVar */
-	// TODO: granb self->SwarmVariableName out of the swarm vart register, save reference as self->swarmVar
-	//_SwarmVariable_Build( self->swarmVar, data ); /* dave, 18.09.07 */
-}
-
-void _SwarmVariableField_Initialise( void* swarmVariableField, void* data ) {
-	SwarmVariableField*		self			= (SwarmVariableField*)swarmVariableField;
-
-   Stg_Component_Initialise( self->materialSwarm, data, False );
-
-   if( self->swarmVar ) Stg_Component_Initialise( self->swarmVar, data, False );
-
-	_ParticleFeVariable_Initialise( self, data );
-}
-
-void _SwarmVariableField_Execute( void* swarmVariableField, void* data ) {
-	_ParticleFeVariable_Execute( swarmVariableField, data );
-}
-
-void _SwarmVariableField_Destroy( void* swarmVariableField, void* data ) {
-	SwarmVariableField*		self			= (SwarmVariableField*)swarmVariableField;
-
-   Stg_Component_Destroy( self->materialSwarm, data, False );
-   if( self->swarmVar ) Stg_Component_Destroy( self->swarmVar, data, False );
-   
-	_ParticleFeVariable_Destroy( swarmVariableField, data );
-}
-
-void _SwarmVariableField_ValueAtParticle(
-	void*							swarmVariableField, 
-	IntegrationPointsSwarm*	swarm, 
-	Element_LocalIndex		lElement_I, 
-	IntegrationPoint*			particle,
-	double*						value ) 
-{
-	SwarmVariableField*	self = (SwarmVariableField*)swarmVariableField;
-	double					distance;
-	Cell_Index				cell_I;
-	Particle_InCellIndex	cParticle_I;
-	Particle_Index			lParticle_I;
-
-	cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	cParticle_I = Swarm_FindClosestParticleInCell( swarm, cell_I, Mesh_GetDimSize( self->dofLayout->mesh ), particle->xi, &distance );
-
-	// this function doesn't seem to be doing its joob properly!
-	//lParticle_I = IntegrationPointMapper_GetMaterialIndexAt( swarm->mapper, swarm->cellParticleTbl[cell_I][cParticle_I] );
-	
-	/* assume that the material and intergation points swarms map 1:1 */
-	lParticle_I = swarm->cellParticleTbl[cell_I][cParticle_I];
-	
-	
-	SwarmVariable_ValueAt( self->swarmVar, lParticle_I, value ); /* does the copy inside this func. dave, 18.09.07 */
-}
-
-void _SwarmVariableField_GetValueAtNode( void* swarmVariableField, Node_DomainIndex dNode_I, double* value ) {
-	FeVariable_GetValueAtNode( swarmVariableField, dNode_I, value );
-}
-
-/* implement these two functions later... */
-/*
-double _SwarmVariableField_GetMinGlobalMagnitude( void* swarmVariableField ) {
-	return _SwarmVariable_GetMinGlobalMagnitude( swarmVariableField );
-}
-double _SwarmVariableField_GetMaxGlobalMagnitude( void* swarmVariableField ) {
-	return _SwarmVariable_GetMaxGlobalMagnitude( swarmVariableField );
-}
-*/
-
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/src/SwarmVariableField.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/src/SwarmVariableField.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,262 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: SwarmVariableField.c 376 2006-10-18 06:58:41Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+
+#include "types.h"
+#include "ParticleFeVariable.h"
+#include "SwarmVariableField.h"
+#include "IntegrationPointsSwarm.h"
+#include "MaterialPointsSwarm.h"
+#include "IntegrationPointMapper.h"
+
+#include <assert.h>
+#include <string.h>
+
+const Type SwarmVariableField_Type = "SwarmVariableField";
+
+/* Creation implementation / Virtual constructor */
+SwarmVariableField* _SwarmVariableField_New(  SWARMVARIABLEFIELD_DEFARGS  ) 
+{
+	SwarmVariableField* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(SwarmVariableField) );
+
+	self = (SwarmVariableField*) _ParticleFeVariable_New(  PARTICLEFEVARIABLE_PASSARGS  );
+	/* Virtual info */
+	
+	return self;
+}
+
+void _SwarmVariableField_Init( SwarmVariableField* swarmVariableField, Variable_Register* variable_Register, Name swarmVarName, MaterialPointsSwarm*	materialSwarm ) {
+	SwarmVariableField* 	self 	= (SwarmVariableField*)swarmVariableField;
+	self->variable_Register = variable_Register;
+	self->swarmVarName = swarmVarName;
+	self->materialSwarm = materialSwarm;
+}
+
+void _SwarmVariableField_Delete( void* swarmVariableField ) {
+	SwarmVariableField* self = (SwarmVariableField*)swarmVariableField;
+
+	_ParticleFeVariable_Delete( self );
+}
+
+void _SwarmVariableField_Print( void* swarmVariableField, Stream* stream ) {
+	SwarmVariableField* self = (SwarmVariableField*)swarmVariableField;
+	
+	_ParticleFeVariable_Print( self, stream );
+}
+
+void* _SwarmVariableField_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                       _sizeOfSelf = sizeof(SwarmVariableField);
+	Type                                                               type = SwarmVariableField_Type;
+	Stg_Class_DeleteFunction*                                       _delete = _SwarmVariableField_Delete;
+	Stg_Class_PrintFunction*                                         _print = _SwarmVariableField_Print;
+	Stg_Class_CopyFunction*                                           _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*           _defaultConstructor = _SwarmVariableField_DefaultNew;
+	Stg_Component_ConstructFunction*                             _construct = _SwarmVariableField_AssignFromXML;
+	Stg_Component_BuildFunction*                                     _build = _SwarmVariableField_Build;
+	Stg_Component_InitialiseFunction*                           _initialise = _SwarmVariableField_Initialise;
+	Stg_Component_ExecuteFunction*                                 _execute = _SwarmVariableField_Execute;
+	Stg_Component_DestroyFunction*                                 _destroy = _SwarmVariableField_Destroy;
+	FieldVariable_InterpolateValueAtFunction*           _interpolateValueAt = _FeVariable_InterpolateValueAt;
+	FieldVariable_GetCoordFunction*                _getMinAndMaxLocalCoords = _FeVariable_GetMinAndMaxLocalCoords;
+	FieldVariable_GetCoordFunction*               _getMinAndMaxGlobalCoords = _FeVariable_GetMinAndMaxGlobalCoords;
+	FeVariable_InterpolateWithinElementFunction*  _interpolateWithinElement = _FeVariable_InterpolateNodeValuesToElLocalCoord;
+	FeVariable_GetValueAtNodeFunction*                      _getValueAtNode = _FeVariable_GetValueAtNode;
+	ParticleFeVariable_ValueAtParticleFunction*            _valueAtParticle = (ParticleFeVariable_ValueAtParticleFunction*)_SwarmVariableField_ValueAtParticle;
+
+	/* 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;
+	FieldVariable_GetValueFunction*   _getMinGlobalFieldMagnitude = NULL;
+	FieldVariable_GetValueFunction*   _getMaxGlobalFieldMagnitude = NULL;
+	FeVariable_SyncShadowValuesFunc*            _syncShadowValues = NULL;
+
+	return (void*)_SwarmVariableField_New(  SWARMVARIABLEFIELD_PASSARGS  );
+}
+
+void _SwarmVariableField_AssignFromXML( void* swarmVariableField, Stg_ComponentFactory* cf, void* data ) {
+	SwarmVariableField*		self = (SwarmVariableField*)swarmVariableField;
+	IntegrationPointsSwarm*	integrationSwarm;
+	Variable_Register*		variable_Register;
+   Name			            swarmVarName;
+   MaterialPointsSwarm*	   materialSwarm;
+	_ParticleFeVariable_AssignFromXML( self, cf, data );
+
+	variable_Register = self->context->variable_Register; 
+
+	// TODO: just get the textual name here - see gLucifer's SwarmPlotter DrawignObject 
+	swarmVarName = Stg_ComponentFactory_GetString( cf, self->name, (Dictionary_Entry_Key)"swarmVariable", ""  );
+
+	materialSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialSwarm", MaterialPointsSwarm, True, data  );
+	integrationSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Swarm", IntegrationPointsSwarm, True, NULL );
+	assert( integrationSwarm  );
+
+	_SwarmVariableField_Init( self, variable_Register, swarmVarName, materialSwarm );
+}
+
+void _SwarmVariableField_Build( void* swarmVariableField, void* data ) {
+	SwarmVariableField*	      self	            = (SwarmVariableField*)swarmVariableField;
+	unsigned		               nDomainVerts      = Mesh_GetDomainSize( self->feMesh, MT_VERTEX );
+	SwarmVariable_Register*		swarmVar_Register	= self->materialSwarm->swarmVariable_Register;
+	Stream*				         errorStream		   = Journal_Register( Error_Type, (Name)self->type  );
+	char*			               tmpName;
+
+	Stg_Component_Build( self->materialSwarm, data, False );
+	/* make this more flexible to handle vector values at each node - will have to get the num dofs from the XML
+	 * as other components are not necessarily built yet... dave. 03.10.07 */
+	assert( Class_IsSuper( self->feMesh->topo, IGraph ) );
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"DataVariable"  );
+	self->dataVariable = Variable_NewScalar( tmpName,
+		(AbstractContext*)self->context,
+		Variable_DataType_Double,
+		&nDomainVerts,
+		NULL,
+		(void**)&self->data,
+		self->variable_Register );
+	Memory_Free( tmpName );
+	self->fieldComponentCount = 1;
+
+	tmpName = Stg_Object_AppendSuffix( self, (Name)"DofLayout"  );
+	self->dofLayout = DofLayout_New( tmpName, self->context, self->variable_Register, 0, self->feMesh );
+
+	/* must build before adding the variable to the dof layout, dave. 04.10.07 */
+	//Stg_Component_Build( self->dofLayout, data, False );
+	Stg_Component_Build( self->dofLayout->mesh, data, False );
+	self->dofLayout->_numItemsInLayout = Mesh_GetDomainSize( self->dofLayout->mesh, MT_VERTEX );
+	DofLayout_AddAllFromVariableArray( self->dofLayout, 1, &self->dataVariable );
+	Memory_Free( tmpName );
+	
+	self->eqNum->dofLayout = self->dofLayout;
+
+	/* assign the swarm variable, assume its already built */
+	if( 0 != strcmp( self->swarmVarName, "" ) ) {
+		self->swarmVar = SwarmVariable_Register_GetByName( swarmVar_Register, self->swarmVarName );
+		Journal_Firewall( self->swarmVar != NULL, errorStream, "Error - cannot find swarm variable \"%s\" in %s() for swarm \"%s\".\n",
+			          self->swarmVarName, __func__, self->materialSwarm->name );
+
+		Stg_Component_Build( self->swarmVar, data, False );
+	}
+
+	_ParticleFeVariable_Build( self, data );
+	/* TODO: build self->swarmVar */
+	// TODO: granb self->SwarmVariableName out of the swarm vart register, save reference as self->swarmVar
+	//_SwarmVariable_Build( self->swarmVar, data ); /* dave, 18.09.07 */
+}
+
+void _SwarmVariableField_Initialise( void* swarmVariableField, void* data ) {
+	SwarmVariableField*		self			= (SwarmVariableField*)swarmVariableField;
+
+   Stg_Component_Initialise( self->materialSwarm, data, False );
+
+   if( self->swarmVar ) Stg_Component_Initialise( self->swarmVar, data, False );
+
+	_ParticleFeVariable_Initialise( self, data );
+}
+
+void _SwarmVariableField_Execute( void* swarmVariableField, void* data ) {
+	_ParticleFeVariable_Execute( swarmVariableField, data );
+}
+
+void _SwarmVariableField_Destroy( void* swarmVariableField, void* data ) {
+	SwarmVariableField*		self			= (SwarmVariableField*)swarmVariableField;
+
+   Stg_Component_Destroy( self->materialSwarm, data, False );
+   if( self->swarmVar ) Stg_Component_Destroy( self->swarmVar, data, False );
+   
+	_ParticleFeVariable_Destroy( swarmVariableField, data );
+}
+
+void _SwarmVariableField_ValueAtParticle(
+	void*							swarmVariableField, 
+	IntegrationPointsSwarm*	swarm, 
+	Element_LocalIndex		lElement_I, 
+	IntegrationPoint*			particle,
+	double*						value ) 
+{
+	SwarmVariableField*	self = (SwarmVariableField*)swarmVariableField;
+	double					distance;
+	Cell_Index				cell_I;
+	Particle_InCellIndex	cParticle_I;
+	Particle_Index			lParticle_I;
+
+	cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	cParticle_I = Swarm_FindClosestParticleInCell( swarm, cell_I, Mesh_GetDimSize( self->dofLayout->mesh ), particle->xi, &distance );
+
+	// this function doesn't seem to be doing its joob properly!
+	//lParticle_I = IntegrationPointMapper_GetMaterialIndexAt( swarm->mapper, swarm->cellParticleTbl[cell_I][cParticle_I] );
+	
+	/* assume that the material and intergation points swarms map 1:1 */
+	lParticle_I = swarm->cellParticleTbl[cell_I][cParticle_I];
+	
+	
+	SwarmVariable_ValueAt( self->swarmVar, lParticle_I, value ); /* does the copy inside this func. dave, 18.09.07 */
+}
+
+void _SwarmVariableField_GetValueAtNode( void* swarmVariableField, Node_DomainIndex dNode_I, double* value ) {
+	FeVariable_GetValueAtNode( swarmVariableField, dNode_I, value );
+}
+
+/* implement these two functions later... */
+/*
+double _SwarmVariableField_GetMinGlobalMagnitude( void* swarmVariableField ) {
+	return _SwarmVariable_GetMinGlobalMagnitude( swarmVariableField );
+}
+double _SwarmVariableField_GetMaxGlobalMagnitude( void* swarmVariableField ) {
+	return _SwarmVariable_GetMaxGlobalMagnitude( swarmVariableField );
+}
+*/
+
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/AdvectionSuite.c
--- a/MaterialPoints/tests/AdvectionSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,229 +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 AdvectionSuite
-**
-** $Id: testAdvection.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/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include "AdvectionSuite.h"
-
-#define CURR_MODULE_NAME "AdvectionSuite"
-
-ExtensionInfo_Index handle;
-
-typedef struct {
-} AdvectionSuiteData;
-
-
-void AdvectionSuite_Setup( AdvectionSuiteData* data ) {
-}
-
-void AdvectionSuite_Teardown( AdvectionSuiteData* data ) {
-}
-
-double dt( void* dd, PICelleratorContext* context ) {
-	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"dt", 0.01 );
-}
-
-void check( PICelleratorContext* context  ) {
-	MaterialPointsSwarm*   materialPointsSwarm;
-	GlobalParticle*   particle;
-	double*           originalCoord;
-	double*           coord;
-	Particle_Index    lParticle_I;
-	double            maxRadiusError       = 0.0;
-	double            maxThetaError        = 0.0;
-	double            maxDepthError        = 0.0;
-	double            maxRadiusErrorGlobal;
-	double            maxThetaErrorGlobal;
-	double            maxDepthErrorGlobal;
-	double            currentRadius;
-	double            originalRadius;
-	double            originalTheta;
-	Coord             analyticCoord;
-	double            time                 = context->currentTime + context->dt;
-	Dictionary*       dictionary           = context->dictionary;
-	double		  depthErrorTolerance  = Dictionary_GetDouble( dictionary, "depthErrorTolerance" );
-	double		  radiusErrorTolerance = Dictionary_GetDouble( dictionary, "radiusErrorTolerance" );
-	double		  thetaErrorTolerance  = Dictionary_GetDouble( dictionary, "thetaErrorTolerance" );
-	double		  theta;
-
-	/* Add original pos to particle */
-	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm" );
-
-	for ( lParticle_I = 0 ; lParticle_I < materialPointsSwarm->particleLocalCount ; lParticle_I++ ) {
-		particle      = (GlobalParticle* )Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
-		coord         = particle->coord;
-		originalCoord = (double*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, particle, handle );
-
-		currentRadius  = StGermain_VectorMagnitude( coord, 2 );
-		originalRadius = StGermain_VectorMagnitude( originalCoord, 2 );
-		
-		originalTheta = acos( originalCoord[ I_AXIS ]/originalRadius );
-		if ( originalCoord[ J_AXIS ] < 0.0 )
-			originalTheta = 2 * M_PI - originalTheta;
-
-		analyticCoord[ I_AXIS ] = originalRadius*cos( time + originalTheta );
-		analyticCoord[ J_AXIS ] = originalRadius*sin( time + originalTheta );
-		analyticCoord[ K_AXIS ] = originalCoord[ K_AXIS ];
-
-		maxDepthError  = MAX( maxDepthError,  fabs( originalCoord[ K_AXIS ] - coord[ K_AXIS ] ) );
-		maxRadiusError = MAX( maxRadiusError, fabs( currentRadius - originalRadius ) );
-
-		theta = StGermain_AngleBetweenVectors( analyticCoord, coord, 2 );
-		if( theta > maxThetaError )
-			maxThetaError = theta;
-		//maxThetaError  = MAX( maxThetaError, theta );
-	}
-
-	MPI_Allreduce( &maxDepthError,  &maxDepthErrorGlobal,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-	MPI_Allreduce( &maxRadiusError, &maxRadiusErrorGlobal, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-	MPI_Allreduce( &maxThetaError,  &maxThetaErrorGlobal,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
-
-	pcu_check_true( maxDepthErrorGlobal < depthErrorTolerance );
-	pcu_check_true( maxRadiusErrorGlobal < radiusErrorTolerance );
-	pcu_check_true( maxThetaErrorGlobal < thetaErrorTolerance );
-}
-
-void AdvectionSuite_TestEuler( AdvectionSuiteData* data ) {
-	Stg_ComponentFactory* 	cf;
-	PICelleratorContext* 	context;
-	char			filename[PCU_PATH_MAX];
-	MaterialPointsSwarm*	matSwarm;
-	unsigned		particle_i;
-	GlobalParticle*		particle;
-	double*			origCoord;
-	
-	pcu_filename_input( "testEuler.xml", filename );
-	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
-	cf = stgMainInitFromXML( filename, MPI_COMM_WORLD, context );
-
-	matSwarm = (MaterialPointsSwarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm"  );
-	handle = ExtensionManager_Add( matSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof(Coord)  );
-
-	Stg_ComponentFactory_BuildComponents( cf, NULL );
-	Stg_ComponentFactory_InitialiseComponents( cf, NULL );
-
-	for( particle_i = 0; particle_i < matSwarm->particleLocalCount; particle_i++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( matSwarm, particle_i );
-		origCoord = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, particle, handle );
-		memcpy( origCoord, particle->coord, sizeof(Coord) );
-	}
-
-	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
-
-	stgMainLoop( cf );
-
-	Stg_ComponentFactory_DestroyComponents( cf, data );
-}
-
-void AdvectionSuite_TestRK2( AdvectionSuiteData* data ) {
-	Stg_ComponentFactory* 	cf;
-	PICelleratorContext* 	context;
-	char			filename[PCU_PATH_MAX];
-	MaterialPointsSwarm*	matSwarm;
-	unsigned		particle_i;
-	GlobalParticle*		particle;
-	double*			origCoord;
-	
-	pcu_filename_input( "testRK2.xml", filename );
-	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
-	cf = stgMainInitFromXML( filename, MPI_COMM_WORLD, context );
-
-	matSwarm = (MaterialPointsSwarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm"  );
-	handle = ExtensionManager_Add( matSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof(Coord)  );
-
-	Stg_ComponentFactory_BuildComponents( cf, NULL );
-	Stg_ComponentFactory_InitialiseComponents( cf, NULL );
-
-	for( particle_i = 0; particle_i < matSwarm->particleLocalCount; particle_i++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( matSwarm, particle_i );
-		origCoord = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, particle, handle );
-		memcpy( origCoord, particle->coord, sizeof(Coord) );
-	}
-
-	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
-
-	stgMainLoop( cf );
-
-	Stg_ComponentFactory_DestroyComponents( cf, data );
-}
-
-void AdvectionSuite_TestRK4( AdvectionSuiteData* data ) {
-	Stg_ComponentFactory* 	cf;
-	PICelleratorContext* 	context;
-	char			filename[PCU_PATH_MAX];
-	MaterialPointsSwarm*	matSwarm;
-	unsigned		particle_i;
-	GlobalParticle*		particle;
-	double*			origCoord;
-	
-	pcu_filename_input( "testRK4.xml", filename );
-	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
-	cf = stgMainInitFromXML( filename, MPI_COMM_WORLD, context );
-
-	matSwarm = (MaterialPointsSwarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm"  );
-	handle = ExtensionManager_Add( matSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof(Coord)  );
-
-	Stg_ComponentFactory_BuildComponents( cf, NULL );
-	Stg_ComponentFactory_InitialiseComponents( cf, NULL );
-
-	for( particle_i = 0; particle_i < matSwarm->particleLocalCount; particle_i++ ) {
-		particle = (GlobalParticle*)Swarm_ParticleAt( matSwarm, particle_i );
-		origCoord = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, particle, handle );
-		memcpy( origCoord, particle->coord, sizeof(Coord) );
-	}
-
-	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
-	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
-
-	stgMainLoop( cf );
-
-	Stg_ComponentFactory_DestroyComponents( cf, data );
-}
-
-void AdvectionSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, AdvectionSuiteData );
-   pcu_suite_setFixtures( suite, AdvectionSuite_Setup, AdvectionSuite_Teardown );
-   pcu_suite_addTest( suite, AdvectionSuite_TestEuler );
-   pcu_suite_addTest( suite, AdvectionSuite_TestRK2 );
-   pcu_suite_addTest( suite, AdvectionSuite_TestRK4 );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/AdvectionSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/tests/AdvectionSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,229 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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 AdvectionSuite
+**
+** $Id: testAdvection.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/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include "AdvectionSuite.h"
+
+#define CURR_MODULE_NAME "AdvectionSuite"
+
+ExtensionInfo_Index handle;
+
+typedef struct {
+} AdvectionSuiteData;
+
+
+void AdvectionSuite_Setup( AdvectionSuiteData* data ) {
+}
+
+void AdvectionSuite_Teardown( AdvectionSuiteData* data ) {
+}
+
+double dt( void* dd, PICelleratorContext* context ) {
+	return Dictionary_GetDouble_WithDefault( context->dictionary, (Dictionary_Entry_Key)"dt", 0.01 );
+}
+
+void check( PICelleratorContext* context  ) {
+	MaterialPointsSwarm*   materialPointsSwarm;
+	GlobalParticle*   particle;
+	double*           originalCoord;
+	double*           coord;
+	Particle_Index    lParticle_I;
+	double            maxRadiusError       = 0.0;
+	double            maxThetaError        = 0.0;
+	double            maxDepthError        = 0.0;
+	double            maxRadiusErrorGlobal;
+	double            maxThetaErrorGlobal;
+	double            maxDepthErrorGlobal;
+	double            currentRadius;
+	double            originalRadius;
+	double            originalTheta;
+	Coord             analyticCoord;
+	double            time                 = context->currentTime + context->dt;
+	Dictionary*       dictionary           = context->dictionary;
+	double		  depthErrorTolerance  = Dictionary_GetDouble( dictionary, "depthErrorTolerance" );
+	double		  radiusErrorTolerance = Dictionary_GetDouble( dictionary, "radiusErrorTolerance" );
+	double		  thetaErrorTolerance  = Dictionary_GetDouble( dictionary, "thetaErrorTolerance" );
+	double		  theta;
+
+	/* Add original pos to particle */
+	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm" );
+
+	for ( lParticle_I = 0 ; lParticle_I < materialPointsSwarm->particleLocalCount ; lParticle_I++ ) {
+		particle      = (GlobalParticle* )Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
+		coord         = particle->coord;
+		originalCoord = (double*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, particle, handle );
+
+		currentRadius  = StGermain_VectorMagnitude( coord, 2 );
+		originalRadius = StGermain_VectorMagnitude( originalCoord, 2 );
+		
+		originalTheta = acos( originalCoord[ I_AXIS ]/originalRadius );
+		if ( originalCoord[ J_AXIS ] < 0.0 )
+			originalTheta = 2 * M_PI - originalTheta;
+
+		analyticCoord[ I_AXIS ] = originalRadius*cos( time + originalTheta );
+		analyticCoord[ J_AXIS ] = originalRadius*sin( time + originalTheta );
+		analyticCoord[ K_AXIS ] = originalCoord[ K_AXIS ];
+
+		maxDepthError  = MAX( maxDepthError,  fabs( originalCoord[ K_AXIS ] - coord[ K_AXIS ] ) );
+		maxRadiusError = MAX( maxRadiusError, fabs( currentRadius - originalRadius ) );
+
+		theta = StGermain_AngleBetweenVectors( analyticCoord, coord, 2 );
+		if( theta > maxThetaError )
+			maxThetaError = theta;
+		//maxThetaError  = MAX( maxThetaError, theta );
+	}
+
+	MPI_Allreduce( &maxDepthError,  &maxDepthErrorGlobal,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+	MPI_Allreduce( &maxRadiusError, &maxRadiusErrorGlobal, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+	MPI_Allreduce( &maxThetaError,  &maxThetaErrorGlobal,  1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
+
+	pcu_check_true( maxDepthErrorGlobal < depthErrorTolerance );
+	pcu_check_true( maxRadiusErrorGlobal < radiusErrorTolerance );
+	pcu_check_true( maxThetaErrorGlobal < thetaErrorTolerance );
+}
+
+void AdvectionSuite_TestEuler( AdvectionSuiteData* data ) {
+	Stg_ComponentFactory* 	cf;
+	PICelleratorContext* 	context;
+	char			filename[PCU_PATH_MAX];
+	MaterialPointsSwarm*	matSwarm;
+	unsigned		particle_i;
+	GlobalParticle*		particle;
+	double*			origCoord;
+	
+	pcu_filename_input( "testEuler.xml", filename );
+	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
+	cf = stgMainInitFromXML( filename, MPI_COMM_WORLD, context );
+
+	matSwarm = (MaterialPointsSwarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm"  );
+	handle = ExtensionManager_Add( matSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof(Coord)  );
+
+	Stg_ComponentFactory_BuildComponents( cf, NULL );
+	Stg_ComponentFactory_InitialiseComponents( cf, NULL );
+
+	for( particle_i = 0; particle_i < matSwarm->particleLocalCount; particle_i++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( matSwarm, particle_i );
+		origCoord = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, particle, handle );
+		memcpy( origCoord, particle->coord, sizeof(Coord) );
+	}
+
+	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
+
+	stgMainLoop( cf );
+
+	Stg_ComponentFactory_DestroyComponents( cf, data );
+}
+
+void AdvectionSuite_TestRK2( AdvectionSuiteData* data ) {
+	Stg_ComponentFactory* 	cf;
+	PICelleratorContext* 	context;
+	char			filename[PCU_PATH_MAX];
+	MaterialPointsSwarm*	matSwarm;
+	unsigned		particle_i;
+	GlobalParticle*		particle;
+	double*			origCoord;
+	
+	pcu_filename_input( "testRK2.xml", filename );
+	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
+	cf = stgMainInitFromXML( filename, MPI_COMM_WORLD, context );
+
+	matSwarm = (MaterialPointsSwarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm"  );
+	handle = ExtensionManager_Add( matSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof(Coord)  );
+
+	Stg_ComponentFactory_BuildComponents( cf, NULL );
+	Stg_ComponentFactory_InitialiseComponents( cf, NULL );
+
+	for( particle_i = 0; particle_i < matSwarm->particleLocalCount; particle_i++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( matSwarm, particle_i );
+		origCoord = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, particle, handle );
+		memcpy( origCoord, particle->coord, sizeof(Coord) );
+	}
+
+	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
+
+	stgMainLoop( cf );
+
+	Stg_ComponentFactory_DestroyComponents( cf, data );
+}
+
+void AdvectionSuite_TestRK4( AdvectionSuiteData* data ) {
+	Stg_ComponentFactory* 	cf;
+	PICelleratorContext* 	context;
+	char			filename[PCU_PATH_MAX];
+	MaterialPointsSwarm*	matSwarm;
+	unsigned		particle_i;
+	GlobalParticle*		particle;
+	double*			origCoord;
+	
+	pcu_filename_input( "testRK4.xml", filename );
+	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
+	cf = stgMainInitFromXML( filename, MPI_COMM_WORLD, context );
+
+	matSwarm = (MaterialPointsSwarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPointsSwarm"  );
+	handle = ExtensionManager_Add( matSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof(Coord)  );
+
+	Stg_ComponentFactory_BuildComponents( cf, NULL );
+	Stg_ComponentFactory_InitialiseComponents( cf, NULL );
+
+	for( particle_i = 0; particle_i < matSwarm->particleLocalCount; particle_i++ ) {
+		particle = (GlobalParticle*)Swarm_ParticleAt( matSwarm, particle_i );
+		origCoord = (double*)ExtensionManager_Get( matSwarm->particleExtensionMgr, particle, handle );
+		memcpy( origCoord, particle->coord, sizeof(Coord) );
+	}
+
+	ContextEP_Prepend( context, AbstractContext_EP_Step, check );
+	EP_AppendClassHook( Context_GetEntryPoint( context, FiniteElementContext_EP_CalcDt ), dt, context );
+
+	stgMainLoop( cf );
+
+	Stg_ComponentFactory_DestroyComponents( cf, data );
+}
+
+void AdvectionSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, AdvectionSuiteData );
+   pcu_suite_setFixtures( suite, AdvectionSuite_Setup, AdvectionSuite_Teardown );
+   pcu_suite_addTest( suite, AdvectionSuite_TestEuler );
+   pcu_suite_addTest( suite, AdvectionSuite_TestRK2 );
+   pcu_suite_addTest( suite, AdvectionSuite_TestRK4 );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/MaterialComponentsSuite.c
--- a/MaterialPoints/tests/MaterialComponentsSuite.c	Wed May 11 13:26:28 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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-/*******************
-** Note: this test is currently designed to test the 3 components MaterialPointsSwarm, Material, and Materials_Register.
-**  The reason is that their design and implementation is very tightly coupled (especially during Build and Init phases).
-** 
-********************/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "PICellerator/PopulationControl/PopulationControl.h"
-#include "PICellerator/Weights/Weights.h"
-#include "PICellerator/MaterialPoints/MaterialPoints.h"
-
-struct _Node {
-   Coord            coord;
-};
-
-struct _Element {
-   Coord            coord;
-};
-
-struct _Particle {
-   __MaterialPoint
-   unsigned int   matProp1;
-   double         matProp2;
-   Bool           matProp3;
-   Bool           matProp4;
-};
-
-typedef struct {
-   FeMesh*                       feMesh;
-   CellLayout*                   cellLayout;
-   ParticleLayout*               particleLayout;
-   MaterialPointsSwarm*          mpSwarm;
-   Variable_Register*            svRegister;
-   ExtensionManager_Register*    eRegister;
-   Materials_Register*           mRegister;
-	LiveComponentRegister*			lcRegister;
-   Dictionary*                   matDict1;
-   Dictionary*                   matDict2;
-   Stg_Shape*                    shape1;
-   Stg_Shape*                    shape2;
-   Material*                     mat1;
-   Material*                     mat2;
-   SwarmVariable*                matPropVar1;
-   SwarmVariable*                matPropVar2;
-   SwarmVariable*                matPropVar3;
-   SwarmVariable*                matPropVar4;
-} MaterialComponentsSuiteData;
-
-
-FeMesh* buildFeMesh( unsigned nDims, unsigned* size, 
-           double* minCrds, double* maxCrds, 
-           ExtensionManager_Register* emReg )
-{
-   CartesianGenerator*   gen;
-   FeMesh*         feMesh;
-
-   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 );
-
-   feMesh = FeMesh_New( "", NULL );
-   Mesh_SetExtensionManagerRegister( feMesh, emReg );
-   Mesh_SetGenerator( feMesh, gen );
-   FeMesh_SetElementFamily( feMesh, "linear" );
-
-   Stg_Component_Build( feMesh, NULL, False );
-   Stg_Component_Initialise( feMesh, NULL, False );
-
-   KillObject( feMesh->generator );
-
-   return feMesh;
-}
-
-
-void MaterialComponentsSuite_BuildInitSwarmBasics( MaterialComponentsSuiteData* data ) {
-   Index             var_I;
-   Particle_Index    pI;
-   MaterialPoint*    matPoint;
-
-   /* Mesh will already be initialised */
-   /* Manually do the basic Swarm building and initialising */
-   _Swarm_Build( data->mpSwarm, NULL );
-   for( var_I = 0 ; var_I < data->mpSwarm->nSwarmVars ; var_I++ ) {
-		Stg_Component_Build( data->mpSwarm->swarmVars[var_I], NULL , False );
-	}
-   _Swarm_Initialise( data->mpSwarm, NULL );
-   for( var_I = 0 ; var_I < data->mpSwarm->nSwarmVars ; var_I++ ) {
-		Stg_Component_Initialise( data->mpSwarm->swarmVars[var_I], NULL , False );
-	}
-   /* Pre-set the swarm particle material indexes to undefined, as in the build function */
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
-      matPoint->materialIndex = UNDEFINED_MATERIAL;
-   }
-}
-
-
-void MaterialComponentsSuite_Setup( MaterialComponentsSuiteData* data ) {
-   unsigned    dim = 3;
-   unsigned    meshSize[3] = {2, 2, 2};
-   double      minCrds[3] = {0.0, 0.0, 0.0};
-   double      maxCrds[3] = {1.0, 1.0, 1.0};
-   XYZ         boxCentre = {0.25,0.25,0.25};
-   XYZ         boxWidth = {0.4,0.4,0.4};
-   XYZ         sphereCentre = {0.75,0.75,0.75};
-   double      sphereRadius = 0.2;
-   Particle_Index    pI;
-   Particle*         matPoint;
-   Particle          particle;
-
-	data->lcRegister = LiveComponentRegister_New();
-   data->svRegister = Variable_Register_New();
-   data->eRegister = ExtensionManager_Register_New();
-   data->mRegister = Materials_Register_New();
-
-   /* Turn off the journal to avoid debug messages about parsing */
-   Journal_Enable_TypedStream( Debug_Type, False );
-   Journal_Enable_TypedStream( Info_Type, False );
-
-   data->feMesh = buildFeMesh( dim, meshSize, minCrds, maxCrds, data->eRegister );
-
-   data->cellLayout = (CellLayout*)ElementCellLayout_New( "elementCellLayout", NULL, data->feMesh );
-   data->particleLayout = (ParticleLayout*)RandomParticleLayout_New( "randomParticleCellLayout", NULL, GlobalCoordSystem, False, 20, 13 );
-
-   data->mpSwarm = MaterialPointsSwarm_New(
-         "testSwarm", NULL,
-         data->cellLayout,
-         data->particleLayout,
-         dim,                      /* dim */
-         sizeof(Particle),
-         data->feMesh,
-         NULL,                   /* escapedRoutine*/
-         NULL,                   /* material */
-         data->svRegister,
-         data->eRegister,
-         data->mRegister,
-         MPI_COMM_WORLD,
-         NULL );
-
-   data->shape1 = (Stg_Shape*)Box_New( "boxShape", dim, boxCentre, 0, 0, 0, boxWidth );
-   data->shape2 = (Stg_Shape*)Sphere_New( "sphereShape", dim, sphereCentre, 0, 0, 0, sphereRadius );
-
-   /* Set up the dictionaries, and set some sample properties for testing */
-   data->matDict1 = Dictionary_New();
-   Dictionary_Add( data->matDict1, (Dictionary_Entry_Key)"testSwarm-matProp1", Dictionary_Entry_Value_FromUnsignedInt( 1 )  );
-   Dictionary_Add( data->matDict1, (Dictionary_Entry_Key)"testSwarm-matProp2", Dictionary_Entry_Value_FromDouble( 1.1 )  );
-   Dictionary_Add( data->matDict1, (Dictionary_Entry_Key)"testSwarm-matProp3", Dictionary_Entry_Value_FromBool( False ) );
-   data->matDict2 = Dictionary_New( );
-   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp1", Dictionary_Entry_Value_FromUnsignedInt( 2 )  );
-   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp2", Dictionary_Entry_Value_FromDouble( 2.2 )  );
-   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp3", Dictionary_Entry_Value_FromBool( True )  );
-   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp4", Dictionary_Entry_Value_FromBool( True )  );
-
-   /* Now update the svRegister to match the material properties */
-	data->matPropVar1 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp1", GetOffsetOfMember( particle , matProp1  ), Variable_DataType_Int );
-	data->matPropVar2 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp2", GetOffsetOfMember( particle , matProp2  ), Variable_DataType_Double );
-	data->matPropVar3 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp3", GetOffsetOfMember( particle , matProp3  ), Variable_DataType_Int );
-	data->matPropVar4 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp4", GetOffsetOfMember( particle , matProp4  ), Variable_DataType_Int );
-
-   data->mat1 = Material_New( "mat1", NULL, data->shape1, data->matDict1, data->mRegister );
-   data->mat2 = Material_New( "mat2", NULL, data->shape2, data->matDict2, data->mRegister );
-
-   MaterialComponentsSuite_BuildInitSwarmBasics( data );
-   /* Now set them all the swarm var properties to 0 / False initially */
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (Particle*)Swarm_ParticleAt( data->mpSwarm, pI );
-      matPoint->matProp1 = 0;
-      matPoint->matProp2 = 0.0;
-      matPoint->matProp3 = False;
-      matPoint->matProp4 = False;
-   }
-}
-
-
-void MaterialComponentsSuite_Teardown( MaterialComponentsSuiteData* data ) {
-   _Stg_Component_Delete( data->mpSwarm );
-   _Stg_Component_Delete( data->cellLayout );
-   _Stg_Component_Delete( data->particleLayout );
-   _Stg_Component_Delete( data->feMesh );
-	Stg_Class_Delete( data->lcRegister );
-   Stg_Class_Delete( data->eRegister );
-   Stg_Class_Delete( data->svRegister );
-   Stg_Class_Delete( data->mRegister );
-   _Stg_Component_Delete( data->mat1 );
-   _Stg_Component_Delete( data->mat2 );
-   Stg_Class_Delete( data->matDict1 );
-   Stg_Class_Delete( data->matDict2 );
-   _Stg_Component_Delete( data->shape1 );
-   _Stg_Component_Delete( data->shape2 );
-}
-
-
-/*Tests*/
-void MaterialComponentsSuite_TestRegisterSetup( MaterialComponentsSuiteData* data ) {
-
-   pcu_docstring( "This test simply checks that the Material_Register associated to a test MP_Swarm is correctly set-up as part of the "
-      "Swarm's Build phase (performed already in test suite setup." );
-
-   pcu_check_true( data->mRegister != NULL );
-   pcu_check_true( Materials_Register_GetCount( data->mRegister ) == 2 );
-   pcu_check_true( Materials_Register_GetByIndex( data->mRegister, 0 ) == data->mat1 );
-   pcu_check_true( Materials_Register_GetByIndex( data->mRegister, 1 ) == data->mat2 );
-}
-
-
-void MaterialComponentsSuite_TestMaterialLayout( MaterialComponentsSuiteData* data ) {
-   Particle_Index    pI;
-   MaterialPoint*    matPoint;
-
-   pcu_docstring( "Tests that 2 given materials can be successfully 'layed out' - that is, the particles of a swarm have their materialIndex"
-      "correctly updated to index the right material in the material register, thus setting up an ownership relationship." );
-   
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
-      pcu_check_true( matPoint->materialIndex == UNDEFINED_MATERIAL );
-   }
-
-   Material_Layout( data->mat1, data->mpSwarm );
-   Material_Layout( data->mat2, data->mpSwarm );
-
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
-      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
-         pcu_check_true( matPoint->materialIndex == 0 );
-      }
-      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
-         pcu_check_true( matPoint->materialIndex == 1 );
-      }
-      else {
-         pcu_check_true( matPoint->materialIndex == UNDEFINED_MATERIAL );
-      }
-   }
-}
-
-
-void MaterialComponentsSuite_TestLayoutGeometry( MaterialComponentsSuiteData* data ) {
-   Particle_Index    pI;
-   MaterialPoint*    matPoint;
-
-   pcu_docstring( "Similar to TestMaterialLayout, checks that all materials in a register can be 'layed out' correctly - ie the individual"
-      "Particles in a MaterialPointSwarm updated to index the correct material in the register." );
-   _Materials_Register_LayoutGeometry( data->mRegister, data->mpSwarm );
-   
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
-      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
-         pcu_check_true( matPoint->materialIndex == 0 );
-      }
-      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
-         pcu_check_true( matPoint->materialIndex == 1 );
-      }
-      else {
-         pcu_check_true( matPoint->materialIndex == UNDEFINED_MATERIAL );
-      }
-   }
-}
-
-void MaterialComponentsSuite_TestGetMaterial( MaterialComponentsSuiteData* data ) {
-   Particle_Index    pI;
-   MaterialPoint*    matPoint;
-   Material*         material = NULL;
-   Material*         materialOn = NULL;
-   Material_Index    matIndex;
-
-   pcu_docstring( "Tests that after a layout has been performed, the material that a particle belongs to can be successfully looked up."
-      "Thus requires TestLayoutGeometry to pass beforehand." );
-
-   _Materials_Register_LayoutGeometry( data->mRegister, data->mpSwarm );
-
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
-      material = MaterialPointsSwarm_GetMaterialAt( data->mpSwarm, pI );
-      materialOn = MaterialPointsSwarm_GetMaterialOn( data->mpSwarm, matPoint );
-      matIndex = MaterialPointsSwarm_GetMaterialIndexAt( data->mpSwarm, pI );
-
-      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
-         pcu_check_true( material == data->mat1 );
-         pcu_check_true( materialOn == data->mat1 );
-         pcu_check_true( matIndex == 0 );
-      }
-      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
-         pcu_check_true( material == data->mat2 );
-         pcu_check_true( materialOn == data->mat2 );
-         pcu_check_true( matIndex == 1 );
-      }
-      else {
-         pcu_check_true( NULL == material );
-         pcu_check_true( NULL == materialOn );
-         pcu_check_true( UNDEFINED_MATERIAL == matIndex );
-      }
-   }
-}
-
-
-void MaterialComponentsSuite_TestAssignParticleProperties( MaterialComponentsSuiteData* data ) {
-   Particle_Index    pI;
-   Particle*         matPoint;
-
-   pcu_docstring( "This tests the function Materials_Register_AssignParticleProperties: essentially, material "
-      "properties that should be allowed to vary on a per-particle basis during simulation are set up as "
-      "SwarmVariables, and this test ensures they are applied correctly at startup." );
-
-   _Materials_Register_LayoutGeometry( data->mRegister, data->mpSwarm );
-   Materials_Register_AssignParticleProperties( data->mRegister, data->mpSwarm, data->svRegister );
-
-   /* check the properties have been assigned as expected - see Setup phase */
-   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
-      matPoint = (Particle*)Swarm_ParticleAt( data->mpSwarm, pI );
-      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
-         pcu_check_true( matPoint->matProp1 == 1 );
-         pcu_check_true( matPoint->matProp2 == 1.1 );
-         pcu_check_true( matPoint->matProp3 == False );
-         pcu_check_true( matPoint->matProp4 == False );
-      }
-      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
-         pcu_check_true( matPoint->matProp1 == 2 );
-         pcu_check_true( matPoint->matProp2 == 2.2 );
-         pcu_check_true( matPoint->matProp3 == True );
-         pcu_check_true( matPoint->matProp4 == True );
-      }
-      else {
-         pcu_check_true( matPoint->matProp1 == 0 );
-         pcu_check_true( matPoint->matProp2 == 0.0 );
-         pcu_check_true( matPoint->matProp3 == False );
-         pcu_check_true( matPoint->matProp4 == False );
-      }
-   }
-}
-
-/* TODO M_Register: Test the extension functions work correctly */
-
-
-void MaterialComponentsSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, MaterialComponentsSuiteData );
-   pcu_suite_setFixtures( suite, MaterialComponentsSuite_Setup, MaterialComponentsSuite_Teardown );
-   pcu_suite_addTest( suite, MaterialComponentsSuite_TestRegisterSetup );
-   pcu_suite_addTest( suite, MaterialComponentsSuite_TestMaterialLayout );
-   pcu_suite_addTest( suite, MaterialComponentsSuite_TestLayoutGeometry );
-   pcu_suite_addTest( suite, MaterialComponentsSuite_TestGetMaterial );
-   pcu_suite_addTest( suite, MaterialComponentsSuite_TestAssignParticleProperties );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/MaterialComponentsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/tests/MaterialComponentsSuite.cxx	Thu May 12 11:18:04 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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+/*******************
+** Note: this test is currently designed to test the 3 components MaterialPointsSwarm, Material, and Materials_Register.
+**  The reason is that their design and implementation is very tightly coupled (especially during Build and Init phases).
+** 
+********************/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "PICellerator/PopulationControl/PopulationControl.h"
+#include "PICellerator/Weights/Weights.h"
+#include "PICellerator/MaterialPoints/MaterialPoints.h"
+
+struct _Node {
+   Coord            coord;
+};
+
+struct _Element {
+   Coord            coord;
+};
+
+struct _Particle {
+   __MaterialPoint
+   unsigned int   matProp1;
+   double         matProp2;
+   Bool           matProp3;
+   Bool           matProp4;
+};
+
+typedef struct {
+   FeMesh*                       feMesh;
+   CellLayout*                   cellLayout;
+   ParticleLayout*               particleLayout;
+   MaterialPointsSwarm*          mpSwarm;
+   Variable_Register*            svRegister;
+   ExtensionManager_Register*    eRegister;
+   Materials_Register*           mRegister;
+	LiveComponentRegister*			lcRegister;
+   Dictionary*                   matDict1;
+   Dictionary*                   matDict2;
+   Stg_Shape*                    shape1;
+   Stg_Shape*                    shape2;
+   Material*                     mat1;
+   Material*                     mat2;
+   SwarmVariable*                matPropVar1;
+   SwarmVariable*                matPropVar2;
+   SwarmVariable*                matPropVar3;
+   SwarmVariable*                matPropVar4;
+} MaterialComponentsSuiteData;
+
+
+FeMesh* buildFeMesh( unsigned nDims, unsigned* size, 
+           double* minCrds, double* maxCrds, 
+           ExtensionManager_Register* emReg )
+{
+   CartesianGenerator*   gen;
+   FeMesh*         feMesh;
+
+   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 );
+
+   feMesh = FeMesh_New( "", NULL );
+   Mesh_SetExtensionManagerRegister( feMesh, emReg );
+   Mesh_SetGenerator( feMesh, gen );
+   FeMesh_SetElementFamily( feMesh, "linear" );
+
+   Stg_Component_Build( feMesh, NULL, False );
+   Stg_Component_Initialise( feMesh, NULL, False );
+
+   KillObject( feMesh->generator );
+
+   return feMesh;
+}
+
+
+void MaterialComponentsSuite_BuildInitSwarmBasics( MaterialComponentsSuiteData* data ) {
+   Index             var_I;
+   Particle_Index    pI;
+   MaterialPoint*    matPoint;
+
+   /* Mesh will already be initialised */
+   /* Manually do the basic Swarm building and initialising */
+   _Swarm_Build( data->mpSwarm, NULL );
+   for( var_I = 0 ; var_I < data->mpSwarm->nSwarmVars ; var_I++ ) {
+		Stg_Component_Build( data->mpSwarm->swarmVars[var_I], NULL , False );
+	}
+   _Swarm_Initialise( data->mpSwarm, NULL );
+   for( var_I = 0 ; var_I < data->mpSwarm->nSwarmVars ; var_I++ ) {
+		Stg_Component_Initialise( data->mpSwarm->swarmVars[var_I], NULL , False );
+	}
+   /* Pre-set the swarm particle material indexes to undefined, as in the build function */
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
+      matPoint->materialIndex = UNDEFINED_MATERIAL;
+   }
+}
+
+
+void MaterialComponentsSuite_Setup( MaterialComponentsSuiteData* data ) {
+   unsigned    dim = 3;
+   unsigned    meshSize[3] = {2, 2, 2};
+   double      minCrds[3] = {0.0, 0.0, 0.0};
+   double      maxCrds[3] = {1.0, 1.0, 1.0};
+   XYZ         boxCentre = {0.25,0.25,0.25};
+   XYZ         boxWidth = {0.4,0.4,0.4};
+   XYZ         sphereCentre = {0.75,0.75,0.75};
+   double      sphereRadius = 0.2;
+   Particle_Index    pI;
+   Particle*         matPoint;
+   Particle          particle;
+
+	data->lcRegister = LiveComponentRegister_New();
+   data->svRegister = Variable_Register_New();
+   data->eRegister = ExtensionManager_Register_New();
+   data->mRegister = Materials_Register_New();
+
+   /* Turn off the journal to avoid debug messages about parsing */
+   Journal_Enable_TypedStream( Debug_Type, False );
+   Journal_Enable_TypedStream( Info_Type, False );
+
+   data->feMesh = buildFeMesh( dim, meshSize, minCrds, maxCrds, data->eRegister );
+
+   data->cellLayout = (CellLayout*)ElementCellLayout_New( "elementCellLayout", NULL, data->feMesh );
+   data->particleLayout = (ParticleLayout*)RandomParticleLayout_New( "randomParticleCellLayout", NULL, GlobalCoordSystem, False, 20, 13 );
+
+   data->mpSwarm = MaterialPointsSwarm_New(
+         "testSwarm", NULL,
+         data->cellLayout,
+         data->particleLayout,
+         dim,                      /* dim */
+         sizeof(Particle),
+         data->feMesh,
+         NULL,                   /* escapedRoutine*/
+         NULL,                   /* material */
+         data->svRegister,
+         data->eRegister,
+         data->mRegister,
+         MPI_COMM_WORLD,
+         NULL );
+
+   data->shape1 = (Stg_Shape*)Box_New( "boxShape", dim, boxCentre, 0, 0, 0, boxWidth );
+   data->shape2 = (Stg_Shape*)Sphere_New( "sphereShape", dim, sphereCentre, 0, 0, 0, sphereRadius );
+
+   /* Set up the dictionaries, and set some sample properties for testing */
+   data->matDict1 = Dictionary_New();
+   Dictionary_Add( data->matDict1, (Dictionary_Entry_Key)"testSwarm-matProp1", Dictionary_Entry_Value_FromUnsignedInt( 1 )  );
+   Dictionary_Add( data->matDict1, (Dictionary_Entry_Key)"testSwarm-matProp2", Dictionary_Entry_Value_FromDouble( 1.1 )  );
+   Dictionary_Add( data->matDict1, (Dictionary_Entry_Key)"testSwarm-matProp3", Dictionary_Entry_Value_FromBool( False ) );
+   data->matDict2 = Dictionary_New( );
+   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp1", Dictionary_Entry_Value_FromUnsignedInt( 2 )  );
+   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp2", Dictionary_Entry_Value_FromDouble( 2.2 )  );
+   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp3", Dictionary_Entry_Value_FromBool( True )  );
+   Dictionary_Add( data->matDict2, (Dictionary_Entry_Key)"testSwarm-matProp4", Dictionary_Entry_Value_FromBool( True )  );
+
+   /* Now update the svRegister to match the material properties */
+	data->matPropVar1 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp1", GetOffsetOfMember( particle , matProp1  ), Variable_DataType_Int );
+	data->matPropVar2 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp2", GetOffsetOfMember( particle , matProp2  ), Variable_DataType_Double );
+	data->matPropVar3 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp3", GetOffsetOfMember( particle , matProp3  ), Variable_DataType_Int );
+	data->matPropVar4 = Swarm_NewScalarVariable( data->mpSwarm, (Name)"matProp4", GetOffsetOfMember( particle , matProp4  ), Variable_DataType_Int );
+
+   data->mat1 = Material_New( "mat1", NULL, data->shape1, data->matDict1, data->mRegister );
+   data->mat2 = Material_New( "mat2", NULL, data->shape2, data->matDict2, data->mRegister );
+
+   MaterialComponentsSuite_BuildInitSwarmBasics( data );
+   /* Now set them all the swarm var properties to 0 / False initially */
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (Particle*)Swarm_ParticleAt( data->mpSwarm, pI );
+      matPoint->matProp1 = 0;
+      matPoint->matProp2 = 0.0;
+      matPoint->matProp3 = False;
+      matPoint->matProp4 = False;
+   }
+}
+
+
+void MaterialComponentsSuite_Teardown( MaterialComponentsSuiteData* data ) {
+   _Stg_Component_Delete( data->mpSwarm );
+   _Stg_Component_Delete( data->cellLayout );
+   _Stg_Component_Delete( data->particleLayout );
+   _Stg_Component_Delete( data->feMesh );
+	Stg_Class_Delete( data->lcRegister );
+   Stg_Class_Delete( data->eRegister );
+   Stg_Class_Delete( data->svRegister );
+   Stg_Class_Delete( data->mRegister );
+   _Stg_Component_Delete( data->mat1 );
+   _Stg_Component_Delete( data->mat2 );
+   Stg_Class_Delete( data->matDict1 );
+   Stg_Class_Delete( data->matDict2 );
+   _Stg_Component_Delete( data->shape1 );
+   _Stg_Component_Delete( data->shape2 );
+}
+
+
+/*Tests*/
+void MaterialComponentsSuite_TestRegisterSetup( MaterialComponentsSuiteData* data ) {
+
+   pcu_docstring( "This test simply checks that the Material_Register associated to a test MP_Swarm is correctly set-up as part of the "
+      "Swarm's Build phase (performed already in test suite setup." );
+
+   pcu_check_true( data->mRegister != NULL );
+   pcu_check_true( Materials_Register_GetCount( data->mRegister ) == 2 );
+   pcu_check_true( Materials_Register_GetByIndex( data->mRegister, 0 ) == data->mat1 );
+   pcu_check_true( Materials_Register_GetByIndex( data->mRegister, 1 ) == data->mat2 );
+}
+
+
+void MaterialComponentsSuite_TestMaterialLayout( MaterialComponentsSuiteData* data ) {
+   Particle_Index    pI;
+   MaterialPoint*    matPoint;
+
+   pcu_docstring( "Tests that 2 given materials can be successfully 'layed out' - that is, the particles of a swarm have their materialIndex"
+      "correctly updated to index the right material in the material register, thus setting up an ownership relationship." );
+   
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
+      pcu_check_true( matPoint->materialIndex == UNDEFINED_MATERIAL );
+   }
+
+   Material_Layout( data->mat1, data->mpSwarm );
+   Material_Layout( data->mat2, data->mpSwarm );
+
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
+      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
+         pcu_check_true( matPoint->materialIndex == 0 );
+      }
+      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
+         pcu_check_true( matPoint->materialIndex == 1 );
+      }
+      else {
+         pcu_check_true( matPoint->materialIndex == UNDEFINED_MATERIAL );
+      }
+   }
+}
+
+
+void MaterialComponentsSuite_TestLayoutGeometry( MaterialComponentsSuiteData* data ) {
+   Particle_Index    pI;
+   MaterialPoint*    matPoint;
+
+   pcu_docstring( "Similar to TestMaterialLayout, checks that all materials in a register can be 'layed out' correctly - ie the individual"
+      "Particles in a MaterialPointSwarm updated to index the correct material in the register." );
+   _Materials_Register_LayoutGeometry( data->mRegister, data->mpSwarm );
+   
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
+      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
+         pcu_check_true( matPoint->materialIndex == 0 );
+      }
+      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
+         pcu_check_true( matPoint->materialIndex == 1 );
+      }
+      else {
+         pcu_check_true( matPoint->materialIndex == UNDEFINED_MATERIAL );
+      }
+   }
+}
+
+void MaterialComponentsSuite_TestGetMaterial( MaterialComponentsSuiteData* data ) {
+   Particle_Index    pI;
+   MaterialPoint*    matPoint;
+   Material*         material = NULL;
+   Material*         materialOn = NULL;
+   Material_Index    matIndex;
+
+   pcu_docstring( "Tests that after a layout has been performed, the material that a particle belongs to can be successfully looked up."
+      "Thus requires TestLayoutGeometry to pass beforehand." );
+
+   _Materials_Register_LayoutGeometry( data->mRegister, data->mpSwarm );
+
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (MaterialPoint*)Swarm_ParticleAt( data->mpSwarm, pI );
+      material = MaterialPointsSwarm_GetMaterialAt( data->mpSwarm, pI );
+      materialOn = MaterialPointsSwarm_GetMaterialOn( data->mpSwarm, matPoint );
+      matIndex = MaterialPointsSwarm_GetMaterialIndexAt( data->mpSwarm, pI );
+
+      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
+         pcu_check_true( material == data->mat1 );
+         pcu_check_true( materialOn == data->mat1 );
+         pcu_check_true( matIndex == 0 );
+      }
+      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
+         pcu_check_true( material == data->mat2 );
+         pcu_check_true( materialOn == data->mat2 );
+         pcu_check_true( matIndex == 1 );
+      }
+      else {
+         pcu_check_true( NULL == material );
+         pcu_check_true( NULL == materialOn );
+         pcu_check_true( UNDEFINED_MATERIAL == matIndex );
+      }
+   }
+}
+
+
+void MaterialComponentsSuite_TestAssignParticleProperties( MaterialComponentsSuiteData* data ) {
+   Particle_Index    pI;
+   Particle*         matPoint;
+
+   pcu_docstring( "This tests the function Materials_Register_AssignParticleProperties: essentially, material "
+      "properties that should be allowed to vary on a per-particle basis during simulation are set up as "
+      "SwarmVariables, and this test ensures they are applied correctly at startup." );
+
+   _Materials_Register_LayoutGeometry( data->mRegister, data->mpSwarm );
+   Materials_Register_AssignParticleProperties( data->mRegister, data->mpSwarm, data->svRegister );
+
+   /* check the properties have been assigned as expected - see Setup phase */
+   for ( pI = 0; pI < data->mpSwarm->particleLocalCount; pI++ ) {
+      matPoint = (Particle*)Swarm_ParticleAt( data->mpSwarm, pI );
+      if ( Stg_Shape_IsCoordInside( data->shape1, matPoint->coord ) ) {
+         pcu_check_true( matPoint->matProp1 == 1 );
+         pcu_check_true( matPoint->matProp2 == 1.1 );
+         pcu_check_true( matPoint->matProp3 == False );
+         pcu_check_true( matPoint->matProp4 == False );
+      }
+      else if ( Stg_Shape_IsCoordInside( data->shape2, matPoint->coord ) ) {
+         pcu_check_true( matPoint->matProp1 == 2 );
+         pcu_check_true( matPoint->matProp2 == 2.2 );
+         pcu_check_true( matPoint->matProp3 == True );
+         pcu_check_true( matPoint->matProp4 == True );
+      }
+      else {
+         pcu_check_true( matPoint->matProp1 == 0 );
+         pcu_check_true( matPoint->matProp2 == 0.0 );
+         pcu_check_true( matPoint->matProp3 == False );
+         pcu_check_true( matPoint->matProp4 == False );
+      }
+   }
+}
+
+/* TODO M_Register: Test the extension functions work correctly */
+
+
+void MaterialComponentsSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, MaterialComponentsSuiteData );
+   pcu_suite_setFixtures( suite, MaterialComponentsSuite_Setup, MaterialComponentsSuite_Teardown );
+   pcu_suite_addTest( suite, MaterialComponentsSuite_TestRegisterSetup );
+   pcu_suite_addTest( suite, MaterialComponentsSuite_TestMaterialLayout );
+   pcu_suite_addTest( suite, MaterialComponentsSuite_TestLayoutGeometry );
+   pcu_suite_addTest( suite, MaterialComponentsSuite_TestGetMaterial );
+   pcu_suite_addTest( suite, MaterialComponentsSuite_TestAssignParticleProperties );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/MaterialFeVariableSuite.c
--- a/MaterialPoints/tests/MaterialFeVariableSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "PICellerator/PopulationControl/PopulationControl.h"
-#include "PICellerator/Weights/Weights.h"
-#include "PICellerator/MaterialPoints/MaterialPoints.h"
-
-typedef struct {
-   PICelleratorContext* context;
-   Stg_ComponentFactory* cf;
-} MaterialFeVariableSuiteData;
-
-void MaterialFeVariableSuite_Setup( MaterialFeVariableSuiteData* data ) {
-   char xmlInputFilename[PCU_PATH_MAX];
-
-   pcu_filename_input( "testMaterialFeVariable.xml", xmlInputFilename );
-   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
-	data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
-	stgMainBuildAndInitialise( data->cf );
-
-	stgMainLoop( data->cf );
-} 
-
-
-void MaterialFeVariableSuite_Teardown( MaterialFeVariableSuiteData* data ) {
-   stgMainDestroy( data->cf );
-}
-
-
-void MaterialFeVariableSuite_TestVolume( MaterialFeVariableSuiteData* data ) {
-/** Test Definition: This test compares the volume of a swarm as calculated based on the material points swarm and as calculate from a MaterialFeVariable */
-   IntegrationPointsSwarm* swarm;
-   MaterialFeVariable* materialFeVariable;
-   Material*           material;
-   Swarm*              gaussSwarm;
-   double              volumePIC;
-   double              volumeFEM;
-   Coord               centroid;
-
-   materialFeVariable = (MaterialFeVariable* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"materialFeVariable" );
-   gaussSwarm = (Swarm* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"gaussSwarm" );
-
-   assert(materialFeVariable);
-   assert(gaussSwarm );
-
-   material = materialFeVariable->material;
-   swarm = materialFeVariable->picIntegrationPoints;
-
-   volumePIC = Material_Volume( material, swarm, centroid );
-   volumeFEM = FeVariable_Integrate( materialFeVariable, gaussSwarm );
-
-   pcu_check_true(  fabs(volumePIC-volumeFEM) < 1e-4 );
-}
-
-void MaterialFeVariableSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, MaterialFeVariableSuiteData );
-   pcu_suite_setFixtures( suite, MaterialFeVariableSuite_Setup, MaterialFeVariableSuite_Teardown );
-   pcu_suite_addTest( suite, MaterialFeVariableSuite_TestVolume );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/MaterialFeVariableSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/tests/MaterialFeVariableSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,96 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "PICellerator/PopulationControl/PopulationControl.h"
+#include "PICellerator/Weights/Weights.h"
+#include "PICellerator/MaterialPoints/MaterialPoints.h"
+
+typedef struct {
+   PICelleratorContext* context;
+   Stg_ComponentFactory* cf;
+} MaterialFeVariableSuiteData;
+
+void MaterialFeVariableSuite_Setup( MaterialFeVariableSuiteData* data ) {
+   char xmlInputFilename[PCU_PATH_MAX];
+
+   pcu_filename_input( "testMaterialFeVariable.xml", xmlInputFilename );
+   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
+	data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
+	stgMainBuildAndInitialise( data->cf );
+
+	stgMainLoop( data->cf );
+} 
+
+
+void MaterialFeVariableSuite_Teardown( MaterialFeVariableSuiteData* data ) {
+   stgMainDestroy( data->cf );
+}
+
+
+void MaterialFeVariableSuite_TestVolume( MaterialFeVariableSuiteData* data ) {
+/** Test Definition: This test compares the volume of a swarm as calculated based on the material points swarm and as calculate from a MaterialFeVariable */
+   IntegrationPointsSwarm* swarm;
+   MaterialFeVariable* materialFeVariable;
+   Material*           material;
+   Swarm*              gaussSwarm;
+   double              volumePIC;
+   double              volumeFEM;
+   Coord               centroid;
+
+   materialFeVariable = (MaterialFeVariable* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"materialFeVariable" );
+   gaussSwarm = (Swarm* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"gaussSwarm" );
+
+   assert(materialFeVariable);
+   assert(gaussSwarm );
+
+   material = materialFeVariable->material;
+   swarm = materialFeVariable->picIntegrationPoints;
+
+   volumePIC = Material_Volume( material, swarm, centroid );
+   volumeFEM = FeVariable_Integrate( materialFeVariable, gaussSwarm );
+
+   pcu_check_true(  fabs(volumePIC-volumeFEM) < 1e-4 );
+}
+
+void MaterialFeVariableSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, MaterialFeVariableSuiteData );
+   pcu_suite_setFixtures( suite, MaterialFeVariableSuite_Setup, MaterialFeVariableSuite_Teardown );
+   pcu_suite_addTest( suite, MaterialFeVariableSuite_TestVolume );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/PeriodicBoundariesManagerSuite.c
--- a/MaterialPoints/tests/PeriodicBoundariesManagerSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,155 +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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "PICellerator/PopulationControl/PopulationControl.h"
-#include "PICellerator/Weights/Weights.h"
-#include "PICellerator/MaterialPoints/MaterialPoints.h"
-
-
-struct _Node {
-   Coord            coord;
-};
-
-struct _Element {
-   Coord            coord;
-};
-
-struct _Particle {
-   __GlobalParticle
-};
-
-void UpdateParticlePositionsToLeft( Swarm* swarm );
-
-typedef struct {
-   PICelleratorContext*       context;
-   Stg_ComponentFactory*	cf;
-} PeriodicBoundariesManagerSuiteData;
-
-
-void PeriodicBoundariesManagerSuite_Setup( PeriodicBoundariesManagerSuiteData* data ) {
-   char              xmlInputFilename[PCU_PATH_MAX];
-
-   pcu_filename_input( "testPeriodicBoundariesManager.xml", xmlInputFilename );
-   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
-	stgMainBuildAndInitialise( data->cf );
-   data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
-} 
-
-
-void PeriodicBoundariesManagerSuite_Teardown( PeriodicBoundariesManagerSuiteData* data ) {
-   stgMainDestroy( data->cf );
-}
-
-
-void PeriodicBoundariesManagerSuite_TestAdvectOverLeftBoundary( PeriodicBoundariesManagerSuiteData* data ) {
-   Swarm*                     swarm;
-   PeriodicBoundariesManager* perBCsManager;
-   Index                      timeStep;
-   GlobalParticle*            currParticle;
-   Particle_Index             lParticle_I;
-
-   swarm = (Swarm* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"swarm" );
-   perBCsManager = (PeriodicBoundariesManager* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"perBCsManager" );
-
-   for ( timeStep=1; timeStep <= 10; timeStep++ ) {
-      UpdateParticlePositionsToLeft( swarm );
-      for ( lParticle_I = 0; lParticle_I < swarm->particleLocalCount ; lParticle_I++  ) {
-         PeriodicBoundariesManager_UpdateParticle( perBCsManager, lParticle_I );
-      }
-      Swarm_UpdateAllParticleOwners( swarm );
-   }
-
-   /* After 10 timesteps, all the particles should have been advected from the left row of cells, to the right row,
-    *  to a coord somewhere between 0.9 and 1.0 */   
-   /* TODO: first check the particles all still exist */
-   for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
-      currParticle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
-      pcu_check_true( currParticle->coord[0] >= 0.9 && currParticle->coord[0] <= 1.0 ); 
-   }
-   /* TODO: check that their cell ownership is correct */
-}
-
-
-void PeriodicBoundariesManagerSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, PeriodicBoundariesManagerSuiteData );
-   pcu_suite_setFixtures( suite, PeriodicBoundariesManagerSuite_Setup, PeriodicBoundariesManagerSuite_Teardown );
-   pcu_suite_addTest( suite, PeriodicBoundariesManagerSuite_TestAdvectOverLeftBoundary );
-}
-
-
-void UpdateParticlePositionsToLeft( Swarm* swarm ) {
-   Cell_LocalIndex         lCell_I;
-   Particle_InCellIndex    cParticle_I;
-   GlobalParticle*         currParticle;
-   Index                   dim_I;
-   Stream*                 debugStream = Journal_Register( Debug_Type, (Name)"UpdateParticlesLeft" );
-
-   Stream_Indent( debugStream );
-   for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++  ) {
-      Journal_Printf( debugStream, "Updating 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 = (GlobalParticle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-         oldCoord = &currParticle->coord;
-
-         Stream_Indent( debugStream );
-         Journal_Printf( debugStream, "Updating particleInCell %d:\n", cParticle_I );
-
-         movementVector[I_AXIS] = -0.01;
-
-         for ( dim_I=0; dim_I < 3; dim_I++ ) {
-            newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
-         }
-
-         Journal_Printf( debugStream, "Changing 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];
-         }
-         Stream_UnIndent( debugStream );
-      }
-   }
-   Stream_UnIndent( debugStream );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 MaterialPoints/tests/PeriodicBoundariesManagerSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaterialPoints/tests/PeriodicBoundariesManagerSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,155 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "PICellerator/PopulationControl/PopulationControl.h"
+#include "PICellerator/Weights/Weights.h"
+#include "PICellerator/MaterialPoints/MaterialPoints.h"
+
+
+struct _Node {
+   Coord            coord;
+};
+
+struct _Element {
+   Coord            coord;
+};
+
+struct _Particle {
+   __GlobalParticle
+};
+
+void UpdateParticlePositionsToLeft( Swarm* swarm );
+
+typedef struct {
+   PICelleratorContext*       context;
+   Stg_ComponentFactory*	cf;
+} PeriodicBoundariesManagerSuiteData;
+
+
+void PeriodicBoundariesManagerSuite_Setup( PeriodicBoundariesManagerSuiteData* data ) {
+   char              xmlInputFilename[PCU_PATH_MAX];
+
+   pcu_filename_input( "testPeriodicBoundariesManager.xml", xmlInputFilename );
+   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
+	stgMainBuildAndInitialise( data->cf );
+   data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
+} 
+
+
+void PeriodicBoundariesManagerSuite_Teardown( PeriodicBoundariesManagerSuiteData* data ) {
+   stgMainDestroy( data->cf );
+}
+
+
+void PeriodicBoundariesManagerSuite_TestAdvectOverLeftBoundary( PeriodicBoundariesManagerSuiteData* data ) {
+   Swarm*                     swarm;
+   PeriodicBoundariesManager* perBCsManager;
+   Index                      timeStep;
+   GlobalParticle*            currParticle;
+   Particle_Index             lParticle_I;
+
+   swarm = (Swarm* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"swarm" );
+   perBCsManager = (PeriodicBoundariesManager* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"perBCsManager" );
+
+   for ( timeStep=1; timeStep <= 10; timeStep++ ) {
+      UpdateParticlePositionsToLeft( swarm );
+      for ( lParticle_I = 0; lParticle_I < swarm->particleLocalCount ; lParticle_I++  ) {
+         PeriodicBoundariesManager_UpdateParticle( perBCsManager, lParticle_I );
+      }
+      Swarm_UpdateAllParticleOwners( swarm );
+   }
+
+   /* After 10 timesteps, all the particles should have been advected from the left row of cells, to the right row,
+    *  to a coord somewhere between 0.9 and 1.0 */   
+   /* TODO: first check the particles all still exist */
+   for( lParticle_I=0; lParticle_I < swarm->particleLocalCount; lParticle_I++ ) {
+      currParticle = (GlobalParticle*)Swarm_ParticleAt( swarm, lParticle_I );
+      pcu_check_true( currParticle->coord[0] >= 0.9 && currParticle->coord[0] <= 1.0 ); 
+   }
+   /* TODO: check that their cell ownership is correct */
+}
+
+
+void PeriodicBoundariesManagerSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, PeriodicBoundariesManagerSuiteData );
+   pcu_suite_setFixtures( suite, PeriodicBoundariesManagerSuite_Setup, PeriodicBoundariesManagerSuite_Teardown );
+   pcu_suite_addTest( suite, PeriodicBoundariesManagerSuite_TestAdvectOverLeftBoundary );
+}
+
+
+void UpdateParticlePositionsToLeft( Swarm* swarm ) {
+   Cell_LocalIndex         lCell_I;
+   Particle_InCellIndex    cParticle_I;
+   GlobalParticle*         currParticle;
+   Index                   dim_I;
+   Stream*                 debugStream = Journal_Register( Debug_Type, (Name)"UpdateParticlesLeft" );
+
+   Stream_Indent( debugStream );
+   for ( lCell_I=0; lCell_I < swarm->cellLocalCount; lCell_I++  ) {
+      Journal_Printf( debugStream, "Updating 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 = (GlobalParticle*)Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+         oldCoord = &currParticle->coord;
+
+         Stream_Indent( debugStream );
+         Journal_Printf( debugStream, "Updating particleInCell %d:\n", cParticle_I );
+
+         movementVector[I_AXIS] = -0.01;
+
+         for ( dim_I=0; dim_I < 3; dim_I++ ) {
+            newParticleCoord[dim_I] = (*oldCoord)[dim_I] + movementVector[dim_I];
+         }
+
+         Journal_Printf( debugStream, "Changing 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];
+         }
+         Stream_UnIndent( debugStream );
+      }
+   }
+   Stream_UnIndent( debugStream );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/src/EscapedRoutine.c
--- a/PopulationControl/src/EscapedRoutine.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,307 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-
-#include "types.h"
-#include "EscapedRoutine.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type EscapedRoutine_Type = "EscapedRoutine";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-EscapedRoutine* _EscapedRoutine_New(  ESCAPEDROUTINE_DEFARGS  )
-{
-	EscapedRoutine* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(EscapedRoutine) );
-	/* 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 = (EscapedRoutine*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-	
-	/* General info */
-
-	/* Virtual Info */
-	self->_select = _select;
-	
-	return self;
-}
-
-void* _EscapedRoutine_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(EscapedRoutine);
-	Type                                                      type = EscapedRoutine_Type;
-	Stg_Class_DeleteFunction*                              _delete = _EscapedRoutine_Delete;
-	Stg_Class_PrintFunction*                                _print = _EscapedRoutine_Print;
-	Stg_Class_CopyFunction*                                  _copy = _EscapedRoutine_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _EscapedRoutine_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _EscapedRoutine_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _EscapedRoutine_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _EscapedRoutine_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _EscapedRoutine_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _EscapedRoutine_Destroy;
-	EscapedRoutine_SelectFunction*                         _select = _EscapedRoutine_Select;
-
-	/* 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*) _EscapedRoutine_New(  ESCAPEDROUTINE_PASSARGS  );
-}
-
-void _EscapedRoutine_Init( 
-	void*					escapedRoutine, 
-	DomainContext*		context,
-	Dimension_Index	dim, 
-	Particle_Index		particlesToRemoveDelta )
-{
-	EscapedRoutine* self = (EscapedRoutine*)escapedRoutine;
-
-	self->context = context;
-	self->dim = dim;
-	self->particlesToRemoveDelta = particlesToRemoveDelta;
-
-	self->debug = Journal_Register( Debug_Type, (Name)EscapedRoutine_Type ); /* TODO Register Child */
-	self->particlesToRemoveCount = 0;
-	self->particlesToRemoveAlloced = 0;
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _EscapedRoutine_Delete( void* escapedRoutine ) {
-	EscapedRoutine* self = (EscapedRoutine*)escapedRoutine;
-	
-	/* Delete parent */
-	_Stg_Component_Delete( self  );
-}
-
-void _EscapedRoutine_Print( void* escapedRoutine, Stream* stream ) {
-	EscapedRoutine* self = (EscapedRoutine*)escapedRoutine;
-	
-	/* Print parent */
-	_Stg_Component_Print( self, stream );
-}
-
-void* _EscapedRoutine_Copy( const void* escapedRoutine, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-	EscapedRoutine*	self = (EscapedRoutine*)escapedRoutine;
-	EscapedRoutine*	newEscapedRoutine;
-	
-	newEscapedRoutine = (EscapedRoutine*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
-	
-	return (void*)newEscapedRoutine;
-}
-
-void _EscapedRoutine_AssignFromXML( void* escapedRoutine, Stg_ComponentFactory* cf, void* data ) {
-	EscapedRoutine*	self = (EscapedRoutine*) escapedRoutine;
-	Dimension_Index	dim;
-	Particle_Index		particlesToRemoveDelta;
-	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  );
-
-	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-	particlesToRemoveDelta = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"particlesToRemoveDelta", 20  );
-
-	_EscapedRoutine_Init( self, context, dim, particlesToRemoveDelta );
-}
-
-void _EscapedRoutine_Build( void* escapedRoutine, void* data ) {
-	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
-
-	self->particlesToRemoveAlloced = self->particlesToRemoveDelta * 10;
-	self->particlesToRemoveList = Memory_Alloc_Array( unsigned, self->particlesToRemoveAlloced, "particlesToRemoveList" );
-}
-
-void _EscapedRoutine_Initialise( void* escapedRoutine, void* data ) {
-}
-
-void _EscapedRoutine_Execute( void* escapedRoutine, void* data ) {
-	Swarm* swarm = Stg_CheckType( data, Swarm );
-
-	EscapedRoutine_RemoveFromSwarm( escapedRoutine, swarm );
-}
-
-void _EscapedRoutine_Destroy( void* escapedRoutine, void* data ) {
-	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
-
-	Memory_Free( self->particlesToRemoveList );
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void EscapedRoutine_Select( void* escapedRoutine, void* _swarm ) {
-	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
-
-	self->_select( self, _swarm );
-}
-
-void _EscapedRoutine_Select( void* escapedRoutine, void* _swarm ) {
-	EscapedRoutine*	self = (EscapedRoutine*)escapedRoutine;
-	Swarm*				swarm = (Swarm*)_swarm;
-	unsigned	p_i;
-
-	assert( self );
-	assert( swarm );
-
-	/* Check all particles for removal. */
-	for( p_i = 0; p_i < swarm->particleLocalCount; p_i++ ) {
-		StandardParticle*	particle = (StandardParticle*)Swarm_ParticleAt( swarm, p_i );
-
-		if( particle->owningCell >= swarm->cellDomainCount ) {
-			EscapedRoutine_SetParticleToRemove( self, swarm, p_i );
-		}
-	}
-}
-
-
-void EscapedRoutine_RemoveFromSwarm( void* escapedRoutine, void* _swarm ) {
-	EscapedRoutine*	self = (EscapedRoutine*) escapedRoutine;
-	Swarm*				swarm = (Swarm*) _swarm;
-	
-	EscapedRoutine_InitialiseParticleList( self );
-	
-	/* Select particles to remove. */
-	EscapedRoutine_Select( self, swarm );
-
-	/* Actually remove particles */
-	EscapedRoutine_RemoveParticles( self, swarm );
-}
-
-void EscapedRoutine_InitialiseParticleList( void* escapedRoutine ) {
-	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
-
-	self->particlesToRemoveCount = 0;
-	memset( self->particlesToRemoveList, 0, sizeof(unsigned) * self->particlesToRemoveAlloced );
-}
-
-void EscapedRoutine_SetParticleToRemove( void* escapedRoutine, Swarm* swarm, Particle_Index lParticle_I ) {
-	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
-
-	/* Check memory */
-	if ( self->particlesToRemoveCount >= self->particlesToRemoveAlloced ) {
-		self->particlesToRemoveAlloced += self->particlesToRemoveDelta;
-		self->particlesToRemoveList = Memory_Realloc_Array( self->particlesToRemoveList, unsigned, self->particlesToRemoveAlloced );
-	}
-
-	self->particlesToRemoveList[ self->particlesToRemoveCount ] = lParticle_I;
-	self->particlesToRemoveCount++;
-}
-
-/* This typedef is required by qsort: the two arguments must be ptrs to particle indexes, as in particlesToRemoveList */
-int _EscapedRoutine_CompareParticles( const void* _aParticleInfo, const void* _bParticleInfo ) {
-	return (*(unsigned*)_aParticleInfo - *(unsigned*)_bParticleInfo );
-}
-
-void EscapedRoutine_SortParticleList( void* escapedRoutine ) {
-	EscapedRoutine*	     self                = (EscapedRoutine*) escapedRoutine;
-
-	qsort( self->particlesToRemoveList, self->particlesToRemoveCount, sizeof(unsigned), _EscapedRoutine_CompareParticles );
-}
-
-void EscapedRoutine_RemoveParticles( void* escapedRoutine, Swarm* swarm ) {
-	EscapedRoutine*		self = (EscapedRoutine*) escapedRoutine;
-	Index                 array_I;
-	StandardParticle*     particleToRemove;
-	Particle_Index        particleToRemove_I;
-	
-	StandardParticle*     lastParticle;
-	Cell_Index            lastParticle_CellIndex;
-	Particle_Index        lastParticle_I;
-	Particle_InCellIndex  lastParticle_IndexWithinCell;
-	SizeT                 particleSize        = swarm->particleExtensionMgr->finalSize;
-
-	EscapedRoutine_SortParticleList( self );
-
-	for ( array_I = self->particlesToRemoveCount - 1 ; array_I < self->particlesToRemoveCount ; array_I-- ) {
-		particleToRemove_I = self->particlesToRemoveList[ array_I ];
-		particleToRemove = Swarm_ParticleAt( swarm, particleToRemove_I );
-
-		Journal_DPrintfL( self->debug, 2, "Removing particle %u\n", particleToRemove_I );
-		
-		/* Copy over particle with last particle in array - as long as it isn't the last one */
-		lastParticle_I = swarm->particleLocalCount - 1;
-		lastParticle   = Swarm_ParticleAt( swarm, lastParticle_I );
-		if ( particleToRemove_I != lastParticle_I ) {
-			/* Get last Particle information */
-			lastParticle_CellIndex       = lastParticle->owningCell;
-			lastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( swarm, 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", 
-					particleToRemove_I, lastParticle_I, lastParticle_CellIndex, lastParticle_IndexWithinCell );
-
-			/* Copy over particle */
-			memcpy( particleToRemove, lastParticle, particleSize );
-			
-			/* Change value in cell particle table to point to new index in array */
-			swarm->cellParticleTbl[lastParticle_CellIndex][ lastParticle_IndexWithinCell ] = particleToRemove_I;
-		}
-
-		/* Initialise memory to zero so it is clear that it's been deleted */
-		memset( lastParticle, 0, particleSize );
-		swarm->particleLocalCount--;
-	}
-
-	Swarm_Realloc( swarm );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/src/EscapedRoutine.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PopulationControl/src/EscapedRoutine.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,307 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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:  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+
+#include "types.h"
+#include "EscapedRoutine.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type EscapedRoutine_Type = "EscapedRoutine";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+EscapedRoutine* _EscapedRoutine_New(  ESCAPEDROUTINE_DEFARGS  )
+{
+	EscapedRoutine* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(EscapedRoutine) );
+	/* 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 = (EscapedRoutine*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+	
+	/* General info */
+
+	/* Virtual Info */
+	self->_select = _select;
+	
+	return self;
+}
+
+void* _EscapedRoutine_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(EscapedRoutine);
+	Type                                                      type = EscapedRoutine_Type;
+	Stg_Class_DeleteFunction*                              _delete = _EscapedRoutine_Delete;
+	Stg_Class_PrintFunction*                                _print = _EscapedRoutine_Print;
+	Stg_Class_CopyFunction*                                  _copy = _EscapedRoutine_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _EscapedRoutine_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _EscapedRoutine_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _EscapedRoutine_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _EscapedRoutine_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _EscapedRoutine_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _EscapedRoutine_Destroy;
+	EscapedRoutine_SelectFunction*                         _select = _EscapedRoutine_Select;
+
+	/* 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*) _EscapedRoutine_New(  ESCAPEDROUTINE_PASSARGS  );
+}
+
+void _EscapedRoutine_Init( 
+	void*					escapedRoutine, 
+	DomainContext*		context,
+	Dimension_Index	dim, 
+	Particle_Index		particlesToRemoveDelta )
+{
+	EscapedRoutine* self = (EscapedRoutine*)escapedRoutine;
+
+	self->context = context;
+	self->dim = dim;
+	self->particlesToRemoveDelta = particlesToRemoveDelta;
+
+	self->debug = Journal_Register( Debug_Type, (Name)EscapedRoutine_Type ); /* TODO Register Child */
+	self->particlesToRemoveCount = 0;
+	self->particlesToRemoveAlloced = 0;
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _EscapedRoutine_Delete( void* escapedRoutine ) {
+	EscapedRoutine* self = (EscapedRoutine*)escapedRoutine;
+	
+	/* Delete parent */
+	_Stg_Component_Delete( self  );
+}
+
+void _EscapedRoutine_Print( void* escapedRoutine, Stream* stream ) {
+	EscapedRoutine* self = (EscapedRoutine*)escapedRoutine;
+	
+	/* Print parent */
+	_Stg_Component_Print( self, stream );
+}
+
+void* _EscapedRoutine_Copy( const void* escapedRoutine, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+	EscapedRoutine*	self = (EscapedRoutine*)escapedRoutine;
+	EscapedRoutine*	newEscapedRoutine;
+	
+	newEscapedRoutine = (EscapedRoutine*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
+	
+	return (void*)newEscapedRoutine;
+}
+
+void _EscapedRoutine_AssignFromXML( void* escapedRoutine, Stg_ComponentFactory* cf, void* data ) {
+	EscapedRoutine*	self = (EscapedRoutine*) escapedRoutine;
+	Dimension_Index	dim;
+	Particle_Index		particlesToRemoveDelta;
+	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  );
+
+	dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+	particlesToRemoveDelta = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"particlesToRemoveDelta", 20  );
+
+	_EscapedRoutine_Init( self, context, dim, particlesToRemoveDelta );
+}
+
+void _EscapedRoutine_Build( void* escapedRoutine, void* data ) {
+	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
+
+	self->particlesToRemoveAlloced = self->particlesToRemoveDelta * 10;
+	self->particlesToRemoveList = Memory_Alloc_Array( unsigned, self->particlesToRemoveAlloced, "particlesToRemoveList" );
+}
+
+void _EscapedRoutine_Initialise( void* escapedRoutine, void* data ) {
+}
+
+void _EscapedRoutine_Execute( void* escapedRoutine, void* data ) {
+	Swarm* swarm = Stg_CheckType( data, Swarm );
+
+	EscapedRoutine_RemoveFromSwarm( escapedRoutine, swarm );
+}
+
+void _EscapedRoutine_Destroy( void* escapedRoutine, void* data ) {
+	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
+
+	Memory_Free( self->particlesToRemoveList );
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void EscapedRoutine_Select( void* escapedRoutine, void* _swarm ) {
+	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
+
+	self->_select( self, _swarm );
+}
+
+void _EscapedRoutine_Select( void* escapedRoutine, void* _swarm ) {
+	EscapedRoutine*	self = (EscapedRoutine*)escapedRoutine;
+	Swarm*				swarm = (Swarm*)_swarm;
+	unsigned	p_i;
+
+	assert( self );
+	assert( swarm );
+
+	/* Check all particles for removal. */
+	for( p_i = 0; p_i < swarm->particleLocalCount; p_i++ ) {
+		StandardParticle*	particle = (StandardParticle*)Swarm_ParticleAt( swarm, p_i );
+
+		if( particle->owningCell >= swarm->cellDomainCount ) {
+			EscapedRoutine_SetParticleToRemove( self, swarm, p_i );
+		}
+	}
+}
+
+
+void EscapedRoutine_RemoveFromSwarm( void* escapedRoutine, void* _swarm ) {
+	EscapedRoutine*	self = (EscapedRoutine*) escapedRoutine;
+	Swarm*				swarm = (Swarm*) _swarm;
+	
+	EscapedRoutine_InitialiseParticleList( self );
+	
+	/* Select particles to remove. */
+	EscapedRoutine_Select( self, swarm );
+
+	/* Actually remove particles */
+	EscapedRoutine_RemoveParticles( self, swarm );
+}
+
+void EscapedRoutine_InitialiseParticleList( void* escapedRoutine ) {
+	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
+
+	self->particlesToRemoveCount = 0;
+	memset( self->particlesToRemoveList, 0, sizeof(unsigned) * self->particlesToRemoveAlloced );
+}
+
+void EscapedRoutine_SetParticleToRemove( void* escapedRoutine, Swarm* swarm, Particle_Index lParticle_I ) {
+	EscapedRoutine* self = (EscapedRoutine*) escapedRoutine;
+
+	/* Check memory */
+	if ( self->particlesToRemoveCount >= self->particlesToRemoveAlloced ) {
+		self->particlesToRemoveAlloced += self->particlesToRemoveDelta;
+		self->particlesToRemoveList = Memory_Realloc_Array( self->particlesToRemoveList, unsigned, self->particlesToRemoveAlloced );
+	}
+
+	self->particlesToRemoveList[ self->particlesToRemoveCount ] = lParticle_I;
+	self->particlesToRemoveCount++;
+}
+
+/* This typedef is required by qsort: the two arguments must be ptrs to particle indexes, as in particlesToRemoveList */
+int _EscapedRoutine_CompareParticles( const void* _aParticleInfo, const void* _bParticleInfo ) {
+	return (*(unsigned*)_aParticleInfo - *(unsigned*)_bParticleInfo );
+}
+
+void EscapedRoutine_SortParticleList( void* escapedRoutine ) {
+	EscapedRoutine*	     self                = (EscapedRoutine*) escapedRoutine;
+
+	qsort( self->particlesToRemoveList, self->particlesToRemoveCount, sizeof(unsigned), _EscapedRoutine_CompareParticles );
+}
+
+void EscapedRoutine_RemoveParticles( void* escapedRoutine, Swarm* swarm ) {
+	EscapedRoutine*		self = (EscapedRoutine*) escapedRoutine;
+	Index                 array_I;
+	StandardParticle*     particleToRemove;
+	Particle_Index        particleToRemove_I;
+	
+	StandardParticle*     lastParticle;
+	Cell_Index            lastParticle_CellIndex;
+	Particle_Index        lastParticle_I;
+	Particle_InCellIndex  lastParticle_IndexWithinCell;
+	SizeT                 particleSize        = swarm->particleExtensionMgr->finalSize;
+
+	EscapedRoutine_SortParticleList( self );
+
+	for ( array_I = self->particlesToRemoveCount - 1 ; array_I < self->particlesToRemoveCount ; array_I-- ) {
+		particleToRemove_I = self->particlesToRemoveList[ array_I ];
+		particleToRemove = Swarm_ParticleAt( swarm, particleToRemove_I );
+
+		Journal_DPrintfL( self->debug, 2, "Removing particle %u\n", particleToRemove_I );
+		
+		/* Copy over particle with last particle in array - as long as it isn't the last one */
+		lastParticle_I = swarm->particleLocalCount - 1;
+		lastParticle   = Swarm_ParticleAt( swarm, lastParticle_I );
+		if ( particleToRemove_I != lastParticle_I ) {
+			/* Get last Particle information */
+			lastParticle_CellIndex       = lastParticle->owningCell;
+			lastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( swarm, 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", 
+					particleToRemove_I, lastParticle_I, lastParticle_CellIndex, lastParticle_IndexWithinCell );
+
+			/* Copy over particle */
+			memcpy( particleToRemove, lastParticle, particleSize );
+			
+			/* Change value in cell particle table to point to new index in array */
+			swarm->cellParticleTbl[lastParticle_CellIndex][ lastParticle_IndexWithinCell ] = particleToRemove_I;
+		}
+
+		/* Initialise memory to zero so it is clear that it's been deleted */
+		memset( lastParticle, 0, particleSize );
+		swarm->particleLocalCount--;
+	}
+
+	Swarm_Realloc( swarm );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/src/Finalise.c
--- a/PopulationControl/src/Finalise.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-
-
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool PICellerator_PopulationControl_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PopulationControl/src/Finalise.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,61 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+
+
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool PICellerator_PopulationControl_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/src/Init.c
--- a/PopulationControl/src/Init.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "PopulationControl.h"
-
-#include <stdio.h>
-
-Bool PICellerator_PopulationControl_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-	Stg_ComponentRegister_Add( componentsRegister, EscapedRoutine_Type, (Name)"0", _EscapedRoutine_DefaultNew  );
-	RegisterParent( EscapedRoutine_Type,      	 Stg_Component_Type );
-
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PopulationControl/src/Init.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,65 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "PopulationControl.h"
+
+#include <stdio.h>
+
+Bool PICellerator_PopulationControl_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+	Stg_ComponentRegister_Add( componentsRegister, EscapedRoutine_Type, (Name)"0", _EscapedRoutine_DefaultNew  );
+	RegisterParent( EscapedRoutine_Type,      	 Stg_Component_Type );
+
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/tests/EscapedRoutineSuite.c
--- a/PopulationControl/tests/EscapedRoutineSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,205 +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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "PICellerator/PopulationControl/PopulationControl.h"
-
-struct _Particle {
-   __GlobalParticle
-   Bool     toRemove;
-};
-
-
-typedef struct {
-   FiniteElementContext*	context;
-   Stg_ComponentFactory*	cf;
-   Swarm*						swarm;
-   EscapedRoutine*			escRoutine;
-} EscapedRoutineSuiteData;
-
-void EscapedRoutineSuite_Setup( EscapedRoutineSuiteData* data ) {
-   char              xmlInputFilename[PCU_PATH_MAX];
-   Particle_Index    lParticle_I=0;
-
-   pcu_filename_input( "EscapedRoutineSuite.xml", xmlInputFilename );
-   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
-   data->context = (FiniteElementContext*) LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
-   data->swarm = (Swarm* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"swarm" );
-   data->escRoutine = (EscapedRoutine* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"escapedRoutine" );
-	stgMainBuildAndInitialise( data->cf );
-
-   /* Use our test param to mark all the particles as not to be removed by default*/
-   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
-      ((Particle* )Swarm_ParticleAt( data->swarm, lParticle_I ))->toRemove = False;
-   }
-} 
-
-void EscapedRoutineSuite_Teardown( EscapedRoutineSuiteData* data ) {
-   stgMainDestroy( data->cf );
-}
-
-
-void EscapedRoutineSuite_TestSetParticleToRemove( EscapedRoutineSuiteData* data ) {
-   Particle_Index lParticle_I=0;
-
-   pcu_check_true( data->escRoutine->particlesToRemoveCount == 0 );
-   pcu_check_true( data->escRoutine->particlesToRemoveAlloced == 10*data->escRoutine->particlesToRemoveDelta );
-
-   /* Do it enough times that pToRemoveList has to be expanded at least once */
-   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
-      EscapedRoutine_SetParticleToRemove( data->escRoutine, data->swarm, lParticle_I );
-   }
-   
-   pcu_check_true( data->escRoutine->particlesToRemoveCount == data->swarm->particleLocalCount );
-   pcu_check_true( data->escRoutine->particlesToRemoveAlloced >= data->escRoutine->particlesToRemoveCount );
-   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
-      pcu_check_true( data->escRoutine->particlesToRemoveList[lParticle_I] == lParticle_I );
-   }
-}   
-
-void EscapedRoutineSuite_TestSelect( EscapedRoutineSuiteData* data ) {
-   Particle_Index lParticle_I=0;
-   Particle_Index pToRemove_I=0;
-
-   /* Modify some of the swarm particles to be outside list of global cells - in this case, only one cell,
-    * so any value other than 0 should be considered as outside the box */
-   for ( lParticle_I=10; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
-      (Swarm_ParticleAt( data->swarm, lParticle_I ))->owningCell = 100;
-   }
-   
-   EscapedRoutine_Select( data->escRoutine, data->swarm );
-
-   /* Check that the particles have been set to be removed as expected */
-   pcu_check_true( data->escRoutine->particlesToRemoveCount == (data->swarm->particleLocalCount-10) );
-   for ( pToRemove_I=0; pToRemove_I < (data->swarm->particleLocalCount-10); pToRemove_I++ ) {
-      pcu_check_true( data->escRoutine->particlesToRemoveList[pToRemove_I] == 10+pToRemove_I );
-   }
-}
-
-
-void EscapedRoutineSuite_TestInitialiseParticleList( EscapedRoutineSuiteData* data ) {
-   Particle_Index pToRemove_I=0;
-   
-   /* Fill the list with some initial random data */
-   for ( pToRemove_I=0; pToRemove_I < data->escRoutine->particlesToRemoveAlloced; pToRemove_I++ ) {
-      data->escRoutine->particlesToRemoveList[pToRemove_I] = pToRemove_I*2;
-   }
-
-   EscapedRoutine_InitialiseParticleList( data->escRoutine );
-
-   pcu_check_true( data->escRoutine->particlesToRemoveCount == 0 );
-   for ( pToRemove_I=0; pToRemove_I < data->escRoutine->particlesToRemoveAlloced; pToRemove_I++ ) {
-      pcu_check_true( 0 == data->escRoutine->particlesToRemoveList[pToRemove_I] );
-   }
-}
-
-
-void EscapedRoutineSuite_TestCompareParticles( EscapedRoutineSuiteData* data ) {
-   unsigned    pToRemoveList[3] = { 1, 4, 7 };
-
-   /* This function is needed for sorting plists into order. Should just be based on value of ptrs, which
-    *  implies position in particle array */
-   pcu_check_true( _EscapedRoutine_CompareParticles( &pToRemoveList[0], &pToRemoveList[1] ) < 0 );
-   pcu_check_true( _EscapedRoutine_CompareParticles( &pToRemoveList[2], &pToRemoveList[1] ) > 0 );
-   pcu_check_true( _EscapedRoutine_CompareParticles( &pToRemoveList[1], &pToRemoveList[1] ) == 0 );
-}
-
-void EscapedRoutineSuite_TestSortParticleList( EscapedRoutineSuiteData* data ) {
-   Particle_Index pToRemove_I=0;
-   Particle_Index pToRemoveCount=4;
-   unsigned    pToRemoveList[4] = { 8, 12, 1, 3 };
-
-   /* first put some data in escRoutine's particlesToRemoveList */
-   for ( pToRemove_I=0; pToRemove_I < pToRemoveCount; pToRemove_I++ ) {
-      EscapedRoutine_SetParticleToRemove( data->escRoutine, data->swarm, pToRemoveList[pToRemove_I] );
-   }
-
-   EscapedRoutine_SortParticleList( data->escRoutine );
-
-   pcu_check_true( data->escRoutine->particlesToRemoveCount == pToRemoveCount );
-   pcu_check_true( data->escRoutine->particlesToRemoveList[0] == 1 );
-   pcu_check_true( data->escRoutine->particlesToRemoveList[1] == 3 );
-   pcu_check_true( data->escRoutine->particlesToRemoveList[2] == 8 );
-   pcu_check_true( data->escRoutine->particlesToRemoveList[3] == 12 );
-}
-
-
-void EscapedRoutineSuite_TestRemoveParticles( EscapedRoutineSuiteData* data ) {
-   Particle_Index lParticle_I=0;
-   Particle_Index pToRemove_I=0;
-   Particle_Index pToRemoveCount=4;
-   unsigned    pToRemoveList[4] = { 8, 12, 1, 3 };
-
-   /* First set up the particles to remove list, and manually mark these */
-   for ( pToRemove_I=0; pToRemove_I < pToRemoveCount; pToRemove_I++ ) {
-      EscapedRoutine_SetParticleToRemove( data->escRoutine, data->swarm, pToRemoveList[pToRemove_I] );
-      ((Particle*)Swarm_ParticleAt( data->swarm, pToRemoveList[pToRemove_I] ))->toRemove = True; 
-   }
-   pcu_check_true( data->escRoutine->particlesToRemoveCount == pToRemoveCount );
-
-   EscapedRoutine_RemoveParticles( data->escRoutine, data->swarm );
-
-   /* Check these particles have been removed from the swarm */
-   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
-      pcu_check_true( ((Particle*)Swarm_ParticleAt( data->swarm, lParticle_I ))->toRemove == False );
-   }
-}
-
-
-/* We don't need to do a regular test of execute, since it just calls EscapedRoutine_RemoveFromSwarm.
- * However, since this is the main public function, test if it can correctly catch bad input data */
-void EscapedRoutineSuite_TestExecuteBadInput( EscapedRoutineSuiteData* data ) {
-   stJournal->enable = False;
-   pcu_check_assert( Stg_Component_Execute( data->escRoutine, NULL, True ) ); 
-   pcu_check_assert( Stg_Component_Execute( data->escRoutine, stJournal, True ) );
-   stJournal->enable = True;
-}
-
-
-void EscapedRoutineSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, EscapedRoutineSuiteData );
-   pcu_suite_setFixtures( suite, EscapedRoutineSuite_Setup, EscapedRoutineSuite_Teardown );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestSetParticleToRemove );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestSelect );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestInitialiseParticleList );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestCompareParticles );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestSortParticleList );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestRemoveParticles );
-   pcu_suite_addTest( suite, EscapedRoutineSuite_TestExecuteBadInput );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 PopulationControl/tests/EscapedRoutineSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PopulationControl/tests/EscapedRoutineSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,205 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "PICellerator/PopulationControl/PopulationControl.h"
+
+struct _Particle {
+   __GlobalParticle
+   Bool     toRemove;
+};
+
+
+typedef struct {
+   FiniteElementContext*	context;
+   Stg_ComponentFactory*	cf;
+   Swarm*						swarm;
+   EscapedRoutine*			escRoutine;
+} EscapedRoutineSuiteData;
+
+void EscapedRoutineSuite_Setup( EscapedRoutineSuiteData* data ) {
+   char              xmlInputFilename[PCU_PATH_MAX];
+   Particle_Index    lParticle_I=0;
+
+   pcu_filename_input( "EscapedRoutineSuite.xml", xmlInputFilename );
+   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
+   data->context = (FiniteElementContext*) LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
+   data->swarm = (Swarm* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"swarm" );
+   data->escRoutine = (EscapedRoutine* ) LiveComponentRegister_Get( data->context->CF->LCRegister, (Name)"escapedRoutine" );
+	stgMainBuildAndInitialise( data->cf );
+
+   /* Use our test param to mark all the particles as not to be removed by default*/
+   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
+      ((Particle* )Swarm_ParticleAt( data->swarm, lParticle_I ))->toRemove = False;
+   }
+} 
+
+void EscapedRoutineSuite_Teardown( EscapedRoutineSuiteData* data ) {
+   stgMainDestroy( data->cf );
+}
+
+
+void EscapedRoutineSuite_TestSetParticleToRemove( EscapedRoutineSuiteData* data ) {
+   Particle_Index lParticle_I=0;
+
+   pcu_check_true( data->escRoutine->particlesToRemoveCount == 0 );
+   pcu_check_true( data->escRoutine->particlesToRemoveAlloced == 10*data->escRoutine->particlesToRemoveDelta );
+
+   /* Do it enough times that pToRemoveList has to be expanded at least once */
+   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
+      EscapedRoutine_SetParticleToRemove( data->escRoutine, data->swarm, lParticle_I );
+   }
+   
+   pcu_check_true( data->escRoutine->particlesToRemoveCount == data->swarm->particleLocalCount );
+   pcu_check_true( data->escRoutine->particlesToRemoveAlloced >= data->escRoutine->particlesToRemoveCount );
+   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
+      pcu_check_true( data->escRoutine->particlesToRemoveList[lParticle_I] == lParticle_I );
+   }
+}   
+
+void EscapedRoutineSuite_TestSelect( EscapedRoutineSuiteData* data ) {
+   Particle_Index lParticle_I=0;
+   Particle_Index pToRemove_I=0;
+
+   /* Modify some of the swarm particles to be outside list of global cells - in this case, only one cell,
+    * so any value other than 0 should be considered as outside the box */
+   for ( lParticle_I=10; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
+      (Swarm_ParticleAt( data->swarm, lParticle_I ))->owningCell = 100;
+   }
+   
+   EscapedRoutine_Select( data->escRoutine, data->swarm );
+
+   /* Check that the particles have been set to be removed as expected */
+   pcu_check_true( data->escRoutine->particlesToRemoveCount == (data->swarm->particleLocalCount-10) );
+   for ( pToRemove_I=0; pToRemove_I < (data->swarm->particleLocalCount-10); pToRemove_I++ ) {
+      pcu_check_true( data->escRoutine->particlesToRemoveList[pToRemove_I] == 10+pToRemove_I );
+   }
+}
+
+
+void EscapedRoutineSuite_TestInitialiseParticleList( EscapedRoutineSuiteData* data ) {
+   Particle_Index pToRemove_I=0;
+   
+   /* Fill the list with some initial random data */
+   for ( pToRemove_I=0; pToRemove_I < data->escRoutine->particlesToRemoveAlloced; pToRemove_I++ ) {
+      data->escRoutine->particlesToRemoveList[pToRemove_I] = pToRemove_I*2;
+   }
+
+   EscapedRoutine_InitialiseParticleList( data->escRoutine );
+
+   pcu_check_true( data->escRoutine->particlesToRemoveCount == 0 );
+   for ( pToRemove_I=0; pToRemove_I < data->escRoutine->particlesToRemoveAlloced; pToRemove_I++ ) {
+      pcu_check_true( 0 == data->escRoutine->particlesToRemoveList[pToRemove_I] );
+   }
+}
+
+
+void EscapedRoutineSuite_TestCompareParticles( EscapedRoutineSuiteData* data ) {
+   unsigned    pToRemoveList[3] = { 1, 4, 7 };
+
+   /* This function is needed for sorting plists into order. Should just be based on value of ptrs, which
+    *  implies position in particle array */
+   pcu_check_true( _EscapedRoutine_CompareParticles( &pToRemoveList[0], &pToRemoveList[1] ) < 0 );
+   pcu_check_true( _EscapedRoutine_CompareParticles( &pToRemoveList[2], &pToRemoveList[1] ) > 0 );
+   pcu_check_true( _EscapedRoutine_CompareParticles( &pToRemoveList[1], &pToRemoveList[1] ) == 0 );
+}
+
+void EscapedRoutineSuite_TestSortParticleList( EscapedRoutineSuiteData* data ) {
+   Particle_Index pToRemove_I=0;
+   Particle_Index pToRemoveCount=4;
+   unsigned    pToRemoveList[4] = { 8, 12, 1, 3 };
+
+   /* first put some data in escRoutine's particlesToRemoveList */
+   for ( pToRemove_I=0; pToRemove_I < pToRemoveCount; pToRemove_I++ ) {
+      EscapedRoutine_SetParticleToRemove( data->escRoutine, data->swarm, pToRemoveList[pToRemove_I] );
+   }
+
+   EscapedRoutine_SortParticleList( data->escRoutine );
+
+   pcu_check_true( data->escRoutine->particlesToRemoveCount == pToRemoveCount );
+   pcu_check_true( data->escRoutine->particlesToRemoveList[0] == 1 );
+   pcu_check_true( data->escRoutine->particlesToRemoveList[1] == 3 );
+   pcu_check_true( data->escRoutine->particlesToRemoveList[2] == 8 );
+   pcu_check_true( data->escRoutine->particlesToRemoveList[3] == 12 );
+}
+
+
+void EscapedRoutineSuite_TestRemoveParticles( EscapedRoutineSuiteData* data ) {
+   Particle_Index lParticle_I=0;
+   Particle_Index pToRemove_I=0;
+   Particle_Index pToRemoveCount=4;
+   unsigned    pToRemoveList[4] = { 8, 12, 1, 3 };
+
+   /* First set up the particles to remove list, and manually mark these */
+   for ( pToRemove_I=0; pToRemove_I < pToRemoveCount; pToRemove_I++ ) {
+      EscapedRoutine_SetParticleToRemove( data->escRoutine, data->swarm, pToRemoveList[pToRemove_I] );
+      ((Particle*)Swarm_ParticleAt( data->swarm, pToRemoveList[pToRemove_I] ))->toRemove = True; 
+   }
+   pcu_check_true( data->escRoutine->particlesToRemoveCount == pToRemoveCount );
+
+   EscapedRoutine_RemoveParticles( data->escRoutine, data->swarm );
+
+   /* Check these particles have been removed from the swarm */
+   for ( lParticle_I=0; lParticle_I < data->swarm->particleLocalCount; lParticle_I++ ) {
+      pcu_check_true( ((Particle*)Swarm_ParticleAt( data->swarm, lParticle_I ))->toRemove == False );
+   }
+}
+
+
+/* We don't need to do a regular test of execute, since it just calls EscapedRoutine_RemoveFromSwarm.
+ * However, since this is the main public function, test if it can correctly catch bad input data */
+void EscapedRoutineSuite_TestExecuteBadInput( EscapedRoutineSuiteData* data ) {
+   stJournal->enable = False;
+   pcu_check_assert( Stg_Component_Execute( data->escRoutine, NULL, True ) ); 
+   pcu_check_assert( Stg_Component_Execute( data->escRoutine, stJournal, True ) );
+   stJournal->enable = True;
+}
+
+
+void EscapedRoutineSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, EscapedRoutineSuiteData );
+   pcu_suite_setFixtures( suite, EscapedRoutineSuite_Setup, EscapedRoutineSuite_Teardown );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestSetParticleToRemove );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestSelect );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestInitialiseParticleList );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestCompareParticles );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestSortParticleList );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestRemoveParticles );
+   pcu_suite_addTest( suite, EscapedRoutineSuite_TestExecuteBadInput );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 SConscript
--- a/SConscript	Wed May 11 13:26:28 2011 -0700
+++ b/SConscript	Thu May 12 11:18:04 2011 -0700
@@ -58,8 +58,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.
@@ -71,7 +71,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 + '/*'))
@@ -96,8 +96,8 @@ for d in dirs:
 
     env.Install('include/PICellerator/' + 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)
 
@@ -198,7 +198,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'], 'PICellerator', 'picellerator_static_modules.c')
+    reg_filename = os.path.join(env['build_dir'], 'PICellerator', 'picellerator_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')
@@ -207,12 +207,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, '   picellerator_register_static_modules();\n')
     txt.insert(0, 'void picellerator_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 420e7ed7a877 -r 285af3102548 SysTest/AnalyticPlugins/AnalyticPressure/AnalyticPressure.c
--- a/SysTest/AnalyticPlugins/AnalyticPressure/AnalyticPressure.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** Copyright (c) 2005, Monash Cluster Computing 
-** All rights reserved.
-** Redistribution and use in source and binary forms, with or without modification,
-** are permitted provided that the following conditions are met:
-**
-** 		* Redistributions of source code must retain the above copyright notice, 
-** 			this list of conditions and the following disclaimer.
-** 		* Redistributions in binary form must reproduce the above copyright 
-**			notice, this list of conditions and the following disclaimer in the 
-**			documentation and/or other materials provided with the distribution.
-** 		* Neither the name of the Monash University nor the names of its contributors 
-**			may be used to endorse or promote products derived from this software 
-**			without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
-** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
-** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
-** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
-** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
-** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
-** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
-** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-**
-** Contact:
-*%		Louis Moresi - Louis.Moresi at sci.monash.edu.au
-*%
-** Contributors:
-*+		Julian Giordani
-*+		Mirko Velic
-*+		Robert Turnbull
-*+		Vincent Lemiale
-*+		Louis Moresi
-*+		David May
-*+		David Stegman
-*+		Patrick Sunter
-** $Id: solA.c 636 2006-09-08 03:07:06Z JulianGiordani $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "AnalyticPressure.h"
-
-const Type AnalyticPressure_Type = "PICellerator_AnalyticPressure";
-
-void _PICellerator_AnalyticPressure_PressureFunction( void* _self, double* coord, double* pressure ) {
-  AnalyticPressure*  self    = (AnalyticPressure*)_self;
-  double             density = self->density;
-  double             gravity = self->gravity;
-  double             y;
-
-  /* Find coordinate of node */
-  y = -coord[ J_AXIS ] + (self->minY+self->maxY)/2.0;
-
-  *pressure = y * density * gravity;
-}
-
-void _AnalyticPressure_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
-  AnalyticPressure* 		self = (AnalyticPressure*) _self;
-
-  /* Construct Parent */
-  _FieldTest_AssignFromXML( self, cf, data );
-
-    /* Create Analytic Fields */
-  self->density  = Stg_ComponentFactory_GetDouble( cf, "layer", (Dictionary_Entry_Key)"density", 0.0  );
-  self->gravity  = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"gravity", 0  );
-  self->maxY     = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxY", 0  );
-  self->minY     = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minY", 0  );
-}
-
-void _AnalyticPressure_Build( void* _self, void* data ) {
-  AnalyticPressure* 		self = (AnalyticPressure*) _self;
-
-  _FieldTest_Build( self, data );
-
-  /* here we assign the memory and the func ptr for analytic sols */
-  self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 1 );
-  /* this order MUST be consistent with the xml file definition */
-  self->_analyticSolutionList[0] = _PICellerator_AnalyticPressure_PressureFunction;
-}
-
-void* _AnalyticPressure_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(AnalyticPressure);
-	Type                                                      type = AnalyticPressure_Type;
-	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
-	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
-	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _AnalyticPressure_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _AnalyticPressure_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _AnalyticPressure_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _FieldTest_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _FieldTest_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 _FieldTest_New(  FIELDTEST_PASSARGS  );
-}
-
-Index PICellerator_AnalyticPressure_Register( PluginsManager* pluginsManager ) {
-  return PluginsManager_Submit( pluginsManager, AnalyticPressure_Type, "0", _AnalyticPressure_DefaultNew  );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 SysTest/AnalyticPlugins/AnalyticPressure/AnalyticPressure.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SysTest/AnalyticPlugins/AnalyticPressure/AnalyticPressure.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,108 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** Copyright (c) 2005, Monash Cluster Computing 
+** All rights reserved.
+** Redistribution and use in source and binary forms, with or without modification,
+** are permitted provided that the following conditions are met:
+**
+** 		* Redistributions of source code must retain the above copyright notice, 
+** 			this list of conditions and the following disclaimer.
+** 		* Redistributions in binary form must reproduce the above copyright 
+**			notice, this list of conditions and the following disclaimer in the 
+**			documentation and/or other materials provided with the distribution.
+** 		* Neither the name of the Monash University nor the names of its contributors 
+**			may be used to endorse or promote products derived from this software 
+**			without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
+** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
+** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
+** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+**
+** Contact:
+*%		Louis Moresi - Louis.Moresi at sci.monash.edu.au
+*%
+** Contributors:
+*+		Julian Giordani
+*+		Mirko Velic
+*+		Robert Turnbull
+*+		Vincent Lemiale
+*+		Louis Moresi
+*+		David May
+*+		David Stegman
+*+		Patrick Sunter
+** $Id: solA.c 636 2006-09-08 03:07:06Z JulianGiordani $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "AnalyticPressure.h"
+
+const Type AnalyticPressure_Type = "PICellerator_AnalyticPressure";
+
+void _PICellerator_AnalyticPressure_PressureFunction( void* _self, double* coord, double* pressure ) {
+  AnalyticPressure*  self    = (AnalyticPressure*)_self;
+  double             density = self->density;
+  double             gravity = self->gravity;
+  double             y;
+
+  /* Find coordinate of node */
+  y = -coord[ J_AXIS ] + (self->minY+self->maxY)/2.0;
+
+  *pressure = y * density * gravity;
+}
+
+void _AnalyticPressure_AssignFromXML( void* _self, Stg_ComponentFactory* cf, void* data ) {
+  AnalyticPressure* 		self = (AnalyticPressure*) _self;
+
+  /* Construct Parent */
+  _FieldTest_AssignFromXML( self, cf, data );
+
+    /* Create Analytic Fields */
+  self->density  = Stg_ComponentFactory_GetDouble( cf, "layer", (Dictionary_Entry_Key)"density", 0.0  );
+  self->gravity  = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"gravity", 0  );
+  self->maxY     = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"maxY", 0  );
+  self->minY     = Stg_ComponentFactory_GetRootDictDouble( cf, (Dictionary_Entry_Key)"minY", 0  );
+}
+
+void _AnalyticPressure_Build( void* _self, void* data ) {
+  AnalyticPressure* 		self = (AnalyticPressure*) _self;
+
+  _FieldTest_Build( self, data );
+
+  /* here we assign the memory and the func ptr for analytic sols */
+  self->_analyticSolutionList = Memory_Alloc_Array_Unnamed( FieldTest_AnalyticSolutionFunc*, 1 );
+  /* this order MUST be consistent with the xml file definition */
+  self->_analyticSolutionList[0] = _PICellerator_AnalyticPressure_PressureFunction;
+}
+
+void* _AnalyticPressure_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(AnalyticPressure);
+	Type                                                      type = AnalyticPressure_Type;
+	Stg_Class_DeleteFunction*                              _delete = _FieldTest_Delete;
+	Stg_Class_PrintFunction*                                _print = _FieldTest_Print;
+	Stg_Class_CopyFunction*                                  _copy = _FieldTest_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _AnalyticPressure_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _AnalyticPressure_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _AnalyticPressure_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _FieldTest_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _FieldTest_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _FieldTest_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 _FieldTest_New(  FIELDTEST_PASSARGS  );
+}
+
+Index PICellerator_AnalyticPressure_Register( PluginsManager* pluginsManager ) {
+  return PluginsManager_Submit( pluginsManager, AnalyticPressure_Type, "0", _AnalyticPressure_DefaultNew  );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/BuoyancyForceTerm.c
--- a/Utils/src/BuoyancyForceTerm.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,441 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: BuoyancyForceTerm.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-#include "types.h"
-#include "BuoyancyForceTerm.h"
-#include "HydrostaticTerm.h"
-#include "MaterialSwarmVariable.h"
-
-#include <assert.h>
-#include <string.h>
-#include <stddef.h>
-
-/* Textual name of this class */
-const Type BuoyancyForceTerm_Type = "BuoyancyForceTerm";
-
-BuoyancyForceTerm* BuoyancyForceTerm_New( 
-	Name							name,
-	FiniteElementContext*	context,
-	ForceVector*				forceVector,
-	Swarm*						integrationSwarm,
-	FeVariable*					temperatureField,
-	double						gravity,
-	Bool							adjust,
-	Materials_Register*		materials_Register,
-        HydrostaticTerm*                                hydrostaticTerm )
-{
-	BuoyancyForceTerm* self = (BuoyancyForceTerm*) _BuoyancyForceTerm_DefaultNew( name );
-
-	self->isConstructed = True;
-	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
-	_BuoyancyForceTerm_Init( self, temperatureField, gravity, adjust, materials_Register,
-                                 hydrostaticTerm );
-
-	return self;
-}
-
-/* Creation implementation / Virtual constructor */
-BuoyancyForceTerm* _BuoyancyForceTerm_New(  BUOYANCYFORCETERM_DEFARGS  )
-{
-	BuoyancyForceTerm* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(BuoyancyForceTerm) );
-	/* 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 = (BuoyancyForceTerm*) _ForceTerm_New(  FORCETERM_PASSARGS  );
-	
-	/* Virtual info */
-	self->_calcGravity = _calcGravity;
-	
-	return self;
-}
-
-void _BuoyancyForceTerm_Init( 
-	void*						forceTerm, 
-	FeVariable*				temperatureField,
-	double					gravity,
-	Bool						adjust,
-	Materials_Register*	materials_Register,
-        HydrostaticTerm*                        hydrostaticTerm )
-{
-	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
-
-	self->temperatureField    = temperatureField;
-	self->gravity             = gravity;
-	self->gHat		  = NULL;
-	self->adjust              = adjust;
-	self->materials_Register  = materials_Register;
-        self->hydrostaticTerm     = hydrostaticTerm;
-}
-
-void _BuoyancyForceTerm_Delete( void* forceTerm ) {
-	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
-
-	_ForceTerm_Delete( self );
-}
-
-void _BuoyancyForceTerm_Print( void* forceTerm, Stream* stream ) {
-	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
-	
-	_ForceTerm_Print( self, stream );
-
-	/* General info */
-	Journal_PrintPointer( stream, self->temperatureField );
-	Journal_PrintDouble( stream, self->gravity );
-}
-
-void* _BuoyancyForceTerm_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(BuoyancyForceTerm);
-	Type                                                      type = BuoyancyForceTerm_Type;
-	Stg_Class_DeleteFunction*                              _delete = _BuoyancyForceTerm_Delete;
-	Stg_Class_PrintFunction*                                _print = _BuoyancyForceTerm_Print;
-	Stg_Class_CopyFunction*                                  _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _BuoyancyForceTerm_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _BuoyancyForceTerm_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _BuoyancyForceTerm_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _BuoyancyForceTerm_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _BuoyancyForceTerm_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _BuoyancyForceTerm_Destroy;
-	ForceTerm_AssembleElementFunction*            _assembleElement = _BuoyancyForceTerm_AssembleElement;
-	BuoyancyForceTerm_CalcGravityFunction*            _calcGravity = _BuoyancyForceTerm_CalcGravity;
-
-	/* 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*)_BuoyancyForceTerm_New(  BUOYANCYFORCETERM_PASSARGS  );
-}
-
-void _BuoyancyForceTerm_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
-	BuoyancyForceTerm*		self = (BuoyancyForceTerm*)forceTerm;
-	Dictionary*					dict;
-	Dictionary_Entry_Value*	tmp;
-	char*							rootKey;
-	FeVariable*					temperatureField;
-	double						gravity;
-	Bool							adjust;
-	Materials_Register*		materials_Register;
-	unsigned						nDims;
-	Dictionary_Entry_Value*	direcList;
-	double*						direc;
-	unsigned						d_i;
-	PICelleratorContext*		context;
-        HydrostaticTerm*                                    hydrostaticTerm;
-
-	/* Construct Parent */
-	_ForceTerm_AssignFromXML( self, cf, data );
-
-	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
-	temperatureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TemperatureField", FeVariable, False, data  ) ;
-	gravity = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"gravity", 0.0  );
-	adjust = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"adjust", False  );
-
-	direcList = Dictionary_Get( dict, (Dictionary_Entry_Key)"gravityDirection" );
-
-	if( direcList ) {
-		nDims = Dictionary_Entry_Value_GetCount( direcList  );
-		direc = AllocArray( double, nDims );
-
-		for( d_i = 0; d_i < nDims; d_i++ ) {
-			tmp = Dictionary_Entry_Value_GetElement( direcList, d_i );
-			rootKey = Dictionary_Entry_Value_AsString( tmp );
-
-			if( !Stg_StringIsNumeric( (char *)rootKey )  )
-				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
-			direc[d_i] = Dictionary_Entry_Value_AsDouble( tmp );
-		}
-		if( nDims == 2  )
-			Vec_Norm2D( direc, direc );
-		else
-			Vec_Norm3D( direc, direc );
-	}
-	else
-		direc = NULL;
-	self->gHat = direc;
-
-	context = (PICelleratorContext*)self->context;
-	assert( Stg_CheckType( context, PICelleratorContext ) );
-	materials_Register = context->materials_Register;
-	assert( materials_Register );
-
-	hydrostaticTerm = Stg_ComponentFactory_ConstructByKey( cf, self->name, "HydrostaticTerm", HydrostaticTerm, False, data ) ;
-
-	_BuoyancyForceTerm_Init( self, temperatureField, gravity, adjust,
-                                 materials_Register, hydrostaticTerm );
-}
-
-void _BuoyancyForceTerm_Build( void* forceTerm, void* data ) {
-	BuoyancyForceTerm*               self               = (BuoyancyForceTerm*)forceTerm;
-	BuoyancyForceTerm_MaterialExt*   materialExt;
-	Material_Index                   material_I;
-	Material*                        material;
-	Materials_Register*              materials_Register = self->materials_Register;
-	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
-	MaterialPointsSwarm**            materialSwarms;
-	Index                            materialSwarm_I;
-	char*                            name;
-	Stg_ComponentFactory*            cf;
-
-	cf = self->context->CF;
-
-	_ForceTerm_Build( self, data );
-
-	if ( self->temperatureField )
-		Stg_Component_Build( self->temperatureField, data, False );
-
-	/* Sort out material extension stuff */
-	self->materialExtHandle = Materials_Register_AddMaterialExtension( 
-			self->materials_Register, 
-			self->type, 
-			sizeof(BuoyancyForceTerm_MaterialExt) );
-	for ( material_I = 0 ; material_I < Materials_Register_GetCount( materials_Register ) ; material_I++) {
-		material = Materials_Register_GetByIndex( materials_Register, material_I );
-		materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material, self->materialExtHandle );
-
-		materialExt->density = Stg_ComponentFactory_GetDouble( cf, material->name, (Dictionary_Entry_Key)"density", 0.0  );
-		materialExt->alpha   = Stg_ComponentFactory_GetDouble( cf, material->name, (Dictionary_Entry_Key)"alpha", 0.0  );
-	}
-	
-	/* Create Swarm Variables of each material swarm this ip swarm is mapped against */
-	materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms( swarm->mapper, &(self->materialSwarmCount) );
-	self->densitySwarmVariables = Memory_Alloc_Array( MaterialSwarmVariable*, self->materialSwarmCount, "DensityVariables" );
-	self->alphaSwarmVariables   = Memory_Alloc_Array( MaterialSwarmVariable*, self->materialSwarmCount, "AlphaVariables" );
-	
-	for ( materialSwarm_I = 0; materialSwarm_I < self->materialSwarmCount; ++materialSwarm_I ) {
-		name = Stg_Object_AppendSuffix( materialSwarms[materialSwarm_I], (Name)"Density"  );
-		self->densitySwarmVariables[materialSwarm_I] = MaterialSwarmVariable_New( 
-				name,
-				(AbstractContext*)self->context,
-				materialSwarms[materialSwarm_I], 
-				1, 
-				self->materials_Register, 
-				self->materialExtHandle, 
-				GetOffsetOfMember( *materialExt, density ) );
-		Memory_Free( name );
-
-		name = Stg_Object_AppendSuffix( materialSwarms[materialSwarm_I], (Name)"Alpha"  );
-		self->alphaSwarmVariables[materialSwarm_I] = MaterialSwarmVariable_New( 
-				name,
-				(AbstractContext*)self->context,
-				materialSwarms[materialSwarm_I], 
-				1, 
-				self->materials_Register, 
-				self->materialExtHandle, 
-				GetOffsetOfMember( *materialExt, alpha ) );
-		Memory_Free( name );
-	
-		/* Build new Swarm Variables */
-		Stg_Component_Build( self->densitySwarmVariables[materialSwarm_I], data, False );
-		Stg_Component_Build( self->alphaSwarmVariables[materialSwarm_I],   data, False );
-	}
-}
-
-void _BuoyancyForceTerm_Initialise( void* forceTerm, void* data ) {
-	BuoyancyForceTerm*             self             = (BuoyancyForceTerm*)forceTerm;
-	Index                          i;
-
-	_ForceTerm_Initialise( self, data );
-
-	if ( self->temperatureField )
-		Stg_Component_Initialise( self->temperatureField, data, False );
-	
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		Stg_Component_Initialise( self->densitySwarmVariables[i], data, False );
-		Stg_Component_Initialise( self->alphaSwarmVariables[i],   data, False );
-	}
-}
-
-void _BuoyancyForceTerm_Execute( void* forceTerm, void* data ) {
-	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
-
-	_ForceTerm_Execute( self, data );
-}
-
-void _BuoyancyForceTerm_Destroy( void* forceTerm, void* data ) {
-	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
-	Index i;
-
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		_Stg_Component_Delete( self->densitySwarmVariables[i] );
-		_Stg_Component_Delete( self->alphaSwarmVariables[i] );
-	}
-
-	FreeArray( self->gHat );
-
-	Memory_Free( self->densitySwarmVariables );
-	Memory_Free( self->alphaSwarmVariables );
-
-	_ForceTerm_Destroy( forceTerm, data );
-}
-
-void _BuoyancyForceTerm_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
-	BuoyancyForceTerm*               self               = (BuoyancyForceTerm*) forceTerm;
-	IntegrationPoint*                particle;
-	Particle_InCellIndex             cParticle_I;
-	Particle_InCellIndex             cellParticleCount;
-	Element_NodeIndex                elementNodeCount;
-	Dimension_Index                  dim                = forceVector->dim;
-	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
-	FeMesh*              mesh               = forceVector->feVariable->feMesh;
-	Node_ElementLocalIndex           eNode_I;
-	Cell_Index                       cell_I;
-	ElementType*                     elementType;
-	Dof_Index                        nodeDofCount;
-	double                           gravity;
-	double                           detJac             = 0.0;
-	double                           factor;
-	double                           Ni[27];
-	double                           force;
-	double*                          xi;
-#if 0
-	BuoyancyForceTerm_MaterialExt*   materialExt;
-	Material*                        material;
-#endif
-	FeVariable*                      temperatureField   = self->temperatureField;
-	double                           temperature        = 0.0;
-        double                           background_density = 0.0;
-	double*				 gHat;
-	unsigned			d_i;
-
-	double totalWeight = 0.0;
-	double adjustFactor = 0.0;
-	double density;
-	double alpha;
-
-	elementType       = FeMesh_GetElementType( mesh, lElement_I );
-	elementNodeCount  = elementType->nodeCount;
-	nodeDofCount      = dim;
-	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	cellParticleCount = swarm->cellParticleCountTbl[cell_I];
-	gHat		  = self->gHat;
-
-	/* adjust & adjustFactor -- 20060411 Alan
-	 *
-	 * The adjust decides whether an adjustFactor should be applied to the resulting factor.
-	 * If on, the total weight of the particles in the cell are scaled to the cell local volume.
-	 *
-	 * This is designed to be used when integrating with swarms which do not cover the whole domain
-	 * (ie - I used it to do dave.m's test of 1 swarm for blob, 1 swarm for background)
-	 */ 
-	if ( self->adjust ) {
-		for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-			particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-			totalWeight += particle->weight;
-		}
-		adjustFactor = swarm->weights->cellLocalVolume / totalWeight;
-	}
-	else {
-		adjustFactor = 1.0;
-	}
-
-	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-          Coord coord;
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		xi       = particle->xi;
-
-		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
-		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
-
-		/* Get parameters */
-		if ( temperatureField ) 
-			FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, lElement_I, xi, &temperature );
-
-		density = IntegrationPointMapper_GetDoubleFromMaterial(
-		    swarm->mapper, particle, self->materialExtHandle,
-		    offsetof(BuoyancyForceTerm_MaterialExt, density));
-		alpha = IntegrationPointMapper_GetDoubleFromMaterial(
-		    swarm->mapper, particle, self->materialExtHandle,
-		    offsetof(BuoyancyForceTerm_MaterialExt, alpha));
-
-/*
-		material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*) swarm, particle );
-		materialExt = ExtensionManager_Get( material->extensionMgr, material, self->materialExtHandle );
-*/
-                if(self->hydrostaticTerm)
-                  {
-                    FeMesh_CoordLocalToGlobal(mesh, cell_I, xi, coord);
-                    background_density=HydrostaticTerm_Density(self->hydrostaticTerm,coord);
-                  }
-
-		/* Calculate Force */
-		gravity = BuoyancyForceTerm_CalcGravity( self, (Swarm*)swarm, lElement_I, particle );
-                force=gravity*(density*(1.0-alpha*temperature)
-                               - background_density);
-		factor = detJac * particle->weight * adjustFactor * force;
-
-		/* Apply force in the correct direction */
-		for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) {
-			if( gHat ) {
-				for( d_i = 0; d_i < dim; d_i++ )
-					elForceVec[ eNode_I * nodeDofCount + d_i ] += gHat[d_i] * factor * Ni[ eNode_I ] ;
-			}
-			else {
-				elForceVec[ eNode_I * nodeDofCount + J_AXIS ] += -1.0 * factor * Ni[ eNode_I ] ;
-			}
-		}
-	}
-	
-}
-
-/* The default implementation is for the gravity to be constant. */
-double _BuoyancyForceTerm_CalcGravity( void* forceTerm, Swarm* swarm, Element_DomainIndex dElement_I, void* particle ) {
-	BuoyancyForceTerm*               self               = (BuoyancyForceTerm*) forceTerm;
-
-	return self->gravity;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/BuoyancyForceTerm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/BuoyancyForceTerm.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,441 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: BuoyancyForceTerm.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+#include "types.h"
+#include "BuoyancyForceTerm.h"
+#include "HydrostaticTerm.h"
+#include "MaterialSwarmVariable.h"
+
+#include <assert.h>
+#include <string.h>
+#include <stddef.h>
+
+/* Textual name of this class */
+const Type BuoyancyForceTerm_Type = "BuoyancyForceTerm";
+
+BuoyancyForceTerm* BuoyancyForceTerm_New( 
+	Name							name,
+	FiniteElementContext*	context,
+	ForceVector*				forceVector,
+	Swarm*						integrationSwarm,
+	FeVariable*					temperatureField,
+	double						gravity,
+	Bool							adjust,
+	Materials_Register*		materials_Register,
+        HydrostaticTerm*                                hydrostaticTerm )
+{
+	BuoyancyForceTerm* self = (BuoyancyForceTerm*) _BuoyancyForceTerm_DefaultNew( name );
+
+	self->isConstructed = True;
+	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
+	_BuoyancyForceTerm_Init( self, temperatureField, gravity, adjust, materials_Register,
+                                 hydrostaticTerm );
+
+	return self;
+}
+
+/* Creation implementation / Virtual constructor */
+BuoyancyForceTerm* _BuoyancyForceTerm_New(  BUOYANCYFORCETERM_DEFARGS  )
+{
+	BuoyancyForceTerm* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(BuoyancyForceTerm) );
+	/* 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 = (BuoyancyForceTerm*) _ForceTerm_New(  FORCETERM_PASSARGS  );
+	
+	/* Virtual info */
+	self->_calcGravity = _calcGravity;
+	
+	return self;
+}
+
+void _BuoyancyForceTerm_Init( 
+	void*						forceTerm, 
+	FeVariable*				temperatureField,
+	double					gravity,
+	Bool						adjust,
+	Materials_Register*	materials_Register,
+        HydrostaticTerm*                        hydrostaticTerm )
+{
+	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
+
+	self->temperatureField    = temperatureField;
+	self->gravity             = gravity;
+	self->gHat		  = NULL;
+	self->adjust              = adjust;
+	self->materials_Register  = materials_Register;
+        self->hydrostaticTerm     = hydrostaticTerm;
+}
+
+void _BuoyancyForceTerm_Delete( void* forceTerm ) {
+	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
+
+	_ForceTerm_Delete( self );
+}
+
+void _BuoyancyForceTerm_Print( void* forceTerm, Stream* stream ) {
+	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
+	
+	_ForceTerm_Print( self, stream );
+
+	/* General info */
+	Journal_PrintPointer( stream, self->temperatureField );
+	Journal_PrintDouble( stream, self->gravity );
+}
+
+void* _BuoyancyForceTerm_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(BuoyancyForceTerm);
+	Type                                                      type = BuoyancyForceTerm_Type;
+	Stg_Class_DeleteFunction*                              _delete = _BuoyancyForceTerm_Delete;
+	Stg_Class_PrintFunction*                                _print = _BuoyancyForceTerm_Print;
+	Stg_Class_CopyFunction*                                  _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _BuoyancyForceTerm_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _BuoyancyForceTerm_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _BuoyancyForceTerm_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _BuoyancyForceTerm_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _BuoyancyForceTerm_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _BuoyancyForceTerm_Destroy;
+	ForceTerm_AssembleElementFunction*            _assembleElement = _BuoyancyForceTerm_AssembleElement;
+	BuoyancyForceTerm_CalcGravityFunction*            _calcGravity = _BuoyancyForceTerm_CalcGravity;
+
+	/* 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*)_BuoyancyForceTerm_New(  BUOYANCYFORCETERM_PASSARGS  );
+}
+
+void _BuoyancyForceTerm_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
+	BuoyancyForceTerm*		self = (BuoyancyForceTerm*)forceTerm;
+	Dictionary*					dict;
+	Dictionary_Entry_Value*	tmp;
+	char*							rootKey;
+	FeVariable*					temperatureField;
+	double						gravity;
+	Bool							adjust;
+	Materials_Register*		materials_Register;
+	unsigned						nDims;
+	Dictionary_Entry_Value*	direcList;
+	double*						direc;
+	unsigned						d_i;
+	PICelleratorContext*		context;
+        HydrostaticTerm*                                    hydrostaticTerm;
+
+	/* Construct Parent */
+	_ForceTerm_AssignFromXML( self, cf, data );
+
+	dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, (Dictionary_Entry_Key)self->name )  );
+	temperatureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TemperatureField", FeVariable, False, data  ) ;
+	gravity = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"gravity", 0.0  );
+	adjust = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"adjust", False  );
+
+	direcList = Dictionary_Get( dict, (Dictionary_Entry_Key)"gravityDirection" );
+
+	if( direcList ) {
+		nDims = Dictionary_Entry_Value_GetCount( direcList  );
+		direc = AllocArray( double, nDims );
+
+		for( d_i = 0; d_i < nDims; d_i++ ) {
+			tmp = Dictionary_Entry_Value_GetElement( direcList, d_i );
+			rootKey = Dictionary_Entry_Value_AsString( tmp );
+
+			if( !Stg_StringIsNumeric( (char *)rootKey )  )
+				tmp = Dictionary_Get( cf->rootDict, (Dictionary_Entry_Key)rootKey );
+			direc[d_i] = Dictionary_Entry_Value_AsDouble( tmp );
+		}
+		if( nDims == 2  )
+			Vec_Norm2D( direc, direc );
+		else
+			Vec_Norm3D( direc, direc );
+	}
+	else
+		direc = NULL;
+	self->gHat = direc;
+
+	context = (PICelleratorContext*)self->context;
+	assert( Stg_CheckType( context, PICelleratorContext ) );
+	materials_Register = context->materials_Register;
+	assert( materials_Register );
+
+	hydrostaticTerm = Stg_ComponentFactory_ConstructByKey( cf, self->name, "HydrostaticTerm", HydrostaticTerm, False, data ) ;
+
+	_BuoyancyForceTerm_Init( self, temperatureField, gravity, adjust,
+                                 materials_Register, hydrostaticTerm );
+}
+
+void _BuoyancyForceTerm_Build( void* forceTerm, void* data ) {
+	BuoyancyForceTerm*               self               = (BuoyancyForceTerm*)forceTerm;
+	BuoyancyForceTerm_MaterialExt*   materialExt;
+	Material_Index                   material_I;
+	Material*                        material;
+	Materials_Register*              materials_Register = self->materials_Register;
+	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
+	MaterialPointsSwarm**            materialSwarms;
+	Index                            materialSwarm_I;
+	char*                            name;
+	Stg_ComponentFactory*            cf;
+
+	cf = self->context->CF;
+
+	_ForceTerm_Build( self, data );
+
+	if ( self->temperatureField )
+		Stg_Component_Build( self->temperatureField, data, False );
+
+	/* Sort out material extension stuff */
+	self->materialExtHandle = Materials_Register_AddMaterialExtension( 
+			self->materials_Register, 
+			self->type, 
+			sizeof(BuoyancyForceTerm_MaterialExt) );
+	for ( material_I = 0 ; material_I < Materials_Register_GetCount( materials_Register ) ; material_I++) {
+		material = Materials_Register_GetByIndex( materials_Register, material_I );
+		materialExt = (BuoyancyForceTerm_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material, self->materialExtHandle );
+
+		materialExt->density = Stg_ComponentFactory_GetDouble( cf, material->name, (Dictionary_Entry_Key)"density", 0.0  );
+		materialExt->alpha   = Stg_ComponentFactory_GetDouble( cf, material->name, (Dictionary_Entry_Key)"alpha", 0.0  );
+	}
+	
+	/* Create Swarm Variables of each material swarm this ip swarm is mapped against */
+	materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms( swarm->mapper, &(self->materialSwarmCount) );
+	self->densitySwarmVariables = Memory_Alloc_Array( MaterialSwarmVariable*, self->materialSwarmCount, "DensityVariables" );
+	self->alphaSwarmVariables   = Memory_Alloc_Array( MaterialSwarmVariable*, self->materialSwarmCount, "AlphaVariables" );
+	
+	for ( materialSwarm_I = 0; materialSwarm_I < self->materialSwarmCount; ++materialSwarm_I ) {
+		name = Stg_Object_AppendSuffix( materialSwarms[materialSwarm_I], (Name)"Density"  );
+		self->densitySwarmVariables[materialSwarm_I] = MaterialSwarmVariable_New( 
+				name,
+				(AbstractContext*)self->context,
+				materialSwarms[materialSwarm_I], 
+				1, 
+				self->materials_Register, 
+				self->materialExtHandle, 
+				GetOffsetOfMember( *materialExt, density ) );
+		Memory_Free( name );
+
+		name = Stg_Object_AppendSuffix( materialSwarms[materialSwarm_I], (Name)"Alpha"  );
+		self->alphaSwarmVariables[materialSwarm_I] = MaterialSwarmVariable_New( 
+				name,
+				(AbstractContext*)self->context,
+				materialSwarms[materialSwarm_I], 
+				1, 
+				self->materials_Register, 
+				self->materialExtHandle, 
+				GetOffsetOfMember( *materialExt, alpha ) );
+		Memory_Free( name );
+	
+		/* Build new Swarm Variables */
+		Stg_Component_Build( self->densitySwarmVariables[materialSwarm_I], data, False );
+		Stg_Component_Build( self->alphaSwarmVariables[materialSwarm_I],   data, False );
+	}
+}
+
+void _BuoyancyForceTerm_Initialise( void* forceTerm, void* data ) {
+	BuoyancyForceTerm*             self             = (BuoyancyForceTerm*)forceTerm;
+	Index                          i;
+
+	_ForceTerm_Initialise( self, data );
+
+	if ( self->temperatureField )
+		Stg_Component_Initialise( self->temperatureField, data, False );
+	
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		Stg_Component_Initialise( self->densitySwarmVariables[i], data, False );
+		Stg_Component_Initialise( self->alphaSwarmVariables[i],   data, False );
+	}
+}
+
+void _BuoyancyForceTerm_Execute( void* forceTerm, void* data ) {
+	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
+
+	_ForceTerm_Execute( self, data );
+}
+
+void _BuoyancyForceTerm_Destroy( void* forceTerm, void* data ) {
+	BuoyancyForceTerm* self = (BuoyancyForceTerm*)forceTerm;
+	Index i;
+
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		_Stg_Component_Delete( self->densitySwarmVariables[i] );
+		_Stg_Component_Delete( self->alphaSwarmVariables[i] );
+	}
+
+	FreeArray( self->gHat );
+
+	Memory_Free( self->densitySwarmVariables );
+	Memory_Free( self->alphaSwarmVariables );
+
+	_ForceTerm_Destroy( forceTerm, data );
+}
+
+void _BuoyancyForceTerm_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
+	BuoyancyForceTerm*               self               = (BuoyancyForceTerm*) forceTerm;
+	IntegrationPoint*                particle;
+	Particle_InCellIndex             cParticle_I;
+	Particle_InCellIndex             cellParticleCount;
+	Element_NodeIndex                elementNodeCount;
+	Dimension_Index                  dim                = forceVector->dim;
+	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
+	FeMesh*              mesh               = forceVector->feVariable->feMesh;
+	Node_ElementLocalIndex           eNode_I;
+	Cell_Index                       cell_I;
+	ElementType*                     elementType;
+	Dof_Index                        nodeDofCount;
+	double                           gravity;
+	double                           detJac             = 0.0;
+	double                           factor;
+	double                           Ni[27];
+	double                           force;
+	double*                          xi;
+#if 0
+	BuoyancyForceTerm_MaterialExt*   materialExt;
+	Material*                        material;
+#endif
+	FeVariable*                      temperatureField   = self->temperatureField;
+	double                           temperature        = 0.0;
+        double                           background_density = 0.0;
+	double*				 gHat;
+	unsigned			d_i;
+
+	double totalWeight = 0.0;
+	double adjustFactor = 0.0;
+	double density;
+	double alpha;
+
+	elementType       = FeMesh_GetElementType( mesh, lElement_I );
+	elementNodeCount  = elementType->nodeCount;
+	nodeDofCount      = dim;
+	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	cellParticleCount = swarm->cellParticleCountTbl[cell_I];
+	gHat		  = self->gHat;
+
+	/* adjust & adjustFactor -- 20060411 Alan
+	 *
+	 * The adjust decides whether an adjustFactor should be applied to the resulting factor.
+	 * If on, the total weight of the particles in the cell are scaled to the cell local volume.
+	 *
+	 * This is designed to be used when integrating with swarms which do not cover the whole domain
+	 * (ie - I used it to do dave.m's test of 1 swarm for blob, 1 swarm for background)
+	 */ 
+	if ( self->adjust ) {
+		for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+			particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+			totalWeight += particle->weight;
+		}
+		adjustFactor = swarm->weights->cellLocalVolume / totalWeight;
+	}
+	else {
+		adjustFactor = 1.0;
+	}
+
+	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+          Coord coord;
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		xi       = particle->xi;
+
+		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
+		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
+
+		/* Get parameters */
+		if ( temperatureField ) 
+			FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, lElement_I, xi, &temperature );
+
+		density = IntegrationPointMapper_GetDoubleFromMaterial(
+		    swarm->mapper, particle, self->materialExtHandle,
+		    offsetof(BuoyancyForceTerm_MaterialExt, density));
+		alpha = IntegrationPointMapper_GetDoubleFromMaterial(
+		    swarm->mapper, particle, self->materialExtHandle,
+		    offsetof(BuoyancyForceTerm_MaterialExt, alpha));
+
+/*
+		material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*) swarm, particle );
+		materialExt = ExtensionManager_Get( material->extensionMgr, material, self->materialExtHandle );
+*/
+                if(self->hydrostaticTerm)
+                  {
+                    FeMesh_CoordLocalToGlobal(mesh, cell_I, xi, coord);
+                    background_density=HydrostaticTerm_Density(self->hydrostaticTerm,coord);
+                  }
+
+		/* Calculate Force */
+		gravity = BuoyancyForceTerm_CalcGravity( self, (Swarm*)swarm, lElement_I, particle );
+                force=gravity*(density*(1.0-alpha*temperature)
+                               - background_density);
+		factor = detJac * particle->weight * adjustFactor * force;
+
+		/* Apply force in the correct direction */
+		for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) {
+			if( gHat ) {
+				for( d_i = 0; d_i < dim; d_i++ )
+					elForceVec[ eNode_I * nodeDofCount + d_i ] += gHat[d_i] * factor * Ni[ eNode_I ] ;
+			}
+			else {
+				elForceVec[ eNode_I * nodeDofCount + J_AXIS ] += -1.0 * factor * Ni[ eNode_I ] ;
+			}
+		}
+	}
+	
+}
+
+/* The default implementation is for the gravity to be constant. */
+double _BuoyancyForceTerm_CalcGravity( void* forceTerm, Swarm* swarm, Element_DomainIndex dElement_I, void* particle ) {
+	BuoyancyForceTerm*               self               = (BuoyancyForceTerm*) forceTerm;
+
+	return self->gravity;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/BuoyancyForceTermThermoChem.c
--- a/Utils/src/BuoyancyForceTermThermoChem.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,366 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: BuoyancyForceTermThermoChem.c 376 2006-10-18 06:58:41Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-#include "types.h"
-#include "BuoyancyForceTermThermoChem.h"
-#include "MaterialSwarmVariable.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type BuoyancyForceTermThermoChem_Type = "BuoyancyForceTermThermoChem";
-
-BuoyancyForceTermThermoChem* BuoyancyForceTermThermoChem_New( 
-	Name							name,
-	FiniteElementContext*	context,
-	ForceVector*				forceVector,
-	Swarm*						integrationSwarm,
-	FeVariable*					temperatureField,
-	double						RaT,
-	double						RaC,
-	Bool							adjust,
-	Materials_Register*		materials_Register )
-{
-	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*) _BuoyancyForceTermThermoChem_DefaultNew( name );
-
-	self->isConstructed = True;
-	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
-	_BuoyancyForceTermThermoChem_Init( self, temperatureField, RaT, RaC, adjust, materials_Register );
-
-	return self;
-}
-
-void* _BuoyancyForceTermThermoChem_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(BuoyancyForceTermThermoChem);
-	Type                                                         type = BuoyancyForceTermThermoChem_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _BuoyancyForceTermThermoChem_Delete;
-	Stg_Class_PrintFunction*                                   _print = _BuoyancyForceTermThermoChem_Print;
-	Stg_Class_CopyFunction*                                     _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _BuoyancyForceTermThermoChem_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _BuoyancyForceTermThermoChem_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _BuoyancyForceTermThermoChem_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _BuoyancyForceTermThermoChem_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _BuoyancyForceTermThermoChem_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _BuoyancyForceTermThermoChem_Destroy;
-	ForceTerm_AssembleElementFunction*               _assembleElement = _BuoyancyForceTermThermoChem_AssembleElement;
-	BuoyancyForceTermThermoChem_CalcRaTFunction*             _calcRaT = _BuoyancyForceTermThermoChem_CalcRaT;
-	BuoyancyForceTermThermoChem_CalcRaCFunction*             _calcRaC = _BuoyancyForceTermThermoChem_CalcRaC;
-
-	/* 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*)_BuoyancyForceTermThermoChem_New(  BUOYANCYFORCETERMTHERMOCHEM_PASSARGS  );
-}
-
-/* Creation implementation / Virtual constructor */
-BuoyancyForceTermThermoChem* _BuoyancyForceTermThermoChem_New(  BUOYANCYFORCETERMTHERMOCHEM_DEFARGS  )
-{
-	BuoyancyForceTermThermoChem* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(BuoyancyForceTermThermoChem) );
-	/* 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 = (BuoyancyForceTermThermoChem*) _ForceTerm_New(  FORCETERM_PASSARGS  );
-	
-	/* Virtual info */
-	self->_calcRaT = _calcRaT;
-	self->_calcRaC = _calcRaC;
-	
-	return self;
-}
-
-void _BuoyancyForceTermThermoChem_Init( 
-	BuoyancyForceTermThermoChem*	self, 
-	FeVariable*							temperatureField,
-	double								RaT,
-	double								RaC,
-	Bool									adjust,
-	Materials_Register*				materials_Register )
-{
-	self->temperatureField    = temperatureField;
-	self->RaT                 = RaT;
-	self->RaC                 = RaC;
-	self->adjust              = adjust;
-	self->materials_Register  = materials_Register;
-}
-
-void _BuoyancyForceTermThermoChem_Delete( void* forceTerm ) {
-	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*)forceTerm;
-
-   Memory_Free( self->densitySwarmVariables );
-
-	_ForceTerm_Delete( self );
-}
-
-void _BuoyancyForceTermThermoChem_Print( void* forceTerm, Stream* stream ) {
-	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*)forceTerm;
-	
-	_ForceTerm_Print( self, stream );
-
-	/* General info */
-	Journal_PrintPointer( stream, self->temperatureField );
-	Journal_PrintDouble( stream, self->RaT );
-	Journal_PrintDouble( stream, self->RaC );
-}
-
-void _BuoyancyForceTermThermoChem_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
-	BuoyancyForceTermThermoChem*	self = (BuoyancyForceTermThermoChem*)forceTerm;
-	FeVariable*							temperatureField;
-	double								RaT;
-	double								RaC;
-	Bool									adjust;
-	Materials_Register*				materials_Register;
-	PICelleratorContext*				context;
-
-	/* Construct Parent */
-	_ForceTerm_AssignFromXML( self, cf, data );
-
-	temperatureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TemperatureField", FeVariable, False, data  ) ;
-	RaT = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"RaT", 0.0  );
-	RaC = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"RaC", 0.0  );
-	adjust = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"adjust", False );
-
-	context = (PICelleratorContext* )self->context;
-	assert( Stg_CheckType( context, PICelleratorContext ) );
-	materials_Register = context->materials_Register; 
-	assert( materials_Register );
-
-	_BuoyancyForceTermThermoChem_Init( self, temperatureField, RaT, RaC, adjust, materials_Register );
-}
-
-void _BuoyancyForceTermThermoChem_Build( void* forceTerm, void* data ) {
-	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*)forceTerm;
-	BuoyancyForceTermThermoChem_MaterialExt*   materialExt;
-	Material_Index                   material_I;
-	Material*                        material;
-	Materials_Register*              materials_Register = self->materials_Register;
-	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
-	MaterialPointsSwarm**            materialSwarms;
-	Index                            materialSwarm_I;
-	char*                            name;
-
-	_ForceTerm_Build( self, data );
-
-	if ( self->temperatureField )
-		Stg_Component_Build( self->temperatureField, data, False );
-
-	/* Sort out material extension stuff */
-	self->materialExtHandle = Materials_Register_AddMaterialExtension( 
-			self->materials_Register, 
-			self->type, 
-			sizeof(BuoyancyForceTermThermoChem_MaterialExt) );
-	for ( material_I = 0 ; material_I < Materials_Register_GetCount( materials_Register ) ; material_I++) {
-		material = Materials_Register_GetByIndex( materials_Register, material_I );
-		materialExt = (BuoyancyForceTermThermoChem_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material, self->materialExtHandle );
-
-		materialExt->density = Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"density", 0.0  );
-	}
-	
-	/* Create Swarm Variables of each material swarm this ip swarm is mapped against */
-	materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms( swarm->mapper, &(self->materialSwarmCount) );
-	self->densitySwarmVariables = Memory_Alloc_Array( MaterialSwarmVariable*, self->materialSwarmCount, "DensityVariables" );
-	
-	for ( materialSwarm_I = 0; materialSwarm_I < self->materialSwarmCount; ++materialSwarm_I ) {
-		name = Stg_Object_AppendSuffix( materialSwarms[materialSwarm_I], (Name)"Density"  );
-		self->densitySwarmVariables[materialSwarm_I] = MaterialSwarmVariable_New( 
-				name,
-				(AbstractContext*) self->context,
-				materialSwarms[materialSwarm_I], 
-				1, 
-				self->materials_Register, 
-				self->materialExtHandle, 
-				GetOffsetOfMember( *materialExt, density ) );
-		Memory_Free( name );
-		
-		/* Build new Swarm Variables */
-		Stg_Component_Build( self->densitySwarmVariables[materialSwarm_I], data, False );
-	}
-
-
-}
-
-void _BuoyancyForceTermThermoChem_Initialise( void* forceTerm, void* data ) {
-	BuoyancyForceTermThermoChem*             self             = (BuoyancyForceTermThermoChem*)forceTerm;
-	Index                          i;
-
-	_ForceTerm_Initialise( self, data );
-
-	if ( self->temperatureField )
-		Stg_Component_Initialise( self->temperatureField, data, False );
-	
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		Stg_Component_Initialise( self->densitySwarmVariables[i], data, False );
-	}
-}
-
-void _BuoyancyForceTermThermoChem_Execute( void* forceTerm, void* data ) {
-	_ForceTerm_Execute( forceTerm, data );
-}
-
-void _BuoyancyForceTermThermoChem_Destroy( void* forceTerm, void* data ) {
-	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*)forceTerm;
-	Index i;
-
-	for ( i = 0; i < self->materialSwarmCount; ++i ) {
-		Stg_Component_Destroy( self->densitySwarmVariables[i], data, False );
-	}
-
-	if ( self->temperatureField )
-		Stg_Component_Destroy( self->temperatureField, data, False );
-
-	_ForceTerm_Destroy( self, data );
-}
-
-
-void _BuoyancyForceTermThermoChem_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
-	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*) forceTerm;
-	IntegrationPoint*                particle;
-	BuoyancyForceTermThermoChem_MaterialExt*   materialExt;
-	Particle_InCellIndex             cParticle_I;
-	Particle_InCellIndex             cellParticleCount;
-	Element_NodeIndex                elementNodeCount;
-	Dimension_Index                  dim                = forceVector->dim;
-	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
-	FeMesh*		                 mesh               = forceVector->feVariable->feMesh;
-	Node_ElementLocalIndex           eNode_I;
-	Cell_Index                       cell_I;
-	ElementType*                     elementType;
-	Dof_Index                        nodeDofCount;
-	double                           RaT;
-	double                           RaC;
-	double                           detJac             = 0.0;
-	double                           factor;
-	double                           Ni[27];
-	double                           force;
-	double*                          xi;
-	Material*                        material;
-	FeVariable*                      temperatureField   = self->temperatureField;
-	double                           temperature        = 0.0;
-
-	double totalWeight = 0.0;
-	double adjustFactor = 0.0;
-
-	elementType       = FeMesh_GetElementType( mesh, lElement_I );
-	elementNodeCount  = elementType->nodeCount;
-	nodeDofCount      = dim;
-	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-	cellParticleCount = swarm->cellParticleCountTbl[cell_I];
-
-	/* adjust & adjustFactor -- 20060411 Alan
-	 *
-	 * The adjust decides whether an adjustFactor should be applied to the resulting factor.
-	 * If on, the total weight of the particles in the cell are scaled to the cell local volume.
-	 *
-	 * This is designed to be used when integrating with swarms which do not cover the whole domain
-	 * (ie - I used it to do dave.m's test of 1 swarm for blob, 1 swarm for background)
-	 */ 
-	if ( self->adjust ) {
-		for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-			particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-			totalWeight += particle->weight;
-		}
-		adjustFactor = swarm->weights->cellLocalVolume / totalWeight;
-	}
-	else {
-		adjustFactor = 1.0;
-	}
-			
-	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
-		xi       = particle->xi;
-
-		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
-		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
-
-		/* Get parameters */
-		if ( temperatureField )
-			FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, lElement_I, xi, &temperature );
-
-		material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*) swarm, particle );
-		materialExt = (BuoyancyForceTermThermoChem_MaterialExt*)ExtensionManager_Get( material->extensionMgr, material, self->materialExtHandle );
-
-		/* Calculate Force */
-		RaT = BuoyancyForceTermThermoChem_CalcRaT( self, (Swarm*)swarm, lElement_I, particle );
-		RaC = BuoyancyForceTermThermoChem_CalcRaC( self, (Swarm*)swarm, lElement_I, particle );
-
-		force =  ( RaT * temperature) - ( materialExt->density * RaC );
-		factor = detJac * particle->weight * adjustFactor * force;
-
-		/* Apply force in verticle direction */
-		for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) { 		
-			elForceVec[ eNode_I * nodeDofCount + J_AXIS ] += factor * Ni[ eNode_I ] ;
-		}
-	}
-	
-}
-
-/* The default implementation is for the RaC to be constant. */
-double _BuoyancyForceTermThermoChem_CalcRaT( void* forceTerm, Swarm* swarm, Element_DomainIndex dElement_I, void* particle ) {
-	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*) forceTerm;
-
-	return self->RaT;
-}
-
-double _BuoyancyForceTermThermoChem_CalcRaC( void* forceTerm, Swarm* swarm, Element_DomainIndex dElement_I, void* particle ) {
-	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*) forceTerm;
-
-	return self->RaC;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/BuoyancyForceTermThermoChem.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/BuoyancyForceTermThermoChem.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,366 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: BuoyancyForceTermThermoChem.c 376 2006-10-18 06:58:41Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+#include "types.h"
+#include "BuoyancyForceTermThermoChem.h"
+#include "MaterialSwarmVariable.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type BuoyancyForceTermThermoChem_Type = "BuoyancyForceTermThermoChem";
+
+BuoyancyForceTermThermoChem* BuoyancyForceTermThermoChem_New( 
+	Name							name,
+	FiniteElementContext*	context,
+	ForceVector*				forceVector,
+	Swarm*						integrationSwarm,
+	FeVariable*					temperatureField,
+	double						RaT,
+	double						RaC,
+	Bool							adjust,
+	Materials_Register*		materials_Register )
+{
+	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*) _BuoyancyForceTermThermoChem_DefaultNew( name );
+
+	self->isConstructed = True;
+	_ForceTerm_Init( self, context, forceVector, integrationSwarm, NULL );
+	_BuoyancyForceTermThermoChem_Init( self, temperatureField, RaT, RaC, adjust, materials_Register );
+
+	return self;
+}
+
+void* _BuoyancyForceTermThermoChem_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(BuoyancyForceTermThermoChem);
+	Type                                                         type = BuoyancyForceTermThermoChem_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _BuoyancyForceTermThermoChem_Delete;
+	Stg_Class_PrintFunction*                                   _print = _BuoyancyForceTermThermoChem_Print;
+	Stg_Class_CopyFunction*                                     _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _BuoyancyForceTermThermoChem_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _BuoyancyForceTermThermoChem_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _BuoyancyForceTermThermoChem_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _BuoyancyForceTermThermoChem_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _BuoyancyForceTermThermoChem_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _BuoyancyForceTermThermoChem_Destroy;
+	ForceTerm_AssembleElementFunction*               _assembleElement = _BuoyancyForceTermThermoChem_AssembleElement;
+	BuoyancyForceTermThermoChem_CalcRaTFunction*             _calcRaT = _BuoyancyForceTermThermoChem_CalcRaT;
+	BuoyancyForceTermThermoChem_CalcRaCFunction*             _calcRaC = _BuoyancyForceTermThermoChem_CalcRaC;
+
+	/* 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*)_BuoyancyForceTermThermoChem_New(  BUOYANCYFORCETERMTHERMOCHEM_PASSARGS  );
+}
+
+/* Creation implementation / Virtual constructor */
+BuoyancyForceTermThermoChem* _BuoyancyForceTermThermoChem_New(  BUOYANCYFORCETERMTHERMOCHEM_DEFARGS  )
+{
+	BuoyancyForceTermThermoChem* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(BuoyancyForceTermThermoChem) );
+	/* 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 = (BuoyancyForceTermThermoChem*) _ForceTerm_New(  FORCETERM_PASSARGS  );
+	
+	/* Virtual info */
+	self->_calcRaT = _calcRaT;
+	self->_calcRaC = _calcRaC;
+	
+	return self;
+}
+
+void _BuoyancyForceTermThermoChem_Init( 
+	BuoyancyForceTermThermoChem*	self, 
+	FeVariable*							temperatureField,
+	double								RaT,
+	double								RaC,
+	Bool									adjust,
+	Materials_Register*				materials_Register )
+{
+	self->temperatureField    = temperatureField;
+	self->RaT                 = RaT;
+	self->RaC                 = RaC;
+	self->adjust              = adjust;
+	self->materials_Register  = materials_Register;
+}
+
+void _BuoyancyForceTermThermoChem_Delete( void* forceTerm ) {
+	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*)forceTerm;
+
+   Memory_Free( self->densitySwarmVariables );
+
+	_ForceTerm_Delete( self );
+}
+
+void _BuoyancyForceTermThermoChem_Print( void* forceTerm, Stream* stream ) {
+	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*)forceTerm;
+	
+	_ForceTerm_Print( self, stream );
+
+	/* General info */
+	Journal_PrintPointer( stream, self->temperatureField );
+	Journal_PrintDouble( stream, self->RaT );
+	Journal_PrintDouble( stream, self->RaC );
+}
+
+void _BuoyancyForceTermThermoChem_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf, void* data ) {
+	BuoyancyForceTermThermoChem*	self = (BuoyancyForceTermThermoChem*)forceTerm;
+	FeVariable*							temperatureField;
+	double								RaT;
+	double								RaC;
+	Bool									adjust;
+	Materials_Register*				materials_Register;
+	PICelleratorContext*				context;
+
+	/* Construct Parent */
+	_ForceTerm_AssignFromXML( self, cf, data );
+
+	temperatureField = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"TemperatureField", FeVariable, False, data  ) ;
+	RaT = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"RaT", 0.0  );
+	RaC = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"RaC", 0.0  );
+	adjust = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"adjust", False );
+
+	context = (PICelleratorContext* )self->context;
+	assert( Stg_CheckType( context, PICelleratorContext ) );
+	materials_Register = context->materials_Register; 
+	assert( materials_Register );
+
+	_BuoyancyForceTermThermoChem_Init( self, temperatureField, RaT, RaC, adjust, materials_Register );
+}
+
+void _BuoyancyForceTermThermoChem_Build( void* forceTerm, void* data ) {
+	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*)forceTerm;
+	BuoyancyForceTermThermoChem_MaterialExt*   materialExt;
+	Material_Index                   material_I;
+	Material*                        material;
+	Materials_Register*              materials_Register = self->materials_Register;
+	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
+	MaterialPointsSwarm**            materialSwarms;
+	Index                            materialSwarm_I;
+	char*                            name;
+
+	_ForceTerm_Build( self, data );
+
+	if ( self->temperatureField )
+		Stg_Component_Build( self->temperatureField, data, False );
+
+	/* Sort out material extension stuff */
+	self->materialExtHandle = Materials_Register_AddMaterialExtension( 
+			self->materials_Register, 
+			self->type, 
+			sizeof(BuoyancyForceTermThermoChem_MaterialExt) );
+	for ( material_I = 0 ; material_I < Materials_Register_GetCount( materials_Register ) ; material_I++) {
+		material = Materials_Register_GetByIndex( materials_Register, material_I );
+		materialExt = (BuoyancyForceTermThermoChem_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material, self->materialExtHandle );
+
+		materialExt->density = Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"density", 0.0  );
+	}
+	
+	/* Create Swarm Variables of each material swarm this ip swarm is mapped against */
+	materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms( swarm->mapper, &(self->materialSwarmCount) );
+	self->densitySwarmVariables = Memory_Alloc_Array( MaterialSwarmVariable*, self->materialSwarmCount, "DensityVariables" );
+	
+	for ( materialSwarm_I = 0; materialSwarm_I < self->materialSwarmCount; ++materialSwarm_I ) {
+		name = Stg_Object_AppendSuffix( materialSwarms[materialSwarm_I], (Name)"Density"  );
+		self->densitySwarmVariables[materialSwarm_I] = MaterialSwarmVariable_New( 
+				name,
+				(AbstractContext*) self->context,
+				materialSwarms[materialSwarm_I], 
+				1, 
+				self->materials_Register, 
+				self->materialExtHandle, 
+				GetOffsetOfMember( *materialExt, density ) );
+		Memory_Free( name );
+		
+		/* Build new Swarm Variables */
+		Stg_Component_Build( self->densitySwarmVariables[materialSwarm_I], data, False );
+	}
+
+
+}
+
+void _BuoyancyForceTermThermoChem_Initialise( void* forceTerm, void* data ) {
+	BuoyancyForceTermThermoChem*             self             = (BuoyancyForceTermThermoChem*)forceTerm;
+	Index                          i;
+
+	_ForceTerm_Initialise( self, data );
+
+	if ( self->temperatureField )
+		Stg_Component_Initialise( self->temperatureField, data, False );
+	
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		Stg_Component_Initialise( self->densitySwarmVariables[i], data, False );
+	}
+}
+
+void _BuoyancyForceTermThermoChem_Execute( void* forceTerm, void* data ) {
+	_ForceTerm_Execute( forceTerm, data );
+}
+
+void _BuoyancyForceTermThermoChem_Destroy( void* forceTerm, void* data ) {
+	BuoyancyForceTermThermoChem* self = (BuoyancyForceTermThermoChem*)forceTerm;
+	Index i;
+
+	for ( i = 0; i < self->materialSwarmCount; ++i ) {
+		Stg_Component_Destroy( self->densitySwarmVariables[i], data, False );
+	}
+
+	if ( self->temperatureField )
+		Stg_Component_Destroy( self->temperatureField, data, False );
+
+	_ForceTerm_Destroy( self, data );
+}
+
+
+void _BuoyancyForceTermThermoChem_AssembleElement( void* forceTerm, ForceVector* forceVector, Element_LocalIndex lElement_I, double* elForceVec ) {
+	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*) forceTerm;
+	IntegrationPoint*                particle;
+	BuoyancyForceTermThermoChem_MaterialExt*   materialExt;
+	Particle_InCellIndex             cParticle_I;
+	Particle_InCellIndex             cellParticleCount;
+	Element_NodeIndex                elementNodeCount;
+	Dimension_Index                  dim                = forceVector->dim;
+	IntegrationPointsSwarm*          swarm              = (IntegrationPointsSwarm*)self->integrationSwarm;
+	FeMesh*		                 mesh               = forceVector->feVariable->feMesh;
+	Node_ElementLocalIndex           eNode_I;
+	Cell_Index                       cell_I;
+	ElementType*                     elementType;
+	Dof_Index                        nodeDofCount;
+	double                           RaT;
+	double                           RaC;
+	double                           detJac             = 0.0;
+	double                           factor;
+	double                           Ni[27];
+	double                           force;
+	double*                          xi;
+	Material*                        material;
+	FeVariable*                      temperatureField   = self->temperatureField;
+	double                           temperature        = 0.0;
+
+	double totalWeight = 0.0;
+	double adjustFactor = 0.0;
+
+	elementType       = FeMesh_GetElementType( mesh, lElement_I );
+	elementNodeCount  = elementType->nodeCount;
+	nodeDofCount      = dim;
+	cell_I            = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+	cellParticleCount = swarm->cellParticleCountTbl[cell_I];
+
+	/* adjust & adjustFactor -- 20060411 Alan
+	 *
+	 * The adjust decides whether an adjustFactor should be applied to the resulting factor.
+	 * If on, the total weight of the particles in the cell are scaled to the cell local volume.
+	 *
+	 * This is designed to be used when integrating with swarms which do not cover the whole domain
+	 * (ie - I used it to do dave.m's test of 1 swarm for blob, 1 swarm for background)
+	 */ 
+	if ( self->adjust ) {
+		for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+			particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+			totalWeight += particle->weight;
+		}
+		adjustFactor = swarm->weights->cellLocalVolume / totalWeight;
+	}
+	else {
+		adjustFactor = 1.0;
+	}
+			
+	for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+		particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, cell_I, cParticle_I );
+		xi       = particle->xi;
+
+		detJac = ElementType_JacobianDeterminant( elementType, mesh, lElement_I, xi, dim );
+		ElementType_EvaluateShapeFunctionsAt( elementType, xi, Ni );
+
+		/* Get parameters */
+		if ( temperatureField )
+			FeVariable_InterpolateFromMeshLocalCoord( temperatureField, mesh, lElement_I, xi, &temperature );
+
+		material = IntegrationPointsSwarm_GetMaterialOn( (IntegrationPointsSwarm*) swarm, particle );
+		materialExt = (BuoyancyForceTermThermoChem_MaterialExt*)ExtensionManager_Get( material->extensionMgr, material, self->materialExtHandle );
+
+		/* Calculate Force */
+		RaT = BuoyancyForceTermThermoChem_CalcRaT( self, (Swarm*)swarm, lElement_I, particle );
+		RaC = BuoyancyForceTermThermoChem_CalcRaC( self, (Swarm*)swarm, lElement_I, particle );
+
+		force =  ( RaT * temperature) - ( materialExt->density * RaC );
+		factor = detJac * particle->weight * adjustFactor * force;
+
+		/* Apply force in verticle direction */
+		for( eNode_I = 0 ; eNode_I < elementNodeCount; eNode_I++ ) { 		
+			elForceVec[ eNode_I * nodeDofCount + J_AXIS ] += factor * Ni[ eNode_I ] ;
+		}
+	}
+	
+}
+
+/* The default implementation is for the RaC to be constant. */
+double _BuoyancyForceTermThermoChem_CalcRaT( void* forceTerm, Swarm* swarm, Element_DomainIndex dElement_I, void* particle ) {
+	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*) forceTerm;
+
+	return self->RaT;
+}
+
+double _BuoyancyForceTermThermoChem_CalcRaC( void* forceTerm, Swarm* swarm, Element_DomainIndex dElement_I, void* particle ) {
+	BuoyancyForceTermThermoChem*               self               = (BuoyancyForceTermThermoChem*) forceTerm;
+
+	return self->RaC;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/DiffusionSMT.c
--- a/Utils/src/DiffusionSMT.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,301 +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)
-**
-**  This library is free software; you can redistribute it and/or
-**  modify it under the terms of the GNU Lesser General Public
-**  License as published by the Free Software Foundation; either
-**  version 2.1 of the License, or (at your option) any later version.
-**
-**  This library is distributed in the hope that it will be useful,
-**  but WITHOUT ANY WARRANTY; without even the implied warranty of
-**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-**  Lesser General Public License for more details.
-**
-**  You should have received a copy of the GNU Lesser General Public
-**  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: DiffusionSMT.c 964 2007-10-11 08:03:06Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <assert.h>
-#include <string.h>
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-#include "types.h"
-#include "DiffusionSMT.h"
-#include "MaterialSwarmVariable.h"
-
-
-/* Textual name of this class */
-const Type DiffusionSMT_Type = "DiffusionSMT";
-
-
-DiffusionSMT* DiffusionSMT_New( 
-    Name                                                name,
-    FiniteElementContext*				                    context,
-    StiffnessMatrix*                                    stiffnessMatrix,
-    Swarm*                                              integrationSwarm )
-{
-    DiffusionSMT* self = (DiffusionSMT*) _DiffusionSMT_DefaultNew( name );
-
-	self->isConstructed = True;
-	_StiffnessMatrixTerm_Init( self, context, stiffnessMatrix, integrationSwarm, NULL );
-	_DiffusionSMT_Init( self );
-
-	return self;
-}
-
-/* Creation implementation / Virtual constructor */
-DiffusionSMT* _DiffusionSMT_New(  DIFFUSIONSMT_DEFARGS  )
-{
-    DiffusionSMT* self;
-	
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(DiffusionSMT) );
-    self = (DiffusionSMT*) _StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
-	
-    /* Virtual info */
-	
-    return self;
-}
-
-void _DiffusionSMT_Init( void* matrixTerm ) {
-	DiffusionSMT* self;
-
-	self = (DiffusionSMT*)matrixTerm;
-}
-
-void _DiffusionSMT_Delete( void* matrixTerm ) {
-    DiffusionSMT* self = (DiffusionSMT*)matrixTerm;
-    Index ii;
-
-    for(ii = 0; ii < self->materialSwarmCount; ii++)
-	Stg_Class_Delete( self->diffusionSwarmVariables[ii] );
-
-    _StiffnessMatrixTerm_Delete( self );
-}
-
-void _DiffusionSMT_Print( void* matrixTerm, Stream* stream ) {
-    DiffusionSMT* self = (DiffusionSMT*)matrixTerm;
-	
-    _StiffnessMatrixTerm_Print( self, stream );
-
-    /* General info */
-}
-
-void* _DiffusionSMT_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(DiffusionSMT);
-	Type                                                         type = DiffusionSMT_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _DiffusionSMT_Delete;
-	Stg_Class_PrintFunction*                                   _print = _DiffusionSMT_Print;
-	Stg_Class_CopyFunction*                                     _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _DiffusionSMT_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _DiffusionSMT_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _DiffusionSMT_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _DiffusionSMT_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _DiffusionSMT_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _DiffusionSMT_Destroy;
-	StiffnessMatrixTerm_AssembleElementFunction*     _assembleElement = _DiffusionSMT_AssembleElement;
-
-	/* 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*)_DiffusionSMT_New(  DIFFUSIONSMT_PASSARGS  );
-}
-
-void _DiffusionSMT_AssignFromXML( void* matrixTerm, Stg_ComponentFactory* cf, void* data ) {
-    DiffusionSMT*            self             = (DiffusionSMT*)matrixTerm;
-    PICelleratorContext*     context	      = (PICelleratorContext*)self->context;
-
-    /* Construct Parent */
-    _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
-
-    _DiffusionSMT_Init( self );
-
-    assert( Stg_CheckType( context, PICelleratorContext ) );
-    self->materials_Register = context->materials_Register;
-}
-
-void _DiffusionSMT_Build( void* matrixTerm, void* data ) {
-    DiffusionSMT*             self             = (DiffusionSMT*)matrixTerm;
-    AbstractContext*                 context;
-    Stg_ComponentFactory*            cf=NULL;
-    Materials_Register*              materials_Register = self->materials_Register;
-    IntegrationPointsSwarm*          swarm = (IntegrationPointsSwarm*)self->integrationSwarm;
-    MaterialPointsSwarm**            materialSwarms;
-    DiffusionSMT_MaterialExt*   materialExt;
-    char*                            name;
-    Material*                        material;
-    Index ii;
-
-    _StiffnessMatrixTerm_Build( self, data );
-
-    /* Get Component Factory if we can */
-    if ( Stg_Class_IsInstance( data, AbstractContext_Type ) ) {
-	context = (AbstractContext*) data;
-	cf = context->CF;
-    }
-
-    /* Sort out material extension stuff */
-    self->materialExtHandle = Materials_Register_AddMaterialExtension(
-	self->materials_Register, 
-	self->type, 
-	sizeof(DiffusionSMT_MaterialExt));
-
-    for ( ii = 0 ; ii < Materials_Register_GetCount( materials_Register ) ; ii++) {
-	material = Materials_Register_GetByIndex( materials_Register, ii );
-	materialExt = (DiffusionSMT_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material,
-                                                                           self->materialExtHandle );
-
-	if ( cf ) {
-	    materialExt->diffusion = Stg_ComponentFactory_GetDouble( cf, material->name, (Dictionary_Entry_Key)"diffusivity", 0.0  );
-	}
-	else {
-	    materialExt->diffusion = Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"diffusivity", 0.0  );
-	}
-    }
-
-    /* Create Swarm Variables of each material swarm this ip swarm is mapped against */
-    materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms(
-	swarm->mapper, &(self->materialSwarmCount) );
-    self->diffusionSwarmVariables = Memory_Alloc_Array(
-	MaterialSwarmVariable*, self->materialSwarmCount, "DiffusionVariables");
-
-    for ( ii = 0; ii < self->materialSwarmCount; ++ii ) {
-	name = Stg_Object_AppendSuffix( materialSwarms[ii], (Name)"diffusivity"  );
-	self->diffusionSwarmVariables[ii] = MaterialSwarmVariable_New( 
-	    name, 
-	    (AbstractContext*) self->context, 
-	    materialSwarms[ii], 
-	    1, 
-	    self->materials_Register, 
-	    self->materialExtHandle, 
-	    GetOffsetOfMember( *materialExt, diffusion ) );
-	Memory_Free( name );
-	
-	/* Build new Swarm Variables */
-	Stg_Component_Build( self->diffusionSwarmVariables[ii], data, False );
-    }
-}
-
-void _DiffusionSMT_Initialise( void* matrixTerm, void* data ) {
-    DiffusionSMT*             self             = (DiffusionSMT*)matrixTerm;
-    Index ii;
-
-    _StiffnessMatrixTerm_Initialise( self, data );
-
-    for ( ii = 0; ii < self->materialSwarmCount; ++ii )
-	Stg_Component_Initialise( self->diffusionSwarmVariables[ii], data, False );
-}
-
-void _DiffusionSMT_Execute( void* matrixTerm, void* data ) {
-    _StiffnessMatrixTerm_Execute( matrixTerm, data );
-}
-
-void _DiffusionSMT_Destroy( void* matrixTerm, void* data ) {
-    DiffusionSMT*             self             = (DiffusionSMT*)matrixTerm;
-    Index ii;
-    _StiffnessMatrixTerm_Destroy( matrixTerm, data );
-    for ( ii = 0; ii < self->materialSwarmCount; ++ii )
-      Stg_Component_Destroy( self->diffusionSwarmVariables[ii], data, False );
-}
-
-
-void _DiffusionSMT_AssembleElement( 
-    void*                                              matrixTerm,
-    StiffnessMatrix*                                   stiffnessMatrix, 
-    Element_LocalIndex                                 lElement_I, 
-    SystemLinearEquations*                             sle,
-    FiniteElementContext*                              context,
-    double**                                           elStiffMat ) 
-{
-    DiffusionSMT*       self         = Stg_CheckType( matrixTerm, DiffusionSMT );
-    Swarm*                              swarm        = self->integrationSwarm;
-    FeVariable*                         variable1    = stiffnessMatrix->rowVariable;
-    Dimension_Index                     dim          = stiffnessMatrix->dim;
-    IntegrationPoint*                   currIntegrationPoint;
-    double*                             xi;
-    double                              weight;
-    Particle_InCellIndex                cParticle_I, cellParticleCount;
-    Index                               nodesPerEl;
-    Index                               i,j;
-    Dimension_Index                     dim_I;
-    double**                            GNx;
-    double                              detJac;
-	
-    Cell_Index                          cell_I;
-    ElementType*                        elementType;
-    DiffusionSMT_MaterialExt*   materialExt;
-    Material*                        material;
-	
-    /* Set the element type */
-    elementType = FeMesh_GetElementType( variable1->feMesh, lElement_I );
-    nodesPerEl = elementType->nodeCount;
-	
-    /* allocate */
-    GNx = Memory_Alloc_2DArray( double, dim, nodesPerEl, (Name)"GNx"  );
-	
-    cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
-    cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
-
-    /* Slap the laplacian together */
-    for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
-		
-	currIntegrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt(
-	    swarm, cell_I, cParticle_I );
-
-	material = IntegrationPointsSwarm_GetMaterialOn(
-	    (IntegrationPointsSwarm*) swarm, currIntegrationPoint );
-	materialExt = (DiffusionSMT_MaterialExt*)ExtensionManager_Get(material->extensionMgr, material, self->materialExtHandle );
-
-	xi = currIntegrationPoint->xi;
-	weight = currIntegrationPoint->weight;
-		
-	ElementType_ShapeFunctionsGlobalDerivs( 
-	    elementType,
-	    variable1->feMesh, lElement_I,
-	    xi, dim, &detJac, GNx );
-
-	for( i=0; i<nodesPerEl; i++ ) {
-	    for( j=0; j<nodesPerEl; j++ ) {
-		for ( dim_I = 0; dim_I < dim ; dim_I++ ) { 
-		    elStiffMat[i][j] += 
-			materialExt->diffusion * detJac * weight * 
-			GNx[dim_I][i] * GNx[dim_I][j];
-		}
-	    }
-	}
-    }
-	
-    Memory_Free(GNx); 
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/DiffusionSMT.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/DiffusionSMT.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,301 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: DiffusionSMT.c 964 2007-10-11 08:03:06Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <assert.h>
+#include <string.h>
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+#include "types.h"
+#include "DiffusionSMT.h"
+#include "MaterialSwarmVariable.h"
+
+
+/* Textual name of this class */
+const Type DiffusionSMT_Type = "DiffusionSMT";
+
+
+DiffusionSMT* DiffusionSMT_New( 
+    Name                                                name,
+    FiniteElementContext*				                    context,
+    StiffnessMatrix*                                    stiffnessMatrix,
+    Swarm*                                              integrationSwarm )
+{
+    DiffusionSMT* self = (DiffusionSMT*) _DiffusionSMT_DefaultNew( name );
+
+	self->isConstructed = True;
+	_StiffnessMatrixTerm_Init( self, context, stiffnessMatrix, integrationSwarm, NULL );
+	_DiffusionSMT_Init( self );
+
+	return self;
+}
+
+/* Creation implementation / Virtual constructor */
+DiffusionSMT* _DiffusionSMT_New(  DIFFUSIONSMT_DEFARGS  )
+{
+    DiffusionSMT* self;
+	
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(DiffusionSMT) );
+    self = (DiffusionSMT*) _StiffnessMatrixTerm_New(  STIFFNESSMATRIXTERM_PASSARGS  );
+	
+    /* Virtual info */
+	
+    return self;
+}
+
+void _DiffusionSMT_Init( void* matrixTerm ) {
+	DiffusionSMT* self;
+
+	self = (DiffusionSMT*)matrixTerm;
+}
+
+void _DiffusionSMT_Delete( void* matrixTerm ) {
+    DiffusionSMT* self = (DiffusionSMT*)matrixTerm;
+    Index ii;
+
+    for(ii = 0; ii < self->materialSwarmCount; ii++)
+	Stg_Class_Delete( self->diffusionSwarmVariables[ii] );
+
+    _StiffnessMatrixTerm_Delete( self );
+}
+
+void _DiffusionSMT_Print( void* matrixTerm, Stream* stream ) {
+    DiffusionSMT* self = (DiffusionSMT*)matrixTerm;
+	
+    _StiffnessMatrixTerm_Print( self, stream );
+
+    /* General info */
+}
+
+void* _DiffusionSMT_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(DiffusionSMT);
+	Type                                                         type = DiffusionSMT_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _DiffusionSMT_Delete;
+	Stg_Class_PrintFunction*                                   _print = _DiffusionSMT_Print;
+	Stg_Class_CopyFunction*                                     _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _DiffusionSMT_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _DiffusionSMT_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _DiffusionSMT_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _DiffusionSMT_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _DiffusionSMT_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _DiffusionSMT_Destroy;
+	StiffnessMatrixTerm_AssembleElementFunction*     _assembleElement = _DiffusionSMT_AssembleElement;
+
+	/* 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*)_DiffusionSMT_New(  DIFFUSIONSMT_PASSARGS  );
+}
+
+void _DiffusionSMT_AssignFromXML( void* matrixTerm, Stg_ComponentFactory* cf, void* data ) {
+    DiffusionSMT*            self             = (DiffusionSMT*)matrixTerm;
+    PICelleratorContext*     context	      = (PICelleratorContext*)self->context;
+
+    /* Construct Parent */
+    _StiffnessMatrixTerm_AssignFromXML( self, cf, data );
+
+    _DiffusionSMT_Init( self );
+
+    assert( Stg_CheckType( context, PICelleratorContext ) );
+    self->materials_Register = context->materials_Register;
+}
+
+void _DiffusionSMT_Build( void* matrixTerm, void* data ) {
+    DiffusionSMT*             self             = (DiffusionSMT*)matrixTerm;
+    AbstractContext*                 context;
+    Stg_ComponentFactory*            cf=NULL;
+    Materials_Register*              materials_Register = self->materials_Register;
+    IntegrationPointsSwarm*          swarm = (IntegrationPointsSwarm*)self->integrationSwarm;
+    MaterialPointsSwarm**            materialSwarms;
+    DiffusionSMT_MaterialExt*   materialExt;
+    char*                            name;
+    Material*                        material;
+    Index ii;
+
+    _StiffnessMatrixTerm_Build( self, data );
+
+    /* Get Component Factory if we can */
+    if ( Stg_Class_IsInstance( data, AbstractContext_Type ) ) {
+	context = (AbstractContext*) data;
+	cf = context->CF;
+    }
+
+    /* Sort out material extension stuff */
+    self->materialExtHandle = Materials_Register_AddMaterialExtension(
+	self->materials_Register, 
+	self->type, 
+	sizeof(DiffusionSMT_MaterialExt));
+
+    for ( ii = 0 ; ii < Materials_Register_GetCount( materials_Register ) ; ii++) {
+	material = Materials_Register_GetByIndex( materials_Register, ii );
+	materialExt = (DiffusionSMT_MaterialExt*)ExtensionManager_GetFunc( material->extensionMgr, material,
+                                                                           self->materialExtHandle );
+
+	if ( cf ) {
+	    materialExt->diffusion = Stg_ComponentFactory_GetDouble( cf, material->name, (Dictionary_Entry_Key)"diffusivity", 0.0  );
+	}
+	else {
+	    materialExt->diffusion = Dictionary_GetDouble_WithDefault( material->dictionary, (Dictionary_Entry_Key)"diffusivity", 0.0  );
+	}
+    }
+
+    /* Create Swarm Variables of each material swarm this ip swarm is mapped against */
+    materialSwarms = IntegrationPointMapper_GetMaterialPointsSwarms(
+	swarm->mapper, &(self->materialSwarmCount) );
+    self->diffusionSwarmVariables = Memory_Alloc_Array(
+	MaterialSwarmVariable*, self->materialSwarmCount, "DiffusionVariables");
+
+    for ( ii = 0; ii < self->materialSwarmCount; ++ii ) {
+	name = Stg_Object_AppendSuffix( materialSwarms[ii], (Name)"diffusivity"  );
+	self->diffusionSwarmVariables[ii] = MaterialSwarmVariable_New( 
+	    name, 
+	    (AbstractContext*) self->context, 
+	    materialSwarms[ii], 
+	    1, 
+	    self->materials_Register, 
+	    self->materialExtHandle, 
+	    GetOffsetOfMember( *materialExt, diffusion ) );
+	Memory_Free( name );
+	
+	/* Build new Swarm Variables */
+	Stg_Component_Build( self->diffusionSwarmVariables[ii], data, False );
+    }
+}
+
+void _DiffusionSMT_Initialise( void* matrixTerm, void* data ) {
+    DiffusionSMT*             self             = (DiffusionSMT*)matrixTerm;
+    Index ii;
+
+    _StiffnessMatrixTerm_Initialise( self, data );
+
+    for ( ii = 0; ii < self->materialSwarmCount; ++ii )
+	Stg_Component_Initialise( self->diffusionSwarmVariables[ii], data, False );
+}
+
+void _DiffusionSMT_Execute( void* matrixTerm, void* data ) {
+    _StiffnessMatrixTerm_Execute( matrixTerm, data );
+}
+
+void _DiffusionSMT_Destroy( void* matrixTerm, void* data ) {
+    DiffusionSMT*             self             = (DiffusionSMT*)matrixTerm;
+    Index ii;
+    _StiffnessMatrixTerm_Destroy( matrixTerm, data );
+    for ( ii = 0; ii < self->materialSwarmCount; ++ii )
+      Stg_Component_Destroy( self->diffusionSwarmVariables[ii], data, False );
+}
+
+
+void _DiffusionSMT_AssembleElement( 
+    void*                                              matrixTerm,
+    StiffnessMatrix*                                   stiffnessMatrix, 
+    Element_LocalIndex                                 lElement_I, 
+    SystemLinearEquations*                             sle,
+    FiniteElementContext*                              context,
+    double**                                           elStiffMat ) 
+{
+    DiffusionSMT*       self         = Stg_CheckType( matrixTerm, DiffusionSMT );
+    Swarm*                              swarm        = self->integrationSwarm;
+    FeVariable*                         variable1    = stiffnessMatrix->rowVariable;
+    Dimension_Index                     dim          = stiffnessMatrix->dim;
+    IntegrationPoint*                   currIntegrationPoint;
+    double*                             xi;
+    double                              weight;
+    Particle_InCellIndex                cParticle_I, cellParticleCount;
+    Index                               nodesPerEl;
+    Index                               i,j;
+    Dimension_Index                     dim_I;
+    double**                            GNx;
+    double                              detJac;
+	
+    Cell_Index                          cell_I;
+    ElementType*                        elementType;
+    DiffusionSMT_MaterialExt*   materialExt;
+    Material*                        material;
+	
+    /* Set the element type */
+    elementType = FeMesh_GetElementType( variable1->feMesh, lElement_I );
+    nodesPerEl = elementType->nodeCount;
+	
+    /* allocate */
+    GNx = Memory_Alloc_2DArray( double, dim, nodesPerEl, (Name)"GNx"  );
+	
+    cell_I = CellLayout_MapElementIdToCellId( swarm->cellLayout, lElement_I );
+    cellParticleCount = swarm->cellParticleCountTbl[ cell_I ];
+
+    /* Slap the laplacian together */
+    for( cParticle_I = 0 ; cParticle_I < cellParticleCount ; cParticle_I++ ) {
+		
+	currIntegrationPoint = (IntegrationPoint*)Swarm_ParticleInCellAt(
+	    swarm, cell_I, cParticle_I );
+
+	material = IntegrationPointsSwarm_GetMaterialOn(
+	    (IntegrationPointsSwarm*) swarm, currIntegrationPoint );
+	materialExt = (DiffusionSMT_MaterialExt*)ExtensionManager_Get(material->extensionMgr, material, self->materialExtHandle );
+
+	xi = currIntegrationPoint->xi;
+	weight = currIntegrationPoint->weight;
+		
+	ElementType_ShapeFunctionsGlobalDerivs( 
+	    elementType,
+	    variable1->feMesh, lElement_I,
+	    xi, dim, &detJac, GNx );
+
+	for( i=0; i<nodesPerEl; i++ ) {
+	    for( j=0; j<nodesPerEl; j++ ) {
+		for ( dim_I = 0; dim_I < dim ; dim_I++ ) { 
+		    elStiffMat[i][j] += 
+			materialExt->diffusion * detJac * weight * 
+			GNx[dim_I][i] * GNx[dim_I][j];
+		}
+	    }
+	}
+    }
+	
+    Memory_Free(GNx); 
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/Finalise.c
--- a/Utils/src/Finalise.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-
-
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool PICellerator_Utils_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Finalise.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,61 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+
+
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool PICellerator_Utils_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/HydrostaticTerm.c
--- a/Utils/src/HydrostaticTerm.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,435 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: /cig/src/PICellerator/Utils/src/HydrostaticTerm.c 2420 2008-12-12T20:12:30.951338Z boo  $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-#include "types.h"
-#include "HydrostaticTerm.h"
-#include "MaterialSwarmVariable.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type HydrostaticTerm_Type = "HydrostaticTerm";
-
-HydrostaticTerm* HydrostaticTerm_New(Name name,
-                                     double upper_density,
-                                     double upper_alpha,
-                                     double lower_density,
-                                     double lower_alpha,
-                                     double height,
-                                     double material_boundary,
-                                     double T_0,
-                                     double T_max,
-                                     double T_max_depth,
-                                     double linear_coefficient,
-                                     double exponential_coefficient1,
-                                     double exponential_coefficient2,
-                                     double gravity,
-                                     double v,
-                                     double width,
-                                     AbstractContext *context)
-{
-	HydrostaticTerm* self = (HydrostaticTerm*) _HydrostaticTerm_DefaultNew( name );
-
-	HydrostaticTerm_InitAll(self,
-                                upper_density,
-                                upper_alpha,
-                                lower_density,
-                                lower_alpha,
-                                height,
-                                material_boundary,
-                                T_0,
-                                T_max,
-                                T_max_depth,
-                                linear_coefficient,
-                                exponential_coefficient1,
-                                exponential_coefficient2,
-                                gravity,
-                                v,
-                                width,
-                                context);
-	return self;
-}
-
-/* Creation implementation / Virtual constructor */
-HydrostaticTerm* _HydrostaticTerm_New( HYDROSTATICTERM_DEFARGS )
-{
-  HydrostaticTerm* self;
-  
-  /* Allocate memory */
-  assert( _sizeOfSelf >= sizeof(HydrostaticTerm) );
-  self = (HydrostaticTerm*)_Stg_Component_New(STG_COMPONENT_PASSARGS);
-
-  return self;
-}
-
-void _HydrostaticTerm_Init(HydrostaticTerm* self,
-                           double upper_density,
-                           double upper_alpha,
-                           double lower_density,
-                           double lower_alpha,
-                           double height,
-                           double material_boundary,
-                           double T_0,
-                           double T_max,
-                           double T_max_depth,
-                           double linear_coefficient,
-                           double exponential_coefficient1,
-                           double exponential_coefficient2,
-                           double gravity,
-                           double v,
-                           double width,
-                           AbstractContext *context)
-{
-  self->isConstructed    = True;
-
-  self->upper_density=upper_density;
-  self->upper_alpha=upper_alpha;
-  self->lower_density=lower_density;
-  self->lower_alpha=lower_alpha;
-  self->height=height;
-  self->material_boundary=material_boundary;
-  self->T_0=T_0;
-  self->T_max=T_max;
-  self->T_max_depth=T_max_depth;
-  self->linear_coefficient=linear_coefficient;
-  self->exponential_coefficient1=exponential_coefficient1;
-  self->exponential_coefficient2=exponential_coefficient2;
-  self->gravity=gravity;
-  self->v=v;
-  self->width=width;
-  self->context=context;
-}
-
-void HydrostaticTerm_InitAll(void* forceTerm,
-                             double upper_density,
-                             double upper_alpha,
-                             double lower_density,
-                             double lower_alpha,
-                             double height,
-                             double material_boundary,
-                             double T_0,
-                             double T_max,
-                             double T_max_depth,
-                             double linear_coefficient,
-                             double exponential_coefficient1,
-                             double exponential_coefficient2,
-                             double gravity,
-                             double v,
-                             double width,
-                             AbstractContext *context)
-{
-  HydrostaticTerm* self = (HydrostaticTerm*) forceTerm;
-  _HydrostaticTerm_Init( self,
-                         upper_density,
-                         upper_alpha,
-                         lower_density,
-                         lower_alpha,
-                         height,
-                         material_boundary,
-                         T_0,
-                         T_max,
-                         T_max_depth,
-                         linear_coefficient,
-                         exponential_coefficient1,
-                         exponential_coefficient2,
-                         gravity,
-                         v,
-                         width,
-                         context);
-}
-
-void _HydrostaticTerm_Delete( void* forceTerm ) {
-}
-
-void _HydrostaticTerm_Print( void* forceTerm, Stream* stream ) {
-}
-
-void* _HydrostaticTerm_DefaultNew( Name name ) {
-	SizeT                                                 _sizeOfSelf = sizeof(HydrostaticTerm);
-	Type                                                         type = HydrostaticTerm_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _HydrostaticTerm_Delete;
-	Stg_Class_PrintFunction*                                   _print = _HydrostaticTerm_Print;
-	Stg_Class_CopyFunction*                                     _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _HydrostaticTerm_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _HydrostaticTerm_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _HydrostaticTerm_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _HydrostaticTerm_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _HydrostaticTerm_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _HydrostaticTerm_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*)_HydrostaticTerm_New( HYDROSTATICTERM_PASSARGS);
-}
-
-void _HydrostaticTerm_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf,
-                                 void* data ) {
-  HydrostaticTerm* self = (HydrostaticTerm*)forceTerm;
-  double upper_density,upper_alpha,lower_density,lower_alpha,height,
-    material_boundary,T_0,T_max,T_max_depth,linear_coefficient,
-    exponential_coefficient1,
-    exponential_coefficient2,gravity,v,width;
-  AbstractContext *context;
-
-  /* Construct Parent */
-  Stg_Component_AssignFromXML( self, cf, data, False );
-
-  context = Stg_ComponentFactory_ConstructByName( cf, "context", AbstractContext, True, data );
-
-  upper_density=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"upperDensity",0.0);
-  upper_alpha=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"upperAlpha",0.0);
-  lower_density=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"lowerDensity",0.0);
-  lower_alpha=Stg_ComponentFactory_GetDouble(cf,self->name,"lowerAlpha",0.0);
-  height=Stg_ComponentFactory_GetDouble(cf,self->name,"height",0.0);
-  material_boundary=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"materialBoundary",0.0);
-  T_0=Stg_ComponentFactory_GetDouble(cf,self->name,"T_0",0.0);
-  T_max=Stg_ComponentFactory_GetDouble(cf,self->name,"T_max",0.0);
-  T_max_depth=Stg_ComponentFactory_GetDouble(cf,self->name,"T_max_depth",0.0);
-  linear_coefficient=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"linearCoefficient",0.0);
-  exponential_coefficient1=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"exponentialCoefficient1",0.0);
-  exponential_coefficient2=
-    Stg_ComponentFactory_GetDouble(cf,self->name,"exponentialCoefficient2",0.0);
-  gravity=Stg_ComponentFactory_GetDouble(cf,self->name,"gravity",0.0);
-
-  v=Stg_ComponentFactory_GetDouble(cf,self->name,"expansionVelocity",0.0);
-  width=Stg_ComponentFactory_GetDouble(cf,self->name,"width",0.0);
-
-  _HydrostaticTerm_Init( self, upper_density,
-                         upper_alpha,
-                         lower_density,
-                         lower_alpha,
-                         height,
-                         material_boundary,
-                         T_0,
-                         T_max,
-                         T_max_depth,
-                         linear_coefficient,
-                         exponential_coefficient1,
-                         exponential_coefficient2,
-                         gravity,
-                         v,
-                         width,
-                         context);
-}
-
-void _HydrostaticTerm_Build( void* forceTerm, void* data ) {
-}
-
-void _HydrostaticTerm_Initialise( void* forceTerm, void* data ) {
-}
-
-void _HydrostaticTerm_Execute( void* forceTerm, void* data ) {
-}
-
-void _HydrostaticTerm_Destroy( void* forceTerm, void* data ) {
-}
-
-void HydrostaticTerm_Current_Heights(void* forceTerm, double *current_height,
-                                     double *current_boundary)
-{
-  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
-  double current_thickness;
-  double t=self->context->currentTime;
-
-  if(self->v!=0)
-    {
-      current_thickness=(self->height - self->material_boundary)
-        *self->width / (self->width + self->v * t);
-      *current_boundary=self->material_boundary
-        + (self->upper_density / self->lower_density)
-        * (self->height - self->material_boundary - current_thickness);
-    }
-  else
-    {
-      current_thickness=self->height - self->material_boundary;
-      *current_boundary=self->material_boundary;
-    }
-  *current_height=current_thickness + *current_boundary;
-}
-
-double HydrostaticTerm_Temperature(void* forceTerm, Coord coord)
-{
-  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
-  double h=self->height-coord[1];
-  double T;
-
-  if(h<0)
-    {
-      T=self->T_0;
-    }
-  else if(self->T_max_depth!=0 && h>self->T_max_depth)
-    {
-      T=self->T_max;
-    }
-  else
-    {
-      T=self->T_0 + self->linear_coefficient*h
-        + self->exponential_coefficient1
-        *(1-exp(-self->exponential_coefficient2*h));
-    }
-  return T;
-}
-
-double HydrostaticTerm_Density( void* forceTerm, Coord coord)
-{
-  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
-  double T, density, alpha;
-  double current_height, current_boundary;
-
-  HydrostaticTerm_Current_Heights(self,&current_height,&current_boundary);
-
-  /* First, get the temperature */
-  T=HydrostaticTerm_Temperature(forceTerm, coord);
-
-  /* Then, get the density */
-  if(coord[1]>current_height)
-    {
-      density=alpha=0;
-    }
-  else if(coord[1]>current_boundary)
-    {
-      density=self->upper_density;;
-      alpha=self->upper_alpha;
-    }
-  else
-    {
-      density=self->lower_density;
-      alpha=self->lower_alpha;
-    }
-
-  return density*(1-alpha*T);
-}
-
-double HydrostaticTerm_Pressure_Analytic(double density, double gravity,
-                                         double h, double alpha,
-                                         double T_0, double A,
-                                         double B, double C)
-{
-  if(C==0)
-    return density*gravity*h*(1-alpha*(T_0 + A*h/2));
-  else
-    return density*gravity*h*(1-alpha*(T_0 + A*h/2 + B*(1+(exp(-C*h)-1)/(C*h))));
-}
-
-double HydrostaticTerm_Pressure( void* forceTerm, Coord coord)
-{
-  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
-  double h=self->height-coord[1];
-  double p;
-
-  if(coord[1]>=self->height)
-    {
-      p=0;
-    }
-  else if(coord[1]>self->material_boundary)
-    {
-      p=HydrostaticTerm_Pressure_Analytic(self->upper_density, self->gravity, h,
-                                          self->upper_alpha,
-                                          self->T_0,
-                                          self->linear_coefficient,
-                                          self->exponential_coefficient1,
-                                          self->exponential_coefficient2);
-    }
-  else
-    {
-      p=HydrostaticTerm_Pressure_Analytic(self->upper_density,
-                                          self->gravity,
-                                          self->height-self->material_boundary,
-                                          self->upper_alpha,
-                                          self->T_0,
-                                          self->linear_coefficient,
-                                          self->exponential_coefficient1,
-                                          self->exponential_coefficient2)
-        - HydrostaticTerm_Pressure_Analytic(self->lower_density, self->gravity,
-                                            self->height-self->material_boundary,
-                                            self->lower_alpha,
-                                            self->T_0,
-                                            self->linear_coefficient,
-                                            self->exponential_coefficient1,
-                                            self->exponential_coefficient2);
-      /* Add in the contribution from where the temperature is constant */
-      if(self->T_max_depth!=0 && h>self->T_max_depth)
-        {
-          p+=self->lower_density*self->gravity*(h-self->T_max_depth)
-            *(1-self->lower_alpha*self->T_max);
-          h=self->T_max_depth;
-        }
-      /* Add in the last part of the analytic term.  Note that h may
-         have been adjusted to T_max_depth */
-      p+=HydrostaticTerm_Pressure_Analytic(self->lower_density, self->gravity,
-                                           h,
-                                           self->lower_alpha,
-                                           self->T_0,
-                                           self->linear_coefficient,
-                                           self->exponential_coefficient1,
-                                           self->exponential_coefficient2);
-    }
-  return p;
-}
-
-double HydrostaticTerm_Pressure_Bottom( void* forceTerm)
-{
-  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
-  Coord coord;
-
-  coord[1]=self->height;
-  return HydrostaticTerm_Pressure(self,coord);
-}
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/HydrostaticTerm.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/HydrostaticTerm.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,435 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: /cig/src/PICellerator/Utils/src/HydrostaticTerm.c 2420 2008-12-12T20:12:30.951338Z boo  $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+#include "types.h"
+#include "HydrostaticTerm.h"
+#include "MaterialSwarmVariable.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type HydrostaticTerm_Type = "HydrostaticTerm";
+
+HydrostaticTerm* HydrostaticTerm_New(Name name,
+                                     double upper_density,
+                                     double upper_alpha,
+                                     double lower_density,
+                                     double lower_alpha,
+                                     double height,
+                                     double material_boundary,
+                                     double T_0,
+                                     double T_max,
+                                     double T_max_depth,
+                                     double linear_coefficient,
+                                     double exponential_coefficient1,
+                                     double exponential_coefficient2,
+                                     double gravity,
+                                     double v,
+                                     double width,
+                                     AbstractContext *context)
+{
+	HydrostaticTerm* self = (HydrostaticTerm*) _HydrostaticTerm_DefaultNew( name );
+
+	HydrostaticTerm_InitAll(self,
+                                upper_density,
+                                upper_alpha,
+                                lower_density,
+                                lower_alpha,
+                                height,
+                                material_boundary,
+                                T_0,
+                                T_max,
+                                T_max_depth,
+                                linear_coefficient,
+                                exponential_coefficient1,
+                                exponential_coefficient2,
+                                gravity,
+                                v,
+                                width,
+                                context);
+	return self;
+}
+
+/* Creation implementation / Virtual constructor */
+HydrostaticTerm* _HydrostaticTerm_New( HYDROSTATICTERM_DEFARGS )
+{
+  HydrostaticTerm* self;
+  
+  /* Allocate memory */
+  assert( _sizeOfSelf >= sizeof(HydrostaticTerm) );
+  self = (HydrostaticTerm*)_Stg_Component_New(STG_COMPONENT_PASSARGS);
+
+  return self;
+}
+
+void _HydrostaticTerm_Init(HydrostaticTerm* self,
+                           double upper_density,
+                           double upper_alpha,
+                           double lower_density,
+                           double lower_alpha,
+                           double height,
+                           double material_boundary,
+                           double T_0,
+                           double T_max,
+                           double T_max_depth,
+                           double linear_coefficient,
+                           double exponential_coefficient1,
+                           double exponential_coefficient2,
+                           double gravity,
+                           double v,
+                           double width,
+                           AbstractContext *context)
+{
+  self->isConstructed    = True;
+
+  self->upper_density=upper_density;
+  self->upper_alpha=upper_alpha;
+  self->lower_density=lower_density;
+  self->lower_alpha=lower_alpha;
+  self->height=height;
+  self->material_boundary=material_boundary;
+  self->T_0=T_0;
+  self->T_max=T_max;
+  self->T_max_depth=T_max_depth;
+  self->linear_coefficient=linear_coefficient;
+  self->exponential_coefficient1=exponential_coefficient1;
+  self->exponential_coefficient2=exponential_coefficient2;
+  self->gravity=gravity;
+  self->v=v;
+  self->width=width;
+  self->context=context;
+}
+
+void HydrostaticTerm_InitAll(void* forceTerm,
+                             double upper_density,
+                             double upper_alpha,
+                             double lower_density,
+                             double lower_alpha,
+                             double height,
+                             double material_boundary,
+                             double T_0,
+                             double T_max,
+                             double T_max_depth,
+                             double linear_coefficient,
+                             double exponential_coefficient1,
+                             double exponential_coefficient2,
+                             double gravity,
+                             double v,
+                             double width,
+                             AbstractContext *context)
+{
+  HydrostaticTerm* self = (HydrostaticTerm*) forceTerm;
+  _HydrostaticTerm_Init( self,
+                         upper_density,
+                         upper_alpha,
+                         lower_density,
+                         lower_alpha,
+                         height,
+                         material_boundary,
+                         T_0,
+                         T_max,
+                         T_max_depth,
+                         linear_coefficient,
+                         exponential_coefficient1,
+                         exponential_coefficient2,
+                         gravity,
+                         v,
+                         width,
+                         context);
+}
+
+void _HydrostaticTerm_Delete( void* forceTerm ) {
+}
+
+void _HydrostaticTerm_Print( void* forceTerm, Stream* stream ) {
+}
+
+void* _HydrostaticTerm_DefaultNew( Name name ) {
+	SizeT                                                 _sizeOfSelf = sizeof(HydrostaticTerm);
+	Type                                                         type = HydrostaticTerm_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _HydrostaticTerm_Delete;
+	Stg_Class_PrintFunction*                                   _print = _HydrostaticTerm_Print;
+	Stg_Class_CopyFunction*                                     _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _HydrostaticTerm_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _HydrostaticTerm_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _HydrostaticTerm_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _HydrostaticTerm_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _HydrostaticTerm_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _HydrostaticTerm_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*)_HydrostaticTerm_New( HYDROSTATICTERM_PASSARGS);
+}
+
+void _HydrostaticTerm_AssignFromXML( void* forceTerm, Stg_ComponentFactory* cf,
+                                 void* data ) {
+  HydrostaticTerm* self = (HydrostaticTerm*)forceTerm;
+  double upper_density,upper_alpha,lower_density,lower_alpha,height,
+    material_boundary,T_0,T_max,T_max_depth,linear_coefficient,
+    exponential_coefficient1,
+    exponential_coefficient2,gravity,v,width;
+  AbstractContext *context;
+
+  /* Construct Parent */
+  Stg_Component_AssignFromXML( self, cf, data, False );
+
+  context = Stg_ComponentFactory_ConstructByName( cf, "context", AbstractContext, True, data );
+
+  upper_density=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"upperDensity",0.0);
+  upper_alpha=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"upperAlpha",0.0);
+  lower_density=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"lowerDensity",0.0);
+  lower_alpha=Stg_ComponentFactory_GetDouble(cf,self->name,"lowerAlpha",0.0);
+  height=Stg_ComponentFactory_GetDouble(cf,self->name,"height",0.0);
+  material_boundary=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"materialBoundary",0.0);
+  T_0=Stg_ComponentFactory_GetDouble(cf,self->name,"T_0",0.0);
+  T_max=Stg_ComponentFactory_GetDouble(cf,self->name,"T_max",0.0);
+  T_max_depth=Stg_ComponentFactory_GetDouble(cf,self->name,"T_max_depth",0.0);
+  linear_coefficient=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"linearCoefficient",0.0);
+  exponential_coefficient1=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"exponentialCoefficient1",0.0);
+  exponential_coefficient2=
+    Stg_ComponentFactory_GetDouble(cf,self->name,"exponentialCoefficient2",0.0);
+  gravity=Stg_ComponentFactory_GetDouble(cf,self->name,"gravity",0.0);
+
+  v=Stg_ComponentFactory_GetDouble(cf,self->name,"expansionVelocity",0.0);
+  width=Stg_ComponentFactory_GetDouble(cf,self->name,"width",0.0);
+
+  _HydrostaticTerm_Init( self, upper_density,
+                         upper_alpha,
+                         lower_density,
+                         lower_alpha,
+                         height,
+                         material_boundary,
+                         T_0,
+                         T_max,
+                         T_max_depth,
+                         linear_coefficient,
+                         exponential_coefficient1,
+                         exponential_coefficient2,
+                         gravity,
+                         v,
+                         width,
+                         context);
+}
+
+void _HydrostaticTerm_Build( void* forceTerm, void* data ) {
+}
+
+void _HydrostaticTerm_Initialise( void* forceTerm, void* data ) {
+}
+
+void _HydrostaticTerm_Execute( void* forceTerm, void* data ) {
+}
+
+void _HydrostaticTerm_Destroy( void* forceTerm, void* data ) {
+}
+
+void HydrostaticTerm_Current_Heights(void* forceTerm, double *current_height,
+                                     double *current_boundary)
+{
+  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
+  double current_thickness;
+  double t=self->context->currentTime;
+
+  if(self->v!=0)
+    {
+      current_thickness=(self->height - self->material_boundary)
+        *self->width / (self->width + self->v * t);
+      *current_boundary=self->material_boundary
+        + (self->upper_density / self->lower_density)
+        * (self->height - self->material_boundary - current_thickness);
+    }
+  else
+    {
+      current_thickness=self->height - self->material_boundary;
+      *current_boundary=self->material_boundary;
+    }
+  *current_height=current_thickness + *current_boundary;
+}
+
+double HydrostaticTerm_Temperature(void* forceTerm, Coord coord)
+{
+  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
+  double h=self->height-coord[1];
+  double T;
+
+  if(h<0)
+    {
+      T=self->T_0;
+    }
+  else if(self->T_max_depth!=0 && h>self->T_max_depth)
+    {
+      T=self->T_max;
+    }
+  else
+    {
+      T=self->T_0 + self->linear_coefficient*h
+        + self->exponential_coefficient1
+        *(1-exp(-self->exponential_coefficient2*h));
+    }
+  return T;
+}
+
+double HydrostaticTerm_Density( void* forceTerm, Coord coord)
+{
+  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
+  double T, density, alpha;
+  double current_height, current_boundary;
+
+  HydrostaticTerm_Current_Heights(self,&current_height,&current_boundary);
+
+  /* First, get the temperature */
+  T=HydrostaticTerm_Temperature(forceTerm, coord);
+
+  /* Then, get the density */
+  if(coord[1]>current_height)
+    {
+      density=alpha=0;
+    }
+  else if(coord[1]>current_boundary)
+    {
+      density=self->upper_density;;
+      alpha=self->upper_alpha;
+    }
+  else
+    {
+      density=self->lower_density;
+      alpha=self->lower_alpha;
+    }
+
+  return density*(1-alpha*T);
+}
+
+double HydrostaticTerm_Pressure_Analytic(double density, double gravity,
+                                         double h, double alpha,
+                                         double T_0, double A,
+                                         double B, double C)
+{
+  if(C==0)
+    return density*gravity*h*(1-alpha*(T_0 + A*h/2));
+  else
+    return density*gravity*h*(1-alpha*(T_0 + A*h/2 + B*(1+(exp(-C*h)-1)/(C*h))));
+}
+
+double HydrostaticTerm_Pressure( void* forceTerm, Coord coord)
+{
+  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
+  double h=self->height-coord[1];
+  double p;
+
+  if(coord[1]>=self->height)
+    {
+      p=0;
+    }
+  else if(coord[1]>self->material_boundary)
+    {
+      p=HydrostaticTerm_Pressure_Analytic(self->upper_density, self->gravity, h,
+                                          self->upper_alpha,
+                                          self->T_0,
+                                          self->linear_coefficient,
+                                          self->exponential_coefficient1,
+                                          self->exponential_coefficient2);
+    }
+  else
+    {
+      p=HydrostaticTerm_Pressure_Analytic(self->upper_density,
+                                          self->gravity,
+                                          self->height-self->material_boundary,
+                                          self->upper_alpha,
+                                          self->T_0,
+                                          self->linear_coefficient,
+                                          self->exponential_coefficient1,
+                                          self->exponential_coefficient2)
+        - HydrostaticTerm_Pressure_Analytic(self->lower_density, self->gravity,
+                                            self->height-self->material_boundary,
+                                            self->lower_alpha,
+                                            self->T_0,
+                                            self->linear_coefficient,
+                                            self->exponential_coefficient1,
+                                            self->exponential_coefficient2);
+      /* Add in the contribution from where the temperature is constant */
+      if(self->T_max_depth!=0 && h>self->T_max_depth)
+        {
+          p+=self->lower_density*self->gravity*(h-self->T_max_depth)
+            *(1-self->lower_alpha*self->T_max);
+          h=self->T_max_depth;
+        }
+      /* Add in the last part of the analytic term.  Note that h may
+         have been adjusted to T_max_depth */
+      p+=HydrostaticTerm_Pressure_Analytic(self->lower_density, self->gravity,
+                                           h,
+                                           self->lower_alpha,
+                                           self->T_0,
+                                           self->linear_coefficient,
+                                           self->exponential_coefficient1,
+                                           self->exponential_coefficient2);
+    }
+  return p;
+}
+
+double HydrostaticTerm_Pressure_Bottom( void* forceTerm)
+{
+  HydrostaticTerm *self=(HydrostaticTerm *)forceTerm;
+  Coord coord;
+
+  coord[1]=self->height;
+  return HydrostaticTerm_Pressure(self,coord);
+}
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/Init.c
--- a/Utils/src/Init.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-#include "Utils.h"
-#include <stdio.h>
-
-Bool PICellerator_Utils_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, "Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-        Stg_ComponentRegister_Add( componentsRegister, PCDVC_Type, "0", _PCDVC_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, BuoyancyForceTerm_Type, (Name)"0", _BuoyancyForceTerm_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, BuoyancyForceTermThermoChem_Type, (Name)"0", _BuoyancyForceTermThermoChem_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, DiffusionSMT_Type, (Name)"0", _DiffusionSMT_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, HydrostaticTerm_Type, (Name)"0", _HydrostaticTerm_DefaultNew );
-
-	RegisterParent( BuoyancyForceTerm_Type,     ForceTerm_Type );
-	RegisterParent( BuoyancyForceTermThermoChem_Type,     ForceTerm_Type );
-	RegisterParent( DiffusionSMT_Type,     StiffnessMatrixTerm_Type );
-	RegisterParent( MaterialSwarmVariable_Type, SwarmVariable_Type );
-	RegisterParent( PCDVC_Type,                 DVCWeights_Type );
-	RegisterParent( HydrostaticTerm_Type,       Stg_Component_Type );
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/Init.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,76 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+#include "Utils.h"
+#include <stdio.h>
+
+Bool PICellerator_Utils_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, "Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+        Stg_ComponentRegister_Add( componentsRegister, PCDVC_Type, "0", _PCDVC_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, BuoyancyForceTerm_Type, (Name)"0", _BuoyancyForceTerm_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, BuoyancyForceTermThermoChem_Type, (Name)"0", _BuoyancyForceTermThermoChem_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, DiffusionSMT_Type, (Name)"0", _DiffusionSMT_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, HydrostaticTerm_Type, (Name)"0", _HydrostaticTerm_DefaultNew );
+
+	RegisterParent( BuoyancyForceTerm_Type,     ForceTerm_Type );
+	RegisterParent( BuoyancyForceTermThermoChem_Type,     ForceTerm_Type );
+	RegisterParent( DiffusionSMT_Type,     StiffnessMatrixTerm_Type );
+	RegisterParent( MaterialSwarmVariable_Type, SwarmVariable_Type );
+	RegisterParent( PCDVC_Type,                 DVCWeights_Type );
+	RegisterParent( HydrostaticTerm_Type,       Stg_Component_Type );
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/MaterialSwarmVariable.c
--- a/Utils/src/MaterialSwarmVariable.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,208 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MaterialSwarmVariable.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-#include "types.h"
-#include "MaterialSwarmVariable.h"
-
-#include <assert.h>
-#include <string.h>
-
-/* Textual name of this class */
-const Type MaterialSwarmVariable_Type = "MaterialSwarmVariable";
-
-MaterialSwarmVariable* MaterialSwarmVariable_New( 
-	Name						name,
-	AbstractContext*		context,
-	MaterialPointsSwarm*	swarm,
-	Index						dofCount,
-	Materials_Register*	materials_Register,
-	ExtensionInfo_Index	materialExtensionHandle,
-	SizeT						offset )
-{
-	MaterialSwarmVariable* self = (MaterialSwarmVariable*) _MaterialSwarmVariable_DefaultNew( name );
-
-	self->isConstructed = True;
-	_SwarmVariable_Init( (SwarmVariable*)self, context, (Swarm*)swarm, NULL, dofCount );
-	_MaterialSwarmVariable_Init( self, materials_Register, materialExtensionHandle, offset );
-
-	return self;
-}
-
-void* _MaterialSwarmVariable_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(MaterialSwarmVariable);
-	Type                                                         type = MaterialSwarmVariable_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _MaterialSwarmVariable_Delete;
-	Stg_Class_PrintFunction*                                   _print = _MaterialSwarmVariable_Print;
-	Stg_Class_CopyFunction*                                     _copy = NULL;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _MaterialSwarmVariable_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _MaterialSwarmVariable_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _MaterialSwarmVariable_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _MaterialSwarmVariable_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _MaterialSwarmVariable_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _MaterialSwarmVariable_Destroy;
-	AllocationType                                 nameAllocationType = NON_GLOBAL;
-	SwarmVariable_ValueAtFunction*                           _valueAt = _MaterialSwarmVariable_ValueAt;
-	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _MaterialSwarmVariable_GetMinGlobalMagnitude;
-	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _MaterialSwarmVariable_GetMaxGlobalMagnitude;
-
-	return (void*)_MaterialSwarmVariable_New(  MATERIALSWARMVARIABLE_PASSARGS  );
-}
-
-/* Creation implementation / Virtual constructor */
-MaterialSwarmVariable* _MaterialSwarmVariable_New(  MATERIALSWARMVARIABLE_DEFARGS  ) {
-	MaterialSwarmVariable* self;
-	
-	/* Allocate memory */
-	assert( _sizeOfSelf >= sizeof(MaterialSwarmVariable) );
-	self = (MaterialSwarmVariable*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
-	
-	/* Virtual info */
-	
-	return self;
-}
-
-void _MaterialSwarmVariable_Init(
-	void*						swarmVariable,
-	Materials_Register*	materials_Register,
-	ExtensionInfo_Index	materialExtensionHandle,
-	SizeT						offset )
-{
-	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
-
-	self->materials_Register        = materials_Register;
-	self->materialExtensionHandle   = materialExtensionHandle;
-	self->offset                    = offset;
-   /* variable does not store data, so is not checkpointed */
-   self->isCheckpointedAndReloaded = False;
-}
-
-void _MaterialSwarmVariable_Delete( void* swarmVariable ) {
-	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
-
-	_SwarmVariable_Delete( self );
-}
-
-void _MaterialSwarmVariable_Print( void* swarmVariable, Stream* stream ) {
-	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
-	
-	_SwarmVariable_Print( self, stream );
-
-	/* General info */
-	Journal_PrintPointer( stream, self->materials_Register );
-	Journal_PrintValue( stream, self->materialExtensionHandle );
-	Journal_PrintValue( stream, self->offset );
-}
-
-void _MaterialSwarmVariable_AssignFromXML( void* swarmVariable, Stg_ComponentFactory* cf, void* data ) {
-	MaterialSwarmVariable*	self = (MaterialSwarmVariable*)swarmVariable;
-	Materials_Register*		materials_Register;
-	PICelleratorContext*		context = (PICelleratorContext*)self->context;
-
-	/* Construct Parent */
-	_SwarmVariable_AssignFromXML( self, cf, data );
-
-	assert( Stg_CheckType( context, PICelleratorContext ) );
-	materials_Register = context->materials_Register;
-	assert( materials_Register );
-
-	abort( );
-	_MaterialSwarmVariable_Init( self, materials_Register, 0, 0 );
-}
-
-void _MaterialSwarmVariable_Build( void* swarmVariable, void* data ) {
-	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
-
-	_SwarmVariable_Build( self, data );
-}
-
-void _MaterialSwarmVariable_Initialise( void* swarmVariable, void* data ) {
-	_SwarmVariable_Initialise( swarmVariable, data );
-}
-
-void _MaterialSwarmVariable_Execute( void* swarmVariable, void* data ) {
-	_SwarmVariable_Execute( swarmVariable, data );
-}
-
-void _MaterialSwarmVariable_Destroy( void* swarmVariable, void* data ) {
-	MaterialSwarmVariable*  self = (MaterialSwarmVariable*) swarmVariable;
-
-	_SwarmVariable_Destroy( self, data );
-}
-
-void _MaterialSwarmVariable_ValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
-	MaterialSwarmVariable*  self = (MaterialSwarmVariable*) swarmVariable;
-	MaterialPointsSwarm*    swarm = (MaterialPointsSwarm*)self->swarm;
-	Material*               material;
-	ArithPointer            materialExt;
-
-	/* Get Material */
-	material = MaterialPointsSwarm_GetMaterialAt( swarm, lParticle_I );
-
-	/* Get Material Extension */
-	materialExt = (ArithPointer) ExtensionManager_Get( material->extensionMgr, NULL, self->materialExtensionHandle );
-
-	/* Copy value */
-	memcpy( value, (void*) (materialExt + self->offset), sizeof(double) * self->dofCount );
-}
-
-double _MaterialSwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) {
-	return _SwarmVariable_GetMinGlobalMagnitude( swarmVariable );
-}
-double _MaterialSwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
-	return _SwarmVariable_GetMaxGlobalMagnitude( swarmVariable );
-}
-	
-	
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/MaterialSwarmVariable.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/MaterialSwarmVariable.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,208 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MaterialSwarmVariable.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+#include "types.h"
+#include "MaterialSwarmVariable.h"
+
+#include <assert.h>
+#include <string.h>
+
+/* Textual name of this class */
+const Type MaterialSwarmVariable_Type = "MaterialSwarmVariable";
+
+MaterialSwarmVariable* MaterialSwarmVariable_New( 
+	Name						name,
+	AbstractContext*		context,
+	MaterialPointsSwarm*	swarm,
+	Index						dofCount,
+	Materials_Register*	materials_Register,
+	ExtensionInfo_Index	materialExtensionHandle,
+	SizeT						offset )
+{
+	MaterialSwarmVariable* self = (MaterialSwarmVariable*) _MaterialSwarmVariable_DefaultNew( name );
+
+	self->isConstructed = True;
+	_SwarmVariable_Init( (SwarmVariable*)self, context, (Swarm*)swarm, NULL, dofCount );
+	_MaterialSwarmVariable_Init( self, materials_Register, materialExtensionHandle, offset );
+
+	return self;
+}
+
+void* _MaterialSwarmVariable_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(MaterialSwarmVariable);
+	Type                                                         type = MaterialSwarmVariable_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _MaterialSwarmVariable_Delete;
+	Stg_Class_PrintFunction*                                   _print = _MaterialSwarmVariable_Print;
+	Stg_Class_CopyFunction*                                     _copy = NULL;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _MaterialSwarmVariable_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _MaterialSwarmVariable_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _MaterialSwarmVariable_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _MaterialSwarmVariable_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _MaterialSwarmVariable_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _MaterialSwarmVariable_Destroy;
+	AllocationType                                 nameAllocationType = NON_GLOBAL;
+	SwarmVariable_ValueAtFunction*                           _valueAt = _MaterialSwarmVariable_ValueAt;
+	SwarmVariable_GetGlobalValueFunction*      _getMinGlobalMagnitude = _MaterialSwarmVariable_GetMinGlobalMagnitude;
+	SwarmVariable_GetGlobalValueFunction*      _getMaxGlobalMagnitude = _MaterialSwarmVariable_GetMaxGlobalMagnitude;
+
+	return (void*)_MaterialSwarmVariable_New(  MATERIALSWARMVARIABLE_PASSARGS  );
+}
+
+/* Creation implementation / Virtual constructor */
+MaterialSwarmVariable* _MaterialSwarmVariable_New(  MATERIALSWARMVARIABLE_DEFARGS  ) {
+	MaterialSwarmVariable* self;
+	
+	/* Allocate memory */
+	assert( _sizeOfSelf >= sizeof(MaterialSwarmVariable) );
+	self = (MaterialSwarmVariable*) _SwarmVariable_New(  SWARMVARIABLE_PASSARGS  );
+	
+	/* Virtual info */
+	
+	return self;
+}
+
+void _MaterialSwarmVariable_Init(
+	void*						swarmVariable,
+	Materials_Register*	materials_Register,
+	ExtensionInfo_Index	materialExtensionHandle,
+	SizeT						offset )
+{
+	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
+
+	self->materials_Register        = materials_Register;
+	self->materialExtensionHandle   = materialExtensionHandle;
+	self->offset                    = offset;
+   /* variable does not store data, so is not checkpointed */
+   self->isCheckpointedAndReloaded = False;
+}
+
+void _MaterialSwarmVariable_Delete( void* swarmVariable ) {
+	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
+
+	_SwarmVariable_Delete( self );
+}
+
+void _MaterialSwarmVariable_Print( void* swarmVariable, Stream* stream ) {
+	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
+	
+	_SwarmVariable_Print( self, stream );
+
+	/* General info */
+	Journal_PrintPointer( stream, self->materials_Register );
+	Journal_PrintValue( stream, self->materialExtensionHandle );
+	Journal_PrintValue( stream, self->offset );
+}
+
+void _MaterialSwarmVariable_AssignFromXML( void* swarmVariable, Stg_ComponentFactory* cf, void* data ) {
+	MaterialSwarmVariable*	self = (MaterialSwarmVariable*)swarmVariable;
+	Materials_Register*		materials_Register;
+	PICelleratorContext*		context = (PICelleratorContext*)self->context;
+
+	/* Construct Parent */
+	_SwarmVariable_AssignFromXML( self, cf, data );
+
+	assert( Stg_CheckType( context, PICelleratorContext ) );
+	materials_Register = context->materials_Register;
+	assert( materials_Register );
+
+	abort( );
+	_MaterialSwarmVariable_Init( self, materials_Register, 0, 0 );
+}
+
+void _MaterialSwarmVariable_Build( void* swarmVariable, void* data ) {
+	MaterialSwarmVariable* self = (MaterialSwarmVariable*)swarmVariable;
+
+	_SwarmVariable_Build( self, data );
+}
+
+void _MaterialSwarmVariable_Initialise( void* swarmVariable, void* data ) {
+	_SwarmVariable_Initialise( swarmVariable, data );
+}
+
+void _MaterialSwarmVariable_Execute( void* swarmVariable, void* data ) {
+	_SwarmVariable_Execute( swarmVariable, data );
+}
+
+void _MaterialSwarmVariable_Destroy( void* swarmVariable, void* data ) {
+	MaterialSwarmVariable*  self = (MaterialSwarmVariable*) swarmVariable;
+
+	_SwarmVariable_Destroy( self, data );
+}
+
+void _MaterialSwarmVariable_ValueAt( void* swarmVariable, Particle_Index lParticle_I, double* value ) {
+	MaterialSwarmVariable*  self = (MaterialSwarmVariable*) swarmVariable;
+	MaterialPointsSwarm*    swarm = (MaterialPointsSwarm*)self->swarm;
+	Material*               material;
+	ArithPointer            materialExt;
+
+	/* Get Material */
+	material = MaterialPointsSwarm_GetMaterialAt( swarm, lParticle_I );
+
+	/* Get Material Extension */
+	materialExt = (ArithPointer) ExtensionManager_Get( material->extensionMgr, NULL, self->materialExtensionHandle );
+
+	/* Copy value */
+	memcpy( value, (void*) (materialExt + self->offset), sizeof(double) * self->dofCount );
+}
+
+double _MaterialSwarmVariable_GetMinGlobalMagnitude( void* swarmVariable ) {
+	return _SwarmVariable_GetMinGlobalMagnitude( swarmVariable );
+}
+double _MaterialSwarmVariable_GetMaxGlobalMagnitude( void* swarmVariable ) {
+	return _SwarmVariable_GetMaxGlobalMagnitude( swarmVariable );
+}
+	
+	
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/PCDVC.c
--- a/Utils/src/PCDVC.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1624 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** Copyright (c) 2006, Monash Cluster Computing 
-** All rights reserved.
-** Redistribution and use in source and binary forms, with or without modification,
-** are permitted provided that the following conditions are met:
-**
-** 		* Redistributions of source code must retain the above copyright notice, 
-** 			this list of conditions and the following disclaimer.
-** 		* Redistributions in binary form must reproduce the above copyright 
-**			notice, this list of conditions and the following disclaimer in the 
-**			documentation and/or other materials provided with the distribution.
-** 		* Neither the name of the Monash University nor the names of its contributors 
-**			may be used to endorse or promote products derived from this software 
-**			without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
-** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
-** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
-** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
-** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
-** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
-** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
-** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-**
-** Contact:
-*%		Louis Moresi - Louis.Moresi at sci.monash.edu.au
-*%
-** Author:
-**              Mirko Velic - Mirko.Velic at sci.monash.edu.au
-**              Julian Giordani - julian.giordani at sci.monash.edu.au
-**              Patrick Sunter - patrick at vpac.org
-**          
-**  Assumptions:
-**  	 I am assuming that the xi's (local coords) on the IntegrationPoint particles
-**       are precalculated. i.e. We assume the Coincident mapper is being used.
-**
-**  Notes:
-**         The PCDVC class should really be a class the next level up here.
-**	   We should be able to swap out the WeightsCalculator_CalculateAll function instead of just setting
-**                 a pointer inside that function.
-**
-**         If the function  getIntParticleMaterialRef_PointingToMaterialParticle ever gets called
-**         then someone has messed up the mapping between integration and material points. This function
-**         is potentially slow as it traverses the whole swarm. This should be avoided.
-**
-**         We do not allow particle deletion in interface cells (cells that have more than one type of material
-**         in them). Splitting is optional. This may be inadequate. We may need to do some handling of the neighbours
-**         to interface cells as well, in order to preserve particle density about an interface.
-
-How to use this:
-You may place the following in a top-level xml file to change the parameters:
-This assumes a lower level xml file is not using a weights calculator other than PCDVC.
-	   
-<struct name="weights" mergeType="replace">
-<param name="Type">PCDVC</param>
-<param name="resolutionX">10</param>
-<param name="resolutionY">10</param>
-<param name="resolutionZ">10</param>
-<param name="lowerT">0.25</param>  <!-- lower % threshold volume for deletion of particles. i.e if a particle volume < 0.25% of total then delete it -->
-<param name="upperT">15</param>    <!-- upper % threshold volume for deletion of particles. i.e if a particle volume > 15% of total then split it -->
-<param name="maxDeletions">5</param>
-<param name="maxSplits">10</param>
-<param name="MaterialPointsSwarm">materialSwarm</param>
-</struct>
-<struct name="weights" mergeType="merge">
-<param name="Inflow">True</param>  <!-- switches the Inflow flag on -->
-<param name="Threshold">0.8</param> <!-- Threshold for cell population in an inflow problem: If a cell has less than 80% of its assigned particles then we re-populate -->
-<param name="CentPosRatio">0.01</param> <!-- Threshold for cell population in an inflow problem: If a cell's centroid is more than sqrt(0.01) of the width of an FEM cell away from the particle position then we re-populate -->
-</struct>
-		
-Note that you can use the Inflow flags for non-inflow problems. Might be OK for paranoid people or weird situations.
-There is a slight performance hit having the Inflow flag enabled.
-	    
-This code is a bit messy and needs some tidying up and more comments. But for now, the inflow stuff seems to work OK.
-Tested in 3D with as few as 15 particles per cell for 50 time-steps with an Inflow problem.
-Tested in 2D with as few as 10 particles per cell for 150 time-steps with an Inflow problem.
-
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-/****************************************************************************************************************
-
-  The algorithm here uses the DVCWeights module to compute a discrete voronoi diagram per FEM cell given a set of local
-  particle positions, in 3D and 2D. The volumes of the Voronoi regions are used as integration weights for
-  the integration point swarm and the integration points are the centroids of the same volumes.
-
-  The volumes are also used as criteria for splitting and deleting particles. i.e. lowerT and upperT as percentages.
-
-  The Threshold and CentPosRatio parameters are only used when Inflow is turned on.
-
-  For a description of the Voronoi algorithm, see the article by Velic et.al.
-     "A Fast Robust Algorithm for computing Discrete Voronoi Diagrams in N-dimensions"
-  
-*****************************************************************************************************************/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PopulationControl/PopulationControl.h>
-#include <PICellerator/Weights/Weights.h>
-#include <PICellerator/MaterialPoints/MaterialPoints.h>
-
-//#include <PICellerator/PICellerator.h>
-#include "types.h"
-
-#include "PCDVC.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type PCDVC_Type = "PCDVC";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-PCDVC* PCDVC_New(
-	Name						name,
-	Dimension_Index		dim,
-	int*						res,
- 	MaterialPointsSwarm*	mps,
-	double					upT,
-	double					lowT,
-	int						maxDeletions,
-	int						maxSplits,
-	Bool						splitInInterfaceCells,
- 	Bool						deleteInInterfaceCells,
-	Bool						Inflow,
-	double					CentPosRatio,
-	int						ParticlesPerCell,
-	double					Threshold )
-{
-  PCDVC *self = (PCDVC*)_PCDVC_DefaultNew( name );
-
-    self->isConstructed = True;
-    _WeightsCalculator_Init( self, dim );
-    _DVCWeights_Init( self, res );
-    _PCDVC_Init( self, mps, upT, lowT, maxDeletions, maxSplits, splitInInterfaceCells, deleteInInterfaceCells, Inflow, CentPosRatio, ParticlesPerCell, Threshold );
-
-	return self;
-}
-
-PCDVC* _PCDVC_New(  PCDVC_DEFARGS  ) {
-    PCDVC* self;
-
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(PCDVC) );
-
-    /* Initialise the parent class. Every class has a parent, bar Stg_Component, which needs to be called */
-    self = (PCDVC*)_DVCWeights_New(  DVCWEIGHTS_PASSARGS  );
-
-    /* General info */
-
-    /* Virtual Info */
-
-    return self;
-}
-
-void _PCDVC_Init( void* pcdvc, MaterialPointsSwarm* mps, double upT, double lowT,
-                  int maxDeletions, int maxSplits, Bool splitInInterfaceCells,
-                  Bool deleteInInterfaceCells, Bool Inflow, double CentPosRatio,
-                  int ParticlesPerCell, double Threshold )
-{
-    PCDVC* self = (PCDVC*)pcdvc;
-	
-    self->materialPointsSwarm = mps;
-    self->upperT = upT;
-    self->lowerT = lowT;
-    self->maxDeletions = self->maxDeletions_orig = maxDeletions;
-    self->maxSplits    = self->maxSplits_orig    = maxSplits;
-    self->Inflow       = self->Inflow_orig       = Inflow;
-    self->splitInInterfaceCells = self->splitInInterfaceCells_orig = splitInInterfaceCells;
-    self->deleteInInterfaceCells = self->deleteInInterfaceCells_orig = deleteInInterfaceCells;
-    self->Threshold = Threshold;
-    self->CentPosRatio = CentPosRatio;
-    self->ParticlesPerCell = ParticlesPerCell;
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _PCDVC_Delete( void* pcdvc ) {
-    PCDVC* self = (PCDVC*)pcdvc;
-    /* Delete parent */
-    _DVCWeights_Delete( self );
-}
-
-
-void _PCDVC_Print( void* pcdvc, Stream* stream ) {
-    PCDVC* self = (PCDVC*)pcdvc;
-    /* Print parent */
-    _DVCWeights_Print( self, stream );
-}
-
-
-
-void* _PCDVC_Copy( const void* pcdvc, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    PCDVC*	self = (PCDVC*)pcdvc;
-    PCDVC*	newPCDVC;
-	
-    newPCDVC = (PCDVC*)_DVCWeights_Copy( self, dest, deep, nameExt, ptrMap );
-    return (void*)newPCDVC;
-}
-
-void* _PCDVC_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                                 _sizeOfSelf = sizeof(PCDVC);
-	Type                                                         type = PCDVC_Type;
-	Stg_Class_DeleteFunction*                                 _delete = _PCDVC_Delete;
-	Stg_Class_PrintFunction*                                   _print = _PCDVC_Print;
-	Stg_Class_CopyFunction*                                     _copy = _PCDVC_Copy;
-	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _PCDVC_DefaultNew;
-	Stg_Component_ConstructFunction*                       _construct = _PCDVC_AssignFromXML;
-	Stg_Component_BuildFunction*                               _build = _PCDVC_Build;
-	Stg_Component_InitialiseFunction*                     _initialise = _PCDVC_Initialise;
-	Stg_Component_ExecuteFunction*                           _execute = _PCDVC_Execute;
-	Stg_Component_DestroyFunction*                           _destroy = _PCDVC_Destroy;
-	AllocationType                                 nameAllocationType = NON_GLOBAL;
-	WeightsCalculator_CalculateFunction*                   _calculate = _PCDVC_Calculate;
-
-    return (void*) _PCDVC_New(  PCDVC_PASSARGS  );
-}
-
-
-void _PCDVC_AssignFromXML( void* pcdvc, Stg_ComponentFactory* cf, void *data ) {
-
-    PCDVC*	     self          = (PCDVC*) pcdvc;
-    MaterialPointsSwarm*       materialPointsSwarm;
-    double upT, lowT;
-    int maxD, maxS;
-    Bool splitInInterfaceCells;
-    Bool deleteInInterfaceCells;
-    Bool Inflow;
-    double CentPosRatio;
-    int ParticlesPerCell;
-    double Thresh;
-
-    _DVCWeights_AssignFromXML( self, cf, data );
-
-    materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
-    Stream*  stream = Journal_Register( Info_Type, (Name)materialPointsSwarm->type  );
-	
-
-    stream = Journal_Register( Info_Type, (Name)materialPointsSwarm->type  );
-    upT = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"upperT", 25  );
-    lowT = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"lowerT", 0.6  );
-    maxD = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxDeletions", 2 );
-    maxS = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxSplits", 3 );
-    splitInInterfaceCells  = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"splitInInterfaceCells", False );
-    deleteInInterfaceCells = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"deleteInInterfaceCells", False );
-    Inflow =  Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"Inflow", False );
-    Thresh = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Threshold", 0.8  );
-    //CentPosRatio is ratio of allowable distance of a centroid from generating particle to distance across a FEM cell.
-    // I think the centroid distance idea is not ideal in the end...can create some weirdness...even thought the code "works"
-    // after a while one can get wiggly lines in the cells...the centriods are close to the particles but its all
-    // centred in the FEM cell.
-    CentPosRatio =  Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentPosRatio", 0.01  );
-    // just getting the initial PPC for now...maybe could make this a separate parameter yet if needed.
-    ParticlesPerCell = cf->getRootDictUnsignedInt( cf, "particlesPerCell", 25);
-    if(upT < lowT){
-        lowT = 0.6;
-        upT = 25;
-        Journal_Printf( stream,"On Proc %d: In func %s(): WARNING!! lowT and upT have been reset to some more reasonable values. (lowT = 0.6, upT = 25) now!",materialPointsSwarm->myRank, __func__);
-    }
-
-    _PCDVC_Init( self, materialPointsSwarm,  upT, lowT, maxD, maxS, splitInInterfaceCells,
-                 deleteInInterfaceCells, Inflow, CentPosRatio, ParticlesPerCell, Thresh );
-}
-
-void _PCDVC_Build( void* pcdvc, void* data ) {
-    PCDVC*	self = (PCDVC*)pcdvc;
-    _DVCWeights_Build( self, data );
-    Stg_Component_Build( self->materialPointsSwarm, data, False );
-}
-void _PCDVC_Destroy( void* pcdvc, void* data ) {
-    PCDVC*	self = (PCDVC*)pcdvc;
-    _DVCWeights_Destroy( self, data );
-    Stg_Component_Destroy( self->materialPointsSwarm, data, False );
-}
-void _PCDVC_Initialise( void* pcdvc, void* data ) {
-    PCDVC*	self = (PCDVC*)pcdvc;
-    /** for interpolation restart, we need to set these values high to ensure correct population of */
-    /** integration point swarms                                                                    */
-    /** these parameters will be reset to correct values after first timestep                       */
-    if ( (True == self->context->loadFromCheckPoint) && (True == self->context->interpolateRestart) ){
-        self->maxDeletions           = 999999;
-        self->maxSplits              = 999999;
-        self->Inflow                 = True;
-        self->splitInInterfaceCells  = True;
-        self->deleteInInterfaceCells = True;
-    }
-    Stg_Component_Initialise( self->materialPointsSwarm, data, False );
-    _DVCWeights_Initialise( self, data );
-}
-void _PCDVC_Execute( void* pcdvc, void* data ) {
-    PCDVC*	self = (PCDVC*)pcdvc;
-    _DVCWeights_Execute( self, data );
-}
-
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-/* this function loops over the intSwarm in order to find the MaterialPointRef for the integration point particle
-   that points to the matLastParticle_IndexOnCPU of a material particle. It is used here in the case that the last integration point
-   particle DOES NOT point to the last material point particle, as it should.
-   If this function is being called ever, then some other module/component somewhere has messed up the mapping between the integration Swarm and the material Swarm*/
-MaterialPointRef* getIntParticleMaterialRef_PointingToMaterialParticle( IntegrationPointsSwarm*  intSwarm, Particle_Index matLastParticle_IndexOnCPU ){
-    IntegrationPoint* intTestParticle;
-    MaterialPointRef*       ref=NULL;
-    Index i;
-    Stream*  stream = Journal_Register( Info_Type, (Name)intSwarm->type  );
-    Journal_Printf( stream,"\n\n\e[31m\nOn Proc %d: In func %s(): WARNING!! If this function is being called, then some other module/component, somewhere, has messed up the mapping between the integration Swarm and the material Swarm\n\n", intSwarm->myRank, __func__);
-    Journal_Printf( stream,"This function is potentially slow. Someone should fix the offending module so that it doesn not mess up the ordering\n\n");
-    Journal_Printf( stream,"\e[0;32m");
-    for(i=0;i<intSwarm->particleLocalCount;i++){
-        intTestParticle =  (IntegrationPoint*)Swarm_ParticleAt( intSwarm, i);
-        ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intTestParticle);
-        if(ref->particle_I == matLastParticle_IndexOnCPU){
-            break;
-        }
-    }
-    return ref;
-}
-/****************************************************************************************************
- This function deletes integration particle number intParticleToRemove_IndexWithinCell in lCell_I
- as well as the corresponding material point.
- It assumes the one to one coincidence mapper is being used. i.e. for every integration point 
- there is one material point and vice versa.
-******************************************************************************************************/
-void deleteIntParticleByIndexWithinCell( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Cell_LocalIndex lCell_I, Particle_Index intParticleToRemove_IndexWithinCell ) {
-    MaterialPointRef*       ref;
-    MaterialPointRef*       refTestLastParticle;
-    MaterialPointRef*       ref_moved_particle;
-    MaterialPointRef*   refToLastMatParticle;
-    int refToLastMatParticleFlag = 0;
-    Particle_Index    intParticleToRemove_IndexOnCPU;/* the particle number within the swarm on the local CPU */
-    Particle_Index    matParticleToRemove_IndexOnCPU;
-    IntegrationPoint* intParticleToRemove;
-    MaterialPoint*    matParticleToRemove;
-    //Particle_Index    intParticleToRemove_IndexWithinCell;/* the number of the particle within the cell */
-    Particle_Index    matParticleToRemove_IndexWithinCell;
-    IntegrationPoint* intSwarmLastParticle; /* The last particle in the swarm on the local CPU */
-    MaterialPoint*    matSwarmLastParticle;
-    Particle_Index    intLastParticle_IndexOnCPU;
-    Particle_Index    matLastParticle_IndexOnCPU;
-    Particle_Index    intLastParticle_IndexWithinCell;
-    Particle_Index    matLastParticle_IndexWithinCell;
-
-    SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
-    SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
-
-
-    intParticleToRemove_IndexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ intParticleToRemove_IndexWithinCell ];
-    intParticleToRemove =  (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intParticleToRemove_IndexOnCPU);
-    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
-    matParticleToRemove_IndexOnCPU = ref->particle_I;
-    matParticleToRemove =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToRemove_IndexOnCPU);
-    matParticleToRemove_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexOnCPU);
-
-    /* The particles are homeless after these function-calls and for this reason alone must be destroyed */
-    Swarm_RemoveParticleFromCell( intSwarm, lCell_I, intParticleToRemove_IndexWithinCell );
-    Swarm_RemoveParticleFromCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell );
-
-    /* Copy over particle to remove with the last particle in the particle array - as long as it isn't the last one  */
-    intLastParticle_IndexOnCPU = intSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
-    matLastParticle_IndexOnCPU = matSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
-
-    /* we are switching places between the particle we are deleting and the last particle in the array
-       then actually deleting the last particle in the array */
-    intSwarmLastParticle = (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intLastParticle_IndexOnCPU );
-    matSwarmLastParticle = (MaterialPoint*)Swarm_ParticleAt( matSwarm, matLastParticle_IndexOnCPU );
-    /* we have the last particles of both swarms now..
-       if the intSwarmLastParticle material ref does NOT point to the matSwarmLastParticle
-       then we might be in trouble...so test for this here */
-    refTestLastParticle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intSwarmLastParticle); /* so we can get the material point */
-    //refToLastMatParticleFlag = 0;
-    if(refTestLastParticle->particle_I != matLastParticle_IndexOnCPU){
-        printf("\e[31mThe last int particle does NOT point to the last mat particle..we need to handle this\n\n");
-        printf("\e[0;32m");
-        refToLastMatParticle = getIntParticleMaterialRef_PointingToMaterialParticle( intSwarm, matLastParticle_IndexOnCPU );
-        refToLastMatParticle->particle_I = matParticleToRemove_IndexOnCPU;
-        refToLastMatParticleFlag = 1;
-        exit(0);
-        /* if the test here is true then that means that some other int particle points to the last material particle
-           and therefore *its* material ref needs to be updated when we move the last material particle.
-           It also means that we do not update the ref for the last int particle as that must be pointing somewhere
-           other than the last material particle and the mat particle that is somewhere else is not being moved.
-        */
-    }
-    if ( intParticleToRemove_IndexOnCPU != intLastParticle_IndexOnCPU ) {                                                                                                                       
-        //printf("Deleting int particle number %d from cell %d local cell particle num = %d\n\n", intParticleToRemove_IndexOnCPU ,lCell_I, intParticleToRemove_IndexWithinCell);                    
-                                                                                                                                                                                                
-        intLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intSwarmLastParticle->owningCell, intLastParticle_IndexOnCPU);                                              
-                                                                                                                                                                                                
-        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
-        memcpy( intParticleToRemove, intSwarmLastParticle, intparticleSize );                                                                                                       
-                                                                                                                                                                                                
-        /* Change value in cell particle table to point to new index in localCPU particle array.                                                                                    
-           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
-           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
-        intSwarm->cellParticleTbl[ intSwarmLastParticle->owningCell ] [intLastParticle_IndexWithinCell ] = intParticleToRemove_IndexOnCPU;
-        if(!refToLastMatParticleFlag){                                                         
-            ref_moved_particle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
-            ref_moved_particle->particle_I = matParticleToRemove_IndexOnCPU;
-        }
-    }                                                                                                                                                                                 
-    intSwarm->particleLocalCount--; 
-    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
-    if ( matParticleToRemove_IndexOnCPU != matLastParticle_IndexOnCPU ) {                                                                                                                       
-        //printf("Deleting mat particle number %d from cell %d local cell particle num = %d\n\n", matParticleToRemove_IndexOnCPU, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell);                    
-                                                                                                                                                                                                
-        matLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matSwarmLastParticle->owningCell, matLastParticle_IndexOnCPU);                                              
-                                                                                                                                                                                                
-        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
-        memcpy( matParticleToRemove, matSwarmLastParticle, matparticleSize );                                                                                                       
-                                                                                                                                                                                                
-        /* Change value in cell particle table to point to new index in localCPU particle array.                                                                                    
-           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
-           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
-        matSwarm->cellParticleTbl[ matSwarmLastParticle->owningCell][matLastParticle_IndexWithinCell ] = matParticleToRemove_IndexOnCPU;                                                          
-                                                                                                                                                                                                
-    }                                                                                                                                                                                 
-    matSwarm->particleLocalCount--; 
-    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
-	      
-}
-/****************************************************************************************************
- This function deletes integration particle number intParticleToRemove_IndexOnCPU
- on integration swarm as well as the corresponding material point.
- It assumes the one to one coincidence mapper is being used. i.e. for every integration point 
- there is one material point and vice versa.
-******************************************************************************************************/
-void deleteIntParticleByIndexOnCPU( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Particle_Index intParticleToRemove_IndexOnCPU ) {
-    MaterialPointRef*       ref;
-    MaterialPointRef*       refTestLastParticle;
-    MaterialPointRef*       ref_moved_particle;
-    MaterialPointRef*   refToLastMatParticle;
-    int refToLastMatParticleFlag = 0;
-    //Particle_Index    intParticleToRemove_IndexOnCPU;/* the particle number within the swarm on the local CPU */
-    Particle_Index    matParticleToRemove_IndexOnCPU;
-    IntegrationPoint* intParticleToRemove;
-    MaterialPoint*    matParticleToRemove;
-    Particle_Index    intParticleToRemove_IndexWithinCell;/* the number of the particle within the cell */
-    Particle_Index    matParticleToRemove_IndexWithinCell;
-    IntegrationPoint* intSwarmLastParticle; /* The last particle in the swarm on the local CPU */
-    MaterialPoint*    matSwarmLastParticle;
-    Particle_Index    intLastParticle_IndexOnCPU;
-    Particle_Index    matLastParticle_IndexOnCPU;
-    Particle_Index    intLastParticle_IndexWithinCell;
-    Particle_Index    matLastParticle_IndexWithinCell;
-    Cell_LocalIndex lCell_I;
-
-
-    SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
-    SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
-
-    //intParticleToRemove_IndexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ intParticleToRemove_IndexWithinCell ];
-    intParticleToRemove =  (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intParticleToRemove_IndexOnCPU);
-
-    intParticleToRemove_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intParticleToRemove->owningCell, intParticleToRemove_IndexOnCPU);
-
-    lCell_I = intParticleToRemove->owningCell;
-
-    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
-    matParticleToRemove_IndexOnCPU = ref->particle_I;
-    matParticleToRemove =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToRemove_IndexOnCPU);
-    matParticleToRemove_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexOnCPU);
-
-    /* The particles are homeless after these function-calls and for this reason alone must be destroyed */
-    Swarm_RemoveParticleFromCell( intSwarm, lCell_I, intParticleToRemove_IndexWithinCell );
-    Swarm_RemoveParticleFromCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell );
-
-    /* Copy over particle to remove with the last particle in the particle array - as long as it isn't the last one  */
-    intLastParticle_IndexOnCPU = intSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
-    matLastParticle_IndexOnCPU = matSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
-
-    /* we are switching places between the particle we are deleting and the last particle in the array
-       then actually deleting the last particle in the array */
-    intSwarmLastParticle = (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intLastParticle_IndexOnCPU );
-    matSwarmLastParticle = (MaterialPoint*)Swarm_ParticleAt( matSwarm, matLastParticle_IndexOnCPU );
-    /* we have the last particles of both swarms now..
-       if the intSwarmLastParticle material ref does NOT point to the matSwarmLastParticle
-       then we might be in trouble...so test for this here */
-    refTestLastParticle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intSwarmLastParticle); /* so we can get the material point */
-    //refToLastMatParticleFlag = 0;
-    if(refTestLastParticle->particle_I != matLastParticle_IndexOnCPU){
-        printf("\e[31mThe last int particle does NOT point to the last mat particle..we need to handle this\n\n");
-        printf("\e[0;32m");
-        refToLastMatParticle = getIntParticleMaterialRef_PointingToMaterialParticle( intSwarm, matLastParticle_IndexOnCPU );
-        refToLastMatParticle->particle_I = matParticleToRemove_IndexOnCPU;
-        refToLastMatParticleFlag = 1;
-        exit(0);
-        /* if the test here is true then that means that some other int particle points to the last material particle
-           and therefore *its* material ref needs to be updated when we move the last material particle.
-           It also means that we do not update the ref for the last int particle as that must be pointing somewhere
-           other than the last material particle and the mat particle that is somewhere else is not being moved.
-        */
-    }
-
-    if ( intParticleToRemove_IndexOnCPU != intLastParticle_IndexOnCPU ) {
-        //printf("Deleting int particle number %d from cell %d local cell particle num = %d\n\n", intParticleToRemove_IndexOnCPU ,lCell_I, intParticleToRemove_IndexWithinCell);
-
-        intLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intSwarmLastParticle->owningCell, intLastParticle_IndexOnCPU);
-      
-        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
-        memcpy( intParticleToRemove, intSwarmLastParticle, intparticleSize );
-
-        /* Change value in cell particle table to point to new index in localCPU particle array.
-           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
-           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
-        intSwarm->cellParticleTbl[ intSwarmLastParticle->owningCell ] [intLastParticle_IndexWithinCell ] = intParticleToRemove_IndexOnCPU;
-        if(!refToLastMatParticleFlag){
-            ref_moved_particle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
-            ref_moved_particle->particle_I = matParticleToRemove_IndexOnCPU;
-        }
-    }
-
-    intSwarm->particleLocalCount--; 
-    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
-    if ( matParticleToRemove_IndexOnCPU != matLastParticle_IndexOnCPU ) {                                                                                                                       
-        //printf("Deleting mat particle number %d from cell %d local cell particle num = %d\n\n", matParticleToRemove_IndexOnCPU, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell);                    
-                                                                                                                                                                                                
-        matLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matSwarmLastParticle->owningCell, matLastParticle_IndexOnCPU);                                              
-                                                                                                                                                                                                
-        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
-        memcpy( matParticleToRemove, matSwarmLastParticle, matparticleSize );                                                                                                       
-                                                                                                                                                                                                
-        /* Change value in cell particle table to point to new index in localCPU particle array.                                                                                    
-           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
-           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
-        matSwarm->cellParticleTbl[ matSwarmLastParticle->owningCell][matLastParticle_IndexWithinCell ] = matParticleToRemove_IndexOnCPU;                                                          
-                                                                                                                                                                                                
-    }                                                                                                                                                                                 
-    matSwarm->particleLocalCount--; 
-    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
-	      
-}
-void splitIntParticleByIndexWithinCell( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Cell_LocalIndex lCell_I, Particle_Index intParticleToSplit_IndexWithinCell, Coord xi ) {
-    MaterialPointRef*       ref;
-    Particle_Index    intNewParticle_IndexOnCPU;/* the particle number within the swarm on the local CPU */
-    Particle_Index    matNewParticle_IndexOnCPU;
-    IntegrationPoint* intNewParticle;
-    MaterialPoint*    matNewParticle;
-    Particle_Index    intNewParticle_IndexWithinCell;/* the number of the particle within the cell */
-    //Particle_Index    matNewParticle_IndexWithinCell;
-    IntegrationPoint* intParticleToSplit;
-    MaterialPoint*    matParticleToSplit;
-    //Particle_Index    intParticleToSplit_IndexWithinCell;
-    //Particle_Index    matParticleToSplit_IndexWithinCell;
-    Particle_Index    matParticleToSplit_IndexOnCPU;
-//      SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
-//      SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
-    Coord                   newCoord;
-//      Coord                   xi;
-
-    FeMesh*     mesh              = (FeMesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
-
-	      
-    //intParticleToSplit_IndexWithinCell = maxI;
-
-    /* Add a new particle to end the end of each swarm */
-    /* this calls Swarm_Realloc -- don't like reallocing every time we create a particle
-       need to do this differently */
-    intNewParticle     = (IntegrationPoint*) Swarm_CreateNewParticle( intSwarm, &intNewParticle_IndexOnCPU );
-    matNewParticle     = (MaterialPoint*) Swarm_CreateNewParticle( matSwarm, &matNewParticle_IndexOnCPU );
-	      
-    /* Copy particle information */
-    intParticleToSplit = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, intParticleToSplit_IndexWithinCell );
-    memcpy( intNewParticle, intParticleToSplit, intSwarm->particleExtensionMgr->finalSize );
-    Swarm_AddParticleToCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU );
-    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intNewParticle); /* so we can set the reference to the material point */
-    ref->particle_I = matNewParticle_IndexOnCPU; /* now the ref for the new int particle points to the new material particle -- the swarm id should be correct because we memcpy'd from the original */
-
-    /* Now get the material point corresponding to the int point being split so that
-       we can copy the material properties to the newly created material particle */
-    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToSplit);
-    matParticleToSplit_IndexOnCPU = ref->particle_I;
-    matParticleToSplit  =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToSplit_IndexOnCPU );
-    memcpy( matNewParticle, matParticleToSplit, matSwarm->particleExtensionMgr->finalSize );
-    Swarm_AddParticleToCell( matSwarm, matNewParticle->owningCell, matNewParticle_IndexOnCPU );
-
-    /* Copy new local position to xi on new int particle */
-    memcpy( intNewParticle->xi, xi, sizeof(Coord) );
-	      
-    /* Get new Global Coordinates from the Local Coordinates */
-    FeMesh_CoordLocalToGlobal( mesh, lCell_I, xi, newCoord );
-
-    /* Copy new global position to coord on new mat particle */
-    memcpy( matNewParticle->coord, newCoord, sizeof(Coord) );
-	      
-    intNewParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU);
-    /*
-      printf("\e[1;33m");
-      printf("Creating int particle number %d from cell %d local within cell particle num = %d\n\n", intNewParticle_IndexOnCPU ,lCell_I, intNewParticle_IndexWithinCell);
-      printf("matSwarm particle count is now : %d\n",matSwarm->cellParticleCountTbl[lCell_I]);
-      printf("intSwarm particle count is now : %d\n",intSwarm->cellParticleCountTbl[lCell_I]);
-      printf("Original Population was %d\n",nump-1);
-      printf("\e[0;32m");
-    */
-
-}
-void splitIntParticleByIndexOnCPU( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Particle_Index intParticleToSplit_IndexOnCPU, Coord xi ) {
-    MaterialPointRef*       ref;
-    Particle_Index    intNewParticle_IndexOnCPU;/* the particle number within the swarm on the local CPU */
-    Particle_Index    matNewParticle_IndexOnCPU;
-    IntegrationPoint* intNewParticle;
-    MaterialPoint*    matNewParticle;
-    Particle_Index    intNewParticle_IndexWithinCell;/* the number of the particle within the cell */
-    //Particle_Index    matNewParticle_IndexWithinCell;
-    IntegrationPoint* intParticleToSplit;
-    MaterialPoint*    matParticleToSplit;
-    Particle_Index    intParticleToSplit_IndexWithinCell;
-    //Particle_Index    matParticleToSplit_IndexWithinCell;
-    Particle_Index    matParticleToSplit_IndexOnCPU;
-//      SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
-//      SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
-    Coord                   newCoord;
-//      Coord                   xi;
-
-    Cell_LocalIndex lCell_I;
-
-    FeMesh*     mesh              = (FeMesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
-
-	      
-    //intParticleToSplit_IndexWithinCell = maxI;
-
-    /* Add a new particle to end the end of each swarm */
-    /* this calls Swarm_Realloc -- don't like reallocing every time we create a particle
-       need to do this differently */
-    intNewParticle     = (IntegrationPoint*) Swarm_CreateNewParticle( intSwarm, &intNewParticle_IndexOnCPU );
-    matNewParticle     = (MaterialPoint*) Swarm_CreateNewParticle( matSwarm, &matNewParticle_IndexOnCPU );
-	      
-
-
-    /* Copy particle information */
-    intParticleToSplit_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intParticleToSplit->owningCell, intParticleToSplit_IndexOnCPU);
-
-    intParticleToSplit = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, intParticleToSplit_IndexWithinCell );
-
-
-    lCell_I = intParticleToSplit->owningCell;
-
-
-    memcpy( intNewParticle, intParticleToSplit, intSwarm->particleExtensionMgr->finalSize );
-    Swarm_AddParticleToCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU );
-    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intNewParticle); /* so we can set the reference to the material point */
-    ref->particle_I = matNewParticle_IndexOnCPU; /* now the ref for the new int particle points to the new material particle -- the swarm id should be correct because we memcpy'd from the original */
-
-    /* Now get the material point corresponding to the int point being split so that
-       we can copy the material properties to the newly created material particle */
-    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToSplit);
-    matParticleToSplit_IndexOnCPU = ref->particle_I;
-    matParticleToSplit  =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToSplit_IndexOnCPU );
-    memcpy( matNewParticle, matParticleToSplit, matSwarm->particleExtensionMgr->finalSize );
-    Swarm_AddParticleToCell( matSwarm, matNewParticle->owningCell, matNewParticle_IndexOnCPU );
-
-    /* Copy new local position to xi on new int particle */
-    memcpy( intNewParticle->xi, xi, sizeof(Coord) );
-	      
-    /* Get new Global Coordinates from the Local Coordinates */
-    FeMesh_CoordLocalToGlobal( mesh, lCell_I, xi, newCoord );
-
-    /* Copy new global position to coord on new mat particle */
-    memcpy( matNewParticle->coord, newCoord, sizeof(Coord) );
-	      
-    intNewParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU);
-    /*
-      printf("\e[1;33m");
-      printf("Creating int particle number %d from cell %d local within cell particle num = %d\n\n", intNewParticle_IndexOnCPU ,lCell_I, intNewParticle_IndexWithinCell);
-      printf("matSwarm particle count is now : %d\n",matSwarm->cellParticleCountTbl[lCell_I]);
-      printf("intSwarm particle count is now : %d\n",intSwarm->cellParticleCountTbl[lCell_I]);
-      printf("Original Population was %d\n",nump-1);
-      printf("\e[0;32m");
-    */
-
-}
-/* sort indexOnCPU in reverse order */
-int compare_indexOnCPU(const void * _particleA, const void * _particleB){
-    struct deleteParticle * particleA = (struct deleteParticle *) _particleA;
-    struct deleteParticle * particleB = (struct deleteParticle *) _particleB;
-      
-    if(particleA->indexOnCPU < particleB->indexOnCPU)
-        return 1;
-    else
-        return -1;
-
-}
-int compare_ints(const void * _A, const void * _B){
-    int *A = (int *) _A;
-    int *B = (int *) _B;
-    if(*A > *B) return 1; else return -1;
-}
-#if 0
-void buildPVCList(int **particleVornoiCellList, struct particle2d *pList, struct cell2d *cells, int *VCsize, double da, int nump, int XY, int dim){
-    int oneOda = (int)(1.0/da + 0.5);
-    int i,j;
-    int *count = (int)malloc(nump*sizeof(int));
-      
-    for(i=0;i<nump;i++){ 
-        count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
-        VCsize[i] = count[i];
-        //countSum += count[i];//for debugging
-        //wSum += pList[i].w;//for debugging
-        particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
-    }
-    for(i=0;i<XY;i++){// traverse the grid
-        /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
-            internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
-        //if(VCsize[cells[i].p] != 0){// in case a particle is unresolved
-        if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
-            particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
-            count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
-            //countSum++;
-        }
-        //}
-    }
-    free(count);
-}
-#endif
-/* Calculate the integration weights for each particle by contructing
-   a voronoi diagram in an element in 3D*/
-void _PCDVC_Calculate3D( void* pcdvc, void* _swarm, Cell_LocalIndex lCell_I ) {
-    PCDVC*             self            = (PCDVC*)  pcdvc;
-    IntegrationPointsSwarm*  intSwarm  = (IntegrationPointsSwarm*) _swarm;
-    MaterialPointsSwarm* matSwarm =	(MaterialPointsSwarm*) self->materialPointsSwarm;
-    /* CoincidentMapper is a special case of the one to one mapper */
-    //CoincidentMapper* mapper  = (CoincidentMapper*)(intSwarm->mapper); /* need the mapper after-all to update the material ref */
-    Particle_InCellIndex         cParticleCount;
-    IntegrationPoint**           particle;
-    static int visited = 0 ;
-    //static int deleted = 0 ;
-    double dx,dy,dz,da;
-    static struct cell *cells;// the connected grid
-    struct particle *pList;// particle List
-    struct chain *bchain;//boundary chain
-    int nump_orig,nump,numx,numy,numz;
-    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
-    double BBXMAX = 1.0;
-    double BBYMIN = -1.0;
-    double BBYMAX = 1.0;
-    double BBZMIN = -1.0;
-    double BBZMAX = 1.0;
-    int i,k;
-
-    /*************************************/
-    /* stuff for particle removal/adding */
-    struct deleteParticle* deleteList;
-    double maxW,minW;
-    int maxI, minI;
-    double lowT = self->lowerT;
-    double upT = self->upperT;
-    int delete_flag, split_flag;
-    Particle_Index  *splitList;
-//	int deleteListStackPtr = -1;/* use a number to tell me how many particles we are going to delete: saves doing it some other less efficient way */
-//	int splitListStackPtr = -1;
-    int maxDeletions = self->maxDeletions;/* hard setting this till I get stuff from xml file */
-    int maxSplits = self->maxSplits;
-    int splitCount;
-    int deleteCount;
-    int Count;
-    int matTypeFirst;
-    int matType;
-    Bool splitInInterfaceCells  = self->splitInInterfaceCells;
-    Bool deleteInInterfaceCells = self->deleteInInterfaceCells;
-    Bool Inflow = self->Inflow;
-    double Thresh = self->Threshold;
-    int ParticlesPerCell = self->ParticlesPerCell;
-    double CentPosRatio = self->CentPosRatio;
-//	SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
-//	SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
-//	Coord                   newCoord;
-    Coord                   xi;
-
-//	FiniteElement_Mesh*     mesh              = (FiniteElement_Mesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
-
-    /* end decs needed for particle control */
-    /*************************************/
-	
-
-
-    numx = self->resX;
-    numy = self->resY;
-    numz = self->resZ;
-
-    nump_orig = nump = cParticleCount = intSwarm->cellParticleCountTbl[lCell_I];
-
-    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"PCDVC" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
-
-    dx = (BBXMAX - BBXMIN)/numx;
-    dy = (BBYMAX - BBYMIN)/numy;
-    dz = (BBZMAX - BBZMIN)/numz;
-    da = dx*dy*dz;
-	
-    // Construct the grid for the Voronoi cells only once.
-    // If we wanted to call this function again during a job with a different resolution
-    // then we should destroy the grid once we have looped through the whole mesh.
-    // I am assuming we are not going to do that for now.
-    // Easy to implement this anyway, if needed.
-    if(!visited){
-        /* The PCDVC class should really be a class the next level up here */
-        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
-           a pointer inside that function */
-        visited++;
-        _DVCWeights_ConstructGrid(&cells,numz,numy,numx,BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);
-    }
-	
-    // init the data structures
-    _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
-    _DVCWeights_ResetGrid(&cells,numz*numy*numx);
-	
-    particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));
-	
-    // initialize the particle positions to be the local coordinates of the material swarm particles
-    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
-    // positions each time step.
-    for(i=0;i<nump;i++){
-	      
-        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
-        pList[i].x = particle[i]->xi[0];
-        pList[i].y = particle[i]->xi[1];
-        pList[i].z = particle[i]->xi[2];
-	      
-    }
-    _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-    _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
-
-    /************************************/
-    /************************************/
-    /*    Start 3D Population Control   */
-    /************************************/
-    /************************************/
-    /* todo: put print statements into Journal statements */
-    /*********************************/
-
-    /** want to do something special for inflow problems **/
-    /** we need to be a lot more aggressive with adding particles in this case **/
-    /************************************/
-    /************************************/
-    /*      Start 3D Inflow Control     */
-    /************************************/
-    /************************************/
-
-    int *VCsize=NULL;
-    int **particleVoronoiCellList=NULL;
-    int *count=NULL; // count of how many cells each particle owns in the Voronoi diagram.
-    int flag =0;
-    double FEMCEllspan = BBXMAX - BBXMIN;
-    double dist=0;
-    if(Inflow){
-        for(i=0;i<nump_orig;i++){
-            dist = (pList[i].cx - pList[i].x)*(pList[i].cx - pList[i].x) + (pList[i].cy - pList[i].y)*(pList[i].cy - pList[i].y) + (pList[i].cz - pList[i].z)*(pList[i].cz - pList[i].z);
-        }
-        if(dist > CentPosRatio*FEMCEllspan){flag = 1;}
-	      
-    }
-    if(Inflow && (  ((1.0*nump_orig)/ParticlesPerCell < Thresh) || flag  ) ){
-        int oneOda = (int)(1.0/da + 0.5);
-        int *VCsize=(int *)malloc(sizeof(int)*nump);
-#if 0
-        double dist;
-        int numberofnewpoints;
-        int newpindex;
-#endif
-        int j;
-        int delNum;
-        VCsize=(int *)malloc(sizeof(int)*nump_orig);
-        count=(int *)malloc(sizeof(int)*nump_orig);
-        splitCount = 0;
-        particleVoronoiCellList = (int **)malloc(nump_orig * sizeof(int *));// [i][j] is jth cell owned by particle i
-        for(i=0;i<nump_orig;i++){ 
-            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
-            VCsize[i] = count[i];
-            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
-        }
-        for(i=0;i<numx*numy*numz;i++){// traverse the grid
-            //count[ cells[i].p ]++;
-            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
-                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
-            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
-                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
-                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
-                //countSum++;
-            }
-        }
-        // we now have a list of cells from the grid belonging to each particle that make up each Voronoi cell in the Voronoi diagram
-        // next lets compare how far our centroids are from the particle positions.
-        // this is my criteria for a voronoi cell having a weird shape...too stretched out for example.
-        // this is exactly what happens in inflow situations.  
-        // Add a random number of new particles...
-        // But Need to add them where they are needed. 
-        for(i=0;i<ParticlesPerCell;i++){
-            j  =  (int) ( numx*numy*numz * (rand() / (RAND_MAX + 1.0)));
-            xi[0] = cells[ j ].x;
-            xi[1] = cells[ j ].y;
-            xi[2] = cells[ j ].z;
-            splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, cells[j].p, xi );
-            nump++; splitCount++;
-        }
-        for(i=0;i<nump_orig;i++){
-            free(particleVoronoiCellList[i]);
-        }
-        free(particleVoronoiCellList);
-        free(VCsize); free(count);
-        //if(splitCount) printf("\n\e[32mnump is now %d splitCount = %d\n",nump,splitCount);
-        delNum = nump - ParticlesPerCell;
-        if(delNum > 5){
-            for(i=0;i<delNum;i++){
-                j =  (int) (nump * (rand() / (RAND_MAX + 1.0)));
-                deleteIntParticleByIndexWithinCell( intSwarm,  matSwarm, lCell_I, j );
-                nump--;
-                splitCount++;
-            }
-        }
-#if 0
-        for(i=0;i<nump;i++){
-            if(0 != VCsize[i]){
-                dist = (pList[i].cx - pList[i].x)*(pList[i].cx - pList[i].x) + (pList[i].cy - pList[i].y)*(pList[i].cy - pList[i].y) + (pList[i].cz - pList[i].z)*(pList[i].cz - pList[i].z);
-                if(dist > CentPosRatio*FEMCEllspan){
-                    // Then populate this Voronoi cell with more particles.
-                    // A working number might be based on the initial population per FEM cell, i.e. restore the density.
-                    // which I can't be bothered trying to figure out how to extract right this minute.
-                    // So, for now, I will just go with say..30? or could pass in via xml?
-                    numberofnewpoints = ParticlesPerCell*pList[i].w/8; // 8 is total volume of a local element.
-                    for(j=0;j<numberofnewpoints;j++){
-                        newpindex = rand()%VCsize[i];
-                        // we going to split particle[i] numberofnewpoints times and each time give the new particle the coordinates
-                        // of the cell we are planting it in.
-                        // it should not matter if we put newly created particles on top of each other accidentally.
-                        xi[0] = cells[ particleVoronoiCellList[i][newpindex] ].x;
-                        xi[1] = cells[ particleVoronoiCellList[i][newpindex] ].y;
-                        xi[2] = cells[ particleVoronoiCellList[i][newpindex] ].z;
-                        nump++;
-                        splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, i, xi );
-                        splitCount++;
-                    }
-                }//if
-            }//if
-        }//for i=0:nump
-#endif
-        if(splitCount){// then redo Voronoi diagram.
-            for(k=0;k<nump_orig;k++){
-                free(bchain[k].new_claimed_cells);
-                free(bchain[k].new_bound_cells);
-            }
-            free(particle);
-            free(bchain);
-            free(pList);
-            if(nump < 3){
-                Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
-            }
-            // init the data structures
-            _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
-	      
-            particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));
-	
-            // re-initialize the particle positions to be the local coordinates of the material swarm particles
-            // could do better here..instead of completely destroying these lists I could append to them I suppose.
-            for(i=0;i<nump;i++){
-		    
-                particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
-                pList[i].x = particle[i]->xi[0];
-                pList[i].y = particle[i]->xi[1];
-                pList[i].z = particle[i]->xi[2];
-		    
-            }
-            _DVCWeights_ResetGrid(&cells,numz*numy*numx);
-            _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-            _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
-
-        }
-        nump_orig = nump;
-    }// if Inflow && ...
-    if(Inflow){
-        int oneOda = (int)(1.0/da + 0.5);
-        //recreate the lists.
-        particleVoronoiCellList = (int **)malloc(nump * sizeof(int *));// [i][j] is jth cell owned by particle i
-        //VCsize = (int*)realloc(VCsize,nump_orig);
-        //count = (int*)realloc(count,nump_orig);
-        VCsize=(int *)malloc(sizeof(int)*nump);
-        count=(int *)malloc(sizeof(int)*nump); 
-	
-        for(i=0;i<nump;i++){ 
-            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
-            VCsize[i] = count[i];
-            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
-        }
-        for(i=0;i<numx*numy*numz;i++){// traverse the grid
-            //count[ cells[i].p ]++;
-            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
-                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
-            //if(VCsize[cells[i].p] != 0){// in case a particle is unresolved
-            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
-                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
-                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
-                //countSum++;
-            }
-            //}
-        }
-    }//if Inflow
-    /**************************************/
-    /**************************************/
-    /*        End 3D Inflow Control       */
-    /**************************************/
-    /**************************************/
-    split_flag = 0;
-    delete_flag = 0;
-//	maxW = 0.0;
-//	minW = 8.0;
-    splitCount = 0;
-    deleteCount = 0;
-    /* shouldn't need maxI and minI now */
-    maxW = upT*8/100.0;
-    minW = lowT*8/100.0;
-    /* check to see if we are in an interface cell.
-       We never want to delete particles in an interface cell */
-    matTypeFirst = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ 0 ]);
-    for(i=0;i<nump;i++){
-        matType = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ i ]);
-        if(matType != matTypeFirst){
-            if(!deleteInInterfaceCells) maxDeletions = 0; /* no deletions in an interface cell */
-            /* this may be inadequate...we may need to do something in the neighbouring cells to interface cells as well */
-            if(!splitInInterfaceCells)  maxSplits    = 0;
-            break;
-        }
-    }
-    /* need a struct for the deletList because we must sort it by indexOnCPU and delete in reverse order
-       so we don't have the potential problem of  deleting a particle from the list that points to the last particle on the swarm */
-    deleteList = (struct deleteParticle*)malloc(nump*sizeof(struct deleteParticle));/* I don't think I am going to let you delete more than half the particles in a given cell */
-    splitList  = (Particle_Index*)malloc(nump*sizeof(Particle_Index));
-    for(i=0;i<nump;i++){
-        if(pList[i].w > maxW){ /* maxW = pList[i].w; maxI = i;*/ splitList[splitCount] = i; splitCount++;}
-        if(pList[i].w < minW){
-            /* minW = pList[i].w; minI = i; */
-            deleteList[deleteCount].indexWithinCell = i;
-            deleteList[deleteCount].indexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ i ];		    
-            deleteCount++;
-        }
-    }
-    /* sort the deleteList by indexOnCPU so we can delete the list in reverse order */
-    qsort(deleteList, (deleteCount), sizeof(struct deleteParticle),compare_indexOnCPU);
-    //deleteCount--; /* is going to be one size too large after the loop */
-    /*
-      for(i=0;i<deleteCount;i++){
-      printf("deleteCount = %d\n",deleteCount);
-      printf("indices are indexWithinCell %d indexOnCPU %d\n",deleteList[i].indexWithinCell,deleteList[i].indexOnCPU);
-      }
-    */
-    if(maxDeletions > nump-4){ maxDeletions = nump/2;}
-
-    /* we now have our lists of particles to delete and split */
-
-//	if(pList[maxI].w > upT*8/100.0){
-    Count = maxSplits > splitCount ? splitCount : maxSplits;
-    for(i=0;i<Count;i++){
-        int j;
-        maxI = splitList[i];
-        if(!Inflow){
-            /* now get local coords from centroid of the cell that particleToSplit lives in */
-            xi[0] = pList[maxI].cx;
-            xi[1] = pList[maxI].cy;
-            xi[2] = pList[maxI].cz;
-        }
-        else{
-            /* lets do something different now..because am getting lines formed on inflow probs */
-            j =  (int) (VCsize[maxI] * (rand() / (RAND_MAX + 1.0)));
-            xi[0] = cells[ particleVoronoiCellList[maxI][j] ].x;
-            xi[1] = cells[ particleVoronoiCellList[maxI][j] ].y;
-            xi[2] = cells[ particleVoronoiCellList[maxI][j] ].z;
-        }
-        split_flag = 1;
-        nump++;
-        splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, maxI, xi );
-    }
-
-    if(Inflow){
-        for(i=0;i<nump_orig;i++){
-            free(particleVoronoiCellList[i]);
-        }
-        free(particleVoronoiCellList);
-        free(VCsize);
-        free(count);
-    }
-    Count = maxDeletions > deleteCount ? deleteCount : maxDeletions;
-    for(i=0;i<Count;i++){
-        minI = deleteList[i].indexOnCPU;
-        deleteIntParticleByIndexOnCPU( intSwarm,  matSwarm, minI );
-        delete_flag = 1;
-        nump--;
-    }
-
-    if(delete_flag || split_flag ){/* then we need to redo the Voronoi diagram */
-        for(k=0;k<nump_orig;k++){
-            free(bchain[k].new_claimed_cells);
-            free(bchain[k].new_bound_cells);
-        }
-        free(particle);
-        free(bchain);
-        free(pList);
-        if(nump < 3){
-            Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
-        }
-        // init the data structures
-        _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
-        //_DVCWeights_ResetGrid(&cells,numz*numy*numx);
-	      
-        particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));
-	
-        // re-initialize the particle positions to be the local coordinates of the material swarm particles
-        for(i=0;i<nump;i++){
-		    
-            particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
-            pList[i].x = particle[i]->xi[0];
-            pList[i].y = particle[i]->xi[1];
-            pList[i].z = particle[i]->xi[2];
-            //pList[i].index = i; // to track which particle numbers we have after sorting this list */
-		    
-        }
-        //printf("Population of matSwarm is %d\n",matSwarm->particleLocalCount);
-        //printf("Population of intSwarm is %d\n",intSwarm->particleLocalCount);
-        _DVCWeights_ResetGrid(&cells,numz*numy*numx);
-        //reset_grid(&cells,numz*numy*numx);/* adding this line fixed memory leak probs */
-        //create_voronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-        //get_centroids( cells, pList,numz,numy,numx,nump,da);
-        _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-        _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
-
-    }/* if delete_flag */
-    /******************************************/
-    /******************************************/
-    /*        End 3D Population Control       */
-    /******************************************/
-    /******************************************/
-
-    // We are setting the integration points to be the centroids of the Voronoi regions here and
-    // the weight is the volume of each Voronoi region.
-    for(i=0;i<nump;i++){
-
-        particle[i]->xi[0] = pList[i].cx;
-        particle[i]->xi[1] = pList[i].cy;
-        particle[i]->xi[2] = pList[i].cz;
-        particle[i]->weight = pList[i].w;
-
-    }	
-    for(k=0;k<nump;k++){
-        free(bchain[k].new_claimed_cells);
-        free(bchain[k].new_bound_cells);
-    }
-    free(particle);
-    free(bchain);
-    free(pList);
-    free(deleteList);
-    free(splitList);
-
-}
-
-/* Calculate the integration weighting for each particle by contructing
-   a voronoi diagram in an element in 2D*/
-void _PCDVC_Calculate2D( void* pcdvc, void* _swarm, Cell_LocalIndex lCell_I ) {
-    PCDVC*             self            = (PCDVC*)  pcdvc;
-    IntegrationPointsSwarm*  intSwarm  = (IntegrationPointsSwarm*) _swarm;
-    MaterialPointsSwarm* matSwarm =	(MaterialPointsSwarm*) self->materialPointsSwarm;
-    /* CoincidentMapper is a special case of the one to one mapper */
-    //CoincidentMapper* mapper  = (CoincidentMapper*)(intSwarm->mapper); /* need the mapper after-all to update the material ref */
-    Particle_InCellIndex         cParticleCount;
-    IntegrationPoint**           particle;
-    static int visited = 0 ;
-    //static int deleted = 0 ;
-
-    double dx,dy,da;
-    static struct cell2d *cells;// the connected grid
-    struct particle2d *pList;// particle List
-    struct chain *bchain;//boundary chain
-    int nump_orig,nump,numx,numy;
-    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
-    double BBXMAX = 1.0;
-    double BBYMIN = -1.0;
-    double BBYMAX = 1.0;
-    int i,k;
-
-    /*************************************/
-    /* stuff for particle removal/adding */
-    double maxW,minW;
-    int maxI, minI;
-    double lowT = self->lowerT;
-    double upT = self->upperT;
-    int delete_flag, split_flag;
-    struct deleteParticle* deleteList;
-    Particle_Index  *splitList;
-    int splitCount;
-    int deleteCount;
-    int maxDeletions = self->maxDeletions;/* hard setting this till I get stuff from xml file */
-    int maxSplits = self->maxSplits;
-    int Count;
-    int matTypeFirst;
-    int matType;
-    Bool splitInInterfaceCells  = self->splitInInterfaceCells;
-    Bool deleteInInterfaceCells = self->deleteInInterfaceCells;
-    Bool Inflow = self->Inflow;
-    double Thresh = self->Threshold;
-    int ParticlesPerCell = self->ParticlesPerCell;
-    double CentPosRatio = self->CentPosRatio;
-    //time_t tm;
-	
-
-//	SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
-//	SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
-
-//	Coord                   newCoord;
-    Coord                   xi;
-
-//	FiniteElement_Mesh*     mesh              = (FiniteElement_Mesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
-
-    /* end decs needed for particle control */
-    /*************************************/
-	
-
-    numx = self->resX;
-    numy = self->resY;
-
-    nump_orig = nump = cParticleCount = intSwarm->cellParticleCountTbl[lCell_I];
-
-    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"PCDVC" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
-
-    dx = (BBXMAX - BBXMIN)/numx;
-    dy = (BBYMAX - BBYMIN)/numy;
-    da = dx*dy;
-	
-    // Construct the grid for the Voronoi cells only once.
-    // If we wanted to call this function again during a job with a different resolution
-    // then we should destroy the grid once we have looped through the whole mesh.
-    // I am assuming we are not going to do that for now.
-    // Easy to implement this anyway, if needed.
-    if(!visited){
-        /* The PCDVC class should really be a class the next level up here */
-        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
-           a pointer inside that function */
-        visited++;
-        _DVCWeights_ConstructGrid2D(&cells,numy,numx,BBXMIN,BBYMIN,BBXMAX,BBYMAX);
-//	      time(&tm);
-//	      srand( (long) tm);
-    }
-	
-	
-    // init the data structures
-    _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);
-    _DVCWeights_ResetGrid2D(&cells,numy*numx);
-	
-    particle = (IntegrationPoint**)malloc((nump)*sizeof(IntegrationPoint*));
-	
-    // initialize the particle positions to be the local coordinates of the material swarm particles
-    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
-    // positions each time step.
-    for(i=0;i<nump;i++){
-	      
-        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
-        pList[i].x = particle[i]->xi[0];
-        pList[i].y = particle[i]->xi[1];
-	      
-    }
-    _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
-    _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
-/*     for(k=0;k<nump;k++){ */
-/* 	  printf("In %s O(%10.7lf %10.7lf) C(%10.7lf %10.7lf) W(%.4lf)\n", __func__, pList[k].x, pList[k].y, pList[k].cx, pList[k].cy, pList[k].w); */
-/*     } */
-      
-    /************************************/
-    /************************************/
-    /*    Start 2D Population Control   */
-    /************************************/
-    /** want to do something special for inflow problems **/
-    /** we need to be a lot more aggressive with adding particles in this case **/
-    /************************************/
-    /************************************/
-    /*      Start 2D Inflow Control     */
-    /************************************/
-    /************************************/
-//	if(0){
-    int *VCsize=NULL;
-    int **particleVoronoiCellList=NULL;
-    int *count=NULL; // count of how many cells each particle owns in the Voronoi diagram.
-    int flag =0;
-    double FEMCEllspan = BBXMAX - BBXMIN;
-    double dist=0;
-    if(Inflow){
-        for(i=0;i<nump_orig;i++){
-            dist = (pList[i].x-pList[i].cx)*(pList[i].x-pList[i].cx)+(pList[i].y-pList[i].cy)*(pList[i].y-pList[i].cy);;
-        }
-        if(dist > CentPosRatio*FEMCEllspan){flag = 1;}
-	      
-    }
-    if(Inflow && (  ((1.0*nump_orig)/ParticlesPerCell < Thresh) || flag  ) ){
-        int oneOda = (int)(1.0/da + 0.5);
-        /*double dist; */
-        /*int numberofnewpoints;*/
-        /*int newpindex;*/
-        int j;
-		  /*int countSum;*/
-        /*double wSum;*/
-        /*int *temparray;*/
-        int delNum;
-        VCsize=(int *)malloc(sizeof(int)*nump_orig);
-        count=(int *)malloc(sizeof(int)*nump_orig);
-        //wSum = 0.0;
-        //countSum = 0;
-        splitCount = 0;
-        particleVoronoiCellList = (int **)malloc(nump_orig * sizeof(int *));// [i][j] is jth cell owned by particle i
-        for(i=0;i<nump_orig;i++){ 
-            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
-            VCsize[i] = count[i];
-            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
-        }
-        for(i=0;i<numx*numy;i++){// traverse the grid
-            //count[ cells[i].p ]++;
-            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
-                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
-            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
-                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
-                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
-                //countSum++;
-            }
-        }
-        //printf("countSum = %d\n",countSum);
-        // we now have a list of cells from the grid belonging to each particle that make up each Voronoi cell in the Voronoi diagram
-        // next lets compare how far our centroids are from the particle positions.
-        // this is my criteria for a voronoi cell having a weird shape...too stretched out for example.
-        // this is exactly what happens in inflow situations.
-        // Add a random number of new particles...
-        // But Need to add them where they are needed.
-        for(i=0;i<ParticlesPerCell;i++){
-            j  =  (int) ( numx*numy * (rand() / (RAND_MAX + 1.0)));
-            xi[0] = cells[ j ].x;
-            xi[1] = cells[ j ].y;
-            splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, cells[j].p, xi );
-            nump++; splitCount++;
-        }
-        for(i=0;i<nump_orig;i++){
-            free(particleVoronoiCellList[i]);
-        }
-        free(particleVoronoiCellList);
-        free(VCsize); free(count);
-        //if(splitCount) printf("\n\e[32mnump is now %d splitCount = %d\n",nump,splitCount);
-        delNum = nump - ParticlesPerCell;
-        if(delNum > 5){
-            for(i=0;i<delNum;i++){
-                j =  (int) (nump * (rand() / (RAND_MAX + 1.0)));
-                deleteIntParticleByIndexWithinCell( intSwarm,  matSwarm, lCell_I, j );
-                nump--;
-                splitCount++;
-            }
-        }
-        //if(splitCount) printf("\e[34mnump is now %d splitCount = %d\n",nump,splitCount);;printf("\e[0;37m");
-        //printf("\n\n");
-        if(splitCount){// then redo Voronoi diagram.
-            for(k=0;k<nump_orig;k++){
-                free(bchain[k].new_claimed_cells);
-                free(bchain[k].new_bound_cells);
-            }
-            free(particle);
-            free(bchain);
-            free(pList);
-            //printf("\e[33mnump is now %d splitCount = %d\n",nump,splitCount);printf("\e[0;37m");
-            if(nump < 3){
-                Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
-            }
-            // init the data structures
-            _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);		    	      
-            particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));	
-            // re-initialize the particle positions to be the local coordinates of the material swarm particles
-            // could do better here..instead of completely destroying these lists I could append to them I suppose.
-            for(i=0;i<nump;i++){		    
-                particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
-                pList[i].x = particle[i]->xi[0];
-                pList[i].y = particle[i]->xi[1];		    
-            }
-            _DVCWeights_ResetGrid2D(&cells,numy*numx);
-            _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
-            _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
-        }
-        nump_orig = nump;
-    }// if Inflow && ...
-    if(Inflow){
-        int oneOda = (int)(1.0/da + 0.5);
-        //int sumc = 0;
-        //int j;
-        //recreate the lists.
-        particleVoronoiCellList = (int **)malloc(nump * sizeof(int *));// [i][j] is jth cell owned by particle i
-        //VCsize = (int*)realloc(VCsize,nump_orig);
-        //count = (int*)realloc(count,nump_orig);
-        VCsize=(int *)malloc(sizeof(int)*nump);
-        count=(int *)malloc(sizeof(int)*nump); 
-	
-        for(i=0;i<nump;i++){ 
-            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
-            VCsize[i] = count[i];
-            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
-        }
-        for(i=0;i<numx*numy;i++){// traverse the grid
-            //count[ cells[i].p ]++;
-            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
-                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
-            //if(VCsize[cells[i].p] != 0){// in case a particle is unresolved
-            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
-                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
-                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
-                //countSum++;
-            }
-            //}
-        }
-        /*
-          for(i=0;i<nump;i++){
-          for(j=0;j<VCsize[i];j++){
-          sumc +=  1;
-          }
-          }
-        */
-        //printf("sumc = %d cell = %d\n",sumc,lCell_I);
-    }//if Inflow
-    /************************************/
-    /************************************/
-    /*        End 2D Inflow Control     */
-    /************************************/
-    /************************************/
-    split_flag = 0;
-    delete_flag = 0;
-    splitCount = 0;
-    deleteCount = 0;
-    /* shouldn't need maxI and minI now */
-    maxW = upT*4/100.0;
-    minW = lowT*4/100.0;
-    /* check to see if we are in an interface cell.
-       We never want to delete particles in an interface cell */
-    matTypeFirst = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ 0 ]);
-    for(i=0;i<nump;i++){
-        matType = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ i ]);
-        if(matType != matTypeFirst){
-            if(!deleteInInterfaceCells) maxDeletions = 0; /* no deletions in an interface cell */
-            /* this may be inadequate...we may need to do something in the neighbouring cells to interface cells as well */
-            if(!splitInInterfaceCells)  maxSplits    = 0;
-            //printf("------- FOUND an Interface Cell!! --------------\n");
-            break;
-        }
-    }
-    /* need a struct for the deletList because we must sort it bu indexOnCPU and delete in reverse order
-       so we don't have the potential problem of  deleting a particle from the list that points to the last particle on the swarm */
-    splitList  = (Particle_Index*)malloc(nump*sizeof(Particle_Index));	
-    deleteList = (struct deleteParticle*)malloc(nump*sizeof(struct deleteParticle));/* I don't think I am going to let you delete more than half the particles in a given cell */	
-    for(i=0;i<nump;i++){
-        if(pList[i].w > maxW){ /* maxW = pList[i].w; maxI = i;*/ splitList[splitCount] = i; splitCount++;}
-        if(pList[i].w < minW){
-            /* minW = pList[i].w; minI = i; */
-            deleteList[deleteCount].indexWithinCell = i;
-            deleteList[deleteCount].indexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ i ];		    
-            deleteCount++;
-        }
-    }
-    /* sort the deleteList by indexOnCPU so we can delete the list in reverse order */
-    qsort(deleteList, (deleteCount), sizeof(struct deleteParticle),compare_indexOnCPU);
-    //deleteCount--; /* is going to be one size too large after the loop */
-    /*
-      for(i=0;i<deleteCount;i++){
-      printf("deleteCount = %d\n",deleteCount);
-      printf("indices are indexWithinCell %d indexOnCPU %d\n",deleteList[i].indexWithinCell,deleteList[i].indexOnCPU);
-      }
-    */
-
-    if(maxDeletions > nump-4){ maxDeletions = Inflow ? nump - 4 : nump/2;}
-
-    /* we now have our lists of particles to delete and split */
-    Count = maxSplits > splitCount ? splitCount : maxSplits;
-    /* lets do something different now..because am getting lines formed on inflow probs */
-    //if(Inflow){ Count = 0;} //turn off ordinary splitting if inflow is on for moment      
-    for(i=0;i<Count;i++){
-        int j;
-        maxI = splitList[i];
-        if(!Inflow){
-            /* now get local coords from centroid of the cell that particleToSplit lives in */
-            xi[0] = pList[maxI].cx;
-            xi[1] = pList[maxI].cy;
-        }
-        else{
-            /* lets do something different now..because am getting lines formed on inflow probs */
-            j =  (int) (VCsize[maxI] * (rand() / (RAND_MAX + 1.0)));
-            xi[0] = cells[ particleVoronoiCellList[maxI][j] ].x;
-            xi[1] = cells[ particleVoronoiCellList[maxI][j] ].y;
-        }     
-        split_flag = 1;
-        nump++;
-        splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, maxI, xi );
-    }
-
-    if(Inflow){
-        for(i=0;i<nump_orig;i++){
-            free(particleVoronoiCellList[i]);
-        }
-        free(particleVoronoiCellList);
-        free(VCsize);
-        free(count);
-    }
-
-    Count = maxDeletions > deleteCount ? deleteCount : maxDeletions;
-    for(i=0;i<Count;i++){
-        minI = deleteList[i].indexOnCPU;
-        deleteIntParticleByIndexOnCPU( intSwarm,  matSwarm, minI );
-        delete_flag = 1;
-        nump--;
-    }
-    //printf("pList[maxI].w = %lf particle num = %d : %d\n", pList[maxI].w, pList[maxI].index,maxI);
-    //printf("pList[minI].w = %lf particle num = %d : %d\n", pList[minI].w, pList[minI].index,minI);
-    if(delete_flag || split_flag ){/* then we need to redo the Voronoi diagram */
-        for(k=0;k<nump_orig;k++){
-            free(bchain[k].new_claimed_cells);
-            free(bchain[k].new_bound_cells);
-        }
-        free(particle);
-        free(bchain);
-        free(pList);
-        if(nump < 3){
-            Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
-        }
-        particle = (IntegrationPoint**)malloc((nump)*sizeof(IntegrationPoint*));
-        // init the data structures
-        _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);
-        // re-initialize the particle positions to be the local coordinates of the material swarm particles
-        for(i=0;i<nump;i++){
-		    
-            particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
-            pList[i].x = particle[i]->xi[0];
-            pList[i].y = particle[i]->xi[1];
-            //pList[i].index = i; // to track which particle numbers we have after sorting this list */
-		    
-        }
-        //printf("Population of matSwarm is %d\n",matSwarm->particleLocalCount);
-        //printf("Population of intSwarm is %d\n",intSwarm->particleLocalCount);
-
-        _DVCWeights_ResetGrid2D(&cells,numy*numx);
-        //reset_grid(&cells,numz*numy*numx);/* adding this line fixed memory leak probs */
-        _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
-        _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
-
-    }/* if delete_flag */
-    /**************************************/
-    /**************************************/
-    /*      End 2D Population Control     */
-    /**************************************/
-    /**************************************/
-
-
-    // We are setting the integration points to be the centroids of the Voronoi regions here and
-    // the weight is the volume of each Voronoi region.
-    for(i=0;i<nump;i++){
-
-        particle[i]->xi[0] = pList[i].cx;
-        particle[i]->xi[1] = pList[i].cy;
-        particle[i]->weight = pList[i].w;
-
-    }	
-    /* for(k=0;k<nump;k++){ */
-/* 	  printf("::In %s O(%10.7lf %10.7lf) C(%10.7lf %10.7lf) W(%.4lf)\n", __func__, pList[k].x, pList[k].y, pList[k].cx, pList[k].cy, pList[k].w); */
-/*     } */
-    for(k=0;k<nump;k++){
-        free(bchain[k].new_claimed_cells);
-        free(bchain[k].new_bound_cells);
-    }
-    free(particle);
-    free(bchain);
-    free(pList);
-    free(deleteList);
-    free(splitList);
-    /*
-      FILE *fp;
-      fp=fopen("nump.txt","a");
-      if(lCell_I< 33){
-      fprintf(fp,"nump = %d cell = %d\n",nump,lCell_I);
-      }
-      fclose(fp);
-    */
-}
-
-void _PCDVC_Calculate( void* pcdvc, void* _swarm, Cell_LocalIndex lCell_I ){
-    Swarm* swarm = (Swarm*) _swarm;
-    Dimension_Index dim = swarm->dim;
-    /* Stream*  stream = Journal_Register( Info_Type, (Name)swarm->type ); */
-    PCDVC*             self            = (PCDVC*)  pcdvc;
-    /* MaterialPointsSwarm* matSwarm =	(MaterialPointsSwarm*) self->materialPointsSwarm; */
-    /* it might be nice to report the total deletions and splits as well as the final population here */
-    /* One could set the parameters to be too aggressive and cause "swarm thrashing" where many particles
-       are being created and destroyed while maintaining some population that it has converged on */
-
-/*
-  if(lCell_I == 0 ){
-  Journal_Printf( stream, "\nOn Proc %d: In func %s(): for swarm \"%s\" Population is %d\n", swarm->myRank, __func__, swarm->name, swarm->particleLocalCount );
-  Journal_Printf( stream, "On Proc %d: In func %s(): for swarm \"%s\" Population is %d\n\n", matSwarm->myRank,__func__, matSwarm->name, matSwarm->particleLocalCount );
-  }      
-*/
-    if(dim == 3)
-        _PCDVC_Calculate3D( pcdvc, _swarm, lCell_I);
-    else
-        _PCDVC_Calculate2D( pcdvc, _swarm, lCell_I);
-
-    /* reset the below parameters incase they were originally set for interpolation restarts */
-    if(lCell_I == swarm->cellLocalCount - 1){
-        self->maxDeletions           = self->maxDeletions_orig;
-        self->maxSplits              = self->maxSplits_orig;
-        self->Inflow                 = self->Inflow_orig;
-        self->splitInInterfaceCells  = self->splitInInterfaceCells_orig;
-        self->deleteInInterfaceCells = self->deleteInInterfaceCells_orig;
-    }
-
-}
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/src/PCDVC.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/src/PCDVC.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,1624 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** Copyright (c) 2006, Monash Cluster Computing 
+** All rights reserved.
+** Redistribution and use in source and binary forms, with or without modification,
+** are permitted provided that the following conditions are met:
+**
+** 		* Redistributions of source code must retain the above copyright notice, 
+** 			this list of conditions and the following disclaimer.
+** 		* Redistributions in binary form must reproduce the above copyright 
+**			notice, this list of conditions and the following disclaimer in the 
+**			documentation and/or other materials provided with the distribution.
+** 		* Neither the name of the Monash University nor the names of its contributors 
+**			may be used to endorse or promote products derived from this software 
+**			without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
+** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
+** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
+** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+**
+** Contact:
+*%		Louis Moresi - Louis.Moresi at sci.monash.edu.au
+*%
+** Author:
+**              Mirko Velic - Mirko.Velic at sci.monash.edu.au
+**              Julian Giordani - julian.giordani at sci.monash.edu.au
+**              Patrick Sunter - patrick at vpac.org
+**          
+**  Assumptions:
+**  	 I am assuming that the xi's (local coords) on the IntegrationPoint particles
+**       are precalculated. i.e. We assume the Coincident mapper is being used.
+**
+**  Notes:
+**         The PCDVC class should really be a class the next level up here.
+**	   We should be able to swap out the WeightsCalculator_CalculateAll function instead of just setting
+**                 a pointer inside that function.
+**
+**         If the function  getIntParticleMaterialRef_PointingToMaterialParticle ever gets called
+**         then someone has messed up the mapping between integration and material points. This function
+**         is potentially slow as it traverses the whole swarm. This should be avoided.
+**
+**         We do not allow particle deletion in interface cells (cells that have more than one type of material
+**         in them). Splitting is optional. This may be inadequate. We may need to do some handling of the neighbours
+**         to interface cells as well, in order to preserve particle density about an interface.
+
+How to use this:
+You may place the following in a top-level xml file to change the parameters:
+This assumes a lower level xml file is not using a weights calculator other than PCDVC.
+	   
+<struct name="weights" mergeType="replace">
+<param name="Type">PCDVC</param>
+<param name="resolutionX">10</param>
+<param name="resolutionY">10</param>
+<param name="resolutionZ">10</param>
+<param name="lowerT">0.25</param>  <!-- lower % threshold volume for deletion of particles. i.e if a particle volume < 0.25% of total then delete it -->
+<param name="upperT">15</param>    <!-- upper % threshold volume for deletion of particles. i.e if a particle volume > 15% of total then split it -->
+<param name="maxDeletions">5</param>
+<param name="maxSplits">10</param>
+<param name="MaterialPointsSwarm">materialSwarm</param>
+</struct>
+<struct name="weights" mergeType="merge">
+<param name="Inflow">True</param>  <!-- switches the Inflow flag on -->
+<param name="Threshold">0.8</param> <!-- Threshold for cell population in an inflow problem: If a cell has less than 80% of its assigned particles then we re-populate -->
+<param name="CentPosRatio">0.01</param> <!-- Threshold for cell population in an inflow problem: If a cell's centroid is more than sqrt(0.01) of the width of an FEM cell away from the particle position then we re-populate -->
+</struct>
+		
+Note that you can use the Inflow flags for non-inflow problems. Might be OK for paranoid people or weird situations.
+There is a slight performance hit having the Inflow flag enabled.
+	    
+This code is a bit messy and needs some tidying up and more comments. But for now, the inflow stuff seems to work OK.
+Tested in 3D with as few as 15 particles per cell for 50 time-steps with an Inflow problem.
+Tested in 2D with as few as 10 particles per cell for 150 time-steps with an Inflow problem.
+
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+/****************************************************************************************************************
+
+  The algorithm here uses the DVCWeights module to compute a discrete voronoi diagram per FEM cell given a set of local
+  particle positions, in 3D and 2D. The volumes of the Voronoi regions are used as integration weights for
+  the integration point swarm and the integration points are the centroids of the same volumes.
+
+  The volumes are also used as criteria for splitting and deleting particles. i.e. lowerT and upperT as percentages.
+
+  The Threshold and CentPosRatio parameters are only used when Inflow is turned on.
+
+  For a description of the Voronoi algorithm, see the article by Velic et.al.
+     "A Fast Robust Algorithm for computing Discrete Voronoi Diagrams in N-dimensions"
+  
+*****************************************************************************************************************/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PopulationControl/PopulationControl.h>
+#include <PICellerator/Weights/Weights.h>
+#include <PICellerator/MaterialPoints/MaterialPoints.h>
+
+//#include <PICellerator/PICellerator.h>
+#include "types.h"
+
+#include "PCDVC.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type PCDVC_Type = "PCDVC";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+PCDVC* PCDVC_New(
+	Name						name,
+	Dimension_Index		dim,
+	int*						res,
+ 	MaterialPointsSwarm*	mps,
+	double					upT,
+	double					lowT,
+	int						maxDeletions,
+	int						maxSplits,
+	Bool						splitInInterfaceCells,
+ 	Bool						deleteInInterfaceCells,
+	Bool						Inflow,
+	double					CentPosRatio,
+	int						ParticlesPerCell,
+	double					Threshold )
+{
+  PCDVC *self = (PCDVC*)_PCDVC_DefaultNew( name );
+
+    self->isConstructed = True;
+    _WeightsCalculator_Init( self, dim );
+    _DVCWeights_Init( self, res );
+    _PCDVC_Init( self, mps, upT, lowT, maxDeletions, maxSplits, splitInInterfaceCells, deleteInInterfaceCells, Inflow, CentPosRatio, ParticlesPerCell, Threshold );
+
+	return self;
+}
+
+PCDVC* _PCDVC_New(  PCDVC_DEFARGS  ) {
+    PCDVC* self;
+
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(PCDVC) );
+
+    /* Initialise the parent class. Every class has a parent, bar Stg_Component, which needs to be called */
+    self = (PCDVC*)_DVCWeights_New(  DVCWEIGHTS_PASSARGS  );
+
+    /* General info */
+
+    /* Virtual Info */
+
+    return self;
+}
+
+void _PCDVC_Init( void* pcdvc, MaterialPointsSwarm* mps, double upT, double lowT,
+                  int maxDeletions, int maxSplits, Bool splitInInterfaceCells,
+                  Bool deleteInInterfaceCells, Bool Inflow, double CentPosRatio,
+                  int ParticlesPerCell, double Threshold )
+{
+    PCDVC* self = (PCDVC*)pcdvc;
+	
+    self->materialPointsSwarm = mps;
+    self->upperT = upT;
+    self->lowerT = lowT;
+    self->maxDeletions = self->maxDeletions_orig = maxDeletions;
+    self->maxSplits    = self->maxSplits_orig    = maxSplits;
+    self->Inflow       = self->Inflow_orig       = Inflow;
+    self->splitInInterfaceCells = self->splitInInterfaceCells_orig = splitInInterfaceCells;
+    self->deleteInInterfaceCells = self->deleteInInterfaceCells_orig = deleteInInterfaceCells;
+    self->Threshold = Threshold;
+    self->CentPosRatio = CentPosRatio;
+    self->ParticlesPerCell = ParticlesPerCell;
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _PCDVC_Delete( void* pcdvc ) {
+    PCDVC* self = (PCDVC*)pcdvc;
+    /* Delete parent */
+    _DVCWeights_Delete( self );
+}
+
+
+void _PCDVC_Print( void* pcdvc, Stream* stream ) {
+    PCDVC* self = (PCDVC*)pcdvc;
+    /* Print parent */
+    _DVCWeights_Print( self, stream );
+}
+
+
+
+void* _PCDVC_Copy( const void* pcdvc, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    PCDVC*	self = (PCDVC*)pcdvc;
+    PCDVC*	newPCDVC;
+	
+    newPCDVC = (PCDVC*)_DVCWeights_Copy( self, dest, deep, nameExt, ptrMap );
+    return (void*)newPCDVC;
+}
+
+void* _PCDVC_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                                 _sizeOfSelf = sizeof(PCDVC);
+	Type                                                         type = PCDVC_Type;
+	Stg_Class_DeleteFunction*                                 _delete = _PCDVC_Delete;
+	Stg_Class_PrintFunction*                                   _print = _PCDVC_Print;
+	Stg_Class_CopyFunction*                                     _copy = _PCDVC_Copy;
+	Stg_Component_DefaultConstructorFunction*     _defaultConstructor = _PCDVC_DefaultNew;
+	Stg_Component_ConstructFunction*                       _construct = _PCDVC_AssignFromXML;
+	Stg_Component_BuildFunction*                               _build = _PCDVC_Build;
+	Stg_Component_InitialiseFunction*                     _initialise = _PCDVC_Initialise;
+	Stg_Component_ExecuteFunction*                           _execute = _PCDVC_Execute;
+	Stg_Component_DestroyFunction*                           _destroy = _PCDVC_Destroy;
+	AllocationType                                 nameAllocationType = NON_GLOBAL;
+	WeightsCalculator_CalculateFunction*                   _calculate = _PCDVC_Calculate;
+
+    return (void*) _PCDVC_New(  PCDVC_PASSARGS  );
+}
+
+
+void _PCDVC_AssignFromXML( void* pcdvc, Stg_ComponentFactory* cf, void *data ) {
+
+    PCDVC*	     self          = (PCDVC*) pcdvc;
+    MaterialPointsSwarm*       materialPointsSwarm;
+    double upT, lowT;
+    int maxD, maxS;
+    Bool splitInInterfaceCells;
+    Bool deleteInInterfaceCells;
+    Bool Inflow;
+    double CentPosRatio;
+    int ParticlesPerCell;
+    double Thresh;
+
+    _DVCWeights_AssignFromXML( self, cf, data );
+
+    materialPointsSwarm = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"MaterialPointsSwarm", MaterialPointsSwarm, True, data  );
+    Stream*  stream = Journal_Register( Info_Type, (Name)materialPointsSwarm->type  );
+	
+
+    stream = Journal_Register( Info_Type, (Name)materialPointsSwarm->type  );
+    upT = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"upperT", 25  );
+    lowT = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"lowerT", 0.6  );
+    maxD = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxDeletions", 2 );
+    maxS = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxSplits", 3 );
+    splitInInterfaceCells  = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"splitInInterfaceCells", False );
+    deleteInInterfaceCells = Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"deleteInInterfaceCells", False );
+    Inflow =  Stg_ComponentFactory_GetBool( cf, self->name, (Dictionary_Entry_Key)"Inflow", False );
+    Thresh = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"Threshold", 0.8  );
+    //CentPosRatio is ratio of allowable distance of a centroid from generating particle to distance across a FEM cell.
+    // I think the centroid distance idea is not ideal in the end...can create some weirdness...even thought the code "works"
+    // after a while one can get wiggly lines in the cells...the centriods are close to the particles but its all
+    // centred in the FEM cell.
+    CentPosRatio =  Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"CentPosRatio", 0.01  );
+    // just getting the initial PPC for now...maybe could make this a separate parameter yet if needed.
+    ParticlesPerCell = cf->getRootDictUnsignedInt( cf, "particlesPerCell", 25);
+    if(upT < lowT){
+        lowT = 0.6;
+        upT = 25;
+        Journal_Printf( stream,"On Proc %d: In func %s(): WARNING!! lowT and upT have been reset to some more reasonable values. (lowT = 0.6, upT = 25) now!",materialPointsSwarm->myRank, __func__);
+    }
+
+    _PCDVC_Init( self, materialPointsSwarm,  upT, lowT, maxD, maxS, splitInInterfaceCells,
+                 deleteInInterfaceCells, Inflow, CentPosRatio, ParticlesPerCell, Thresh );
+}
+
+void _PCDVC_Build( void* pcdvc, void* data ) {
+    PCDVC*	self = (PCDVC*)pcdvc;
+    _DVCWeights_Build( self, data );
+    Stg_Component_Build( self->materialPointsSwarm, data, False );
+}
+void _PCDVC_Destroy( void* pcdvc, void* data ) {
+    PCDVC*	self = (PCDVC*)pcdvc;
+    _DVCWeights_Destroy( self, data );
+    Stg_Component_Destroy( self->materialPointsSwarm, data, False );
+}
+void _PCDVC_Initialise( void* pcdvc, void* data ) {
+    PCDVC*	self = (PCDVC*)pcdvc;
+    /** for interpolation restart, we need to set these values high to ensure correct population of */
+    /** integration point swarms                                                                    */
+    /** these parameters will be reset to correct values after first timestep                       */
+    if ( (True == self->context->loadFromCheckPoint) && (True == self->context->interpolateRestart) ){
+        self->maxDeletions           = 999999;
+        self->maxSplits              = 999999;
+        self->Inflow                 = True;
+        self->splitInInterfaceCells  = True;
+        self->deleteInInterfaceCells = True;
+    }
+    Stg_Component_Initialise( self->materialPointsSwarm, data, False );
+    _DVCWeights_Initialise( self, data );
+}
+void _PCDVC_Execute( void* pcdvc, void* data ) {
+    PCDVC*	self = (PCDVC*)pcdvc;
+    _DVCWeights_Execute( self, data );
+}
+
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+/* this function loops over the intSwarm in order to find the MaterialPointRef for the integration point particle
+   that points to the matLastParticle_IndexOnCPU of a material particle. It is used here in the case that the last integration point
+   particle DOES NOT point to the last material point particle, as it should.
+   If this function is being called ever, then some other module/component somewhere has messed up the mapping between the integration Swarm and the material Swarm*/
+MaterialPointRef* getIntParticleMaterialRef_PointingToMaterialParticle( IntegrationPointsSwarm*  intSwarm, Particle_Index matLastParticle_IndexOnCPU ){
+    IntegrationPoint* intTestParticle;
+    MaterialPointRef*       ref=NULL;
+    Index i;
+    Stream*  stream = Journal_Register( Info_Type, (Name)intSwarm->type  );
+    Journal_Printf( stream,"\n\n\e[31m\nOn Proc %d: In func %s(): WARNING!! If this function is being called, then some other module/component, somewhere, has messed up the mapping between the integration Swarm and the material Swarm\n\n", intSwarm->myRank, __func__);
+    Journal_Printf( stream,"This function is potentially slow. Someone should fix the offending module so that it doesn not mess up the ordering\n\n");
+    Journal_Printf( stream,"\e[0;32m");
+    for(i=0;i<intSwarm->particleLocalCount;i++){
+        intTestParticle =  (IntegrationPoint*)Swarm_ParticleAt( intSwarm, i);
+        ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intTestParticle);
+        if(ref->particle_I == matLastParticle_IndexOnCPU){
+            break;
+        }
+    }
+    return ref;
+}
+/****************************************************************************************************
+ This function deletes integration particle number intParticleToRemove_IndexWithinCell in lCell_I
+ as well as the corresponding material point.
+ It assumes the one to one coincidence mapper is being used. i.e. for every integration point 
+ there is one material point and vice versa.
+******************************************************************************************************/
+void deleteIntParticleByIndexWithinCell( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Cell_LocalIndex lCell_I, Particle_Index intParticleToRemove_IndexWithinCell ) {
+    MaterialPointRef*       ref;
+    MaterialPointRef*       refTestLastParticle;
+    MaterialPointRef*       ref_moved_particle;
+    MaterialPointRef*   refToLastMatParticle;
+    int refToLastMatParticleFlag = 0;
+    Particle_Index    intParticleToRemove_IndexOnCPU;/* the particle number within the swarm on the local CPU */
+    Particle_Index    matParticleToRemove_IndexOnCPU;
+    IntegrationPoint* intParticleToRemove;
+    MaterialPoint*    matParticleToRemove;
+    //Particle_Index    intParticleToRemove_IndexWithinCell;/* the number of the particle within the cell */
+    Particle_Index    matParticleToRemove_IndexWithinCell;
+    IntegrationPoint* intSwarmLastParticle; /* The last particle in the swarm on the local CPU */
+    MaterialPoint*    matSwarmLastParticle;
+    Particle_Index    intLastParticle_IndexOnCPU;
+    Particle_Index    matLastParticle_IndexOnCPU;
+    Particle_Index    intLastParticle_IndexWithinCell;
+    Particle_Index    matLastParticle_IndexWithinCell;
+
+    SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
+    SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
+
+
+    intParticleToRemove_IndexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ intParticleToRemove_IndexWithinCell ];
+    intParticleToRemove =  (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intParticleToRemove_IndexOnCPU);
+    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
+    matParticleToRemove_IndexOnCPU = ref->particle_I;
+    matParticleToRemove =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToRemove_IndexOnCPU);
+    matParticleToRemove_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexOnCPU);
+
+    /* The particles are homeless after these function-calls and for this reason alone must be destroyed */
+    Swarm_RemoveParticleFromCell( intSwarm, lCell_I, intParticleToRemove_IndexWithinCell );
+    Swarm_RemoveParticleFromCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell );
+
+    /* Copy over particle to remove with the last particle in the particle array - as long as it isn't the last one  */
+    intLastParticle_IndexOnCPU = intSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
+    matLastParticle_IndexOnCPU = matSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
+
+    /* we are switching places between the particle we are deleting and the last particle in the array
+       then actually deleting the last particle in the array */
+    intSwarmLastParticle = (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intLastParticle_IndexOnCPU );
+    matSwarmLastParticle = (MaterialPoint*)Swarm_ParticleAt( matSwarm, matLastParticle_IndexOnCPU );
+    /* we have the last particles of both swarms now..
+       if the intSwarmLastParticle material ref does NOT point to the matSwarmLastParticle
+       then we might be in trouble...so test for this here */
+    refTestLastParticle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intSwarmLastParticle); /* so we can get the material point */
+    //refToLastMatParticleFlag = 0;
+    if(refTestLastParticle->particle_I != matLastParticle_IndexOnCPU){
+        printf("\e[31mThe last int particle does NOT point to the last mat particle..we need to handle this\n\n");
+        printf("\e[0;32m");
+        refToLastMatParticle = getIntParticleMaterialRef_PointingToMaterialParticle( intSwarm, matLastParticle_IndexOnCPU );
+        refToLastMatParticle->particle_I = matParticleToRemove_IndexOnCPU;
+        refToLastMatParticleFlag = 1;
+        exit(0);
+        /* if the test here is true then that means that some other int particle points to the last material particle
+           and therefore *its* material ref needs to be updated when we move the last material particle.
+           It also means that we do not update the ref for the last int particle as that must be pointing somewhere
+           other than the last material particle and the mat particle that is somewhere else is not being moved.
+        */
+    }
+    if ( intParticleToRemove_IndexOnCPU != intLastParticle_IndexOnCPU ) {                                                                                                                       
+        //printf("Deleting int particle number %d from cell %d local cell particle num = %d\n\n", intParticleToRemove_IndexOnCPU ,lCell_I, intParticleToRemove_IndexWithinCell);                    
+                                                                                                                                                                                                
+        intLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intSwarmLastParticle->owningCell, intLastParticle_IndexOnCPU);                                              
+                                                                                                                                                                                                
+        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
+        memcpy( intParticleToRemove, intSwarmLastParticle, intparticleSize );                                                                                                       
+                                                                                                                                                                                                
+        /* Change value in cell particle table to point to new index in localCPU particle array.                                                                                    
+           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
+           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
+        intSwarm->cellParticleTbl[ intSwarmLastParticle->owningCell ] [intLastParticle_IndexWithinCell ] = intParticleToRemove_IndexOnCPU;
+        if(!refToLastMatParticleFlag){                                                         
+            ref_moved_particle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
+            ref_moved_particle->particle_I = matParticleToRemove_IndexOnCPU;
+        }
+    }                                                                                                                                                                                 
+    intSwarm->particleLocalCount--; 
+    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
+    if ( matParticleToRemove_IndexOnCPU != matLastParticle_IndexOnCPU ) {                                                                                                                       
+        //printf("Deleting mat particle number %d from cell %d local cell particle num = %d\n\n", matParticleToRemove_IndexOnCPU, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell);                    
+                                                                                                                                                                                                
+        matLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matSwarmLastParticle->owningCell, matLastParticle_IndexOnCPU);                                              
+                                                                                                                                                                                                
+        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
+        memcpy( matParticleToRemove, matSwarmLastParticle, matparticleSize );                                                                                                       
+                                                                                                                                                                                                
+        /* Change value in cell particle table to point to new index in localCPU particle array.                                                                                    
+           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
+           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
+        matSwarm->cellParticleTbl[ matSwarmLastParticle->owningCell][matLastParticle_IndexWithinCell ] = matParticleToRemove_IndexOnCPU;                                                          
+                                                                                                                                                                                                
+    }                                                                                                                                                                                 
+    matSwarm->particleLocalCount--; 
+    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
+	      
+}
+/****************************************************************************************************
+ This function deletes integration particle number intParticleToRemove_IndexOnCPU
+ on integration swarm as well as the corresponding material point.
+ It assumes the one to one coincidence mapper is being used. i.e. for every integration point 
+ there is one material point and vice versa.
+******************************************************************************************************/
+void deleteIntParticleByIndexOnCPU( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Particle_Index intParticleToRemove_IndexOnCPU ) {
+    MaterialPointRef*       ref;
+    MaterialPointRef*       refTestLastParticle;
+    MaterialPointRef*       ref_moved_particle;
+    MaterialPointRef*   refToLastMatParticle;
+    int refToLastMatParticleFlag = 0;
+    //Particle_Index    intParticleToRemove_IndexOnCPU;/* the particle number within the swarm on the local CPU */
+    Particle_Index    matParticleToRemove_IndexOnCPU;
+    IntegrationPoint* intParticleToRemove;
+    MaterialPoint*    matParticleToRemove;
+    Particle_Index    intParticleToRemove_IndexWithinCell;/* the number of the particle within the cell */
+    Particle_Index    matParticleToRemove_IndexWithinCell;
+    IntegrationPoint* intSwarmLastParticle; /* The last particle in the swarm on the local CPU */
+    MaterialPoint*    matSwarmLastParticle;
+    Particle_Index    intLastParticle_IndexOnCPU;
+    Particle_Index    matLastParticle_IndexOnCPU;
+    Particle_Index    intLastParticle_IndexWithinCell;
+    Particle_Index    matLastParticle_IndexWithinCell;
+    Cell_LocalIndex lCell_I;
+
+
+    SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
+    SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
+
+    //intParticleToRemove_IndexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ intParticleToRemove_IndexWithinCell ];
+    intParticleToRemove =  (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intParticleToRemove_IndexOnCPU);
+
+    intParticleToRemove_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intParticleToRemove->owningCell, intParticleToRemove_IndexOnCPU);
+
+    lCell_I = intParticleToRemove->owningCell;
+
+    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
+    matParticleToRemove_IndexOnCPU = ref->particle_I;
+    matParticleToRemove =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToRemove_IndexOnCPU);
+    matParticleToRemove_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexOnCPU);
+
+    /* The particles are homeless after these function-calls and for this reason alone must be destroyed */
+    Swarm_RemoveParticleFromCell( intSwarm, lCell_I, intParticleToRemove_IndexWithinCell );
+    Swarm_RemoveParticleFromCell( matSwarm, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell );
+
+    /* Copy over particle to remove with the last particle in the particle array - as long as it isn't the last one  */
+    intLastParticle_IndexOnCPU = intSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
+    matLastParticle_IndexOnCPU = matSwarm->particleLocalCount - 1; /* lastParticle_I is the last particle in the array of particles residing on the current CPU */
+
+    /* we are switching places between the particle we are deleting and the last particle in the array
+       then actually deleting the last particle in the array */
+    intSwarmLastParticle = (IntegrationPoint*)Swarm_ParticleAt( intSwarm, intLastParticle_IndexOnCPU );
+    matSwarmLastParticle = (MaterialPoint*)Swarm_ParticleAt( matSwarm, matLastParticle_IndexOnCPU );
+    /* we have the last particles of both swarms now..
+       if the intSwarmLastParticle material ref does NOT point to the matSwarmLastParticle
+       then we might be in trouble...so test for this here */
+    refTestLastParticle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intSwarmLastParticle); /* so we can get the material point */
+    //refToLastMatParticleFlag = 0;
+    if(refTestLastParticle->particle_I != matLastParticle_IndexOnCPU){
+        printf("\e[31mThe last int particle does NOT point to the last mat particle..we need to handle this\n\n");
+        printf("\e[0;32m");
+        refToLastMatParticle = getIntParticleMaterialRef_PointingToMaterialParticle( intSwarm, matLastParticle_IndexOnCPU );
+        refToLastMatParticle->particle_I = matParticleToRemove_IndexOnCPU;
+        refToLastMatParticleFlag = 1;
+        exit(0);
+        /* if the test here is true then that means that some other int particle points to the last material particle
+           and therefore *its* material ref needs to be updated when we move the last material particle.
+           It also means that we do not update the ref for the last int particle as that must be pointing somewhere
+           other than the last material particle and the mat particle that is somewhere else is not being moved.
+        */
+    }
+
+    if ( intParticleToRemove_IndexOnCPU != intLastParticle_IndexOnCPU ) {
+        //printf("Deleting int particle number %d from cell %d local cell particle num = %d\n\n", intParticleToRemove_IndexOnCPU ,lCell_I, intParticleToRemove_IndexWithinCell);
+
+        intLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intSwarmLastParticle->owningCell, intLastParticle_IndexOnCPU);
+      
+        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
+        memcpy( intParticleToRemove, intSwarmLastParticle, intparticleSize );
+
+        /* Change value in cell particle table to point to new index in localCPU particle array.
+           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
+           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
+        intSwarm->cellParticleTbl[ intSwarmLastParticle->owningCell ] [intLastParticle_IndexWithinCell ] = intParticleToRemove_IndexOnCPU;
+        if(!refToLastMatParticleFlag){
+            ref_moved_particle = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToRemove); /* so we can get the material point */
+            ref_moved_particle->particle_I = matParticleToRemove_IndexOnCPU;
+        }
+    }
+
+    intSwarm->particleLocalCount--; 
+    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
+    if ( matParticleToRemove_IndexOnCPU != matLastParticle_IndexOnCPU ) {                                                                                                                       
+        //printf("Deleting mat particle number %d from cell %d local cell particle num = %d\n\n", matParticleToRemove_IndexOnCPU, matParticleToRemove->owningCell, matParticleToRemove_IndexWithinCell);                    
+                                                                                                                                                                                                
+        matLastParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( matSwarm, matSwarmLastParticle->owningCell, matLastParticle_IndexOnCPU);                                              
+                                                                                                                                                                                                
+        /* particleToRemove gets over-written by lastParticle  void *memcpy(void *dest, const void *src, size_t n); */                                                              
+        memcpy( matParticleToRemove, matSwarmLastParticle, matparticleSize );                                                                                                       
+                                                                                                                                                                                                
+        /* Change value in cell particle table to point to new index in localCPU particle array.                                                                                    
+           ok.. lastParticle_I is a global index of the last particle...we no longer have that many particles                                                                       
+           so give it a new index in the swarm...it has now assumed the identity of the particle that got removed...complete identity theft*/                                       
+        matSwarm->cellParticleTbl[ matSwarmLastParticle->owningCell][matLastParticle_IndexWithinCell ] = matParticleToRemove_IndexOnCPU;                                                          
+                                                                                                                                                                                                
+    }                                                                                                                                                                                 
+    matSwarm->particleLocalCount--; 
+    //Swarm_Realloc( intSwarm ); /* do I really want to do this EVERY time I delete a particle? No I don't hmmm*/
+	      
+}
+void splitIntParticleByIndexWithinCell( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Cell_LocalIndex lCell_I, Particle_Index intParticleToSplit_IndexWithinCell, Coord xi ) {
+    MaterialPointRef*       ref;
+    Particle_Index    intNewParticle_IndexOnCPU;/* the particle number within the swarm on the local CPU */
+    Particle_Index    matNewParticle_IndexOnCPU;
+    IntegrationPoint* intNewParticle;
+    MaterialPoint*    matNewParticle;
+    Particle_Index    intNewParticle_IndexWithinCell;/* the number of the particle within the cell */
+    //Particle_Index    matNewParticle_IndexWithinCell;
+    IntegrationPoint* intParticleToSplit;
+    MaterialPoint*    matParticleToSplit;
+    //Particle_Index    intParticleToSplit_IndexWithinCell;
+    //Particle_Index    matParticleToSplit_IndexWithinCell;
+    Particle_Index    matParticleToSplit_IndexOnCPU;
+//      SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
+//      SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
+    Coord                   newCoord;
+//      Coord                   xi;
+
+    FeMesh*     mesh              = (FeMesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
+
+	      
+    //intParticleToSplit_IndexWithinCell = maxI;
+
+    /* Add a new particle to end the end of each swarm */
+    /* this calls Swarm_Realloc -- don't like reallocing every time we create a particle
+       need to do this differently */
+    intNewParticle     = (IntegrationPoint*) Swarm_CreateNewParticle( intSwarm, &intNewParticle_IndexOnCPU );
+    matNewParticle     = (MaterialPoint*) Swarm_CreateNewParticle( matSwarm, &matNewParticle_IndexOnCPU );
+	      
+    /* Copy particle information */
+    intParticleToSplit = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, intParticleToSplit_IndexWithinCell );
+    memcpy( intNewParticle, intParticleToSplit, intSwarm->particleExtensionMgr->finalSize );
+    Swarm_AddParticleToCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU );
+    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intNewParticle); /* so we can set the reference to the material point */
+    ref->particle_I = matNewParticle_IndexOnCPU; /* now the ref for the new int particle points to the new material particle -- the swarm id should be correct because we memcpy'd from the original */
+
+    /* Now get the material point corresponding to the int point being split so that
+       we can copy the material properties to the newly created material particle */
+    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToSplit);
+    matParticleToSplit_IndexOnCPU = ref->particle_I;
+    matParticleToSplit  =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToSplit_IndexOnCPU );
+    memcpy( matNewParticle, matParticleToSplit, matSwarm->particleExtensionMgr->finalSize );
+    Swarm_AddParticleToCell( matSwarm, matNewParticle->owningCell, matNewParticle_IndexOnCPU );
+
+    /* Copy new local position to xi on new int particle */
+    memcpy( intNewParticle->xi, xi, sizeof(Coord) );
+	      
+    /* Get new Global Coordinates from the Local Coordinates */
+    FeMesh_CoordLocalToGlobal( mesh, lCell_I, xi, newCoord );
+
+    /* Copy new global position to coord on new mat particle */
+    memcpy( matNewParticle->coord, newCoord, sizeof(Coord) );
+	      
+    intNewParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU);
+    /*
+      printf("\e[1;33m");
+      printf("Creating int particle number %d from cell %d local within cell particle num = %d\n\n", intNewParticle_IndexOnCPU ,lCell_I, intNewParticle_IndexWithinCell);
+      printf("matSwarm particle count is now : %d\n",matSwarm->cellParticleCountTbl[lCell_I]);
+      printf("intSwarm particle count is now : %d\n",intSwarm->cellParticleCountTbl[lCell_I]);
+      printf("Original Population was %d\n",nump-1);
+      printf("\e[0;32m");
+    */
+
+}
+void splitIntParticleByIndexOnCPU( IntegrationPointsSwarm*  intSwarm, MaterialPointsSwarm* matSwarm, Particle_Index intParticleToSplit_IndexOnCPU, Coord xi ) {
+    MaterialPointRef*       ref;
+    Particle_Index    intNewParticle_IndexOnCPU;/* the particle number within the swarm on the local CPU */
+    Particle_Index    matNewParticle_IndexOnCPU;
+    IntegrationPoint* intNewParticle;
+    MaterialPoint*    matNewParticle;
+    Particle_Index    intNewParticle_IndexWithinCell;/* the number of the particle within the cell */
+    //Particle_Index    matNewParticle_IndexWithinCell;
+    IntegrationPoint* intParticleToSplit;
+    MaterialPoint*    matParticleToSplit;
+    Particle_Index    intParticleToSplit_IndexWithinCell;
+    //Particle_Index    matParticleToSplit_IndexWithinCell;
+    Particle_Index    matParticleToSplit_IndexOnCPU;
+//      SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
+//      SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
+    Coord                   newCoord;
+//      Coord                   xi;
+
+    Cell_LocalIndex lCell_I;
+
+    FeMesh*     mesh              = (FeMesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
+
+	      
+    //intParticleToSplit_IndexWithinCell = maxI;
+
+    /* Add a new particle to end the end of each swarm */
+    /* this calls Swarm_Realloc -- don't like reallocing every time we create a particle
+       need to do this differently */
+    intNewParticle     = (IntegrationPoint*) Swarm_CreateNewParticle( intSwarm, &intNewParticle_IndexOnCPU );
+    matNewParticle     = (MaterialPoint*) Swarm_CreateNewParticle( matSwarm, &matNewParticle_IndexOnCPU );
+	      
+
+
+    /* Copy particle information */
+    intParticleToSplit_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, intParticleToSplit->owningCell, intParticleToSplit_IndexOnCPU);
+
+    intParticleToSplit = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, intParticleToSplit_IndexWithinCell );
+
+
+    lCell_I = intParticleToSplit->owningCell;
+
+
+    memcpy( intNewParticle, intParticleToSplit, intSwarm->particleExtensionMgr->finalSize );
+    Swarm_AddParticleToCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU );
+    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intNewParticle); /* so we can set the reference to the material point */
+    ref->particle_I = matNewParticle_IndexOnCPU; /* now the ref for the new int particle points to the new material particle -- the swarm id should be correct because we memcpy'd from the original */
+
+    /* Now get the material point corresponding to the int point being split so that
+       we can copy the material properties to the newly created material particle */
+    ref = OneToOneMapper_GetMaterialRef(intSwarm->mapper, intParticleToSplit);
+    matParticleToSplit_IndexOnCPU = ref->particle_I;
+    matParticleToSplit  =  (MaterialPoint*)Swarm_ParticleAt( matSwarm, matParticleToSplit_IndexOnCPU );
+    memcpy( matNewParticle, matParticleToSplit, matSwarm->particleExtensionMgr->finalSize );
+    Swarm_AddParticleToCell( matSwarm, matNewParticle->owningCell, matNewParticle_IndexOnCPU );
+
+    /* Copy new local position to xi on new int particle */
+    memcpy( intNewParticle->xi, xi, sizeof(Coord) );
+	      
+    /* Get new Global Coordinates from the Local Coordinates */
+    FeMesh_CoordLocalToGlobal( mesh, lCell_I, xi, newCoord );
+
+    /* Copy new global position to coord on new mat particle */
+    memcpy( matNewParticle->coord, newCoord, sizeof(Coord) );
+	      
+    intNewParticle_IndexWithinCell = Swarm_GetParticleIndexWithinCell( intSwarm, lCell_I, intNewParticle_IndexOnCPU);
+    /*
+      printf("\e[1;33m");
+      printf("Creating int particle number %d from cell %d local within cell particle num = %d\n\n", intNewParticle_IndexOnCPU ,lCell_I, intNewParticle_IndexWithinCell);
+      printf("matSwarm particle count is now : %d\n",matSwarm->cellParticleCountTbl[lCell_I]);
+      printf("intSwarm particle count is now : %d\n",intSwarm->cellParticleCountTbl[lCell_I]);
+      printf("Original Population was %d\n",nump-1);
+      printf("\e[0;32m");
+    */
+
+}
+/* sort indexOnCPU in reverse order */
+int compare_indexOnCPU(const void * _particleA, const void * _particleB){
+    struct deleteParticle * particleA = (struct deleteParticle *) _particleA;
+    struct deleteParticle * particleB = (struct deleteParticle *) _particleB;
+      
+    if(particleA->indexOnCPU < particleB->indexOnCPU)
+        return 1;
+    else
+        return -1;
+
+}
+int compare_ints(const void * _A, const void * _B){
+    int *A = (int *) _A;
+    int *B = (int *) _B;
+    if(*A > *B) return 1; else return -1;
+}
+#if 0
+void buildPVCList(int **particleVornoiCellList, struct particle2d *pList, struct cell2d *cells, int *VCsize, double da, int nump, int XY, int dim){
+    int oneOda = (int)(1.0/da + 0.5);
+    int i,j;
+    int *count = (int)malloc(nump*sizeof(int));
+      
+    for(i=0;i<nump;i++){ 
+        count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
+        VCsize[i] = count[i];
+        //countSum += count[i];//for debugging
+        //wSum += pList[i].w;//for debugging
+        particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
+    }
+    for(i=0;i<XY;i++){// traverse the grid
+        /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
+            internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
+        //if(VCsize[cells[i].p] != 0){// in case a particle is unresolved
+        if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
+            particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
+            count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
+            //countSum++;
+        }
+        //}
+    }
+    free(count);
+}
+#endif
+/* Calculate the integration weights for each particle by contructing
+   a voronoi diagram in an element in 3D*/
+void _PCDVC_Calculate3D( void* pcdvc, void* _swarm, Cell_LocalIndex lCell_I ) {
+    PCDVC*             self            = (PCDVC*)  pcdvc;
+    IntegrationPointsSwarm*  intSwarm  = (IntegrationPointsSwarm*) _swarm;
+    MaterialPointsSwarm* matSwarm =	(MaterialPointsSwarm*) self->materialPointsSwarm;
+    /* CoincidentMapper is a special case of the one to one mapper */
+    //CoincidentMapper* mapper  = (CoincidentMapper*)(intSwarm->mapper); /* need the mapper after-all to update the material ref */
+    Particle_InCellIndex         cParticleCount;
+    IntegrationPoint**           particle;
+    static int visited = 0 ;
+    //static int deleted = 0 ;
+    double dx,dy,dz,da;
+    static struct cell *cells;// the connected grid
+    struct particle *pList;// particle List
+    struct chain *bchain;//boundary chain
+    int nump_orig,nump,numx,numy,numz;
+    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
+    double BBXMAX = 1.0;
+    double BBYMIN = -1.0;
+    double BBYMAX = 1.0;
+    double BBZMIN = -1.0;
+    double BBZMAX = 1.0;
+    int i,k;
+
+    /*************************************/
+    /* stuff for particle removal/adding */
+    struct deleteParticle* deleteList;
+    double maxW,minW;
+    int maxI, minI;
+    double lowT = self->lowerT;
+    double upT = self->upperT;
+    int delete_flag, split_flag;
+    Particle_Index  *splitList;
+//	int deleteListStackPtr = -1;/* use a number to tell me how many particles we are going to delete: saves doing it some other less efficient way */
+//	int splitListStackPtr = -1;
+    int maxDeletions = self->maxDeletions;/* hard setting this till I get stuff from xml file */
+    int maxSplits = self->maxSplits;
+    int splitCount;
+    int deleteCount;
+    int Count;
+    int matTypeFirst;
+    int matType;
+    Bool splitInInterfaceCells  = self->splitInInterfaceCells;
+    Bool deleteInInterfaceCells = self->deleteInInterfaceCells;
+    Bool Inflow = self->Inflow;
+    double Thresh = self->Threshold;
+    int ParticlesPerCell = self->ParticlesPerCell;
+    double CentPosRatio = self->CentPosRatio;
+//	SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
+//	SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
+//	Coord                   newCoord;
+    Coord                   xi;
+
+//	FiniteElement_Mesh*     mesh              = (FiniteElement_Mesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
+
+    /* end decs needed for particle control */
+    /*************************************/
+	
+
+
+    numx = self->resX;
+    numy = self->resY;
+    numz = self->resZ;
+
+    nump_orig = nump = cParticleCount = intSwarm->cellParticleCountTbl[lCell_I];
+
+    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"PCDVC" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
+
+    dx = (BBXMAX - BBXMIN)/numx;
+    dy = (BBYMAX - BBYMIN)/numy;
+    dz = (BBZMAX - BBZMIN)/numz;
+    da = dx*dy*dz;
+	
+    // Construct the grid for the Voronoi cells only once.
+    // If we wanted to call this function again during a job with a different resolution
+    // then we should destroy the grid once we have looped through the whole mesh.
+    // I am assuming we are not going to do that for now.
+    // Easy to implement this anyway, if needed.
+    if(!visited){
+        /* The PCDVC class should really be a class the next level up here */
+        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
+           a pointer inside that function */
+        visited++;
+        _DVCWeights_ConstructGrid(&cells,numz,numy,numx,BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);
+    }
+	
+    // init the data structures
+    _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
+    _DVCWeights_ResetGrid(&cells,numz*numy*numx);
+	
+    particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));
+	
+    // initialize the particle positions to be the local coordinates of the material swarm particles
+    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
+    // positions each time step.
+    for(i=0;i<nump;i++){
+	      
+        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
+        pList[i].x = particle[i]->xi[0];
+        pList[i].y = particle[i]->xi[1];
+        pList[i].z = particle[i]->xi[2];
+	      
+    }
+    _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+    _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
+
+    /************************************/
+    /************************************/
+    /*    Start 3D Population Control   */
+    /************************************/
+    /************************************/
+    /* todo: put print statements into Journal statements */
+    /*********************************/
+
+    /** want to do something special for inflow problems **/
+    /** we need to be a lot more aggressive with adding particles in this case **/
+    /************************************/
+    /************************************/
+    /*      Start 3D Inflow Control     */
+    /************************************/
+    /************************************/
+
+    int *VCsize=NULL;
+    int **particleVoronoiCellList=NULL;
+    int *count=NULL; // count of how many cells each particle owns in the Voronoi diagram.
+    int flag =0;
+    double FEMCEllspan = BBXMAX - BBXMIN;
+    double dist=0;
+    if(Inflow){
+        for(i=0;i<nump_orig;i++){
+            dist = (pList[i].cx - pList[i].x)*(pList[i].cx - pList[i].x) + (pList[i].cy - pList[i].y)*(pList[i].cy - pList[i].y) + (pList[i].cz - pList[i].z)*(pList[i].cz - pList[i].z);
+        }
+        if(dist > CentPosRatio*FEMCEllspan){flag = 1;}
+	      
+    }
+    if(Inflow && (  ((1.0*nump_orig)/ParticlesPerCell < Thresh) || flag  ) ){
+        int oneOda = (int)(1.0/da + 0.5);
+        int *VCsize=(int *)malloc(sizeof(int)*nump);
+#if 0
+        double dist;
+        int numberofnewpoints;
+        int newpindex;
+#endif
+        int j;
+        int delNum;
+        VCsize=(int *)malloc(sizeof(int)*nump_orig);
+        count=(int *)malloc(sizeof(int)*nump_orig);
+        splitCount = 0;
+        particleVoronoiCellList = (int **)malloc(nump_orig * sizeof(int *));// [i][j] is jth cell owned by particle i
+        for(i=0;i<nump_orig;i++){ 
+            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
+            VCsize[i] = count[i];
+            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
+        }
+        for(i=0;i<numx*numy*numz;i++){// traverse the grid
+            //count[ cells[i].p ]++;
+            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
+                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
+            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
+                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
+                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
+                //countSum++;
+            }
+        }
+        // we now have a list of cells from the grid belonging to each particle that make up each Voronoi cell in the Voronoi diagram
+        // next lets compare how far our centroids are from the particle positions.
+        // this is my criteria for a voronoi cell having a weird shape...too stretched out for example.
+        // this is exactly what happens in inflow situations.  
+        // Add a random number of new particles...
+        // But Need to add them where they are needed. 
+        for(i=0;i<ParticlesPerCell;i++){
+            j  =  (int) ( numx*numy*numz * (rand() / (RAND_MAX + 1.0)));
+            xi[0] = cells[ j ].x;
+            xi[1] = cells[ j ].y;
+            xi[2] = cells[ j ].z;
+            splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, cells[j].p, xi );
+            nump++; splitCount++;
+        }
+        for(i=0;i<nump_orig;i++){
+            free(particleVoronoiCellList[i]);
+        }
+        free(particleVoronoiCellList);
+        free(VCsize); free(count);
+        //if(splitCount) printf("\n\e[32mnump is now %d splitCount = %d\n",nump,splitCount);
+        delNum = nump - ParticlesPerCell;
+        if(delNum > 5){
+            for(i=0;i<delNum;i++){
+                j =  (int) (nump * (rand() / (RAND_MAX + 1.0)));
+                deleteIntParticleByIndexWithinCell( intSwarm,  matSwarm, lCell_I, j );
+                nump--;
+                splitCount++;
+            }
+        }
+#if 0
+        for(i=0;i<nump;i++){
+            if(0 != VCsize[i]){
+                dist = (pList[i].cx - pList[i].x)*(pList[i].cx - pList[i].x) + (pList[i].cy - pList[i].y)*(pList[i].cy - pList[i].y) + (pList[i].cz - pList[i].z)*(pList[i].cz - pList[i].z);
+                if(dist > CentPosRatio*FEMCEllspan){
+                    // Then populate this Voronoi cell with more particles.
+                    // A working number might be based on the initial population per FEM cell, i.e. restore the density.
+                    // which I can't be bothered trying to figure out how to extract right this minute.
+                    // So, for now, I will just go with say..30? or could pass in via xml?
+                    numberofnewpoints = ParticlesPerCell*pList[i].w/8; // 8 is total volume of a local element.
+                    for(j=0;j<numberofnewpoints;j++){
+                        newpindex = rand()%VCsize[i];
+                        // we going to split particle[i] numberofnewpoints times and each time give the new particle the coordinates
+                        // of the cell we are planting it in.
+                        // it should not matter if we put newly created particles on top of each other accidentally.
+                        xi[0] = cells[ particleVoronoiCellList[i][newpindex] ].x;
+                        xi[1] = cells[ particleVoronoiCellList[i][newpindex] ].y;
+                        xi[2] = cells[ particleVoronoiCellList[i][newpindex] ].z;
+                        nump++;
+                        splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, i, xi );
+                        splitCount++;
+                    }
+                }//if
+            }//if
+        }//for i=0:nump
+#endif
+        if(splitCount){// then redo Voronoi diagram.
+            for(k=0;k<nump_orig;k++){
+                free(bchain[k].new_claimed_cells);
+                free(bchain[k].new_bound_cells);
+            }
+            free(particle);
+            free(bchain);
+            free(pList);
+            if(nump < 3){
+                Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
+            }
+            // init the data structures
+            _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
+	      
+            particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));
+	
+            // re-initialize the particle positions to be the local coordinates of the material swarm particles
+            // could do better here..instead of completely destroying these lists I could append to them I suppose.
+            for(i=0;i<nump;i++){
+		    
+                particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
+                pList[i].x = particle[i]->xi[0];
+                pList[i].y = particle[i]->xi[1];
+                pList[i].z = particle[i]->xi[2];
+		    
+            }
+            _DVCWeights_ResetGrid(&cells,numz*numy*numx);
+            _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+            _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
+
+        }
+        nump_orig = nump;
+    }// if Inflow && ...
+    if(Inflow){
+        int oneOda = (int)(1.0/da + 0.5);
+        //recreate the lists.
+        particleVoronoiCellList = (int **)malloc(nump * sizeof(int *));// [i][j] is jth cell owned by particle i
+        //VCsize = (int*)realloc(VCsize,nump_orig);
+        //count = (int*)realloc(count,nump_orig);
+        VCsize=(int *)malloc(sizeof(int)*nump);
+        count=(int *)malloc(sizeof(int)*nump); 
+	
+        for(i=0;i<nump;i++){ 
+            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
+            VCsize[i] = count[i];
+            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
+        }
+        for(i=0;i<numx*numy*numz;i++){// traverse the grid
+            //count[ cells[i].p ]++;
+            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
+                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
+            //if(VCsize[cells[i].p] != 0){// in case a particle is unresolved
+            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
+                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
+                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
+                //countSum++;
+            }
+            //}
+        }
+    }//if Inflow
+    /**************************************/
+    /**************************************/
+    /*        End 3D Inflow Control       */
+    /**************************************/
+    /**************************************/
+    split_flag = 0;
+    delete_flag = 0;
+//	maxW = 0.0;
+//	minW = 8.0;
+    splitCount = 0;
+    deleteCount = 0;
+    /* shouldn't need maxI and minI now */
+    maxW = upT*8/100.0;
+    minW = lowT*8/100.0;
+    /* check to see if we are in an interface cell.
+       We never want to delete particles in an interface cell */
+    matTypeFirst = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ 0 ]);
+    for(i=0;i<nump;i++){
+        matType = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ i ]);
+        if(matType != matTypeFirst){
+            if(!deleteInInterfaceCells) maxDeletions = 0; /* no deletions in an interface cell */
+            /* this may be inadequate...we may need to do something in the neighbouring cells to interface cells as well */
+            if(!splitInInterfaceCells)  maxSplits    = 0;
+            break;
+        }
+    }
+    /* need a struct for the deletList because we must sort it by indexOnCPU and delete in reverse order
+       so we don't have the potential problem of  deleting a particle from the list that points to the last particle on the swarm */
+    deleteList = (struct deleteParticle*)malloc(nump*sizeof(struct deleteParticle));/* I don't think I am going to let you delete more than half the particles in a given cell */
+    splitList  = (Particle_Index*)malloc(nump*sizeof(Particle_Index));
+    for(i=0;i<nump;i++){
+        if(pList[i].w > maxW){ /* maxW = pList[i].w; maxI = i;*/ splitList[splitCount] = i; splitCount++;}
+        if(pList[i].w < minW){
+            /* minW = pList[i].w; minI = i; */
+            deleteList[deleteCount].indexWithinCell = i;
+            deleteList[deleteCount].indexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ i ];		    
+            deleteCount++;
+        }
+    }
+    /* sort the deleteList by indexOnCPU so we can delete the list in reverse order */
+    qsort(deleteList, (deleteCount), sizeof(struct deleteParticle),compare_indexOnCPU);
+    //deleteCount--; /* is going to be one size too large after the loop */
+    /*
+      for(i=0;i<deleteCount;i++){
+      printf("deleteCount = %d\n",deleteCount);
+      printf("indices are indexWithinCell %d indexOnCPU %d\n",deleteList[i].indexWithinCell,deleteList[i].indexOnCPU);
+      }
+    */
+    if(maxDeletions > nump-4){ maxDeletions = nump/2;}
+
+    /* we now have our lists of particles to delete and split */
+
+//	if(pList[maxI].w > upT*8/100.0){
+    Count = maxSplits > splitCount ? splitCount : maxSplits;
+    for(i=0;i<Count;i++){
+        int j;
+        maxI = splitList[i];
+        if(!Inflow){
+            /* now get local coords from centroid of the cell that particleToSplit lives in */
+            xi[0] = pList[maxI].cx;
+            xi[1] = pList[maxI].cy;
+            xi[2] = pList[maxI].cz;
+        }
+        else{
+            /* lets do something different now..because am getting lines formed on inflow probs */
+            j =  (int) (VCsize[maxI] * (rand() / (RAND_MAX + 1.0)));
+            xi[0] = cells[ particleVoronoiCellList[maxI][j] ].x;
+            xi[1] = cells[ particleVoronoiCellList[maxI][j] ].y;
+            xi[2] = cells[ particleVoronoiCellList[maxI][j] ].z;
+        }
+        split_flag = 1;
+        nump++;
+        splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, maxI, xi );
+    }
+
+    if(Inflow){
+        for(i=0;i<nump_orig;i++){
+            free(particleVoronoiCellList[i]);
+        }
+        free(particleVoronoiCellList);
+        free(VCsize);
+        free(count);
+    }
+    Count = maxDeletions > deleteCount ? deleteCount : maxDeletions;
+    for(i=0;i<Count;i++){
+        minI = deleteList[i].indexOnCPU;
+        deleteIntParticleByIndexOnCPU( intSwarm,  matSwarm, minI );
+        delete_flag = 1;
+        nump--;
+    }
+
+    if(delete_flag || split_flag ){/* then we need to redo the Voronoi diagram */
+        for(k=0;k<nump_orig;k++){
+            free(bchain[k].new_claimed_cells);
+            free(bchain[k].new_bound_cells);
+        }
+        free(particle);
+        free(bchain);
+        free(pList);
+        if(nump < 3){
+            Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
+        }
+        // init the data structures
+        _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
+        //_DVCWeights_ResetGrid(&cells,numz*numy*numx);
+	      
+        particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));
+	
+        // re-initialize the particle positions to be the local coordinates of the material swarm particles
+        for(i=0;i<nump;i++){
+		    
+            particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
+            pList[i].x = particle[i]->xi[0];
+            pList[i].y = particle[i]->xi[1];
+            pList[i].z = particle[i]->xi[2];
+            //pList[i].index = i; // to track which particle numbers we have after sorting this list */
+		    
+        }
+        //printf("Population of matSwarm is %d\n",matSwarm->particleLocalCount);
+        //printf("Population of intSwarm is %d\n",intSwarm->particleLocalCount);
+        _DVCWeights_ResetGrid(&cells,numz*numy*numx);
+        //reset_grid(&cells,numz*numy*numx);/* adding this line fixed memory leak probs */
+        //create_voronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+        //get_centroids( cells, pList,numz,numy,numx,nump,da);
+        _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+        _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
+
+    }/* if delete_flag */
+    /******************************************/
+    /******************************************/
+    /*        End 3D Population Control       */
+    /******************************************/
+    /******************************************/
+
+    // We are setting the integration points to be the centroids of the Voronoi regions here and
+    // the weight is the volume of each Voronoi region.
+    for(i=0;i<nump;i++){
+
+        particle[i]->xi[0] = pList[i].cx;
+        particle[i]->xi[1] = pList[i].cy;
+        particle[i]->xi[2] = pList[i].cz;
+        particle[i]->weight = pList[i].w;
+
+    }	
+    for(k=0;k<nump;k++){
+        free(bchain[k].new_claimed_cells);
+        free(bchain[k].new_bound_cells);
+    }
+    free(particle);
+    free(bchain);
+    free(pList);
+    free(deleteList);
+    free(splitList);
+
+}
+
+/* Calculate the integration weighting for each particle by contructing
+   a voronoi diagram in an element in 2D*/
+void _PCDVC_Calculate2D( void* pcdvc, void* _swarm, Cell_LocalIndex lCell_I ) {
+    PCDVC*             self            = (PCDVC*)  pcdvc;
+    IntegrationPointsSwarm*  intSwarm  = (IntegrationPointsSwarm*) _swarm;
+    MaterialPointsSwarm* matSwarm =	(MaterialPointsSwarm*) self->materialPointsSwarm;
+    /* CoincidentMapper is a special case of the one to one mapper */
+    //CoincidentMapper* mapper  = (CoincidentMapper*)(intSwarm->mapper); /* need the mapper after-all to update the material ref */
+    Particle_InCellIndex         cParticleCount;
+    IntegrationPoint**           particle;
+    static int visited = 0 ;
+    //static int deleted = 0 ;
+
+    double dx,dy,da;
+    static struct cell2d *cells;// the connected grid
+    struct particle2d *pList;// particle List
+    struct chain *bchain;//boundary chain
+    int nump_orig,nump,numx,numy;
+    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
+    double BBXMAX = 1.0;
+    double BBYMIN = -1.0;
+    double BBYMAX = 1.0;
+    int i,k;
+
+    /*************************************/
+    /* stuff for particle removal/adding */
+    double maxW,minW;
+    int maxI, minI;
+    double lowT = self->lowerT;
+    double upT = self->upperT;
+    int delete_flag, split_flag;
+    struct deleteParticle* deleteList;
+    Particle_Index  *splitList;
+    int splitCount;
+    int deleteCount;
+    int maxDeletions = self->maxDeletions;/* hard setting this till I get stuff from xml file */
+    int maxSplits = self->maxSplits;
+    int Count;
+    int matTypeFirst;
+    int matType;
+    Bool splitInInterfaceCells  = self->splitInInterfaceCells;
+    Bool deleteInInterfaceCells = self->deleteInInterfaceCells;
+    Bool Inflow = self->Inflow;
+    double Thresh = self->Threshold;
+    int ParticlesPerCell = self->ParticlesPerCell;
+    double CentPosRatio = self->CentPosRatio;
+    //time_t tm;
+	
+
+//	SizeT                 intparticleSize     = intSwarm->particleExtensionMgr->finalSize;
+//	SizeT                 matparticleSize     = matSwarm->particleExtensionMgr->finalSize;
+
+//	Coord                   newCoord;
+    Coord                   xi;
+
+//	FiniteElement_Mesh*     mesh              = (FiniteElement_Mesh*)((ElementCellLayout*)matSwarm->cellLayout)->mesh;
+
+    /* end decs needed for particle control */
+    /*************************************/
+	
+
+    numx = self->resX;
+    numy = self->resY;
+
+    nump_orig = nump = cParticleCount = intSwarm->cellParticleCountTbl[lCell_I];
+
+    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"PCDVC" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
+
+    dx = (BBXMAX - BBXMIN)/numx;
+    dy = (BBYMAX - BBYMIN)/numy;
+    da = dx*dy;
+	
+    // Construct the grid for the Voronoi cells only once.
+    // If we wanted to call this function again during a job with a different resolution
+    // then we should destroy the grid once we have looped through the whole mesh.
+    // I am assuming we are not going to do that for now.
+    // Easy to implement this anyway, if needed.
+    if(!visited){
+        /* The PCDVC class should really be a class the next level up here */
+        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
+           a pointer inside that function */
+        visited++;
+        _DVCWeights_ConstructGrid2D(&cells,numy,numx,BBXMIN,BBYMIN,BBXMAX,BBYMAX);
+//	      time(&tm);
+//	      srand( (long) tm);
+    }
+	
+	
+    // init the data structures
+    _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);
+    _DVCWeights_ResetGrid2D(&cells,numy*numx);
+	
+    particle = (IntegrationPoint**)malloc((nump)*sizeof(IntegrationPoint*));
+	
+    // initialize the particle positions to be the local coordinates of the material swarm particles
+    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
+    // positions each time step.
+    for(i=0;i<nump;i++){
+	      
+        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
+        pList[i].x = particle[i]->xi[0];
+        pList[i].y = particle[i]->xi[1];
+	      
+    }
+    _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
+    _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
+/*     for(k=0;k<nump;k++){ */
+/* 	  printf("In %s O(%10.7lf %10.7lf) C(%10.7lf %10.7lf) W(%.4lf)\n", __func__, pList[k].x, pList[k].y, pList[k].cx, pList[k].cy, pList[k].w); */
+/*     } */
+      
+    /************************************/
+    /************************************/
+    /*    Start 2D Population Control   */
+    /************************************/
+    /** want to do something special for inflow problems **/
+    /** we need to be a lot more aggressive with adding particles in this case **/
+    /************************************/
+    /************************************/
+    /*      Start 2D Inflow Control     */
+    /************************************/
+    /************************************/
+//	if(0){
+    int *VCsize=NULL;
+    int **particleVoronoiCellList=NULL;
+    int *count=NULL; // count of how many cells each particle owns in the Voronoi diagram.
+    int flag =0;
+    double FEMCEllspan = BBXMAX - BBXMIN;
+    double dist=0;
+    if(Inflow){
+        for(i=0;i<nump_orig;i++){
+            dist = (pList[i].x-pList[i].cx)*(pList[i].x-pList[i].cx)+(pList[i].y-pList[i].cy)*(pList[i].y-pList[i].cy);;
+        }
+        if(dist > CentPosRatio*FEMCEllspan){flag = 1;}
+	      
+    }
+    if(Inflow && (  ((1.0*nump_orig)/ParticlesPerCell < Thresh) || flag  ) ){
+        int oneOda = (int)(1.0/da + 0.5);
+        /*double dist; */
+        /*int numberofnewpoints;*/
+        /*int newpindex;*/
+        int j;
+		  /*int countSum;*/
+        /*double wSum;*/
+        /*int *temparray;*/
+        int delNum;
+        VCsize=(int *)malloc(sizeof(int)*nump_orig);
+        count=(int *)malloc(sizeof(int)*nump_orig);
+        //wSum = 0.0;
+        //countSum = 0;
+        splitCount = 0;
+        particleVoronoiCellList = (int **)malloc(nump_orig * sizeof(int *));// [i][j] is jth cell owned by particle i
+        for(i=0;i<nump_orig;i++){ 
+            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
+            VCsize[i] = count[i];
+            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
+        }
+        for(i=0;i<numx*numy;i++){// traverse the grid
+            //count[ cells[i].p ]++;
+            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
+                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
+            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
+                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
+                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
+                //countSum++;
+            }
+        }
+        //printf("countSum = %d\n",countSum);
+        // we now have a list of cells from the grid belonging to each particle that make up each Voronoi cell in the Voronoi diagram
+        // next lets compare how far our centroids are from the particle positions.
+        // this is my criteria for a voronoi cell having a weird shape...too stretched out for example.
+        // this is exactly what happens in inflow situations.
+        // Add a random number of new particles...
+        // But Need to add them where they are needed.
+        for(i=0;i<ParticlesPerCell;i++){
+            j  =  (int) ( numx*numy * (rand() / (RAND_MAX + 1.0)));
+            xi[0] = cells[ j ].x;
+            xi[1] = cells[ j ].y;
+            splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, cells[j].p, xi );
+            nump++; splitCount++;
+        }
+        for(i=0;i<nump_orig;i++){
+            free(particleVoronoiCellList[i]);
+        }
+        free(particleVoronoiCellList);
+        free(VCsize); free(count);
+        //if(splitCount) printf("\n\e[32mnump is now %d splitCount = %d\n",nump,splitCount);
+        delNum = nump - ParticlesPerCell;
+        if(delNum > 5){
+            for(i=0;i<delNum;i++){
+                j =  (int) (nump * (rand() / (RAND_MAX + 1.0)));
+                deleteIntParticleByIndexWithinCell( intSwarm,  matSwarm, lCell_I, j );
+                nump--;
+                splitCount++;
+            }
+        }
+        //if(splitCount) printf("\e[34mnump is now %d splitCount = %d\n",nump,splitCount);;printf("\e[0;37m");
+        //printf("\n\n");
+        if(splitCount){// then redo Voronoi diagram.
+            for(k=0;k<nump_orig;k++){
+                free(bchain[k].new_claimed_cells);
+                free(bchain[k].new_bound_cells);
+            }
+            free(particle);
+            free(bchain);
+            free(pList);
+            //printf("\e[33mnump is now %d splitCount = %d\n",nump,splitCount);printf("\e[0;37m");
+            if(nump < 3){
+                Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
+            }
+            // init the data structures
+            _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);		    	      
+            particle = (IntegrationPoint**)malloc( (nump)*sizeof(IntegrationPoint*));	
+            // re-initialize the particle positions to be the local coordinates of the material swarm particles
+            // could do better here..instead of completely destroying these lists I could append to them I suppose.
+            for(i=0;i<nump;i++){		    
+                particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
+                pList[i].x = particle[i]->xi[0];
+                pList[i].y = particle[i]->xi[1];		    
+            }
+            _DVCWeights_ResetGrid2D(&cells,numy*numx);
+            _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
+            _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
+        }
+        nump_orig = nump;
+    }// if Inflow && ...
+    if(Inflow){
+        int oneOda = (int)(1.0/da + 0.5);
+        //int sumc = 0;
+        //int j;
+        //recreate the lists.
+        particleVoronoiCellList = (int **)malloc(nump * sizeof(int *));// [i][j] is jth cell owned by particle i
+        //VCsize = (int*)realloc(VCsize,nump_orig);
+        //count = (int*)realloc(count,nump_orig);
+        VCsize=(int *)malloc(sizeof(int)*nump);
+        count=(int *)malloc(sizeof(int)*nump); 
+	
+        for(i=0;i<nump;i++){ 
+            count[i] = (int)( pList[i].w*oneOda +0.5 ); // add the 0.5 so we don't lose anything from rounding down accidentally
+            VCsize[i] = count[i];
+            particleVoronoiCellList[i] = (int *)malloc( ( 1 + count[i] ) * sizeof(int));
+        }
+        for(i=0;i<numx*numy;i++){// traverse the grid
+            //count[ cells[i].p ]++;
+            /** for total volume of a cell i.e. how many cells a particle owns .. this is actually calculated
+                internally in the Centroids function and could be also accessed by dividing the weight of a particle by 'da'. **/
+            //if(VCsize[cells[i].p] != 0){// in case a particle is unresolved
+            if( count[cells[i].p] > 0 ){// it's possible for the total count to be a little off...this can cause a negative index
+                particleVoronoiCellList[ cells[i].p ][ count[cells[i].p]-1 ] = i;
+                count[cells[i].p] = count[cells[i].p] - 1;//decrement the count to insert i value into correct slot.
+                //countSum++;
+            }
+            //}
+        }
+        /*
+          for(i=0;i<nump;i++){
+          for(j=0;j<VCsize[i];j++){
+          sumc +=  1;
+          }
+          }
+        */
+        //printf("sumc = %d cell = %d\n",sumc,lCell_I);
+    }//if Inflow
+    /************************************/
+    /************************************/
+    /*        End 2D Inflow Control     */
+    /************************************/
+    /************************************/
+    split_flag = 0;
+    delete_flag = 0;
+    splitCount = 0;
+    deleteCount = 0;
+    /* shouldn't need maxI and minI now */
+    maxW = upT*4/100.0;
+    minW = lowT*4/100.0;
+    /* check to see if we are in an interface cell.
+       We never want to delete particles in an interface cell */
+    matTypeFirst = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ 0 ]);
+    for(i=0;i<nump;i++){
+        matType = IntegrationPointMapper_GetMaterialIndexAt(intSwarm->mapper,intSwarm->cellParticleTbl[ lCell_I ][ i ]);
+        if(matType != matTypeFirst){
+            if(!deleteInInterfaceCells) maxDeletions = 0; /* no deletions in an interface cell */
+            /* this may be inadequate...we may need to do something in the neighbouring cells to interface cells as well */
+            if(!splitInInterfaceCells)  maxSplits    = 0;
+            //printf("------- FOUND an Interface Cell!! --------------\n");
+            break;
+        }
+    }
+    /* need a struct for the deletList because we must sort it bu indexOnCPU and delete in reverse order
+       so we don't have the potential problem of  deleting a particle from the list that points to the last particle on the swarm */
+    splitList  = (Particle_Index*)malloc(nump*sizeof(Particle_Index));	
+    deleteList = (struct deleteParticle*)malloc(nump*sizeof(struct deleteParticle));/* I don't think I am going to let you delete more than half the particles in a given cell */	
+    for(i=0;i<nump;i++){
+        if(pList[i].w > maxW){ /* maxW = pList[i].w; maxI = i;*/ splitList[splitCount] = i; splitCount++;}
+        if(pList[i].w < minW){
+            /* minW = pList[i].w; minI = i; */
+            deleteList[deleteCount].indexWithinCell = i;
+            deleteList[deleteCount].indexOnCPU  = intSwarm->cellParticleTbl[ lCell_I ][ i ];		    
+            deleteCount++;
+        }
+    }
+    /* sort the deleteList by indexOnCPU so we can delete the list in reverse order */
+    qsort(deleteList, (deleteCount), sizeof(struct deleteParticle),compare_indexOnCPU);
+    //deleteCount--; /* is going to be one size too large after the loop */
+    /*
+      for(i=0;i<deleteCount;i++){
+      printf("deleteCount = %d\n",deleteCount);
+      printf("indices are indexWithinCell %d indexOnCPU %d\n",deleteList[i].indexWithinCell,deleteList[i].indexOnCPU);
+      }
+    */
+
+    if(maxDeletions > nump-4){ maxDeletions = Inflow ? nump - 4 : nump/2;}
+
+    /* we now have our lists of particles to delete and split */
+    Count = maxSplits > splitCount ? splitCount : maxSplits;
+    /* lets do something different now..because am getting lines formed on inflow probs */
+    //if(Inflow){ Count = 0;} //turn off ordinary splitting if inflow is on for moment      
+    for(i=0;i<Count;i++){
+        int j;
+        maxI = splitList[i];
+        if(!Inflow){
+            /* now get local coords from centroid of the cell that particleToSplit lives in */
+            xi[0] = pList[maxI].cx;
+            xi[1] = pList[maxI].cy;
+        }
+        else{
+            /* lets do something different now..because am getting lines formed on inflow probs */
+            j =  (int) (VCsize[maxI] * (rand() / (RAND_MAX + 1.0)));
+            xi[0] = cells[ particleVoronoiCellList[maxI][j] ].x;
+            xi[1] = cells[ particleVoronoiCellList[maxI][j] ].y;
+        }     
+        split_flag = 1;
+        nump++;
+        splitIntParticleByIndexWithinCell( intSwarm, matSwarm, lCell_I, maxI, xi );
+    }
+
+    if(Inflow){
+        for(i=0;i<nump_orig;i++){
+            free(particleVoronoiCellList[i]);
+        }
+        free(particleVoronoiCellList);
+        free(VCsize);
+        free(count);
+    }
+
+    Count = maxDeletions > deleteCount ? deleteCount : maxDeletions;
+    for(i=0;i<Count;i++){
+        minI = deleteList[i].indexOnCPU;
+        deleteIntParticleByIndexOnCPU( intSwarm,  matSwarm, minI );
+        delete_flag = 1;
+        nump--;
+    }
+    //printf("pList[maxI].w = %lf particle num = %d : %d\n", pList[maxI].w, pList[maxI].index,maxI);
+    //printf("pList[minI].w = %lf particle num = %d : %d\n", pList[minI].w, pList[minI].index,minI);
+    if(delete_flag || split_flag ){/* then we need to redo the Voronoi diagram */
+        for(k=0;k<nump_orig;k++){
+            free(bchain[k].new_claimed_cells);
+            free(bchain[k].new_bound_cells);
+        }
+        free(particle);
+        free(bchain);
+        free(pList);
+        if(nump < 3){
+            Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"PCDVC" ), "Something went horribly wrong in %s: Problem has an under resolved cell (Cell Id = %d), check or tune your population control parameters\n", __func__, lCell_I );
+        }
+        particle = (IntegrationPoint**)malloc((nump)*sizeof(IntegrationPoint*));
+        // init the data structures
+        _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);
+        // re-initialize the particle positions to be the local coordinates of the material swarm particles
+        for(i=0;i<nump;i++){
+		    
+            particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( intSwarm, lCell_I, i );
+            pList[i].x = particle[i]->xi[0];
+            pList[i].y = particle[i]->xi[1];
+            //pList[i].index = i; // to track which particle numbers we have after sorting this list */
+		    
+        }
+        //printf("Population of matSwarm is %d\n",matSwarm->particleLocalCount);
+        //printf("Population of intSwarm is %d\n",intSwarm->particleLocalCount);
+
+        _DVCWeights_ResetGrid2D(&cells,numy*numx);
+        //reset_grid(&cells,numz*numy*numx);/* adding this line fixed memory leak probs */
+        _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
+        _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
+
+    }/* if delete_flag */
+    /**************************************/
+    /**************************************/
+    /*      End 2D Population Control     */
+    /**************************************/
+    /**************************************/
+
+
+    // We are setting the integration points to be the centroids of the Voronoi regions here and
+    // the weight is the volume of each Voronoi region.
+    for(i=0;i<nump;i++){
+
+        particle[i]->xi[0] = pList[i].cx;
+        particle[i]->xi[1] = pList[i].cy;
+        particle[i]->weight = pList[i].w;
+
+    }	
+    /* for(k=0;k<nump;k++){ */
+/* 	  printf("::In %s O(%10.7lf %10.7lf) C(%10.7lf %10.7lf) W(%.4lf)\n", __func__, pList[k].x, pList[k].y, pList[k].cx, pList[k].cy, pList[k].w); */
+/*     } */
+    for(k=0;k<nump;k++){
+        free(bchain[k].new_claimed_cells);
+        free(bchain[k].new_bound_cells);
+    }
+    free(particle);
+    free(bchain);
+    free(pList);
+    free(deleteList);
+    free(splitList);
+    /*
+      FILE *fp;
+      fp=fopen("nump.txt","a");
+      if(lCell_I< 33){
+      fprintf(fp,"nump = %d cell = %d\n",nump,lCell_I);
+      }
+      fclose(fp);
+    */
+}
+
+void _PCDVC_Calculate( void* pcdvc, void* _swarm, Cell_LocalIndex lCell_I ){
+    Swarm* swarm = (Swarm*) _swarm;
+    Dimension_Index dim = swarm->dim;
+    /* Stream*  stream = Journal_Register( Info_Type, (Name)swarm->type ); */
+    PCDVC*             self            = (PCDVC*)  pcdvc;
+    /* MaterialPointsSwarm* matSwarm =	(MaterialPointsSwarm*) self->materialPointsSwarm; */
+    /* it might be nice to report the total deletions and splits as well as the final population here */
+    /* One could set the parameters to be too aggressive and cause "swarm thrashing" where many particles
+       are being created and destroyed while maintaining some population that it has converged on */
+
+/*
+  if(lCell_I == 0 ){
+  Journal_Printf( stream, "\nOn Proc %d: In func %s(): for swarm \"%s\" Population is %d\n", swarm->myRank, __func__, swarm->name, swarm->particleLocalCount );
+  Journal_Printf( stream, "On Proc %d: In func %s(): for swarm \"%s\" Population is %d\n\n", matSwarm->myRank,__func__, matSwarm->name, matSwarm->particleLocalCount );
+  }      
+*/
+    if(dim == 3)
+        _PCDVC_Calculate3D( pcdvc, _swarm, lCell_I);
+    else
+        _PCDVC_Calculate2D( pcdvc, _swarm, lCell_I);
+
+    /* reset the below parameters incase they were originally set for interpolation restarts */
+    if(lCell_I == swarm->cellLocalCount - 1){
+        self->maxDeletions           = self->maxDeletions_orig;
+        self->maxSplits              = self->maxSplits_orig;
+        self->Inflow                 = self->Inflow_orig;
+        self->splitInInterfaceCells  = self->splitInInterfaceCells_orig;
+        self->deleteInInterfaceCells = self->deleteInInterfaceCells_orig;
+    }
+
+}
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 Utils/tests/PCDVCSuite.c
--- a/Utils/tests/PCDVCSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,365 +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 PCDVCSuite
-**
-** $Id: testPCDVC.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/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-//#include "PICellerator/PopulationControl/PopulationControl.h"
-//#include "PICellerator/Weights/Weights.h"
-#include <PICellerator/PICellerator.h>
-#include "PCDVCSuite.h"
-
-#define CURR_MODULE_NAME "PCDVCSuite"
-
-typedef struct {
-} PCDVCSuiteData;
-
-extern void _IntegrationPointsSwarm_UpdateHook( void* timeIntegrator, void* swarm );
-
-void ConstantFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	*value = -3.0;
-}
-void LinearFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-	double y = xi[1];
-
-	*value = 2.0 + 2.2 * x - y;
-}
-void ShapeFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-	double y = xi[1];
-
-	*value = 1 + x + y + x * y;
-}
-void PolynomialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-	double y = xi[1];
-
-	*value = 11 + 2*x*x + 3*x*x*x*y + y + x*x*x + 2*y*y;
-}
-void QuadraticFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-
-	*value = 1 + x + x * x;
-}
-
-void ExponentialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-	double y = xi[1];
-
-	*value = 5*exp(2*x*x*x + 2*y*y*y) * (1-x) * (1+y);
-}
-void ExponentialInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-	double y = xi[1];
-
-	*value = (double) (y <= 0.1 * exp( 2*x ));
-}
-void CircleInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-	double x = xi[0];
-	double y = xi[1];
-
-	*value = (double) (x*x + y*y <= 1.0);
-}
-
-void PCDVCSuite_Setup( PCDVCSuiteData* data ) {
-}
-
-void PCDVCSuite_Teardown( PCDVCSuiteData* data ) {
-}
-
-void compareAgainstReferenceSolution(PICelleratorContext* context, Stream* stream, double mean, double standardDeviation, Name expFile) {
-	double 	meanTolerance, stdDevTolerance;
-	double 	expectedMean, expectedStdDev;
-	char		expectedFile[PCU_PATH_MAX];
-	FILE*		expectedfp;
-
-	pcu_filename_expected( expFile, expectedFile );
-	expectedfp = fopen( expectedFile, "r" );
-
-	fscanf( expectedfp, "%lf %lf", &meanTolerance, &expectedMean );
-	pcu_check_true( fabs( expectedMean - mean ) < meanTolerance );
-
-	fscanf( expectedfp, "%lf %lf", &stdDevTolerance, &expectedStdDev );
-	pcu_check_true( fabs( expectedStdDev - standardDeviation ) < stdDevTolerance );
-	
-	fclose( expectedfp );
-}
-
-void testElementIntegral_CircleInterface( PICelleratorContext* context, double* mean, double* standardDeviation ) {
-	Swarm*					integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
-	Swarm*					materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
-	FeMesh*					mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
-	FeVariable*				feVariable;
-	Element_LocalIndex 	lElement_I       = 0;
-	double					analyticValue    = 0.0;
-	double					integral         = 0.0;
-	double					error;
-	double					errorSquaredSum  = 0.0;
-	double					errorSum         = 0.0;
-	Index						loop_I;
-	Index						count            = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "SampleSize", 5000 );
-	void*						data=NULL;
-		      IntegrationPoint* intParticle;
-		      MaterialPoint*  materialPoint;
-	/* Create FeVariable */
-	feVariable = FeVariable_New_Full(
-		"feVariable",
-		(DomainContext*) context,
-		mesh,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL, 
-		1,
-		context->dim,
-		False,
-		False,
-		False,
-		MPI_COMM_WORLD,
-		context->fieldVariable_Register );
-
-	feVariable->_interpolateWithinElement = CircleInterface;
-	analyticValue = M_PI;
-
-	for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
-		/* Layout Particles */
-		Swarm_Random_Seed( (long) loop_I );
-		_Swarm_InitialiseParticles( materialSwarm, data );
-
-		_IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
-		/* The following function should not be called here as it is already called ultimately via the above function */
-		/* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
-		//WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
-		if(loop_I%10 == 0){
-		      Index i;
-
-		      for(i=0;i<integrationSwarm->cellParticleCountTbl[0];i++){
-			    intParticle  =  (IntegrationPoint*)Swarm_ParticleInCellAt( integrationSwarm, 0, i );
-			    materialPoint = (MaterialPoint*)Swarm_ParticleInCellAt( materialSwarm, 0, i );
-			    //printf("In %s M(%10.7lf %10.7lf) I(%10.7lf %10.7lf) W(%.4lf) particle layout type %s: point %d in cell %d\n",__func__,materialPoint->coord[0], materialPoint->coord[1],
-			//	   intParticle->xi[0], intParticle->xi[1], intParticle->weight, materialSwarm->particleLayout->type, i, 0);
-		
-			    //printf("%lf %lf\n",intParticle->xi[0],intParticle->xi[1]);
-		      }
-                }
-
-		/* Evaluate Integral */
-		integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
-
-		/* Calculate Error */
-		error = fabs( ( integral - analyticValue )/( analyticValue ) );
-		errorSum += error;
-		errorSquaredSum += error*error;
-	}
-
-	/* Calculate Mean and Standard Deviation */
-	*mean = errorSum / (double) count;
-	*standardDeviation = sqrt( errorSquaredSum / (double) count - *mean * *mean );
-	printf("In %s: Mean %lf SD %lf Sol %lf Count = %d\n", __func__, *mean, *standardDeviation, analyticValue,   count);
-	Stg_Component_Destroy( feVariable, NULL, True );
-}
-
-void testElementIntegral_PolynomialFunction( PICelleratorContext* context, double* mean, double* standardDeviation ) {
-	Swarm*					integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
-	Swarm*					materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
-	FeMesh*					mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
-	FeVariable*				feVariable;
-	Element_LocalIndex 	lElement_I       = 0;
-	double					analyticValue    = 0.0;
-	double					integral         = 0.0;
-	double					error;
-	double					errorSquaredSum  = 0.0;
-	double					errorSum         = 0.0;
-	Index						loop_I;
-	Index						count            = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "SampleSize", 5000 );
-	void*						data=NULL;
-
-	/* Create FeVariable */
-	feVariable = FeVariable_New_Full(
-		"feVariable",
-		(DomainContext*) context,
-		mesh,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL, 
-		1,
-		context->dim,
-		False,
-		False,
-		False,
-		MPI_COMM_WORLD,
-		context->fieldVariable_Register );
-
-	feVariable->_interpolateWithinElement = PolynomialFunction;
-	analyticValue = 148.0/3.0;
-
-	for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
-		/* Layout Particles */
-		Swarm_Random_Seed( (long) loop_I );
-		_Swarm_InitialiseParticles( materialSwarm, data );
-
-		_IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
-		/* The following function should not be called here as it is already called ultimately via the above function */
-		/* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
-		//WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
-
-		/* Evaluate Integral */
-		integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
-
-		/* Calculate Error */
-		error = fabs( integral - analyticValue )/fabs( analyticValue );
-		errorSum += error;
-		errorSquaredSum += error*error;
-	}
-
-	/* Calculate Mean and Standard Deviation */
-	*mean = errorSum / (double) count;
-	*standardDeviation = sqrt( errorSquaredSum / (double) count - *mean * *mean );
-	printf("In %s: Mean %lf SD %lf Sol %lf\n", __func__, *mean, *standardDeviation, analyticValue);
-	Stg_Component_Destroy( feVariable, NULL, True );
-}
-
-void testElementIntegral_ExponentialInterface( PICelleratorContext* context, double* mean, double* standardDeviation ) {
-	Swarm*              integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
-	Swarm*              materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
-	FeMesh* 	    mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
-	FeVariable*         feVariable;
-	Element_LocalIndex  lElement_I       = 0;
-	double              analyticValue    = 0.0;
-	double              integral         = 0.0;
-	double              error;
-	double              errorSquaredSum  = 0.0;
-	double              errorSum         = 0.0;
-	Index               loop_I;
-	Index               count            = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "SampleSize", 5000 );
-	void*               data=NULL;
-
-	/* Create FeVariable */
-	feVariable = FeVariable_New_Full(
-		"feVariable",
-		(DomainContext*) context,
-		mesh,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL, 
-		1,
-		context->dim,
-		False,
-		False,
-		False,
-		MPI_COMM_WORLD,
-		context->fieldVariable_Register );
-
-	feVariable->_interpolateWithinElement = ExponentialInterface;
-	analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;
-
-	for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
-		/* Layout Particles */
-		Swarm_Random_Seed( (long) loop_I );
-		_Swarm_InitialiseParticles( materialSwarm, data );
-
-		_IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
-		/* The following function should not be called here as it is already called ultimately via the above function */
-		/* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
-		//WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
-
-		/* Evaluate Integral */
-		integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
-
-		/* Calculate Error */
-		error = fabs( integral - analyticValue )/fabs( analyticValue );
-		errorSum += error;
-		errorSquaredSum += error*error;
-	}
-
-	/* Calculate Mean and Standard Deviation */
-	*mean = errorSum / (double) count;
-	*standardDeviation = sqrt( errorSquaredSum / (double) count - *mean * *mean );
-	printf("In %s: Mean %lf SD %lf Sol %lf\n", __func__, *mean, *standardDeviation, analyticValue);
-	Stg_Component_Destroy( feVariable, NULL, True );
-}
-
-void PCDVCSuite_Test( PCDVCSuiteData* data ) {
-	PICelleratorContext*	context;
-	Stg_ComponentFactory*	cf;
-	char			inputFile[PCU_PATH_MAX];
-	Stream*			stream           = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
-	double			mean;
-	double			standardDeviation;
-
-	pcu_filename_input( "testPCDVC.xml", inputFile );
-
-   /* rejigged this test to clean up after each run */
-	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
-	cf = stgMainInitFromXML( inputFile, MPI_COMM_WORLD, context );
-	stgMainBuildAndInitialise( cf );
-	testElementIntegral_CircleInterface( context, &mean, &standardDeviation );
-	compareAgainstReferenceSolution(context, stream, mean, standardDeviation, "testPCDVC_CircleInterface.expected" );
-	stgMainDestroy( cf );
-
-        context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
-	cf = stgMainInitFromXML( inputFile, MPI_COMM_WORLD, context );
-	stgMainBuildAndInitialise( cf );
-	testElementIntegral_PolynomialFunction( context, &mean, &standardDeviation );
-	compareAgainstReferenceSolution(context, stream, mean, standardDeviation, "testPCDVC_PolynomialFunction.expected" );
-	stgMainDestroy( cf );
-
-        context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
-	cf = stgMainInitFromXML( inputFile, MPI_COMM_WORLD, context );
-	stgMainBuildAndInitialise( cf );
-	testElementIntegral_ExponentialInterface( context, &mean, &standardDeviation );
-	compareAgainstReferenceSolution(context, stream, mean, standardDeviation, "testPCDVC_ExponentialInterface.expected" );
-	stgMainDestroy( cf );
-}
-
-
-void PCDVCSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, PCDVCSuiteData );
-   pcu_suite_setFixtures( suite, PCDVCSuite_Setup, PCDVCSuite_Teardown );
-   pcu_suite_addTest( suite, PCDVCSuite_Test );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Utils/tests/PCDVCSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/tests/PCDVCSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,365 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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 PCDVCSuite
+**
+** $Id: testPCDVC.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/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+//#include "PICellerator/PopulationControl/PopulationControl.h"
+//#include "PICellerator/Weights/Weights.h"
+#include <PICellerator/PICellerator.h>
+#include "PCDVCSuite.h"
+
+#define CURR_MODULE_NAME "PCDVCSuite"
+
+typedef struct {
+} PCDVCSuiteData;
+
+extern void _IntegrationPointsSwarm_UpdateHook( void* timeIntegrator, void* swarm );
+
+void ConstantFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	*value = -3.0;
+}
+void LinearFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+	double y = xi[1];
+
+	*value = 2.0 + 2.2 * x - y;
+}
+void ShapeFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+	double y = xi[1];
+
+	*value = 1 + x + y + x * y;
+}
+void PolynomialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+	double y = xi[1];
+
+	*value = 11 + 2*x*x + 3*x*x*x*y + y + x*x*x + 2*y*y;
+}
+void QuadraticFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+
+	*value = 1 + x + x * x;
+}
+
+void ExponentialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+	double y = xi[1];
+
+	*value = 5*exp(2*x*x*x + 2*y*y*y) * (1-x) * (1+y);
+}
+void ExponentialInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+	double y = xi[1];
+
+	*value = (double) (y <= 0.1 * exp( 2*x ));
+}
+void CircleInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+	double x = xi[0];
+	double y = xi[1];
+
+	*value = (double) (x*x + y*y <= 1.0);
+}
+
+void PCDVCSuite_Setup( PCDVCSuiteData* data ) {
+}
+
+void PCDVCSuite_Teardown( PCDVCSuiteData* data ) {
+}
+
+void compareAgainstReferenceSolution(PICelleratorContext* context, Stream* stream, double mean, double standardDeviation, Name expFile) {
+	double 	meanTolerance, stdDevTolerance;
+	double 	expectedMean, expectedStdDev;
+	char		expectedFile[PCU_PATH_MAX];
+	FILE*		expectedfp;
+
+	pcu_filename_expected( expFile, expectedFile );
+	expectedfp = fopen( expectedFile, "r" );
+
+	fscanf( expectedfp, "%lf %lf", &meanTolerance, &expectedMean );
+	pcu_check_true( fabs( expectedMean - mean ) < meanTolerance );
+
+	fscanf( expectedfp, "%lf %lf", &stdDevTolerance, &expectedStdDev );
+	pcu_check_true( fabs( expectedStdDev - standardDeviation ) < stdDevTolerance );
+	
+	fclose( expectedfp );
+}
+
+void testElementIntegral_CircleInterface( PICelleratorContext* context, double* mean, double* standardDeviation ) {
+	Swarm*					integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
+	Swarm*					materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
+	FeMesh*					mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
+	FeVariable*				feVariable;
+	Element_LocalIndex 	lElement_I       = 0;
+	double					analyticValue    = 0.0;
+	double					integral         = 0.0;
+	double					error;
+	double					errorSquaredSum  = 0.0;
+	double					errorSum         = 0.0;
+	Index						loop_I;
+	Index						count            = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "SampleSize", 5000 );
+	void*						data=NULL;
+		      IntegrationPoint* intParticle;
+		      MaterialPoint*  materialPoint;
+	/* Create FeVariable */
+	feVariable = FeVariable_New_Full(
+		"feVariable",
+		(DomainContext*) context,
+		mesh,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL, 
+		1,
+		context->dim,
+		False,
+		False,
+		False,
+		MPI_COMM_WORLD,
+		context->fieldVariable_Register );
+
+	feVariable->_interpolateWithinElement = CircleInterface;
+	analyticValue = M_PI;
+
+	for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
+		/* Layout Particles */
+		Swarm_Random_Seed( (long) loop_I );
+		_Swarm_InitialiseParticles( materialSwarm, data );
+
+		_IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
+		/* The following function should not be called here as it is already called ultimately via the above function */
+		/* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
+		//WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
+		if(loop_I%10 == 0){
+		      Index i;
+
+		      for(i=0;i<integrationSwarm->cellParticleCountTbl[0];i++){
+			    intParticle  =  (IntegrationPoint*)Swarm_ParticleInCellAt( integrationSwarm, 0, i );
+			    materialPoint = (MaterialPoint*)Swarm_ParticleInCellAt( materialSwarm, 0, i );
+			    //printf("In %s M(%10.7lf %10.7lf) I(%10.7lf %10.7lf) W(%.4lf) particle layout type %s: point %d in cell %d\n",__func__,materialPoint->coord[0], materialPoint->coord[1],
+			//	   intParticle->xi[0], intParticle->xi[1], intParticle->weight, materialSwarm->particleLayout->type, i, 0);
+		
+			    //printf("%lf %lf\n",intParticle->xi[0],intParticle->xi[1]);
+		      }
+                }
+
+		/* Evaluate Integral */
+		integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
+
+		/* Calculate Error */
+		error = fabs( ( integral - analyticValue )/( analyticValue ) );
+		errorSum += error;
+		errorSquaredSum += error*error;
+	}
+
+	/* Calculate Mean and Standard Deviation */
+	*mean = errorSum / (double) count;
+	*standardDeviation = sqrt( errorSquaredSum / (double) count - *mean * *mean );
+	printf("In %s: Mean %lf SD %lf Sol %lf Count = %d\n", __func__, *mean, *standardDeviation, analyticValue,   count);
+	Stg_Component_Destroy( feVariable, NULL, True );
+}
+
+void testElementIntegral_PolynomialFunction( PICelleratorContext* context, double* mean, double* standardDeviation ) {
+	Swarm*					integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
+	Swarm*					materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
+	FeMesh*					mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
+	FeVariable*				feVariable;
+	Element_LocalIndex 	lElement_I       = 0;
+	double					analyticValue    = 0.0;
+	double					integral         = 0.0;
+	double					error;
+	double					errorSquaredSum  = 0.0;
+	double					errorSum         = 0.0;
+	Index						loop_I;
+	Index						count            = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "SampleSize", 5000 );
+	void*						data=NULL;
+
+	/* Create FeVariable */
+	feVariable = FeVariable_New_Full(
+		"feVariable",
+		(DomainContext*) context,
+		mesh,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL, 
+		1,
+		context->dim,
+		False,
+		False,
+		False,
+		MPI_COMM_WORLD,
+		context->fieldVariable_Register );
+
+	feVariable->_interpolateWithinElement = PolynomialFunction;
+	analyticValue = 148.0/3.0;
+
+	for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
+		/* Layout Particles */
+		Swarm_Random_Seed( (long) loop_I );
+		_Swarm_InitialiseParticles( materialSwarm, data );
+
+		_IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
+		/* The following function should not be called here as it is already called ultimately via the above function */
+		/* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
+		//WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
+
+		/* Evaluate Integral */
+		integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
+
+		/* Calculate Error */
+		error = fabs( integral - analyticValue )/fabs( analyticValue );
+		errorSum += error;
+		errorSquaredSum += error*error;
+	}
+
+	/* Calculate Mean and Standard Deviation */
+	*mean = errorSum / (double) count;
+	*standardDeviation = sqrt( errorSquaredSum / (double) count - *mean * *mean );
+	printf("In %s: Mean %lf SD %lf Sol %lf\n", __func__, *mean, *standardDeviation, analyticValue);
+	Stg_Component_Destroy( feVariable, NULL, True );
+}
+
+void testElementIntegral_ExponentialInterface( PICelleratorContext* context, double* mean, double* standardDeviation ) {
+	Swarm*              integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
+	Swarm*              materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
+	FeMesh* 	    mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
+	FeVariable*         feVariable;
+	Element_LocalIndex  lElement_I       = 0;
+	double              analyticValue    = 0.0;
+	double              integral         = 0.0;
+	double              error;
+	double              errorSquaredSum  = 0.0;
+	double              errorSum         = 0.0;
+	Index               loop_I;
+	Index               count            = Dictionary_GetUnsignedInt_WithDefault( context->dictionary, "SampleSize", 5000 );
+	void*               data=NULL;
+
+	/* Create FeVariable */
+	feVariable = FeVariable_New_Full(
+		"feVariable",
+		(DomainContext*) context,
+		mesh,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL, 
+		1,
+		context->dim,
+		False,
+		False,
+		False,
+		MPI_COMM_WORLD,
+		context->fieldVariable_Register );
+
+	feVariable->_interpolateWithinElement = ExponentialInterface;
+	analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;
+
+	for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
+		/* Layout Particles */
+		Swarm_Random_Seed( (long) loop_I );
+		_Swarm_InitialiseParticles( materialSwarm, data );
+
+		_IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
+		/* The following function should not be called here as it is already called ultimately via the above function */
+		/* calling this function again causes a first iteration in Lloyd's algorithm for the Voronoi cells which we don't want here */
+		//WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
+
+		/* Evaluate Integral */
+		integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
+
+		/* Calculate Error */
+		error = fabs( integral - analyticValue )/fabs( analyticValue );
+		errorSum += error;
+		errorSquaredSum += error*error;
+	}
+
+	/* Calculate Mean and Standard Deviation */
+	*mean = errorSum / (double) count;
+	*standardDeviation = sqrt( errorSquaredSum / (double) count - *mean * *mean );
+	printf("In %s: Mean %lf SD %lf Sol %lf\n", __func__, *mean, *standardDeviation, analyticValue);
+	Stg_Component_Destroy( feVariable, NULL, True );
+}
+
+void PCDVCSuite_Test( PCDVCSuiteData* data ) {
+	PICelleratorContext*	context;
+	Stg_ComponentFactory*	cf;
+	char			inputFile[PCU_PATH_MAX];
+	Stream*			stream           = Journal_Register( Info_Type, (Name)CURR_MODULE_NAME  );
+	double			mean;
+	double			standardDeviation;
+
+	pcu_filename_input( "testPCDVC.xml", inputFile );
+
+   /* rejigged this test to clean up after each run */
+	context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
+	cf = stgMainInitFromXML( inputFile, MPI_COMM_WORLD, context );
+	stgMainBuildAndInitialise( cf );
+	testElementIntegral_CircleInterface( context, &mean, &standardDeviation );
+	compareAgainstReferenceSolution(context, stream, mean, standardDeviation, "testPCDVC_CircleInterface.expected" );
+	stgMainDestroy( cf );
+
+        context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
+	cf = stgMainInitFromXML( inputFile, MPI_COMM_WORLD, context );
+	stgMainBuildAndInitialise( cf );
+	testElementIntegral_PolynomialFunction( context, &mean, &standardDeviation );
+	compareAgainstReferenceSolution(context, stream, mean, standardDeviation, "testPCDVC_PolynomialFunction.expected" );
+	stgMainDestroy( cf );
+
+        context = (PICelleratorContext*)_PICelleratorContext_DefaultNew( "context" );
+	cf = stgMainInitFromXML( inputFile, MPI_COMM_WORLD, context );
+	stgMainBuildAndInitialise( cf );
+	testElementIntegral_ExponentialInterface( context, &mean, &standardDeviation );
+	compareAgainstReferenceSolution(context, stream, mean, standardDeviation, "testPCDVC_ExponentialInterface.expected" );
+	stgMainDestroy( cf );
+}
+
+
+void PCDVCSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, PCDVCSuiteData );
+   pcu_suite_setFixtures( suite, PCDVCSuite_Setup, PCDVCSuite_Teardown );
+   pcu_suite_addTest( suite, PCDVCSuite_Test );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/ConstantWeights.c
--- a/Weights/src/ConstantWeights.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,198 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**      Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**      Victoria, 3800, 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
-**
-** Contributors:
-**      Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**      Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**      David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**      Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**      Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**      David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**      Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: ConstantWeights.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "types.h"
-#include "WeightsCalculator.h"
-#include "ConstantWeights.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type ConstantWeights_Type = "ConstantWeights";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-ConstantWeights* ConstantWeights_New( Name name, int dim ) {
-  ConstantWeights *self = (ConstantWeights*)_ConstantWeights_DefaultNew( name );
-
-    self->isConstructed = True;
-    _WeightsCalculator_Init( self, dim );
-    _ConstantWeights_Init( self );
-
-	return self;
-}
-
-ConstantWeights* _ConstantWeights_New(  CONSTANTWEIGHTS_DEFARGS  ) {
-    ConstantWeights* self;
-
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(ConstantWeights) );
-    self = (ConstantWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  );
-
-    /* General info */
-
-    /* Virtual Info */
-
-    return self;
-}
-
-void _ConstantWeights_Init( void* constantWeights  ) {
-	ConstantWeights* self;
-		
-	self = (ConstantWeights*)constantWeights;
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _ConstantWeights_Delete( void* constantWeights ) {
-    ConstantWeights* self = (ConstantWeights*)constantWeights;
-        
-    /* Delete parent */
-    _WeightsCalculator_Delete( self );
-}
-
-
-void _ConstantWeights_Print( void* constantWeights, Stream* stream ) {
-    ConstantWeights* self = (ConstantWeights*)constantWeights;
-        
-    /* Print parent */
-    _WeightsCalculator_Print( self, stream );
-}
-
-
-
-void* _ConstantWeights_Copy( const void* constantWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    ConstantWeights*    self = (ConstantWeights*)constantWeights;
-    ConstantWeights*    newConstantWeights;
-        
-    newConstantWeights = (ConstantWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
-        
-    return (void*)newConstantWeights;
-}
-
-void* _ConstantWeights_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(ConstantWeights);
-	Type                                                      type = ConstantWeights_Type;
-	Stg_Class_DeleteFunction*                              _delete = _ConstantWeights_Delete;
-	Stg_Class_PrintFunction*                                _print = _ConstantWeights_Print;
-	Stg_Class_CopyFunction*                                  _copy = _ConstantWeights_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _ConstantWeights_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _ConstantWeights_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _ConstantWeights_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _ConstantWeights_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _ConstantWeights_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _ConstantWeights_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	WeightsCalculator_CalculateFunction*                _calculate = _ConstantWeights_Calculate;
-
-    return (void*) _ConstantWeights_New(  CONSTANTWEIGHTS_PASSARGS  );
-}
-
-
-void _ConstantWeights_AssignFromXML( void* constantWeights, Stg_ComponentFactory* cf, void* data ) {
-    ConstantWeights*         self          = (ConstantWeights*) constantWeights;
-
-    _WeightsCalculator_AssignFromXML( self, cf, data );
-        
-    _ConstantWeights_Init( self );
-}
-
-void _ConstantWeights_Build( void* constantWeights, void* data ) {
-    ConstantWeights*    self = (ConstantWeights*)constantWeights;
-
-    _WeightsCalculator_Build( self, data );
-}
-
-void _ConstantWeights_Destroy( void* constantWeights, void* data ) {
-    ConstantWeights*    self = (ConstantWeights*)constantWeights;
-
-    _WeightsCalculator_Destroy( self, data );
-}
-
-void _ConstantWeights_Initialise( void* constantWeights, void* data ) {
-    ConstantWeights*    self = (ConstantWeights*)constantWeights;
-        
-    _WeightsCalculator_Initialise( self, data );
-}
-void _ConstantWeights_Execute( void* constantWeights, void* data ) {
-    ConstantWeights*    self = (ConstantWeights*)constantWeights;
-        
-    _WeightsCalculator_Execute( self, data );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-void _ConstantWeights_Calculate( void* constantWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    ConstantWeights*             self            = (ConstantWeights*)  constantWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    double                       weight;
-    Particle_InCellIndex         cParticleCount;
-                
-    cParticleCount = swarm->cellParticleCountTbl[lCell_I];
-    weight = self->cellLocalVolume / (double) cParticleCount;
-    WeightsCalculator_SetWeightsValueAllInCell( self, swarm, lCell_I, weight );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/ConstantWeights.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/ConstantWeights.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,198 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**      Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**      Victoria, 3800, 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
+**
+** Contributors:
+**      Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**      Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**      David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**      Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**      Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**      David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**      Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: ConstantWeights.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "types.h"
+#include "WeightsCalculator.h"
+#include "ConstantWeights.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type ConstantWeights_Type = "ConstantWeights";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+ConstantWeights* ConstantWeights_New( Name name, int dim ) {
+  ConstantWeights *self = (ConstantWeights*)_ConstantWeights_DefaultNew( name );
+
+    self->isConstructed = True;
+    _WeightsCalculator_Init( self, dim );
+    _ConstantWeights_Init( self );
+
+	return self;
+}
+
+ConstantWeights* _ConstantWeights_New(  CONSTANTWEIGHTS_DEFARGS  ) {
+    ConstantWeights* self;
+
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(ConstantWeights) );
+    self = (ConstantWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  );
+
+    /* General info */
+
+    /* Virtual Info */
+
+    return self;
+}
+
+void _ConstantWeights_Init( void* constantWeights  ) {
+	ConstantWeights* self;
+		
+	self = (ConstantWeights*)constantWeights;
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _ConstantWeights_Delete( void* constantWeights ) {
+    ConstantWeights* self = (ConstantWeights*)constantWeights;
+        
+    /* Delete parent */
+    _WeightsCalculator_Delete( self );
+}
+
+
+void _ConstantWeights_Print( void* constantWeights, Stream* stream ) {
+    ConstantWeights* self = (ConstantWeights*)constantWeights;
+        
+    /* Print parent */
+    _WeightsCalculator_Print( self, stream );
+}
+
+
+
+void* _ConstantWeights_Copy( const void* constantWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    ConstantWeights*    self = (ConstantWeights*)constantWeights;
+    ConstantWeights*    newConstantWeights;
+        
+    newConstantWeights = (ConstantWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
+        
+    return (void*)newConstantWeights;
+}
+
+void* _ConstantWeights_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(ConstantWeights);
+	Type                                                      type = ConstantWeights_Type;
+	Stg_Class_DeleteFunction*                              _delete = _ConstantWeights_Delete;
+	Stg_Class_PrintFunction*                                _print = _ConstantWeights_Print;
+	Stg_Class_CopyFunction*                                  _copy = _ConstantWeights_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _ConstantWeights_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _ConstantWeights_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _ConstantWeights_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _ConstantWeights_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _ConstantWeights_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _ConstantWeights_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	WeightsCalculator_CalculateFunction*                _calculate = _ConstantWeights_Calculate;
+
+    return (void*) _ConstantWeights_New(  CONSTANTWEIGHTS_PASSARGS  );
+}
+
+
+void _ConstantWeights_AssignFromXML( void* constantWeights, Stg_ComponentFactory* cf, void* data ) {
+    ConstantWeights*         self          = (ConstantWeights*) constantWeights;
+
+    _WeightsCalculator_AssignFromXML( self, cf, data );
+        
+    _ConstantWeights_Init( self );
+}
+
+void _ConstantWeights_Build( void* constantWeights, void* data ) {
+    ConstantWeights*    self = (ConstantWeights*)constantWeights;
+
+    _WeightsCalculator_Build( self, data );
+}
+
+void _ConstantWeights_Destroy( void* constantWeights, void* data ) {
+    ConstantWeights*    self = (ConstantWeights*)constantWeights;
+
+    _WeightsCalculator_Destroy( self, data );
+}
+
+void _ConstantWeights_Initialise( void* constantWeights, void* data ) {
+    ConstantWeights*    self = (ConstantWeights*)constantWeights;
+        
+    _WeightsCalculator_Initialise( self, data );
+}
+void _ConstantWeights_Execute( void* constantWeights, void* data ) {
+    ConstantWeights*    self = (ConstantWeights*)constantWeights;
+        
+    _WeightsCalculator_Execute( self, data );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+void _ConstantWeights_Calculate( void* constantWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    ConstantWeights*             self            = (ConstantWeights*)  constantWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    double                       weight;
+    Particle_InCellIndex         cParticleCount;
+                
+    cParticleCount = swarm->cellParticleCountTbl[lCell_I];
+    weight = self->cellLocalVolume / (double) cParticleCount;
+    WeightsCalculator_SetWeightsValueAllInCell( self, swarm, lCell_I, weight );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/DVCWeights.c
--- a/Weights/src/DVCWeights.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,943 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-** Copyright (c) 2006, Monash Cluster Computing 
-** All rights reserved.
-** Redistribution and use in source and binary forms, with or without modification,
-** are permitted provided that the following conditions are met:
-**
-**              * Redistributions of source code must retain the above copyright notice, 
-**                      this list of conditions and the following disclaimer.
-**              * Redistributions in binary form must reproduce the above copyright 
-**                      notice, this list of conditions and the following disclaimer in the 
-**                      documentation and/or other materials provided with the distribution.
-**              * Neither the name of the Monash University nor the names of its contributors 
-**                      may be used to endorse or promote products derived from this software 
-**                      without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
-** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
-** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
-** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
-** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
-** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
-** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
-** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-**
-** Contact:
-*%              Louis Moresi - Louis.Moresi at sci.monash.edu.au
-*%
-** Author:
-**              Mirko Velic - Mirko.Velic at sci.monash.edu.au
-**
-**  Assumptions:
-**       I am assuming that the xi's (local coords) on the IntegrationPoint particles
-**       are precalculated somewhere and get reset based on material PIC positions each time step.
-**
-**  Notes:
-**         The DVCWeights class should really be a class the next level up here.
-**         We should be able to swap out the WeightsCalculator_CalculateAll function instead of just setting
-**                 a pointer inside that function 
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
-/****************************************************************************************************************
-
-  The algorithm here-in computes a discrete voronoi diagram per FEM cell given a set of local
-  particle positions, in 3D and 2D. The volumes of the Voronoi regions are used as integration weights for
-  the integration point swarm and the integration points are the centroids of the same volumes.
-
-  For a description of this algorithm, see the article by Velic et.al.
-     "A Fast Robust Algorithm for computing Discrete Voronoi Diagrams in N-dimensions"
-  
-  Warning:
-
-  Be very careful of making changes here. It may have undesirable consequences in regard to the
-  speed of this implementation. Speed is very important here. You may be tempted to merge the
-  2D and 3D functions. Don't do it unless you can do it without using control statements.
-  This implementation uses von-Neumann neighbourhoods for boundary chain growth. Do not be tempted 
-  to implement "diagonal" neighbourhood growth cycles. For this is an abomination unto me.
-*****************************************************************************************************************/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "types.h"
-#include "WeightsCalculator.h"
-#include "DVCWeights.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type DVCWeights_Type = "DVCWeights";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-DVCWeights* DVCWeights_New( Name name, Dimension_Index dim, int *res ) {
-  DVCWeights *self = (DVCWeights*)_DVCWeights_DefaultNew( name );
-
-	self->isConstructed = True;
-	_WeightsCalculator_Init( self, dim );
-	_DVCWeights_Init( self, res );
-
-	return self;
-}
-
-DVCWeights* _DVCWeights_New(  DVCWEIGHTS_DEFARGS  ) {
-    DVCWeights* self;
-        
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(DVCWeights) );
-    self = (DVCWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  );
-        
-    /* General info */
-
-    /* Virtual Info */
-
-    return self;
-}
-
-void _DVCWeights_Init( void* dvcWeights, int *res ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-
-    self->resX = res[I_AXIS];
-    self->resY = res[J_AXIS];
-    self->resZ = res[K_AXIS];
-
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _DVCWeights_Delete( void* dvcWeights ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    /* Delete parent */
-    _WeightsCalculator_Delete( self );
-}
-
-
-void _DVCWeights_Print( void* dvcWeights, Stream* stream ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    /* Print parent */
-    _WeightsCalculator_Print( self, stream );
-}
-
-
-
-void* _DVCWeights_Copy( const void* dvcWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    DVCWeights* newDVCWeights;
-        
-    newDVCWeights = (DVCWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
-    return (void*)newDVCWeights;
-}
-
-void* _DVCWeights_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(DVCWeights);
-	Type                                                      type = DVCWeights_Type;
-	Stg_Class_DeleteFunction*                              _delete = _DVCWeights_Delete;
-	Stg_Class_PrintFunction*                                _print = _DVCWeights_Print;
-	Stg_Class_CopyFunction*                                  _copy = _DVCWeights_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _DVCWeights_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _DVCWeights_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _DVCWeights_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _DVCWeights_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _DVCWeights_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _DVCWeights_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	WeightsCalculator_CalculateFunction*                _calculate = _DVCWeights_Calculate;
-
-    return (void*) _DVCWeights_New(  DVCWEIGHTS_PASSARGS  );
-}
-
-
-void _DVCWeights_AssignFromXML( void* dvcWeights, Stg_ComponentFactory* cf, void *data ) {
-
-    DVCWeights*      self          = (DVCWeights*) dvcWeights;
-
-    int defaultResolution;
-    int resolution[3];
-
-    _WeightsCalculator_AssignFromXML( self, cf, data );
-
-    defaultResolution = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolution", 10  );
-    resolution[ I_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionX", defaultResolution  );
-    resolution[ J_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionY", defaultResolution  );
-    resolution[ K_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionZ", defaultResolution  );
-       
-    _DVCWeights_Init( self, resolution );
-}
-
-void _DVCWeights_Build( void* dvcWeights, void* data ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    _WeightsCalculator_Build( self, data );
-}
-void _DVCWeights_Initialise( void* dvcWeights, void* data ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    _WeightsCalculator_Initialise( self, data );
-}
-void _DVCWeights_Execute( void* dvcWeights, void* data ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    _WeightsCalculator_Execute( self, data );
-}
-
-void _DVCWeights_Destroy( void* dvcWeights, void* data ) {
-    DVCWeights* self = (DVCWeights*)dvcWeights;
-    _WeightsCalculator_Destroy( self, data );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-/** Get centroids of each voronoi region */
-void _DVCWeights_GetCentroids( struct cell *cells,struct particle *pList,
-                               int n, int m, int l,int nump,double vol){
-    int i;
-    int *count;
-
-    count=(int *)malloc(sizeof(int)*nump);
-
-    for(i=0;i<nump;i++){
-        count[i] = 0;
-        pList[ i ].cx = 0.0;
-        pList[ i ].cy = 0.0;
-        pList[ i ].cz = 0.0;    
-    }
-    for(i=0;i<n*m*l;i++){
-        pList[ cells[i].p ].cx += cells[i].x;
-        pList[ cells[i].p ].cy += cells[i].y;
-        pList[ cells[i].p ].cz += cells[i].z;
-        count[ cells[i].p ]++;//for total volume of a cell
-    }
-    for(i=0;i<nump;i++){
-        pList[ i ].w = count[i]*vol;
-        if(count[i] != 0){
-            pList[ i ].cx /= count[i];
-            pList[ i ].cy /= count[i];
-            pList[ i ].cz /= count[i];
-        } 
-    }
-    free(count);
-}
-/** Get centroids of each voronoi region in 2D*/
-void _DVCWeights_GetCentroids2D( struct cell2d *cells,struct particle2d *pList,
-                                 int n, int m, int nump,double vol){
-    int i;
-    int *count;
-
-    count=(int *)malloc(sizeof(int)*nump);
-  
-    for(i=0;i<nump;i++){
-        count[i] = 0;
-        pList[ i ].cx = 0.0;
-        pList[ i ].cy = 0.0;
-    }
-    for(i=0;i<n*m;i++){
-        pList[ cells[i].p ].cx += cells[i].x;
-        pList[ cells[i].p ].cy += cells[i].y;
-        count[ cells[i].p ]++;//for total volume of a cell
-    }
-    for(i=0;i<nump;i++){
-        pList[ i ].w = count[i]*vol;
-        if(count[i] != 0){
-            pList[ i ].cx /= count[i];
-            pList[ i ].cy /= count[i];
-        } 
-    }  
-    free(count);
-}
-
-/** Claim a cell for a particle in the list */
-void _DVCWeights_ClaimCells(struct chain **bbchain,struct cell **ccells,struct particle **pList,int p_i){
-    int i,count;
-    int cell_num0;
-    double x0,y0,x1,y1,x2,y2,z0,z1,z2,dist1;
-    struct chain *bchain = &(*bbchain)[p_i];
-    struct cell *cells = *ccells;
-    int *temp;
-
-    count = 0;
-    bchain->numclaimed = 0;
-
-
-    for(i=0;i<bchain->sizeofboundary;i++){
-        cell_num0 = bchain->new_bound_cells[i];// cell number we are trying to claim
-        if(cells[cell_num0].p == -1){//if cell unowned then claim cell
-            /* This is the bit needed for mallocing */
-            /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
-            if( count > bchain->new_claimed_cells_malloced - 1 ){
-                temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
-                bchain->new_claimed_cells = temp;
-                bchain->new_claimed_cells_malloced += DVC_INC;
-                temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
-                bchain->new_bound_cells = temp;
-                bchain->new_bound_cells_malloced += DVC_INC;      
-            }
-            /* end of bit needed for mallocing */
-            bchain->new_claimed_cells[count] = cell_num0;
-            bchain->numclaimed++;
-            count++;
-            cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
-        }
-        else{
-            if(cells[cell_num0].p != p_i){
-                //we need a contest between particles for the cell.
-                x2 = (*pList)[p_i].x;
-                y2 = (*pList)[p_i].y;
-                z2 = (*pList)[p_i].z;
-                x1 = (*pList)[cells[cell_num0].p].x;
-                y1 = (*pList)[cells[cell_num0].p].y;
-                z1 = (*pList)[cells[cell_num0].p].z;
-                x0 = cells[cell_num0].x;
-                y0 = cells[cell_num0].y;
-                z0 = cells[cell_num0].z;
-        
-                dist1 = _DVCWeights_DistanceTest(x0,y0,z0,x1,y1,z1,x2,y2,z2);
-                if(dist1 > 0.0){
-                    bchain->new_claimed_cells[count] = cell_num0;
-                    bchain->numclaimed++;
-                    count++;
-                    cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
-                }
-            }//if
-        }//else
-    }
-    bchain->new_claimed_cells[count] = -1;// end of list
-}
-
-/** Claim a cell for a particle in the list  in 2D*/
-void _DVCWeights_ClaimCells2D(struct chain **bbchain,struct cell2d **ccells,struct particle2d **pList,int p_i){
-    int i,count;
-    int cell_num0;
-    double x0,y0,x1,y1,x2,y2,dist1;
-    struct chain *bchain = &(*bbchain)[p_i];
-    struct cell2d *cells = *ccells;
-    int *temp;
-
-    count = 0;
-    bchain->numclaimed = 0;
-
-
-    for(i=0;i<bchain->sizeofboundary;i++){
-        cell_num0 = bchain->new_bound_cells[i];// cell number we are trying to claim
-        if(cells[cell_num0].p == -1){//if cell unowned then claim cell
-            /* This is the bit needed for mallocing */
-            /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
-            if( count > bchain->new_claimed_cells_malloced - 1 ){
-                temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
-                bchain->new_claimed_cells = temp;
-                bchain->new_claimed_cells_malloced += DVC_INC;
-                temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
-                bchain->new_bound_cells = temp;
-                bchain->new_bound_cells_malloced += DVC_INC;      
-            }
-            /* end of bit needed for mallocing */
-            bchain->new_claimed_cells[count] = cell_num0;
-            bchain->numclaimed++;
-            count++;
-            cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
-        }
-        else{
-            if(cells[cell_num0].p != p_i){
-                //we need a contest between particles for the cell.
-                x2 = (*pList)[p_i].x;
-                y2 = (*pList)[p_i].y;
-                x1 = (*pList)[cells[cell_num0].p].x;
-                y1 = (*pList)[cells[cell_num0].p].y;
-                x0 = cells[cell_num0].x;
-                y0 = cells[cell_num0].y;
-        
-                dist1 = _DVCWeights_DistanceTest2D(x0,y0,x1,y1,x2,y2);
-                if(dist1 > 0.0){
-                    bchain->new_claimed_cells[count] = cell_num0;
-                    bchain->numclaimed++;
-                    count++;
-                    cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
-                }
-            }//if
-        }//else
-    }
-    bchain->new_claimed_cells[count] = -1;// end of list
-}
-
-/** Reset the values in the cells so that the grid over the element can be used again */
-void _DVCWeights_ResetGrid(struct cell **cells, int n){
-    int i;
-
-    for(i=0;i<n;i++){
-        (*cells)[i].p = -1;
-        (*cells)[i].done = 0;
-    }
-}
-
-/** Reset the values in the cells so that the grid over the element can be used again, in 2D */
-void _DVCWeights_ResetGrid2D(struct cell2d **cells, int n){
-    int i;
-
-    for(i=0;i<n;i++){
-        (*cells)[i].p = -1;
-        (*cells)[i].done = 0;
-    }
-}
-
-/** Update the list of the cells on the boundary of the growing voronoi cells 
-    Add new particles on the boundary, and remove particles no longer on the boundary.*/
-void _DVCWeights_UpdateBchain(struct chain **bbchain,struct cell **ccells,int p_i){
-    int i,k,count;
-    int cell_num0,cell_num[6],cell_num1;
-    struct chain *bchain = &(*bbchain)[p_i];
-    struct cell *cells = *ccells;
-    int *temp;
-
-    count = 0;
-    bchain->sizeofboundary = 0;
-    for(i=0;i<bchain->numclaimed;i++){
-        cell_num0 =bchain->new_claimed_cells[i];
-
-        cell_num[0] = cells[cell_num0].S;    
-        cell_num[1] = cells[cell_num0].N;
-        cell_num[2] = cells[cell_num0].E;
-        cell_num[3] = cells[cell_num0].W;
-        cell_num[4] = cells[cell_num0].U;
-        cell_num[5] = cells[cell_num0].D;
-
-        for(k=0;k<6;k++){
-            cell_num1 = cell_num[k];
-            // if cell does not already belong to the particle and hasn't been
-            // marked as being done then add it to new boundary array and mark it
-            // as done
-            if(cell_num1 != -2){
-                if(cells[cell_num1].p != p_i && cells[cell_num1].done != 1){
-                    /* This is the bit needed for mallocing */     
-                    /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
-                    if( count > bchain->new_bound_cells_malloced - 1 ){
-                        temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
-                        bchain->new_claimed_cells = temp;
-                        bchain->new_claimed_cells_malloced += DVC_INC;
-                        temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
-                        bchain->new_bound_cells = temp;
-                        bchain->new_bound_cells_malloced += DVC_INC; 
-                    }
-                    /* end of bit needed for mallocing */
-                    bchain->new_bound_cells[count] = cell_num1;
-                    bchain->sizeofboundary++;
-                    count++;
-                    cells[cell_num1].done = 1;
-                }//if
-            }//if cell_num1
-        }//for k
-    }//for
-    // reset the done flags back to zero for next time
-    for(i=0;i<count;i++){
-        cells[  bchain->new_bound_cells[i]  ].done = 0;
-    }
-}
-
-/** Update the list of the cells on the boundary of the growing voronoi cells 
-    Add new particles on the boundary, and remove particles no longer on the boundary. In 2D*/
-void _DVCWeights_UpdateBchain2D(struct chain **bbchain,struct cell2d **ccells,int p_i){
-    int i,k,count;
-    int cell_num0,cell_num[4],cell_num1;
-    struct chain *bchain = &(*bbchain)[p_i];
-    struct cell2d *cells = *ccells;
-    int *temp;
-
-    count = 0;
-    bchain->sizeofboundary = 0;
-    for(i=0;i<bchain->numclaimed;i++){
-        cell_num0 =bchain->new_claimed_cells[i];
-
-        cell_num[0] = cells[cell_num0].S;    
-        cell_num[1] = cells[cell_num0].N;
-        cell_num[2] = cells[cell_num0].E;
-        cell_num[3] = cells[cell_num0].W;
-
-        for(k=0;k<4;k++){
-            cell_num1 = cell_num[k];
-            // if cell does not already belong to the particle and hasn't been
-            // marked as being done then add it to new boundary array and mark it
-            // as done
-            if(cell_num1 != -2){
-                if(cells[cell_num1].p != p_i && cells[cell_num1].done != 1){
-                    /* This is the bit needed for mallocing */     
-                    /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
-                    if( count > bchain->new_bound_cells_malloced - 1 ){
-                        temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
-                        bchain->new_claimed_cells = temp;
-                        bchain->new_claimed_cells_malloced += DVC_INC;
-                        temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
-                        bchain->new_bound_cells = temp;
-                        bchain->new_bound_cells_malloced += DVC_INC; 
-                    }
-                    /* end of bit needed for mallocing */
-                    bchain->new_bound_cells[count] = cell_num1;
-                    bchain->sizeofboundary++;
-                    count++;
-                    cells[cell_num1].done = 1;
-                }//if
-            }//if cell_num1
-        }//for k
-    }//for
-    // reset the done flags back to zero for next time
-    for(i=0;i<count;i++){
-        cells[  bchain->new_bound_cells[i]  ].done = 0;
-    }
-}
-
-
-/** Construct the grid over the element. This grid is fixed. 
-    (n, m, l) are (z, x, y) grid resolutions respectively.*/
-void _DVCWeights_ConstructGrid(struct cell **cell_list, int n, int m, int l,
-                               double x0,double y0,double z0,double x1,double y1,double z1){
-    struct cell *cells;
-    int i,j,k;
-    double dx,dy,dz,Dx,Dy,Dz,X,Y,Z;
-
-    cells = (struct cell*)malloc(n*m*l*sizeof(struct cell));
-    for(i=0;i<l*m*n;i++){
-        cells[i].S = -2;
-        cells[i].N = -2;
-        cells[i].E = -2;
-        cells[i].W = -2;
-        cells[i].U = -2;
-        cells[i].D = -2;
-        cells[i].p = -1;
-        cells[i].done = 0;
-    }
-    for(k=0;k<n;k++){
-        for(i=0;i<l*(m-1);i++){
-            cells[i+k*l*m].N=i+k*l*m+l;
-            cells[i+l+k*l*m].S = i+k*l*m;
-        }
-    }
-    for(k=0;k<n-1;k++){
-        for(i=0;i<l*m;i++){
-            cells[i+k*l*m].U=i+k*l*m+l*m;
-            cells[i+k*l*m+l*m].D = i+k*l*m;
-        }
-    }
-  
-    Dx = x1-x0; Dy = y1-y0; Dz = z1-z0;
-    dx = Dx/l;  dy = Dy/m;  dz = Dz/n;
-    Z = z0 - dz/2.0;
-    for(k=0;k<n;k++){
-        Z = Z + dz;
-        Y = y0 - dy/2.0;
-        for(j=0;j<m;j++){
-            Y = Y + dy;
-            X = x0 - dx/2.0;
-            for(i=0;i<l;i++){
-                X=X+dx;
-                cells[i+l*j+k*l*m].x = X;
-                cells[i+l*j+k*l*m].y = Y;
-                cells[i+l*j+k*l*m].z = Z;
-                if(i!= l-1){
-                    cells[i+l*j+k*l*m].E = i+l*j+1+k*l*m;
-                    cells[i+l*j+1+k*l*m].W = i+l*j+k*l*m;
-                }
-            }//x
-        }//y
-    }//z
-    *cell_list = cells; 
-}
-
-
-/** Construct the grid over the element. This grid is fixed. 
-    (m, l) are (x, y) grid resolutions respectively.*/
-void _DVCWeights_ConstructGrid2D(struct cell2d **cell_list, int m, int l,
-                                 double x0,double y0,double x1,double y1){
-    struct cell2d *cells;
-    int i,j;
-    double dx,dy,Dx,Dy,X,Y;
-
-    cells = (struct cell2d*)malloc(m*l*sizeof(struct cell));
-    for(i=0;i<l*m;i++){
-        cells[i].S = -2;
-        cells[i].N = -2;
-        cells[i].E = -2;
-        cells[i].W = -2;
-        cells[i].p = -1;
-        cells[i].done = 0;
-    }
-    for(i=0;i<l*(m-1);i++){
-        cells[i].N=i+l;
-        cells[i+l].S = i;
-    }
-    Dx = x1-x0; Dy = y1-y0;
-    dx = Dx/l;  dy = Dy/m;
-    Y = y0 - dy/2.0;
-    for(j=0;j<m;j++){
-        Y = Y + dy;
-        X = x0 - dx/2.0;
-        for(i=0;i<l;i++){
-            X=X+dx;
-            cells[i+l*j].x = X;
-            cells[i+l*j].y = Y;
-            if(i!= l-1){
-                cells[i+l*j].E = i+l*j+1;
-                cells[i+l*j+1].W = i+l*j;
-            }
-        }
-    }
-    *cell_list = cells; 
-}
-
-/** Calculate the sqaure of the distance between two points */
-double _DVCWeights_DistanceSquared(double x0, double y0, double z0, double x1, double y1, double z1){
-    return (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)+(z1-z0)*(z1-z0);
-}
-
-/** Calculate the sqaure of the distance between two points in 2D*/
-double _DVCWeights_DistanceSquared2D(double x0, double y0,double x1, double y1){
-    return (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
-}
-double _DVCWeights_DistanceTest2D(double x0, double y0, double x1, double y1,double x2, double y2){
-    return (x1+x2-x0-x0)*(x1-x2) + (y1+y2-y0-y0)*(y1-y2);
-}
-double _DVCWeights_DistanceTest(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2){
-    return (x1+x2-x0-x0)*(x1-x2) + (y1+y2-y0-y0)*(y1-y2) + (z1+z2-z0-z0)*(z1-z2);
-}
-/** Allocate the internal structs for the bchain (boundary chain) and the plist (particle list) */
-void _DVCWeights_InitialiseStructs( struct chain **bchain, struct particle **pList, int nump){
-
-    int i;
-    // init the data structures
-    if( (*bchain = (struct chain *)malloc( nump*sizeof(struct chain ) )) == 0){
-        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ), "No memory for bchain in '%s'\nCannot continue.\n", __func__);
-    }
-    // note that doing bchain[i]->new... doesn't work
-    for(i=0;i<nump;i++){
-        (*bchain)[i].new_claimed_cells = (int *)malloc(DVC_INC*sizeof(int));
-        (*bchain)[i].new_claimed_cells_malloced = DVC_INC;
-        (*bchain)[i].new_bound_cells = (int *)malloc(DVC_INC*sizeof(int));
-        (*bchain)[i].new_bound_cells_malloced = DVC_INC;
-    }
-    if( (*pList = (struct particle *)malloc( nump*sizeof(struct particle ) )) == 0){
-        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ),"No memory for pList in '%s'\nCannot continue.\n", __func__);
-    }
-
-    /* Initialise all particle values to zero */
-    for (i = 0; i < nump; i++) {
-        (*pList)[i].x = 0; (*pList)[i].y = 0; (*pList)[i].z = 0;
-        (*pList)[i].cx = 0; (*pList)[i].cy = 0; (*pList)[i].cz = 0;
-        (*pList)[i].w = 0;
-        (*pList)[i].index = 0;
-    }
-}
-/** Allocate the internal structs for the bchain (boundary chain) and the plist (particle list) */
-void _DVCWeights_InitialiseStructs2D( struct chain **bchain, struct particle2d **pList, int nump){
-
-    int i;
-    // init the data structures
-    if( (*bchain = (struct chain *)malloc( nump*sizeof(struct chain ) )) == 0){
-        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ),"No memory for bchain in '%s'\nCannot continue.\n", __func__);
-    }
-    //
-    for(i=0;i<nump;i++){
-        (*bchain)[i].new_claimed_cells = (int *)malloc(DVC_INC*sizeof(int));
-        (*bchain)[i].new_claimed_cells_malloced = DVC_INC;
-        (*bchain)[i].new_bound_cells = (int *)malloc(DVC_INC*sizeof(int));
-        (*bchain)[i].new_bound_cells_malloced = DVC_INC;
-    }
-    if( (*pList = (struct particle2d *)malloc( nump*sizeof(struct particle2d ) )) == 0){
-        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ),"No memory for pList in '%s'\nCannot continue.\n", __func__);
-    }
-
-    /* Initialise all particle values to zero */
-    for (i = 0; i < nump; i++) {
-        (*pList)[i].x = 0; (*pList)[i].y = 0;
-        (*pList)[i].cx = 0; (*pList)[i].cy = 0;
-        (*pList)[i].w = 0;
-        (*pList)[i].index = 0;
-    }
-}
-
-/** Create the Voronoi diagram by growing the voronoi cells from the particle locations.
-    All the parameters passed into _DVCWeights_CreateVoronoi
-    must be initialised already. */
-void _DVCWeights_CreateVoronoi( struct chain **bchain, struct particle **pList, struct cell **cells, 
-                                double dx, double dy, double dz,
-                                int nump,
-                                int numx, int numy, int numz, 
-                                double BBXMIN, double BBXMAX, 
-                                double BBYMIN, double BBYMAX,
-                                double BBZMIN, double BBZMAX){
-    int i,j,k,l;
-    int count;
-    int claimed;
-
-    for(i=0;i<nump;i++){
-        k = ((*pList)[i].x - BBXMIN)/dx;
-        j = ((*pList)[i].y - BBYMIN)/dy;
-        l = ((*pList)[i].z - BBZMIN)/dz;
-        /* If a particle is exactly on the border then make sure it is in a valid cell inside the element */
-        if (k == numx){  k--; }
-        if (j == numy) { j--; }
-        if (l == numz) { l--; }
-        (*cells)[k+j*numx+l*numx*numy].p = i; //particle number i
-        (*bchain)[i].numclaimed = 1;// number of most recently claimed cells
-        (*bchain)[i].sizeofboundary = 0;
-        (*bchain)[i].totalclaimed = 1;// total of claimed cells so far.
-        (*bchain)[i].done = 0;
-        (*bchain)[i].index = k+j*numx+l*numx*numy;// ith particle is in cell # k+j*numx
-        (*bchain)[i].new_claimed_cells[0] = k+j*numx+l*numx*numy; 
-        // ith particle has just claimed cell number k+j*numx+l*numx*numy
-        (*bchain)[i].new_claimed_cells[1] = -1;// denotes end of claimed_cells list
-        // when we have finished claiming cells we call this function.
-        _DVCWeights_UpdateBchain(bchain,cells,i);
-    }
-    count = i;// number of particles
-    claimed = 1;
-      
-    while(claimed != 0){
-        claimed = 0 ;
-        for(i=0;i<count;i++){
-            _DVCWeights_ClaimCells(bchain,cells,pList,i);
-            claimed += (*bchain)[i].numclaimed;
-            _DVCWeights_UpdateBchain(bchain,cells,i);
-        }
-    }//while
-}
-
-/** Create the Voronoi diagram by growing the voronoi cells from the particle locations.
-    All the parameters passed into _DVCWeights_CreateVoronoi2D
-    must be initialised already. */
-void _DVCWeights_CreateVoronoi2D( struct chain **bchain, struct particle2d **pList, struct cell2d **cells, 
-                                  double dx, double dy,
-                                  int nump,
-                                  int numx, int numy,
-                                  double BBXMIN, double BBXMAX, 
-                                  double BBYMIN, double BBYMAX){
-    int i,j,k;
-    int claimed;
-
-    for(i=0;i<nump;i++){
-        k = ((*pList)[i].x - BBXMIN)/dx;
-        j = ((*pList)[i].y - BBYMIN)/dy;
-        /* If particle is on the border exactly, make sure it is
-           put in a valid cell inside the element */
-        if (k == numx){
-            k--;
-        }
-        if ( j == numy) {
-            j--;
-        }
-        
-        (*cells)[k+j*numx].p = i; //particle number i
-      
-        (*bchain)[i].numclaimed = 1;// number of most recently claimed cells
-        (*bchain)[i].sizeofboundary = 0;
-        (*bchain)[i].totalclaimed = 1;// total of claimed cells so far.
-        (*bchain)[i].done = 0;
-        (*bchain)[i].index = k+j*numx;// ith particle is in cell # k+j*numx
-        (*bchain)[i].new_claimed_cells[0] = k+j*numx; // ith particle has just claimed cell number k+j*numx
-        (*bchain)[i].new_claimed_cells[1] = -1;// denotes end of claimed_cells list
-        // when we have finished claiming cells we call this function.
-        _DVCWeights_UpdateBchain2D( bchain, cells, i);
-    }//nump
-   
-    claimed = 1;
-
-    while(claimed != 0){
-        claimed = 0 ;
-        for(i=0;i<nump;i++){
-            _DVCWeights_ClaimCells2D( bchain, cells, pList, i);
-            claimed += (*bchain)[i].numclaimed;
-            _DVCWeights_UpdateBchain2D( bchain, cells, i);
-        }
-    }//while
-}
-
-/* Calculate the integration weighting for each particle by contructing
-   a voronoi diagram in an element in 3D*/
-void _DVCWeights_Calculate3D( void* dvcWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    DVCWeights*             self            = (DVCWeights*)  dvcWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount;
-    IntegrationPoint**           particle;
-    static int visited = 0 ;
-    double dx,dy,dz,da;
-    static struct cell *cells;// the connected grid
-    struct particle *pList;// particle List
-    struct chain *bchain;//boundary chain
-    int nump,numx,numy,numz;
-    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
-    double BBXMAX = 1.0;
-    double BBYMIN = -1.0;
-    double BBYMAX = 1.0;
-    double BBZMIN = -1.0;
-    double BBZMAX = 1.0;
-    int i,k;
-
-    numx = self->resX;
-    numy = self->resY;
-    numz = self->resZ;
-
-    nump = cParticleCount = swarm->cellParticleCountTbl[lCell_I];
-
-    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"DVC_Weights" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
-
-    dx = (BBXMAX - BBXMIN)/numx;
-    dy = (BBYMAX - BBYMIN)/numy;
-    dz = (BBZMAX - BBZMIN)/numz;
-    da = dx*dy*dz;
-        
-    // Construct the grid for the Voronoi cells only once.
-    // If we wanted to call this function again during a job with a different resolution
-    // then we should destroy the grid once we have looped through the whole mesh.
-    // I am assuming we are not going to do that for now.
-    // Easy to implement this anyway, if needed.
-    if(!visited){
-        /* The DVCWeights class should really be a class the next level up here */
-        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
-           a pointer inside that function */
-        visited++;
-        _DVCWeights_ConstructGrid(&cells,numz,numy,numx,BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);
-    }
-        
-        
-    // init the data structures
-    _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
-    _DVCWeights_ResetGrid(&cells,numz*numy*numx);
-        
-    particle = (IntegrationPoint**)malloc(nump*sizeof(IntegrationPoint*));
-        
-    // initialize the particle positions to be the local coordinates of the material swarm particles
-    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
-    // positions each time step.
-    for(i=0;i<nump;i++){
-              
-        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, i );
-        pList[i].x = particle[i]->xi[0];
-        pList[i].y = particle[i]->xi[1];
-        pList[i].z = particle[i]->xi[2];
-              
-    }
-    _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-    _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
-    // We are setting the integration points to be the centroids of the Voronoi regions here and
-    // the weight is the volume of each Voronoi region.
-    for(i=0;i<nump;i++){
-
-        particle[i]->xi[0] = pList[i].cx;
-        particle[i]->xi[1] = pList[i].cy;
-        particle[i]->xi[2] = pList[i].cz;
-        particle[i]->weight = pList[i].w;
-
-    }   
-    for(k=0;k<nump;k++){
-        free(bchain[k].new_claimed_cells);
-        free(bchain[k].new_bound_cells);
-    }
-    free(particle);
-    free(bchain);
-    free(pList);
-
-}
-
-/* Calculate the integration weighting for each particle by contructing
-   a voronoi diagram in an element in 2D*/
-void _DVCWeights_Calculate2D( void* dvcWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    DVCWeights*             self            = (DVCWeights*)  dvcWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount;
-    IntegrationPoint**           particle;
-    static int visited = 0 ;
-    double dx,dy,da;
-    static struct cell2d *cells;// the connected grid
-    struct particle2d *pList;// particle List
-    struct chain *bchain;//boundary chain
-    int nump,numx,numy;
-    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
-    double BBXMAX = 1.0;
-    double BBYMIN = -1.0;
-    double BBYMAX = 1.0;
-    int i,k;
-
-    numx = self->resX;
-    numy = self->resY;
-
-    nump = cParticleCount = swarm->cellParticleCountTbl[lCell_I];
-
-    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"DVC_Weights" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
-
-    dx = (BBXMAX - BBXMIN)/numx;
-    dy = (BBYMAX - BBYMIN)/numy;
-    da = dx*dy;
-        
-    // Construct the grid for the Voronoi cells only once.
-    // If we wanted to call this function again during a job with a different resolution
-    // then we should destroy the grid once we have looped through the whole mesh.
-    // I am assuming we are not going to do that for now.
-    // Easy to implement this anyway, if needed.
-    if(!visited){
-        /* The DVCWeights class should really be a class the next level up here */
-        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
-           a pointer inside that function */
-        visited++;
-        _DVCWeights_ConstructGrid2D(&cells,numy,numx,BBXMIN,BBYMIN,BBXMAX,BBYMAX);
-    }
-        
-        
-    // init the data structures
-    _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);
-    _DVCWeights_ResetGrid2D(&cells,numy*numx);
-        
-    particle = (IntegrationPoint**)malloc(nump*sizeof(IntegrationPoint*));
-        
-    // initialize the particle positions to be the local coordinates of the material swarm particles
-    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
-    // positions each time step.
-    for(i=0;i<nump;i++){
-              
-        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, i );
-        pList[i].x = particle[i]->xi[0];
-        pList[i].y = particle[i]->xi[1];
-              
-    }
-    _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
-    _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
-    // We are setting the integration points to be the centroids of the Voronoi regions here and
-    // the weight is the volume of each Voronoi region.
-    for(i=0;i<nump;i++){
-
-        particle[i]->xi[0] = pList[i].cx;
-        particle[i]->xi[1] = pList[i].cy;
-        particle[i]->weight = pList[i].w;
-
-    }   
-    for(k=0;k<nump;k++){
-        free(bchain[k].new_claimed_cells);
-        free(bchain[k].new_bound_cells);
-    }
-    free(particle);
-    free(bchain);
-    free(pList);
-
-}
-
-void _DVCWeights_Calculate( void* dvcWeights, void* _swarm, Cell_LocalIndex lCell_I ){
-    Swarm* swarm = (Swarm*) _swarm;
-    Dimension_Index dim = swarm->dim;
-
-    if(dim == 3){
-        _DVCWeights_Calculate3D( dvcWeights, _swarm, lCell_I);
-    }
-    else {
-        _DVCWeights_Calculate2D( dvcWeights, _swarm, lCell_I);
-    }
-}
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/DVCWeights.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/DVCWeights.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,943 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+** Copyright (c) 2006, Monash Cluster Computing 
+** All rights reserved.
+** Redistribution and use in source and binary forms, with or without modification,
+** are permitted provided that the following conditions are met:
+**
+**              * Redistributions of source code must retain the above copyright notice, 
+**                      this list of conditions and the following disclaimer.
+**              * Redistributions in binary form must reproduce the above copyright 
+**                      notice, this list of conditions and the following disclaimer in the 
+**                      documentation and/or other materials provided with the distribution.
+**              * Neither the name of the Monash University nor the names of its contributors 
+**                      may be used to endorse or promote products derived from this software 
+**                      without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
+** THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
+** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
+** BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
+** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
+** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
+** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+**
+**
+** Contact:
+*%              Louis Moresi - Louis.Moresi at sci.monash.edu.au
+*%
+** Author:
+**              Mirko Velic - Mirko.Velic at sci.monash.edu.au
+**
+**  Assumptions:
+**       I am assuming that the xi's (local coords) on the IntegrationPoint particles
+**       are precalculated somewhere and get reset based on material PIC positions each time step.
+**
+**  Notes:
+**         The DVCWeights class should really be a class the next level up here.
+**         We should be able to swap out the WeightsCalculator_CalculateAll function instead of just setting
+**                 a pointer inside that function 
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+/****************************************************************************************************************
+
+  The algorithm here-in computes a discrete voronoi diagram per FEM cell given a set of local
+  particle positions, in 3D and 2D. The volumes of the Voronoi regions are used as integration weights for
+  the integration point swarm and the integration points are the centroids of the same volumes.
+
+  For a description of this algorithm, see the article by Velic et.al.
+     "A Fast Robust Algorithm for computing Discrete Voronoi Diagrams in N-dimensions"
+  
+  Warning:
+
+  Be very careful of making changes here. It may have undesirable consequences in regard to the
+  speed of this implementation. Speed is very important here. You may be tempted to merge the
+  2D and 3D functions. Don't do it unless you can do it without using control statements.
+  This implementation uses von-Neumann neighbourhoods for boundary chain growth. Do not be tempted 
+  to implement "diagonal" neighbourhood growth cycles. For this is an abomination unto me.
+*****************************************************************************************************************/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "types.h"
+#include "WeightsCalculator.h"
+#include "DVCWeights.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type DVCWeights_Type = "DVCWeights";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+DVCWeights* DVCWeights_New( Name name, Dimension_Index dim, int *res ) {
+  DVCWeights *self = (DVCWeights*)_DVCWeights_DefaultNew( name );
+
+	self->isConstructed = True;
+	_WeightsCalculator_Init( self, dim );
+	_DVCWeights_Init( self, res );
+
+	return self;
+}
+
+DVCWeights* _DVCWeights_New(  DVCWEIGHTS_DEFARGS  ) {
+    DVCWeights* self;
+        
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(DVCWeights) );
+    self = (DVCWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  );
+        
+    /* General info */
+
+    /* Virtual Info */
+
+    return self;
+}
+
+void _DVCWeights_Init( void* dvcWeights, int *res ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+
+    self->resX = res[I_AXIS];
+    self->resY = res[J_AXIS];
+    self->resZ = res[K_AXIS];
+
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _DVCWeights_Delete( void* dvcWeights ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    /* Delete parent */
+    _WeightsCalculator_Delete( self );
+}
+
+
+void _DVCWeights_Print( void* dvcWeights, Stream* stream ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    /* Print parent */
+    _WeightsCalculator_Print( self, stream );
+}
+
+
+
+void* _DVCWeights_Copy( const void* dvcWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    DVCWeights* newDVCWeights;
+        
+    newDVCWeights = (DVCWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
+    return (void*)newDVCWeights;
+}
+
+void* _DVCWeights_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(DVCWeights);
+	Type                                                      type = DVCWeights_Type;
+	Stg_Class_DeleteFunction*                              _delete = _DVCWeights_Delete;
+	Stg_Class_PrintFunction*                                _print = _DVCWeights_Print;
+	Stg_Class_CopyFunction*                                  _copy = _DVCWeights_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _DVCWeights_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _DVCWeights_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _DVCWeights_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _DVCWeights_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _DVCWeights_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _DVCWeights_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	WeightsCalculator_CalculateFunction*                _calculate = _DVCWeights_Calculate;
+
+    return (void*) _DVCWeights_New(  DVCWEIGHTS_PASSARGS  );
+}
+
+
+void _DVCWeights_AssignFromXML( void* dvcWeights, Stg_ComponentFactory* cf, void *data ) {
+
+    DVCWeights*      self          = (DVCWeights*) dvcWeights;
+
+    int defaultResolution;
+    int resolution[3];
+
+    _WeightsCalculator_AssignFromXML( self, cf, data );
+
+    defaultResolution = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolution", 10  );
+    resolution[ I_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionX", defaultResolution  );
+    resolution[ J_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionY", defaultResolution  );
+    resolution[ K_AXIS ] = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"resolutionZ", defaultResolution  );
+       
+    _DVCWeights_Init( self, resolution );
+}
+
+void _DVCWeights_Build( void* dvcWeights, void* data ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    _WeightsCalculator_Build( self, data );
+}
+void _DVCWeights_Initialise( void* dvcWeights, void* data ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    _WeightsCalculator_Initialise( self, data );
+}
+void _DVCWeights_Execute( void* dvcWeights, void* data ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    _WeightsCalculator_Execute( self, data );
+}
+
+void _DVCWeights_Destroy( void* dvcWeights, void* data ) {
+    DVCWeights* self = (DVCWeights*)dvcWeights;
+    _WeightsCalculator_Destroy( self, data );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+/** Get centroids of each voronoi region */
+void _DVCWeights_GetCentroids( struct cell *cells,struct particle *pList,
+                               int n, int m, int l,int nump,double vol){
+    int i;
+    int *count;
+
+    count=(int *)malloc(sizeof(int)*nump);
+
+    for(i=0;i<nump;i++){
+        count[i] = 0;
+        pList[ i ].cx = 0.0;
+        pList[ i ].cy = 0.0;
+        pList[ i ].cz = 0.0;    
+    }
+    for(i=0;i<n*m*l;i++){
+        pList[ cells[i].p ].cx += cells[i].x;
+        pList[ cells[i].p ].cy += cells[i].y;
+        pList[ cells[i].p ].cz += cells[i].z;
+        count[ cells[i].p ]++;//for total volume of a cell
+    }
+    for(i=0;i<nump;i++){
+        pList[ i ].w = count[i]*vol;
+        if(count[i] != 0){
+            pList[ i ].cx /= count[i];
+            pList[ i ].cy /= count[i];
+            pList[ i ].cz /= count[i];
+        } 
+    }
+    free(count);
+}
+/** Get centroids of each voronoi region in 2D*/
+void _DVCWeights_GetCentroids2D( struct cell2d *cells,struct particle2d *pList,
+                                 int n, int m, int nump,double vol){
+    int i;
+    int *count;
+
+    count=(int *)malloc(sizeof(int)*nump);
+  
+    for(i=0;i<nump;i++){
+        count[i] = 0;
+        pList[ i ].cx = 0.0;
+        pList[ i ].cy = 0.0;
+    }
+    for(i=0;i<n*m;i++){
+        pList[ cells[i].p ].cx += cells[i].x;
+        pList[ cells[i].p ].cy += cells[i].y;
+        count[ cells[i].p ]++;//for total volume of a cell
+    }
+    for(i=0;i<nump;i++){
+        pList[ i ].w = count[i]*vol;
+        if(count[i] != 0){
+            pList[ i ].cx /= count[i];
+            pList[ i ].cy /= count[i];
+        } 
+    }  
+    free(count);
+}
+
+/** Claim a cell for a particle in the list */
+void _DVCWeights_ClaimCells(struct chain **bbchain,struct cell **ccells,struct particle **pList,int p_i){
+    int i,count;
+    int cell_num0;
+    double x0,y0,x1,y1,x2,y2,z0,z1,z2,dist1;
+    struct chain *bchain = &(*bbchain)[p_i];
+    struct cell *cells = *ccells;
+    int *temp;
+
+    count = 0;
+    bchain->numclaimed = 0;
+
+
+    for(i=0;i<bchain->sizeofboundary;i++){
+        cell_num0 = bchain->new_bound_cells[i];// cell number we are trying to claim
+        if(cells[cell_num0].p == -1){//if cell unowned then claim cell
+            /* This is the bit needed for mallocing */
+            /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
+            if( count > bchain->new_claimed_cells_malloced - 1 ){
+                temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
+                bchain->new_claimed_cells = temp;
+                bchain->new_claimed_cells_malloced += DVC_INC;
+                temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
+                bchain->new_bound_cells = temp;
+                bchain->new_bound_cells_malloced += DVC_INC;      
+            }
+            /* end of bit needed for mallocing */
+            bchain->new_claimed_cells[count] = cell_num0;
+            bchain->numclaimed++;
+            count++;
+            cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
+        }
+        else{
+            if(cells[cell_num0].p != p_i){
+                //we need a contest between particles for the cell.
+                x2 = (*pList)[p_i].x;
+                y2 = (*pList)[p_i].y;
+                z2 = (*pList)[p_i].z;
+                x1 = (*pList)[cells[cell_num0].p].x;
+                y1 = (*pList)[cells[cell_num0].p].y;
+                z1 = (*pList)[cells[cell_num0].p].z;
+                x0 = cells[cell_num0].x;
+                y0 = cells[cell_num0].y;
+                z0 = cells[cell_num0].z;
+        
+                dist1 = _DVCWeights_DistanceTest(x0,y0,z0,x1,y1,z1,x2,y2,z2);
+                if(dist1 > 0.0){
+                    bchain->new_claimed_cells[count] = cell_num0;
+                    bchain->numclaimed++;
+                    count++;
+                    cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
+                }
+            }//if
+        }//else
+    }
+    bchain->new_claimed_cells[count] = -1;// end of list
+}
+
+/** Claim a cell for a particle in the list  in 2D*/
+void _DVCWeights_ClaimCells2D(struct chain **bbchain,struct cell2d **ccells,struct particle2d **pList,int p_i){
+    int i,count;
+    int cell_num0;
+    double x0,y0,x1,y1,x2,y2,dist1;
+    struct chain *bchain = &(*bbchain)[p_i];
+    struct cell2d *cells = *ccells;
+    int *temp;
+
+    count = 0;
+    bchain->numclaimed = 0;
+
+
+    for(i=0;i<bchain->sizeofboundary;i++){
+        cell_num0 = bchain->new_bound_cells[i];// cell number we are trying to claim
+        if(cells[cell_num0].p == -1){//if cell unowned then claim cell
+            /* This is the bit needed for mallocing */
+            /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
+            if( count > bchain->new_claimed_cells_malloced - 1 ){
+                temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
+                bchain->new_claimed_cells = temp;
+                bchain->new_claimed_cells_malloced += DVC_INC;
+                temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
+                bchain->new_bound_cells = temp;
+                bchain->new_bound_cells_malloced += DVC_INC;      
+            }
+            /* end of bit needed for mallocing */
+            bchain->new_claimed_cells[count] = cell_num0;
+            bchain->numclaimed++;
+            count++;
+            cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
+        }
+        else{
+            if(cells[cell_num0].p != p_i){
+                //we need a contest between particles for the cell.
+                x2 = (*pList)[p_i].x;
+                y2 = (*pList)[p_i].y;
+                x1 = (*pList)[cells[cell_num0].p].x;
+                y1 = (*pList)[cells[cell_num0].p].y;
+                x0 = cells[cell_num0].x;
+                y0 = cells[cell_num0].y;
+        
+                dist1 = _DVCWeights_DistanceTest2D(x0,y0,x1,y1,x2,y2);
+                if(dist1 > 0.0){
+                    bchain->new_claimed_cells[count] = cell_num0;
+                    bchain->numclaimed++;
+                    count++;
+                    cells[cell_num0].p = p_i;// this cell is now owned by particle p_i
+                }
+            }//if
+        }//else
+    }
+    bchain->new_claimed_cells[count] = -1;// end of list
+}
+
+/** Reset the values in the cells so that the grid over the element can be used again */
+void _DVCWeights_ResetGrid(struct cell **cells, int n){
+    int i;
+
+    for(i=0;i<n;i++){
+        (*cells)[i].p = -1;
+        (*cells)[i].done = 0;
+    }
+}
+
+/** Reset the values in the cells so that the grid over the element can be used again, in 2D */
+void _DVCWeights_ResetGrid2D(struct cell2d **cells, int n){
+    int i;
+
+    for(i=0;i<n;i++){
+        (*cells)[i].p = -1;
+        (*cells)[i].done = 0;
+    }
+}
+
+/** Update the list of the cells on the boundary of the growing voronoi cells 
+    Add new particles on the boundary, and remove particles no longer on the boundary.*/
+void _DVCWeights_UpdateBchain(struct chain **bbchain,struct cell **ccells,int p_i){
+    int i,k,count;
+    int cell_num0,cell_num[6],cell_num1;
+    struct chain *bchain = &(*bbchain)[p_i];
+    struct cell *cells = *ccells;
+    int *temp;
+
+    count = 0;
+    bchain->sizeofboundary = 0;
+    for(i=0;i<bchain->numclaimed;i++){
+        cell_num0 =bchain->new_claimed_cells[i];
+
+        cell_num[0] = cells[cell_num0].S;    
+        cell_num[1] = cells[cell_num0].N;
+        cell_num[2] = cells[cell_num0].E;
+        cell_num[3] = cells[cell_num0].W;
+        cell_num[4] = cells[cell_num0].U;
+        cell_num[5] = cells[cell_num0].D;
+
+        for(k=0;k<6;k++){
+            cell_num1 = cell_num[k];
+            // if cell does not already belong to the particle and hasn't been
+            // marked as being done then add it to new boundary array and mark it
+            // as done
+            if(cell_num1 != -2){
+                if(cells[cell_num1].p != p_i && cells[cell_num1].done != 1){
+                    /* This is the bit needed for mallocing */     
+                    /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
+                    if( count > bchain->new_bound_cells_malloced - 1 ){
+                        temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
+                        bchain->new_claimed_cells = temp;
+                        bchain->new_claimed_cells_malloced += DVC_INC;
+                        temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
+                        bchain->new_bound_cells = temp;
+                        bchain->new_bound_cells_malloced += DVC_INC; 
+                    }
+                    /* end of bit needed for mallocing */
+                    bchain->new_bound_cells[count] = cell_num1;
+                    bchain->sizeofboundary++;
+                    count++;
+                    cells[cell_num1].done = 1;
+                }//if
+            }//if cell_num1
+        }//for k
+    }//for
+    // reset the done flags back to zero for next time
+    for(i=0;i<count;i++){
+        cells[  bchain->new_bound_cells[i]  ].done = 0;
+    }
+}
+
+/** Update the list of the cells on the boundary of the growing voronoi cells 
+    Add new particles on the boundary, and remove particles no longer on the boundary. In 2D*/
+void _DVCWeights_UpdateBchain2D(struct chain **bbchain,struct cell2d **ccells,int p_i){
+    int i,k,count;
+    int cell_num0,cell_num[4],cell_num1;
+    struct chain *bchain = &(*bbchain)[p_i];
+    struct cell2d *cells = *ccells;
+    int *temp;
+
+    count = 0;
+    bchain->sizeofboundary = 0;
+    for(i=0;i<bchain->numclaimed;i++){
+        cell_num0 =bchain->new_claimed_cells[i];
+
+        cell_num[0] = cells[cell_num0].S;    
+        cell_num[1] = cells[cell_num0].N;
+        cell_num[2] = cells[cell_num0].E;
+        cell_num[3] = cells[cell_num0].W;
+
+        for(k=0;k<4;k++){
+            cell_num1 = cell_num[k];
+            // if cell does not already belong to the particle and hasn't been
+            // marked as being done then add it to new boundary array and mark it
+            // as done
+            if(cell_num1 != -2){
+                if(cells[cell_num1].p != p_i && cells[cell_num1].done != 1){
+                    /* This is the bit needed for mallocing */     
+                    /* do a test here to see if we need to realloc bchain->new_claimed_cells and bchain->new_bound_cells */
+                    if( count > bchain->new_bound_cells_malloced - 1 ){
+                        temp = (int *)realloc( bchain->new_claimed_cells, (bchain->new_claimed_cells_malloced + DVC_INC)*sizeof(int) );
+                        bchain->new_claimed_cells = temp;
+                        bchain->new_claimed_cells_malloced += DVC_INC;
+                        temp = (int *)realloc( bchain->new_bound_cells, (bchain->new_bound_cells_malloced + DVC_INC)*sizeof(int) );
+                        bchain->new_bound_cells = temp;
+                        bchain->new_bound_cells_malloced += DVC_INC; 
+                    }
+                    /* end of bit needed for mallocing */
+                    bchain->new_bound_cells[count] = cell_num1;
+                    bchain->sizeofboundary++;
+                    count++;
+                    cells[cell_num1].done = 1;
+                }//if
+            }//if cell_num1
+        }//for k
+    }//for
+    // reset the done flags back to zero for next time
+    for(i=0;i<count;i++){
+        cells[  bchain->new_bound_cells[i]  ].done = 0;
+    }
+}
+
+
+/** Construct the grid over the element. This grid is fixed. 
+    (n, m, l) are (z, x, y) grid resolutions respectively.*/
+void _DVCWeights_ConstructGrid(struct cell **cell_list, int n, int m, int l,
+                               double x0,double y0,double z0,double x1,double y1,double z1){
+    struct cell *cells;
+    int i,j,k;
+    double dx,dy,dz,Dx,Dy,Dz,X,Y,Z;
+
+    cells = (struct cell*)malloc(n*m*l*sizeof(struct cell));
+    for(i=0;i<l*m*n;i++){
+        cells[i].S = -2;
+        cells[i].N = -2;
+        cells[i].E = -2;
+        cells[i].W = -2;
+        cells[i].U = -2;
+        cells[i].D = -2;
+        cells[i].p = -1;
+        cells[i].done = 0;
+    }
+    for(k=0;k<n;k++){
+        for(i=0;i<l*(m-1);i++){
+            cells[i+k*l*m].N=i+k*l*m+l;
+            cells[i+l+k*l*m].S = i+k*l*m;
+        }
+    }
+    for(k=0;k<n-1;k++){
+        for(i=0;i<l*m;i++){
+            cells[i+k*l*m].U=i+k*l*m+l*m;
+            cells[i+k*l*m+l*m].D = i+k*l*m;
+        }
+    }
+  
+    Dx = x1-x0; Dy = y1-y0; Dz = z1-z0;
+    dx = Dx/l;  dy = Dy/m;  dz = Dz/n;
+    Z = z0 - dz/2.0;
+    for(k=0;k<n;k++){
+        Z = Z + dz;
+        Y = y0 - dy/2.0;
+        for(j=0;j<m;j++){
+            Y = Y + dy;
+            X = x0 - dx/2.0;
+            for(i=0;i<l;i++){
+                X=X+dx;
+                cells[i+l*j+k*l*m].x = X;
+                cells[i+l*j+k*l*m].y = Y;
+                cells[i+l*j+k*l*m].z = Z;
+                if(i!= l-1){
+                    cells[i+l*j+k*l*m].E = i+l*j+1+k*l*m;
+                    cells[i+l*j+1+k*l*m].W = i+l*j+k*l*m;
+                }
+            }//x
+        }//y
+    }//z
+    *cell_list = cells; 
+}
+
+
+/** Construct the grid over the element. This grid is fixed. 
+    (m, l) are (x, y) grid resolutions respectively.*/
+void _DVCWeights_ConstructGrid2D(struct cell2d **cell_list, int m, int l,
+                                 double x0,double y0,double x1,double y1){
+    struct cell2d *cells;
+    int i,j;
+    double dx,dy,Dx,Dy,X,Y;
+
+    cells = (struct cell2d*)malloc(m*l*sizeof(struct cell));
+    for(i=0;i<l*m;i++){
+        cells[i].S = -2;
+        cells[i].N = -2;
+        cells[i].E = -2;
+        cells[i].W = -2;
+        cells[i].p = -1;
+        cells[i].done = 0;
+    }
+    for(i=0;i<l*(m-1);i++){
+        cells[i].N=i+l;
+        cells[i+l].S = i;
+    }
+    Dx = x1-x0; Dy = y1-y0;
+    dx = Dx/l;  dy = Dy/m;
+    Y = y0 - dy/2.0;
+    for(j=0;j<m;j++){
+        Y = Y + dy;
+        X = x0 - dx/2.0;
+        for(i=0;i<l;i++){
+            X=X+dx;
+            cells[i+l*j].x = X;
+            cells[i+l*j].y = Y;
+            if(i!= l-1){
+                cells[i+l*j].E = i+l*j+1;
+                cells[i+l*j+1].W = i+l*j;
+            }
+        }
+    }
+    *cell_list = cells; 
+}
+
+/** Calculate the sqaure of the distance between two points */
+double _DVCWeights_DistanceSquared(double x0, double y0, double z0, double x1, double y1, double z1){
+    return (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)+(z1-z0)*(z1-z0);
+}
+
+/** Calculate the sqaure of the distance between two points in 2D*/
+double _DVCWeights_DistanceSquared2D(double x0, double y0,double x1, double y1){
+    return (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
+}
+double _DVCWeights_DistanceTest2D(double x0, double y0, double x1, double y1,double x2, double y2){
+    return (x1+x2-x0-x0)*(x1-x2) + (y1+y2-y0-y0)*(y1-y2);
+}
+double _DVCWeights_DistanceTest(double x0, double y0, double z0, double x1, double y1, double z1, double x2, double y2, double z2){
+    return (x1+x2-x0-x0)*(x1-x2) + (y1+y2-y0-y0)*(y1-y2) + (z1+z2-z0-z0)*(z1-z2);
+}
+/** Allocate the internal structs for the bchain (boundary chain) and the plist (particle list) */
+void _DVCWeights_InitialiseStructs( struct chain **bchain, struct particle **pList, int nump){
+
+    int i;
+    // init the data structures
+    if( (*bchain = (struct chain *)malloc( nump*sizeof(struct chain ) )) == 0){
+        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ), "No memory for bchain in '%s'\nCannot continue.\n", __func__);
+    }
+    // note that doing bchain[i]->new... doesn't work
+    for(i=0;i<nump;i++){
+        (*bchain)[i].new_claimed_cells = (int *)malloc(DVC_INC*sizeof(int));
+        (*bchain)[i].new_claimed_cells_malloced = DVC_INC;
+        (*bchain)[i].new_bound_cells = (int *)malloc(DVC_INC*sizeof(int));
+        (*bchain)[i].new_bound_cells_malloced = DVC_INC;
+    }
+    if( (*pList = (struct particle *)malloc( nump*sizeof(struct particle ) )) == 0){
+        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ),"No memory for pList in '%s'\nCannot continue.\n", __func__);
+    }
+
+    /* Initialise all particle values to zero */
+    for (i = 0; i < nump; i++) {
+        (*pList)[i].x = 0; (*pList)[i].y = 0; (*pList)[i].z = 0;
+        (*pList)[i].cx = 0; (*pList)[i].cy = 0; (*pList)[i].cz = 0;
+        (*pList)[i].w = 0;
+        (*pList)[i].index = 0;
+    }
+}
+/** Allocate the internal structs for the bchain (boundary chain) and the plist (particle list) */
+void _DVCWeights_InitialiseStructs2D( struct chain **bchain, struct particle2d **pList, int nump){
+
+    int i;
+    // init the data structures
+    if( (*bchain = (struct chain *)malloc( nump*sizeof(struct chain ) )) == 0){
+        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ),"No memory for bchain in '%s'\nCannot continue.\n", __func__);
+    }
+    //
+    for(i=0;i<nump;i++){
+        (*bchain)[i].new_claimed_cells = (int *)malloc(DVC_INC*sizeof(int));
+        (*bchain)[i].new_claimed_cells_malloced = DVC_INC;
+        (*bchain)[i].new_bound_cells = (int *)malloc(DVC_INC*sizeof(int));
+        (*bchain)[i].new_bound_cells_malloced = DVC_INC;
+    }
+    if( (*pList = (struct particle2d *)malloc( nump*sizeof(struct particle2d ) )) == 0){
+        Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVC_Weights" ),"No memory for pList in '%s'\nCannot continue.\n", __func__);
+    }
+
+    /* Initialise all particle values to zero */
+    for (i = 0; i < nump; i++) {
+        (*pList)[i].x = 0; (*pList)[i].y = 0;
+        (*pList)[i].cx = 0; (*pList)[i].cy = 0;
+        (*pList)[i].w = 0;
+        (*pList)[i].index = 0;
+    }
+}
+
+/** Create the Voronoi diagram by growing the voronoi cells from the particle locations.
+    All the parameters passed into _DVCWeights_CreateVoronoi
+    must be initialised already. */
+void _DVCWeights_CreateVoronoi( struct chain **bchain, struct particle **pList, struct cell **cells, 
+                                double dx, double dy, double dz,
+                                int nump,
+                                int numx, int numy, int numz, 
+                                double BBXMIN, double BBXMAX, 
+                                double BBYMIN, double BBYMAX,
+                                double BBZMIN, double BBZMAX){
+    int i,j,k,l;
+    int count;
+    int claimed;
+
+    for(i=0;i<nump;i++){
+        k = ((*pList)[i].x - BBXMIN)/dx;
+        j = ((*pList)[i].y - BBYMIN)/dy;
+        l = ((*pList)[i].z - BBZMIN)/dz;
+        /* If a particle is exactly on the border then make sure it is in a valid cell inside the element */
+        if (k == numx){  k--; }
+        if (j == numy) { j--; }
+        if (l == numz) { l--; }
+        (*cells)[k+j*numx+l*numx*numy].p = i; //particle number i
+        (*bchain)[i].numclaimed = 1;// number of most recently claimed cells
+        (*bchain)[i].sizeofboundary = 0;
+        (*bchain)[i].totalclaimed = 1;// total of claimed cells so far.
+        (*bchain)[i].done = 0;
+        (*bchain)[i].index = k+j*numx+l*numx*numy;// ith particle is in cell # k+j*numx
+        (*bchain)[i].new_claimed_cells[0] = k+j*numx+l*numx*numy; 
+        // ith particle has just claimed cell number k+j*numx+l*numx*numy
+        (*bchain)[i].new_claimed_cells[1] = -1;// denotes end of claimed_cells list
+        // when we have finished claiming cells we call this function.
+        _DVCWeights_UpdateBchain(bchain,cells,i);
+    }
+    count = i;// number of particles
+    claimed = 1;
+      
+    while(claimed != 0){
+        claimed = 0 ;
+        for(i=0;i<count;i++){
+            _DVCWeights_ClaimCells(bchain,cells,pList,i);
+            claimed += (*bchain)[i].numclaimed;
+            _DVCWeights_UpdateBchain(bchain,cells,i);
+        }
+    }//while
+}
+
+/** Create the Voronoi diagram by growing the voronoi cells from the particle locations.
+    All the parameters passed into _DVCWeights_CreateVoronoi2D
+    must be initialised already. */
+void _DVCWeights_CreateVoronoi2D( struct chain **bchain, struct particle2d **pList, struct cell2d **cells, 
+                                  double dx, double dy,
+                                  int nump,
+                                  int numx, int numy,
+                                  double BBXMIN, double BBXMAX, 
+                                  double BBYMIN, double BBYMAX){
+    int i,j,k;
+    int claimed;
+
+    for(i=0;i<nump;i++){
+        k = ((*pList)[i].x - BBXMIN)/dx;
+        j = ((*pList)[i].y - BBYMIN)/dy;
+        /* If particle is on the border exactly, make sure it is
+           put in a valid cell inside the element */
+        if (k == numx){
+            k--;
+        }
+        if ( j == numy) {
+            j--;
+        }
+        
+        (*cells)[k+j*numx].p = i; //particle number i
+      
+        (*bchain)[i].numclaimed = 1;// number of most recently claimed cells
+        (*bchain)[i].sizeofboundary = 0;
+        (*bchain)[i].totalclaimed = 1;// total of claimed cells so far.
+        (*bchain)[i].done = 0;
+        (*bchain)[i].index = k+j*numx;// ith particle is in cell # k+j*numx
+        (*bchain)[i].new_claimed_cells[0] = k+j*numx; // ith particle has just claimed cell number k+j*numx
+        (*bchain)[i].new_claimed_cells[1] = -1;// denotes end of claimed_cells list
+        // when we have finished claiming cells we call this function.
+        _DVCWeights_UpdateBchain2D( bchain, cells, i);
+    }//nump
+   
+    claimed = 1;
+
+    while(claimed != 0){
+        claimed = 0 ;
+        for(i=0;i<nump;i++){
+            _DVCWeights_ClaimCells2D( bchain, cells, pList, i);
+            claimed += (*bchain)[i].numclaimed;
+            _DVCWeights_UpdateBchain2D( bchain, cells, i);
+        }
+    }//while
+}
+
+/* Calculate the integration weighting for each particle by contructing
+   a voronoi diagram in an element in 3D*/
+void _DVCWeights_Calculate3D( void* dvcWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    DVCWeights*             self            = (DVCWeights*)  dvcWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount;
+    IntegrationPoint**           particle;
+    static int visited = 0 ;
+    double dx,dy,dz,da;
+    static struct cell *cells;// the connected grid
+    struct particle *pList;// particle List
+    struct chain *bchain;//boundary chain
+    int nump,numx,numy,numz;
+    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
+    double BBXMAX = 1.0;
+    double BBYMIN = -1.0;
+    double BBYMAX = 1.0;
+    double BBZMIN = -1.0;
+    double BBZMAX = 1.0;
+    int i,k;
+
+    numx = self->resX;
+    numy = self->resY;
+    numz = self->resZ;
+
+    nump = cParticleCount = swarm->cellParticleCountTbl[lCell_I];
+
+    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"DVC_Weights" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
+
+    dx = (BBXMAX - BBXMIN)/numx;
+    dy = (BBYMAX - BBYMIN)/numy;
+    dz = (BBZMAX - BBZMIN)/numz;
+    da = dx*dy*dz;
+        
+    // Construct the grid for the Voronoi cells only once.
+    // If we wanted to call this function again during a job with a different resolution
+    // then we should destroy the grid once we have looped through the whole mesh.
+    // I am assuming we are not going to do that for now.
+    // Easy to implement this anyway, if needed.
+    if(!visited){
+        /* The DVCWeights class should really be a class the next level up here */
+        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
+           a pointer inside that function */
+        visited++;
+        _DVCWeights_ConstructGrid(&cells,numz,numy,numx,BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);
+    }
+        
+        
+    // init the data structures
+    _DVCWeights_InitialiseStructs( &bchain, &pList, nump);
+    _DVCWeights_ResetGrid(&cells,numz*numy*numx);
+        
+    particle = (IntegrationPoint**)malloc(nump*sizeof(IntegrationPoint*));
+        
+    // initialize the particle positions to be the local coordinates of the material swarm particles
+    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
+    // positions each time step.
+    for(i=0;i<nump;i++){
+              
+        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, i );
+        pList[i].x = particle[i]->xi[0];
+        pList[i].y = particle[i]->xi[1];
+        pList[i].z = particle[i]->xi[2];
+              
+    }
+    _DVCWeights_CreateVoronoi( &bchain, &pList, &cells, dx, dy, dz, nump, numx, numy, numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+    _DVCWeights_GetCentroids( cells, pList,numz,numy,numx,nump,da);
+    // We are setting the integration points to be the centroids of the Voronoi regions here and
+    // the weight is the volume of each Voronoi region.
+    for(i=0;i<nump;i++){
+
+        particle[i]->xi[0] = pList[i].cx;
+        particle[i]->xi[1] = pList[i].cy;
+        particle[i]->xi[2] = pList[i].cz;
+        particle[i]->weight = pList[i].w;
+
+    }   
+    for(k=0;k<nump;k++){
+        free(bchain[k].new_claimed_cells);
+        free(bchain[k].new_bound_cells);
+    }
+    free(particle);
+    free(bchain);
+    free(pList);
+
+}
+
+/* Calculate the integration weighting for each particle by contructing
+   a voronoi diagram in an element in 2D*/
+void _DVCWeights_Calculate2D( void* dvcWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    DVCWeights*             self            = (DVCWeights*)  dvcWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount;
+    IntegrationPoint**           particle;
+    static int visited = 0 ;
+    double dx,dy,da;
+    static struct cell2d *cells;// the connected grid
+    struct particle2d *pList;// particle List
+    struct chain *bchain;//boundary chain
+    int nump,numx,numy;
+    double BBXMIN = -1.0; // the ranges of the local coordinates of a FEM cell.
+    double BBXMAX = 1.0;
+    double BBYMIN = -1.0;
+    double BBYMAX = 1.0;
+    int i,k;
+
+    numx = self->resX;
+    numy = self->resY;
+
+    nump = cParticleCount = swarm->cellParticleCountTbl[lCell_I];
+
+    Journal_Firewall( nump , Journal_Register( Error_Type, (Name)"DVC_Weights" ), "Error in %s: Problem has an under resolved cell (Cell Id = %d), add more particles to your model\n", __func__, lCell_I );
+
+    dx = (BBXMAX - BBXMIN)/numx;
+    dy = (BBYMAX - BBYMIN)/numy;
+    da = dx*dy;
+        
+    // Construct the grid for the Voronoi cells only once.
+    // If we wanted to call this function again during a job with a different resolution
+    // then we should destroy the grid once we have looped through the whole mesh.
+    // I am assuming we are not going to do that for now.
+    // Easy to implement this anyway, if needed.
+    if(!visited){
+        /* The DVCWeights class should really be a class the next level up here */
+        /* We should be able to swap out the WeightsCalculator_CalculateAll instead of just setting
+           a pointer inside that function */
+        visited++;
+        _DVCWeights_ConstructGrid2D(&cells,numy,numx,BBXMIN,BBYMIN,BBXMAX,BBYMAX);
+    }
+        
+        
+    // init the data structures
+    _DVCWeights_InitialiseStructs2D( &bchain, &pList, nump);
+    _DVCWeights_ResetGrid2D(&cells,numy*numx);
+        
+    particle = (IntegrationPoint**)malloc(nump*sizeof(IntegrationPoint*));
+        
+    // initialize the particle positions to be the local coordinates of the material swarm particles
+    // I am assuming the xi's (local coords) are precalculated somewhere and get reset based on material
+    // positions each time step.
+    for(i=0;i<nump;i++){
+              
+        particle[i] = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, i );
+        pList[i].x = particle[i]->xi[0];
+        pList[i].y = particle[i]->xi[1];
+              
+    }
+    _DVCWeights_CreateVoronoi2D( &bchain, &pList, &cells, dx, dy, nump, numx, numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
+    _DVCWeights_GetCentroids2D( cells, pList,numy,numx,nump,da);
+    // We are setting the integration points to be the centroids of the Voronoi regions here and
+    // the weight is the volume of each Voronoi region.
+    for(i=0;i<nump;i++){
+
+        particle[i]->xi[0] = pList[i].cx;
+        particle[i]->xi[1] = pList[i].cy;
+        particle[i]->weight = pList[i].w;
+
+    }   
+    for(k=0;k<nump;k++){
+        free(bchain[k].new_claimed_cells);
+        free(bchain[k].new_bound_cells);
+    }
+    free(particle);
+    free(bchain);
+    free(pList);
+
+}
+
+void _DVCWeights_Calculate( void* dvcWeights, void* _swarm, Cell_LocalIndex lCell_I ){
+    Swarm* swarm = (Swarm*) _swarm;
+    Dimension_Index dim = swarm->dim;
+
+    if(dim == 3){
+        _DVCWeights_Calculate3D( dvcWeights, _swarm, lCell_I);
+    }
+    else {
+        _DVCWeights_Calculate2D( dvcWeights, _swarm, lCell_I);
+    }
+}
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/Finalise.c
--- a/Weights/src/Finalise.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-
-#include "types.h"
-#include "Finalise.h"
-
-#include <stdio.h>
-
-Bool PICellerator_Weights_Finalise( void ) {
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-	
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/Finalise.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,60 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+
+#include "types.h"
+#include "Finalise.h"
+
+#include <stdio.h>
+
+Bool PICellerator_Weights_Finalise( void ) {
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+	
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/Init.c
--- a/Weights/src/Init.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "Weights.h"
-
-#include <stdio.h>
-
-Bool PICellerator_Weights_Init( int* argc, char** argv[] ) {
-	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
-
-	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-
-	Stg_ComponentRegister_Add( componentsRegister, ConstantWeights_Type, (Name)"0", _ConstantWeights_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, VolumeWeights_Type, (Name)"0", _VolumeWeights_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, IterativeWeights_Type, (Name)"0", _IterativeWeights_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, MomentBalanceWeights_Type, (Name)"0", _MomentBalanceWeights_DefaultNew  );
-	Stg_ComponentRegister_Add( componentsRegister, DVCWeights_Type, (Name)"0", _DVCWeights_DefaultNew  );
-	
-	RegisterParent( WeightsCalculator_Type,      Stg_Component_Type );
-	RegisterParent( ConstantWeights_Type,        WeightsCalculator_Type );
-	RegisterParent( VolumeWeights_Type,          WeightsCalculator_Type );
-	RegisterParent( IterativeWeights_Type,       WeightsCalculator_Type );
-	RegisterParent( MomentBalanceWeights_Type,   WeightsCalculator_Type );
-	RegisterParent( DVCWeights_Type,             WeightsCalculator_Type );
-	
-	return True;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/Init.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,75 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "Weights.h"
+
+#include <stdio.h>
+
+Bool PICellerator_Weights_Init( int* argc, char** argv[] ) {
+	Stg_ComponentRegister* componentsRegister = Stg_ComponentRegister_Get_ComponentRegister();
+
+	Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+
+	Stg_ComponentRegister_Add( componentsRegister, ConstantWeights_Type, (Name)"0", _ConstantWeights_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, VolumeWeights_Type, (Name)"0", _VolumeWeights_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, IterativeWeights_Type, (Name)"0", _IterativeWeights_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, MomentBalanceWeights_Type, (Name)"0", _MomentBalanceWeights_DefaultNew  );
+	Stg_ComponentRegister_Add( componentsRegister, DVCWeights_Type, (Name)"0", _DVCWeights_DefaultNew  );
+	
+	RegisterParent( WeightsCalculator_Type,      Stg_Component_Type );
+	RegisterParent( ConstantWeights_Type,        WeightsCalculator_Type );
+	RegisterParent( VolumeWeights_Type,          WeightsCalculator_Type );
+	RegisterParent( IterativeWeights_Type,       WeightsCalculator_Type );
+	RegisterParent( MomentBalanceWeights_Type,   WeightsCalculator_Type );
+	RegisterParent( DVCWeights_Type,             WeightsCalculator_Type );
+	
+	return True;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/IterativeWeights.c
--- a/Weights/src/IterativeWeights.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,277 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: IterativeWeights.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "types.h"
-#include "WeightsCalculator.h"
-#include "ConstantWeights.h"
-#include "IterativeWeights.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/** IterativeWeights is an implementation of Frederic Dufour's weights routine from Ellipsis which is described
- * in his PhD Thesis Section 2.6.1 pp. 63-66 */
-
-/* Textual name of this class */
-const Type IterativeWeights_Type = "IterativeWeights";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-IterativeWeights* _IterativeWeights_New(  ITERATIVEWEIGHTS_DEFARGS  ) {
-    IterativeWeights* self;
-
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(IterativeWeights) );
-    self = (IterativeWeights*)_ConstantWeights_New(  CONSTANTWEIGHTS_PASSARGS  );
-	
-    /* General info */
-
-    /* Virtual Info */
-	
-    return self;
-}
-
-void _IterativeWeights_Init( void* iterativeWeights, WeightsCalculator* initialWeights,
-                             Iteration_Index maxIterations, double tolerance, double alpha )
-{
-    IterativeWeights* self = (IterativeWeights*)iterativeWeights;
-
-    if ( initialWeights ) {
-        self->initialWeights = initialWeights;
-        self->freeInitialWeights = False;
-    }
-    else {
-        self->initialWeights = (WeightsCalculator*) ConstantWeights_New( "initialWeights", self->dim );
-        self->freeInitialWeights = True;
-    }
-
-    self->maxIterations = maxIterations;
-    self->tolerance = tolerance;
-    self->alpha = alpha;
-	
-    Journal_Firewall( self->dim == 2, Journal_Register( Error_Type, (Name)self->type  ), "%s only works in 2D.\n", self->type );
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _IterativeWeights_Delete( void* iterativeWeights ) {
-    IterativeWeights* self = (IterativeWeights*)iterativeWeights;
-	
-    if (self->freeInitialWeights )
-        Stg_Class_Delete( self->initialWeights );
-    /* Delete parent */
-    _ConstantWeights_Delete( self );
-}
-
-
-void _IterativeWeights_Print( void* iterativeWeights, Stream* stream ) {
-    IterativeWeights* self = (IterativeWeights*)iterativeWeights;
-	
-    /* Print parent */
-    _ConstantWeights_Print( self, stream );
-}
-
-
-
-void* _IterativeWeights_Copy( const void* iterativeWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
-    IterativeWeights*	newIterativeWeights;
-	
-    newIterativeWeights = (IterativeWeights*)_ConstantWeights_Copy( self, dest, deep, nameExt, ptrMap );
-	
-    return (void*)newIterativeWeights;
-}
-
-void* _IterativeWeights_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(IterativeWeights);
-	Type                                                      type = IterativeWeights_Type;
-	Stg_Class_DeleteFunction*                              _delete = _IterativeWeights_Delete;
-	Stg_Class_PrintFunction*                                _print = _IterativeWeights_Print;
-	Stg_Class_CopyFunction*                                  _copy = _IterativeWeights_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _IterativeWeights_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _IterativeWeights_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _IterativeWeights_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _IterativeWeights_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _IterativeWeights_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _IterativeWeights_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	WeightsCalculator_CalculateFunction*                _calculate = _IterativeWeights_Calculate;
-
-    return (void*) _IterativeWeights_New(  ITERATIVEWEIGHTS_PASSARGS  );
-}
-
-
-void _IterativeWeights_AssignFromXML( void* iterativeWeights, Stg_ComponentFactory* cf, void* data ) {
-    IterativeWeights*	     self          = (IterativeWeights*) iterativeWeights;
-    WeightsCalculator*       initialWeights;
-    Iteration_Index          maxIterations;
-    double                   tolerance;
-    double                   alpha;
-
-    _ConstantWeights_AssignFromXML( self, cf, data );
-
-    initialWeights =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"InitialWeights", WeightsCalculator, False, data  );
-
-    maxIterations = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxIterations", 10  );
-    tolerance     = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"tolerance", 0.01  );
-    alpha         = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"alpha", 0.8  ); /* 0.8 is default in Dufour p. 65 */
-	
-    _IterativeWeights_Init( self, initialWeights, maxIterations, tolerance, alpha );
-}
-
-void _IterativeWeights_Build( void* iterativeWeights, void* data ) {
-    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
-
-    Stg_Component_Build( self->initialWeights, data, False ); 
-    _ConstantWeights_Build( self, data );
-}
-void _IterativeWeights_Initialise( void* iterativeWeights, void* data ) {
-    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
-
-    Stg_Component_Initialise( self->initialWeights, data, False ); 	
-    _ConstantWeights_Initialise( self, data );
-}
-void _IterativeWeights_Execute( void* iterativeWeights, void* data ) {
-    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
-	
-    _ConstantWeights_Execute( self, data );
-}
-void _IterativeWeights_Destroy( void* iterativeWeights, void* data ) {
-    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
-
-    if (self->freeInitialWeights )
-       Stg_Component_Destroy( self->initialWeights, data, False ); 	
-    _ConstantWeights_Destroy( self, data );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-void _IterativeWeights_Calculate( void* iterativeWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    IterativeWeights*            self            = (IterativeWeights*)  iterativeWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Iteration_Index              iteration_I;
-    double                       constaintLHS[3] = { 0.0,0.0,0.0 };
-    double                       squareTerms[3]  = { 0.0,0.0,1.0 };
-    double                       constaintError;
-    Particle_InCellIndex         cParticle_I;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    IntegrationPoint*            particle;
-    Dimension_Index              dim_I;
-    Dimension_Index              dim             = self->dim;
-
-    /* Initialise Weights Using Constant Weights routine - Dufour Equation 2.52 */
-    WeightsCalculator_CalculateCell( self->initialWeights, swarm, lCell_I );
-		
-    for ( iteration_I = 0 ; iteration_I < self->maxIterations ; iteration_I++ ) {
-        constaintLHS[ I_AXIS ] = WeightsCalculator_GetConstraintLHS( self, swarm, lCell_I, 1, 0, 0 );
-        constaintLHS[ J_AXIS ] = WeightsCalculator_GetConstraintLHS( self, swarm, lCell_I, 0, 1, 0 );
-        if ( self->dim == 3 )
-            constaintLHS[ K_AXIS ] = WeightsCalculator_GetConstraintLHS( self, swarm, lCell_I, 0, 0, 1 );
-
-        /* Test for convergence - See Dufour Equation 2.55 */
-        constaintError = 
-            fabs(constaintLHS[ I_AXIS ]) + 
-            fabs(constaintLHS[ J_AXIS ]) + 
-            fabs(constaintLHS[ K_AXIS ]);
-
-        if ( constaintError < self->tolerance )
-            /* Then this cell has converged - bail out of loop */
-            break;
-
-        /* Adjust weights according to Dufour Equation 2.54 */
-        squareTerms[ I_AXIS ] = WeightsCalculator_GetLocalCoordSum( self, swarm, lCell_I, 2, 0, 0 );
-        squareTerms[ J_AXIS ] = WeightsCalculator_GetLocalCoordSum( self, swarm, lCell_I, 0, 2, 0 );
-        if ( self->dim == 3 )
-            squareTerms[ K_AXIS ] = WeightsCalculator_GetLocalCoordSum( self, swarm, lCell_I, 0, 0, 2 );
-
-        for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-            particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-			
-            for ( dim_I = 0 ; dim_I < dim ; dim_I++ )
-                particle->weight -= self->alpha * constaintLHS[ dim_I ] / squareTerms[ dim_I ] * particle->xi[ dim_I ] ;
-        }
-
-        /* Scale Weights to ensure constant constaint */
-        IterativeWeights_ScaleForConstantConstraint( self, swarm, lCell_I );
-    }
-}
-
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void IterativeWeights_ScaleForConstantConstraint( void* iterativeWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    IterativeWeights*            self            = (IterativeWeights*)  iterativeWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    double                       weightsTotal    = 0.0;
-    Particle_InCellIndex         cParticle_I;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    IntegrationPoint*            particle;
-
-    weightsTotal = WeightsCalculator_SumCellWeights( self, swarm, lCell_I );
-
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-
-        /* Scale weights so that sum of weights = cellLocalVolume */
-        particle->weight *= self->cellLocalVolume/weightsTotal;
-    }
-}
-	
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/IterativeWeights.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/IterativeWeights.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,277 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: IterativeWeights.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "types.h"
+#include "WeightsCalculator.h"
+#include "ConstantWeights.h"
+#include "IterativeWeights.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/** IterativeWeights is an implementation of Frederic Dufour's weights routine from Ellipsis which is described
+ * in his PhD Thesis Section 2.6.1 pp. 63-66 */
+
+/* Textual name of this class */
+const Type IterativeWeights_Type = "IterativeWeights";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+IterativeWeights* _IterativeWeights_New(  ITERATIVEWEIGHTS_DEFARGS  ) {
+    IterativeWeights* self;
+
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(IterativeWeights) );
+    self = (IterativeWeights*)_ConstantWeights_New(  CONSTANTWEIGHTS_PASSARGS  );
+	
+    /* General info */
+
+    /* Virtual Info */
+	
+    return self;
+}
+
+void _IterativeWeights_Init( void* iterativeWeights, WeightsCalculator* initialWeights,
+                             Iteration_Index maxIterations, double tolerance, double alpha )
+{
+    IterativeWeights* self = (IterativeWeights*)iterativeWeights;
+
+    if ( initialWeights ) {
+        self->initialWeights = initialWeights;
+        self->freeInitialWeights = False;
+    }
+    else {
+        self->initialWeights = (WeightsCalculator*) ConstantWeights_New( "initialWeights", self->dim );
+        self->freeInitialWeights = True;
+    }
+
+    self->maxIterations = maxIterations;
+    self->tolerance = tolerance;
+    self->alpha = alpha;
+	
+    Journal_Firewall( self->dim == 2, Journal_Register( Error_Type, (Name)self->type  ), "%s only works in 2D.\n", self->type );
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _IterativeWeights_Delete( void* iterativeWeights ) {
+    IterativeWeights* self = (IterativeWeights*)iterativeWeights;
+	
+    if (self->freeInitialWeights )
+        Stg_Class_Delete( self->initialWeights );
+    /* Delete parent */
+    _ConstantWeights_Delete( self );
+}
+
+
+void _IterativeWeights_Print( void* iterativeWeights, Stream* stream ) {
+    IterativeWeights* self = (IterativeWeights*)iterativeWeights;
+	
+    /* Print parent */
+    _ConstantWeights_Print( self, stream );
+}
+
+
+
+void* _IterativeWeights_Copy( const void* iterativeWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
+    IterativeWeights*	newIterativeWeights;
+	
+    newIterativeWeights = (IterativeWeights*)_ConstantWeights_Copy( self, dest, deep, nameExt, ptrMap );
+	
+    return (void*)newIterativeWeights;
+}
+
+void* _IterativeWeights_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(IterativeWeights);
+	Type                                                      type = IterativeWeights_Type;
+	Stg_Class_DeleteFunction*                              _delete = _IterativeWeights_Delete;
+	Stg_Class_PrintFunction*                                _print = _IterativeWeights_Print;
+	Stg_Class_CopyFunction*                                  _copy = _IterativeWeights_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _IterativeWeights_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _IterativeWeights_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _IterativeWeights_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _IterativeWeights_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _IterativeWeights_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _IterativeWeights_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	WeightsCalculator_CalculateFunction*                _calculate = _IterativeWeights_Calculate;
+
+    return (void*) _IterativeWeights_New(  ITERATIVEWEIGHTS_PASSARGS  );
+}
+
+
+void _IterativeWeights_AssignFromXML( void* iterativeWeights, Stg_ComponentFactory* cf, void* data ) {
+    IterativeWeights*	     self          = (IterativeWeights*) iterativeWeights;
+    WeightsCalculator*       initialWeights;
+    Iteration_Index          maxIterations;
+    double                   tolerance;
+    double                   alpha;
+
+    _ConstantWeights_AssignFromXML( self, cf, data );
+
+    initialWeights =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"InitialWeights", WeightsCalculator, False, data  );
+
+    maxIterations = Stg_ComponentFactory_GetUnsignedInt( cf, self->name, (Dictionary_Entry_Key)"maxIterations", 10  );
+    tolerance     = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"tolerance", 0.01  );
+    alpha         = Stg_ComponentFactory_GetDouble( cf, self->name, (Dictionary_Entry_Key)"alpha", 0.8  ); /* 0.8 is default in Dufour p. 65 */
+	
+    _IterativeWeights_Init( self, initialWeights, maxIterations, tolerance, alpha );
+}
+
+void _IterativeWeights_Build( void* iterativeWeights, void* data ) {
+    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
+
+    Stg_Component_Build( self->initialWeights, data, False ); 
+    _ConstantWeights_Build( self, data );
+}
+void _IterativeWeights_Initialise( void* iterativeWeights, void* data ) {
+    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
+
+    Stg_Component_Initialise( self->initialWeights, data, False ); 	
+    _ConstantWeights_Initialise( self, data );
+}
+void _IterativeWeights_Execute( void* iterativeWeights, void* data ) {
+    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
+	
+    _ConstantWeights_Execute( self, data );
+}
+void _IterativeWeights_Destroy( void* iterativeWeights, void* data ) {
+    IterativeWeights*	self = (IterativeWeights*)iterativeWeights;
+
+    if (self->freeInitialWeights )
+       Stg_Component_Destroy( self->initialWeights, data, False ); 	
+    _ConstantWeights_Destroy( self, data );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+void _IterativeWeights_Calculate( void* iterativeWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    IterativeWeights*            self            = (IterativeWeights*)  iterativeWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Iteration_Index              iteration_I;
+    double                       constaintLHS[3] = { 0.0,0.0,0.0 };
+    double                       squareTerms[3]  = { 0.0,0.0,1.0 };
+    double                       constaintError;
+    Particle_InCellIndex         cParticle_I;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    IntegrationPoint*            particle;
+    Dimension_Index              dim_I;
+    Dimension_Index              dim             = self->dim;
+
+    /* Initialise Weights Using Constant Weights routine - Dufour Equation 2.52 */
+    WeightsCalculator_CalculateCell( self->initialWeights, swarm, lCell_I );
+		
+    for ( iteration_I = 0 ; iteration_I < self->maxIterations ; iteration_I++ ) {
+        constaintLHS[ I_AXIS ] = WeightsCalculator_GetConstraintLHS( self, swarm, lCell_I, 1, 0, 0 );
+        constaintLHS[ J_AXIS ] = WeightsCalculator_GetConstraintLHS( self, swarm, lCell_I, 0, 1, 0 );
+        if ( self->dim == 3 )
+            constaintLHS[ K_AXIS ] = WeightsCalculator_GetConstraintLHS( self, swarm, lCell_I, 0, 0, 1 );
+
+        /* Test for convergence - See Dufour Equation 2.55 */
+        constaintError = 
+            fabs(constaintLHS[ I_AXIS ]) + 
+            fabs(constaintLHS[ J_AXIS ]) + 
+            fabs(constaintLHS[ K_AXIS ]);
+
+        if ( constaintError < self->tolerance )
+            /* Then this cell has converged - bail out of loop */
+            break;
+
+        /* Adjust weights according to Dufour Equation 2.54 */
+        squareTerms[ I_AXIS ] = WeightsCalculator_GetLocalCoordSum( self, swarm, lCell_I, 2, 0, 0 );
+        squareTerms[ J_AXIS ] = WeightsCalculator_GetLocalCoordSum( self, swarm, lCell_I, 0, 2, 0 );
+        if ( self->dim == 3 )
+            squareTerms[ K_AXIS ] = WeightsCalculator_GetLocalCoordSum( self, swarm, lCell_I, 0, 0, 2 );
+
+        for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+            particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+			
+            for ( dim_I = 0 ; dim_I < dim ; dim_I++ )
+                particle->weight -= self->alpha * constaintLHS[ dim_I ] / squareTerms[ dim_I ] * particle->xi[ dim_I ] ;
+        }
+
+        /* Scale Weights to ensure constant constaint */
+        IterativeWeights_ScaleForConstantConstraint( self, swarm, lCell_I );
+    }
+}
+
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void IterativeWeights_ScaleForConstantConstraint( void* iterativeWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    IterativeWeights*            self            = (IterativeWeights*)  iterativeWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    double                       weightsTotal    = 0.0;
+    Particle_InCellIndex         cParticle_I;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    IntegrationPoint*            particle;
+
+    weightsTotal = WeightsCalculator_SumCellWeights( self, swarm, lCell_I );
+
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+
+        /* Scale weights so that sum of weights = cellLocalVolume */
+        particle->weight *= self->cellLocalVolume/weightsTotal;
+    }
+}
+	
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/MomentBalanceWeights.c
--- a/Weights/src/MomentBalanceWeights.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,486 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**      Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**      Victoria, 3800, 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
-**
-** Contributors:
-**      Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**      Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**      David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**      Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**      Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**      David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**      Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MomentBalanceWeights.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "types.h"
-#include "WeightsCalculator.h"
-#include "MomentBalanceWeights.h"
-#include "ConstantWeights.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type MomentBalanceWeights_Type = "MomentBalanceWeights";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-MomentBalanceWeights* MomentBalanceWeights_New( Name name, Dimension_Index dim, WeightsCalculator* backupWeights ) {
-  MomentBalanceWeights* self = (MomentBalanceWeights*)_MomentBalanceWeights_DefaultNew( name );
-
-	self->isConstructed = True;
-	_WeightsCalculator_Init( self, dim );
-	_MomentBalanceWeights_Init( self, backupWeights );
-
-	return self;
-}
-
-MomentBalanceWeights* _MomentBalanceWeights_New(  MOMENTBALANCEWEIGHTS_DEFARGS  ) {
-	MomentBalanceWeights* self;
-	
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(MomentBalanceWeights) );
-    self = (MomentBalanceWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  ); 
-
-    /* General info */
-
-    /* Virtual Info */
-
-    return self;
-}
-
-void _MomentBalanceWeights_Init( void* momentBalanceWeights, WeightsCalculator* backupWeights ) {
-    MomentBalanceWeights* self = (MomentBalanceWeights*)momentBalanceWeights;
-
-    if ( backupWeights ) {
-        self->backupWeights = backupWeights;
-        self->freeBackupWeights = False;
-    }
-    else {
-        self->backupWeights = (WeightsCalculator*) ConstantWeights_New( "backupWeights", self->dim );
-        self->freeBackupWeights = True;
-    }
-        
-    Journal_Firewall( self->dim == 2, Journal_Register( Error_Type, (Name)self->type  ), "%s only works in 2D.\n", self->type );
-        
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _MomentBalanceWeights_Delete( void* momentBalanceWeights ) {
-    MomentBalanceWeights* self = (MomentBalanceWeights*)momentBalanceWeights;
-        
-    /* Delete parent */
-    _WeightsCalculator_Delete( self );
-}
-
-void _MomentBalanceWeights_Print( void* momentBalanceWeights, Stream* stream ) {
-    MomentBalanceWeights* self = (MomentBalanceWeights*)momentBalanceWeights;
-        
-    /* Print parent */
-    _WeightsCalculator_Print( self, stream );
-}
-
-void* _MomentBalanceWeights_Copy( const void* momentBalanceWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
-    MomentBalanceWeights*       newMomentBalanceWeights;
-        
-    newMomentBalanceWeights = (MomentBalanceWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
-        
-    return (void*)newMomentBalanceWeights;
-}
-
-void* _MomentBalanceWeights_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(MomentBalanceWeights);
-	Type                                                      type = MomentBalanceWeights_Type;
-	Stg_Class_DeleteFunction*                              _delete = _MomentBalanceWeights_Delete;
-	Stg_Class_PrintFunction*                                _print = _MomentBalanceWeights_Print;
-	Stg_Class_CopyFunction*                                  _copy = _MomentBalanceWeights_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _MomentBalanceWeights_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _MomentBalanceWeights_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _MomentBalanceWeights_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _MomentBalanceWeights_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _MomentBalanceWeights_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _MomentBalanceWeights_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	WeightsCalculator_CalculateFunction*                _calculate = _MomentBalanceWeights_Calculate;
-
-    return (void*) _MomentBalanceWeights_New(  MOMENTBALANCEWEIGHTS_PASSARGS  );
-}
-
-void _MomentBalanceWeights_AssignFromXML( void* momentBalanceWeights, Stg_ComponentFactory* cf, void* data ) {
-    MomentBalanceWeights*            self          = (MomentBalanceWeights*) momentBalanceWeights;
-    WeightsCalculator*           backupWeights;
-
-    _WeightsCalculator_AssignFromXML( self, cf, data );
-
-    backupWeights =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"BackupWeights", WeightsCalculator, False, data  );
-
-    _MomentBalanceWeights_Init( self, backupWeights );
-}
-
-void _MomentBalanceWeights_Build( void* momentBalanceWeights, void* data ) {
-    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
-    
-    Stg_Component_Build( self->backupWeights, data, False );
-    _WeightsCalculator_Build( self, data );
-}
-void _MomentBalanceWeights_Initialise( void* momentBalanceWeights, void* data ) {
-    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
-
-    Stg_Component_Initialise( self->backupWeights, data, False );
-    _WeightsCalculator_Initialise( self, data );
-}
-void _MomentBalanceWeights_Execute( void* momentBalanceWeights, void* data ) {
-    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
-        
-    _WeightsCalculator_Execute( self, data );
-}
-void _MomentBalanceWeights_Destroy( void* momentBalanceWeights, void* data ) {
-    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
-
-    if ( self->freeBackupWeights )
-       Stg_Component_Destroy( self->backupWeights, data, False );
-    _WeightsCalculator_Destroy( self, data );
-}
-
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-typedef struct {
-    double         x;
-    double         y;
-    double         z;
-    double         weight;
-    Particle_Index particleCount;
-} RegionInfo;
-
-typedef enum {
-    REGION_A,
-    REGION_B,
-    REGION_C,
-    REGION_D,
-    REGION_E,
-    REGION_F,
-    REGION_G,
-    REGION_H
-} RegionIndex;
-
-
-#define _MomentBalanceWeights_WhichRegion2D( xi )               \
-    (( xi[ I_AXIS ] < 0.0 )                                     \
-     ? (( xi[ J_AXIS ] < 0.0 ) ? REGION_C : REGION_B )          \
-     : (( xi[ J_AXIS ] < 0.0 ) ? REGION_D : REGION_A ) )
-
-void _MomentBalanceWeights_Calculate( void* momentBalanceWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    MomentBalanceWeights*        self            = (MomentBalanceWeights*)  momentBalanceWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    Particle_InCellIndex         cParticle_I;
-    RegionInfo                   region[4];
-    RegionIndex                  region_I;
-    double*                      xi;
-    double                       n;
-    double                       m;
-    IntegrationPoint*            particle;
-    double                       a,b,c;
-                
-    /* First Step -
-     * Assume all weights are constant in quadrants - i.e.                  
-     * -------------
-     * |  B  |  A  |
-     * |  C  |  D  |
-     * -------------
-     *
-     * This gives us three constaint equations:
-     * W_A N_A + W_B N_B + W_C N_C + W_D N_D = 4
-     * W_A X_A + W_D X_D = W_B X_B + W_C X_C
-     * W_A Y_A + W_B Y_B = W_C Y_C + W_D Y_D 
-     *
-     * where
-     *
-     * W_Q is the weight for each particle in region Q,
-     * N_Q is the number of particles in region Q,
-     * X_Q = \sum_{q=1}^{N_q} |\xi_{q} | and
-     * Y_Q = \sum_{q=1}^{N_q} |\eta_{q}| */
-
-    memset( region, 0, 4 * sizeof(RegionInfo) );
-
-    /* Calculate region data from particle local coordinates */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-        xi       = particle->xi;
-
-        region_I = _MomentBalanceWeights_WhichRegion2D( xi );
-        region[ region_I ].x += fabs(xi[ I_AXIS ]);
-        region[ region_I ].y += fabs(xi[ J_AXIS ]);
-
-        region[ region_I ].particleCount++;
-    }
-
-    /* Make sure each region has particles - otherwise use back up */
-    if ( region[ REGION_A ].particleCount == 0 ||
-         region[ REGION_B ].particleCount == 0 ||
-         region[ REGION_C ].particleCount == 0 ||
-         region[ REGION_D ].particleCount == 0 ) 
-    {
-        WeightsCalculator_CalculateCell( self->backupWeights, swarm, lCell_I );
-        return;
-    }
-
-
-    /** Let  n = W_B/W_C and
-     *       m = W_D/W_C 
-     *
-     * Assume that the ratios of W_A/W_B and W_D/W_C are the same and
-     * (which also means that W_A/W_D = W_B/W_C)
-     *  
-     * Therefore:
-     *       nm = W_A/W_C 
-     *
-     * This gives us the constraint equations
-     *
-     * nm N_A + n N_B + N_C + m N_D = 4/W_C
-     * nm X_A + m X_D = n X_B + X_C
-     * nm Y_A + n Y_B = Y_C + m Y_D
-     *
-     * Therefore:
-     * m = \frac{n X_B + X_C}{n X_A + X_D} = \frac{ Y_C - n Y_B }{ nY_A - Y_D }
-     * and
-     * (X_B Y_A + Y_B X_A)n^2 + (X_C Y_A + Y_B X_D - Y_D X_B - X_A Y_C)n - (X_C Y_D + Y_C X_D) = 0
-     * which we can solve using the quadratic formula */
-
-    a = ( region[ REGION_A ].y * region[ REGION_B ].x + region[ REGION_A ].x * region[ REGION_B ].y );
-    b = ( region[ REGION_A ].y * region[ REGION_C ].x - region[ REGION_A ].x * region[ REGION_C ].y ) +
-        ( region[ REGION_B ].y * region[ REGION_D ].x - region[ REGION_B ].x * region[ REGION_D ].y );
-    c = - ( region[ REGION_D ].y * region[ REGION_C ].x + region[ REGION_D ].x * region[ REGION_C ].y );
-
-    /* We take the solution which will always give a positive n */
-    n = (-b + sqrt( b*b - 4.0 * a * c ))/(2.0 * a);
-                
-    m = ( n * region[ REGION_B ].x + region[ REGION_C ].x)/
-        ( n * region[ REGION_A ].x + region[ REGION_D ].x);
-
-    /* Calculate weights from intermediate values */
-    region[ REGION_C ].weight = self->cellLocalVolume /
-        ( (double) region[ REGION_A ].particleCount * n * m
-          + (double) region[ REGION_B ].particleCount * n
-          + (double) region[ REGION_C ].particleCount  
-          + (double) region[ REGION_D ].particleCount * m );
-
-    region[ REGION_A ].weight = n * m * region[ REGION_C ].weight;
-    region[ REGION_B ].weight = n *     region[ REGION_C ].weight;
-    region[ REGION_D ].weight =     m * region[ REGION_C ].weight;
-
-    /* Assign weights to particles according to which region it is in */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-        xi       = particle->xi;
-
-        region_I = _MomentBalanceWeights_WhichRegion2D( xi );
-        particle->weight = region[ region_I ].weight;
-    }
-}
-
-
-#define _MomentBalanceWeights_WhichRegion3D( xi )               \
-    (( xi[ K_AXIS ] < 0.0 )                                     \
-     ? ( (( xi[ I_AXIS ] < 0.0 )                                \
-          ? (( xi[ J_AXIS ] < 0.0 ) ? REGION_C : REGION_B )     \
-          : (( xi[ J_AXIS ] < 0.0 ) ? REGION_D : REGION_A ) ))  \
-     : ( (( xi[ I_AXIS ] < 0.0 )                                \
-          ? (( xi[ J_AXIS ] < 0.0 ) ? REGION_G : REGION_F )     \
-          : (( xi[ J_AXIS ] < 0.0 ) ? REGION_H : REGION_E ) )))
-
-void _MomentBalanceWeights_Calculate3D( void* momentBalanceWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    MomentBalanceWeights*        self            = (MomentBalanceWeights*)  momentBalanceWeights;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    Particle_InCellIndex         cParticle_I;
-    RegionInfo                   region[8];
-    RegionIndex                  region_I;
-    double*                      xi;
-    double                       n;
-    double                       m;
-/*      double                       q; */
-    IntegrationPoint*            particle;
-    double                       a,b,c;
-                
-    /* First Step -
-     * Assume all weights are constant in octants - i.e.                  
-     * -FRONT-FACE--
-     * |  B  |  A  |
-     * |  C  |  D  |
-     * -------------
-     *
-     * --BACK-FACE--
-     * |  F  |  E  |
-     * |  G  |  H  |
-     * -------------
-     *
-     * This gives us four constaint equations:
-     * W_A N_A + W_B N_B + W_C N_C + W_D N_D + W_E N_E + W_F N_F + W_G N_G + W_H N_H= 8
-     * W_A X_A + W_D X_D + W_E X_E + W_H X_H = W_B X_B + W_C X_C + W_F X_F + W_G X_G
-     * W_A Y_A + W_B Y_B + W_F Y_F + W_E Y_E = W_C Y_C + W_D Y_D + W_G Y_G + W_H Y_H
-     * W_A Z_A + W_B Z_B + W_C Z_C + W_D Z_D = W_E Z_E + W_F Z_F + W_G Z_G + W_H Z_H
-     *
-     * where
-     *
-     * W_Q is the weight for each particle in region Q,
-     * N_Q is the number of particles in region Q,
-     * X_Q = \sum_{q=1}^{N_q} |\xi_{q}  | and
-     * Y_Q = \sum_{q=1}^{N_q} |\eta_{q} | 
-     * Z_Q = \sum_{q=1}^{N_q} |\zeta_{q}| */
-
-    memset( region, 0, 8 * sizeof(RegionInfo) );
-
-    /* Calculate region data from particle local coordinates */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-        xi       = particle->xi;
-
-        region_I = _MomentBalanceWeights_WhichRegion3D( xi );
-        region[ region_I ].x += fabs(xi[ I_AXIS ]);
-        region[ region_I ].y += fabs(xi[ J_AXIS ]);
-        region[ region_I ].z += fabs(xi[ K_AXIS ]);
-
-        region[ region_I ].particleCount++;
-    }
-
-    /* Make sure each region has particles - otherwise use back up */
-    if ( region[ REGION_A ].particleCount == 0 ||
-         region[ REGION_B ].particleCount == 0 ||
-         region[ REGION_C ].particleCount == 0 ||
-         region[ REGION_D ].particleCount == 0 ||
-         region[ REGION_E ].particleCount == 0 ||
-         region[ REGION_F ].particleCount == 0 ||
-         region[ REGION_G ].particleCount == 0 ||
-         region[ REGION_H ].particleCount == 0 ) 
-    {
-        WeightsCalculator_CalculateCell( self->backupWeights, swarm, lCell_I );
-        return;
-    }
-
-
-    /** Let  n = W_B/W_C and
-     *       m = W_D/W_C 
-     *       q = W_G/W_C 
-     *
-     * To keep ratios even - as in 2D case assume:
-     *  
-     * Therefore:
-     *       nm  = W_A/W_C 
-     *       nmq = W_E/W_C 
-     *       nq  = W_F/W_C 
-     *       mq  = W_H/W_C 
-     *
-     * This gives us the constrain equations
-     *
-     * n X_B + X_C + nq X_F + q X_G      = nm X_A + m X_D + nmq X_E + mq X_H
-     * n Y_B + nm Y_A + nq Y_F + nmq Y_E = Y_C + m Y_D + q Y_G + mq Y_H
-     * nm Z_A + n Z_B + Z_C + m Z_D      = nmq Z_E + nq Z_F + q Z_G + mq Z_H
-     *
-     * Therefore, we obtain 3 equations for m:
-     * m = \frac{ n X_B + X_C + nq X_F + q X_G }{ n X_A + X_D + nq X_E + q X_H }
-     *   = \frac{ n Y_B + nq Y_F - Y_C - q Y_G }{ Y_D + q Y_H + - n Y_A - nq Y_E }
-     *   TODO other one
-     *
-     * which gives two quadratics for n in terms of q:
-     *
-     *   n^2 ( q^2(X_E Y_F + X_F Y_E) + q(X_E Y_B + X_B Y_E + X_A Y_F + X_F Y_A) + (X_B Y_A + X_A Y_B) )
-     * + n   ( q^2( X_G Y_E - X_E Y_G + X_H Y_F - X_F Y_H ) + 
-     *                          + q ( X_H Y_B - X_B Y_H + X_D Y_F - X_F Y_D + X_C Y_E - Y_C X_E + X_G Y_A - X_A Y_G )
-     *                          ( X_C Y_A - X_A Y_C ) + (X_D Y_B - X_B Y_D) )
-     * - ( q^2( X_H Y_G + X_G Y_H ) + q( X_G Y_D + X_D Y_G + X_H Y_C + X_C Y_H ) + X_D Y_C + X_C Y_D ) = 0
-     *
-     * and
-     *   TODO other one
-     *
-     * which we can solve using the quadratic formula:
-     *
-     * n = 
-     * */
-
-    a = ( region[ REGION_A ].y * region[ REGION_B ].x + region[ REGION_A ].x * region[ REGION_B ].y );
-    b = ( region[ REGION_A ].y * region[ REGION_C ].x - region[ REGION_A ].x * region[ REGION_C ].y ) +
-        ( region[ REGION_B ].y * region[ REGION_D ].x - region[ REGION_B ].x * region[ REGION_D ].y );
-    c = - ( region[ REGION_D ].y * region[ REGION_C ].x + region[ REGION_D ].x * region[ REGION_C ].y );
-
-    /* We take the solution which will always give a positive n */
-    n = (-b + sqrt( b*b - 4.0 * a * c ))/(2.0 * a);
-                
-    m = ( n * region[ REGION_B ].x + region[ REGION_C ].x)/
-        ( n * region[ REGION_A ].x + region[ REGION_D ].x);
-
-    /* Calculate weights from intermediate values */
-    region[ REGION_C ].weight = self->cellLocalVolume /
-        ( (double) region[ REGION_A ].particleCount * n * m
-          + (double) region[ REGION_B ].particleCount * n
-          + (double) region[ REGION_C ].particleCount  
-          + (double) region[ REGION_D ].particleCount * m );
-
-    region[ REGION_A ].weight = n * m * region[ REGION_C ].weight;
-    region[ REGION_B ].weight = n *     region[ REGION_C ].weight;
-    region[ REGION_D ].weight =     m * region[ REGION_C ].weight;
-
-    /* Assign weights to particles according to which region it is in */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-        xi       = particle->xi;
-
-        region_I = _MomentBalanceWeights_WhichRegion2D( xi );
-        particle->weight = region[ region_I ].weight;
-    }
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/MomentBalanceWeights.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/MomentBalanceWeights.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,486 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**      Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**      Victoria, 3800, 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
+**
+** Contributors:
+**      Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**      Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**      David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**      Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**      Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**      David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**      Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MomentBalanceWeights.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "types.h"
+#include "WeightsCalculator.h"
+#include "MomentBalanceWeights.h"
+#include "ConstantWeights.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type MomentBalanceWeights_Type = "MomentBalanceWeights";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+MomentBalanceWeights* MomentBalanceWeights_New( Name name, Dimension_Index dim, WeightsCalculator* backupWeights ) {
+  MomentBalanceWeights* self = (MomentBalanceWeights*)_MomentBalanceWeights_DefaultNew( name );
+
+	self->isConstructed = True;
+	_WeightsCalculator_Init( self, dim );
+	_MomentBalanceWeights_Init( self, backupWeights );
+
+	return self;
+}
+
+MomentBalanceWeights* _MomentBalanceWeights_New(  MOMENTBALANCEWEIGHTS_DEFARGS  ) {
+	MomentBalanceWeights* self;
+	
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(MomentBalanceWeights) );
+    self = (MomentBalanceWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  ); 
+
+    /* General info */
+
+    /* Virtual Info */
+
+    return self;
+}
+
+void _MomentBalanceWeights_Init( void* momentBalanceWeights, WeightsCalculator* backupWeights ) {
+    MomentBalanceWeights* self = (MomentBalanceWeights*)momentBalanceWeights;
+
+    if ( backupWeights ) {
+        self->backupWeights = backupWeights;
+        self->freeBackupWeights = False;
+    }
+    else {
+        self->backupWeights = (WeightsCalculator*) ConstantWeights_New( "backupWeights", self->dim );
+        self->freeBackupWeights = True;
+    }
+        
+    Journal_Firewall( self->dim == 2, Journal_Register( Error_Type, (Name)self->type  ), "%s only works in 2D.\n", self->type );
+        
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _MomentBalanceWeights_Delete( void* momentBalanceWeights ) {
+    MomentBalanceWeights* self = (MomentBalanceWeights*)momentBalanceWeights;
+        
+    /* Delete parent */
+    _WeightsCalculator_Delete( self );
+}
+
+void _MomentBalanceWeights_Print( void* momentBalanceWeights, Stream* stream ) {
+    MomentBalanceWeights* self = (MomentBalanceWeights*)momentBalanceWeights;
+        
+    /* Print parent */
+    _WeightsCalculator_Print( self, stream );
+}
+
+void* _MomentBalanceWeights_Copy( const void* momentBalanceWeights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
+    MomentBalanceWeights*       newMomentBalanceWeights;
+        
+    newMomentBalanceWeights = (MomentBalanceWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
+        
+    return (void*)newMomentBalanceWeights;
+}
+
+void* _MomentBalanceWeights_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(MomentBalanceWeights);
+	Type                                                      type = MomentBalanceWeights_Type;
+	Stg_Class_DeleteFunction*                              _delete = _MomentBalanceWeights_Delete;
+	Stg_Class_PrintFunction*                                _print = _MomentBalanceWeights_Print;
+	Stg_Class_CopyFunction*                                  _copy = _MomentBalanceWeights_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _MomentBalanceWeights_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _MomentBalanceWeights_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _MomentBalanceWeights_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _MomentBalanceWeights_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _MomentBalanceWeights_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _MomentBalanceWeights_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	WeightsCalculator_CalculateFunction*                _calculate = _MomentBalanceWeights_Calculate;
+
+    return (void*) _MomentBalanceWeights_New(  MOMENTBALANCEWEIGHTS_PASSARGS  );
+}
+
+void _MomentBalanceWeights_AssignFromXML( void* momentBalanceWeights, Stg_ComponentFactory* cf, void* data ) {
+    MomentBalanceWeights*            self          = (MomentBalanceWeights*) momentBalanceWeights;
+    WeightsCalculator*           backupWeights;
+
+    _WeightsCalculator_AssignFromXML( self, cf, data );
+
+    backupWeights =  Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"BackupWeights", WeightsCalculator, False, data  );
+
+    _MomentBalanceWeights_Init( self, backupWeights );
+}
+
+void _MomentBalanceWeights_Build( void* momentBalanceWeights, void* data ) {
+    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
+    
+    Stg_Component_Build( self->backupWeights, data, False );
+    _WeightsCalculator_Build( self, data );
+}
+void _MomentBalanceWeights_Initialise( void* momentBalanceWeights, void* data ) {
+    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
+
+    Stg_Component_Initialise( self->backupWeights, data, False );
+    _WeightsCalculator_Initialise( self, data );
+}
+void _MomentBalanceWeights_Execute( void* momentBalanceWeights, void* data ) {
+    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
+        
+    _WeightsCalculator_Execute( self, data );
+}
+void _MomentBalanceWeights_Destroy( void* momentBalanceWeights, void* data ) {
+    MomentBalanceWeights*       self = (MomentBalanceWeights*)momentBalanceWeights;
+
+    if ( self->freeBackupWeights )
+       Stg_Component_Destroy( self->backupWeights, data, False );
+    _WeightsCalculator_Destroy( self, data );
+}
+
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+typedef struct {
+    double         x;
+    double         y;
+    double         z;
+    double         weight;
+    Particle_Index particleCount;
+} RegionInfo;
+
+typedef enum {
+    REGION_A,
+    REGION_B,
+    REGION_C,
+    REGION_D,
+    REGION_E,
+    REGION_F,
+    REGION_G,
+    REGION_H
+} RegionIndex;
+
+
+#define _MomentBalanceWeights_WhichRegion2D( xi )               \
+    (( xi[ I_AXIS ] < 0.0 )                                     \
+     ? (( xi[ J_AXIS ] < 0.0 ) ? REGION_C : REGION_B )          \
+     : (( xi[ J_AXIS ] < 0.0 ) ? REGION_D : REGION_A ) )
+
+void _MomentBalanceWeights_Calculate( void* momentBalanceWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    MomentBalanceWeights*        self            = (MomentBalanceWeights*)  momentBalanceWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    Particle_InCellIndex         cParticle_I;
+    RegionInfo                   region[4];
+    RegionIndex                  region_I;
+    double*                      xi;
+    double                       n;
+    double                       m;
+    IntegrationPoint*            particle;
+    double                       a,b,c;
+                
+    /* First Step -
+     * Assume all weights are constant in quadrants - i.e.                  
+     * -------------
+     * |  B  |  A  |
+     * |  C  |  D  |
+     * -------------
+     *
+     * This gives us three constaint equations:
+     * W_A N_A + W_B N_B + W_C N_C + W_D N_D = 4
+     * W_A X_A + W_D X_D = W_B X_B + W_C X_C
+     * W_A Y_A + W_B Y_B = W_C Y_C + W_D Y_D 
+     *
+     * where
+     *
+     * W_Q is the weight for each particle in region Q,
+     * N_Q is the number of particles in region Q,
+     * X_Q = \sum_{q=1}^{N_q} |\xi_{q} | and
+     * Y_Q = \sum_{q=1}^{N_q} |\eta_{q}| */
+
+    memset( region, 0, 4 * sizeof(RegionInfo) );
+
+    /* Calculate region data from particle local coordinates */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+        xi       = particle->xi;
+
+        region_I = _MomentBalanceWeights_WhichRegion2D( xi );
+        region[ region_I ].x += fabs(xi[ I_AXIS ]);
+        region[ region_I ].y += fabs(xi[ J_AXIS ]);
+
+        region[ region_I ].particleCount++;
+    }
+
+    /* Make sure each region has particles - otherwise use back up */
+    if ( region[ REGION_A ].particleCount == 0 ||
+         region[ REGION_B ].particleCount == 0 ||
+         region[ REGION_C ].particleCount == 0 ||
+         region[ REGION_D ].particleCount == 0 ) 
+    {
+        WeightsCalculator_CalculateCell( self->backupWeights, swarm, lCell_I );
+        return;
+    }
+
+
+    /** Let  n = W_B/W_C and
+     *       m = W_D/W_C 
+     *
+     * Assume that the ratios of W_A/W_B and W_D/W_C are the same and
+     * (which also means that W_A/W_D = W_B/W_C)
+     *  
+     * Therefore:
+     *       nm = W_A/W_C 
+     *
+     * This gives us the constraint equations
+     *
+     * nm N_A + n N_B + N_C + m N_D = 4/W_C
+     * nm X_A + m X_D = n X_B + X_C
+     * nm Y_A + n Y_B = Y_C + m Y_D
+     *
+     * Therefore:
+     * m = \frac{n X_B + X_C}{n X_A + X_D} = \frac{ Y_C - n Y_B }{ nY_A - Y_D }
+     * and
+     * (X_B Y_A + Y_B X_A)n^2 + (X_C Y_A + Y_B X_D - Y_D X_B - X_A Y_C)n - (X_C Y_D + Y_C X_D) = 0
+     * which we can solve using the quadratic formula */
+
+    a = ( region[ REGION_A ].y * region[ REGION_B ].x + region[ REGION_A ].x * region[ REGION_B ].y );
+    b = ( region[ REGION_A ].y * region[ REGION_C ].x - region[ REGION_A ].x * region[ REGION_C ].y ) +
+        ( region[ REGION_B ].y * region[ REGION_D ].x - region[ REGION_B ].x * region[ REGION_D ].y );
+    c = - ( region[ REGION_D ].y * region[ REGION_C ].x + region[ REGION_D ].x * region[ REGION_C ].y );
+
+    /* We take the solution which will always give a positive n */
+    n = (-b + sqrt( b*b - 4.0 * a * c ))/(2.0 * a);
+                
+    m = ( n * region[ REGION_B ].x + region[ REGION_C ].x)/
+        ( n * region[ REGION_A ].x + region[ REGION_D ].x);
+
+    /* Calculate weights from intermediate values */
+    region[ REGION_C ].weight = self->cellLocalVolume /
+        ( (double) region[ REGION_A ].particleCount * n * m
+          + (double) region[ REGION_B ].particleCount * n
+          + (double) region[ REGION_C ].particleCount  
+          + (double) region[ REGION_D ].particleCount * m );
+
+    region[ REGION_A ].weight = n * m * region[ REGION_C ].weight;
+    region[ REGION_B ].weight = n *     region[ REGION_C ].weight;
+    region[ REGION_D ].weight =     m * region[ REGION_C ].weight;
+
+    /* Assign weights to particles according to which region it is in */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+        xi       = particle->xi;
+
+        region_I = _MomentBalanceWeights_WhichRegion2D( xi );
+        particle->weight = region[ region_I ].weight;
+    }
+}
+
+
+#define _MomentBalanceWeights_WhichRegion3D( xi )               \
+    (( xi[ K_AXIS ] < 0.0 )                                     \
+     ? ( (( xi[ I_AXIS ] < 0.0 )                                \
+          ? (( xi[ J_AXIS ] < 0.0 ) ? REGION_C : REGION_B )     \
+          : (( xi[ J_AXIS ] < 0.0 ) ? REGION_D : REGION_A ) ))  \
+     : ( (( xi[ I_AXIS ] < 0.0 )                                \
+          ? (( xi[ J_AXIS ] < 0.0 ) ? REGION_G : REGION_F )     \
+          : (( xi[ J_AXIS ] < 0.0 ) ? REGION_H : REGION_E ) )))
+
+void _MomentBalanceWeights_Calculate3D( void* momentBalanceWeights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    MomentBalanceWeights*        self            = (MomentBalanceWeights*)  momentBalanceWeights;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    Particle_InCellIndex         cParticle_I;
+    RegionInfo                   region[8];
+    RegionIndex                  region_I;
+    double*                      xi;
+    double                       n;
+    double                       m;
+/*      double                       q; */
+    IntegrationPoint*            particle;
+    double                       a,b,c;
+                
+    /* First Step -
+     * Assume all weights are constant in octants - i.e.                  
+     * -FRONT-FACE--
+     * |  B  |  A  |
+     * |  C  |  D  |
+     * -------------
+     *
+     * --BACK-FACE--
+     * |  F  |  E  |
+     * |  G  |  H  |
+     * -------------
+     *
+     * This gives us four constaint equations:
+     * W_A N_A + W_B N_B + W_C N_C + W_D N_D + W_E N_E + W_F N_F + W_G N_G + W_H N_H= 8
+     * W_A X_A + W_D X_D + W_E X_E + W_H X_H = W_B X_B + W_C X_C + W_F X_F + W_G X_G
+     * W_A Y_A + W_B Y_B + W_F Y_F + W_E Y_E = W_C Y_C + W_D Y_D + W_G Y_G + W_H Y_H
+     * W_A Z_A + W_B Z_B + W_C Z_C + W_D Z_D = W_E Z_E + W_F Z_F + W_G Z_G + W_H Z_H
+     *
+     * where
+     *
+     * W_Q is the weight for each particle in region Q,
+     * N_Q is the number of particles in region Q,
+     * X_Q = \sum_{q=1}^{N_q} |\xi_{q}  | and
+     * Y_Q = \sum_{q=1}^{N_q} |\eta_{q} | 
+     * Z_Q = \sum_{q=1}^{N_q} |\zeta_{q}| */
+
+    memset( region, 0, 8 * sizeof(RegionInfo) );
+
+    /* Calculate region data from particle local coordinates */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+        xi       = particle->xi;
+
+        region_I = _MomentBalanceWeights_WhichRegion3D( xi );
+        region[ region_I ].x += fabs(xi[ I_AXIS ]);
+        region[ region_I ].y += fabs(xi[ J_AXIS ]);
+        region[ region_I ].z += fabs(xi[ K_AXIS ]);
+
+        region[ region_I ].particleCount++;
+    }
+
+    /* Make sure each region has particles - otherwise use back up */
+    if ( region[ REGION_A ].particleCount == 0 ||
+         region[ REGION_B ].particleCount == 0 ||
+         region[ REGION_C ].particleCount == 0 ||
+         region[ REGION_D ].particleCount == 0 ||
+         region[ REGION_E ].particleCount == 0 ||
+         region[ REGION_F ].particleCount == 0 ||
+         region[ REGION_G ].particleCount == 0 ||
+         region[ REGION_H ].particleCount == 0 ) 
+    {
+        WeightsCalculator_CalculateCell( self->backupWeights, swarm, lCell_I );
+        return;
+    }
+
+
+    /** Let  n = W_B/W_C and
+     *       m = W_D/W_C 
+     *       q = W_G/W_C 
+     *
+     * To keep ratios even - as in 2D case assume:
+     *  
+     * Therefore:
+     *       nm  = W_A/W_C 
+     *       nmq = W_E/W_C 
+     *       nq  = W_F/W_C 
+     *       mq  = W_H/W_C 
+     *
+     * This gives us the constrain equations
+     *
+     * n X_B + X_C + nq X_F + q X_G      = nm X_A + m X_D + nmq X_E + mq X_H
+     * n Y_B + nm Y_A + nq Y_F + nmq Y_E = Y_C + m Y_D + q Y_G + mq Y_H
+     * nm Z_A + n Z_B + Z_C + m Z_D      = nmq Z_E + nq Z_F + q Z_G + mq Z_H
+     *
+     * Therefore, we obtain 3 equations for m:
+     * m = \frac{ n X_B + X_C + nq X_F + q X_G }{ n X_A + X_D + nq X_E + q X_H }
+     *   = \frac{ n Y_B + nq Y_F - Y_C - q Y_G }{ Y_D + q Y_H + - n Y_A - nq Y_E }
+     *   TODO other one
+     *
+     * which gives two quadratics for n in terms of q:
+     *
+     *   n^2 ( q^2(X_E Y_F + X_F Y_E) + q(X_E Y_B + X_B Y_E + X_A Y_F + X_F Y_A) + (X_B Y_A + X_A Y_B) )
+     * + n   ( q^2( X_G Y_E - X_E Y_G + X_H Y_F - X_F Y_H ) + 
+     *                          + q ( X_H Y_B - X_B Y_H + X_D Y_F - X_F Y_D + X_C Y_E - Y_C X_E + X_G Y_A - X_A Y_G )
+     *                          ( X_C Y_A - X_A Y_C ) + (X_D Y_B - X_B Y_D) )
+     * - ( q^2( X_H Y_G + X_G Y_H ) + q( X_G Y_D + X_D Y_G + X_H Y_C + X_C Y_H ) + X_D Y_C + X_C Y_D ) = 0
+     *
+     * and
+     *   TODO other one
+     *
+     * which we can solve using the quadratic formula:
+     *
+     * n = 
+     * */
+
+    a = ( region[ REGION_A ].y * region[ REGION_B ].x + region[ REGION_A ].x * region[ REGION_B ].y );
+    b = ( region[ REGION_A ].y * region[ REGION_C ].x - region[ REGION_A ].x * region[ REGION_C ].y ) +
+        ( region[ REGION_B ].y * region[ REGION_D ].x - region[ REGION_B ].x * region[ REGION_D ].y );
+    c = - ( region[ REGION_D ].y * region[ REGION_C ].x + region[ REGION_D ].x * region[ REGION_C ].y );
+
+    /* We take the solution which will always give a positive n */
+    n = (-b + sqrt( b*b - 4.0 * a * c ))/(2.0 * a);
+                
+    m = ( n * region[ REGION_B ].x + region[ REGION_C ].x)/
+        ( n * region[ REGION_A ].x + region[ REGION_D ].x);
+
+    /* Calculate weights from intermediate values */
+    region[ REGION_C ].weight = self->cellLocalVolume /
+        ( (double) region[ REGION_A ].particleCount * n * m
+          + (double) region[ REGION_B ].particleCount * n
+          + (double) region[ REGION_C ].particleCount  
+          + (double) region[ REGION_D ].particleCount * m );
+
+    region[ REGION_A ].weight = n * m * region[ REGION_C ].weight;
+    region[ REGION_B ].weight = n *     region[ REGION_C ].weight;
+    region[ REGION_D ].weight =     m * region[ REGION_C ].weight;
+
+    /* Assign weights to particles according to which region it is in */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+        xi       = particle->xi;
+
+        region_I = _MomentBalanceWeights_WhichRegion2D( xi );
+        particle->weight = region[ region_I ].weight;
+    }
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/VolumeWeights.c
--- a/Weights/src/VolumeWeights.c	Wed May 11 13:26:28 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) ) {
-IrregTopology* self = (IrregTopology*)ir
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**
-** This file may be distributed under the terms of the VPAC Public License
-** as defined by VPAC of Australia and appearing in the file
-** LICENSE.VPL included in the packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** $Id: VolumeWeights.c 189 2005-10-20 00:39:29Z RobertTurnbull $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "types.h"
-#include "WeightsCalculator.h"
-#include "VolumeWeights.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-
-/* Textual name of this class */
-const Type VolumeWeights_Type = "VolumeWeights";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-VolumeWeights* VolumeWeights_New( Name name, Dimension_Index dim, Stg_Shape* shape, FeMesh* mesh ) {
-  VolumeWeights *self = (VolumeWeights*)_VolumeWeights_DefaultNew( name );
-
-	self->isConstructed = True;
-	_WeightsCalculator_Init( self, dim );
-	_VolumeWeights_Init( self, shape, mesh );
-
-	return self;
-}
-
-VolumeWeights* _VolumeWeights_New(  VOLUMEWEIGHTS_DEFARGS  ) {
-    VolumeWeights* self;
-	
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(VolumeWeights) );
-    self = (VolumeWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  );
-	
-    /* General info */
-
-    /* Virtual Info */
-
-    return self;
-}
-
-void _VolumeWeights_Init( void* weights, Stg_Shape* shape, FeMesh* mesh ) {
-    VolumeWeights* self = (VolumeWeights*)weights;
-
-    self->shape = shape;
-    self->mesh  = mesh;
-
-}
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _VolumeWeights_Delete( void* weights ) {
-    VolumeWeights* self = (VolumeWeights*)weights;
-	
-    /* Delete parent */
-    _WeightsCalculator_Delete( self );
-}
-
-
-void _VolumeWeights_Print( void* weights, Stream* stream ) {
-    VolumeWeights* self = (VolumeWeights*)weights;
-	
-    /* Print parent */
-    _WeightsCalculator_Print( self, stream );
-}
-
-
-
-void* _VolumeWeights_Copy( const void* weights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    VolumeWeights*	self = (VolumeWeights*)weights;
-    VolumeWeights*	newVolumeWeights;
-	
-    newVolumeWeights = (VolumeWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
-	
-    return (void*)newVolumeWeights;
-}
-
-void* _VolumeWeights_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof(VolumeWeights);
-	Type                                                      type = VolumeWeights_Type;
-	Stg_Class_DeleteFunction*                              _delete = _VolumeWeights_Delete;
-	Stg_Class_PrintFunction*                                _print = _VolumeWeights_Print;
-	Stg_Class_CopyFunction*                                  _copy = _VolumeWeights_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _VolumeWeights_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _VolumeWeights_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _VolumeWeights_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _VolumeWeights_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _VolumeWeights_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _VolumeWeights_Destroy;
-	AllocationType                              nameAllocationType = NON_GLOBAL;
-	WeightsCalculator_CalculateFunction*                _calculate = _VolumeWeights_Calculate;
-
-    return (void*) _VolumeWeights_New(  VOLUMEWEIGHTS_PASSARGS  );
-}
-
-
-void _VolumeWeights_AssignFromXML( void* weights, Stg_ComponentFactory* cf, void* data ) {
-    VolumeWeights*	     self          = (VolumeWeights*) weights;
-    Stg_Shape*           shape;
-    FeMesh*  mesh;
-
-    _WeightsCalculator_AssignFromXML( self, cf, data );
-
-    shape = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, data  );
-    mesh  = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", FeMesh, True, data  );
-/*
-  Journal_Firewall(
-  Stg_Class_IsInstance( shape, Sphere_Type ),
-  Journal_MyStream( Error_Type, self ),
-  "In func %s, VolumeWeights is only designed for spheres right now.\n",
-  __func__ );
-*/	
-    _VolumeWeights_Init( self, shape, mesh );
-}
-
-void _VolumeWeights_Build( void* weights, void* data ) {
-    VolumeWeights*	self = (VolumeWeights*)weights;
-
-    Stg_Component_Build( self->shape, data, False );
-    Stg_Component_Build( self->mesh, data, False );
-    _WeightsCalculator_Build( self, data );
-}
-void _VolumeWeights_Initialise( void* weights, void* data ) {
-    VolumeWeights*	self = (VolumeWeights*)weights;
-
-    Stg_Component_Initialise( self->shape, data, False );
-    Stg_Component_Initialise( self->mesh, data, False );	
-    _WeightsCalculator_Initialise( self, data );
-}
-void _VolumeWeights_Execute( void* weights, void* data ) {
-    VolumeWeights*	self = (VolumeWeights*)weights;
-	
-    _WeightsCalculator_Execute( self, data );
-}
-void _VolumeWeights_Destroy( void* weights, void* data ) {
-    VolumeWeights*	self = (VolumeWeights*)weights;
-
-    Stg_Component_Destroy( self->shape, data, False );
-    Stg_Component_Destroy( self->mesh, data, False );	
-    _WeightsCalculator_Destroy( self, data );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-void _VolumeWeights_Calculate( void* weights, void* _swarm, Cell_LocalIndex lCell_I ) {
-    VolumeWeights*               self               = (VolumeWeights*)  weights;
-    Swarm*                       swarm              = (Swarm*) _swarm;
-    Sphere*                      shape              = (Sphere*)self->shape;
-    Index                        numberOfParticles;
-    double                       volume;
-    double                       dx;
-    double                       dy;
-    double                       dz;
-    double                       weight;
-    Grid*				vertGrid;
-	
-    MPI_Allreduce( 
-        &(swarm->particleLocalCount),
-        &(numberOfParticles),
-        1,
-        MPI_UNSIGNED,
-        MPI_SUM,
-        MPI_COMM_WORLD );
-
-    volume = Stg_Shape_CalculateVolume( shape );
-
-    /*
-    ** NOTE: Big assumption that the mesh is regular.
-    */
-    vertGrid = *(Grid**)ExtensionManager_Get( self->mesh->info, self->mesh, 
-                                              ExtensionManager_GetHandle( self->mesh->info, (Name)"vertexGrid" ) );
-	
-    dx = 1.0 / (double)(vertGrid->sizes[0] - 1); /* size of an element */
-    dy = 1.0 / (double)(vertGrid->sizes[1] - 1);
-    if ( self->dim > 2 ) {
-        dz = 1.0 / (double)(vertGrid->sizes[2] - 1);
-    }
-    else {
-        dz = 1.0;
-    }
-
-    /* (V / np) * 4 / ( dx * dy * dz ) */
-    /* Where 4 in the value of cellLocalVolume in 2D */
-    weight = (volume / (double)numberOfParticles) * ( self->cellLocalVolume / ( dx * dy * dz )  );
-
-    WeightsCalculator_SetWeightsValueAllInCell( self, swarm, lCell_I, weight );
-}
-
-/*-------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/VolumeWeights.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/VolumeWeights.cxx	Thu May 12 11:18:04 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) ) {
+IrregTopology* self = (IrregTopology*)ir
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+** This file may be distributed under the terms of the VPAC Public License
+** as defined by VPAC of Australia and appearing in the file
+** LICENSE.VPL included in the packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** $Id: VolumeWeights.c 189 2005-10-20 00:39:29Z RobertTurnbull $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "types.h"
+#include "WeightsCalculator.h"
+#include "VolumeWeights.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+
+/* Textual name of this class */
+const Type VolumeWeights_Type = "VolumeWeights";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+VolumeWeights* VolumeWeights_New( Name name, Dimension_Index dim, Stg_Shape* shape, FeMesh* mesh ) {
+  VolumeWeights *self = (VolumeWeights*)_VolumeWeights_DefaultNew( name );
+
+	self->isConstructed = True;
+	_WeightsCalculator_Init( self, dim );
+	_VolumeWeights_Init( self, shape, mesh );
+
+	return self;
+}
+
+VolumeWeights* _VolumeWeights_New(  VOLUMEWEIGHTS_DEFARGS  ) {
+    VolumeWeights* self;
+	
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(VolumeWeights) );
+    self = (VolumeWeights*)_WeightsCalculator_New(  WEIGHTSCALCULATOR_PASSARGS  );
+	
+    /* General info */
+
+    /* Virtual Info */
+
+    return self;
+}
+
+void _VolumeWeights_Init( void* weights, Stg_Shape* shape, FeMesh* mesh ) {
+    VolumeWeights* self = (VolumeWeights*)weights;
+
+    self->shape = shape;
+    self->mesh  = mesh;
+
+}
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _VolumeWeights_Delete( void* weights ) {
+    VolumeWeights* self = (VolumeWeights*)weights;
+	
+    /* Delete parent */
+    _WeightsCalculator_Delete( self );
+}
+
+
+void _VolumeWeights_Print( void* weights, Stream* stream ) {
+    VolumeWeights* self = (VolumeWeights*)weights;
+	
+    /* Print parent */
+    _WeightsCalculator_Print( self, stream );
+}
+
+
+
+void* _VolumeWeights_Copy( const void* weights, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    VolumeWeights*	self = (VolumeWeights*)weights;
+    VolumeWeights*	newVolumeWeights;
+	
+    newVolumeWeights = (VolumeWeights*)_WeightsCalculator_Copy( self, dest, deep, nameExt, ptrMap );
+	
+    return (void*)newVolumeWeights;
+}
+
+void* _VolumeWeights_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof(VolumeWeights);
+	Type                                                      type = VolumeWeights_Type;
+	Stg_Class_DeleteFunction*                              _delete = _VolumeWeights_Delete;
+	Stg_Class_PrintFunction*                                _print = _VolumeWeights_Print;
+	Stg_Class_CopyFunction*                                  _copy = _VolumeWeights_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _VolumeWeights_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _VolumeWeights_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _VolumeWeights_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _VolumeWeights_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _VolumeWeights_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _VolumeWeights_Destroy;
+	AllocationType                              nameAllocationType = NON_GLOBAL;
+	WeightsCalculator_CalculateFunction*                _calculate = _VolumeWeights_Calculate;
+
+    return (void*) _VolumeWeights_New(  VOLUMEWEIGHTS_PASSARGS  );
+}
+
+
+void _VolumeWeights_AssignFromXML( void* weights, Stg_ComponentFactory* cf, void* data ) {
+    VolumeWeights*	     self          = (VolumeWeights*) weights;
+    Stg_Shape*           shape;
+    FeMesh*  mesh;
+
+    _WeightsCalculator_AssignFromXML( self, cf, data );
+
+    shape = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Shape", Stg_Shape, True, data  );
+    mesh  = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Mesh", FeMesh, True, data  );
+/*
+  Journal_Firewall(
+  Stg_Class_IsInstance( shape, Sphere_Type ),
+  Journal_MyStream( Error_Type, self ),
+  "In func %s, VolumeWeights is only designed for spheres right now.\n",
+  __func__ );
+*/	
+    _VolumeWeights_Init( self, shape, mesh );
+}
+
+void _VolumeWeights_Build( void* weights, void* data ) {
+    VolumeWeights*	self = (VolumeWeights*)weights;
+
+    Stg_Component_Build( self->shape, data, False );
+    Stg_Component_Build( self->mesh, data, False );
+    _WeightsCalculator_Build( self, data );
+}
+void _VolumeWeights_Initialise( void* weights, void* data ) {
+    VolumeWeights*	self = (VolumeWeights*)weights;
+
+    Stg_Component_Initialise( self->shape, data, False );
+    Stg_Component_Initialise( self->mesh, data, False );	
+    _WeightsCalculator_Initialise( self, data );
+}
+void _VolumeWeights_Execute( void* weights, void* data ) {
+    VolumeWeights*	self = (VolumeWeights*)weights;
+	
+    _WeightsCalculator_Execute( self, data );
+}
+void _VolumeWeights_Destroy( void* weights, void* data ) {
+    VolumeWeights*	self = (VolumeWeights*)weights;
+
+    Stg_Component_Destroy( self->shape, data, False );
+    Stg_Component_Destroy( self->mesh, data, False );	
+    _WeightsCalculator_Destroy( self, data );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+void _VolumeWeights_Calculate( void* weights, void* _swarm, Cell_LocalIndex lCell_I ) {
+    VolumeWeights*               self               = (VolumeWeights*)  weights;
+    Swarm*                       swarm              = (Swarm*) _swarm;
+    Sphere*                      shape              = (Sphere*)self->shape;
+    Index                        numberOfParticles;
+    double                       volume;
+    double                       dx;
+    double                       dy;
+    double                       dz;
+    double                       weight;
+    Grid*				vertGrid;
+	
+    MPI_Allreduce( 
+        &(swarm->particleLocalCount),
+        &(numberOfParticles),
+        1,
+        MPI_UNSIGNED,
+        MPI_SUM,
+        MPI_COMM_WORLD );
+
+    volume = Stg_Shape_CalculateVolume( shape );
+
+    /*
+    ** NOTE: Big assumption that the mesh is regular.
+    */
+    vertGrid = *(Grid**)ExtensionManager_Get( self->mesh->info, self->mesh, 
+                                              ExtensionManager_GetHandle( self->mesh->info, (Name)"vertexGrid" ) );
+	
+    dx = 1.0 / (double)(vertGrid->sizes[0] - 1); /* size of an element */
+    dy = 1.0 / (double)(vertGrid->sizes[1] - 1);
+    if ( self->dim > 2 ) {
+        dz = 1.0 / (double)(vertGrid->sizes[2] - 1);
+    }
+    else {
+        dz = 1.0;
+    }
+
+    /* (V / np) * 4 / ( dx * dy * dz ) */
+    /* Where 4 in the value of cellLocalVolume in 2D */
+    weight = (volume / (double)numberOfParticles) * ( self->cellLocalVolume / ( dx * dy * dz )  );
+
+    WeightsCalculator_SetWeightsValueAllInCell( self, swarm, lCell_I, weight );
+}
+
+/*-------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/WeightsCalculator.c
--- a/Weights/src/WeightsCalculator.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,460 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**      Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**      Victoria, 3800, 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
-**
-** Contributors:
-**      Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**      Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**      David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**      Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**      Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**      David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**      Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: WeightsCalculator.c 531 2008-02-11 10:32:00Z DavidMay $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "types.h"
-#include "WeightsCalculator.h"
-
-#include <assert.h>
-#include <string.h>
-#include <math.h>
-
-/* Textual name of this class */
-const Type WeightsCalculator_Type = "WeightsCalculator";
-
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Constructors
-*/
-
-
-WeightsCalculator* _WeightsCalculator_New(  WEIGHTSCALCULATOR_DEFARGS  ) {
-    WeightsCalculator* self;
-
-    /* Allocate memory */
-    assert( _sizeOfSelf >= sizeof(WeightsCalculator) );
-    self = (WeightsCalculator*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
-
-    /* General info */
-
-    /* Virtual Info */
-    self->_calculate = _calculate;
-
-    return self;
-}
-
-void _WeightsCalculator_Init( void* weightsCalculator, int dim ) {
-    WeightsCalculator* self = (WeightsCalculator*)weightsCalculator;
-
-    self->dim = dim;
-    self->cellLocalVolume = pow( 2.0, (double) dim );
-}
-
-
-/*------------------------------------------------------------------------------------------------------------------------
-** Virtual functions
-*/
-
-void _WeightsCalculator_Delete( void* weightsCalculator ) {
-    WeightsCalculator* self = (WeightsCalculator*)weightsCalculator;
-        
-    /* Delete parent */
-    _Stg_Component_Delete( self );
-}
-
-
-void _WeightsCalculator_Print( void* weightsCalculator, Stream* stream ) {
-    WeightsCalculator* self = (WeightsCalculator*)weightsCalculator;
-        
-    /* Print parent */
-    _Stg_Component_Print( self, stream );
-}
-
-
-void* _WeightsCalculator_Copy( const void* weightsCalculator, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-    WeightsCalculator*  self = (WeightsCalculator*)weightsCalculator;
-    WeightsCalculator*  newWeightsCalculator;
-        
-    newWeightsCalculator = (WeightsCalculator*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
-        
-    return (void*)newWeightsCalculator;
-}
-
-
-
-void _WeightsCalculator_AssignFromXML( void* weightsCalculator, Stg_ComponentFactory* cf, void* data ) {
-    WeightsCalculator*   self          = (WeightsCalculator*) weightsCalculator;
-    Dimension_Index      dim;
-
-    self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", FiniteElementContext, False, data );
-    if( !self->context  ) 
-        self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, data  );
-
-    dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
-
-    _WeightsCalculator_Init( self, dim );
-}
-
-void _WeightsCalculator_Build( void* weightsCalculator, void* data ) {
-/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
-
-}
-
-void _WeightsCalculator_Destroy( void* weightsCalculator, void* data ) {
-/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
-}
-
-
-void _WeightsCalculator_Initialise( void* weightsCalculator, void* data ) {
-/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
-        
-}
-void _WeightsCalculator_Execute( void* weightsCalculator, void* data ) {
-/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
-        
-}
-
-/*--------------------------------------------------------------------------------------------------------------------------
-** Public Functions
-*/
-
-void WeightsCalculator_CalculateCell( void* weightsCalculator, void* swarm, Cell_LocalIndex lCell_I ) {
-    WeightsCalculator*  self = (WeightsCalculator*)weightsCalculator;
-
-    self->_calculate( self, swarm, lCell_I );
-}
-
-
-        
-/*----------------------------------------------------------------------------------------------------------------------------------
-** Private Functions
-*/
-
-
-void WeightsCalculator_CalculateAll( void* weightsCalculator, void* _swarm ) {
-    WeightsCalculator*   self           = (WeightsCalculator*)weightsCalculator;
-    Swarm*               swarm          = (Swarm*) _swarm;
-    Cell_LocalIndex          cellLocalCount = swarm->cellLocalCount;
-    Cell_LocalIndex          cellGlobalCount = 0;
-    Cell_LocalIndex          lCell_I;
-    unsigned int         numberOfCompletionPrintIncrements=10;
-    double               completionRatioIncrement= 1 / (double)numberOfCompletionPrintIncrements;
-    double               nextCompletionRatioToPrint=0;
-    Cell_Index           nextCompletedCellCountToPrint=0;
-    Cell_Index           nextPlusOneCompletedCellCountToPrint=0;
-    Stream*              stream = Journal_Register( Info_Type, (Name)self->type  );
-    Processor_Index      formerStreamPrintingRank = 0;
-
-    Journal_RPrintf( stream, "In func %s(): for swarm \"%s\"\n", __func__, swarm->name );
-    Stream_Indent( stream );
-    formerStreamPrintingRank = Stream_GetPrintingRank( stream );
-    Stream_SetPrintingRank( stream, 0 );
-    MPI_Reduce( &cellLocalCount, &cellGlobalCount, 1, MPI_UNSIGNED, MPI_SUM, 0, swarm->comm );
-    Journal_RPrintf( stream, "Calculating weights for the particles in the %u global cells\n",
-                     cellGlobalCount );
-    Stream_Indent( stream );
-
-    nextCompletionRatioToPrint = completionRatioIncrement;
-    nextCompletedCellCountToPrint = ceil(cellLocalCount * nextCompletionRatioToPrint - 0.001 );
-
-    /* Loop over all local cells */
-    for ( lCell_I = 0 ; lCell_I < cellLocalCount ; lCell_I++ ) {
-/*              WeightsCalculator_CheckEmptyCell( self, swarm, lCell_I );*/
-        WeightsCalculator_CalculateCell( self, swarm, lCell_I );
-/*               TODO: parallelise */
-
-        if ( (lCell_I+1) >= nextCompletedCellCountToPrint ) {
-            nextPlusOneCompletedCellCountToPrint = ceil(( cellLocalCount
-                                                          * (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
-
-            while ( (lCell_I+1) >= nextPlusOneCompletedCellCountToPrint )
-            {
-                nextCompletionRatioToPrint += completionRatioIncrement;
-                nextPlusOneCompletedCellCountToPrint = ceil(( cellLocalCount
-                                                              * (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
-                if ( nextCompletionRatioToPrint >= 1.0 ) {
-                    nextCompletionRatioToPrint = 1.0;
-                    break;
-                }
-            }
-            Journal_Printf( stream, "done %.0f%% (%u cells)...\n", 
-                            (nextCompletionRatioToPrint * 100),
-                            lCell_I+1 );
-            nextCompletionRatioToPrint += completionRatioIncrement;
-            nextCompletedCellCountToPrint = ceil(cellLocalCount * nextCompletionRatioToPrint - 0.001);
-        }
-    }
-    Stream_UnIndent( stream );
-    /* Need this barrier so the time is accurate */
-    MPI_Barrier( swarm->comm );
-    Stream_SetPrintingRank( stream, formerStreamPrintingRank );
-    Stream_UnIndent( stream );
-    Journal_RPrintf( stream, "%s(): finished update of weights for swarm \"%s\"\n"
-                     /*"\ttook %g secs\n"*/, __func__, swarm->name );
-}
-
-
-void WeightsCalculator_SetWeightsValueAll( void* weightsCalculator, void* _swarm, double weight ) {
-    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
-    Swarm*                       swarm             = (Swarm*) _swarm;
-    Cell_LocalIndex              lCell_I;
-
-    for ( lCell_I = 0 ; lCell_I < swarm->cellLocalCount ; lCell_I++ )
-        WeightsCalculator_SetWeightsValueAllInCell( self, swarm, lCell_I, weight );
-}
-
-void WeightsCalculator_SetWeightsValueAllInCell( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, double weight ) {
-    Swarm*                       swarm             = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount    = swarm->cellParticleCountTbl[lCell_I];
-    Particle_InCellIndex         cParticle_I;
-    IntegrationPoint*            particle;
-        
-    /* Loop over particles in this cell */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-
-        particle->weight = weight;
-    }
-}
-
-#define TOLERENCE 0.0001
-#define MAX_ORDER 100
-
-Constraint_Index WeightsCalculator_FindConstraintOrder( void* weightsCalculator, void* _swarm, Dimension_Index dim, Stream* stream ) {
-    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
-    Swarm*                       swarm             = (Swarm*) _swarm;
-    Constraint_Index             order             =  0;
-    double                       error;
-
-    while ( (error = WeightsCalculator_TestConstraint( self, swarm, dim, order )) < TOLERENCE ) {
-        order++;
-        if (order > MAX_ORDER) {
-            Journal_Printf( stream, "Reached maximum number of constraints to calculate.\n");
-            break;
-        }
-    }
-
-    /* If test fails then decrement to last order that the test passed */
-    order--;
-
-    if (order == (Constraint_Index) -1)
-        Journal_Printf( stream, "Weights '%s' for swarm '%s' satisfy no weight constraints.\n", 
-                        self->name, swarm->name );
-    else 
-        Journal_Printf( stream, "Weights '%s' for swarm '%s' satisfy weight constraints to order %u.\n", 
-                        self->name, swarm->name, order );
-        
-    return order;
-}
-
-double WeightsCalculator_TestConstraint( void* weightsCalculator, void* _swarm, Dimension_Index dim, Constraint_Index order ) {
-    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
-    Swarm*                       swarm             = (Swarm*) _swarm;
-    Cell_LocalIndex                  lCell_I;
-    double                       error            = 0.0;
-
-    /* Loop over all local cells */
-    for ( lCell_I = 0 ; lCell_I < swarm->cellLocalCount ; lCell_I++ ) 
-        error += WeightsCalculator_TestConstraintOverCell( self, swarm, lCell_I, dim, order );
-
-    Journal_DPrintfL( swarm->debug, 2, "In func %s: Error for weights for constraints of order %u is %0.3g\n", __func__, order, error );
-    return error;
-}
-
-#define IS_ODD(A)  ((A) % 2 == 1)
-
-double WeightsCalculator_TestConstraintOverCell( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, Dimension_Index dim, Constraint_Index order ) {
-    Swarm*                       swarm             = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticle_I;
-    IntegrationPoint*            particle;
-    double                       volume            = pow(2.0, (double) dim);
-    Index                        power_i, power_j;
-    double                       rightHandSide;
-    double                       leftHandSide;
-    double                       error             = 0.0;
-    double*                      xi;
-    Constraint_Index             constraintCount   = 0;
-        
-    Journal_DPrintfL( swarm->debug, 2, 
-                      "In func %s: For Cell %u and Dimension %u and order %u\n", __func__, lCell_I, dim, order );
-    Stream_Indent( swarm->debug );
-
-    for ( power_j = 0 ; power_j <= order ; power_j++ ) {
-        for ( power_i = power_j ; power_i <= order ; power_i++ ) {
-            /* Sum number of constrainst calculated */
-            constraintCount++;
-
-            /************ Calculate Right Hand Side of Constraint **************************/
-            if ( IS_ODD( power_i ) || IS_ODD( power_j ) || IS_ODD( order - power_i - power_j ) )
-                rightHandSide = 0.0;
-            else 
-                rightHandSide = volume/
-                    (double)(( power_i + 1 )*( power_j + 1 )*( order - power_i - power_j + 1));
-                        
-            Journal_DPrintfL( swarm->debug, 3, 
-                              "Constraint %u: \\Sigma w_p \\xi^%u \\eta^%u \\Zeta^%u = %0.3g\n", 
-                              constraintCount, power_i, order - power_i - power_j, power_j , rightHandSide );
-            /************ Calculate Left Hand Side of Constraint **************************/
-            leftHandSide = 0.0;
-                        
-            /* Loop over particles in this cell */
-            Stream_Indent( swarm->debug );
-            for ( cParticle_I = 0 ; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
-                particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-                                
-                /* Get local Coordinates of particle */
-                xi = particle->xi;
-                        
-                leftHandSide += particle->weight * 
-                    pow( xi[ I_AXIS ], (double) power_i ) *
-                    pow( xi[ J_AXIS ], (double) (order - power_i - power_j) ) *
-                    pow( xi[ K_AXIS ], (double) power_j ) ;
-                Journal_DPrintfL( swarm->debug, 3, 
-                                  "ParticleInCell %u, weight = %0.3g, local element coords = (%0.3g, %0.3g, %0.3g)\n", 
-                                  cParticle_I, particle->weight, 
-                                  xi[ I_AXIS ], xi[ J_AXIS ], xi[ K_AXIS ],
-                                  power_i, (order - power_i - power_j), power_j );
-            }
-            Stream_UnIndent( swarm->debug );
-
-            /* Calculate Error */
-            error += fabs(leftHandSide - rightHandSide);
-
-            Journal_DPrintfL( swarm->debug, 3, "RHS = %2.5f LHS = %2.5f: Total Error = %f\n", rightHandSide, leftHandSide, error );
-
-        }
-        /* 3D Constrain Equations collapse to 2D constraint equation only if j = 0 */
-        if (dim == 2) 
-            break;
-    }
-    Stream_UnIndent( swarm->debug );
-
-    Journal_Firewall( dim == 2 ? constraintCount == order + 1 : constraintCount*2 == (order + 1)*(order + 2) , 
-                      Journal_Register( Error_Type, (Name)swarm->type  ),
-                      "In func %s: Number of constraints %u incorrect for dimension %u which should be %u\n", 
-                      __func__ , dim == 2 ? order + 1 : (order + 1)*(order + 2)/2 );
-
-    return error;
-}
-
-double WeightsCalculator_GetConstraintLHS( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, Index power_i, Index power_j, Index power_k ) {
-    Swarm*                       swarm           = (Swarm*)             _swarm;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    Particle_InCellIndex         cParticle_I;
-    IntegrationPoint*            particle;
-    double                       leftHandSide    = 0.0;
-    double*                      xi;
-        
-    /* Loop over particles in this cell */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-                
-        /* Get local Coordinates of particle */
-        xi = particle->xi;
-        
-        leftHandSide += particle->weight * 
-            pow( xi[ I_AXIS ], (double) power_i ) *
-            pow( xi[ J_AXIS ], (double) power_j ) ;
-
-        if ( swarm->dim == 3 )
-            leftHandSide += particle->weight * pow( xi[ K_AXIS ], (double) power_k );
-
-    }
-    return leftHandSide;
-}
-
-double WeightsCalculator_GetLocalCoordSum( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, Index power_i, Index power_j, Index power_k ) 
-{
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    Particle_InCellIndex         cParticle_I;
-    IntegrationPoint*            particle;
-    double                       localCoordSum   = 0.0;
-    double*                      xi;
-        
-    /* Loop over particles in this cell */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-                
-        /* Get local Coordinates of particle */
-        xi = particle->xi;
-        
-        localCoordSum += 
-            pow( xi[ I_AXIS ], (double) power_i ) *
-            pow( xi[ J_AXIS ], (double) power_j ) ;
-
-        if ( swarm->dim == 3 )
-            localCoordSum += pow( xi[ K_AXIS ], (double) power_k );
-
-    }
-    return localCoordSum;
-}
-
-
-double WeightsCalculator_SumCellWeights( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I ) {
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    double                       weightsTotal    = 0.0;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
-    Particle_InCellIndex         cParticle_I;
-    IntegrationPoint*            particle;
-
-    /* Find Sum of the Weights */
-    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
-        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
-                
-        /* Put weight onto particle */
-        weightsTotal += particle->weight;
-    }
-
-    return weightsTotal;
-}
-
-void WeightsCalculator_CheckEmptyCell( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I ) {
-    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
-    Swarm*                       swarm           = (Swarm*) _swarm;
-    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];        
-
-    if ( cParticleCount == 0 ) {
-        Journal_Firewall( cParticleCount, Journal_Register( Error_Type, (Name)self->type  ),
-                          "Error in func '%s' for %s '%s' and %s '%s' - Cell %u has no particles.\n"
-                          "You must either add more initial particles or add population control.\n",
-                          __func__, self->type, self->name, swarm->type, swarm->name, lCell_I );
-    }
-}
-                        
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/src/WeightsCalculator.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/src/WeightsCalculator.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,460 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**      Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**      Victoria, 3800, 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
+**
+** Contributors:
+**      Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**      Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**      Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**      Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**      David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**      Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**      Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**      Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**      David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**      Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: WeightsCalculator.c 531 2008-02-11 10:32:00Z DavidMay $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "types.h"
+#include "WeightsCalculator.h"
+
+#include <assert.h>
+#include <string.h>
+#include <math.h>
+
+/* Textual name of this class */
+const Type WeightsCalculator_Type = "WeightsCalculator";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+
+WeightsCalculator* _WeightsCalculator_New(  WEIGHTSCALCULATOR_DEFARGS  ) {
+    WeightsCalculator* self;
+
+    /* Allocate memory */
+    assert( _sizeOfSelf >= sizeof(WeightsCalculator) );
+    self = (WeightsCalculator*)_Stg_Component_New(  STG_COMPONENT_PASSARGS  );
+
+    /* General info */
+
+    /* Virtual Info */
+    self->_calculate = _calculate;
+
+    return self;
+}
+
+void _WeightsCalculator_Init( void* weightsCalculator, int dim ) {
+    WeightsCalculator* self = (WeightsCalculator*)weightsCalculator;
+
+    self->dim = dim;
+    self->cellLocalVolume = pow( 2.0, (double) dim );
+}
+
+
+/*------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _WeightsCalculator_Delete( void* weightsCalculator ) {
+    WeightsCalculator* self = (WeightsCalculator*)weightsCalculator;
+        
+    /* Delete parent */
+    _Stg_Component_Delete( self );
+}
+
+
+void _WeightsCalculator_Print( void* weightsCalculator, Stream* stream ) {
+    WeightsCalculator* self = (WeightsCalculator*)weightsCalculator;
+        
+    /* Print parent */
+    _Stg_Component_Print( self, stream );
+}
+
+
+void* _WeightsCalculator_Copy( const void* weightsCalculator, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+    WeightsCalculator*  self = (WeightsCalculator*)weightsCalculator;
+    WeightsCalculator*  newWeightsCalculator;
+        
+    newWeightsCalculator = (WeightsCalculator*)_Stg_Component_Copy( self, dest, deep, nameExt, ptrMap );
+        
+    return (void*)newWeightsCalculator;
+}
+
+
+
+void _WeightsCalculator_AssignFromXML( void* weightsCalculator, Stg_ComponentFactory* cf, void* data ) {
+    WeightsCalculator*   self          = (WeightsCalculator*) weightsCalculator;
+    Dimension_Index      dim;
+
+    self->context = Stg_ComponentFactory_ConstructByKey( cf, self->name, (Dictionary_Entry_Key)"Context", FiniteElementContext, False, data );
+    if( !self->context  ) 
+        self->context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", FiniteElementContext, True, data  );
+
+    dim = Stg_ComponentFactory_GetRootDictUnsignedInt( cf, (Dictionary_Entry_Key)"dim", 0  );
+
+    _WeightsCalculator_Init( self, dim );
+}
+
+void _WeightsCalculator_Build( void* weightsCalculator, void* data ) {
+/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
+
+}
+
+void _WeightsCalculator_Destroy( void* weightsCalculator, void* data ) {
+/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
+}
+
+
+void _WeightsCalculator_Initialise( void* weightsCalculator, void* data ) {
+/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
+        
+}
+void _WeightsCalculator_Execute( void* weightsCalculator, void* data ) {
+/*      WeightsCalculator*      self = (WeightsCalculator*)weightsCalculator; */
+        
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void WeightsCalculator_CalculateCell( void* weightsCalculator, void* swarm, Cell_LocalIndex lCell_I ) {
+    WeightsCalculator*  self = (WeightsCalculator*)weightsCalculator;
+
+    self->_calculate( self, swarm, lCell_I );
+}
+
+
+        
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/
+
+
+void WeightsCalculator_CalculateAll( void* weightsCalculator, void* _swarm ) {
+    WeightsCalculator*   self           = (WeightsCalculator*)weightsCalculator;
+    Swarm*               swarm          = (Swarm*) _swarm;
+    Cell_LocalIndex          cellLocalCount = swarm->cellLocalCount;
+    Cell_LocalIndex          cellGlobalCount = 0;
+    Cell_LocalIndex          lCell_I;
+    unsigned int         numberOfCompletionPrintIncrements=10;
+    double               completionRatioIncrement= 1 / (double)numberOfCompletionPrintIncrements;
+    double               nextCompletionRatioToPrint=0;
+    Cell_Index           nextCompletedCellCountToPrint=0;
+    Cell_Index           nextPlusOneCompletedCellCountToPrint=0;
+    Stream*              stream = Journal_Register( Info_Type, (Name)self->type  );
+    Processor_Index      formerStreamPrintingRank = 0;
+
+    Journal_RPrintf( stream, "In func %s(): for swarm \"%s\"\n", __func__, swarm->name );
+    Stream_Indent( stream );
+    formerStreamPrintingRank = Stream_GetPrintingRank( stream );
+    Stream_SetPrintingRank( stream, 0 );
+    MPI_Reduce( &cellLocalCount, &cellGlobalCount, 1, MPI_UNSIGNED, MPI_SUM, 0, swarm->comm );
+    Journal_RPrintf( stream, "Calculating weights for the particles in the %u global cells\n",
+                     cellGlobalCount );
+    Stream_Indent( stream );
+
+    nextCompletionRatioToPrint = completionRatioIncrement;
+    nextCompletedCellCountToPrint = ceil(cellLocalCount * nextCompletionRatioToPrint - 0.001 );
+
+    /* Loop over all local cells */
+    for ( lCell_I = 0 ; lCell_I < cellLocalCount ; lCell_I++ ) {
+/*              WeightsCalculator_CheckEmptyCell( self, swarm, lCell_I );*/
+        WeightsCalculator_CalculateCell( self, swarm, lCell_I );
+/*               TODO: parallelise */
+
+        if ( (lCell_I+1) >= nextCompletedCellCountToPrint ) {
+            nextPlusOneCompletedCellCountToPrint = ceil(( cellLocalCount
+                                                          * (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
+
+            while ( (lCell_I+1) >= nextPlusOneCompletedCellCountToPrint )
+            {
+                nextCompletionRatioToPrint += completionRatioIncrement;
+                nextPlusOneCompletedCellCountToPrint = ceil(( cellLocalCount
+                                                              * (nextCompletionRatioToPrint + completionRatioIncrement )) - 0.001 );
+                if ( nextCompletionRatioToPrint >= 1.0 ) {
+                    nextCompletionRatioToPrint = 1.0;
+                    break;
+                }
+            }
+            Journal_Printf( stream, "done %.0f%% (%u cells)...\n", 
+                            (nextCompletionRatioToPrint * 100),
+                            lCell_I+1 );
+            nextCompletionRatioToPrint += completionRatioIncrement;
+            nextCompletedCellCountToPrint = ceil(cellLocalCount * nextCompletionRatioToPrint - 0.001);
+        }
+    }
+    Stream_UnIndent( stream );
+    /* Need this barrier so the time is accurate */
+    MPI_Barrier( swarm->comm );
+    Stream_SetPrintingRank( stream, formerStreamPrintingRank );
+    Stream_UnIndent( stream );
+    Journal_RPrintf( stream, "%s(): finished update of weights for swarm \"%s\"\n"
+                     /*"\ttook %g secs\n"*/, __func__, swarm->name );
+}
+
+
+void WeightsCalculator_SetWeightsValueAll( void* weightsCalculator, void* _swarm, double weight ) {
+    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
+    Swarm*                       swarm             = (Swarm*) _swarm;
+    Cell_LocalIndex              lCell_I;
+
+    for ( lCell_I = 0 ; lCell_I < swarm->cellLocalCount ; lCell_I++ )
+        WeightsCalculator_SetWeightsValueAllInCell( self, swarm, lCell_I, weight );
+}
+
+void WeightsCalculator_SetWeightsValueAllInCell( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, double weight ) {
+    Swarm*                       swarm             = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount    = swarm->cellParticleCountTbl[lCell_I];
+    Particle_InCellIndex         cParticle_I;
+    IntegrationPoint*            particle;
+        
+    /* Loop over particles in this cell */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+
+        particle->weight = weight;
+    }
+}
+
+#define TOLERENCE 0.0001
+#define MAX_ORDER 100
+
+Constraint_Index WeightsCalculator_FindConstraintOrder( void* weightsCalculator, void* _swarm, Dimension_Index dim, Stream* stream ) {
+    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
+    Swarm*                       swarm             = (Swarm*) _swarm;
+    Constraint_Index             order             =  0;
+    double                       error;
+
+    while ( (error = WeightsCalculator_TestConstraint( self, swarm, dim, order )) < TOLERENCE ) {
+        order++;
+        if (order > MAX_ORDER) {
+            Journal_Printf( stream, "Reached maximum number of constraints to calculate.\n");
+            break;
+        }
+    }
+
+    /* If test fails then decrement to last order that the test passed */
+    order--;
+
+    if (order == (Constraint_Index) -1)
+        Journal_Printf( stream, "Weights '%s' for swarm '%s' satisfy no weight constraints.\n", 
+                        self->name, swarm->name );
+    else 
+        Journal_Printf( stream, "Weights '%s' for swarm '%s' satisfy weight constraints to order %u.\n", 
+                        self->name, swarm->name, order );
+        
+    return order;
+}
+
+double WeightsCalculator_TestConstraint( void* weightsCalculator, void* _swarm, Dimension_Index dim, Constraint_Index order ) {
+    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
+    Swarm*                       swarm             = (Swarm*) _swarm;
+    Cell_LocalIndex                  lCell_I;
+    double                       error            = 0.0;
+
+    /* Loop over all local cells */
+    for ( lCell_I = 0 ; lCell_I < swarm->cellLocalCount ; lCell_I++ ) 
+        error += WeightsCalculator_TestConstraintOverCell( self, swarm, lCell_I, dim, order );
+
+    Journal_DPrintfL( swarm->debug, 2, "In func %s: Error for weights for constraints of order %u is %0.3g\n", __func__, order, error );
+    return error;
+}
+
+#define IS_ODD(A)  ((A) % 2 == 1)
+
+double WeightsCalculator_TestConstraintOverCell( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, Dimension_Index dim, Constraint_Index order ) {
+    Swarm*                       swarm             = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticle_I;
+    IntegrationPoint*            particle;
+    double                       volume            = pow(2.0, (double) dim);
+    Index                        power_i, power_j;
+    double                       rightHandSide;
+    double                       leftHandSide;
+    double                       error             = 0.0;
+    double*                      xi;
+    Constraint_Index             constraintCount   = 0;
+        
+    Journal_DPrintfL( swarm->debug, 2, 
+                      "In func %s: For Cell %u and Dimension %u and order %u\n", __func__, lCell_I, dim, order );
+    Stream_Indent( swarm->debug );
+
+    for ( power_j = 0 ; power_j <= order ; power_j++ ) {
+        for ( power_i = power_j ; power_i <= order ; power_i++ ) {
+            /* Sum number of constrainst calculated */
+            constraintCount++;
+
+            /************ Calculate Right Hand Side of Constraint **************************/
+            if ( IS_ODD( power_i ) || IS_ODD( power_j ) || IS_ODD( order - power_i - power_j ) )
+                rightHandSide = 0.0;
+            else 
+                rightHandSide = volume/
+                    (double)(( power_i + 1 )*( power_j + 1 )*( order - power_i - power_j + 1));
+                        
+            Journal_DPrintfL( swarm->debug, 3, 
+                              "Constraint %u: \\Sigma w_p \\xi^%u \\eta^%u \\Zeta^%u = %0.3g\n", 
+                              constraintCount, power_i, order - power_i - power_j, power_j , rightHandSide );
+            /************ Calculate Left Hand Side of Constraint **************************/
+            leftHandSide = 0.0;
+                        
+            /* Loop over particles in this cell */
+            Stream_Indent( swarm->debug );
+            for ( cParticle_I = 0 ; cParticle_I < swarm->cellParticleCountTbl[lCell_I]; cParticle_I++ ) {
+                particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+                                
+                /* Get local Coordinates of particle */
+                xi = particle->xi;
+                        
+                leftHandSide += particle->weight * 
+                    pow( xi[ I_AXIS ], (double) power_i ) *
+                    pow( xi[ J_AXIS ], (double) (order - power_i - power_j) ) *
+                    pow( xi[ K_AXIS ], (double) power_j ) ;
+                Journal_DPrintfL( swarm->debug, 3, 
+                                  "ParticleInCell %u, weight = %0.3g, local element coords = (%0.3g, %0.3g, %0.3g)\n", 
+                                  cParticle_I, particle->weight, 
+                                  xi[ I_AXIS ], xi[ J_AXIS ], xi[ K_AXIS ],
+                                  power_i, (order - power_i - power_j), power_j );
+            }
+            Stream_UnIndent( swarm->debug );
+
+            /* Calculate Error */
+            error += fabs(leftHandSide - rightHandSide);
+
+            Journal_DPrintfL( swarm->debug, 3, "RHS = %2.5f LHS = %2.5f: Total Error = %f\n", rightHandSide, leftHandSide, error );
+
+        }
+        /* 3D Constrain Equations collapse to 2D constraint equation only if j = 0 */
+        if (dim == 2) 
+            break;
+    }
+    Stream_UnIndent( swarm->debug );
+
+    Journal_Firewall( dim == 2 ? constraintCount == order + 1 : constraintCount*2 == (order + 1)*(order + 2) , 
+                      Journal_Register( Error_Type, (Name)swarm->type  ),
+                      "In func %s: Number of constraints %u incorrect for dimension %u which should be %u\n", 
+                      __func__ , dim == 2 ? order + 1 : (order + 1)*(order + 2)/2 );
+
+    return error;
+}
+
+double WeightsCalculator_GetConstraintLHS( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, Index power_i, Index power_j, Index power_k ) {
+    Swarm*                       swarm           = (Swarm*)             _swarm;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    Particle_InCellIndex         cParticle_I;
+    IntegrationPoint*            particle;
+    double                       leftHandSide    = 0.0;
+    double*                      xi;
+        
+    /* Loop over particles in this cell */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+                
+        /* Get local Coordinates of particle */
+        xi = particle->xi;
+        
+        leftHandSide += particle->weight * 
+            pow( xi[ I_AXIS ], (double) power_i ) *
+            pow( xi[ J_AXIS ], (double) power_j ) ;
+
+        if ( swarm->dim == 3 )
+            leftHandSide += particle->weight * pow( xi[ K_AXIS ], (double) power_k );
+
+    }
+    return leftHandSide;
+}
+
+double WeightsCalculator_GetLocalCoordSum( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I, Index power_i, Index power_j, Index power_k ) 
+{
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    Particle_InCellIndex         cParticle_I;
+    IntegrationPoint*            particle;
+    double                       localCoordSum   = 0.0;
+    double*                      xi;
+        
+    /* Loop over particles in this cell */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+                
+        /* Get local Coordinates of particle */
+        xi = particle->xi;
+        
+        localCoordSum += 
+            pow( xi[ I_AXIS ], (double) power_i ) *
+            pow( xi[ J_AXIS ], (double) power_j ) ;
+
+        if ( swarm->dim == 3 )
+            localCoordSum += pow( xi[ K_AXIS ], (double) power_k );
+
+    }
+    return localCoordSum;
+}
+
+
+double WeightsCalculator_SumCellWeights( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I ) {
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    double                       weightsTotal    = 0.0;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];
+    Particle_InCellIndex         cParticle_I;
+    IntegrationPoint*            particle;
+
+    /* Find Sum of the Weights */
+    for ( cParticle_I = 0 ; cParticle_I < cParticleCount ; cParticle_I++ ) {
+        particle = (IntegrationPoint*) Swarm_ParticleInCellAt( swarm, lCell_I, cParticle_I );
+                
+        /* Put weight onto particle */
+        weightsTotal += particle->weight;
+    }
+
+    return weightsTotal;
+}
+
+void WeightsCalculator_CheckEmptyCell( void* weightsCalculator, void* _swarm, Cell_LocalIndex lCell_I ) {
+    WeightsCalculator*           self              = (WeightsCalculator*) weightsCalculator;
+    Swarm*                       swarm           = (Swarm*) _swarm;
+    Particle_InCellIndex         cParticleCount  = swarm->cellParticleCountTbl[lCell_I];        
+
+    if ( cParticleCount == 0 ) {
+        Journal_Firewall( cParticleCount, Journal_Register( Error_Type, (Name)self->type  ),
+                          "Error in func '%s' for %s '%s' and %s '%s' - Cell %u has no particles.\n"
+                          "You must either add more initial particles or add population control.\n",
+                          __func__, self->type, self->name, swarm->type, swarm->name, lCell_I );
+    }
+}
+                        
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/ConstantWeightsSuite.c
--- a/Weights/tests/ConstantWeightsSuite.c	Wed May 11 13:26:28 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
-**
-** Role:
-**   Tests the ConstantWeightsSuite
-**
-** $Id: testWeights.c 3462 2006-02-19 06:53:24Z WalterLandry $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include "ConstantWeightsSuite.h"
-
-typedef struct {
-   PICelleratorContext* context;
-   Stg_ComponentFactory* cf;
-} ConstantWeightsSuiteData;
-
-void constantFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   *value = -3.0;
-}
-void linearFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-   double y = xi[1];
-
-   *value = 2.0 + 2.2 * x - y;
-}
-void shapeFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-   double y = xi[1];
-
-   *value = 1 + x + y + x * y;
-}
-void polynomialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-   double y = xi[1];
-
-   *value = 11 + 2*x*x + 3*x*x*x*y + y + x*x*x + 2*y*y;
-}
-void quadraticFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-
-   *value = 1 + x + x * x;
-}
-void exponentialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-   double y = xi[1];
-
-   *value = 5*exp(2*x*x*x + 2*y*y*y) * (1-x) * (1+y);
-}
-void exponentialInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-   double y = xi[1];
-
-   *value = (double) (y <= 0.1 * exp( 2*x ));
-}
-void circleInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
-   double x = xi[0];
-   double y = xi[1];
-
-   *value = (double) (x*x + y*y <= 1.0);
-}
-
-void WeightsSuite_TestElementIntegral(
- 	PICelleratorContext*	context,
- 	Name 						funcName,
- 	Index						count,   // was SampleSize - defaults to 5000
- 	double					meanTolerance,
-  	double					stdDevTolerance,
-  	double					expectedMean,
-  	double					expectedStdDev ) 
-{
-   Swarm*              integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
-   Swarm*              materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
-   FeMesh*             mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
-   WeightsCalculator*  weights          = (WeightsCalculator* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"weights"  );
-   FeVariable*         feVariable;
-   Element_LocalIndex  lElement_I       = 0;
-   double              analyticValue    = 0.0;
-   double              integral         = 0.0;
-   double              error;
-   double              errorSquaredSum  = 0.0;
-   double              errorSum         = 0.0;
-   double              mean;
-   double              standardDeviation;
-   Index               loop_I;
-   void*               data=NULL;
-   double              differenceMean, differenceStdDev;   
-
-   /* Create FeVariable */
-   feVariable = FeVariable_New_Full(
-		"feVariable", 
-		(DomainContext*) context,
-		mesh,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL,
-		NULL, 
-     	1,
-		context->dim,
-		False,
-		False,
-		False,
-		MPI_COMM_WORLD,
-		context->fieldVariable_Register );
-
-   Journal_Firewall( (funcName!=NULL), Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
-      "Error, function name input to %s is NULL", __func__ );
-
-   if ( strcasecmp( funcName, "ShapeFunction" ) == 0 ) {
-      feVariable->_interpolateWithinElement = shapeFunction;
-      analyticValue = 4.0;
-   }
-   else if ( strcasecmp( funcName, "ConstantFunction" ) == 0 ) {
-      feVariable->_interpolateWithinElement = constantFunction;
-      analyticValue = -12.0;
-   }
-   else if ( strcasecmp( funcName, "LinearFunction" ) == 0 ) {
-      feVariable->_interpolateWithinElement = linearFunction;
-      analyticValue = 8.0;
-   }
-   else if ( strcasecmp( funcName, "QuadraticFunction" ) == 0 ) {
-      feVariable->_interpolateWithinElement = quadraticFunction;
-      analyticValue = 16.0/3.0;
-   }
-   else if ( strcasecmp( funcName, "PolynomialFunction" ) == 0 ) {
-      feVariable->_interpolateWithinElement = polynomialFunction;
-      analyticValue = 148.0/3.0;
-   }
-   else if ( strcasecmp( funcName, "ExponentialFunction" ) == 0 ) {
-      feVariable->_interpolateWithinElement = exponentialFunction;
-      analyticValue = 0.0 /*TODO*/;
-      abort();
-   }
-   else if ( strcasecmp( funcName, "ExponentialInterface" ) == 0 ) {
-      feVariable->_interpolateWithinElement = exponentialInterface;
-      analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;
-   }
-   else if ( strcasecmp( funcName, "CircleInterface" ) == 0 ) {
-      feVariable->_interpolateWithinElement = circleInterface;
-      analyticValue = M_PI;
-   }
-   else 
-      Journal_Firewall( False,
-            Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
-            "Cannot understand function name '%s'\n", funcName );
-
-   for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
-      Swarm_Random_Seed( (long) loop_I );
-      /* Layout Particles */
-      _Swarm_InitialiseParticles( materialSwarm, data );
-
-      _IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
-      
-      WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
-
-      /* Evaluate Integral */
-      integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
-
-      /* Calculate Error */
-      error = fabs( integral - analyticValue )/fabs( analyticValue );
-      errorSum += error;
-      errorSquaredSum += error*error;
-   }
-
-   /* Calculate Mean and Standard Deviation */
-   mean = errorSum / (double) count;
-   standardDeviation = sqrt( errorSquaredSum / (double) count - mean * mean );
-
-   //printf( "Func: %s - Mean = %g; SD = %g\n", funcName, mean, standardDeviation );
-
-   /* compare the mean and standard deviation */
-   differenceMean = fabs(mean - expectedMean);
-   differenceStdDev = fabs(standardDeviation - expectedStdDev);
-   pcu_check_le( differenceMean, meanTolerance );
-   pcu_check_le( differenceStdDev, stdDevTolerance );
-}
-void ConstantWeightsSuite_Setup( ConstantWeightsSuiteData* data ) {
-   char	xmlInputFilename[PCU_PATH_MAX];
-
-   pcu_filename_input( "testConstantWeights.xml", xmlInputFilename );
-   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
-   data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context"  );
-	// Stg_ComponentFactory_BuildComponents( data->cf, NULL );
-   
-   stgMainBuildAndInitialise( data->cf );
-}
-
-void ConstantWeightsSuite_Teardown( ConstantWeightsSuiteData* data ) {
-	stgMainDestroy( data->cf );
-}
-
-void ConstantWeightsSuite_TestConstantFunction( ConstantWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "ConstantFunction", 1000,
-      1e-10, /* --mean-tolerance */
-      1e-10, /* --standardDeviation-tolerance */
-      2.96059e-16, /* --mean-expectedValue */
-      4.98509e-23 /* --standardDeviation-expectedValue */ );
-}
-void ConstantWeightsSuite_TestLinearFunction ( ConstantWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "LinearFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.119677, /* --mean-expectedValue */
-      0.0921005 /* --standardDeviation-expectedValue */ );
-}
-
-void ConstantWeightsSuite_TestQuadraticFunction ( ConstantWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "QuadraticFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0840621, /* --mean-expectedValue */
-      0.0627759 /* --standardDeviation-expectedValue */ );
-}
-
-void ConstantWeightsSuite_TestPolynomialFunction ( ConstantWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "PolynomialFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0174753, /* --mean-expectedValue */
-      0.0137385 /* --standardDeviation-expectedValue */ );
-}
-
-void ConstantWeightsSuite_TestCircleInterface( ConstantWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "CircleInterface", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.091215, /* --mean-expectedValue */
-      0.066458 /* --standardDeviation-expectedValue */ );
-}
-   
-void ConstantWeightsSuite_TestExponentialInterface( ConstantWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "ExponentialInterface", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.155483, /* --mean-expectedValue */
-      0.116796 /* --standardDeviation-expectedValue */ );
-}
-   
-void ConstantWeightsSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, ConstantWeightsSuiteData );
-   pcu_suite_setFixtures( suite, ConstantWeightsSuite_Setup, ConstantWeightsSuite_Teardown );
-   pcu_suite_addTest( suite, ConstantWeightsSuite_TestConstantFunction );
-   pcu_suite_addTest( suite, ConstantWeightsSuite_TestLinearFunction );
-   pcu_suite_addTest( suite, ConstantWeightsSuite_TestQuadraticFunction );
-   pcu_suite_addTest( suite, ConstantWeightsSuite_TestPolynomialFunction );
-   pcu_suite_addTest( suite, ConstantWeightsSuite_TestExponentialInterface );
-   pcu_suite_addTest( suite, ConstantWeightsSuite_TestCircleInterface );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/ConstantWeightsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/tests/ConstantWeightsSuite.cxx	Thu May 12 11:18:04 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
+**
+** Role:
+**   Tests the ConstantWeightsSuite
+**
+** $Id: testWeights.c 3462 2006-02-19 06:53:24Z WalterLandry $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include "ConstantWeightsSuite.h"
+
+typedef struct {
+   PICelleratorContext* context;
+   Stg_ComponentFactory* cf;
+} ConstantWeightsSuiteData;
+
+void constantFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   *value = -3.0;
+}
+void linearFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+   double y = xi[1];
+
+   *value = 2.0 + 2.2 * x - y;
+}
+void shapeFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+   double y = xi[1];
+
+   *value = 1 + x + y + x * y;
+}
+void polynomialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+   double y = xi[1];
+
+   *value = 11 + 2*x*x + 3*x*x*x*y + y + x*x*x + 2*y*y;
+}
+void quadraticFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+
+   *value = 1 + x + x * x;
+}
+void exponentialFunction( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+   double y = xi[1];
+
+   *value = 5*exp(2*x*x*x + 2*y*y*y) * (1-x) * (1+y);
+}
+void exponentialInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+   double y = xi[1];
+
+   *value = (double) (y <= 0.1 * exp( 2*x ));
+}
+void circleInterface( void* feVariable, Element_DomainIndex dElement_I, Coord xi, double* value ) {
+   double x = xi[0];
+   double y = xi[1];
+
+   *value = (double) (x*x + y*y <= 1.0);
+}
+
+void WeightsSuite_TestElementIntegral(
+ 	PICelleratorContext*	context,
+ 	Name 						funcName,
+ 	Index						count,   // was SampleSize - defaults to 5000
+ 	double					meanTolerance,
+  	double					stdDevTolerance,
+  	double					expectedMean,
+  	double					expectedStdDev ) 
+{
+   Swarm*              integrationSwarm = (Swarm*)LiveComponentRegister_Get( context->CF->LCRegister, (Name)"integrationSwarm" );
+   Swarm*              materialSwarm    = (Swarm* )LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialPoints" );
+   FeMesh*             mesh             = (FeMesh* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"linearMesh" );
+   WeightsCalculator*  weights          = (WeightsCalculator* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"weights"  );
+   FeVariable*         feVariable;
+   Element_LocalIndex  lElement_I       = 0;
+   double              analyticValue    = 0.0;
+   double              integral         = 0.0;
+   double              error;
+   double              errorSquaredSum  = 0.0;
+   double              errorSum         = 0.0;
+   double              mean;
+   double              standardDeviation;
+   Index               loop_I;
+   void*               data=NULL;
+   double              differenceMean, differenceStdDev;   
+
+   /* Create FeVariable */
+   feVariable = FeVariable_New_Full(
+		"feVariable", 
+		(DomainContext*) context,
+		mesh,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL,
+		NULL, 
+     	1,
+		context->dim,
+		False,
+		False,
+		False,
+		MPI_COMM_WORLD,
+		context->fieldVariable_Register );
+
+   Journal_Firewall( (funcName!=NULL), Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
+      "Error, function name input to %s is NULL", __func__ );
+
+   if ( strcasecmp( funcName, "ShapeFunction" ) == 0 ) {
+      feVariable->_interpolateWithinElement = shapeFunction;
+      analyticValue = 4.0;
+   }
+   else if ( strcasecmp( funcName, "ConstantFunction" ) == 0 ) {
+      feVariable->_interpolateWithinElement = constantFunction;
+      analyticValue = -12.0;
+   }
+   else if ( strcasecmp( funcName, "LinearFunction" ) == 0 ) {
+      feVariable->_interpolateWithinElement = linearFunction;
+      analyticValue = 8.0;
+   }
+   else if ( strcasecmp( funcName, "QuadraticFunction" ) == 0 ) {
+      feVariable->_interpolateWithinElement = quadraticFunction;
+      analyticValue = 16.0/3.0;
+   }
+   else if ( strcasecmp( funcName, "PolynomialFunction" ) == 0 ) {
+      feVariable->_interpolateWithinElement = polynomialFunction;
+      analyticValue = 148.0/3.0;
+   }
+   else if ( strcasecmp( funcName, "ExponentialFunction" ) == 0 ) {
+      feVariable->_interpolateWithinElement = exponentialFunction;
+      analyticValue = 0.0 /*TODO*/;
+      abort();
+   }
+   else if ( strcasecmp( funcName, "ExponentialInterface" ) == 0 ) {
+      feVariable->_interpolateWithinElement = exponentialInterface;
+      analyticValue = 0.05 * (exp(2) - exp(-2)) + 2.0;
+   }
+   else if ( strcasecmp( funcName, "CircleInterface" ) == 0 ) {
+      feVariable->_interpolateWithinElement = circleInterface;
+      analyticValue = M_PI;
+   }
+   else 
+      Journal_Firewall( False,
+            Journal_Register( Error_Type, (Name)"ConstantWeightsSuite"  ),
+            "Cannot understand function name '%s'\n", funcName );
+
+   for ( loop_I = 0 ; loop_I < count ; loop_I++ ) {
+      Swarm_Random_Seed( (long) loop_I );
+      /* Layout Particles */
+      _Swarm_InitialiseParticles( materialSwarm, data );
+
+      _IntegrationPointsSwarm_UpdateHook( NULL, integrationSwarm );
+      
+      WeightsCalculator_CalculateCell( weights, integrationSwarm, lElement_I );
+
+      /* Evaluate Integral */
+      integral = FeVariable_IntegrateElement( feVariable, integrationSwarm, lElement_I );
+
+      /* Calculate Error */
+      error = fabs( integral - analyticValue )/fabs( analyticValue );
+      errorSum += error;
+      errorSquaredSum += error*error;
+   }
+
+   /* Calculate Mean and Standard Deviation */
+   mean = errorSum / (double) count;
+   standardDeviation = sqrt( errorSquaredSum / (double) count - mean * mean );
+
+   //printf( "Func: %s - Mean = %g; SD = %g\n", funcName, mean, standardDeviation );
+
+   /* compare the mean and standard deviation */
+   differenceMean = fabs(mean - expectedMean);
+   differenceStdDev = fabs(standardDeviation - expectedStdDev);
+   pcu_check_le( differenceMean, meanTolerance );
+   pcu_check_le( differenceStdDev, stdDevTolerance );
+}
+void ConstantWeightsSuite_Setup( ConstantWeightsSuiteData* data ) {
+   char	xmlInputFilename[PCU_PATH_MAX];
+
+   pcu_filename_input( "testConstantWeights.xml", xmlInputFilename );
+   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
+   data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context"  );
+	// Stg_ComponentFactory_BuildComponents( data->cf, NULL );
+   
+   stgMainBuildAndInitialise( data->cf );
+}
+
+void ConstantWeightsSuite_Teardown( ConstantWeightsSuiteData* data ) {
+	stgMainDestroy( data->cf );
+}
+
+void ConstantWeightsSuite_TestConstantFunction( ConstantWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "ConstantFunction", 1000,
+      1e-10, /* --mean-tolerance */
+      1e-10, /* --standardDeviation-tolerance */
+      2.96059e-16, /* --mean-expectedValue */
+      4.98509e-23 /* --standardDeviation-expectedValue */ );
+}
+void ConstantWeightsSuite_TestLinearFunction ( ConstantWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "LinearFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.119677, /* --mean-expectedValue */
+      0.0921005 /* --standardDeviation-expectedValue */ );
+}
+
+void ConstantWeightsSuite_TestQuadraticFunction ( ConstantWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "QuadraticFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0840621, /* --mean-expectedValue */
+      0.0627759 /* --standardDeviation-expectedValue */ );
+}
+
+void ConstantWeightsSuite_TestPolynomialFunction ( ConstantWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "PolynomialFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0174753, /* --mean-expectedValue */
+      0.0137385 /* --standardDeviation-expectedValue */ );
+}
+
+void ConstantWeightsSuite_TestCircleInterface( ConstantWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "CircleInterface", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.091215, /* --mean-expectedValue */
+      0.066458 /* --standardDeviation-expectedValue */ );
+}
+   
+void ConstantWeightsSuite_TestExponentialInterface( ConstantWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "ExponentialInterface", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.155483, /* --mean-expectedValue */
+      0.116796 /* --standardDeviation-expectedValue */ );
+}
+   
+void ConstantWeightsSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, ConstantWeightsSuiteData );
+   pcu_suite_setFixtures( suite, ConstantWeightsSuite_Setup, ConstantWeightsSuite_Teardown );
+   pcu_suite_addTest( suite, ConstantWeightsSuite_TestConstantFunction );
+   pcu_suite_addTest( suite, ConstantWeightsSuite_TestLinearFunction );
+   pcu_suite_addTest( suite, ConstantWeightsSuite_TestQuadraticFunction );
+   pcu_suite_addTest( suite, ConstantWeightsSuite_TestPolynomialFunction );
+   pcu_suite_addTest( suite, ConstantWeightsSuite_TestExponentialInterface );
+   pcu_suite_addTest( suite, ConstantWeightsSuite_TestCircleInterface );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/DVCWeightsSuite.c
--- a/Weights/tests/DVCWeightsSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,546 +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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include "PICellerator/PopulationControl/PopulationControl.h"
-#include "PICellerator/Weights/Weights.h"
-
-
-/* the ranges of the local coordinates of a FEM cell.*/
-const double BBXMIN = -1.0; 
-const double BBXMAX = 1.0;
-const double BBYMIN = -1.0;
-const double BBYMAX = 1.0;
-const double BBZMIN = -1.0;
-const double BBZMAX = 1.0;
-
-typedef struct {
-   struct cell*         cells;   /* the 3D connected grid */ 
-   struct particle*     pList;   /* 3D particle List */
-   struct chain*        bchain;  /*3D boundary chain */
-
-   struct cell2d*       cells2D; /* the 2D connected grid */
-   struct particle2d*   pList2D; /*2D particle List */
-   struct chain*        bchain2D;/*2D boundary chain */
-   unsigned int         numx,numy,numz;
-   unsigned int         nump,nump2D;
-   unsigned int         px, py, pz;
-   double               dx,dy,dz;
-   double               da,da2D;
-} DVCWeightsSuiteData;
-
-
-void DVCWeightsSuite_Setup( DVCWeightsSuiteData* data ) {
-   data->cells = NULL;
-   data->pList = NULL;
-   data->bchain = NULL;
-   data->cells2D = NULL;
-   data->pList2D = NULL;
-   data->bchain2D = NULL;
-
-   /*Define the resolution */
-   data->numx = 10;/* the data are hard-coded at this time, so don't change this from 10 */
-   data->numy = 10;/* the data are hard-coded at this time, so don't change this from 10 */
-   data->numz = 10;/* the data are hard-coded at this time, so don't change this from 10 */
-
-   /*Define the number of particles */
-   data->px = 2;
-   data->py = 2; 
-   data->pz = 2;
-   //data->nump = data->px * data->py * data->pz;
-   data->nump = 10; /* the data are hard-coded at this time, so don't change this from 10 */
-   //data->nump2D = data->px * data->py;
-   data->nump2D = 10; /* the data are hard-coded at this time, so don't change this from 10 */
-
-   data->dx = (BBXMAX - BBXMIN)/data->numx;
-   data->dy = (BBYMAX - BBYMIN)/data->numy;
-   data->dz = (BBZMAX - BBZMIN)/data->numz;
-   data->da = data->dx*data->dy*data->dz;
-   data->da2D = data->dx*data->dy;
-}
-
-
-void DVCWeightsSuite_Teardown( DVCWeightsSuiteData* data ) {
-   if(data->bchain) { free(data->bchain); }
-   if(data->pList) { free(data->pList); }
-   if(data->cells) { free(data->cells); }
-
-   if(data->bchain2D) { free(data->bchain2D); }
-   if(data->pList2D) { free(data->pList2D); }
-   if(data->cells2D) { free(data->cells2D); }
-}
-
-
-/* Do the testing of the 3D functions*/
-void DVCWeightsSuite_TestConstructGrid( DVCWeightsSuiteData* data ) {
-   FILE *fp;
-   unsigned int   ii=0;
-   Name    gridFilename = "DVCWeightsSuite_testConstructGrid.txt";
-   char           expectedGridFilename[PCU_PATH_MAX];
-   //int passed=0;
-   char line[100];
-   float x,y,z,dx,dy,dz;
-   int N,S,E,W,U,D;
-   float tol=1e-6;
-   /* We'll use an expected file for this test, as visual checking of the correct parameters is probably
-    *  most logical way to maintain it */
-
-   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);		
-   pcu_filename_expected( gridFilename, expectedGridFilename );/* get the expected filename to open */
-   fp=fopen(expectedGridFilename,"r");
-   if(!fp){
-     pcu_check_true(0);
-     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestConstructGrid" ),"expected test File %s Not Found in function %s\n" ,expectedGridFilename, __func__);
-   }
-   else{
-     /* Print out the grid */
-     for (ii = 0; ii < (data->numx * data->numy * data->numz); ii++ ) {
-       pcu_check_true( data->cells[ii].p == -1 );   /* Particle index: shouldn't be set up yet */
-       pcu_check_true( data->cells[ii].done == 0 );
-       fgets(line,100,fp);  fgets(line,100,fp);
-       sscanf(line,"\t\tValues: (N: %d, S: %d, E: %d, W: %d, U: %d, D: %d)\n",&N,&S,&E,&W,&U,&D);
-       pcu_check_true( data->cells[ii].N == N );
-       pcu_check_true( data->cells[ii].S == S );
-       pcu_check_true( data->cells[ii].E == E );
-       pcu_check_true( data->cells[ii].W == W );
-       pcu_check_true( data->cells[ii].U == U );
-       pcu_check_true( data->cells[ii].D == D );
-       fgets(line,100,fp);
-       sscanf(line,"\t\tCoords: ( %f, %f, %f)\n",&x,&y,&z);
-       dx = (data->cells[ii].x - x)*(data->cells[ii].x - x); 
-       dy = (data->cells[ii].y - y)*(data->cells[ii].y - y); 
-       dz = (data->cells[ii].z - z)*(data->cells[ii].z - z); 
-       pcu_check_true( dx < tol );
-       pcu_check_true( dy < tol );
-       pcu_check_true( dz < tol );
-     }
-   }
-   fclose(fp);
-}
-
-
-void DVCWeightsSuite_TestInitialiseStructs( DVCWeightsSuiteData* data ) {
-   unsigned int   ii;   
-
-   
-   _DVCWeights_InitialiseStructs( &data->bchain, &data->pList, data->nump);
-   for (ii = 0; ii < data->nump; ii++) {
-      pcu_check_true( data->bchain[ii].new_claimed_cells_malloced == DVC_INC );
-      pcu_check_true( data->bchain[ii].new_bound_cells_malloced == DVC_INC );
-   }
-}
-   
-
-void DVCWeightsSuite_TestResetGrid( DVCWeightsSuiteData* data ) {
-   unsigned int   i;
-   
-   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);		
-   _DVCWeights_ResetGrid(&data->cells, data->numz*data->numy*data->numx);
-
-   for ( i = 0; i < data->numz*data->numy*data->numx; i++) {
-      pcu_check_true( data->cells[i].p == -1 );
-      pcu_check_true( data->cells[i].done == 0 );
-   }
-}
-
-
-void _DVCWeightsSuite_InitialiseParticleCoords( DVCWeightsSuiteData* data ) {
-   Index            i;
-
-   /*Initialise particle coords */
-
-   i=0;
-   data->pList[i].x = -0.64320939127356 ; i++;
-   data->pList[i].x = -0.57575625646859 ; i++;
-   data->pList[i].x = -0.44866901542991 ; i++;
-   data->pList[i].x = -0.45453263074160 ; i++;
-   data->pList[i].x = -0.56068608816713 ; i++;
-   data->pList[i].x = -0.31215981673449 ; i++;
-   data->pList[i].x = -0.94066464062780 ; i++;
-   data->pList[i].x = +0.05528775136918 ; i++;
-   data->pList[i].x = -0.62383012939245 ; i++;
-   data->pList[i].x = +0.43985756300390 ; i++;
-   
-   i=0;
-   data->pList[i].y = -0.20064506959170 ; i++;
-   data->pList[i].y = -0.87612858321518 ; i++;
-   data->pList[i].y = -0.90448551066220 ; i++;
-   data->pList[i].y = -0.26452634204179 ; i++;
-   data->pList[i].y = -0.59652493428439 ; i++;
-   data->pList[i].y = +0.29530759342015 ; i++;
-   data->pList[i].y = +0.75698726624250 ; i++;
-   data->pList[i].y = +0.01171378418803 ; i++;
-   data->pList[i].y = -0.76168798375875 ; i++;
-   data->pList[i].y = +0.27507007215172 ; i++;  
-
-   i=0;
-   data->pList[i].z = -0.66680242400616; i++;
-   data->pList[i].z = -0.89170031249523; i++;
-   data->pList[i].z = -0.35793361812830; i++;
-   data->pList[i].z = -0.55526655819267; i++;
-   data->pList[i].z = -0.91176854260266; i++;
-   data->pList[i].z = -0.70107179880142; i++;
-   data->pList[i].z = +0.31083723250777; i++;
-   data->pList[i].z = +0.83138376288116; i++;
-   data->pList[i].z = -0.88380649406463; i++;
-   data->pList[i].z = +0.76169187109917; i++;  
-
-   for ( i = 0; i < data->nump; i++) {	    
-      //Journal_Printf( stream, "data->pList[%d]:", i);
-      //Journal_Printf( stream, "\t\t coords: (x, y, z) = (%f, %f, %f)\n",
-      //   data->pList[i].x, data->pList[i].y, data->pList[i].z);
-
-   }
-}
-
-
-void DVCWeightsSuite_TestCreateVoronoi( DVCWeightsSuiteData* data ) {
-   Index            i;
-
-   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);		
-   _DVCWeights_InitialiseStructs( &data->bchain, &data->pList, data->nump);
-
-   _DVCWeightsSuite_InitialiseParticleCoords( data );
-   _DVCWeights_CreateVoronoi( &data->bchain, &data->pList, &data->cells, data->dx, data->dy, data->dz,
-      data->nump, data->numx, data->numy, data->numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-   
-   /* data->bchain changes */
-   for (i = 0; i < data->nump; i++) {
-      //pcu_check_true( data->bchain[i].index == (data->nump-1) ); //This value doesn't matter at the moment: also nump-1 is the wrong number anyway
-      pcu_check_true( data->bchain[i].sizeofboundary == 0 );
-      pcu_check_true( data->bchain[i].numclaimed == 0 );
-      pcu_check_true( data->bchain[i].totalclaimed == 1 );
-      pcu_check_true( data->bchain[i].new_bound_cells_malloced == DVC_INC );
-      pcu_check_true( data->bchain[i].new_claimed_cells_malloced == DVC_INC );
-      pcu_check_true( data->bchain[i].done == 0 );
-   }
-   /* particle values */
-   for (i = 0; i < data->nump; i++) {
-      pcu_check_true( (data->pList[i].cx == 0) && (data->pList[i].cy == 0) && (data->pList[i].cz == 0));
-      pcu_check_true( data->pList[i].w == 0 );
-   }
-}
-
-
-void DVCWeightsSuite_TestGetCentroids( DVCWeightsSuiteData* data ) {
-   FILE *fp;
-   unsigned int   i;
-   Name    centroidsFilename = "DVCWeightsSuite_testGetCentroids.txt";
-   char           expectedCentroidsFilename[PCU_PATH_MAX];
-   char line[100];
-   float x,y,z,dx,dy,dz;
-   float tol=1e-6;
-   /* We'll use an expected file for this test, as visual checking of the correct parameters is probably
-    *  most logical way to maintain it */
-   
-   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);
-   _DVCWeights_InitialiseStructs( &data->bchain, &data->pList, data->nump);
-   _DVCWeightsSuite_InitialiseParticleCoords( data );
-   _DVCWeights_CreateVoronoi( &data->bchain, &data->pList, &data->cells, data->dx, data->dy, data->dz,
-      data->nump, data->numx, data->numy, data->numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
-
-   _DVCWeights_GetCentroids( data->cells, data->pList,data->numz,data->numy,data->numx,data->nump,data->da);
-
-   pcu_filename_expected(centroidsFilename, expectedCentroidsFilename);/* get the expected filename to open */
-   fp=fopen(expectedCentroidsFilename,"r");
-   if(!fp){
-     pcu_check_true(0);
-     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestGetCentroids" ),"expected test File %s Not Found in function %s\n" ,expectedCentroidsFilename, __func__);
-   }
-   else{
-     for (i = 0; i < data->nump; i++) {
-       fgets(line,100,fp);
-    
-       fgets(line,100,fp);
-       sscanf(line,"\t\tcoords: (x, y, z) = ( %f, %f, %f)\n",&x,&y,&z);
-       dx = (data->pList[i].x -x)*(data->pList[i].x -x);
-       dy = (data->pList[i].y -y)*(data->pList[i].y -y);
-       dz = (data->pList[i].z -z)*(data->pList[i].z -z);
-       pcu_check_true( dx < tol );
-       pcu_check_true( dy < tol );
-       pcu_check_true( dz < tol );
-
-       fgets(line,100,fp);
-       sscanf(line,"\t\tcentroids: (cx, cy, cz) = ( %f, %f, %f)\n",&x,&y,&z);
-       dx = (data->pList[i].cx -x)*(data->pList[i].cx -x);
-       dy = (data->pList[i].cy -y)*(data->pList[i].cy -y);
-       dz = (data->pList[i].cz -z)*(data->pList[i].cz -z);
-       pcu_check_true( dx < tol );
-       pcu_check_true( dy < tol );
-       pcu_check_true( dz < tol );
-       
-       fgets(line,100,fp);
-       sscanf(line,"\t\tweight = %f\n",&x);
-       dx = (data->pList[i].w -x)*(data->pList[i].w -x);
-       pcu_check_true( dx < tol );
-     }
-   }
-   fclose(fp);
-}
-
-
-void DVCWeightsSuite_TestDistanceSquared( DVCWeightsSuiteData* data ) {
-   double particleDistance;		
-   double particle0[3], particle1[3];
-
-   particle0[0] = 0.5;	particle0[1] = 0.5;	particle0[2] = 0.5;
-   particle1[0] = 0.25; particle1[1] = 0.25; 	particle1[2] = 0; 		
-
-   particleDistance = _DVCWeights_DistanceSquared(
-      particle0[0], particle0[1], particle0[2],
-      particle1[0], particle1[1], particle1[2]);
-
-   pcu_check_true( particleDistance == 0.375 );
-}
-
-
-/* 2D Functions */
-
-void DVCWeightsSuite_TestConstructGrid2D( DVCWeightsSuiteData* data ) {
-   FILE *fp;
-   unsigned int   ii=0;
-   Name    gridFilename = "DVCWeightsSuite_testConstructGrid2D.txt";
-   char           expectedGridFilename[PCU_PATH_MAX];
-   char line[100];
-   float x,y,dx,dy;
-   int N,S,E,W;
-   float tol=1e-6;
-
-   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);		
-
-   pcu_filename_expected( gridFilename, expectedGridFilename );/* get the expected filename to open */
-   fp=fopen(expectedGridFilename,"r");
-   if(!fp){
-     pcu_check_true(0);
-     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestConstructGrid2D" ),"expected test File %s Not Found in function %s\n" ,expectedGridFilename, __func__);
-   }
-   else{
-     /* Print out the grid */
-     for (ii = 0; ii < (data->numx * data->numy); ii++ ) {
-       pcu_check_true( data->cells2D[ii].p == -1 );   /* Particle index: shouldn't be set up yet */
-       pcu_check_true( data->cells2D[ii].done == 0 );
-       fgets(line,100,fp);  fgets(line,100,fp);
-       sscanf(line,"\t\tValues: (N: %d, S: %d, E: %d, W: %d)\n",&N,&S,&E,&W);
-       pcu_check_true( data->cells2D[ii].N == N );
-       pcu_check_true( data->cells2D[ii].S == S );
-       pcu_check_true( data->cells2D[ii].E == E );
-       pcu_check_true( data->cells2D[ii].W == W );
-       fgets(line,100,fp);
-       sscanf(line,"\t\tCoords: ( %f, %f)\n",&x,&y);
-       dx = (data->cells2D[ii].x - x)*(data->cells2D[ii].x - x); 
-       dy = (data->cells2D[ii].y - y)*(data->cells2D[ii].y - y); 
-       pcu_check_true( dx < tol );
-       pcu_check_true( dy < tol );
-     }
-   }
-   fclose(fp);
-}
-
-void DVCWeightsSuite_TestInitialiseStructs2D( DVCWeightsSuiteData* data ) {
-   unsigned int   ii;   
-
-   _DVCWeights_InitialiseStructs2D( &data->bchain2D, &data->pList2D, data->nump2D);
-   for (ii = 0; ii < data->nump2D; ii++) {
-      pcu_check_true( data->bchain2D[ii].new_claimed_cells_malloced == DVC_INC );
-      pcu_check_true( data->bchain2D[ii].new_bound_cells_malloced == DVC_INC );
-   }
-}
-
-   
-void DVCWeightsSuite_TestResetGrid2D( DVCWeightsSuiteData* data ) {
-   unsigned int   i;
-   
-   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);
-   _DVCWeights_ResetGrid2D(&data->cells2D,data->numx*data->numy);
-
-   for ( i = 0; i < data->numx*data->numy; i++) {
-      pcu_check_true( data->cells2D[i].p == -1 );
-      pcu_check_true( data->cells2D[i].done == 0 );
-   }
-}
-
-void _DVCWeightsSuite_InitialiseParticleCoords2D( DVCWeightsSuiteData* data ) {
-   Index i;
-
-   /*Initialise particle coords */
-   i=0;
-   data->pList2D[i].x = -0.55376385338604 ; i++;
-   data->pList2D[i].x = -0.10488151479512 ; i++;
-   data->pList2D[i].x = +0.13873003050685 ; i++;
-   data->pList2D[i].x = -0.05016296077520 ; i++;
-   data->pList2D[i].x = +0.90808211639524 ; i++;
-   data->pList2D[i].x = -0.69216587487608 ; i++;
-   data->pList2D[i].x = -0.62051867879927 ; i++;
-   data->pList2D[i].x = +0.24515981227160 ; i++;
-   data->pList2D[i].x = -0.83195694349706 ; i++;
-   data->pList2D[i].x = +0.92260552570224 ; i++;
-   
-   i=0;
-   data->pList2D[i].y = -0.56640755850822 ; i++;
-   data->pList2D[i].y = -0.01476682443172 ; i++;
-   data->pList2D[i].y = -0.05242515634745 ; i++;
-   data->pList2D[i].y = -0.93268149159849 ; i++;
-   data->pList2D[i].y = +0.91700463462621 ; i++;
-   data->pList2D[i].y = -0.47783328499645 ; i++;
-   data->pList2D[i].y = -0.27844923641533 ; i++;
-   data->pList2D[i].y = -0.66626300383359 ; i++;
-   data->pList2D[i].y = +0.17968866135925 ; i++;
-   data->pList2D[i].y = -0.58136314433068 ; i++;
-   
-
-   for ( i = 0; i < data->nump2D; i++) {	    
-      //Journal_Printf( stream, "data->pList2D[%d]:", i);
-      //Journal_Printf( stream, "\t\t coords: (x, y) = (%f, %f)\n",
-      //   data->pList2D[i].x, data->pList2D[i].y);
-
-   }
-}
-
-
-void DVCWeightsSuite_TestCreateVoronoi2D( DVCWeightsSuiteData* data ) {
-   Index i;
-
-   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);
-   _DVCWeights_InitialiseStructs2D( &data->bchain2D, &data->pList2D, data->nump2D);
-
-   _DVCWeightsSuite_InitialiseParticleCoords2D( data );
-   _DVCWeights_CreateVoronoi2D( &data->bchain2D, &data->pList2D, &data->cells2D, data->dx, data->dy,
-      data->nump2D, data->numx, data->numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
-   
-   /* data->bchain2D changes */
-   for (i = 0; i < data->nump2D; i++) {
-      //pcu_check_true( data->bchain2D[i].index == (data->nump2D-1) );//This value doesn't matter at the moment: also nump2D-1 is the wrong number anyway
-      pcu_check_true( data->bchain2D[i].sizeofboundary == 0 );
-      pcu_check_true( data->bchain2D[i].numclaimed == 0 );
-      pcu_check_true( data->bchain2D[i].totalclaimed == 1 );
-      pcu_check_true( data->bchain2D[i].new_bound_cells_malloced == DVC_INC );
-      pcu_check_true( data->bchain2D[i].new_claimed_cells_malloced == DVC_INC );
-      pcu_check_true( data->bchain2D[i].done == 0 );
-   }
-   /* particle values */
-   for (i = 0; i < data->nump2D; i++) {
-      pcu_check_true( (data->pList2D[i].cx == 0) && (data->pList2D[i].cy == 0) );
-      pcu_check_true( data->pList2D[i].w == 0 );
-   }
-}
-
-
-void DVCWeightsSuite_TestGetCentroids2D( DVCWeightsSuiteData* data ) {
-   FILE *fp;
-   unsigned int   i;
-   Name    centroidsFilename = "DVCWeightsSuite_testGetCentroids2D.txt";
-   char           expectedCentroidsFilename[PCU_PATH_MAX];
-   char line[100];
-   float x,y,dx,dy;
-   float tol=1e-6;
-
-   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);
-   _DVCWeights_InitialiseStructs2D( &data->bchain2D, &data->pList2D, data->nump2D);   
-   _DVCWeightsSuite_InitialiseParticleCoords2D( data );
-   _DVCWeights_CreateVoronoi2D( &data->bchain2D, &data->pList2D, &data->cells2D, data->dx, data->dy,
-      data->nump2D, data->numx, data->numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
-
-   _DVCWeights_GetCentroids2D( data->cells2D, data->pList2D,data->numy,data->numx,data->nump2D,data->da2D);
-
-   pcu_filename_expected( centroidsFilename, expectedCentroidsFilename );
-    fp=fopen(expectedCentroidsFilename,"r");
-   if(!fp){
-     pcu_check_true(0);
-     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestGetCentroids2D" ),"expected test File %s Not Found in function %s\n" ,expectedCentroidsFilename, __func__);
-   }
-   else{
-
-     for (i = 0; i < data->nump2D; i++) {
-       fgets(line,100,fp);
-    
-       fgets(line,100,fp);
-       sscanf(line,"\t\tcoords: (x, y) = ( %f, %f)\n",&x,&y);
-       dx = (data->pList2D[i].x -x)*(data->pList2D[i].x -x);
-       dy = (data->pList2D[i].y -y)*(data->pList2D[i].y -y);
-       pcu_check_true( dx < tol );
-       pcu_check_true( dy < tol );
-
-       fgets(line,100,fp);
-       sscanf(line,"\t\tcentroids: (cx, cy) = ( %f, %f)\n",&x,&y);
-       dx = (data->pList2D[i].cx -x)*(data->pList2D[i].cx -x);
-       dy = (data->pList2D[i].cy -y)*(data->pList2D[i].cy -y);
-       pcu_check_true( dx < tol );
-       pcu_check_true( dy < tol );
-       
-       fgets(line,100,fp);
-       sscanf(line,"\t\tweight = %f\n",&x);
-       dx = (data->pList2D[i].w -x)*(data->pList2D[i].w -x);
-       pcu_check_true( dx < tol );
-     }
-   }
-   fclose(fp);
-}
-
-
-void DVCWeightsSuite_TestDistanceSquared2D( DVCWeightsSuiteData* data ) {
-   double particleDistance;		
-   double particle0[2], particle1[2];
-   
-   particle0[0] = 0.5;	particle0[1] = 0.5;
-   particle1[0] = 0.25; particle1[1] = 0.25;
-
-   particleDistance = _DVCWeights_DistanceSquared2D(
-      particle0[0], particle0[1],
-      particle1[0], particle1[1] );
-   
-   pcu_check_true( particleDistance == 0.125 );
-}
-
-
-void DVCWeightsSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, DVCWeightsSuiteData );
-   pcu_suite_setFixtures( suite, DVCWeightsSuite_Setup, DVCWeightsSuite_Teardown );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestConstructGrid );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestResetGrid );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestInitialiseStructs );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestCreateVoronoi );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestGetCentroids );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestDistanceSquared );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestConstructGrid2D );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestInitialiseStructs2D );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestResetGrid2D );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestCreateVoronoi2D );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestGetCentroids2D );
-   pcu_suite_addTest( suite, DVCWeightsSuite_TestDistanceSquared2D );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/DVCWeightsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/tests/DVCWeightsSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,546 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include "PICellerator/PopulationControl/PopulationControl.h"
+#include "PICellerator/Weights/Weights.h"
+
+
+/* the ranges of the local coordinates of a FEM cell.*/
+const double BBXMIN = -1.0; 
+const double BBXMAX = 1.0;
+const double BBYMIN = -1.0;
+const double BBYMAX = 1.0;
+const double BBZMIN = -1.0;
+const double BBZMAX = 1.0;
+
+typedef struct {
+   struct cell*         cells;   /* the 3D connected grid */ 
+   struct particle*     pList;   /* 3D particle List */
+   struct chain*        bchain;  /*3D boundary chain */
+
+   struct cell2d*       cells2D; /* the 2D connected grid */
+   struct particle2d*   pList2D; /*2D particle List */
+   struct chain*        bchain2D;/*2D boundary chain */
+   unsigned int         numx,numy,numz;
+   unsigned int         nump,nump2D;
+   unsigned int         px, py, pz;
+   double               dx,dy,dz;
+   double               da,da2D;
+} DVCWeightsSuiteData;
+
+
+void DVCWeightsSuite_Setup( DVCWeightsSuiteData* data ) {
+   data->cells = NULL;
+   data->pList = NULL;
+   data->bchain = NULL;
+   data->cells2D = NULL;
+   data->pList2D = NULL;
+   data->bchain2D = NULL;
+
+   /*Define the resolution */
+   data->numx = 10;/* the data are hard-coded at this time, so don't change this from 10 */
+   data->numy = 10;/* the data are hard-coded at this time, so don't change this from 10 */
+   data->numz = 10;/* the data are hard-coded at this time, so don't change this from 10 */
+
+   /*Define the number of particles */
+   data->px = 2;
+   data->py = 2; 
+   data->pz = 2;
+   //data->nump = data->px * data->py * data->pz;
+   data->nump = 10; /* the data are hard-coded at this time, so don't change this from 10 */
+   //data->nump2D = data->px * data->py;
+   data->nump2D = 10; /* the data are hard-coded at this time, so don't change this from 10 */
+
+   data->dx = (BBXMAX - BBXMIN)/data->numx;
+   data->dy = (BBYMAX - BBYMIN)/data->numy;
+   data->dz = (BBZMAX - BBZMIN)/data->numz;
+   data->da = data->dx*data->dy*data->dz;
+   data->da2D = data->dx*data->dy;
+}
+
+
+void DVCWeightsSuite_Teardown( DVCWeightsSuiteData* data ) {
+   if(data->bchain) { free(data->bchain); }
+   if(data->pList) { free(data->pList); }
+   if(data->cells) { free(data->cells); }
+
+   if(data->bchain2D) { free(data->bchain2D); }
+   if(data->pList2D) { free(data->pList2D); }
+   if(data->cells2D) { free(data->cells2D); }
+}
+
+
+/* Do the testing of the 3D functions*/
+void DVCWeightsSuite_TestConstructGrid( DVCWeightsSuiteData* data ) {
+   FILE *fp;
+   unsigned int   ii=0;
+   Name    gridFilename = "DVCWeightsSuite_testConstructGrid.txt";
+   char           expectedGridFilename[PCU_PATH_MAX];
+   //int passed=0;
+   char line[100];
+   float x,y,z,dx,dy,dz;
+   int N,S,E,W,U,D;
+   float tol=1e-6;
+   /* We'll use an expected file for this test, as visual checking of the correct parameters is probably
+    *  most logical way to maintain it */
+
+   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);		
+   pcu_filename_expected( gridFilename, expectedGridFilename );/* get the expected filename to open */
+   fp=fopen(expectedGridFilename,"r");
+   if(!fp){
+     pcu_check_true(0);
+     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestConstructGrid" ),"expected test File %s Not Found in function %s\n" ,expectedGridFilename, __func__);
+   }
+   else{
+     /* Print out the grid */
+     for (ii = 0; ii < (data->numx * data->numy * data->numz); ii++ ) {
+       pcu_check_true( data->cells[ii].p == -1 );   /* Particle index: shouldn't be set up yet */
+       pcu_check_true( data->cells[ii].done == 0 );
+       fgets(line,100,fp);  fgets(line,100,fp);
+       sscanf(line,"\t\tValues: (N: %d, S: %d, E: %d, W: %d, U: %d, D: %d)\n",&N,&S,&E,&W,&U,&D);
+       pcu_check_true( data->cells[ii].N == N );
+       pcu_check_true( data->cells[ii].S == S );
+       pcu_check_true( data->cells[ii].E == E );
+       pcu_check_true( data->cells[ii].W == W );
+       pcu_check_true( data->cells[ii].U == U );
+       pcu_check_true( data->cells[ii].D == D );
+       fgets(line,100,fp);
+       sscanf(line,"\t\tCoords: ( %f, %f, %f)\n",&x,&y,&z);
+       dx = (data->cells[ii].x - x)*(data->cells[ii].x - x); 
+       dy = (data->cells[ii].y - y)*(data->cells[ii].y - y); 
+       dz = (data->cells[ii].z - z)*(data->cells[ii].z - z); 
+       pcu_check_true( dx < tol );
+       pcu_check_true( dy < tol );
+       pcu_check_true( dz < tol );
+     }
+   }
+   fclose(fp);
+}
+
+
+void DVCWeightsSuite_TestInitialiseStructs( DVCWeightsSuiteData* data ) {
+   unsigned int   ii;   
+
+   
+   _DVCWeights_InitialiseStructs( &data->bchain, &data->pList, data->nump);
+   for (ii = 0; ii < data->nump; ii++) {
+      pcu_check_true( data->bchain[ii].new_claimed_cells_malloced == DVC_INC );
+      pcu_check_true( data->bchain[ii].new_bound_cells_malloced == DVC_INC );
+   }
+}
+   
+
+void DVCWeightsSuite_TestResetGrid( DVCWeightsSuiteData* data ) {
+   unsigned int   i;
+   
+   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);		
+   _DVCWeights_ResetGrid(&data->cells, data->numz*data->numy*data->numx);
+
+   for ( i = 0; i < data->numz*data->numy*data->numx; i++) {
+      pcu_check_true( data->cells[i].p == -1 );
+      pcu_check_true( data->cells[i].done == 0 );
+   }
+}
+
+
+void _DVCWeightsSuite_InitialiseParticleCoords( DVCWeightsSuiteData* data ) {
+   Index            i;
+
+   /*Initialise particle coords */
+
+   i=0;
+   data->pList[i].x = -0.64320939127356 ; i++;
+   data->pList[i].x = -0.57575625646859 ; i++;
+   data->pList[i].x = -0.44866901542991 ; i++;
+   data->pList[i].x = -0.45453263074160 ; i++;
+   data->pList[i].x = -0.56068608816713 ; i++;
+   data->pList[i].x = -0.31215981673449 ; i++;
+   data->pList[i].x = -0.94066464062780 ; i++;
+   data->pList[i].x = +0.05528775136918 ; i++;
+   data->pList[i].x = -0.62383012939245 ; i++;
+   data->pList[i].x = +0.43985756300390 ; i++;
+   
+   i=0;
+   data->pList[i].y = -0.20064506959170 ; i++;
+   data->pList[i].y = -0.87612858321518 ; i++;
+   data->pList[i].y = -0.90448551066220 ; i++;
+   data->pList[i].y = -0.26452634204179 ; i++;
+   data->pList[i].y = -0.59652493428439 ; i++;
+   data->pList[i].y = +0.29530759342015 ; i++;
+   data->pList[i].y = +0.75698726624250 ; i++;
+   data->pList[i].y = +0.01171378418803 ; i++;
+   data->pList[i].y = -0.76168798375875 ; i++;
+   data->pList[i].y = +0.27507007215172 ; i++;  
+
+   i=0;
+   data->pList[i].z = -0.66680242400616; i++;
+   data->pList[i].z = -0.89170031249523; i++;
+   data->pList[i].z = -0.35793361812830; i++;
+   data->pList[i].z = -0.55526655819267; i++;
+   data->pList[i].z = -0.91176854260266; i++;
+   data->pList[i].z = -0.70107179880142; i++;
+   data->pList[i].z = +0.31083723250777; i++;
+   data->pList[i].z = +0.83138376288116; i++;
+   data->pList[i].z = -0.88380649406463; i++;
+   data->pList[i].z = +0.76169187109917; i++;  
+
+   for ( i = 0; i < data->nump; i++) {	    
+      //Journal_Printf( stream, "data->pList[%d]:", i);
+      //Journal_Printf( stream, "\t\t coords: (x, y, z) = (%f, %f, %f)\n",
+      //   data->pList[i].x, data->pList[i].y, data->pList[i].z);
+
+   }
+}
+
+
+void DVCWeightsSuite_TestCreateVoronoi( DVCWeightsSuiteData* data ) {
+   Index            i;
+
+   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);		
+   _DVCWeights_InitialiseStructs( &data->bchain, &data->pList, data->nump);
+
+   _DVCWeightsSuite_InitialiseParticleCoords( data );
+   _DVCWeights_CreateVoronoi( &data->bchain, &data->pList, &data->cells, data->dx, data->dy, data->dz,
+      data->nump, data->numx, data->numy, data->numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+   
+   /* data->bchain changes */
+   for (i = 0; i < data->nump; i++) {
+      //pcu_check_true( data->bchain[i].index == (data->nump-1) ); //This value doesn't matter at the moment: also nump-1 is the wrong number anyway
+      pcu_check_true( data->bchain[i].sizeofboundary == 0 );
+      pcu_check_true( data->bchain[i].numclaimed == 0 );
+      pcu_check_true( data->bchain[i].totalclaimed == 1 );
+      pcu_check_true( data->bchain[i].new_bound_cells_malloced == DVC_INC );
+      pcu_check_true( data->bchain[i].new_claimed_cells_malloced == DVC_INC );
+      pcu_check_true( data->bchain[i].done == 0 );
+   }
+   /* particle values */
+   for (i = 0; i < data->nump; i++) {
+      pcu_check_true( (data->pList[i].cx == 0) && (data->pList[i].cy == 0) && (data->pList[i].cz == 0));
+      pcu_check_true( data->pList[i].w == 0 );
+   }
+}
+
+
+void DVCWeightsSuite_TestGetCentroids( DVCWeightsSuiteData* data ) {
+   FILE *fp;
+   unsigned int   i;
+   Name    centroidsFilename = "DVCWeightsSuite_testGetCentroids.txt";
+   char           expectedCentroidsFilename[PCU_PATH_MAX];
+   char line[100];
+   float x,y,z,dx,dy,dz;
+   float tol=1e-6;
+   /* We'll use an expected file for this test, as visual checking of the correct parameters is probably
+    *  most logical way to maintain it */
+   
+   _DVCWeights_ConstructGrid(&data->cells, data->numz, data->numy, data->numx, BBXMIN,BBYMIN,BBZMIN,BBXMAX,BBYMAX,BBZMAX);
+   _DVCWeights_InitialiseStructs( &data->bchain, &data->pList, data->nump);
+   _DVCWeightsSuite_InitialiseParticleCoords( data );
+   _DVCWeights_CreateVoronoi( &data->bchain, &data->pList, &data->cells, data->dx, data->dy, data->dz,
+      data->nump, data->numx, data->numy, data->numz, BBXMIN, BBXMAX, BBYMIN, BBYMAX, BBZMIN, BBZMAX);
+
+   _DVCWeights_GetCentroids( data->cells, data->pList,data->numz,data->numy,data->numx,data->nump,data->da);
+
+   pcu_filename_expected(centroidsFilename, expectedCentroidsFilename);/* get the expected filename to open */
+   fp=fopen(expectedCentroidsFilename,"r");
+   if(!fp){
+     pcu_check_true(0);
+     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestGetCentroids" ),"expected test File %s Not Found in function %s\n" ,expectedCentroidsFilename, __func__);
+   }
+   else{
+     for (i = 0; i < data->nump; i++) {
+       fgets(line,100,fp);
+    
+       fgets(line,100,fp);
+       sscanf(line,"\t\tcoords: (x, y, z) = ( %f, %f, %f)\n",&x,&y,&z);
+       dx = (data->pList[i].x -x)*(data->pList[i].x -x);
+       dy = (data->pList[i].y -y)*(data->pList[i].y -y);
+       dz = (data->pList[i].z -z)*(data->pList[i].z -z);
+       pcu_check_true( dx < tol );
+       pcu_check_true( dy < tol );
+       pcu_check_true( dz < tol );
+
+       fgets(line,100,fp);
+       sscanf(line,"\t\tcentroids: (cx, cy, cz) = ( %f, %f, %f)\n",&x,&y,&z);
+       dx = (data->pList[i].cx -x)*(data->pList[i].cx -x);
+       dy = (data->pList[i].cy -y)*(data->pList[i].cy -y);
+       dz = (data->pList[i].cz -z)*(data->pList[i].cz -z);
+       pcu_check_true( dx < tol );
+       pcu_check_true( dy < tol );
+       pcu_check_true( dz < tol );
+       
+       fgets(line,100,fp);
+       sscanf(line,"\t\tweight = %f\n",&x);
+       dx = (data->pList[i].w -x)*(data->pList[i].w -x);
+       pcu_check_true( dx < tol );
+     }
+   }
+   fclose(fp);
+}
+
+
+void DVCWeightsSuite_TestDistanceSquared( DVCWeightsSuiteData* data ) {
+   double particleDistance;		
+   double particle0[3], particle1[3];
+
+   particle0[0] = 0.5;	particle0[1] = 0.5;	particle0[2] = 0.5;
+   particle1[0] = 0.25; particle1[1] = 0.25; 	particle1[2] = 0; 		
+
+   particleDistance = _DVCWeights_DistanceSquared(
+      particle0[0], particle0[1], particle0[2],
+      particle1[0], particle1[1], particle1[2]);
+
+   pcu_check_true( particleDistance == 0.375 );
+}
+
+
+/* 2D Functions */
+
+void DVCWeightsSuite_TestConstructGrid2D( DVCWeightsSuiteData* data ) {
+   FILE *fp;
+   unsigned int   ii=0;
+   Name    gridFilename = "DVCWeightsSuite_testConstructGrid2D.txt";
+   char           expectedGridFilename[PCU_PATH_MAX];
+   char line[100];
+   float x,y,dx,dy;
+   int N,S,E,W;
+   float tol=1e-6;
+
+   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);		
+
+   pcu_filename_expected( gridFilename, expectedGridFilename );/* get the expected filename to open */
+   fp=fopen(expectedGridFilename,"r");
+   if(!fp){
+     pcu_check_true(0);
+     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestConstructGrid2D" ),"expected test File %s Not Found in function %s\n" ,expectedGridFilename, __func__);
+   }
+   else{
+     /* Print out the grid */
+     for (ii = 0; ii < (data->numx * data->numy); ii++ ) {
+       pcu_check_true( data->cells2D[ii].p == -1 );   /* Particle index: shouldn't be set up yet */
+       pcu_check_true( data->cells2D[ii].done == 0 );
+       fgets(line,100,fp);  fgets(line,100,fp);
+       sscanf(line,"\t\tValues: (N: %d, S: %d, E: %d, W: %d)\n",&N,&S,&E,&W);
+       pcu_check_true( data->cells2D[ii].N == N );
+       pcu_check_true( data->cells2D[ii].S == S );
+       pcu_check_true( data->cells2D[ii].E == E );
+       pcu_check_true( data->cells2D[ii].W == W );
+       fgets(line,100,fp);
+       sscanf(line,"\t\tCoords: ( %f, %f)\n",&x,&y);
+       dx = (data->cells2D[ii].x - x)*(data->cells2D[ii].x - x); 
+       dy = (data->cells2D[ii].y - y)*(data->cells2D[ii].y - y); 
+       pcu_check_true( dx < tol );
+       pcu_check_true( dy < tol );
+     }
+   }
+   fclose(fp);
+}
+
+void DVCWeightsSuite_TestInitialiseStructs2D( DVCWeightsSuiteData* data ) {
+   unsigned int   ii;   
+
+   _DVCWeights_InitialiseStructs2D( &data->bchain2D, &data->pList2D, data->nump2D);
+   for (ii = 0; ii < data->nump2D; ii++) {
+      pcu_check_true( data->bchain2D[ii].new_claimed_cells_malloced == DVC_INC );
+      pcu_check_true( data->bchain2D[ii].new_bound_cells_malloced == DVC_INC );
+   }
+}
+
+   
+void DVCWeightsSuite_TestResetGrid2D( DVCWeightsSuiteData* data ) {
+   unsigned int   i;
+   
+   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);
+   _DVCWeights_ResetGrid2D(&data->cells2D,data->numx*data->numy);
+
+   for ( i = 0; i < data->numx*data->numy; i++) {
+      pcu_check_true( data->cells2D[i].p == -1 );
+      pcu_check_true( data->cells2D[i].done == 0 );
+   }
+}
+
+void _DVCWeightsSuite_InitialiseParticleCoords2D( DVCWeightsSuiteData* data ) {
+   Index i;
+
+   /*Initialise particle coords */
+   i=0;
+   data->pList2D[i].x = -0.55376385338604 ; i++;
+   data->pList2D[i].x = -0.10488151479512 ; i++;
+   data->pList2D[i].x = +0.13873003050685 ; i++;
+   data->pList2D[i].x = -0.05016296077520 ; i++;
+   data->pList2D[i].x = +0.90808211639524 ; i++;
+   data->pList2D[i].x = -0.69216587487608 ; i++;
+   data->pList2D[i].x = -0.62051867879927 ; i++;
+   data->pList2D[i].x = +0.24515981227160 ; i++;
+   data->pList2D[i].x = -0.83195694349706 ; i++;
+   data->pList2D[i].x = +0.92260552570224 ; i++;
+   
+   i=0;
+   data->pList2D[i].y = -0.56640755850822 ; i++;
+   data->pList2D[i].y = -0.01476682443172 ; i++;
+   data->pList2D[i].y = -0.05242515634745 ; i++;
+   data->pList2D[i].y = -0.93268149159849 ; i++;
+   data->pList2D[i].y = +0.91700463462621 ; i++;
+   data->pList2D[i].y = -0.47783328499645 ; i++;
+   data->pList2D[i].y = -0.27844923641533 ; i++;
+   data->pList2D[i].y = -0.66626300383359 ; i++;
+   data->pList2D[i].y = +0.17968866135925 ; i++;
+   data->pList2D[i].y = -0.58136314433068 ; i++;
+   
+
+   for ( i = 0; i < data->nump2D; i++) {	    
+      //Journal_Printf( stream, "data->pList2D[%d]:", i);
+      //Journal_Printf( stream, "\t\t coords: (x, y) = (%f, %f)\n",
+      //   data->pList2D[i].x, data->pList2D[i].y);
+
+   }
+}
+
+
+void DVCWeightsSuite_TestCreateVoronoi2D( DVCWeightsSuiteData* data ) {
+   Index i;
+
+   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);
+   _DVCWeights_InitialiseStructs2D( &data->bchain2D, &data->pList2D, data->nump2D);
+
+   _DVCWeightsSuite_InitialiseParticleCoords2D( data );
+   _DVCWeights_CreateVoronoi2D( &data->bchain2D, &data->pList2D, &data->cells2D, data->dx, data->dy,
+      data->nump2D, data->numx, data->numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
+   
+   /* data->bchain2D changes */
+   for (i = 0; i < data->nump2D; i++) {
+      //pcu_check_true( data->bchain2D[i].index == (data->nump2D-1) );//This value doesn't matter at the moment: also nump2D-1 is the wrong number anyway
+      pcu_check_true( data->bchain2D[i].sizeofboundary == 0 );
+      pcu_check_true( data->bchain2D[i].numclaimed == 0 );
+      pcu_check_true( data->bchain2D[i].totalclaimed == 1 );
+      pcu_check_true( data->bchain2D[i].new_bound_cells_malloced == DVC_INC );
+      pcu_check_true( data->bchain2D[i].new_claimed_cells_malloced == DVC_INC );
+      pcu_check_true( data->bchain2D[i].done == 0 );
+   }
+   /* particle values */
+   for (i = 0; i < data->nump2D; i++) {
+      pcu_check_true( (data->pList2D[i].cx == 0) && (data->pList2D[i].cy == 0) );
+      pcu_check_true( data->pList2D[i].w == 0 );
+   }
+}
+
+
+void DVCWeightsSuite_TestGetCentroids2D( DVCWeightsSuiteData* data ) {
+   FILE *fp;
+   unsigned int   i;
+   Name    centroidsFilename = "DVCWeightsSuite_testGetCentroids2D.txt";
+   char           expectedCentroidsFilename[PCU_PATH_MAX];
+   char line[100];
+   float x,y,dx,dy;
+   float tol=1e-6;
+
+   _DVCWeights_ConstructGrid2D(&data->cells2D,data->numy,data->numx, BBXMIN,BBYMIN,BBXMAX,BBYMAX);
+   _DVCWeights_InitialiseStructs2D( &data->bchain2D, &data->pList2D, data->nump2D);   
+   _DVCWeightsSuite_InitialiseParticleCoords2D( data );
+   _DVCWeights_CreateVoronoi2D( &data->bchain2D, &data->pList2D, &data->cells2D, data->dx, data->dy,
+      data->nump2D, data->numx, data->numy, BBXMIN, BBXMAX, BBYMIN, BBYMAX);
+
+   _DVCWeights_GetCentroids2D( data->cells2D, data->pList2D,data->numy,data->numx,data->nump2D,data->da2D);
+
+   pcu_filename_expected( centroidsFilename, expectedCentroidsFilename );
+    fp=fopen(expectedCentroidsFilename,"r");
+   if(!fp){
+     pcu_check_true(0);
+     Journal_Firewall( 0 , Journal_Register( Error_Type, (Name)"DVCWeightsSuite_TestGetCentroids2D" ),"expected test File %s Not Found in function %s\n" ,expectedCentroidsFilename, __func__);
+   }
+   else{
+
+     for (i = 0; i < data->nump2D; i++) {
+       fgets(line,100,fp);
+    
+       fgets(line,100,fp);
+       sscanf(line,"\t\tcoords: (x, y) = ( %f, %f)\n",&x,&y);
+       dx = (data->pList2D[i].x -x)*(data->pList2D[i].x -x);
+       dy = (data->pList2D[i].y -y)*(data->pList2D[i].y -y);
+       pcu_check_true( dx < tol );
+       pcu_check_true( dy < tol );
+
+       fgets(line,100,fp);
+       sscanf(line,"\t\tcentroids: (cx, cy) = ( %f, %f)\n",&x,&y);
+       dx = (data->pList2D[i].cx -x)*(data->pList2D[i].cx -x);
+       dy = (data->pList2D[i].cy -y)*(data->pList2D[i].cy -y);
+       pcu_check_true( dx < tol );
+       pcu_check_true( dy < tol );
+       
+       fgets(line,100,fp);
+       sscanf(line,"\t\tweight = %f\n",&x);
+       dx = (data->pList2D[i].w -x)*(data->pList2D[i].w -x);
+       pcu_check_true( dx < tol );
+     }
+   }
+   fclose(fp);
+}
+
+
+void DVCWeightsSuite_TestDistanceSquared2D( DVCWeightsSuiteData* data ) {
+   double particleDistance;		
+   double particle0[2], particle1[2];
+   
+   particle0[0] = 0.5;	particle0[1] = 0.5;
+   particle1[0] = 0.25; particle1[1] = 0.25;
+
+   particleDistance = _DVCWeights_DistanceSquared2D(
+      particle0[0], particle0[1],
+      particle1[0], particle1[1] );
+   
+   pcu_check_true( particleDistance == 0.125 );
+}
+
+
+void DVCWeightsSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, DVCWeightsSuiteData );
+   pcu_suite_setFixtures( suite, DVCWeightsSuite_Setup, DVCWeightsSuite_Teardown );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestConstructGrid );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestResetGrid );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestInitialiseStructs );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestCreateVoronoi );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestGetCentroids );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestDistanceSquared );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestConstructGrid2D );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestInitialiseStructs2D );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestResetGrid2D );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestCreateVoronoi2D );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestGetCentroids2D );
+   pcu_suite_addTest( suite, DVCWeightsSuite_TestDistanceSquared2D );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/IterativeWeightsSuite.c
--- a/Weights/tests/IterativeWeightsSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,121 +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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "ConstantWeightsSuite.h"
-#include "IterativeWeightsSuite.h"
-
-typedef struct {
-   PICelleratorContext*       context;
-   Stg_ComponentFactory* cf;
-} IterativeWeightsSuiteData;
-
-
-void IterativeWeightsSuite_Setup( IterativeWeightsSuiteData* data ) {
-   char              xmlInputFilename[PCU_PATH_MAX];
-
-   pcu_filename_input( "testIterativeWeights.xml", xmlInputFilename );
-   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
-   data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
-   stgMainBuildAndInitialise( data->cf );
-} 
-
-
-void IterativeWeightsSuite_Teardown( IterativeWeightsSuiteData* data ) {
-   stgMainDestroy( data->cf );
-}
-
-void IterativeWeightsSuite_TestConstantFunction( IterativeWeightsSuiteData* data  ) {
-   WeightsSuite_TestElementIntegral( data->context, "ConstantFunction", 1000,
-      1e-10, /* --mean-tolerance */
-      1e-10, /* --standardDeviation-tolerance */
-      0.0, /* --mean-expectedValue */
-      0.0 /* --standardDeviation-expectedValue */ );
-}
-void IterativeWeightsSuite_TestLinearFunction ( IterativeWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "LinearFunction", 1000,
-      1e-4, /* --mean-tolerance */
-      1e-4, /* --standardDeviation-tolerance */
-      0.0, /* --mean-expectedValue */
-      0.0 /* --standardDeviation-expectedValue */ );
-}
-void IterativeWeightsSuite_TestQuadraticFunction ( IterativeWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "QuadraticFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0430721, /* --mean-expectedValue */
-      0.0326016 /* --standardDeviation-expectedValue */ );
-}
-
-void IterativeWeightsSuite_TestPolynomialFunction( IterativeWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "PolynomialFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0175259, /* --mean-expectedValue */
-      0.013522 /* --standardDeviation-expectedValue */ );
-}
-
-void IterativeWeightsSuite_TestCircleInterface( IterativeWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "CircleInterface", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.10172, /* --mean-expectedValue */
-      0.070065 /* --standardDeviation-expectedValue */ );
-}
-
-void IterativeWeightsSuite_TestExponentialInterface( IterativeWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "ExponentialInterface", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.088927, /* --mean-expectedValue */
-      0.06681 /* --standardDeviation-expectedValue */ );
-}
-
-void IterativeWeightsSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, IterativeWeightsSuiteData );
-   pcu_suite_setFixtures( suite, IterativeWeightsSuite_Setup, IterativeWeightsSuite_Teardown );
-   pcu_suite_addTest( suite, IterativeWeightsSuite_TestConstantFunction );
-   pcu_suite_addTest( suite, IterativeWeightsSuite_TestLinearFunction );
-   pcu_suite_addTest( suite, IterativeWeightsSuite_TestQuadraticFunction );
-   pcu_suite_addTest( suite, IterativeWeightsSuite_TestPolynomialFunction );
-   pcu_suite_addTest( suite, IterativeWeightsSuite_TestCircleInterface );
-   pcu_suite_addTest( suite, IterativeWeightsSuite_TestExponentialInterface );
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/IterativeWeightsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/tests/IterativeWeightsSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,121 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**   Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**   Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**   Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**   Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**   Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**   Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "ConstantWeightsSuite.h"
+#include "IterativeWeightsSuite.h"
+
+typedef struct {
+   PICelleratorContext*       context;
+   Stg_ComponentFactory* cf;
+} IterativeWeightsSuiteData;
+
+
+void IterativeWeightsSuite_Setup( IterativeWeightsSuiteData* data ) {
+   char              xmlInputFilename[PCU_PATH_MAX];
+
+   pcu_filename_input( "testIterativeWeights.xml", xmlInputFilename );
+   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
+   data->context = (PICelleratorContext*)LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
+   stgMainBuildAndInitialise( data->cf );
+} 
+
+
+void IterativeWeightsSuite_Teardown( IterativeWeightsSuiteData* data ) {
+   stgMainDestroy( data->cf );
+}
+
+void IterativeWeightsSuite_TestConstantFunction( IterativeWeightsSuiteData* data  ) {
+   WeightsSuite_TestElementIntegral( data->context, "ConstantFunction", 1000,
+      1e-10, /* --mean-tolerance */
+      1e-10, /* --standardDeviation-tolerance */
+      0.0, /* --mean-expectedValue */
+      0.0 /* --standardDeviation-expectedValue */ );
+}
+void IterativeWeightsSuite_TestLinearFunction ( IterativeWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "LinearFunction", 1000,
+      1e-4, /* --mean-tolerance */
+      1e-4, /* --standardDeviation-tolerance */
+      0.0, /* --mean-expectedValue */
+      0.0 /* --standardDeviation-expectedValue */ );
+}
+void IterativeWeightsSuite_TestQuadraticFunction ( IterativeWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "QuadraticFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0430721, /* --mean-expectedValue */
+      0.0326016 /* --standardDeviation-expectedValue */ );
+}
+
+void IterativeWeightsSuite_TestPolynomialFunction( IterativeWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "PolynomialFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0175259, /* --mean-expectedValue */
+      0.013522 /* --standardDeviation-expectedValue */ );
+}
+
+void IterativeWeightsSuite_TestCircleInterface( IterativeWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "CircleInterface", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.10172, /* --mean-expectedValue */
+      0.070065 /* --standardDeviation-expectedValue */ );
+}
+
+void IterativeWeightsSuite_TestExponentialInterface( IterativeWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "ExponentialInterface", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.088927, /* --mean-expectedValue */
+      0.06681 /* --standardDeviation-expectedValue */ );
+}
+
+void IterativeWeightsSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, IterativeWeightsSuiteData );
+   pcu_suite_setFixtures( suite, IterativeWeightsSuite_Setup, IterativeWeightsSuite_Teardown );
+   pcu_suite_addTest( suite, IterativeWeightsSuite_TestConstantFunction );
+   pcu_suite_addTest( suite, IterativeWeightsSuite_TestLinearFunction );
+   pcu_suite_addTest( suite, IterativeWeightsSuite_TestQuadraticFunction );
+   pcu_suite_addTest( suite, IterativeWeightsSuite_TestPolynomialFunction );
+   pcu_suite_addTest( suite, IterativeWeightsSuite_TestCircleInterface );
+   pcu_suite_addTest( suite, IterativeWeightsSuite_TestExponentialInterface );
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/MomentBalanceWeightsSuite.c
--- a/Weights/tests/MomentBalanceWeightsSuite.c	Wed May 11 13:26:28 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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pcu/pcu.h"
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "ConstantWeightsSuite.h"
-#include "MomentBalanceWeightsSuite.h"
-
-typedef struct {
-   PICelleratorContext*		context;
-   Stg_ComponentFactory*	cf;
-} MomentBalanceWeightsSuiteData;
-
-void MomentBalanceWeightsSuite_Setup( MomentBalanceWeightsSuiteData* data ) {
-   char xmlInputFilename[PCU_PATH_MAX];
-
-   pcu_filename_input( "testMomentBalanceWeights.xml", xmlInputFilename );
-   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
-   data->context = (PICelleratorContext*) LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
-   stgMainBuildAndInitialise( data->cf );
-} 
-
-void MomentBalanceWeightsSuite_Teardown( MomentBalanceWeightsSuiteData* data ) {
-   stgMainDestroy( data->cf );
-}
-
-void MomentBalanceWeightsSuite_TestConstantFunction( MomentBalanceWeightsSuiteData* data  ) {
-   WeightsSuite_TestElementIntegral( data->context, "ConstantFunction", 1000,
-      1e-10, /* --mean-tolerance */
-      1e-10, /* --standardDeviation-tolerance */
-      0.0, /* --mean-expectedValue */
-      0.0 /* --standardDeviation-expectedValue */ );
-}
-void MomentBalanceWeightsSuite_TestLinearFunction ( MomentBalanceWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "LinearFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.00363688, /* --mean-expectedValue */
-      0.029866 /* --standardDeviation-expectedValue */ );
-}
-void MomentBalanceWeightsSuite_TestQuadraticFunction ( MomentBalanceWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "QuadraticFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0446896, /* --mean-expectedValue */
-      0.0351938 /* --standardDeviation-expectedValue */ );
-}
-
-void MomentBalanceWeightsSuite_TestPolynomialFunction( MomentBalanceWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "PolynomialFunction", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0166968, /* --mean-expectedValue */
-      0.0130415 /* --standardDeviation-expectedValue */ );
-}
-
-void MomentBalanceWeightsSuite_TestCircleInterface( MomentBalanceWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "CircleInterface", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0978135, /* --mean-expectedValue */
-      0.0686067 /* --standardDeviation-expectedValue */ );
-}
-
-void MomentBalanceWeightsSuite_TestExponentialInterface( MomentBalanceWeightsSuiteData* data ) {
-   WeightsSuite_TestElementIntegral( data->context, "ExponentialInterface", 1000,
-      0.000001, /* --mean-tolerance */
-      0.000001, /* --standardDeviation-tolerance */
-      0.0946707, /* --mean-expectedValue */
-      0.0752869 /* --standardDeviation-expectedValue */ );
-}
-
-void MomentBalanceWeightsSuite( pcu_suite_t* suite ) {
-   pcu_suite_setData( suite, MomentBalanceWeightsSuiteData );
-   pcu_suite_setFixtures( suite, MomentBalanceWeightsSuite_Setup, MomentBalanceWeightsSuite_Teardown );
-   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestConstantFunction );
-   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestLinearFunction );
-   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestQuadraticFunction );
-   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestPolynomialFunction );
-   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestCircleInterface );
-   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestExponentialInterface );
-}
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 Weights/tests/MomentBalanceWeightsSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Weights/tests/MomentBalanceWeightsSuite.cxx	Thu May 12 11:18:04 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: testList.c 2136 2004-09-30 02:47:13Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "pcu/pcu.h"
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "ConstantWeightsSuite.h"
+#include "MomentBalanceWeightsSuite.h"
+
+typedef struct {
+   PICelleratorContext*		context;
+   Stg_ComponentFactory*	cf;
+} MomentBalanceWeightsSuiteData;
+
+void MomentBalanceWeightsSuite_Setup( MomentBalanceWeightsSuiteData* data ) {
+   char xmlInputFilename[PCU_PATH_MAX];
+
+   pcu_filename_input( "testMomentBalanceWeights.xml", xmlInputFilename );
+   data->cf = stgMainInitFromXML( xmlInputFilename, MPI_COMM_WORLD, NULL );
+   data->context = (PICelleratorContext*) LiveComponentRegister_Get( data->cf->LCRegister, (Name)"context" );
+   stgMainBuildAndInitialise( data->cf );
+} 
+
+void MomentBalanceWeightsSuite_Teardown( MomentBalanceWeightsSuiteData* data ) {
+   stgMainDestroy( data->cf );
+}
+
+void MomentBalanceWeightsSuite_TestConstantFunction( MomentBalanceWeightsSuiteData* data  ) {
+   WeightsSuite_TestElementIntegral( data->context, "ConstantFunction", 1000,
+      1e-10, /* --mean-tolerance */
+      1e-10, /* --standardDeviation-tolerance */
+      0.0, /* --mean-expectedValue */
+      0.0 /* --standardDeviation-expectedValue */ );
+}
+void MomentBalanceWeightsSuite_TestLinearFunction ( MomentBalanceWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "LinearFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.00363688, /* --mean-expectedValue */
+      0.029866 /* --standardDeviation-expectedValue */ );
+}
+void MomentBalanceWeightsSuite_TestQuadraticFunction ( MomentBalanceWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "QuadraticFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0446896, /* --mean-expectedValue */
+      0.0351938 /* --standardDeviation-expectedValue */ );
+}
+
+void MomentBalanceWeightsSuite_TestPolynomialFunction( MomentBalanceWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "PolynomialFunction", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0166968, /* --mean-expectedValue */
+      0.0130415 /* --standardDeviation-expectedValue */ );
+}
+
+void MomentBalanceWeightsSuite_TestCircleInterface( MomentBalanceWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "CircleInterface", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0978135, /* --mean-expectedValue */
+      0.0686067 /* --standardDeviation-expectedValue */ );
+}
+
+void MomentBalanceWeightsSuite_TestExponentialInterface( MomentBalanceWeightsSuiteData* data ) {
+   WeightsSuite_TestElementIntegral( data->context, "ExponentialInterface", 1000,
+      0.000001, /* --mean-tolerance */
+      0.000001, /* --standardDeviation-tolerance */
+      0.0946707, /* --mean-expectedValue */
+      0.0752869 /* --standardDeviation-expectedValue */ );
+}
+
+void MomentBalanceWeightsSuite( pcu_suite_t* suite ) {
+   pcu_suite_setData( suite, MomentBalanceWeightsSuiteData );
+   pcu_suite_setFixtures( suite, MomentBalanceWeightsSuite_Setup, MomentBalanceWeightsSuite_Teardown );
+   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestConstantFunction );
+   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestLinearFunction );
+   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestQuadraticFunction );
+   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestPolynomialFunction );
+   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestCircleInterface );
+   pcu_suite_addTest( suite, MomentBalanceWeightsSuite_TestExponentialInterface );
+}
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/Toolbox/Toolbox.c
--- a/libPICellerator/Toolbox/Toolbox.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,82 +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 <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include "Toolbox.h"
-
-const Type PICellerator_Toolbox_Type = "PICellerator_Toolbox";
-
-void _PICellerator_Toolbox_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-}
-
-void* _PICellerator_Toolbox_DefaultNew( Name name ) {
-	return Codelet_New(
-			PICellerator_Toolbox_Type,
-			_PICellerator_Toolbox_DefaultNew,
-			_PICellerator_Toolbox_AssignFromXML,
-			_Codelet_Build,
-			_Codelet_Initialise,
-			_Codelet_Execute,
-			_Codelet_Destroy,
-			name );
-}
-
-void PICellerator_Toolbox_Initialise( PluginsManager* pluginsManager, int* argc, char*** argv ) {
-	PICellerator_Init( argc, argv );
-}
-
-void PICellerator_Toolbox_Finalise( PluginsManager* pluginsManager ) {
-	PICellerator_Finalise();
-	
-	Journal_RPrintf( Journal_Register( DebugStream_Type, (Name)PICellerator_Toolbox_Type  ), "Finalised: PICellerator Toolbox.\n" );
-}
-
-Index PICellerator_Toolbox_Register( PluginsManager* pluginsManager ) {
-  return PluginsManager_Submit( pluginsManager, PICellerator_Toolbox_Type, (Name)"0", _PICellerator_Toolbox_DefaultNew  );
-}
-
-
-
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/Toolbox/Toolbox.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libPICellerator/Toolbox/Toolbox.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,82 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** 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 <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include "Toolbox.h"
+
+const Type PICellerator_Toolbox_Type = "PICellerator_Toolbox";
+
+void _PICellerator_Toolbox_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+}
+
+void* _PICellerator_Toolbox_DefaultNew( Name name ) {
+	return Codelet_New(
+			PICellerator_Toolbox_Type,
+			_PICellerator_Toolbox_DefaultNew,
+			_PICellerator_Toolbox_AssignFromXML,
+			_Codelet_Build,
+			_Codelet_Initialise,
+			_Codelet_Execute,
+			_Codelet_Destroy,
+			name );
+}
+
+void PICellerator_Toolbox_Initialise( PluginsManager* pluginsManager, int* argc, char*** argv ) {
+	PICellerator_Init( argc, argv );
+}
+
+void PICellerator_Toolbox_Finalise( PluginsManager* pluginsManager ) {
+	PICellerator_Finalise();
+	
+	Journal_RPrintf( Journal_Register( DebugStream_Type, (Name)PICellerator_Toolbox_Type  ), "Finalised: PICellerator Toolbox.\n" );
+}
+
+Index PICellerator_Toolbox_Register( PluginsManager* pluginsManager ) {
+  return PluginsManager_Submit( pluginsManager, PICellerator_Toolbox_Type, (Name)"0", _PICellerator_Toolbox_DefaultNew  );
+}
+
+
+
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/src/Finalise.c
--- a/libPICellerator/src/Finalise.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "PICellerator.h"
-
-#include <stdio.h>
-
-Bool PICellerator_Finalise( void ) {
-	if( ToolboxesManager_IsInitialised( stgToolboxesManager, "PICellerator" ) ) {
-		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
-		
-		PICellerator_Utils_Finalise();
-		PICellerator_MaterialPoints_Finalise();
-		PICellerator_Weights_Finalise();
-		PICellerator_PopulationControl_Finalise();
-		
-		return True;
-	} else {
-		return False;
-	}
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/src/Finalise.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libPICellerator/src/Finalise.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,69 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Finalise.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "PICellerator.h"
+
+#include <stdio.h>
+
+Bool PICellerator_Finalise( void ) {
+	if( ToolboxesManager_IsInitialised( stgToolboxesManager, "PICellerator" ) ) {
+		Journal_Printf( Journal_Register( DebugStream_Type, (Name)"Context"  ), "In: %s\n", __func__ ); /* DO NOT CHANGE OR REMOVE */
+		
+		PICellerator_Utils_Finalise();
+		PICellerator_MaterialPoints_Finalise();
+		PICellerator_Weights_Finalise();
+		PICellerator_PopulationControl_Finalise();
+		
+		return True;
+	} else {
+		return False;
+	}
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/src/Init.c
--- a/libPICellerator/src/Init.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-
-#include "PICellerator.h"
-
-#include <stdio.h>
-
-/** Initialises this package, then any init for this package
-such as streams etc */
-Bool PICellerator_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, "PICellerator" ) ) {
-		int tmp;
-		char* directory;
-
-		PICellerator_PopulationControl_Init( argc, argv );
-		PICellerator_Weights_Init( argc, argv );
-		PICellerator_MaterialPoints_Init( argc, argv );
-		PICellerator_Utils_Init( argc, argv );
-	
-		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"  ), 
-			"Particle-In-Cellerator (FEM/PIC framework) revision %s. Copyright (C) 2005 VPAC & Monash Cluster Computing.\n", VERSION );
-		Stream_Flush( Journal_Register( InfoStream_Type, (Name)"Context" )  );
-		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), tmp );
-
-		/* Add the PICellerator path to the global xml path dictionary */
-		directory = Memory_Alloc_Array( char, 200, "xmlDirectory" ) ;
-		sprintf(directory, "%s%s", LIB_DIR, "/StGermain" );
-		XML_IO_Handler_AddDirectory( "PICellerator", directory );
-		Memory_Free(directory);
-	
-		/* Add the plugin path to the global plugin list */
-		ModulesManager_AddDirectory( "PICellerator", LIB_DIR );
-
-		return True;
-	}
-	return False;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/src/Init.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libPICellerator/src/Init.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,91 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: Init.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+
+#include "PICellerator.h"
+
+#include <stdio.h>
+
+/** Initialises this package, then any init for this package
+such as streams etc */
+Bool PICellerator_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, "PICellerator" ) ) {
+		int tmp;
+		char* directory;
+
+		PICellerator_PopulationControl_Init( argc, argv );
+		PICellerator_Weights_Init( argc, argv );
+		PICellerator_MaterialPoints_Init( argc, argv );
+		PICellerator_Utils_Init( argc, argv );
+	
+		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"  ), 
+			"Particle-In-Cellerator (FEM/PIC framework) revision %s. Copyright (C) 2005 VPAC & Monash Cluster Computing.\n", VERSION );
+		Stream_Flush( Journal_Register( InfoStream_Type, (Name)"Context" )  );
+		Stream_SetPrintingRank( Journal_Register( InfoStream_Type, (Name)"Context"  ), tmp );
+
+		/* Add the PICellerator path to the global xml path dictionary */
+		directory = Memory_Alloc_Array( char, 200, "xmlDirectory" ) ;
+		sprintf(directory, "%s%s", LIB_DIR, "/StGermain" );
+		XML_IO_Handler_AddDirectory( "PICellerator", directory );
+		Memory_Free(directory);
+	
+		/* Add the plugin path to the global plugin list */
+		ModulesManager_AddDirectory( "PICellerator", LIB_DIR );
+
+		return True;
+	}
+	return False;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/tests/LibPICelleratorSuite.c
--- a/libPICellerator/tests/LibPICelleratorSuite.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +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 <StgFEM/StgFEM.h>
-
-#include "PICellerator/PICellerator.h"
-#include "PICellerator/Init.h"
-#include "PICellerator/Finalise.h"
-
-#include "LibPICelleratorSuite.h"
-
-typedef struct {
-} LibPICelleratorSuiteData;
-
-void LibPICelleratorSuite_Setup( LibPICelleratorSuiteData* data ) {
-}
-
-void LibPICelleratorSuite_Teardown( LibPICelleratorSuiteData* data ) {
-}
-
-void LibPICelleratorSuite_TestDirectoryStGermain( LibPICelleratorSuiteData* data ) {
-    Stg_Object* testDirectoryStGermain;
-    testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain" );
-    pcu_check_true( testDirectoryStGermain != NULL );
-}
-
-void LibPICelleratorSuite_TestDirectoryStgFEM( LibPICelleratorSuiteData * data  ) {
-    Stg_Object* testDirectoryStGermain;
-    Stg_Object* testDirectoryStgFEM;
-
-    testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain"  );
-    testDirectoryStgFEM= (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StgFEM" );
-
-    pcu_check_true( ( strcmp((char* )LIB_DIR, (char*)testDirectoryStGermain) ) || ( testDirectoryStgFEM != NULL ) );
-}
-
-void LibPICelleratorSuite_TestDirectoryPICellerator( LibPICelleratorSuiteData * data ) {
-    Stg_Object* testDirectoryStGermain;
-    Stg_Object* testDirectoryPICellerator;
-
-    testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain"  );
-    testDirectoryPICellerator= (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"PICellerator" );
-
-    pcu_check_true( ( strcmp((char* )LIB_DIR, (char*)testDirectoryStGermain) ) || ( testDirectoryPICellerator != NULL ) );
-}
-
-void LibPICelleratorSuite( pcu_suite_t* suite ) {
-
-    pcu_suite_setData( suite, LibPICelleratorSuiteData );
-    pcu_suite_setFixtures( suite, LibPICelleratorSuite_Setup, LibPICelleratorSuite_Teardown);
-
-    pcu_suite_addTest( suite, LibPICelleratorSuite_TestDirectoryStGermain );
-    pcu_suite_addTest( suite, LibPICelleratorSuite_TestDirectoryStgFEM);
-    pcu_suite_addTest( suite, LibPICelleratorSuite_TestDirectoryPICellerator);
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 libPICellerator/tests/LibPICelleratorSuite.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libPICellerator/tests/LibPICelleratorSuite.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,63 @@
+#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 <StgFEM/StgFEM.h>
+
+#include "PICellerator/PICellerator.h"
+#include "PICellerator/Init.h"
+#include "PICellerator/Finalise.h"
+
+#include "LibPICelleratorSuite.h"
+
+typedef struct {
+} LibPICelleratorSuiteData;
+
+void LibPICelleratorSuite_Setup( LibPICelleratorSuiteData* data ) {
+}
+
+void LibPICelleratorSuite_Teardown( LibPICelleratorSuiteData* data ) {
+}
+
+void LibPICelleratorSuite_TestDirectoryStGermain( LibPICelleratorSuiteData* data ) {
+    Stg_Object* testDirectoryStGermain;
+    testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain" );
+    pcu_check_true( testDirectoryStGermain != NULL );
+}
+
+void LibPICelleratorSuite_TestDirectoryStgFEM( LibPICelleratorSuiteData * data  ) {
+    Stg_Object* testDirectoryStGermain;
+    Stg_Object* testDirectoryStgFEM;
+
+    testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain"  );
+    testDirectoryStgFEM= (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StgFEM" );
+
+    pcu_check_true( ( strcmp((char* )LIB_DIR, (char*)testDirectoryStGermain) ) || ( testDirectoryStgFEM != NULL ) );
+}
+
+void LibPICelleratorSuite_TestDirectoryPICellerator( LibPICelleratorSuiteData * data ) {
+    Stg_Object* testDirectoryStGermain;
+    Stg_Object* testDirectoryPICellerator;
+
+    testDirectoryStGermain = (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"StGermain"  );
+    testDirectoryPICellerator= (Stg_Object*)Stg_ObjectList_Get( Project_XMLSearchPaths, (Name)"PICellerator" );
+
+    pcu_check_true( ( strcmp((char* )LIB_DIR, (char*)testDirectoryStGermain) ) || ( testDirectoryPICellerator != NULL ) );
+}
+
+void LibPICelleratorSuite( pcu_suite_t* suite ) {
+
+    pcu_suite_setData( suite, LibPICelleratorSuiteData );
+    pcu_suite_setFixtures( suite, LibPICelleratorSuite_Setup, LibPICelleratorSuite_Teardown);
+
+    pcu_suite_addTest( suite, LibPICelleratorSuite_TestDirectoryStGermain );
+    pcu_suite_addTest( suite, LibPICelleratorSuite_TestDirectoryStgFEM);
+    pcu_suite_addTest( suite, LibPICelleratorSuite_TestDirectoryPICellerator);
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 plugins/CalculateParticleDisplacement/CalculateParticleDisplacement.c
--- a/plugins/CalculateParticleDisplacement/CalculateParticleDisplacement.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,191 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: CalculateParticleDisplacement.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-
-#include "CalculateParticleDisplacement.h"
-#include <math.h>
-#include <string.h>
-#include <assert.h>
-
-const Type PICellerator_CalculateParticleDisplacement_Type = "PICellerator_CalculateParticleDisplacement";
-
-void _PICellerator_CalculateParticleDisplacement_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-	CalculateParticleDisplacementPlugin*  self = (CalculateParticleDisplacementPlugin*)component;
-	DomainContext*                context;
-	MaterialPointsSwarm*                  materialPointsSwarm;
-	StandardParticle                      particle;
-	ParticleDisplacementInfo*             particleExt;
-	
-	context = (DomainContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
-
-	ContextEP_Append( context, AbstractContext_EP_Initialise, _PICellerator_CalculateParticleDisplacement_StoreOriginalPos );
-	ContextEP_Append( context, AbstractContext_EP_Step, _PICellerator_CalculateParticleDisplacement_UpdateDisplacement );
-
-	/* Extend particle with original pos */
-	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
-	assert( materialPointsSwarm  );
-	self->particleDisplacementInfo_Handle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof( ParticleDisplacementInfo )  );
-
-	/* now register these guys as swarm variables */
-	particleExt = (ParticleDisplacementInfo*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle,
-		self->particleDisplacementInfo_Handle );
-
-	self->particleOriginalCoordSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"OriginalCoord", (ArithPointer) &particleExt->originalCoord - (ArithPointer) &particle,
-		Variable_DataType_Double,
-		materialPointsSwarm->dim,
-		"OriginalCoordX",
-		"OriginalCoordY",
-		"OriginalCoordZ" );
-		
-	self->particleDisplacementSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"Displacement", (ArithPointer) &particleExt->displacement - (ArithPointer) &particle,
-		Variable_DataType_Double,
-		materialPointsSwarm->dim,
-		"DisplacementX",
-		"DisplacementY",
-		"DisplacementZ" );
-
-	/* Create this here, rather than in XML, since if we tried to create it in XML it couldn't
-	find the Displacement swarm variable at configure-time */
-	/* OperatorSwarmVariables don't automatically prefix the swarm's name to the name
-	you give, so we have to add it manually here */
-	self->particleDisplacementMagSwarmVariable = OperatorSwarmVariable_NewUnary(
-		"materialSwarm-DisplacementMagnitude",
-		(AbstractContext*)context, 
-		self->particleDisplacementSwarmVariable,
-		"Magnitude" );
-	
-	/* Need to make sure this guy is build/initialised */
-}
-
-
-void _PICellerator_CalculateParticleDisplacement_StoreOriginalPos( PICelleratorContext* context ) {
-	CalculateParticleDisplacementPlugin*  self;
-	MaterialPointsSwarm*                  materialPointsSwarm;
-	GlobalParticle*                       particle;
-	double*                               originalCoord;
-	ParticleDisplacementInfo*             particleDisplacementInfo; 
-	Particle_Index                        lParticle_I;
-
-	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
-	assert( materialPointsSwarm );
-	self = (CalculateParticleDisplacementPlugin* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"PICellerator_CalculateParticleDisplacement" );
-	assert( self );
-
-	for ( lParticle_I = 0 ; lParticle_I < materialPointsSwarm->particleLocalCount ; lParticle_I++ ) {
-		particle = (GlobalParticle* )Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
-		particleDisplacementInfo = (ParticleDisplacementInfo*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr,
-			particle, self->particleDisplacementInfo_Handle );
-		originalCoord = particleDisplacementInfo->originalCoord;
-
-		memcpy( originalCoord, particle->coord, sizeof(Coord) );
-		memset( particleDisplacementInfo->displacement, 0, sizeof(XYZ) );
-	}
-}
-
-
-void _PICellerator_CalculateParticleDisplacement_UpdateDisplacement( PICelleratorContext* context ) {
-	CalculateParticleDisplacementPlugin*  self;
-	MaterialPointsSwarm*                  materialPointsSwarm;
-	GlobalParticle*                       particle;
-	double*                               originalCoord;
-	double*                               coord;
-	Particle_Index                        lParticle_I;
-	ParticleDisplacementInfo*             particleDisplacementInfo = NULL;
-	Dimension_Index                       dim_I;
-
-	/* Add original pos to particle */
-	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
-	assert( materialPointsSwarm );
-	self = (CalculateParticleDisplacementPlugin* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"PICellerator_CalculateParticleDisplacement" );
-	assert( self );
-
-	for ( lParticle_I = 0 ; lParticle_I < materialPointsSwarm->particleLocalCount ; lParticle_I++ ) {
-		particle      = (GlobalParticle* )Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
-		coord         = particle->coord;
-		particleDisplacementInfo = (ParticleDisplacementInfo*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, particle,
-			self->particleDisplacementInfo_Handle );
-		originalCoord = particleDisplacementInfo->originalCoord;	
-
-		for ( dim_I = 0; dim_I < materialPointsSwarm->dim; dim_I++ ) {
-			particleDisplacementInfo->displacement[dim_I] = coord[dim_I] - originalCoord[dim_I];
-		}
-	}
-}
-
-
-void* _PICellerator_CalculateParticleDisplacement_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( CalculateParticleDisplacementPlugin );
-	Type                                                      type = PICellerator_CalculateParticleDisplacement_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PICellerator_CalculateParticleDisplacement_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _PICellerator_CalculateParticleDisplacement_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Codelet_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Codelet_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 _Codelet_New(  CODELET_PASSARGS  );
-}
-
-
-Index PICellerator_CalculateParticleDisplacement_Register( PluginsManager* pluginsManager ) {
-	Index result;
-
-	result = PluginsManager_Submit( pluginsManager, PICellerator_CalculateParticleDisplacement_Type, "0", _PICellerator_CalculateParticleDisplacement_DefaultNew  );
-
-	return result;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 plugins/CalculateParticleDisplacement/CalculateParticleDisplacement.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/CalculateParticleDisplacement/CalculateParticleDisplacement.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,191 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: CalculateParticleDisplacement.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+
+#include "CalculateParticleDisplacement.h"
+#include <math.h>
+#include <string.h>
+#include <assert.h>
+
+const Type PICellerator_CalculateParticleDisplacement_Type = "PICellerator_CalculateParticleDisplacement";
+
+void _PICellerator_CalculateParticleDisplacement_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+	CalculateParticleDisplacementPlugin*  self = (CalculateParticleDisplacementPlugin*)component;
+	DomainContext*                context;
+	MaterialPointsSwarm*                  materialPointsSwarm;
+	StandardParticle                      particle;
+	ParticleDisplacementInfo*             particleExt;
+	
+	context = (DomainContext*)Stg_ComponentFactory_ConstructByName( cf, (Name)"context", DomainContext, True, data  );
+
+	ContextEP_Append( context, AbstractContext_EP_Initialise, _PICellerator_CalculateParticleDisplacement_StoreOriginalPos );
+	ContextEP_Append( context, AbstractContext_EP_Step, _PICellerator_CalculateParticleDisplacement_UpdateDisplacement );
+
+	/* Extend particle with original pos */
+	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
+	assert( materialPointsSwarm  );
+	self->particleDisplacementInfo_Handle = ExtensionManager_Add( materialPointsSwarm->particleExtensionMgr, (Name)CURR_MODULE_NAME, sizeof( ParticleDisplacementInfo )  );
+
+	/* now register these guys as swarm variables */
+	particleExt = (ParticleDisplacementInfo*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, &particle,
+		self->particleDisplacementInfo_Handle );
+
+	self->particleOriginalCoordSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"OriginalCoord", (ArithPointer) &particleExt->originalCoord - (ArithPointer) &particle,
+		Variable_DataType_Double,
+		materialPointsSwarm->dim,
+		"OriginalCoordX",
+		"OriginalCoordY",
+		"OriginalCoordZ" );
+		
+	self->particleDisplacementSwarmVariable = Swarm_NewVectorVariable( materialPointsSwarm, (Name)"Displacement", (ArithPointer) &particleExt->displacement - (ArithPointer) &particle,
+		Variable_DataType_Double,
+		materialPointsSwarm->dim,
+		"DisplacementX",
+		"DisplacementY",
+		"DisplacementZ" );
+
+	/* Create this here, rather than in XML, since if we tried to create it in XML it couldn't
+	find the Displacement swarm variable at configure-time */
+	/* OperatorSwarmVariables don't automatically prefix the swarm's name to the name
+	you give, so we have to add it manually here */
+	self->particleDisplacementMagSwarmVariable = OperatorSwarmVariable_NewUnary(
+		"materialSwarm-DisplacementMagnitude",
+		(AbstractContext*)context, 
+		self->particleDisplacementSwarmVariable,
+		"Magnitude" );
+	
+	/* Need to make sure this guy is build/initialised */
+}
+
+
+void _PICellerator_CalculateParticleDisplacement_StoreOriginalPos( PICelleratorContext* context ) {
+	CalculateParticleDisplacementPlugin*  self;
+	MaterialPointsSwarm*                  materialPointsSwarm;
+	GlobalParticle*                       particle;
+	double*                               originalCoord;
+	ParticleDisplacementInfo*             particleDisplacementInfo; 
+	Particle_Index                        lParticle_I;
+
+	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
+	assert( materialPointsSwarm );
+	self = (CalculateParticleDisplacementPlugin* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"PICellerator_CalculateParticleDisplacement" );
+	assert( self );
+
+	for ( lParticle_I = 0 ; lParticle_I < materialPointsSwarm->particleLocalCount ; lParticle_I++ ) {
+		particle = (GlobalParticle* )Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
+		particleDisplacementInfo = (ParticleDisplacementInfo*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr,
+			particle, self->particleDisplacementInfo_Handle );
+		originalCoord = particleDisplacementInfo->originalCoord;
+
+		memcpy( originalCoord, particle->coord, sizeof(Coord) );
+		memset( particleDisplacementInfo->displacement, 0, sizeof(XYZ) );
+	}
+}
+
+
+void _PICellerator_CalculateParticleDisplacement_UpdateDisplacement( PICelleratorContext* context ) {
+	CalculateParticleDisplacementPlugin*  self;
+	MaterialPointsSwarm*                  materialPointsSwarm;
+	GlobalParticle*                       particle;
+	double*                               originalCoord;
+	double*                               coord;
+	Particle_Index                        lParticle_I;
+	ParticleDisplacementInfo*             particleDisplacementInfo = NULL;
+	Dimension_Index                       dim_I;
+
+	/* Add original pos to particle */
+	materialPointsSwarm = (MaterialPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"materialSwarm" );
+	assert( materialPointsSwarm );
+	self = (CalculateParticleDisplacementPlugin* ) LiveComponentRegister_Get( context->CF->LCRegister, (Name)"PICellerator_CalculateParticleDisplacement" );
+	assert( self );
+
+	for ( lParticle_I = 0 ; lParticle_I < materialPointsSwarm->particleLocalCount ; lParticle_I++ ) {
+		particle      = (GlobalParticle* )Swarm_ParticleAt( materialPointsSwarm, lParticle_I );
+		coord         = particle->coord;
+		particleDisplacementInfo = (ParticleDisplacementInfo*)ExtensionManager_Get( materialPointsSwarm->particleExtensionMgr, particle,
+			self->particleDisplacementInfo_Handle );
+		originalCoord = particleDisplacementInfo->originalCoord;	
+
+		for ( dim_I = 0; dim_I < materialPointsSwarm->dim; dim_I++ ) {
+			particleDisplacementInfo->displacement[dim_I] = coord[dim_I] - originalCoord[dim_I];
+		}
+	}
+}
+
+
+void* _PICellerator_CalculateParticleDisplacement_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( CalculateParticleDisplacementPlugin );
+	Type                                                      type = PICellerator_CalculateParticleDisplacement_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PICellerator_CalculateParticleDisplacement_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _PICellerator_CalculateParticleDisplacement_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Codelet_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Codelet_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 _Codelet_New(  CODELET_PASSARGS  );
+}
+
+
+Index PICellerator_CalculateParticleDisplacement_Register( PluginsManager* pluginsManager ) {
+	Index result;
+
+	result = PluginsManager_Submit( pluginsManager, PICellerator_CalculateParticleDisplacement_Type, "0", _PICellerator_CalculateParticleDisplacement_DefaultNew  );
+
+	return result;
+}
+
+
diff -r 420e7ed7a877 -r 285af3102548 plugins/Output/MaterialCentroid/MaterialCentroid.c
--- a/plugins/Output/MaterialCentroid/MaterialCentroid.c	Wed May 11 13:26:28 2011 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,150 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-**
-** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
-**	Melbourne, 3053, Australia.
-** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
-**	Victoria, 3800, 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
-**
-** Contributors:
-**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
-**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
-**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
-**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
-**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
-**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
-**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
-**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
-**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
-**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MaterialCentroid.c 518 2007-10-11 08:07:50Z SteveQuenette $
-**
-**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-#include <mpi.h>
-#include <StGermain/StGermain.h>
-#include <StgDomain/StgDomain.h>
-#include <StgFEM/StgFEM.h>
-#include <PICellerator/PICellerator.h>
-#include <assert.h>
-
-const Type PICellerator_MaterialCentroid_Type = "PICellerator_MaterialCentroid";
-
-void MaterialCentroid( PICelleratorContext* context ) {
-	static IntegrationPointsSwarm*      swarm;
-	static Material*            material;
-	Coord                       centroid;
-	double                      volume;
-	static Bool                 beenHere              = False;
-	Stream*                     stream                = Journal_Register( Info_Type, (Name)"MaterialCentroid" );
-
-	if (!beenHere ) {
-		char*                swarmName;
-		char*                materialName;
-		char*                filename;
-      Bool                 fileOpened;
-      Stream*              errorStream  = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  );
-
-		swarmName = Dictionary_GetString_WithDefault( context->dictionary, "MaterialCentroid_Swarm", "picIntegrationPoints" );
-		
-		/* Get Swarm */
-		swarm = (IntegrationPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)swarmName );
-		assert( swarm  );
-	
-		/* Get Material */
-		materialName = Dictionary_GetString( context->dictionary, (Dictionary_Entry_Key)"CentroidMaterial"  );
-		material = Materials_Register_GetByName( swarm->materials_Register, materialName );
-		assert( material );
-		
-		/* Set up stream */
-		Stg_asprintf( &filename, "%sCentroid.dat", materialName );
-      /* Open File */
-      if ( context->rank == 0 ) {
-         if ( context->loadFromCheckPoint == False ) {
-            /* Always overwrite the file if starting a new run */
-            fileOpened = Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
-         } else {
-            /* Just append to the file if doing a restart from checkpoint */
-            fileOpened = Stream_AppendFile_WithPrependedPath( stream, context->outputPath, filename );
-         }
-         Journal_Firewall( fileOpened, errorStream, 
-               "Could not open file %s/%s. Possibly directory %s does not exist or is not writable.\n"
-               "Check 'outputPath' in input file.\n", context->outputPath, filename, context->outputPath );
-      }
-		Memory_Free( filename );
-		Stream_SetAutoFlush( stream, True );
-
-		/* Print header to stream */
-		Journal_Printf( stream, 
-				"#       Timestep            Time          Volume       CentroidX       CentroidY       CentroidZ\n" );
-
-		beenHere = True;
-	}
-		
-	volume = Material_Volume( material, swarm, centroid );
-
-	Journal_Printf( stream, "    %12.6g    %12.6g    %12.6g    %12.6g    %12.6g    %12.6g\n",
-			(double)context->timeStep, context->currentTime, volume, centroid[ I_AXIS ], centroid[ J_AXIS ], centroid[ K_AXIS ] );
-}
-
-
-void _PICellerator_MaterialCentroid_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
-
-	AbstractContext* context;
-
-	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
-	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, MaterialCentroid );
-}
-
-
-void* _PICellerator_MaterialCentroid_DefaultNew( Name name ) {
-	/* Variables set in this function */
-	SizeT                                              _sizeOfSelf = sizeof( Codelet );
-	Type                                                      type = PICellerator_MaterialCentroid_Type;
-	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
-	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
-	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
-	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PICellerator_MaterialCentroid_DefaultNew;
-	Stg_Component_ConstructFunction*                    _construct = _PICellerator_MaterialCentroid_AssignFromXML;
-	Stg_Component_BuildFunction*                            _build = _Codelet_Build;
-	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
-	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
-	Stg_Component_DestroyFunction*                        _destroy = _Codelet_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 _Codelet_New(  CODELET_PASSARGS  );
-}
-
-
-Index PICellerator_MaterialCentroid_Register( PluginsManager* pluginsManager ) {
-	Index result;
-
-	result = PluginsManager_Submit( pluginsManager, PICellerator_MaterialCentroid_Type, (Name)"0", _PICellerator_MaterialCentroid_DefaultNew  );
-
-	return result;
-}
-
-
diff -r 420e7ed7a877 -r 285af3102548 plugins/Output/MaterialCentroid/MaterialCentroid.cxx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/Output/MaterialCentroid/MaterialCentroid.cxx	Thu May 12 11:18:04 2011 -0700
@@ -0,0 +1,150 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003-2006, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street,
+**	Melbourne, 3053, Australia.
+** Copyright (c) 2005-2006, Monash Cluster Computing, Building 28, Monash University Clayton Campus,
+**	Victoria, 3800, 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
+**
+** Contributors:
+**	Robert Turnbull, Research Assistant, Monash University. (robert.turnbull at sci.monash.edu.au)
+**	Patrick D. Sunter, Software Engineer, VPAC. (patrick at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	David May, PhD Student, Monash University (david.may at sci.monash.edu.au)
+**	Vincent Lemiale, Postdoctoral Fellow, Monash University. (vincent.lemiale at sci.monash.edu.au)
+**	Julian Giordani, Research Assistant, Monash University. (julian.giordani 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)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**	David Stegman, Postdoctoral Fellow, Monash University. (david.stegman at sci.monash.edu.au)
+**	Wendy Sharples, PhD Student, Monash University (wendy.sharples 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: MaterialCentroid.c 518 2007-10-11 08:07:50Z SteveQuenette $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <mpi.h>
+#include <StGermain/StGermain.h>
+#include <StgDomain/StgDomain.h>
+#include <StgFEM/StgFEM.h>
+#include <PICellerator/PICellerator.h>
+#include <assert.h>
+
+const Type PICellerator_MaterialCentroid_Type = "PICellerator_MaterialCentroid";
+
+void MaterialCentroid( PICelleratorContext* context ) {
+	static IntegrationPointsSwarm*      swarm;
+	static Material*            material;
+	Coord                       centroid;
+	double                      volume;
+	static Bool                 beenHere              = False;
+	Stream*                     stream                = Journal_Register( Info_Type, (Name)"MaterialCentroid" );
+
+	if (!beenHere ) {
+		char*                swarmName;
+		char*                materialName;
+		char*                filename;
+      Bool                 fileOpened;
+      Stream*              errorStream  = Journal_Register( Error_Type, (Name)CURR_MODULE_NAME  );
+
+		swarmName = Dictionary_GetString_WithDefault( context->dictionary, "MaterialCentroid_Swarm", "picIntegrationPoints" );
+		
+		/* Get Swarm */
+		swarm = (IntegrationPointsSwarm*) LiveComponentRegister_Get( context->CF->LCRegister, (Name)swarmName );
+		assert( swarm  );
+	
+		/* Get Material */
+		materialName = Dictionary_GetString( context->dictionary, (Dictionary_Entry_Key)"CentroidMaterial"  );
+		material = Materials_Register_GetByName( swarm->materials_Register, materialName );
+		assert( material );
+		
+		/* Set up stream */
+		Stg_asprintf( &filename, "%sCentroid.dat", materialName );
+      /* Open File */
+      if ( context->rank == 0 ) {
+         if ( context->loadFromCheckPoint == False ) {
+            /* Always overwrite the file if starting a new run */
+            fileOpened = Stream_RedirectFile_WithPrependedPath( stream, context->outputPath, filename );
+         } else {
+            /* Just append to the file if doing a restart from checkpoint */
+            fileOpened = Stream_AppendFile_WithPrependedPath( stream, context->outputPath, filename );
+         }
+         Journal_Firewall( fileOpened, errorStream, 
+               "Could not open file %s/%s. Possibly directory %s does not exist or is not writable.\n"
+               "Check 'outputPath' in input file.\n", context->outputPath, filename, context->outputPath );
+      }
+		Memory_Free( filename );
+		Stream_SetAutoFlush( stream, True );
+
+		/* Print header to stream */
+		Journal_Printf( stream, 
+				"#       Timestep            Time          Volume       CentroidX       CentroidY       CentroidZ\n" );
+
+		beenHere = True;
+	}
+		
+	volume = Material_Volume( material, swarm, centroid );
+
+	Journal_Printf( stream, "    %12.6g    %12.6g    %12.6g    %12.6g    %12.6g    %12.6g\n",
+			(double)context->timeStep, context->currentTime, volume, centroid[ I_AXIS ], centroid[ J_AXIS ], centroid[ K_AXIS ] );
+}
+
+
+void _PICellerator_MaterialCentroid_AssignFromXML( void* component, Stg_ComponentFactory* cf, void* data ) {
+
+	AbstractContext* context;
+
+	context = Stg_ComponentFactory_ConstructByName( cf, (Name)"context", AbstractContext, True, data  ); 
+	ContextEP_Append( context, AbstractContext_EP_FrequentOutput, MaterialCentroid );
+}
+
+
+void* _PICellerator_MaterialCentroid_DefaultNew( Name name ) {
+	/* Variables set in this function */
+	SizeT                                              _sizeOfSelf = sizeof( Codelet );
+	Type                                                      type = PICellerator_MaterialCentroid_Type;
+	Stg_Class_DeleteFunction*                              _delete = _Codelet_Delete;
+	Stg_Class_PrintFunction*                                _print = _Codelet_Print;
+	Stg_Class_CopyFunction*                                  _copy = _Codelet_Copy;
+	Stg_Component_DefaultConstructorFunction*  _defaultConstructor = _PICellerator_MaterialCentroid_DefaultNew;
+	Stg_Component_ConstructFunction*                    _construct = _PICellerator_MaterialCentroid_AssignFromXML;
+	Stg_Component_BuildFunction*                            _build = _Codelet_Build;
+	Stg_Component_InitialiseFunction*                  _initialise = _Codelet_Initialise;
+	Stg_Component_ExecuteFunction*                        _execute = _Codelet_Execute;
+	Stg_Component_DestroyFunction*                        _destroy = _Codelet_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 _Codelet_New(  CODELET_PASSARGS  );
+}
+
+
+Index PICellerator_MaterialCentroid_Register( PluginsManager* pluginsManager ) {
+	Index result;
+
+	result = PluginsManager_Submit( pluginsManager, PICellerator_MaterialCentroid_Type, (Name)"0", _PICellerator_MaterialCentroid_DefaultNew  );
+
+	return result;
+}
+
+



More information about the CIG-COMMITS mailing list